Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "cdevaudio.h"
19 #include "cdevaudiocontrol.h"
20 #include "cdevplaycontrol.h"
21 #include "cdevrecordcontrol.h"
22 #include "cdevtonecontrol.h"
23 #include "cdevgencontrol.h"
25 #include <a3f/audioprocessingunittypeuids.h>
26 #include <a3f/devsoundadaptationinfo.h>
27 #include <a3f/a3ffourcclookup.h>
28 #include <a3f/audiocontextfactory.h>
29 #include <a3f/maudioprocessingunit.h>
30 #include <a3f/maudiocontext.h>
31 #include <a3f/mcontexteffectiveclient.h>
32 #include <a3f/maudiostream.h>
33 #include <a3f/maudiocodec.h>
34 #include <a3f/maudiogaincontrol.h>
35 #include <a3f/mbuffersource.h>
36 #include <a3f/mbuffersink.h>
38 #include "mglobalproperties.h"
40 const TInt KMidWayBalance = 50; // 50%
41 const TInt KMaxBalance = 100; // 100%
42 const TInt KLeftChannel = 0;
43 const TInt KRightChannel = 1;
46 // ======== LOCAL FUNCTIONS ========
48 // ======== MEMBER FUNCTIONS ========
50 // ---------------------------------------------------------------------------
51 // Default constructor
52 // ---------------------------------------------------------------------------
54 CDevAudio::CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver)
55 : iAdaptationObserver(aAdaptationObserver), iMode(EMMFStateIdle),
56 iActiveState(EDevSoundAdaptorCreated_Uninitialised),
57 iActiveStreamState(EUninitialized)
60 DP_CONTEXT(CDevAudio::CDevAudio *CD1*, CtxDevSound, DPLOCAL);
63 iDevSoundPlayBalance[KLeftChannel] = iDevSoundPlayBalance[KRightChannel] = KMidWayBalance;
64 iDevSoundRecordBalance[KLeftChannel] = iDevSoundRecordBalance[KRightChannel] = KMidWayBalance;
69 // ---------------------------------------------------------------------------
71 // ---------------------------------------------------------------------------
73 CDevAudio::~CDevAudio()
75 DP_CONTEXT(CDevAudio::~CDevAudio *CD1*, CtxDevSound, DPLOCAL);
78 delete iAdaptationInfo;
80 iSupportedInputFormats.Close();
81 iSupportedOutputFormats.Close();
83 // This part is fine at the destructor
84 // All this is syncronous
89 iAudioContext->DeleteAudioProcessingUnit(iGainControl);
93 iAudioContext->DeleteAudioProcessingUnit(iAudioSink);
97 iAudioContext->DeleteAudioProcessingUnit(iAudioCodec);
101 iAudioContext->DeleteAudioProcessingUnit(iAudioSource);
105 iAudioContext->DeleteAudioStream(iAudioStream);
109 iAudioContextFactory->DeleteAudioContext(iAudioContext);
111 if ( iAudioContextFactory )
113 delete iAudioContextFactory;
116 if ( iDevPlayControl )
118 delete iDevPlayControl;
120 if ( iDevRecordControl )
122 delete iDevRecordControl;
124 if ( iDevToneControl )
126 delete iDevToneControl;
128 if ( iDevGenControl )
130 delete iDevGenControl;
136 // -----------------------------------------------------------------------------
138 // Two-phased constructor.
139 // -----------------------------------------------------------------------------
141 CDevAudio* CDevAudio::NewL(MDevSoundAdaptationObserver& aAdaptationObserver,
142 MGlobalProperties& aGlobalProperties)
144 DP_STATIC_CONTEXT(CDevAudio::NewL *CD0*, CtxDevSound, DPLOCAL);
146 CDevAudio* self = new (ELeave) CDevAudio(aAdaptationObserver);
147 CleanupStack::PushL(self);
148 self->ConstructL(aGlobalProperties);
149 CleanupStack::Pop(self);
150 DP0_RET(self, "0x%x");
154 // -----------------------------------------------------------------------------
155 // CDevAudio::ConstructL
156 // -----------------------------------------------------------------------------
158 void CDevAudio::ConstructL(MGlobalProperties& aGlobalProperties)
160 DP_CONTEXT(CDevAudio::ConstructL *CD1*, CtxDevSound, DPLOCAL);
163 iGlobalProperties = &aGlobalProperties;
165 iAudioContextFactory = CAudioContextFactory::NewL();
167 User::LeaveIfError(iAudioContextFactory->CreateAudioContext(iAudioContext));
169 User::LeaveIfError(iAudioContext->CreateAudioStream(iAudioStream));
171 User::LeaveIfError(iAudioContext->CreateAudioProcessingUnit(KUidAudioGainControl, iGainControl));
172 User::LeaveIfError(iAudioStream->AddGainControl(iGainControl));
174 iDevPlayControl = CDevPlayControl::NewL(this, iAdaptationObserver);
175 iDevRecordControl = CDevRecordControl::NewL(this, iAdaptationObserver);
176 iDevToneControl = CDevToneControl::NewL(this, iAdaptationObserver);
177 iDevGenControl = CDevGenControl::NewL(this, iAdaptationObserver);
179 iAdaptationInfo = CA3FDevSoundAdaptationInfo::NewL(*this, const_cast<CFourCCConvertor&>(iGlobalProperties->GetFourCCConvertor()));
181 // The generic audio control is the only one receiving the callbacks at this moment
182 iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevGenControl);
183 TInt err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
184 if ((err != KErrNone) && (err != KErrAlreadyExists))
191 // -----------------------------------------------------------------------------
192 // CDevAudio::PostOpen
193 // -----------------------------------------------------------------------------
195 TInt CDevAudio::PostOpen()
197 DP_CONTEXT(CDevAudio::PostOpen *CD1*, CtxDevSound, DPLOCAL);
199 ASSERT(iPreOpenState==EPreOpenStateIdle);
202 if(iPreOpenState == EPreOpenStateIdle)
204 err = iAdaptationInfo->RequestMaxGain(KUidAudioDecoder);
207 iPreOpenState = EPreOpenStateRequestingMaxVolume;
215 TBool CDevAudio::IsResumeSupported()
217 DP_CONTEXT(CDevAudio::IsResumeSupported *CD1*, CtxDevSound, DPLOCAL);
220 TUid codecType(KNullUid);
221 if(iMode == EMMFStatePlaying || iMode == EMMFStateTonePlaying)
223 codecType = KUidAudioDecoder;
225 else if (iMode == EMMFStateRecording)
227 codecType = KUidAudioEncoder;
229 TBool supported = iAdaptationInfo->IsResumeSupported(codecType, iFormat);
231 DP0_RET(supported, "%d");
235 // -----------------------------------------------------------------------------
236 // CDevAudio::RequestMaxGainComplete
237 // -----------------------------------------------------------------------------
239 void CDevAudio::RequestMaxGainComplete (TUid __DEBUG_ONLY(aCodecType), TInt aError, TInt aResult)
241 DP_CONTEXT(CDevAudio::RequestMaxGainComplete *CD1*, CtxDevSound, DPLOCAL);
243 ASSERT(iPreOpenState==EPreOpenStateRequestingMaxVolume && aCodecType==KUidAudioDecoder||
244 iPreOpenState==EPreOpenStateRequestingMaxGain && aCodecType==KUidAudioEncoder);
247 TBool asyncComplete = EFalse;
251 if (iPreOpenState==EPreOpenStateRequestingMaxVolume)
253 iDevSoundMaxVolume = aResult;
255 err = SetDevSoundVolume((iDevSoundMaxVolume+1)/2, asyncComplete);
257 __ASSERT_DEBUG(asyncComplete==EFalse, User::Invariant());
261 // first request - so request max gain
262 err = iAdaptationInfo->RequestMaxGain(KUidAudioEncoder);
265 iPreOpenState = EPreOpenStateRequestingMaxGain;
269 else if(iPreOpenState==EPreOpenStateRequestingMaxGain)
271 iDevSoundMaxGain = aResult;
273 err = SetDevSoundGain((iDevSoundMaxGain+1)/2, asyncComplete);
275 __ASSERT_DEBUG(asyncComplete==EFalse, User::Invariant());
279 // second request - complete whatever - Ready for Formats
280 err = iAdaptationInfo->RequestSupportedFormats(KUidAudioDecoder, iSupportedInputFormats);
283 iPreOpenState = EPreOpenStateRequestingInputFormats;
291 iPreOpenState = EPreOpenStateIdle;
292 iAdaptationObserver.AsynchronousOperationComplete(err, ETrue);
298 // -----------------------------------------------------------------------------
299 // CDevAudio::RequestSupportedFormatsComplete
300 // -----------------------------------------------------------------------------
302 void CDevAudio::RequestSupportedFormatsComplete(TUid __DEBUG_ONLY(aCodecType), TInt aError)
304 DP_CONTEXT(CDevAudio::RequestSupportedFormatsComplete *CD1*, CtxDevSound, DPLOCAL);
306 ASSERT(iPreOpenState==EPreOpenStateRequestingInputFormats && aCodecType==KUidAudioDecoder||
307 iPreOpenState==EPreOpenStateRequestingOutputFormats && aCodecType==KUidAudioEncoder);
313 if (iPreOpenState==EPreOpenStateRequestingInputFormats)
315 // first request - so request output formats
316 err = iAdaptationInfo->RequestSupportedFormats(KUidAudioEncoder, iSupportedOutputFormats);
319 iPreOpenState = EPreOpenStateRequestingOutputFormats;
324 ASSERT(iPreOpenState==EPreOpenStateRequestingOutputFormats);
325 // second request - complete whatever
326 iPreOpenState = EPreOpenStateIdle;
327 iAdaptationObserver.AsynchronousOperationComplete(aError, ETrue);
333 iPreOpenState = EPreOpenStateIdle;
334 iAdaptationObserver.AsynchronousOperationComplete(err, ETrue);
341 // -----------------------------------------------------------------------------
342 // CDevAudio::Initialize
343 // -----------------------------------------------------------------------------
345 TInt CDevAudio::Initialize(TUid aFormat, TMMFState aMode)
347 DP_CONTEXT(CDevAudio::Initialize*CD1*, CtxDevSound, DPLOCAL);
351 if(iActiveState != EDevSoundAdaptorCreated_Uninitialised &&
352 iActiveState != EDevSoundAdaptorInitialised_Initialised &&
353 iActiveState != EDevSoundAdaptorInitialised_Idle &&
354 iActiveState != EDevSoundAdaptorUnitialised_Uninitialised )
356 DP0_RET(KErrNotReady, "%d");
360 if (iActiveState == EDevSoundAdaptorInitialised_Initialised ||
361 iActiveState == EDevSoundAdaptorInitialised_Idle)
363 iReinitializing = ETrue;
364 iTargetFormat = aFormat;
366 if(iActiveState == EDevSoundAdaptorInitialised_Idle)
368 err = iAudioStream->Unload();
371 err = CommitAudioContext();
375 iActiveState = EDevSoundAdaptorUnloading;
380 err = iCurrentAudioControl->Uninitialize();
385 // Redo partial initialization after pre-emption clash event in
386 // EDevSoundAdaptorRemovingProcessingUnits state
387 if (iActiveState == EDevSoundAdaptorUnitialised_Uninitialised &&
388 iPreviousState == EDevSoundAdaptorRemovingProcessingUnits)
390 err = iCurrentAudioControl->RemoveProcessingUnits();
394 // Delete pUnits if already created
397 iAudioContext->DeleteAudioProcessingUnit(iAudioSource);
403 iAudioContext->DeleteAudioProcessingUnit(iAudioSink);
409 iAudioContext->DeleteAudioProcessingUnit(iAudioCodec);
413 // Create pUnits and select proper DevSound Adaptor Helper
414 if (aMode == EMMFStatePlaying)
416 // create correct type sink&source&codec
417 err = CreateAudioProcessingUnits(KUidMmfBufferSource, KUidAudioDeviceSink, KUidAudioDecoder);
420 // Now just the playcontrol should receive the only one receiving events from
422 iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
423 iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevPlayControl);
424 err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
426 if ((err != KErrNone) && (err != KErrAlreadyExists))
428 DeleteAudioProcessingUnits();
432 else if (aMode == EMMFStateRecording)
434 // create correct type sink&source&codec
435 err = CreateAudioProcessingUnits(KUidAudioDeviceSource, KUidMmfBufferSink, KUidAudioEncoder);
438 iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
439 iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevRecordControl);
440 err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
442 if ((err != KErrNone) && (err != KErrAlreadyExists))
444 DeleteAudioProcessingUnits();
447 else if (aMode == EMMFStateTonePlaying)
449 // create correct type sink&source&codec
450 err = CreateAudioProcessingUnits(KUidMmfBufferSource, KUidAudioDeviceSink, KUidAudioDecoder);
453 iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
454 iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevToneControl);
455 err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
457 if ((err != KErrNone) && (err != KErrAlreadyExists))
459 DeleteAudioProcessingUnits();
462 else if (aMode == EMMFStateIdle)
465 iAudioContext->UnregisterAudioContextObserver(*iCurrentAudioControl);
466 iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevGenControl);
467 err = iAudioContext->RegisterAudioContextObserver(*iCurrentAudioControl);
471 iCurrentAudioControl = static_cast<CDevAudioControl*>(iDevGenControl);
472 err = KErrNotSupported;
477 err = iCurrentAudioControl->Initialize(aFormat);
489 // -----------------------------------------------------------------------------
490 // CDevAudio::CancelInitialize
491 // -----------------------------------------------------------------------------
493 TInt CDevAudio::CancelInitialize()
495 DP_CONTEXT(CDevAudio::CancelInitialize *CD1*, CtxDevSound, DPLOCAL);
499 // Redo partial cancelling of initialization after pre-emption clash event in
500 // EDevSoundAdaptorRemovingProcessingUnits state.
501 if (iActiveState == EDevSoundAdaptorUnitialised_Uninitialised &&
502 iPreviousState == EDevSoundAdaptorRemovingProcessingUnits)
504 err = iCurrentAudioControl->RemoveProcessingUnits();
507 else if(iActiveState != EDevSoundAdaptorInitialised_Initialised)
509 DP0_RET(KErrNotReady, "%d");
512 err = iCurrentAudioControl->Uninitialize();
517 // -----------------------------------------------------------------------------
518 // CDevAudio::GetAudioControl
519 // -----------------------------------------------------------------------------
521 CDevAudioControl* CDevAudio::GetAudioControl()
523 DP_CONTEXT(CDevAudio::GetAudioControl *CD1*, CtxDevSound, DPLOCAL);
526 return iCurrentAudioControl;
529 // -----------------------------------------------------------------------------
530 // CDevAudio::SetPrioritySettings
531 // -----------------------------------------------------------------------------
533 TInt CDevAudio::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
535 DP_CONTEXT(CDevAudio::SetPrioritySettings *CD1*, CtxDevSound, DPLOCAL);
537 iPrioritySettings.iPriority = aPrioritySettings.iPriority;
538 iPrioritySettings.iPref = aPrioritySettings.iPref;
539 iPriorityFlag = ETrue;
540 DP2(DLINFO, "Priority = 0x%x Preference = 0x%x", iPrioritySettings.iPriority,iPrioritySettings.iPref);
544 // -----------------------------------------------------------------------------
545 // CDevAudio::GetPrioritySettings
546 // -----------------------------------------------------------------------------
548 void CDevAudio::GetPrioritySettings(TAudioTypeSettings& aPrioritySettings)
550 aPrioritySettings = iPrioritySettings;
552 // -----------------------------------------------------------------------------
553 // CDevAudio::IsPrioritySet
554 // -----------------------------------------------------------------------------
556 TBool CDevAudio::IsPrioritySet()
558 return iPriorityFlag;
561 // -----------------------------------------------------------------------------
562 // CDevAudio::SetClientConfig
563 // -----------------------------------------------------------------------------
565 TInt CDevAudio::SetClientConfig(const TProcessId& aProcessId)
567 DP_CONTEXT(CDevAudio::SetClientConfig *CD1*, CtxDevSound, DPLOCAL);
569 // TODO: Check if the TClientContextSettings atributte go back since
570 // if not there is no way to send the vendor id
571 TClientContextSettings context;
572 context.iProcessId = aProcessId;
573 TInt err = iAudioContext->SetClientSettings(context);
576 DP1(DLERR, "Error %d setting client context!",err);
581 TInt CDevAudio::SetClientConfig(const TProcessId& aActualProcessId, const TProcessId& aProcessId)
583 DP_CONTEXT(CDevAudio::SetClientConfig *CD1*, CtxDevSound, DPLOCAL);
586 MContextSetEffectiveClient* setEffectiveClient
587 = static_cast<MContextSetEffectiveClient*>(iAudioContext->Interface(KSetClientInfoUid));
591 if (!setEffectiveClient)
593 DP0(DLINFO, "MContextSetEffectiveClient not supported, revert to old behaviour of just passing actual client info");
594 err = SetClientConfig(aActualProcessId);
598 TClientContextSettings context;
599 context.iProcessId = aProcessId;
600 err = iAudioContext->SetClientSettings(context);
603 DP1(DLERR, "Error %d setting client context!",err);
607 err = setEffectiveClient->SetEffectiveClientInfo(aActualProcessId);
610 DP1(DLERR, "Error %d setting effective client context!",err);
619 void CDevAudio::ContextEvent(TUid /*aEvent*/, TInt /*aError*/)
621 DP_CONTEXT(CDevAudio::ContextEvent *CD1*, CtxDevSound, DPLOCAL);
626 // -----------------------------------------------------------------------------
627 // CDevAudio::ActiveState
628 // -----------------------------------------------------------------------------
630 TDevSoundAdaptorState CDevAudio::ActiveState() const
632 DP_CONTEXT(CDevAudio::ActiveState *CD1*, CtxDevSound, DPLOCAL);
634 DP0_RET(iActiveState, "%d");
637 // -----------------------------------------------------------------------------
638 // CDevAudio::ActiveState
639 // -----------------------------------------------------------------------------
641 TDevSoundAdaptorState CDevAudio::PreviousState() const
643 DP_CONTEXT(CDevAudio::PreviousState *CD1*, CtxDevSound, DPLOCAL);
645 DP0_RET(iPreviousState, "%d");
648 // -----------------------------------------------------------------------------
649 // CDevAudio::SetActiveState
650 // -----------------------------------------------------------------------------
652 void CDevAudio::SetActiveState(TDevSoundAdaptorState aAdaptorState)
654 DP_CONTEXT(CDevAudio::SetActiveState *CD1*, CtxDevSound, DPLOCAL);
656 iActiveState = aAdaptorState;
660 // -----------------------------------------------------------------------------
661 // CDevAudio::SetPreviousState
662 // -----------------------------------------------------------------------------
664 void CDevAudio::SetPreviousState(TDevSoundAdaptorState aAdaptorState)
666 DP_CONTEXT(CDevAudio::SetPreviousState *CD1*, CtxDevSound, DPLOCAL);
668 iPreviousState = aAdaptorState;
672 // -----------------------------------------------------------------------------
673 // CDevAudio::SetDevSoundVolume
674 // -----------------------------------------------------------------------------
676 TInt CDevAudio::SetDevSoundVolume(TInt aVolume, TBool& aAsyncComplete)
678 DP_CONTEXT(CDevAudio::SetDevSoundVolume *CD1*, CtxDevSound, DPLOCAL);
681 // Values are clipped between 0 and MaxGain.
682 // because MAudioGainControl expects this to be done
683 TInt volume = aVolume;
688 else if (volume > iDevSoundMaxVolume)
690 volume = iDevSoundMaxVolume;
692 iDevSoundVolume = volume;
694 TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
696 DP0_RET(error, "%d");
700 // -----------------------------------------------------------------------------
701 // CDevAudio::SetDevSoundGain
702 // -----------------------------------------------------------------------------
704 TInt CDevAudio::SetDevSoundGain(TInt aGain, TBool& aAsyncComplete)
706 DP_CONTEXT(CDevAudio::SetDevSoundGain *CD1*, CtxDevSound, DPLOCAL);
709 // Values are clipped between 0 and MaxGain.
710 // because MAudioGainControl expects this to be done
716 else if (gain > iDevSoundMaxGain)
718 gain = iDevSoundMaxGain;
720 iDevSoundGain = gain;
722 TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
724 DP0_RET(error, "%d");
727 // -----------------------------------------------------------------------------
728 // CDevAudio::SetDevSoundPlayBalance
729 // -----------------------------------------------------------------------------
731 TInt CDevAudio::SetDevSoundPlayBalance(TInt aLeftBalance, TInt aRightBalance, TBool& aAsyncComplete)
733 DP_CONTEXT(CDevAudio::SetDevSoundPlayBalance *CD1*, CtxDevSound, DPLOCAL);
737 TInt left = aLeftBalance;
742 else if (left > KMaxBalance)
746 TInt right = aRightBalance;
751 else if (right > KMaxBalance)
755 iDevSoundPlayBalance[KLeftChannel] = left;
756 iDevSoundPlayBalance[KRightChannel] = right;
758 TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
760 DP0_RET(error, "%d");
763 // -----------------------------------------------------------------------------
764 // CDevAudio::SetDevSoundRecordBalance
765 // -----------------------------------------------------------------------------
767 TInt CDevAudio::SetDevSoundRecordBalance(TInt aLeftBalance, TInt aRightBalance, TBool& aAsyncComplete)
769 DP_CONTEXT(CDevAudio::SetDevSoundRecordBalance *CD1*, CtxDevSound, DPLOCAL);
773 TInt left = aLeftBalance;
778 else if (left > KMaxBalance)
782 TInt right = aRightBalance;
787 else if (right > KMaxBalance)
791 iDevSoundRecordBalance[KLeftChannel] = left;
792 iDevSoundRecordBalance[KRightChannel] = right;
794 TInt error = SetGainAndBalance(EFalse, aAsyncComplete);
796 DP0_RET(error, "%d");
800 // -----------------------------------------------------------------------------
801 // CDevAudio::SetVolumeRamp
802 // -----------------------------------------------------------------------------
804 TInt CDevAudio::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
806 DP_CONTEXT(CDevAudioControl::SetVolumeRamp *CD1*, CtxDevSound, DPLOCAL);
809 iRampDuration = aRampDuration;
811 DP0_RET(KErrNone,"%d");
814 // -----------------------------------------------------------------------------
815 // CDevAudio::RequestGainAndBalance
816 // -----------------------------------------------------------------------------
818 TInt CDevAudio::RequestGainAndBalance(CDevAudioControl* aCallingControl)
820 DP_CONTEXT(CDevAudio::RequestGainAndBalance *CD1*, CtxDevSound, DPLOCAL);
823 TInt error = KErrNone;
824 if (aCallingControl != iCurrentAudioControl)
826 error = KErrNotReady;
831 error = SetGainAndBalance(ETrue, dummy);
833 DP0_RET(error, "%d");
836 // -----------------------------------------------------------------------------
837 // CDevAudio::SetGainAndBalance
838 // -----------------------------------------------------------------------------
840 TInt CDevAudio::SetGainAndBalance(TBool aBecomingActive, TBool& aAsyncComplete)
842 DP_CONTEXT(CDevAudio::SetGainAndBalance *CD1*, CtxDevSound, DPLOCAL);
845 TInt error = KErrNone;
846 aAsyncComplete = EFalse; // let's assume this - makes logic easier below
847 // Apply cached settings.
848 // If aBecomingActive is true it indicates this call is doing before the MAudioStream::Activate() transition,
849 // so if required will apply volume ramp and won't itself generate a Commit() call.
850 // Otherwise, when Active, the calls made here will generate a Commit()
851 // and aAsyncComplete is returned true unless the SetGain() call fails
852 if (aBecomingActive || iActiveState == EDevSoundAdaptorActive_Active)
854 if (iCurrentAudioControl==iDevRecordControl)
856 // TODO assumes we are not mid Commit cycle
857 // we are recing, need to change current volume at A3F layer
858 error = iCurrentAudioControl->SetGains(iDevSoundGain, iDevSoundMaxGain, iDevSoundRecordBalance, 0, aBecomingActive);
861 aAsyncComplete = ETrue;
864 else if (iCurrentAudioControl==iDevPlayControl || iCurrentAudioControl==iDevToneControl)
866 // TODO assumes we are not mid Commit cycle
867 // we are playing, need to change current volume at A3F layer
868 error = iCurrentAudioControl->SetGains(iDevSoundVolume, iDevSoundMaxVolume, iDevSoundPlayBalance, iRampDuration, aBecomingActive);
871 aAsyncComplete = ETrue;
878 DP0_RET(error, "%d");
881 // -----------------------------------------------------------------------------
882 // CDevAudio::GetDevSoundPlayBalance
883 // -----------------------------------------------------------------------------
885 void CDevAudio::GetDevSoundPlayBalance(TInt& aLeftBalance, TInt& aRightBalance)
887 DP_CONTEXT(CDevAudio::GetDevSoundPlayBalance *CD1*, CtxDevSound, DPLOCAL);
889 aLeftBalance = iDevSoundPlayBalance[KLeftChannel];
890 aRightBalance = iDevSoundPlayBalance[KRightChannel];
895 // -----------------------------------------------------------------------------
896 // CDevAudio::GetDevSoundRecordBalance
897 // -----------------------------------------------------------------------------
899 void CDevAudio::GetDevSoundRecordBalance(TInt& aLeftBalance, TInt& aRightBalance)
901 DP_CONTEXT(CDevAudio::GetDevSoundRecordBalance *CD1*, CtxDevSound, DPLOCAL);
903 aLeftBalance = iDevSoundRecordBalance[KLeftChannel];
904 aRightBalance = iDevSoundRecordBalance[KRightChannel];
908 // -----------------------------------------------------------------------------
909 // CDevAudio::DevSoundSupportedDataTypesL
910 // -----------------------------------------------------------------------------
912 void CDevAudio::DevSoundSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes, TUint aDataType)
914 DP_CONTEXT(CDevAudio::DevSoundSupportedDataTypesL *CD1*, CtxDevSound, DPLOCAL);
917 //Clear any existing data
918 aSupportedDataTypes.Reset();
920 if(aDataType == KDataForPlay)
922 ConvertToFourCcL(aSupportedDataTypes, iSupportedInputFormats);
924 else if(aDataType == KDataForRecord)
926 ConvertToFourCcL(aSupportedDataTypes, iSupportedOutputFormats);
932 // -----------------------------------------------------------------------------
933 // CDevAudio::ConvertToFourCcL
934 // -----------------------------------------------------------------------------
936 void CDevAudio::ConvertToFourCcL(RArray<TFourCC>& aSupportedDataTypes, RArray<TUid>& aSupportedFormats)
938 DP_CONTEXT(CDevAudio::ConvertToFourCcL *CD1*, CtxDevSound, DPLOCAL);
941 if(aSupportedFormats.Count() > 0)
945 for(TInt element=0; element<aSupportedFormats.Count(); element++)
947 User::LeaveIfError(const_cast<CFourCCConvertor&>(iGlobalProperties->GetFourCCConvertor()).FormatToFourCC(aSupportedFormats[element],fourCC));
948 aSupportedDataTypes.AppendL(fourCC);
955 // -----------------------------------------------------------------------------
956 // CDevAudio::CreateAudioProcessingUnits
957 // -----------------------------------------------------------------------------
959 TInt CDevAudio::CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec)
961 DP_CONTEXT(CDevAudio::CreateAudioProcessingUnits *CD1*, CtxDevSound, DPLOCAL);
963 TInt err = iAudioContext->CreateAudioProcessingUnit(aSource, iAudioSource);
966 DP0_RET(err,"Audio source creation failed!");
968 err = iAudioContext->CreateAudioProcessingUnit(aSink, iAudioSink);
971 DP0_RET(err,"Audio sink creation failed!");
973 err = iAudioContext->CreateAudioProcessingUnit(aCodec, iAudioCodec);
976 DP0_RET(err,"Audio codec creation failed!");
982 // -----------------------------------------------------------------------------
983 // CDevAudio::DeleteAudioProcessingUnits
984 // -----------------------------------------------------------------------------
986 void CDevAudio::DeleteAudioProcessingUnits()
988 DP_CONTEXT(CDevAudio::DeleteAudioProcessingUnits *CD1*, CtxDevSound, DPLOCAL);
992 iAudioContext->DeleteAudioProcessingUnit(iAudioSource);
997 iAudioContext->DeleteAudioProcessingUnit(iAudioSink);
1002 iAudioContext->DeleteAudioProcessingUnit(iAudioCodec);
1008 TInt CDevAudio::CommitAudioContext()
1010 DP_CONTEXT(CDevAudio::CommitAudioContext *CD1*, CtxDevSound, DPLOCAL);
1013 //If we are in mid state then Panic as DevSound server-side session (CMMFDevSoundSession) is not blocking properly
1014 __ASSERT_DEBUG(!IsMidState(iActiveState), Panic(EValidStateBeforeCommit));
1016 TInt err = KErrNone;
1017 iPreviousState = iActiveState;
1018 err = iAudioContext->Commit();
1023 TBool CDevAudio::IsMidState(TDevSoundAdaptorState aAdaptorState)
1025 DP_CONTEXT(CDevAudio::IsMidState *CD1*, CtxDevSound, DPLOCAL);
1027 if (aAdaptorState == EDevSoundAdaptorRemovingProcessingUnits || aAdaptorState == EDevSoundAdaptorUninitialising ||
1028 aAdaptorState == EDevSoundAdaptorInitialising || aAdaptorState == EDevSoundAdaptorLoading ||
1029 aAdaptorState == EDevSoundAdaptorUnloading || aAdaptorState == EDevSoundAdaptorStopping ||
1030 aAdaptorState == EDevSoundAdaptorActivating || aAdaptorState == EDevSoundAdaptorPausing)
1032 DP0_RET(ETrue,"%d");
1034 DP0_RET(EFalse,"%d");
1037 // -----------------------------------------------------------------------------
1038 // From MA3FDevSoundAutoPauseResume
1039 // CDevAudio::RegisterAsClient
1040 // -----------------------------------------------------------------------------
1042 TInt CDevAudio::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
1044 DP_CONTEXT(CDevAudio::RegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
1046 TInt err = KErrNotSupported;
1047 MA3FDevSoundAutoPauseResume* iAPR = static_cast<MA3FDevSoundAutoPauseResume*>(iAudioContext->Interface(KUIdAudioResourceNotification));
1050 err = iAPR->RegisterAsClient(aEventType, aNotificationRegistrationData, this);
1056 // -----------------------------------------------------------------------------
1057 // CDevAudio::CancelRegisterAsClient
1058 // -----------------------------------------------------------------------------
1060 TInt CDevAudio::CancelRegisterAsClient(TUid aEventType)
1062 DP_CONTEXT(CDevAudio::CancelRegisterAsClient *CD1*, CtxDevSound, DPLOCAL);
1064 TInt err = KErrNotSupported;
1065 MA3FDevSoundAutoPauseResume* iAPR = static_cast<MA3FDevSoundAutoPauseResume*>(iAudioContext->Interface(KUIdAudioResourceNotification));
1068 err = iAPR->CancelRegisterAsClient(aEventType);
1074 // -----------------------------------------------------------------------------
1075 // CDevAudio::WillResumePlay
1076 // -----------------------------------------------------------------------------
1078 TInt CDevAudio::WillResumePlay()
1080 DP_CONTEXT(CDevAudio::WillResumePlay *CD1*, CtxDevSound, DPLOCAL);
1082 TInt err = KErrNotSupported;
1083 MA3FDevSoundAutoPauseResume* iAPR = static_cast<MA3FDevSoundAutoPauseResume*>(iAudioContext->Interface(KUIdAudioResourceNotification));
1086 err = iAPR->WillResumePlay();
1092 // -----------------------------------------------------------------------------
1093 // CDevAudio::NotifyResume
1094 // -----------------------------------------------------------------------------
1096 void CDevAudio::NotifyResume()
1098 DP_CONTEXT(CDevAudio::NotifyResume *CD1*, CtxDevSound, DPLOCAL);
1100 iAdaptationObserver.CallbackFromAdaptorReceived(KCallbackAutoPauseResume, KErrNone);
1104 void CDevAudio::Panic(TMMFDevAudioPanicCodes aCode)
1106 User::Panic(KMMFDevAudioPanicCategory, aCode);