os/mm/devsound/a3fdevsound/src/devsoundadaptor/cdevaudiocontrol.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
sl@0
    21
#ifndef CDEVAUDIOCONTROL_H
sl@0
    22
#define CDEVAUDIOCONTROL_H
sl@0
    23
sl@0
    24
#include <e32base.h>
sl@0
    25
sl@0
    26
#include "cdevaudio.h"
sl@0
    27
sl@0
    28
#include <a3f/maudiostreamobserver.h>
sl@0
    29
#include <a3f/maudiocodecobserver.h>
sl@0
    30
#include <a3f/maudiogaincontrolobserver.h>
sl@0
    31
#include <a3f/msynccisupport.h>
sl@0
    32
#include <a3f/a3f_trace_utils.h>
sl@0
    33
sl@0
    34
sl@0
    35
class MAudioCodec;
sl@0
    36
class MAudioGainControl;
sl@0
    37
sl@0
    38
/**
sl@0
    39
*  Panic category and codes that DevSoundAdaptor raises on the client
sl@0
    40
*/
sl@0
    41
enum TDevSoundAdaptorPanicCode
sl@0
    42
	{
sl@0
    43
	ECommitFailedDuringStop = 1, 
sl@0
    44
	ECommitFailedDuringPause,
sl@0
    45
	EStreamBeingDemotedToEIdle,
sl@0
    46
	EAudioCodecIsNull,
sl@0
    47
	EStreamMismatch,
sl@0
    48
	EBufferMismatch,
sl@0
    49
	EInvalidStateDuringPreemptionCycle
sl@0
    50
	};
sl@0
    51
sl@0
    52
sl@0
    53
/**
sl@0
    54
 * CDevAudioControl.
sl@0
    55
 *
sl@0
    56
 * ?description
sl@0
    57
 *
sl@0
    58
 * @lib mmfdevsoundadaptation.lib
sl@0
    59
 * @since
sl@0
    60
 */
sl@0
    61
NONSHARABLE_CLASS(CDevAudioControl) :	public CBase,
sl@0
    62
										public MAudioStreamObserver,
sl@0
    63
										public MAudioGainControlObserver,
sl@0
    64
										public MAudioContextObserver,
sl@0
    65
										public MCustomInterfaceSupportObserver,
sl@0
    66
										public MAudioCodecObserver
sl@0
    67
	{
sl@0
    68
sl@0
    69
public:
sl@0
    70
sl@0
    71
	enum TStereoCh
sl@0
    72
		{
sl@0
    73
		ELeftCh=0,
sl@0
    74
		ERightCh=1
sl@0
    75
		};
sl@0
    76
sl@0
    77
	~CDevAudioControl();
sl@0
    78
sl@0
    79
	/**
sl@0
    80
	* Initialize wanted state control components
sl@0
    81
	* @since
sl@0
    82
	* @return error code
sl@0
    83
	*/
sl@0
    84
	virtual TInt Initialize(TUid aFormat);
sl@0
    85
sl@0
    86
	/**
sl@0
    87
	* Uninitialize wanted state control components
sl@0
    88
	* @since
sl@0
    89
	* @return error code
sl@0
    90
	*/
sl@0
    91
	virtual TInt Uninitialize();
sl@0
    92
sl@0
    93
	/**
sl@0
    94
	* Remove any processing unit
sl@0
    95
	* @since
sl@0
    96
	* @return error code
sl@0
    97
	*/
sl@0
    98
	virtual TInt RemoveProcessingUnits();
sl@0
    99
sl@0
   100
	/**
sl@0
   101
	* Returns the supported Audio settings ie. encoding, sample rates,
sl@0
   102
	* mono/stereo operation, buffer size etc..
sl@0
   103
	* @since
sl@0
   104
	* @param aCaps on return, contains supported capabilities
sl@0
   105
	* @return error code
sl@0
   106
	*/
sl@0
   107
	TInt GetCapabilities(TMMFCapabilities& aCap);
sl@0
   108
sl@0
   109
	/**
sl@0
   110
	* Returns the current device configuration.
sl@0
   111
	* @since
sl@0
   112
	* @param aConfig on return, contains device settings.
sl@0
   113
	* @return error code
sl@0
   114
	*/
sl@0
   115
	TInt GetConfig(TMMFCapabilities& aConfig);
sl@0
   116
sl@0
   117
	/**
sl@0
   118
	* Configure CMMFDevSound object with the settings in aConfig. Use this
sl@0
   119
	* to set sampling rate, encoding and mono/stereo.
sl@0
   120
	* Leaves on failure.
sl@0
   121
	* @since
sl@0
   122
	* @param const TMMFCapabilities& aConfig The attribute values to which
sl@0
   123
	*        CMMFDevSound object will be configured to.
sl@0
   124
	* @return error code
sl@0
   125
	*/
sl@0
   126
	TInt SetConfig(const TMMFCapabilities& aCaps);
sl@0
   127
sl@0
   128
	/**
sl@0
   129
	* Initializes and starts the wanted operation (Play, Record, TonePlay).
sl@0
   130
	* @since
sl@0
   131
	* @return error code
sl@0
   132
	*/
sl@0
   133
	virtual TInt ProcessInit();
sl@0
   134
sl@0
   135
	/**
sl@0
   136
	* Processes the data (PlayData, RecordData).
sl@0
   137
	* @since
sl@0
   138
	* @return void
sl@0
   139
	*/
sl@0
   140
	virtual void ProcessData();
sl@0
   141
sl@0
   142
	/**
sl@0
   143
	* Stops the ongoing operation (Play, Record, TonePlay).
sl@0
   144
	* @since
sl@0
   145
	* @return void
sl@0
   146
	*/
sl@0
   147
	virtual TInt Stop();
sl@0
   148
sl@0
   149
	/**
sl@0
   150
	* Temporarily Stops the ongoing operation (Play, Record, TonePlay).
sl@0
   151
	* @since
sl@0
   152
	* @return void
sl@0
   153
	*/
sl@0
   154
	virtual TInt Pause();
sl@0
   155
sl@0
   156
	/**
sl@0
   157
	* Returns the samples played/recorded so far
sl@0
   158
	* @since
sl@0
   159
	* @return TInt Returns the samples played/recorded.
sl@0
   160
	*/
sl@0
   161
	virtual TInt GetSamples();
sl@0
   162
sl@0
   163
	/**
sl@0
   164
	* Retrieves a custom interface to the device.
sl@0
   165
	* @since
sl@0
   166
	* @param TUid aInterfaceId The interface UID, defined with the custom
sl@0
   167
	*        interface.
sl@0
   168
	* @return TAny* A pointer to the interface implementation, or NULL if
sl@0
   169
	*        the device does not implement the interface requested. The
sl@0
   170
	*        return value must be cast to the correct type by the user.
sl@0
   171
	*/
sl@0
   172
	virtual TAny* CustomInterface(TUid aInterfaceId);
sl@0
   173
sl@0
   174
	/**
sl@0
   175
	* Apply gains, balance. Scale gain to underlying (a3f) max gain.
sl@0
   176
	* Assumed to be in active state. When called for SetVolume() etc call on higher-level
sl@0
   177
	* aCommit should be ETrue, and will call Commit() if derived result is KErrNone.
sl@0
   178
	* @param aDevSoundGain the DevSound gain to be applied
sl@0
   179
	* @param aDevSoundMaxGain the cached A3F Max Gain to be used as boundary
sl@0
   180
	* @param aBalance the balance value to be applied
sl@0
   181
	* @param const TTimeIntervalMicroSeconds &aRampDuration The period over
sl@0
   182
	*        which the volume is to rise. A zero value causes the
sl@0
   183
	*        sample to be played at the normal level for the full duration
sl@0
   184
	*        of the playback. A value, which is longer than the duration of
sl@0
   185
	*        the overall clip means that the sample never reaches its normal
sl@0
   186
	*        volume level.
sl@0
   187
	* @param aBecomingActive indicates if DevSoundAdaptor is becoming active
sl@0
   188
	*        which is needed to avoid if a commit here could clash with the one that is going to activate the stream
sl@0
   189
sl@0
   190
	* @return error code
sl@0
   191
	*/
sl@0
   192
	TInt SetGains(TInt aDevSoundGain, TInt aDevSoundMaxGain, TInt aBalance[2], const TTimeIntervalMicroSeconds& aRampDuration, TBool aBecomingActive);
sl@0
   193
sl@0
   194
	/**
sl@0
   195
	* Maps "legacy" volume/gain values to CAP channel array
sl@0
   196
	* @since
sl@0
   197
	*/
sl@0
   198
	void MapGains();
sl@0
   199
sl@0
   200
	/**
sl@0
   201
	* Destroy logical chain
sl@0
   202
	* @since
sl@0
   203
	* @
sl@0
   204
	*/
sl@0
   205
	TBool DestroyChain();
sl@0
   206
sl@0
   207
	// From base class MAudioStreamObserver
sl@0
   208
sl@0
   209
	/**
sl@0
   210
	* Handles audio stream state change event.
sl@0
   211
	*/
sl@0
   212
	virtual void StateEvent(MAudioStream& aStream, TInt aReason, TAudioState aNewState);
sl@0
   213
sl@0
   214
	/**
sl@0
   215
	* Notifies that adding of processing unit to the stream has been completed
sl@0
   216
	* successfully or otherwise.
sl@0
   217
	*/
sl@0
   218
	virtual void AddProcessingUnitComplete(MAudioStream& aStream, MAudioProcessingUnit* aInstance, TInt aError);
sl@0
   219
sl@0
   220
	/**
sl@0
   221
	* Notifies that removing of processing unit from the stream has been completed
sl@0
   222
	* successfully or otherwise.
sl@0
   223
	*/
sl@0
   224
	virtual void RemoveProcessingUnitComplete(MAudioStream& aStream, MAudioProcessingUnit* aInstance, TInt aError);
sl@0
   225
sl@0
   226
	/*
sl@0
   227
	Call-back indicating that is the last buffer has been processed by the sink.
sl@0
   228
	*/
sl@0
   229
	virtual void ProcessingFinished (MAudioStream & aStream);
sl@0
   230
sl@0
   231
	/**
sl@0
   232
	* Signals completion of a Flush() operation.
sl@0
   233
	*/
sl@0
   234
	virtual void FlushComplete (MAudioStream& aStream, TInt aError);
sl@0
   235
sl@0
   236
	// From base class MAudioGainControlObserver
sl@0
   237
sl@0
   238
	/**
sl@0
   239
	* Notifies the observer that the max ramp time supported by the stream, has changed.
sl@0
   240
	*
sl@0
   241
	* @since
sl@0
   242
	* @param aStream a reference to the stream whose max ramp time changed.
sl@0
   243
	*/
sl@0
   244
	virtual void MaxRampTimeChanged(MAudioGainControl& aGain);
sl@0
   245
sl@0
   246
	/**
sl@0
   247
	* Notifies the observer that the maximum gain value supported by the stream has changed.
sl@0
   248
	*
sl@0
   249
	* @since
sl@0
   250
	* @param aStream a reference to the stream whose supported con
sl@0
   251
	*/
sl@0
   252
	virtual void MaxGainChanged(MAudioGainControl& aGain);
sl@0
   253
sl@0
   254
	/**
sl@0
   255
	* Notifies the observer that the stream gain has changes, due to request from the client
sl@0
   256
	* or otherwise.
sl@0
   257
	*
sl@0
   258
	* If gain change by the client cannot be fulfilled, a gain change with an error code
sl@0
   259
	* other than KErrNone will be issued.
sl@0
   260
	*
sl@0
   261
	* @since
sl@0
   262
	* @param aStream a reference to the stream whose gain has changed.
sl@0
   263
	* @param aStream an error code. KErrNone if the gain change was requested by the client
sl@0
   264
	*        and was completed successfully.
sl@0
   265
	*/
sl@0
   266
	virtual void GainChanged(MAudioGainControl& aGain, TInt aError);
sl@0
   267
sl@0
   268
	/**
sl@0
   269
	* Saves tonedata for later use
sl@0
   270
	* This includes information about tone type, data, length, etc.
sl@0
   271
	*
sl@0
   272
	* @since
sl@0
   273
	* @param aToneData
sl@0
   274
	* @return error code
sl@0
   275
	*/
sl@0
   276
	virtual TInt SetToneData(TToneData& aToneData);
sl@0
   277
sl@0
   278
	// From base class MAudioContextObserver
sl@0
   279
	/**
sl@0
   280
	* Callback to context observer to show progression through Commit() and pre-emption cycles
sl@0
   281
	*
sl@0
   282
	* @param aEvent  a Uid giving the specific event.
sl@0
   283
	* @param aError  an error code. KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   284
	*/
sl@0
   285
	virtual void ContextEvent(TUid aEvent, TInt aError);
sl@0
   286
sl@0
   287
	// from MCustomInterfaceSupportObserver
sl@0
   288
	virtual void CustomInterfaceRemoval(TUid, TAny* aPtr);
sl@0
   289
sl@0
   290
	//From MAudioCodecObserver
sl@0
   291
sl@0
   292
	virtual void SampleRateSet(TInt aError);
sl@0
   293
sl@0
   294
	virtual void ModeSet(TInt aError);
sl@0
   295
sl@0
   296
	virtual void GetSupportedSampleRatesComplete (TInt aError);
sl@0
   297
sl@0
   298
	virtual void GetSupportedModesComplete (TInt aError);
sl@0
   299
sl@0
   300
	/**
sl@0
   301
	* Called when a ProcessingFinished callback is received
sl@0
   302
	*
sl@0
   303
	* @since
sl@0
   304
	* @param TBool& aAyncCompletion
sl@0
   305
	* @return an error code KErrNone if successful
sl@0
   306
	*/
sl@0
   307
	virtual TInt ProcessingFinishedReceived(TBool& aAyncCompletion);
sl@0
   308
sl@0
   309
	virtual TInt ProcessingError(TBool& aAyncCompletion);
sl@0
   310
	
sl@0
   311
	/**
sl@0
   312
	* EmptyBuffers using A3F::Flush
sl@0
   313
	*
sl@0
   314
	* @since
sl@0
   315
	* @return an error code. KErrNone if successful
sl@0
   316
	*						KErrNotReady if not playing or paused
sl@0
   317
	*						KErrNotSupported if the operation is not supported
sl@0
   318
	*/
sl@0
   319
	virtual TInt RequestEmptyBuffers();
sl@0
   320
sl@0
   321
	/**
sl@0
   322
	* Gets the current play time from the audio renderer
sl@0
   323
	* @since 
sl@0
   324
	* @param TTimeIntervalMicroSeconds& aTime On return contains the current play time
sl@0
   325
	* @return an error code KErrNone if successful
sl@0
   326
	*/
sl@0
   327
	virtual TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTime);
sl@0
   328
sl@0
   329
	/**
sl@0
   330
	* Resume the operation (Play, Record, TonePlay) temporarily paused .
sl@0
   331
	* @since
sl@0
   332
	* @return TInt KErrNone if succesful
sl@0
   333
	*              KErrNotSupported if the operation is not supported by this implementation
sl@0
   334
	*/
sl@0
   335
	virtual TInt Resume();
sl@0
   336
sl@0
   337
	/*
sl@0
   338
	Used to send a stop call when there is a error in the buffer
sl@0
   339
	*/
sl@0
   340
	virtual void BufferErrorEvent();
sl@0
   341
	
sl@0
   342
protected:
sl@0
   343
sl@0
   344
	CDevAudioControl();
sl@0
   345
sl@0
   346
	void ConstructL(CDevAudio* aDevAudio, MDevSoundAdaptationObserver& aDevSoundObserver);
sl@0
   347
sl@0
   348
	// Ensure iAudioCodecIf is setup properly
sl@0
   349
	TInt CacheAudioCodecIf();
sl@0
   350
sl@0
   351
	/**
sl@0
   352
	* Returns to initialized state wanted control components
sl@0
   353
	* @since 
sl@0
   354
	* @return error code
sl@0
   355
	*/
sl@0
   356
	TInt Unload();
sl@0
   357
sl@0
   358
sl@0
   359
	/**
sl@0
   360
	* Panic the thread
sl@0
   361
	* @since 
sl@0
   362
	* @param panic code
sl@0
   363
	*/
sl@0
   364
	void Panic(TDevSoundAdaptorPanicCode aCode);
sl@0
   365
	
sl@0
   366
private:
sl@0
   367
	TInt ResolveMode(TUint aMode, TUid& aModeValue);
sl@0
   368
	TInt ResolveSampleRate(TInt aSampleRate, TInt& aSampleRateValue);
sl@0
   369
	TUint GetModes(const RArray<TUid>& aMode);
sl@0
   370
	TUint GetMode(TUid aMode);
sl@0
   371
	TUint GetSampleRates(const RArray<TInt>& aSampleRates);
sl@0
   372
	TUint GetSampleRate(TInt aSampleRates);
sl@0
   373
	void CompleteMessageCap(TInt aError);
sl@0
   374
sl@0
   375
/**
sl@0
   376
 * Member data is protected for subclass access
sl@0
   377
 */
sl@0
   378
protected: // data
sl@0
   379
sl@0
   380
	// Not own
sl@0
   381
	CDevAudio *iDevAudio;
sl@0
   382
sl@0
   383
	/**
sl@0
   384
	* Pointer to audio codec
sl@0
   385
	* Not own.
sl@0
   386
	*/
sl@0
   387
	MAudioCodec* iAudioCodecIf;
sl@0
   388
sl@0
   389
	/**
sl@0
   390
	* Pointer to audio gain control
sl@0
   391
	* Not own.
sl@0
   392
	*/
sl@0
   393
	MAudioGainControl* iGainControl;
sl@0
   394
sl@0
   395
	/**
sl@0
   396
	* Observer for callbacks to DevSound Framework
sl@0
   397
	* Not own.
sl@0
   398
	*/
sl@0
   399
	MDevSoundAdaptationObserver *iAdaptationObserver;
sl@0
   400
sl@0
   401
sl@0
   402
	/*
sl@0
   403
	* TODO: Review if this for buffer exchange
sl@0
   404
	*/
sl@0
   405
	CMMFBuffer* iBuffer;
sl@0
   406
sl@0
   407
	/**
sl@0
   408
	* Local cache of volume stuff
sl@0
   409
	*/
sl@0
   410
	TInt iLegacyGain;
sl@0
   411
	TInt iLegacyLeft;
sl@0
   412
	TInt iLegacyRight;
sl@0
   413
sl@0
   414
	TInt 	iError;
sl@0
   415
	TBool 	iGainUpdateNeeded;
sl@0
   416
	TBool	iStateEventReceived;
sl@0
   417
	TInt 	iStateEventError;
sl@0
   418
	TInt	iCallbackFromAdaptor;
sl@0
   419
	TInt 	iProcessingUnitError;
sl@0
   420
sl@0
   421
	TInt 	iErrorCondition;
sl@0
   422
	
sl@0
   423
	TBool	iObserverRegistered;
sl@0
   424
	
sl@0
   425
	//Indicates whether the AsyncOperationComplete callback needs to be made during Preemption
sl@0
   426
	TBool iIgnoreAsyncOpComplete;
sl@0
   427
sl@0
   428
	TBool	iPauseResumeSequenceDueToEmptyBuffers;
sl@0
   429
sl@0
   430
private:
sl@0
   431
sl@0
   432
	RArray<TAudioChannelGain>	iChannelGains;
sl@0
   433
sl@0
   434
	RArray<TUid>				iSupportedModes;
sl@0
   435
	RArray<TInt>				iSupportedRates;
sl@0
   436
	TInt						iDesiredSampleRate;
sl@0
   437
	TUid						iDesiredMode;
sl@0
   438
	TInt						iCurrentSampleRate;
sl@0
   439
	TUid						iCurrentMode;
sl@0
   440
	TInt						iOutstandingCallbacks;
sl@0
   441
sl@0
   442
	};
sl@0
   443
sl@0
   444
#endif // CDEVAUDIOCONTROL_H