os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundSessionBody.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundSessionBody.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,361 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// DevSoundSessionBody.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef MMFDEVSOUNDSESSIONBODY_H
    1.22 +#define MMFDEVSOUNDSESSIONBODY_H
    1.23 +
    1.24 +#include <e32base.h>
    1.25 +#include <mmf/server/mmfhwdevice.h>
    1.26 +#include "MmfDevSoundSession.h"
    1.27 +#include "MmfDevSoundSessionXtnd.h"
    1.28 +#include "ToneGenerator.h"
    1.29 +#include "mmfAudioPolicyProxy.h"
    1.30 +#include "MmfDevSoundInfo.h"
    1.31 +#include "DevSoundUtility.h"
    1.32 +
    1.33 +#ifdef SYMBIAN_MDF_SHAREDCHUNK_SOUNDDRIVER
    1.34 +	#include "mdasoundadapter.h"
    1.35 +#else
    1.36 +	#include <mdasound.h>
    1.37 +#endif
    1.38 +
    1.39 +#include <mmf/server/devsoundstandardcustominterfaces.h>
    1.40 +
    1.41 +//controlls buffer sizes
    1.42 +const TInt KDevSoundDefaultFrameSize = 0x1000;
    1.43 +const TInt KDevSoundMinFrameSize = 0x800; //2K
    1.44 +const TInt KDevSoundMaxFrameSize = 0x4000;  //16K
    1.45 +const TInt KDevSoundDeltaFrameSize = 0x800; //2K
    1.46 +const TInt KDevSoundFramesPerSecond = 4;
    1.47 +
    1.48 +//Forward references:
    1.49 +class CDevSoundPlayer;
    1.50 +class CDevSoundError;
    1.51 +class CDevSoundRecorder;
    1.52 +class CDevSoundRecordError;
    1.53 +class CMMFDevSoundProxyXtnd;
    1.54 +
    1.55 +class CMMFHwDevice;
    1.56 +class CMMFHwDeviceObserver;
    1.57 +class MPlayCustomInterface;
    1.58 +class MRecordCustomInterface;
    1.59 +class MEmptyBuffersCustomInterface;
    1.60 +class MTimePlayedCustomInterface;
    1.61 +
    1.62 +/*
    1.63 + *
    1.64 + *	Reference internals for CMMFDevSound
    1.65 + *  @internalComponent
    1.66 + *
    1.67 + */
    1.68 +class CMMFDevSoundSvrImp;
    1.69 +NONSHARABLE_CLASS( CMMFDevSoundSvrImp ) : public CBase, public MMMFHwDeviceObserver, 
    1.70 +										  public MMMFDevSoundCustomInterfaceTarget
    1.71 +	{
    1.72 +public:
    1.73 +	static CMMFDevSoundSvrImp* NewL(CMMFDevSoundSessionXtnd* aParent);
    1.74 +	~CMMFDevSoundSvrImp();
    1.75 +
    1.76 +	// Initializes to raw audio data PCM16 and Sampling Rate of 8 KHz. 
    1.77 +	void InitializeL(MDevSoundObserver& aDevSoundObserver, TMMFState aMode);
    1.78 +	// Initializes with hardware device and mode (play, record, convert)
    1.79 +	void InitializeL(MDevSoundObserver& aDevSoundObserver, TUid aHWDev, TMMFState aMode);
    1.80 +	// Initializes with hardware device associated with specific FourCC code 
    1.81 +	// and desired mode (play, record, convert)
    1.82 +	void InitializeL(MDevSoundObserver& aDevSoundObserver, TFourCC aDesiredFourCC, TMMFState aMode); 
    1.83 +
    1.84 +	// Returns device capabilities
    1.85 +	TMMFCapabilities Capabilities();
    1.86 +	// Returns device configuration
    1.87 +	TMMFCapabilities Config() const;
    1.88 +	// Sets device configuration
    1.89 +	void SetConfigL(const TMMFCapabilities& aCaps);
    1.90 +
    1.91 +	// Returns maximum play volume device supports
    1.92 +	TInt MaxVolume();
    1.93 +	// Returns play volume device is configured to
    1.94 +	TInt Volume();
    1.95 +	// Sets device play volume
    1.96 +	void SetVolume(TInt aVolume);
    1.97 +
    1.98 +	// Returns maximum record gain device supports
    1.99 +	TInt MaxGain();
   1.100 +	// Returns record gain device is configured to
   1.101 +	TInt Gain();
   1.102 +	// Sets device record gain
   1.103 +	void SetGain(TInt aGain);
   1.104 +
   1.105 +	// Returns play balance
   1.106 +	void GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
   1.107 +	// Sets play balance
   1.108 +	void SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
   1.109 +
   1.110 +	// Returns record balance
   1.111 +	void GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
   1.112 +	// Sets record balance
   1.113 +	void SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
   1.114 +
   1.115 +	// Initializes audio device and start play process
   1.116 +	void PlayInitL();
   1.117 +	// Initializes audio device and start record process
   1.118 +	void RecordInitL(const RMmfIpcMessage& aMessage);
   1.119 +	// Plays the data in the buffer
   1.120 +	TBool PlayData(const RMmfIpcMessage& aMessage);
   1.121 +	// Records data into buffer
   1.122 +	TBool RecordData(const RMmfIpcMessage& aMessage);
   1.123 +	// Stops the ongoing operation
   1.124 +	void Stop();
   1.125 +	// Tempororily Stops the ongoing operation
   1.126 +	void Pause();
   1.127 +
   1.128 +	// Returns the Sample recorded so far
   1.129 +	TInt SamplesRecorded();
   1.130 +	// Returns the Sample played so far
   1.131 +	TInt SamplesPlayed();
   1.132 +
   1.133 +	// Initializes device and start playing tone
   1.134 +	void PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
   1.135 +	// Initializes device and start playing dual tone
   1.136 +	void PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
   1.137 +	// Initializes device and start playing DTMF String
   1.138 +	void PlayDTMFStringL(const TDesC& aDTMFString);
   1.139 +	// Initializes device and start playing tone sequence
   1.140 +	void PlayToneSequenceL(const TDesC8& aData);
   1.141 +	// Initializes device and start playing fixed sequence
   1.142 +	void PlayFixedSequenceL(TInt aSequenceNumber);
   1.143 +
   1.144 +	// Sets tone repeat attributes
   1.145 +	void SetToneRepeats(TInt aRepeatCount,
   1.146 +					const TTimeIntervalMicroSeconds& aRepeatTrailingSilence);
   1.147 +	// Sets DTMF tone attributes
   1.148 +	void SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength,
   1.149 +									TTimeIntervalMicroSeconds32& aToneOffLength,
   1.150 +									TTimeIntervalMicroSeconds32& aPauseLength);
   1.151 +	// Sets volume ramp for playing
   1.152 +	void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
   1.153 +	// Sets priority settings
   1.154 +	void SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
   1.155 +
   1.156 +	// Provides interface for sending custom commands for the audio device
   1.157 +	virtual TAny* CustomInterface(TUid aInterfaceId);
   1.158 +
   1.159 +	// Provides interface for querying fixed sequence count
   1.160 +	TInt FixedSequenceCount();
   1.161 +	// Provides interface for querying fixed sequence name
   1.162 +	const TDesC& FixedSequenceName(TInt aSequenceNumber);
   1.163 +	// Gets the supported input datatypes
   1.164 +	void GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypesconst, const TMMFPrioritySettings& aPrioritySettings) const;
   1.165 +	// Gets the supported output datatypes
   1.166 +	void GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings) const;
   1.167 +
   1.168 +	// Interface for Audio Policy
   1.169 +	// Sets id for this DevSound instance
   1.170 +	void SetDevSoundId(TInt aDevSoundId);
   1.171 +	// Returns info about this DevSound instance
   1.172 +	TMMFDevSoundInfo DevSoundInfo();
   1.173 +	// Called by Audio Policy Server when play reqeust is granted
   1.174 +	void StartPlayDataL();
   1.175 +	// Called by Audio Policy Server when record reqeust is granted
   1.176 +	void StartRecordDataL();
   1.177 +	// Called by Audio Policy Server when play tone reqeust is granted
   1.178 +	void StartPlayToneL();
   1.179 +	// Called by Audio Policy Server when play dual tone request is granted
   1.180 +	void StartPlayDualToneL();
   1.181 +	// Called by Audio Policy Server when play DTMF reqeust is granted
   1.182 +	void StartPlayDTMFStringL();
   1.183 +	// Called by Audio Policy Server when play tone sequence reqeust is granted
   1.184 +	void StartPlayToneSequenceL();
   1.185 +	// Called by Audio Policy Server when DevSound instance looses device
   1.186 +	void SendEventToClient(const TMMFEvent& aEvent);
   1.187 +	// Updates the total bytes played from audio device
   1.188 +	void UpdateBytesPlayed();
   1.189 +
   1.190 +	// CMMFHwDevice implementation:
   1.191 +	TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
   1.192 +	TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer);
   1.193 +	TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg);
   1.194 +	void Stopped();
   1.195 +	void Error(TInt aError);
   1.196 +	// CMMFHwDevice implementation ends
   1.197 +	
   1.198 +	//provides interface for register a notification event
   1.199 +	TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData = KNullDesC8);
   1.200 +	//provides interface to cancel the registered notification
   1.201 +	TInt CancelRegisterAsClient(TUid aEventType);
   1.202 +	//Gets the notification data for client to resume
   1.203 +	TInt GetResourceNotificationData(TUid aEventType, TDes8& aNotificationData);
   1.204 +	//waits for the client to resume playback even after the timeout expires
   1.205 +	TInt WillResumePlay();
   1.206 +	//Empties the buffers below DevSound without causing the codec to be deleted
   1.207 +	TInt EmptyBuffers();
   1.208 +
   1.209 +	TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTime);
   1.210 +	// CustomCommand implementation - this bit knows it is server side
   1.211 +	void DoSyncCustomCommandL(const RMmfIpcMessage& aMessage);
   1.212 +	void DoSyncCustomCommandResultL(const RMmfIpcMessage& aMessage);
   1.213 +	void DoAsyncCustomCommandL(const RMmfIpcMessage& aMessage);
   1.214 +	void DoAsyncCustomCommandResultL(const RMmfIpcMessage& aMessage);
   1.215 +
   1.216 +private:
   1.217 +	// So that nobody can extend 
   1.218 +	CMMFDevSoundSvrImp(CMMFDevSoundSessionXtnd* aParent);
   1.219 +	// Second phase constructor
   1.220 +	void Construct3L(RServer2& aPolicyServerHandle);
   1.221 +	void PreInitializeL();
   1.222 +	// Initializes format based on format supported
   1.223 +	TInt InitializeFormat(RMdaDevSound::TSoundFormatsSupportedBuf& aSupportedFormat,
   1.224 +		RMdaDevSound::TCurrentSoundFormatBuf& aFormat);
   1.225 +	// Request Policy
   1.226 +	void RequestPolicy();
   1.227 +	// Play tone
   1.228 +	void DoPlayL();
   1.229 +	// Sets active tone
   1.230 +	void SetActiveToneBuffer();
   1.231 +	// Fills free tone buffer with tone data
   1.232 +	TInt FillFreeToneBuffer();
   1.233 +	// Updates the state of audio policy based on the audio policy settings
   1.234 +	TInt UpdatePolicyState(TMMFAudioPolicyState aNewState);
   1.235 +	// HwDevice implementation begins
   1.236 +	TInt InitTask();
   1.237 +	// Returns Sampling Frequency the device is currently configured to
   1.238 +	TInt SamplingFrequency();
   1.239 +	// Returns number of channels the device is currently configured to
   1.240 +	TInt NumberOfChannels();
   1.241 +	//returns the number of bytes in each audio sample
   1.242 +	TInt BytesPerAudioSample();
   1.243 +	// HwDevice implementation ends
   1.244 +	TInt SetDeviceVolume(TInt aVolume);
   1.245 +	TInt SetPlayFormat(RMdaDevSound::TCurrentSoundFormatBuf& aPlayFormat);
   1.246 +	TInt SetRecordFormat(RMdaDevSound::TCurrentSoundFormatBuf& aRecordFormat);
   1.247 +	TInt SetDeviceRecordLevel(TInt aGain);
   1.248 +	TInt SetDeviceVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
   1.249 +public:
   1.250 +	enum TMMFDevSoundState
   1.251 +		{
   1.252 +		/** Idle state.
   1.253 +		*/
   1.254 +		EMMFDevSoundStateIdle,
   1.255 +		/** The DevSound is currently playing.
   1.256 +		*/
   1.257 +		EMMFDevSoundStatePlaying,
   1.258 +		/** The DevSound is playing a tone.
   1.259 +		*/
   1.260 +		EMMFDevSoundStateTonePlaying,
   1.261 +		/** The DevSound is currently recording.
   1.262 +		*/
   1.263 +		EMMFDevSoundStateRecording,
   1.264 +		/** The DevSound is playing and recording.
   1.265 +		*/
   1.266 +		EMMFDevSoundStatePlayingRecording,
   1.267 +		/** The DevSound is converting data.
   1.268 +		*/
   1.269 +		EMMFDevSoundStateConverting
   1.270 +		};                
   1.271 +private:
   1.272 +
   1.273 +	CMMFDevSoundSessionXtnd& iParent;	
   1.274 +
   1.275 +	//Objects (owned or referred to):
   1.276 +	RMMFAudioPolicyProxy*	iAudioPolicyProxy;
   1.277 +	CMMFAudioPolicyRequest*	iAudioPolicyRequest;
   1.278 +	MDevSoundObserver*		iDevSoundObserver;
   1.279 +
   1.280 +	// Handles receiving events
   1.281 +	CMMFDevSoundEventHandler* iDevSoundEventHandler;
   1.282 +
   1.283 +	//WINS Sound Device Structures
   1.284 +	RMdaDevSound::TSoundFormatsSupportedBuf iPlayFormatsSupported;
   1.285 +	RMdaDevSound::TCurrentSoundFormatBuf	iPlayFormat;
   1.286 +	RMdaDevSound::TSoundFormatsSupportedBuf iRecordFormatsSupported;
   1.287 +	RMdaDevSound::TCurrentSoundFormatBuf	iRecordFormat;
   1.288 +
   1.289 +	// DevSound capabilities
   1.290 +	TMMFCapabilities		iDeviceCapabilities;
   1.291 +	// Current Configuration
   1.292 +	TMMFCapabilities		iDeviceConfig;
   1.293 +
   1.294 +	// AudioPolicy priority used to communicate with server
   1.295 +	TMMFAudioPolicyPrioritySettings	iAudioPolicyPrioritySettings;
   1.296 +
   1.297 +	MPlayCustomInterface* iPlayCustomInterface;
   1.298 +	MRecordCustomInterface* iRecordCustomInterface;
   1.299 +	
   1.300 +	// Bytes of audio data played in current play cycle
   1.301 +	TInt					iPlayedBytesCount;
   1.302 +	TInt					iGain;
   1.303 +	TInt					iVolume;
   1.304 +	TMMFDevSoundInfo		iDevSoundInfo;
   1.305 +
   1.306 +	//Tone Stuff:
   1.307 +	MMdaToneSynthesis*			iCurrentGenerator;
   1.308 +	TMdaSimpleToneGenerator		iToneGen;
   1.309 +	TMdaDualToneGenerator		iDualToneGen;
   1.310 +	TMdaDTMFGenerator			iDTMFGen;
   1.311 +	TMdaSequenceGenerator		iSequenceGen; // Not Supported
   1.312 +	TInt						iRepeatCount;
   1.313 +	TTimeIntervalMicroSeconds	iRepeatTrailingSilence;
   1.314 +	TTimeIntervalMicroSeconds	iRampDuration;
   1.315 +	// Double buffer tone playing
   1.316 +	CMMFDataBuffer*				iToneBuffer1;
   1.317 +	CMMFDataBuffer*				iToneBuffer2;
   1.318 +	// Reference to current tone buffer playing
   1.319 +	CMMFDataBuffer*				iActiveToneBuffer;
   1.320 +
   1.321 +	// Hardware device implementation
   1.322 +	CMMFHwDevice*				iCMMFHwDevice;
   1.323 +	// Mode in which DevSound instance will be used for
   1.324 +	TMMFDevSoundState			iMode;
   1.325 +	// Reference to hardware buffer
   1.326 +	CMMFDataBuffer*				iHwDeviceBuffer;
   1.327 +	
   1.328 +	TBool						iLastBufferReceived;
   1.329 +
   1.330 +	// Holds true of Audio data given to DevSound needs to ramped up
   1.331 +	CMMFDevSoundUtility*		iDevSoundUtil;
   1.332 +
   1.333 +	// Fixed sequence related
   1.334 +	CPtrC8Array*				iFixedSequences;	// Holds the fixed sequence data
   1.335 +	TPtrC8						iFixedSequence;		// Holds reference to current sequence
   1.336 +
   1.337 +	// Balance
   1.338 +	TInt						iLeftPlayBalance;
   1.339 +	TInt						iRightPlayBalance;
   1.340 +
   1.341 +	TInt						iLeftRecordBalance;
   1.342 +	TInt						iRightRecordBalance;
   1.343 +
   1.344 +	TBool						iPaused;
   1.345 +
   1.346 +	TUid                        iHwDeviceID;
   1.347 +
   1.348 +	// Hardware device initialization parameters
   1.349 +	THwDeviceInitParams			iDevInfo;
   1.350 +
   1.351 +	TBool                      iFirstCallFromHwDevice;
   1.352 +	TBool 						iFourCCSet;
   1.353 +	TFourCC						iSrcFourCC;
   1.354 +	TFourCC						iDestFourCC;
   1.355 +	
   1.356 +	TBool						iHasPolicy;
   1.357 +	MTimePlayedCustomInterface* iTimePlayedCustomInterface;
   1.358 +	TTimeIntervalMicroSeconds	iTimePlayed;
   1.359 +	friend class CMMFDevSoundSession;
   1.360 +	};
   1.361 +
   1.362 +#include "MmfDevSoundSessionBody.inl"
   1.363 +
   1.364 +#endif // MMFDEVSOUNDSESSIONBODY__H