1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/a3fdevsound/src/devsoundadaptor/cdevaudiocontrol.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,444 @@
1.4 +/*
1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +
1.24 +#ifndef CDEVAUDIOCONTROL_H
1.25 +#define CDEVAUDIOCONTROL_H
1.26 +
1.27 +#include <e32base.h>
1.28 +
1.29 +#include "cdevaudio.h"
1.30 +
1.31 +#include <a3f/maudiostreamobserver.h>
1.32 +#include <a3f/maudiocodecobserver.h>
1.33 +#include <a3f/maudiogaincontrolobserver.h>
1.34 +#include <a3f/msynccisupport.h>
1.35 +#include <a3f/a3f_trace_utils.h>
1.36 +
1.37 +
1.38 +class MAudioCodec;
1.39 +class MAudioGainControl;
1.40 +
1.41 +/**
1.42 +* Panic category and codes that DevSoundAdaptor raises on the client
1.43 +*/
1.44 +enum TDevSoundAdaptorPanicCode
1.45 + {
1.46 + ECommitFailedDuringStop = 1,
1.47 + ECommitFailedDuringPause,
1.48 + EStreamBeingDemotedToEIdle,
1.49 + EAudioCodecIsNull,
1.50 + EStreamMismatch,
1.51 + EBufferMismatch,
1.52 + EInvalidStateDuringPreemptionCycle
1.53 + };
1.54 +
1.55 +
1.56 +/**
1.57 + * CDevAudioControl.
1.58 + *
1.59 + * ?description
1.60 + *
1.61 + * @lib mmfdevsoundadaptation.lib
1.62 + * @since
1.63 + */
1.64 +NONSHARABLE_CLASS(CDevAudioControl) : public CBase,
1.65 + public MAudioStreamObserver,
1.66 + public MAudioGainControlObserver,
1.67 + public MAudioContextObserver,
1.68 + public MCustomInterfaceSupportObserver,
1.69 + public MAudioCodecObserver
1.70 + {
1.71 +
1.72 +public:
1.73 +
1.74 + enum TStereoCh
1.75 + {
1.76 + ELeftCh=0,
1.77 + ERightCh=1
1.78 + };
1.79 +
1.80 + ~CDevAudioControl();
1.81 +
1.82 + /**
1.83 + * Initialize wanted state control components
1.84 + * @since
1.85 + * @return error code
1.86 + */
1.87 + virtual TInt Initialize(TUid aFormat);
1.88 +
1.89 + /**
1.90 + * Uninitialize wanted state control components
1.91 + * @since
1.92 + * @return error code
1.93 + */
1.94 + virtual TInt Uninitialize();
1.95 +
1.96 + /**
1.97 + * Remove any processing unit
1.98 + * @since
1.99 + * @return error code
1.100 + */
1.101 + virtual TInt RemoveProcessingUnits();
1.102 +
1.103 + /**
1.104 + * Returns the supported Audio settings ie. encoding, sample rates,
1.105 + * mono/stereo operation, buffer size etc..
1.106 + * @since
1.107 + * @param aCaps on return, contains supported capabilities
1.108 + * @return error code
1.109 + */
1.110 + TInt GetCapabilities(TMMFCapabilities& aCap);
1.111 +
1.112 + /**
1.113 + * Returns the current device configuration.
1.114 + * @since
1.115 + * @param aConfig on return, contains device settings.
1.116 + * @return error code
1.117 + */
1.118 + TInt GetConfig(TMMFCapabilities& aConfig);
1.119 +
1.120 + /**
1.121 + * Configure CMMFDevSound object with the settings in aConfig. Use this
1.122 + * to set sampling rate, encoding and mono/stereo.
1.123 + * Leaves on failure.
1.124 + * @since
1.125 + * @param const TMMFCapabilities& aConfig The attribute values to which
1.126 + * CMMFDevSound object will be configured to.
1.127 + * @return error code
1.128 + */
1.129 + TInt SetConfig(const TMMFCapabilities& aCaps);
1.130 +
1.131 + /**
1.132 + * Initializes and starts the wanted operation (Play, Record, TonePlay).
1.133 + * @since
1.134 + * @return error code
1.135 + */
1.136 + virtual TInt ProcessInit();
1.137 +
1.138 + /**
1.139 + * Processes the data (PlayData, RecordData).
1.140 + * @since
1.141 + * @return void
1.142 + */
1.143 + virtual void ProcessData();
1.144 +
1.145 + /**
1.146 + * Stops the ongoing operation (Play, Record, TonePlay).
1.147 + * @since
1.148 + * @return void
1.149 + */
1.150 + virtual TInt Stop();
1.151 +
1.152 + /**
1.153 + * Temporarily Stops the ongoing operation (Play, Record, TonePlay).
1.154 + * @since
1.155 + * @return void
1.156 + */
1.157 + virtual TInt Pause();
1.158 +
1.159 + /**
1.160 + * Returns the samples played/recorded so far
1.161 + * @since
1.162 + * @return TInt Returns the samples played/recorded.
1.163 + */
1.164 + virtual TInt GetSamples();
1.165 +
1.166 + /**
1.167 + * Retrieves a custom interface to the device.
1.168 + * @since
1.169 + * @param TUid aInterfaceId The interface UID, defined with the custom
1.170 + * interface.
1.171 + * @return TAny* A pointer to the interface implementation, or NULL if
1.172 + * the device does not implement the interface requested. The
1.173 + * return value must be cast to the correct type by the user.
1.174 + */
1.175 + virtual TAny* CustomInterface(TUid aInterfaceId);
1.176 +
1.177 + /**
1.178 + * Apply gains, balance. Scale gain to underlying (a3f) max gain.
1.179 + * Assumed to be in active state. When called for SetVolume() etc call on higher-level
1.180 + * aCommit should be ETrue, and will call Commit() if derived result is KErrNone.
1.181 + * @param aDevSoundGain the DevSound gain to be applied
1.182 + * @param aDevSoundMaxGain the cached A3F Max Gain to be used as boundary
1.183 + * @param aBalance the balance value to be applied
1.184 + * @param const TTimeIntervalMicroSeconds &aRampDuration The period over
1.185 + * which the volume is to rise. A zero value causes the
1.186 + * sample to be played at the normal level for the full duration
1.187 + * of the playback. A value, which is longer than the duration of
1.188 + * the overall clip means that the sample never reaches its normal
1.189 + * volume level.
1.190 + * @param aBecomingActive indicates if DevSoundAdaptor is becoming active
1.191 + * which is needed to avoid if a commit here could clash with the one that is going to activate the stream
1.192 +
1.193 + * @return error code
1.194 + */
1.195 + TInt SetGains(TInt aDevSoundGain, TInt aDevSoundMaxGain, TInt aBalance[2], const TTimeIntervalMicroSeconds& aRampDuration, TBool aBecomingActive);
1.196 +
1.197 + /**
1.198 + * Maps "legacy" volume/gain values to CAP channel array
1.199 + * @since
1.200 + */
1.201 + void MapGains();
1.202 +
1.203 + /**
1.204 + * Destroy logical chain
1.205 + * @since
1.206 + * @
1.207 + */
1.208 + TBool DestroyChain();
1.209 +
1.210 + // From base class MAudioStreamObserver
1.211 +
1.212 + /**
1.213 + * Handles audio stream state change event.
1.214 + */
1.215 + virtual void StateEvent(MAudioStream& aStream, TInt aReason, TAudioState aNewState);
1.216 +
1.217 + /**
1.218 + * Notifies that adding of processing unit to the stream has been completed
1.219 + * successfully or otherwise.
1.220 + */
1.221 + virtual void AddProcessingUnitComplete(MAudioStream& aStream, MAudioProcessingUnit* aInstance, TInt aError);
1.222 +
1.223 + /**
1.224 + * Notifies that removing of processing unit from the stream has been completed
1.225 + * successfully or otherwise.
1.226 + */
1.227 + virtual void RemoveProcessingUnitComplete(MAudioStream& aStream, MAudioProcessingUnit* aInstance, TInt aError);
1.228 +
1.229 + /*
1.230 + Call-back indicating that is the last buffer has been processed by the sink.
1.231 + */
1.232 + virtual void ProcessingFinished (MAudioStream & aStream);
1.233 +
1.234 + /**
1.235 + * Signals completion of a Flush() operation.
1.236 + */
1.237 + virtual void FlushComplete (MAudioStream& aStream, TInt aError);
1.238 +
1.239 + // From base class MAudioGainControlObserver
1.240 +
1.241 + /**
1.242 + * Notifies the observer that the max ramp time supported by the stream, has changed.
1.243 + *
1.244 + * @since
1.245 + * @param aStream a reference to the stream whose max ramp time changed.
1.246 + */
1.247 + virtual void MaxRampTimeChanged(MAudioGainControl& aGain);
1.248 +
1.249 + /**
1.250 + * Notifies the observer that the maximum gain value supported by the stream has changed.
1.251 + *
1.252 + * @since
1.253 + * @param aStream a reference to the stream whose supported con
1.254 + */
1.255 + virtual void MaxGainChanged(MAudioGainControl& aGain);
1.256 +
1.257 + /**
1.258 + * Notifies the observer that the stream gain has changes, due to request from the client
1.259 + * or otherwise.
1.260 + *
1.261 + * If gain change by the client cannot be fulfilled, a gain change with an error code
1.262 + * other than KErrNone will be issued.
1.263 + *
1.264 + * @since
1.265 + * @param aStream a reference to the stream whose gain has changed.
1.266 + * @param aStream an error code. KErrNone if the gain change was requested by the client
1.267 + * and was completed successfully.
1.268 + */
1.269 + virtual void GainChanged(MAudioGainControl& aGain, TInt aError);
1.270 +
1.271 + /**
1.272 + * Saves tonedata for later use
1.273 + * This includes information about tone type, data, length, etc.
1.274 + *
1.275 + * @since
1.276 + * @param aToneData
1.277 + * @return error code
1.278 + */
1.279 + virtual TInt SetToneData(TToneData& aToneData);
1.280 +
1.281 + // From base class MAudioContextObserver
1.282 + /**
1.283 + * Callback to context observer to show progression through Commit() and pre-emption cycles
1.284 + *
1.285 + * @param aEvent a Uid giving the specific event.
1.286 + * @param aError an error code. KErrNone if successful, otherwise one of the system wide error codes.
1.287 + */
1.288 + virtual void ContextEvent(TUid aEvent, TInt aError);
1.289 +
1.290 + // from MCustomInterfaceSupportObserver
1.291 + virtual void CustomInterfaceRemoval(TUid, TAny* aPtr);
1.292 +
1.293 + //From MAudioCodecObserver
1.294 +
1.295 + virtual void SampleRateSet(TInt aError);
1.296 +
1.297 + virtual void ModeSet(TInt aError);
1.298 +
1.299 + virtual void GetSupportedSampleRatesComplete (TInt aError);
1.300 +
1.301 + virtual void GetSupportedModesComplete (TInt aError);
1.302 +
1.303 + /**
1.304 + * Called when a ProcessingFinished callback is received
1.305 + *
1.306 + * @since
1.307 + * @param TBool& aAyncCompletion
1.308 + * @return an error code KErrNone if successful
1.309 + */
1.310 + virtual TInt ProcessingFinishedReceived(TBool& aAyncCompletion);
1.311 +
1.312 + virtual TInt ProcessingError(TBool& aAyncCompletion);
1.313 +
1.314 + /**
1.315 + * EmptyBuffers using A3F::Flush
1.316 + *
1.317 + * @since
1.318 + * @return an error code. KErrNone if successful
1.319 + * KErrNotReady if not playing or paused
1.320 + * KErrNotSupported if the operation is not supported
1.321 + */
1.322 + virtual TInt RequestEmptyBuffers();
1.323 +
1.324 + /**
1.325 + * Gets the current play time from the audio renderer
1.326 + * @since
1.327 + * @param TTimeIntervalMicroSeconds& aTime On return contains the current play time
1.328 + * @return an error code KErrNone if successful
1.329 + */
1.330 + virtual TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTime);
1.331 +
1.332 + /**
1.333 + * Resume the operation (Play, Record, TonePlay) temporarily paused .
1.334 + * @since
1.335 + * @return TInt KErrNone if succesful
1.336 + * KErrNotSupported if the operation is not supported by this implementation
1.337 + */
1.338 + virtual TInt Resume();
1.339 +
1.340 + /*
1.341 + Used to send a stop call when there is a error in the buffer
1.342 + */
1.343 + virtual void BufferErrorEvent();
1.344 +
1.345 +protected:
1.346 +
1.347 + CDevAudioControl();
1.348 +
1.349 + void ConstructL(CDevAudio* aDevAudio, MDevSoundAdaptationObserver& aDevSoundObserver);
1.350 +
1.351 + // Ensure iAudioCodecIf is setup properly
1.352 + TInt CacheAudioCodecIf();
1.353 +
1.354 + /**
1.355 + * Returns to initialized state wanted control components
1.356 + * @since
1.357 + * @return error code
1.358 + */
1.359 + TInt Unload();
1.360 +
1.361 +
1.362 + /**
1.363 + * Panic the thread
1.364 + * @since
1.365 + * @param panic code
1.366 + */
1.367 + void Panic(TDevSoundAdaptorPanicCode aCode);
1.368 +
1.369 +private:
1.370 + TInt ResolveMode(TUint aMode, TUid& aModeValue);
1.371 + TInt ResolveSampleRate(TInt aSampleRate, TInt& aSampleRateValue);
1.372 + TUint GetModes(const RArray<TUid>& aMode);
1.373 + TUint GetMode(TUid aMode);
1.374 + TUint GetSampleRates(const RArray<TInt>& aSampleRates);
1.375 + TUint GetSampleRate(TInt aSampleRates);
1.376 + void CompleteMessageCap(TInt aError);
1.377 +
1.378 +/**
1.379 + * Member data is protected for subclass access
1.380 + */
1.381 +protected: // data
1.382 +
1.383 + // Not own
1.384 + CDevAudio *iDevAudio;
1.385 +
1.386 + /**
1.387 + * Pointer to audio codec
1.388 + * Not own.
1.389 + */
1.390 + MAudioCodec* iAudioCodecIf;
1.391 +
1.392 + /**
1.393 + * Pointer to audio gain control
1.394 + * Not own.
1.395 + */
1.396 + MAudioGainControl* iGainControl;
1.397 +
1.398 + /**
1.399 + * Observer for callbacks to DevSound Framework
1.400 + * Not own.
1.401 + */
1.402 + MDevSoundAdaptationObserver *iAdaptationObserver;
1.403 +
1.404 +
1.405 + /*
1.406 + * TODO: Review if this for buffer exchange
1.407 + */
1.408 + CMMFBuffer* iBuffer;
1.409 +
1.410 + /**
1.411 + * Local cache of volume stuff
1.412 + */
1.413 + TInt iLegacyGain;
1.414 + TInt iLegacyLeft;
1.415 + TInt iLegacyRight;
1.416 +
1.417 + TInt iError;
1.418 + TBool iGainUpdateNeeded;
1.419 + TBool iStateEventReceived;
1.420 + TInt iStateEventError;
1.421 + TInt iCallbackFromAdaptor;
1.422 + TInt iProcessingUnitError;
1.423 +
1.424 + TInt iErrorCondition;
1.425 +
1.426 + TBool iObserverRegistered;
1.427 +
1.428 + //Indicates whether the AsyncOperationComplete callback needs to be made during Preemption
1.429 + TBool iIgnoreAsyncOpComplete;
1.430 +
1.431 + TBool iPauseResumeSequenceDueToEmptyBuffers;
1.432 +
1.433 +private:
1.434 +
1.435 + RArray<TAudioChannelGain> iChannelGains;
1.436 +
1.437 + RArray<TUid> iSupportedModes;
1.438 + RArray<TInt> iSupportedRates;
1.439 + TInt iDesiredSampleRate;
1.440 + TUid iDesiredMode;
1.441 + TInt iCurrentSampleRate;
1.442 + TUid iCurrentMode;
1.443 + TInt iOutstandingCallbacks;
1.444 +
1.445 + };
1.446 +
1.447 +#endif // CDEVAUDIOCONTROL_H