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