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