Update contrib.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
25 #include "mmfdevsoundadaptationbody.h"
26 #include <a3f/maudiocontextobserver.h>
27 #include <a3f/maudiostreamobserver.h>
28 #include "mdevsoundadaptationinfoobserver.h"
30 #include <a3f/a3f_trace_utils.h>
31 #include <a3f/a3fdevsoundaudiopauseresume.h>
35 class CDevAudioControl;
36 class CDevPlayControl;
37 class CDevRecordControl;
38 class CDevToneControl;
40 class CAudioContextFactory;
41 class CA3FDevSoundAdaptationInfo;
44 class MGlobalProperties;
47 Panic category and codes that CDevAudio raises on the client
49 _LIT(KMMFDevAudioPanicCategory, "CDevAudio");
51 enum TMMFDevAudioPanicCodes
53 EValidStateBeforeCommit =1
56 enum TDevSoundAdaptorState
58 EDevSoundAdaptorCreated_Uninitialised,
59 EDevSoundAdaptorRemovingProcessingUnits,
60 EDevSoundAdaptorUnitialised_Uninitialised,
61 EDevSoundAdaptorUninitialising,
62 EDevSoundAdaptorInitialising,
63 EDevSoundAdaptorInitialised_Initialised,
64 EDevSoundAdaptorLoading,
65 EDevSoundAdaptorUnloading,
66 EDevSoundAdaptorInitialised_Idle,
67 EDevSoundAdaptorGoingActive,
68 EDevSoundAdaptorPreempted,
69 EDevSoundAdaptorBeingPreempted,
70 EDevSoundAdaptorStopping,
71 EDevSoundAdaptorActivating,
72 EDevSoundAdaptorActive_Active,
73 EDevSoundAdaptorPausing,
74 EDevSoundAdaptorPaused_Primed
82 * @lib mmfdevsoundadaptation.lib
85 NONSHARABLE_CLASS(CDevAudio) : public CBase,
86 public MAudioContextObserver,
87 public MA3FDevSoundAdaptationInfoObserver,
88 public MA3FDevSoundAutoPauseResumeObserver
90 friend class CDevAudioControl;
91 friend class CDevPlayControl;
92 friend class CDevRecordControl;
93 friend class CDevToneControl;
94 friend class CDevGenControl;
95 friend class CDevCommonControl;
101 static CDevAudio* NewL(MDevSoundAdaptationObserver& aDevSoundObserver,
102 MGlobalProperties& aGlobalProperties);
104 void ConstructL(MGlobalProperties& aGlobalProperties);
106 // 2nd phase async construct - will callback to aDevSoundObserver
110 * Sets control operating mode (playing/recording...)
112 * @param aMode new control mode
113 * @param aFormat codec format
116 TInt Initialize(TUid aFormat, TMMFState aMode);
119 * Cancels Initialization
123 TInt CancelInitialize();
126 * Returns pointer to audio control instance for current operating mode
128 * @param aAudioControl on return, contains pointer to audio control
131 CDevAudioControl* GetAudioControl();
134 * Defines the priority settings that should be used for this instance.
136 * @param const TMMFPrioritySettings &aPrioritySettings A class type
137 * representing the client's priority, priority preference and
141 TInt SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
144 * Sets client configuration
146 * @param aProcessId DevSound's client process
147 * @param aActualProcessId DevSound's effective/actual client (supplied by SetClientThreadInfo)
149 TInt SetClientConfig(const TProcessId& aProcessId);
150 TInt SetClientConfig(const TProcessId& aActualProcessId, const TProcessId& aProcessId);
154 * Retrieve the current A3F state
156 * @return the current A3F state. See TAudioState
158 TDevSoundAdaptorState ActiveState() const;
161 * Retrieve the previous DevSound adaptor state
164 TDevSoundAdaptorState PreviousState() const;
167 * Set the current DevSound adaptor state
170 void SetActiveState(TDevSoundAdaptorState aAdaptorState);
173 * Set the previous DevSound adaptor state
176 void SetPreviousState(TDevSoundAdaptorState aAdaptorState);
179 * SetVolume for DevSound
181 TInt SetDevSoundVolume(TInt aVolume, TBool& aAsyncCompletion);
184 * SetGain for DevSound
186 TInt SetDevSoundGain(TInt aGain, TBool& aAsyncCompletion);
189 * SetPlayBalance for DevSound
191 TInt SetDevSoundPlayBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion);
194 * SetPlayBalance for DevSound
196 TInt SetDevSoundRecordBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion);
199 * SetVolumeRamp for DevSound
201 TInt SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
204 * MaxVolume for DevSound
206 TInt DevSoundMaxVolume() const;
208 * MaxGain for DevSound
210 TInt DevSoundMaxGain() const;
214 TInt DevSoundVolume() const;
218 TInt DevSoundGain() const;
221 * GetPlayBalance for DevSound
223 void GetDevSoundPlayBalance(TInt& aLeftPercentage, TInt& aRightPercentage);
226 * GetRecordBalance for DevSound
228 void GetDevSoundRecordBalance(TInt& aLeftPercentage, TInt& aRightPercentage);
231 * GetSupportedDataTypes for DevSound
233 void DevSoundSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes, TUint aDataType);
236 * Call from control - generates appropriate SetGainAndBalance() call
238 TInt RequestGainAndBalance(CDevAudioControl* aCallingControl);
240 // From base class MAudioContextObserver
242 * Callback to context observer to show progression through Commit() and pre-emption cycles
244 * @param aEvent a Uid giving the specific event.
245 * @param aError an error code. KErrNone if successful, otherwise one of the system wide error codes.
247 virtual void ContextEvent(TUid aEvent, TInt aError);
249 // from MA3FDevSoundAdaptationInfoObserver
250 void RequestMaxGainComplete (TUid aCodecType, TInt aError, TInt aResult);
251 void RequestSupportedFormatsComplete(TUid aCodecType, TInt aError);
254 * Queries if the low layers does support resume operation.
256 * @return TBool ETrue if Resume is supported
259 TBool IsResumeSupported();
261 void ConvertToFourCcL(RArray<TFourCC>& aSupportedDataTypes, RArray<TUid>& iSupportedFormats);
263 //from MA3FDevSoundAutoPauseResume
264 TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData);
265 TInt CancelRegisterAsClient(TUid aEventType);
266 TInt WillResumePlay();
268 //from MA3FDevSoundAutoPauseResumeObserver
269 virtual void NotifyResume();
272 * GetPrioritySettings for DevSound
274 void GetPrioritySettings(TAudioTypeSettings& astorage);
276 TBool IsPrioritySet();
279 void Panic(TMMFDevAudioPanicCodes aCode);
283 CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver);
285 // If active, apply devsound volume and balance changes
286 TInt SetGainAndBalance(TBool aCallBack, TBool& aAsyncCompletion);
289 TInt CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec);
290 void DeleteAudioProcessingUnits();
292 TInt CommitAudioContext();
293 TBool IsMidState(TDevSoundAdaptorState aAdaptorState);
296 * most of member data is protected for DevAudioControl access
301 * adaptation observer - used to indicate async callbacks etc
303 MDevSoundAdaptationObserver& iAdaptationObserver;
306 * Pointer to audio context factory - context creation
309 CAudioContextFactory *iAudioContextFactory;
312 * Pointer to audio context.
315 MAudioContext *iAudioContext;
318 * Pointer to audio stream.
321 MAudioStream *iAudioStream;
324 * Pointer to audio source.
327 MAudioProcessingUnit* iAudioSource;
330 * Pointer to audio codec.
333 MAudioProcessingUnit* iAudioCodec;
336 * Pointer to audio gain control
339 MAudioProcessingUnit* iGainControl;
342 * Pointer to audio sink
345 MAudioProcessingUnit* iAudioSink;
348 * Mode to which this DevAudio is initialized in
355 * Active DevSound Adaptor state
357 TDevSoundAdaptorState iActiveState;
360 * Previous DevSound Adaptor state
362 TDevSoundAdaptorState iPreviousState;
364 TAudioState iActiveStreamState;
366 TBool iReinitializing;
370 TMMFState iTargetMode;
372 TInt iDevSoundMaxGain;
373 TInt iDevSoundMaxVolume;
375 TInt iDevSoundVolume;
376 TInt iDevSoundPlayBalance[2];
377 TInt iDevSoundRecordBalance[2];
378 TTimeIntervalMicroSeconds iRampDuration;
383 EPreOpenStateRequestingMaxVolume,
384 EPreOpenStateRequestingMaxGain,
385 EPreOpenStateRequestingInputFormats,
386 EPreOpenStateRequestingOutputFormats,
389 TPreOpenState iPreOpenState;
391 RArray<TUid> iSupportedInputFormats;
392 RArray<TUid> iSupportedOutputFormats;
394 CA3FDevSoundAdaptationInfo* iAdaptationInfo;
396 CDevPlayControl* iDevPlayControl;
397 CDevRecordControl* iDevRecordControl;
398 CDevToneControl* iDevToneControl;
399 CDevGenControl* iDevGenControl;
402 * Points to whichever control is active
405 CDevAudioControl* iCurrentAudioControl;
407 // Pointer to global properties
409 MGlobalProperties* iGlobalProperties;
411 TAudioTypeSettings iPrioritySettings;
416 inline TInt CDevAudio::DevSoundMaxVolume() const
418 return iDevSoundMaxVolume;
421 inline TInt CDevAudio::DevSoundMaxGain() const
423 return iDevSoundMaxGain;
426 inline TInt CDevAudio::DevSoundVolume() const
428 return iDevSoundVolume;
431 inline TInt CDevAudio::DevSoundGain() const
433 return iDevSoundGain;
436 #endif // CDEVAUDIO_H