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