os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundSessionBody.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
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// DevSoundSessionBody.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef MMFDEVSOUNDSESSIONBODY_H
sl@0
    19
#define MMFDEVSOUNDSESSIONBODY_H
sl@0
    20
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <mmf/server/mmfhwdevice.h>
sl@0
    23
#include "MmfDevSoundSession.h"
sl@0
    24
#include "MmfDevSoundSessionXtnd.h"
sl@0
    25
#include "ToneGenerator.h"
sl@0
    26
#include "mmfAudioPolicyProxy.h"
sl@0
    27
#include "MmfDevSoundInfo.h"
sl@0
    28
#include "DevSoundUtility.h"
sl@0
    29
sl@0
    30
#ifdef SYMBIAN_MDF_SHAREDCHUNK_SOUNDDRIVER
sl@0
    31
	#include "mdasoundadapter.h"
sl@0
    32
#else
sl@0
    33
	#include <mdasound.h>
sl@0
    34
#endif
sl@0
    35
sl@0
    36
#include <mmf/server/devsoundstandardcustominterfaces.h>
sl@0
    37
sl@0
    38
//controlls buffer sizes
sl@0
    39
const TInt KDevSoundDefaultFrameSize = 0x1000;
sl@0
    40
const TInt KDevSoundMinFrameSize = 0x800; //2K
sl@0
    41
const TInt KDevSoundMaxFrameSize = 0x4000;  //16K
sl@0
    42
const TInt KDevSoundDeltaFrameSize = 0x800; //2K
sl@0
    43
const TInt KDevSoundFramesPerSecond = 4;
sl@0
    44
sl@0
    45
//Forward references:
sl@0
    46
class CDevSoundPlayer;
sl@0
    47
class CDevSoundError;
sl@0
    48
class CDevSoundRecorder;
sl@0
    49
class CDevSoundRecordError;
sl@0
    50
class CMMFDevSoundProxyXtnd;
sl@0
    51
sl@0
    52
class CMMFHwDevice;
sl@0
    53
class CMMFHwDeviceObserver;
sl@0
    54
class MPlayCustomInterface;
sl@0
    55
class MRecordCustomInterface;
sl@0
    56
class MEmptyBuffersCustomInterface;
sl@0
    57
class MTimePlayedCustomInterface;
sl@0
    58
sl@0
    59
/*
sl@0
    60
 *
sl@0
    61
 *	Reference internals for CMMFDevSound
sl@0
    62
 *  @internalComponent
sl@0
    63
 *
sl@0
    64
 */
sl@0
    65
class CMMFDevSoundSvrImp;
sl@0
    66
NONSHARABLE_CLASS( CMMFDevSoundSvrImp ) : public CBase, public MMMFHwDeviceObserver, 
sl@0
    67
										  public MMMFDevSoundCustomInterfaceTarget
sl@0
    68
	{
sl@0
    69
public:
sl@0
    70
	static CMMFDevSoundSvrImp* NewL(CMMFDevSoundSessionXtnd* aParent);
sl@0
    71
	~CMMFDevSoundSvrImp();
sl@0
    72
sl@0
    73
	// Initializes to raw audio data PCM16 and Sampling Rate of 8 KHz. 
sl@0
    74
	void InitializeL(MDevSoundObserver& aDevSoundObserver, TMMFState aMode);
sl@0
    75
	// Initializes with hardware device and mode (play, record, convert)
sl@0
    76
	void InitializeL(MDevSoundObserver& aDevSoundObserver, TUid aHWDev, TMMFState aMode);
sl@0
    77
	// Initializes with hardware device associated with specific FourCC code 
sl@0
    78
	// and desired mode (play, record, convert)
sl@0
    79
	void InitializeL(MDevSoundObserver& aDevSoundObserver, TFourCC aDesiredFourCC, TMMFState aMode); 
sl@0
    80
sl@0
    81
	// Returns device capabilities
sl@0
    82
	TMMFCapabilities Capabilities();
sl@0
    83
	// Returns device configuration
sl@0
    84
	TMMFCapabilities Config() const;
sl@0
    85
	// Sets device configuration
sl@0
    86
	void SetConfigL(const TMMFCapabilities& aCaps);
sl@0
    87
sl@0
    88
	// Returns maximum play volume device supports
sl@0
    89
	TInt MaxVolume();
sl@0
    90
	// Returns play volume device is configured to
sl@0
    91
	TInt Volume();
sl@0
    92
	// Sets device play volume
sl@0
    93
	void SetVolume(TInt aVolume);
sl@0
    94
sl@0
    95
	// Returns maximum record gain device supports
sl@0
    96
	TInt MaxGain();
sl@0
    97
	// Returns record gain device is configured to
sl@0
    98
	TInt Gain();
sl@0
    99
	// Sets device record gain
sl@0
   100
	void SetGain(TInt aGain);
sl@0
   101
sl@0
   102
	// Returns play balance
sl@0
   103
	void GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
sl@0
   104
	// Sets play balance
sl@0
   105
	void SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
sl@0
   106
sl@0
   107
	// Returns record balance
sl@0
   108
	void GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
sl@0
   109
	// Sets record balance
sl@0
   110
	void SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
sl@0
   111
sl@0
   112
	// Initializes audio device and start play process
sl@0
   113
	void PlayInitL();
sl@0
   114
	// Initializes audio device and start record process
sl@0
   115
	void RecordInitL(const RMmfIpcMessage& aMessage);
sl@0
   116
	// Plays the data in the buffer
sl@0
   117
	TBool PlayData(const RMmfIpcMessage& aMessage);
sl@0
   118
	// Records data into buffer
sl@0
   119
	TBool RecordData(const RMmfIpcMessage& aMessage);
sl@0
   120
	// Stops the ongoing operation
sl@0
   121
	void Stop();
sl@0
   122
	// Tempororily Stops the ongoing operation
sl@0
   123
	void Pause();
sl@0
   124
sl@0
   125
	// Returns the Sample recorded so far
sl@0
   126
	TInt SamplesRecorded();
sl@0
   127
	// Returns the Sample played so far
sl@0
   128
	TInt SamplesPlayed();
sl@0
   129
sl@0
   130
	// Initializes device and start playing tone
sl@0
   131
	void PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
sl@0
   132
	// Initializes device and start playing dual tone
sl@0
   133
	void PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
sl@0
   134
	// Initializes device and start playing DTMF String
sl@0
   135
	void PlayDTMFStringL(const TDesC& aDTMFString);
sl@0
   136
	// Initializes device and start playing tone sequence
sl@0
   137
	void PlayToneSequenceL(const TDesC8& aData);
sl@0
   138
	// Initializes device and start playing fixed sequence
sl@0
   139
	void PlayFixedSequenceL(TInt aSequenceNumber);
sl@0
   140
sl@0
   141
	// Sets tone repeat attributes
sl@0
   142
	void SetToneRepeats(TInt aRepeatCount,
sl@0
   143
					const TTimeIntervalMicroSeconds& aRepeatTrailingSilence);
sl@0
   144
	// Sets DTMF tone attributes
sl@0
   145
	void SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength,
sl@0
   146
									TTimeIntervalMicroSeconds32& aToneOffLength,
sl@0
   147
									TTimeIntervalMicroSeconds32& aPauseLength);
sl@0
   148
	// Sets volume ramp for playing
sl@0
   149
	void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
sl@0
   150
	// Sets priority settings
sl@0
   151
	void SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
sl@0
   152
sl@0
   153
	// Provides interface for sending custom commands for the audio device
sl@0
   154
	virtual TAny* CustomInterface(TUid aInterfaceId);
sl@0
   155
sl@0
   156
	// Provides interface for querying fixed sequence count
sl@0
   157
	TInt FixedSequenceCount();
sl@0
   158
	// Provides interface for querying fixed sequence name
sl@0
   159
	const TDesC& FixedSequenceName(TInt aSequenceNumber);
sl@0
   160
	// Gets the supported input datatypes
sl@0
   161
	void GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypesconst, const TMMFPrioritySettings& aPrioritySettings) const;
sl@0
   162
	// Gets the supported output datatypes
sl@0
   163
	void GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings) const;
sl@0
   164
sl@0
   165
	// Interface for Audio Policy
sl@0
   166
	// Sets id for this DevSound instance
sl@0
   167
	void SetDevSoundId(TInt aDevSoundId);
sl@0
   168
	// Returns info about this DevSound instance
sl@0
   169
	TMMFDevSoundInfo DevSoundInfo();
sl@0
   170
	// Called by Audio Policy Server when play reqeust is granted
sl@0
   171
	void StartPlayDataL();
sl@0
   172
	// Called by Audio Policy Server when record reqeust is granted
sl@0
   173
	void StartRecordDataL();
sl@0
   174
	// Called by Audio Policy Server when play tone reqeust is granted
sl@0
   175
	void StartPlayToneL();
sl@0
   176
	// Called by Audio Policy Server when play dual tone request is granted
sl@0
   177
	void StartPlayDualToneL();
sl@0
   178
	// Called by Audio Policy Server when play DTMF reqeust is granted
sl@0
   179
	void StartPlayDTMFStringL();
sl@0
   180
	// Called by Audio Policy Server when play tone sequence reqeust is granted
sl@0
   181
	void StartPlayToneSequenceL();
sl@0
   182
	// Called by Audio Policy Server when DevSound instance looses device
sl@0
   183
	void SendEventToClient(const TMMFEvent& aEvent);
sl@0
   184
	// Updates the total bytes played from audio device
sl@0
   185
	void UpdateBytesPlayed();
sl@0
   186
sl@0
   187
	// CMMFHwDevice implementation:
sl@0
   188
	TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
sl@0
   189
	TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer);
sl@0
   190
	TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg);
sl@0
   191
	void Stopped();
sl@0
   192
	void Error(TInt aError);
sl@0
   193
	// CMMFHwDevice implementation ends
sl@0
   194
	
sl@0
   195
	//provides interface for register a notification event
sl@0
   196
	TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData = KNullDesC8);
sl@0
   197
	//provides interface to cancel the registered notification
sl@0
   198
	TInt CancelRegisterAsClient(TUid aEventType);
sl@0
   199
	//Gets the notification data for client to resume
sl@0
   200
	TInt GetResourceNotificationData(TUid aEventType, TDes8& aNotificationData);
sl@0
   201
	//waits for the client to resume playback even after the timeout expires
sl@0
   202
	TInt WillResumePlay();
sl@0
   203
	//Empties the buffers below DevSound without causing the codec to be deleted
sl@0
   204
	TInt EmptyBuffers();
sl@0
   205
sl@0
   206
	TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTime);
sl@0
   207
	// CustomCommand implementation - this bit knows it is server side
sl@0
   208
	void DoSyncCustomCommandL(const RMmfIpcMessage& aMessage);
sl@0
   209
	void DoSyncCustomCommandResultL(const RMmfIpcMessage& aMessage);
sl@0
   210
	void DoAsyncCustomCommandL(const RMmfIpcMessage& aMessage);
sl@0
   211
	void DoAsyncCustomCommandResultL(const RMmfIpcMessage& aMessage);
sl@0
   212
sl@0
   213
private:
sl@0
   214
	// So that nobody can extend 
sl@0
   215
	CMMFDevSoundSvrImp(CMMFDevSoundSessionXtnd* aParent);
sl@0
   216
	// Second phase constructor
sl@0
   217
	void Construct3L(RServer2& aPolicyServerHandle);
sl@0
   218
	void PreInitializeL();
sl@0
   219
	// Initializes format based on format supported
sl@0
   220
	TInt InitializeFormat(RMdaDevSound::TSoundFormatsSupportedBuf& aSupportedFormat,
sl@0
   221
		RMdaDevSound::TCurrentSoundFormatBuf& aFormat);
sl@0
   222
	// Request Policy
sl@0
   223
	void RequestPolicy();
sl@0
   224
	// Play tone
sl@0
   225
	void DoPlayL();
sl@0
   226
	// Sets active tone
sl@0
   227
	void SetActiveToneBuffer();
sl@0
   228
	// Fills free tone buffer with tone data
sl@0
   229
	TInt FillFreeToneBuffer();
sl@0
   230
	// Updates the state of audio policy based on the audio policy settings
sl@0
   231
	TInt UpdatePolicyState(TMMFAudioPolicyState aNewState);
sl@0
   232
	// HwDevice implementation begins
sl@0
   233
	TInt InitTask();
sl@0
   234
	// Returns Sampling Frequency the device is currently configured to
sl@0
   235
	TInt SamplingFrequency();
sl@0
   236
	// Returns number of channels the device is currently configured to
sl@0
   237
	TInt NumberOfChannels();
sl@0
   238
	//returns the number of bytes in each audio sample
sl@0
   239
	TInt BytesPerAudioSample();
sl@0
   240
	// HwDevice implementation ends
sl@0
   241
	TInt SetDeviceVolume(TInt aVolume);
sl@0
   242
	TInt SetPlayFormat(RMdaDevSound::TCurrentSoundFormatBuf& aPlayFormat);
sl@0
   243
	TInt SetRecordFormat(RMdaDevSound::TCurrentSoundFormatBuf& aRecordFormat);
sl@0
   244
	TInt SetDeviceRecordLevel(TInt aGain);
sl@0
   245
	TInt SetDeviceVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
sl@0
   246
public:
sl@0
   247
	enum TMMFDevSoundState
sl@0
   248
		{
sl@0
   249
		/** Idle state.
sl@0
   250
		*/
sl@0
   251
		EMMFDevSoundStateIdle,
sl@0
   252
		/** The DevSound is currently playing.
sl@0
   253
		*/
sl@0
   254
		EMMFDevSoundStatePlaying,
sl@0
   255
		/** The DevSound is playing a tone.
sl@0
   256
		*/
sl@0
   257
		EMMFDevSoundStateTonePlaying,
sl@0
   258
		/** The DevSound is currently recording.
sl@0
   259
		*/
sl@0
   260
		EMMFDevSoundStateRecording,
sl@0
   261
		/** The DevSound is playing and recording.
sl@0
   262
		*/
sl@0
   263
		EMMFDevSoundStatePlayingRecording,
sl@0
   264
		/** The DevSound is converting data.
sl@0
   265
		*/
sl@0
   266
		EMMFDevSoundStateConverting
sl@0
   267
		};                
sl@0
   268
private:
sl@0
   269
sl@0
   270
	CMMFDevSoundSessionXtnd& iParent;	
sl@0
   271
sl@0
   272
	//Objects (owned or referred to):
sl@0
   273
	RMMFAudioPolicyProxy*	iAudioPolicyProxy;
sl@0
   274
	CMMFAudioPolicyRequest*	iAudioPolicyRequest;
sl@0
   275
	MDevSoundObserver*		iDevSoundObserver;
sl@0
   276
sl@0
   277
	// Handles receiving events
sl@0
   278
	CMMFDevSoundEventHandler* iDevSoundEventHandler;
sl@0
   279
sl@0
   280
	//WINS Sound Device Structures
sl@0
   281
	RMdaDevSound::TSoundFormatsSupportedBuf iPlayFormatsSupported;
sl@0
   282
	RMdaDevSound::TCurrentSoundFormatBuf	iPlayFormat;
sl@0
   283
	RMdaDevSound::TSoundFormatsSupportedBuf iRecordFormatsSupported;
sl@0
   284
	RMdaDevSound::TCurrentSoundFormatBuf	iRecordFormat;
sl@0
   285
sl@0
   286
	// DevSound capabilities
sl@0
   287
	TMMFCapabilities		iDeviceCapabilities;
sl@0
   288
	// Current Configuration
sl@0
   289
	TMMFCapabilities		iDeviceConfig;
sl@0
   290
sl@0
   291
	// AudioPolicy priority used to communicate with server
sl@0
   292
	TMMFAudioPolicyPrioritySettings	iAudioPolicyPrioritySettings;
sl@0
   293
sl@0
   294
	MPlayCustomInterface* iPlayCustomInterface;
sl@0
   295
	MRecordCustomInterface* iRecordCustomInterface;
sl@0
   296
	
sl@0
   297
	// Bytes of audio data played in current play cycle
sl@0
   298
	TInt					iPlayedBytesCount;
sl@0
   299
	TInt					iGain;
sl@0
   300
	TInt					iVolume;
sl@0
   301
	TMMFDevSoundInfo		iDevSoundInfo;
sl@0
   302
sl@0
   303
	//Tone Stuff:
sl@0
   304
	MMdaToneSynthesis*			iCurrentGenerator;
sl@0
   305
	TMdaSimpleToneGenerator		iToneGen;
sl@0
   306
	TMdaDualToneGenerator		iDualToneGen;
sl@0
   307
	TMdaDTMFGenerator			iDTMFGen;
sl@0
   308
	TMdaSequenceGenerator		iSequenceGen; // Not Supported
sl@0
   309
	TInt						iRepeatCount;
sl@0
   310
	TTimeIntervalMicroSeconds	iRepeatTrailingSilence;
sl@0
   311
	TTimeIntervalMicroSeconds	iRampDuration;
sl@0
   312
	// Double buffer tone playing
sl@0
   313
	CMMFDataBuffer*				iToneBuffer1;
sl@0
   314
	CMMFDataBuffer*				iToneBuffer2;
sl@0
   315
	// Reference to current tone buffer playing
sl@0
   316
	CMMFDataBuffer*				iActiveToneBuffer;
sl@0
   317
sl@0
   318
	// Hardware device implementation
sl@0
   319
	CMMFHwDevice*				iCMMFHwDevice;
sl@0
   320
	// Mode in which DevSound instance will be used for
sl@0
   321
	TMMFDevSoundState			iMode;
sl@0
   322
	// Reference to hardware buffer
sl@0
   323
	CMMFDataBuffer*				iHwDeviceBuffer;
sl@0
   324
	
sl@0
   325
	TBool						iLastBufferReceived;
sl@0
   326
sl@0
   327
	// Holds true of Audio data given to DevSound needs to ramped up
sl@0
   328
	CMMFDevSoundUtility*		iDevSoundUtil;
sl@0
   329
sl@0
   330
	// Fixed sequence related
sl@0
   331
	CPtrC8Array*				iFixedSequences;	// Holds the fixed sequence data
sl@0
   332
	TPtrC8						iFixedSequence;		// Holds reference to current sequence
sl@0
   333
sl@0
   334
	// Balance
sl@0
   335
	TInt						iLeftPlayBalance;
sl@0
   336
	TInt						iRightPlayBalance;
sl@0
   337
sl@0
   338
	TInt						iLeftRecordBalance;
sl@0
   339
	TInt						iRightRecordBalance;
sl@0
   340
sl@0
   341
	TBool						iPaused;
sl@0
   342
sl@0
   343
	TUid                        iHwDeviceID;
sl@0
   344
sl@0
   345
	// Hardware device initialization parameters
sl@0
   346
	THwDeviceInitParams			iDevInfo;
sl@0
   347
sl@0
   348
	TBool                      iFirstCallFromHwDevice;
sl@0
   349
	TBool 						iFourCCSet;
sl@0
   350
	TFourCC						iSrcFourCC;
sl@0
   351
	TFourCC						iDestFourCC;
sl@0
   352
	
sl@0
   353
	TBool						iHasPolicy;
sl@0
   354
	MTimePlayedCustomInterface* iTimePlayedCustomInterface;
sl@0
   355
	TTimeIntervalMicroSeconds	iTimePlayed;
sl@0
   356
	friend class CMMFDevSoundSession;
sl@0
   357
	};
sl@0
   358
sl@0
   359
#include "MmfDevSoundSessionBody.inl"
sl@0
   360
sl@0
   361
#endif // MMFDEVSOUNDSESSIONBODY__H