os/mm/devsound/a3fdevsound/src/devsoundadaptor/cdevaudio.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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
#ifndef CDEVAUDIO_H
sl@0
    21
#define CDEVAUDIO_H
sl@0
    22
sl@0
    23
#include <e32base.h>
sl@0
    24
sl@0
    25
#include "mmfdevsoundadaptationbody.h"
sl@0
    26
#include <a3f/maudiocontextobserver.h>
sl@0
    27
#include <a3f/maudiostreamobserver.h>
sl@0
    28
#include "mdevsoundadaptationinfoobserver.h"
sl@0
    29
sl@0
    30
#include <a3f/a3f_trace_utils.h>
sl@0
    31
#include <a3f/a3fdevsoundaudiopauseresume.h>
sl@0
    32
sl@0
    33
sl@0
    34
// CLASS FORWARD
sl@0
    35
class CDevAudioControl;
sl@0
    36
class CDevPlayControl;
sl@0
    37
class CDevRecordControl;
sl@0
    38
class CDevToneControl;
sl@0
    39
class CDevGenControl;
sl@0
    40
class CAudioContextFactory;
sl@0
    41
class CA3FDevSoundAdaptationInfo;
sl@0
    42
class MAudioContext;
sl@0
    43
class MAudioStream;
sl@0
    44
class MGlobalProperties;
sl@0
    45
sl@0
    46
/**
sl@0
    47
Panic category and codes that CDevAudio raises on the client
sl@0
    48
*/
sl@0
    49
_LIT(KMMFDevAudioPanicCategory, "CDevAudio");
sl@0
    50
sl@0
    51
enum TMMFDevAudioPanicCodes
sl@0
    52
	{
sl@0
    53
	EValidStateBeforeCommit =1
sl@0
    54
	};
sl@0
    55
sl@0
    56
enum TDevSoundAdaptorState
sl@0
    57
	{
sl@0
    58
	EDevSoundAdaptorCreated_Uninitialised,
sl@0
    59
	EDevSoundAdaptorRemovingProcessingUnits,
sl@0
    60
	EDevSoundAdaptorUnitialised_Uninitialised,
sl@0
    61
	EDevSoundAdaptorUninitialising,
sl@0
    62
	EDevSoundAdaptorInitialising,
sl@0
    63
	EDevSoundAdaptorInitialised_Initialised,
sl@0
    64
	EDevSoundAdaptorLoading,
sl@0
    65
	EDevSoundAdaptorUnloading,
sl@0
    66
	EDevSoundAdaptorInitialised_Idle,
sl@0
    67
	EDevSoundAdaptorGoingActive,
sl@0
    68
	EDevSoundAdaptorPreempted,
sl@0
    69
	EDevSoundAdaptorBeingPreempted,
sl@0
    70
	EDevSoundAdaptorStopping,
sl@0
    71
	EDevSoundAdaptorActivating,
sl@0
    72
	EDevSoundAdaptorActive_Active,
sl@0
    73
	EDevSoundAdaptorPausing,
sl@0
    74
	EDevSoundAdaptorPaused_Primed
sl@0
    75
	};
sl@0
    76
sl@0
    77
/**
sl@0
    78
 * CDevAudio.
sl@0
    79
 *
sl@0
    80
 * ?description
sl@0
    81
 *
sl@0
    82
 * @lib mmfdevsoundadaptation.lib
sl@0
    83
 * @since
sl@0
    84
 */
sl@0
    85
NONSHARABLE_CLASS(CDevAudio) :	public CBase,
sl@0
    86
								public MAudioContextObserver,
sl@0
    87
								public MA3FDevSoundAdaptationInfoObserver,
sl@0
    88
								public MA3FDevSoundAutoPauseResumeObserver
sl@0
    89
	{
sl@0
    90
	friend class CDevAudioControl;
sl@0
    91
	friend class CDevPlayControl;
sl@0
    92
	friend class CDevRecordControl;
sl@0
    93
	friend class CDevToneControl;
sl@0
    94
    friend class CDevGenControl;
sl@0
    95
    friend class CDevCommonControl;
sl@0
    96
sl@0
    97
public:
sl@0
    98
sl@0
    99
	~CDevAudio();
sl@0
   100
sl@0
   101
	static CDevAudio* NewL(MDevSoundAdaptationObserver& aDevSoundObserver,
sl@0
   102
									MGlobalProperties& aGlobalProperties);
sl@0
   103
sl@0
   104
	void ConstructL(MGlobalProperties& aGlobalProperties);
sl@0
   105
sl@0
   106
	// 2nd phase async construct - will callback to aDevSoundObserver
sl@0
   107
	TInt PostOpen();
sl@0
   108
sl@0
   109
	/**
sl@0
   110
	* Sets control operating mode (playing/recording...)
sl@0
   111
	* @since
sl@0
   112
	* @param aMode new control mode
sl@0
   113
	* @param aFormat codec format
sl@0
   114
	* @return error code
sl@0
   115
	*/
sl@0
   116
	TInt Initialize(TUid aFormat, TMMFState aMode);
sl@0
   117
sl@0
   118
	/**
sl@0
   119
	* Cancels Initialization
sl@0
   120
	* @since
sl@0
   121
	* @return error code
sl@0
   122
	*/
sl@0
   123
	TInt CancelInitialize();
sl@0
   124
sl@0
   125
	/**
sl@0
   126
	* Returns pointer to audio control instance for current operating mode
sl@0
   127
	* @since
sl@0
   128
	* @param aAudioControl on return, contains pointer to audio control
sl@0
   129
	* @return error code
sl@0
   130
	*/
sl@0
   131
	CDevAudioControl* GetAudioControl();
sl@0
   132
sl@0
   133
	/**
sl@0
   134
	* Defines the priority settings that should be used for this instance.
sl@0
   135
	* @since
sl@0
   136
	* @param const TMMFPrioritySettings &aPrioritySettings A class type
sl@0
   137
	*        representing the client's priority, priority preference and
sl@0
   138
	*        state
sl@0
   139
	* @return Err
sl@0
   140
	*/
sl@0
   141
	TInt SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
sl@0
   142
sl@0
   143
	/**
sl@0
   144
	* Sets client configuration
sl@0
   145
	* @since
sl@0
   146
	* @param aProcessId DevSound's client process
sl@0
   147
	* @param aActualProcessId DevSound's effective/actual client (supplied by SetClientThreadInfo)
sl@0
   148
	*/
sl@0
   149
    TInt SetClientConfig(const TProcessId& aProcessId);
sl@0
   150
    TInt SetClientConfig(const TProcessId& aActualProcessId, const TProcessId& aProcessId);
sl@0
   151
sl@0
   152
sl@0
   153
	/**
sl@0
   154
	* Retrieve the current A3F state
sl@0
   155
	* @since
sl@0
   156
	* @return the current A3F state. See TAudioState
sl@0
   157
	*/
sl@0
   158
	TDevSoundAdaptorState ActiveState() const;
sl@0
   159
sl@0
   160
	/**
sl@0
   161
	* Retrieve the previous DevSound adaptor state
sl@0
   162
	* @return void
sl@0
   163
	*/
sl@0
   164
	TDevSoundAdaptorState PreviousState() const;
sl@0
   165
sl@0
   166
	/**
sl@0
   167
	* Set the current DevSound adaptor state
sl@0
   168
	* @return void
sl@0
   169
	*/
sl@0
   170
	void SetActiveState(TDevSoundAdaptorState aAdaptorState);
sl@0
   171
sl@0
   172
	/**
sl@0
   173
	* Set the previous DevSound adaptor state
sl@0
   174
	* @return void
sl@0
   175
	*/
sl@0
   176
	void SetPreviousState(TDevSoundAdaptorState aAdaptorState);
sl@0
   177
sl@0
   178
	/**
sl@0
   179
	* SetVolume for DevSound
sl@0
   180
	*/
sl@0
   181
	TInt SetDevSoundVolume(TInt aVolume, TBool& aAsyncCompletion);
sl@0
   182
sl@0
   183
	/**
sl@0
   184
	* SetGain for DevSound
sl@0
   185
	*/
sl@0
   186
	TInt SetDevSoundGain(TInt aGain, TBool& aAsyncCompletion);
sl@0
   187
sl@0
   188
	/**
sl@0
   189
	* SetPlayBalance for DevSound
sl@0
   190
	*/
sl@0
   191
	TInt SetDevSoundPlayBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion);
sl@0
   192
sl@0
   193
	/**
sl@0
   194
	* SetPlayBalance for DevSound
sl@0
   195
	*/
sl@0
   196
	TInt SetDevSoundRecordBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion);
sl@0
   197
sl@0
   198
	/**
sl@0
   199
	* SetVolumeRamp for DevSound
sl@0
   200
	*/
sl@0
   201
	TInt SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
sl@0
   202
sl@0
   203
	/**
sl@0
   204
	* MaxVolume for DevSound
sl@0
   205
	*/
sl@0
   206
	TInt DevSoundMaxVolume() const;
sl@0
   207
	/**
sl@0
   208
	* MaxGain for DevSound
sl@0
   209
	*/
sl@0
   210
	TInt DevSoundMaxGain() const;
sl@0
   211
	/**
sl@0
   212
	* Volume setting
sl@0
   213
	*/
sl@0
   214
	TInt DevSoundVolume() const;
sl@0
   215
	/**
sl@0
   216
	* Gain setting
sl@0
   217
	*/
sl@0
   218
	TInt DevSoundGain() const;
sl@0
   219
sl@0
   220
	/**
sl@0
   221
	* GetPlayBalance for DevSound
sl@0
   222
	*/
sl@0
   223
	void GetDevSoundPlayBalance(TInt& aLeftPercentage, TInt& aRightPercentage);
sl@0
   224
sl@0
   225
	/**
sl@0
   226
	* GetRecordBalance for DevSound
sl@0
   227
	*/
sl@0
   228
	void GetDevSoundRecordBalance(TInt& aLeftPercentage, TInt& aRightPercentage);
sl@0
   229
sl@0
   230
	/**
sl@0
   231
	* GetSupportedDataTypes for DevSound
sl@0
   232
	*/
sl@0
   233
	void DevSoundSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes, TUint aDataType);
sl@0
   234
sl@0
   235
	/**
sl@0
   236
	* Call from control - generates appropriate SetGainAndBalance() call
sl@0
   237
	*/
sl@0
   238
	TInt RequestGainAndBalance(CDevAudioControl* aCallingControl);
sl@0
   239
sl@0
   240
	// From base class MAudioContextObserver
sl@0
   241
	/**
sl@0
   242
	* Callback to context observer to show progression through Commit() and pre-emption cycles
sl@0
   243
	*
sl@0
   244
	* @param aEvent  a Uid giving the specific event.
sl@0
   245
	* @param aError  an error code. KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   246
	*/
sl@0
   247
	virtual void ContextEvent(TUid aEvent, TInt aError);
sl@0
   248
sl@0
   249
	// from MA3FDevSoundAdaptationInfoObserver
sl@0
   250
	void RequestMaxGainComplete (TUid aCodecType, TInt aError, TInt aResult);
sl@0
   251
	void RequestSupportedFormatsComplete(TUid aCodecType, TInt aError);
sl@0
   252
sl@0
   253
	/**
sl@0
   254
	* Queries if the low layers does support resume operation.
sl@0
   255
	* @since
sl@0
   256
	* @return TBool ETrue if Resume is supported
sl@0
   257
	*               EFalse otherwise
sl@0
   258
	*/
sl@0
   259
	TBool IsResumeSupported();
sl@0
   260
sl@0
   261
	void ConvertToFourCcL(RArray<TFourCC>& aSupportedDataTypes, RArray<TUid>& iSupportedFormats);
sl@0
   262
	
sl@0
   263
	//from MA3FDevSoundAutoPauseResume
sl@0
   264
	TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData);
sl@0
   265
	TInt CancelRegisterAsClient(TUid aEventType);
sl@0
   266
	TInt WillResumePlay();
sl@0
   267
	
sl@0
   268
	//from MA3FDevSoundAutoPauseResumeObserver
sl@0
   269
	virtual void NotifyResume();
sl@0
   270
	
sl@0
   271
	/**
sl@0
   272
	* GetPrioritySettings for DevSound
sl@0
   273
	*/
sl@0
   274
	void GetPrioritySettings(TAudioTypeSettings& astorage);
sl@0
   275
	
sl@0
   276
	TBool IsPrioritySet();
sl@0
   277
	
sl@0
   278
	//Panic function
sl@0
   279
	void Panic(TMMFDevAudioPanicCodes aCode);
sl@0
   280
sl@0
   281
protected:
sl@0
   282
sl@0
   283
	CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver);
sl@0
   284
sl@0
   285
	// If active, apply devsound volume and balance changes
sl@0
   286
	TInt SetGainAndBalance(TBool aCallBack, TBool& aAsyncCompletion);
sl@0
   287
sl@0
   288
	// Helper methods
sl@0
   289
	TInt CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec);
sl@0
   290
	void DeleteAudioProcessingUnits();
sl@0
   291
sl@0
   292
	TInt CommitAudioContext();
sl@0
   293
	TBool IsMidState(TDevSoundAdaptorState aAdaptorState);
sl@0
   294
sl@0
   295
/*
sl@0
   296
* most of member data is protected for DevAudioControl access
sl@0
   297
*/
sl@0
   298
protected: // data
sl@0
   299
sl@0
   300
	/**
sl@0
   301
	* adaptation observer - used to indicate async callbacks etc
sl@0
   302
	*/
sl@0
   303
	MDevSoundAdaptationObserver& iAdaptationObserver;
sl@0
   304
sl@0
   305
	/**
sl@0
   306
	* Pointer to audio context factory - context creation
sl@0
   307
	* Own.
sl@0
   308
	*/
sl@0
   309
	CAudioContextFactory *iAudioContextFactory;
sl@0
   310
sl@0
   311
	/**
sl@0
   312
	* Pointer to audio context.
sl@0
   313
	* Not own.
sl@0
   314
	*/
sl@0
   315
	MAudioContext *iAudioContext;
sl@0
   316
sl@0
   317
	/**
sl@0
   318
	* Pointer to audio stream.
sl@0
   319
	* Not own.
sl@0
   320
	*/
sl@0
   321
	MAudioStream *iAudioStream;
sl@0
   322
sl@0
   323
	/**
sl@0
   324
	* Pointer to audio source.
sl@0
   325
	* Not own.
sl@0
   326
	*/
sl@0
   327
	MAudioProcessingUnit* iAudioSource;
sl@0
   328
sl@0
   329
	/**
sl@0
   330
	* Pointer to audio codec.
sl@0
   331
	* Not own.
sl@0
   332
	*/
sl@0
   333
	MAudioProcessingUnit* iAudioCodec;
sl@0
   334
sl@0
   335
	/**
sl@0
   336
	* Pointer to audio gain control
sl@0
   337
	* Not own.
sl@0
   338
	*/
sl@0
   339
	MAudioProcessingUnit* iGainControl;
sl@0
   340
sl@0
   341
	/**
sl@0
   342
	* Pointer to audio sink
sl@0
   343
	* Not own.
sl@0
   344
	*/
sl@0
   345
	MAudioProcessingUnit* iAudioSink;
sl@0
   346
sl@0
   347
	/**
sl@0
   348
	* Mode to which this DevAudio is initialized in
sl@0
   349
	*/
sl@0
   350
	TMMFState iMode;
sl@0
   351
sl@0
   352
	TUid 	iFormat;
sl@0
   353
sl@0
   354
	/**
sl@0
   355
	* Active DevSound Adaptor state
sl@0
   356
	*/
sl@0
   357
	TDevSoundAdaptorState iActiveState;
sl@0
   358
sl@0
   359
	/**
sl@0
   360
	* Previous DevSound Adaptor state
sl@0
   361
	*/
sl@0
   362
	TDevSoundAdaptorState iPreviousState;
sl@0
   363
sl@0
   364
	TAudioState		iActiveStreamState;
sl@0
   365
sl@0
   366
	TBool 	iReinitializing;
sl@0
   367
	TBool 	iClosing;
sl@0
   368
	TBool	iStop;
sl@0
   369
	TUid 	iTargetFormat;
sl@0
   370
	TMMFState iTargetMode;
sl@0
   371
sl@0
   372
	TInt iDevSoundMaxGain;
sl@0
   373
	TInt iDevSoundMaxVolume;
sl@0
   374
	TInt iDevSoundGain;
sl@0
   375
	TInt iDevSoundVolume;
sl@0
   376
	TInt iDevSoundPlayBalance[2];
sl@0
   377
	TInt iDevSoundRecordBalance[2];
sl@0
   378
	TTimeIntervalMicroSeconds	iRampDuration;
sl@0
   379
private:
sl@0
   380
	enum TPreOpenState
sl@0
   381
		{
sl@0
   382
		EPreOpenStateIdle,
sl@0
   383
		EPreOpenStateRequestingMaxVolume,
sl@0
   384
		EPreOpenStateRequestingMaxGain,
sl@0
   385
		EPreOpenStateRequestingInputFormats,
sl@0
   386
		EPreOpenStateRequestingOutputFormats,
sl@0
   387
		};
sl@0
   388
sl@0
   389
	TPreOpenState iPreOpenState;
sl@0
   390
sl@0
   391
	RArray<TUid> iSupportedInputFormats;
sl@0
   392
	RArray<TUid> iSupportedOutputFormats;
sl@0
   393
sl@0
   394
	CA3FDevSoundAdaptationInfo* iAdaptationInfo;
sl@0
   395
sl@0
   396
	CDevPlayControl*   iDevPlayControl;
sl@0
   397
	CDevRecordControl* iDevRecordControl;
sl@0
   398
	CDevToneControl*   iDevToneControl;
sl@0
   399
	CDevGenControl*    iDevGenControl;
sl@0
   400
sl@0
   401
	/**
sl@0
   402
	* Points to whichever control is active
sl@0
   403
	* Not own.
sl@0
   404
	*/
sl@0
   405
	CDevAudioControl* iCurrentAudioControl;
sl@0
   406
sl@0
   407
	// Pointer to global properties
sl@0
   408
	// Not owned.
sl@0
   409
	MGlobalProperties*	iGlobalProperties;
sl@0
   410
	
sl@0
   411
	TAudioTypeSettings iPrioritySettings;
sl@0
   412
	TBool iPriorityFlag;
sl@0
   413
sl@0
   414
	};
sl@0
   415
sl@0
   416
inline TInt CDevAudio::DevSoundMaxVolume() const
sl@0
   417
	{
sl@0
   418
	return iDevSoundMaxVolume;
sl@0
   419
	}
sl@0
   420
sl@0
   421
inline TInt CDevAudio::DevSoundMaxGain() const
sl@0
   422
	{
sl@0
   423
	return iDevSoundMaxGain;
sl@0
   424
	}
sl@0
   425
sl@0
   426
inline TInt CDevAudio::DevSoundVolume() const
sl@0
   427
	{
sl@0
   428
	return iDevSoundVolume;
sl@0
   429
	}
sl@0
   430
sl@0
   431
inline TInt CDevAudio::DevSoundGain() const
sl@0
   432
	{
sl@0
   433
	return iDevSoundGain;
sl@0
   434
	}
sl@0
   435
sl@0
   436
#endif // CDEVAUDIO_H