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