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.
21 #ifndef CDEVAUDIOCONTROL_H
22 #define CDEVAUDIOCONTROL_H
26 #include "cdevaudio.h"
28 #include <a3f/maudiostreamobserver.h>
29 #include <a3f/maudiocodecobserver.h>
30 #include <a3f/maudiogaincontrolobserver.h>
31 #include <a3f/msynccisupport.h>
32 #include <a3f/a3f_trace_utils.h>
36 class MAudioGainControl;
39 * Panic category and codes that DevSoundAdaptor raises on the client
41 enum TDevSoundAdaptorPanicCode
43 ECommitFailedDuringStop = 1,
44 ECommitFailedDuringPause,
45 EStreamBeingDemotedToEIdle,
49 EInvalidStateDuringPreemptionCycle
58 * @lib mmfdevsoundadaptation.lib
61 NONSHARABLE_CLASS(CDevAudioControl) : public CBase,
62 public MAudioStreamObserver,
63 public MAudioGainControlObserver,
64 public MAudioContextObserver,
65 public MCustomInterfaceSupportObserver,
66 public MAudioCodecObserver
80 * Initialize wanted state control components
84 virtual TInt Initialize(TUid aFormat);
87 * Uninitialize wanted state control components
91 virtual TInt Uninitialize();
94 * Remove any processing unit
98 virtual TInt RemoveProcessingUnits();
101 * Returns the supported Audio settings ie. encoding, sample rates,
102 * mono/stereo operation, buffer size etc..
104 * @param aCaps on return, contains supported capabilities
107 TInt GetCapabilities(TMMFCapabilities& aCap);
110 * Returns the current device configuration.
112 * @param aConfig on return, contains device settings.
115 TInt GetConfig(TMMFCapabilities& aConfig);
118 * Configure CMMFDevSound object with the settings in aConfig. Use this
119 * to set sampling rate, encoding and mono/stereo.
122 * @param const TMMFCapabilities& aConfig The attribute values to which
123 * CMMFDevSound object will be configured to.
126 TInt SetConfig(const TMMFCapabilities& aCaps);
129 * Initializes and starts the wanted operation (Play, Record, TonePlay).
133 virtual TInt ProcessInit();
136 * Processes the data (PlayData, RecordData).
140 virtual void ProcessData();
143 * Stops the ongoing operation (Play, Record, TonePlay).
150 * Temporarily Stops the ongoing operation (Play, Record, TonePlay).
154 virtual TInt Pause();
157 * Returns the samples played/recorded so far
159 * @return TInt Returns the samples played/recorded.
161 virtual TInt GetSamples();
164 * Retrieves a custom interface to the device.
166 * @param TUid aInterfaceId The interface UID, defined with the custom
168 * @return TAny* A pointer to the interface implementation, or NULL if
169 * the device does not implement the interface requested. The
170 * return value must be cast to the correct type by the user.
172 virtual TAny* CustomInterface(TUid aInterfaceId);
175 * Apply gains, balance. Scale gain to underlying (a3f) max gain.
176 * Assumed to be in active state. When called for SetVolume() etc call on higher-level
177 * aCommit should be ETrue, and will call Commit() if derived result is KErrNone.
178 * @param aDevSoundGain the DevSound gain to be applied
179 * @param aDevSoundMaxGain the cached A3F Max Gain to be used as boundary
180 * @param aBalance the balance value to be applied
181 * @param const TTimeIntervalMicroSeconds &aRampDuration The period over
182 * which the volume is to rise. A zero value causes the
183 * sample to be played at the normal level for the full duration
184 * of the playback. A value, which is longer than the duration of
185 * the overall clip means that the sample never reaches its normal
187 * @param aBecomingActive indicates if DevSoundAdaptor is becoming active
188 * which is needed to avoid if a commit here could clash with the one that is going to activate the stream
192 TInt SetGains(TInt aDevSoundGain, TInt aDevSoundMaxGain, TInt aBalance[2], const TTimeIntervalMicroSeconds& aRampDuration, TBool aBecomingActive);
195 * Maps "legacy" volume/gain values to CAP channel array
201 * Destroy logical chain
205 TBool DestroyChain();
207 // From base class MAudioStreamObserver
210 * Handles audio stream state change event.
212 virtual void StateEvent(MAudioStream& aStream, TInt aReason, TAudioState aNewState);
215 * Notifies that adding of processing unit to the stream has been completed
216 * successfully or otherwise.
218 virtual void AddProcessingUnitComplete(MAudioStream& aStream, MAudioProcessingUnit* aInstance, TInt aError);
221 * Notifies that removing of processing unit from the stream has been completed
222 * successfully or otherwise.
224 virtual void RemoveProcessingUnitComplete(MAudioStream& aStream, MAudioProcessingUnit* aInstance, TInt aError);
227 Call-back indicating that is the last buffer has been processed by the sink.
229 virtual void ProcessingFinished (MAudioStream & aStream);
232 * Signals completion of a Flush() operation.
234 virtual void FlushComplete (MAudioStream& aStream, TInt aError);
236 // From base class MAudioGainControlObserver
239 * Notifies the observer that the max ramp time supported by the stream, has changed.
242 * @param aStream a reference to the stream whose max ramp time changed.
244 virtual void MaxRampTimeChanged(MAudioGainControl& aGain);
247 * Notifies the observer that the maximum gain value supported by the stream has changed.
250 * @param aStream a reference to the stream whose supported con
252 virtual void MaxGainChanged(MAudioGainControl& aGain);
255 * Notifies the observer that the stream gain has changes, due to request from the client
258 * If gain change by the client cannot be fulfilled, a gain change with an error code
259 * other than KErrNone will be issued.
262 * @param aStream a reference to the stream whose gain has changed.
263 * @param aStream an error code. KErrNone if the gain change was requested by the client
264 * and was completed successfully.
266 virtual void GainChanged(MAudioGainControl& aGain, TInt aError);
269 * Saves tonedata for later use
270 * This includes information about tone type, data, length, etc.
276 virtual TInt SetToneData(TToneData& aToneData);
278 // From base class MAudioContextObserver
280 * Callback to context observer to show progression through Commit() and pre-emption cycles
282 * @param aEvent a Uid giving the specific event.
283 * @param aError an error code. KErrNone if successful, otherwise one of the system wide error codes.
285 virtual void ContextEvent(TUid aEvent, TInt aError);
287 // from MCustomInterfaceSupportObserver
288 virtual void CustomInterfaceRemoval(TUid, TAny* aPtr);
290 //From MAudioCodecObserver
292 virtual void SampleRateSet(TInt aError);
294 virtual void ModeSet(TInt aError);
296 virtual void GetSupportedSampleRatesComplete (TInt aError);
298 virtual void GetSupportedModesComplete (TInt aError);
301 * Called when a ProcessingFinished callback is received
304 * @param TBool& aAyncCompletion
305 * @return an error code KErrNone if successful
307 virtual TInt ProcessingFinishedReceived(TBool& aAyncCompletion);
309 virtual TInt ProcessingError(TBool& aAyncCompletion);
312 * EmptyBuffers using A3F::Flush
315 * @return an error code. KErrNone if successful
316 * KErrNotReady if not playing or paused
317 * KErrNotSupported if the operation is not supported
319 virtual TInt RequestEmptyBuffers();
322 * Gets the current play time from the audio renderer
324 * @param TTimeIntervalMicroSeconds& aTime On return contains the current play time
325 * @return an error code KErrNone if successful
327 virtual TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTime);
330 * Resume the operation (Play, Record, TonePlay) temporarily paused .
332 * @return TInt KErrNone if succesful
333 * KErrNotSupported if the operation is not supported by this implementation
335 virtual TInt Resume();
338 Used to send a stop call when there is a error in the buffer
340 virtual void BufferErrorEvent();
346 void ConstructL(CDevAudio* aDevAudio, MDevSoundAdaptationObserver& aDevSoundObserver);
348 // Ensure iAudioCodecIf is setup properly
349 TInt CacheAudioCodecIf();
352 * Returns to initialized state wanted control components
364 void Panic(TDevSoundAdaptorPanicCode aCode);
367 TInt ResolveMode(TUint aMode, TUid& aModeValue);
368 TInt ResolveSampleRate(TInt aSampleRate, TInt& aSampleRateValue);
369 TUint GetModes(const RArray<TUid>& aMode);
370 TUint GetMode(TUid aMode);
371 TUint GetSampleRates(const RArray<TInt>& aSampleRates);
372 TUint GetSampleRate(TInt aSampleRates);
373 void CompleteMessageCap(TInt aError);
376 * Member data is protected for subclass access
381 CDevAudio *iDevAudio;
384 * Pointer to audio codec
387 MAudioCodec* iAudioCodecIf;
390 * Pointer to audio gain control
393 MAudioGainControl* iGainControl;
396 * Observer for callbacks to DevSound Framework
399 MDevSoundAdaptationObserver *iAdaptationObserver;
403 * TODO: Review if this for buffer exchange
408 * Local cache of volume stuff
415 TBool iGainUpdateNeeded;
416 TBool iStateEventReceived;
417 TInt iStateEventError;
418 TInt iCallbackFromAdaptor;
419 TInt iProcessingUnitError;
421 TInt iErrorCondition;
423 TBool iObserverRegistered;
425 //Indicates whether the AsyncOperationComplete callback needs to be made during Preemption
426 TBool iIgnoreAsyncOpComplete;
428 TBool iPauseResumeSequenceDueToEmptyBuffers;
432 RArray<TAudioChannelGain> iChannelGains;
434 RArray<TUid> iSupportedModes;
435 RArray<TInt> iSupportedRates;
436 TInt iDesiredSampleRate;
438 TInt iCurrentSampleRate;
440 TInt iOutstandingCallbacks;
444 #endif // CDEVAUDIOCONTROL_H