os/mm/devsound/sounddevbt/PlatSec/src/Server/AudioServer/MmfBtDevSoundSessionBody.h
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __MMFBTDEVSOUNDSESSIONBODY__H__
17 #define __MMFBTDEVSOUNDSESSIONBODY__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"
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};
39 class CDevSoundPlayer;
41 class CDevSoundRecorder;
42 class CDevSoundRecordError;
43 class CMMFDevSoundProxyXtnd;
46 class CMMFHwDeviceObserver;
47 class MPlayCustomInterface;
48 class MRecordCustomInterface;
52 * AO to handle asynch RoutingSoundDevice Initialisation
55 class CRoutingSoundDeviceHandler : public CActive
58 static CRoutingSoundDeviceHandler* NewL(MDevSoundObserver* aObserver);
59 ~CRoutingSoundDeviceHandler();
64 CRoutingSoundDeviceHandler(MDevSoundObserver* aObserver);
67 MDevSoundObserver* iObserver; // Not owned
72 * Reference internals for CMMFDevSound
76 class CMMFDevSoundSvrImp;
77 NONSHARABLE_CLASS( CMMFDevSoundSvrImp ) : public CBase, public MMMFHwDeviceObserver
80 static CMMFDevSoundSvrImp* NewL(CMMFDevSoundSessionXtnd* aParent);
81 ~CMMFDevSoundSvrImp();
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);
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);
100 // Returns maximum play volume device supports
102 // Returns play volume device is configured to
104 // Sets device play volume
105 void SetVolume(TInt aVolume);
107 // Returns maximum record gain device supports
109 // Returns record gain device is configured to
111 // Sets device record gain
112 void SetGain(TInt aGain);
114 // Returns play balance
115 void GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
117 void SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
119 // Returns record balance
120 void GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
121 // Sets record balance
122 void SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
124 // Initializes audio device and start play process
126 // Initializes audio device and start record process
127 void RecordInitL(const RMmfIpcMessage& aMessage);
128 // Plays the data in the buffer
130 // Records data into buffer
131 void RecordData(const RMmfIpcMessage& aMessage);
132 // Stops the ongoing operation
134 // Tempororily Stops the ongoing operation
137 // Returns the Sample recorded so far
138 TInt SamplesRecorded();
139 // Returns the Sample played so far
140 TInt SamplesPlayed();
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);
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);
165 // Provides interface for converting data in buffer
167 // Converts data in the buffer
170 // Provides interface for sending custom commands for the audio device
171 TAny* CustomInterface(TUid aInterfaceId);
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;
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();
204 // CMMFHwDevice implementation:
205 TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
206 TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer);
207 TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg);
209 void Error(TInt aError);
210 // CMMFHwDevice implementation ends
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();
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);
231 void RequestPolicy();
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
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);
257 CMMFDevSoundSessionXtnd& iParent;
259 //Objects (owned or referred to):
260 RMMFAudioPolicyProxy* iAudioPolicyProxy;
261 CMMFAudioPolicyRequest* iAudioPolicyRequest;
262 MDevSoundObserver* iDevSoundObserver;
264 // Handles receiving events
265 CMMFDevSoundEventHandler* iDevSoundEventHandler;
267 //WINS Sound Device Structures
268 RMdaDevSound::TSoundFormatsSupportedBuf iPlayFormatsSupported;
269 RMdaDevSound::TCurrentSoundFormatBuf iPlayFormat;
270 RMdaDevSound::TSoundFormatsSupportedBuf iRecordFormatsSupported;
271 RMdaDevSound::TCurrentSoundFormatBuf iRecordFormat;
273 // DevSound capabilities
274 TMMFCapabilities iDeviceCapabilities;
275 // Current Configuration
276 TMMFCapabilities iDeviceConfig;
278 // AudioPolicy priority used to communicate with server
279 TMMFAudioPolicyPrioritySettings iAudioPolicyPrioritySettings;
281 MPlayCustomInterface* iPlayCustomInterface;
282 MRecordCustomInterface* iRecordCustomInterface;
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;
290 TMMFDevSoundInfo iDevSoundInfo;
293 MMdaToneSynthesis* iCurrentGenerator;
294 TMdaSimpleToneGenerator iToneGen;
295 TMdaDualToneGenerator iDualToneGen;
296 TMdaDTMFGenerator iDTMFGen;
297 TMdaSequenceGenerator iSequenceGen; // Not Supported
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;
307 // Hardware device implementation
308 CMMFHwDevice2* iCMMFHwDevice;
310 // Mode in which DevSound instance will be used for
312 // Reference to hardware buffer
313 CMMFDataBuffer* iHwDeviceBuffer;
315 TBool iLastBufferReceived;
317 // Holds true of Audio data given to DevSound needs to ramped up
318 CMMFDevSoundUtility* iDevSoundUtil;
320 // Fixed sequence related
321 CPtrC8Array* iFixedSequences; // Holds the fixed sequence data
322 TPtrC8 iFixedSequence; // Holds reference to current sequence
325 TInt iLeftPlayBalance;
326 TInt iRightPlayBalance;
328 TInt iLeftRecordBalance;
329 TInt iRightRecordBalance;
335 // Hardware device initialization parameters
336 THwDeviceInitParams iDevInfo;
338 TBool iFirstCallFromHwDevice;
340 // AO to manage the initialisation of the RoutingSoundDevice
341 CRoutingSoundDeviceHandler* iRSDHandler;
343 friend class CMMFDevSoundSession;
346 #include "MmfBtDevSoundSessionBody.inl"
348 #endif // __MMFBTDEVSOUNDSESSIONBODY__H__