os/mm/devsound/devsoundrefplugin/src/platsec/server/AudioServer/MmfDevSoundSessionBody.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.
14 // DevSoundSessionBody.h
18 #ifndef MMFDEVSOUNDSESSIONBODY_H
19 #define MMFDEVSOUNDSESSIONBODY_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"
30 #ifdef SYMBIAN_MDF_SHAREDCHUNK_SOUNDDRIVER
31 #include "mdasoundadapter.h"
36 #include <mmf/server/devsoundstandardcustominterfaces.h>
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;
46 class CDevSoundPlayer;
48 class CDevSoundRecorder;
49 class CDevSoundRecordError;
50 class CMMFDevSoundProxyXtnd;
53 class CMMFHwDeviceObserver;
54 class MPlayCustomInterface;
55 class MRecordCustomInterface;
56 class MEmptyBuffersCustomInterface;
57 class MTimePlayedCustomInterface;
61 * Reference internals for CMMFDevSound
65 class CMMFDevSoundSvrImp;
66 NONSHARABLE_CLASS( CMMFDevSoundSvrImp ) : public CBase, public MMMFHwDeviceObserver,
67 public MMMFDevSoundCustomInterfaceTarget
70 static CMMFDevSoundSvrImp* NewL(CMMFDevSoundSessionXtnd* aParent);
71 ~CMMFDevSoundSvrImp();
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);
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);
88 // Returns maximum play volume device supports
90 // Returns play volume device is configured to
92 // Sets device play volume
93 void SetVolume(TInt aVolume);
95 // Returns maximum record gain device supports
97 // Returns record gain device is configured to
99 // Sets device record gain
100 void SetGain(TInt aGain);
102 // Returns play balance
103 void GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
105 void SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
107 // Returns record balance
108 void GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
109 // Sets record balance
110 void SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage);
112 // Initializes audio device and start play process
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
122 // Tempororily Stops the ongoing operation
125 // Returns the Sample recorded so far
126 TInt SamplesRecorded();
127 // Returns the Sample played so far
128 TInt SamplesPlayed();
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);
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);
153 // Provides interface for sending custom commands for the audio device
154 virtual TAny* CustomInterface(TUid aInterfaceId);
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;
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();
187 // CMMFHwDevice implementation:
188 TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
189 TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer);
190 TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg);
192 void Error(TInt aError);
193 // CMMFHwDevice implementation ends
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
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);
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);
223 void RequestPolicy();
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
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);
247 enum TMMFDevSoundState
251 EMMFDevSoundStateIdle,
252 /** The DevSound is currently playing.
254 EMMFDevSoundStatePlaying,
255 /** The DevSound is playing a tone.
257 EMMFDevSoundStateTonePlaying,
258 /** The DevSound is currently recording.
260 EMMFDevSoundStateRecording,
261 /** The DevSound is playing and recording.
263 EMMFDevSoundStatePlayingRecording,
264 /** The DevSound is converting data.
266 EMMFDevSoundStateConverting
270 CMMFDevSoundSessionXtnd& iParent;
272 //Objects (owned or referred to):
273 RMMFAudioPolicyProxy* iAudioPolicyProxy;
274 CMMFAudioPolicyRequest* iAudioPolicyRequest;
275 MDevSoundObserver* iDevSoundObserver;
277 // Handles receiving events
278 CMMFDevSoundEventHandler* iDevSoundEventHandler;
280 //WINS Sound Device Structures
281 RMdaDevSound::TSoundFormatsSupportedBuf iPlayFormatsSupported;
282 RMdaDevSound::TCurrentSoundFormatBuf iPlayFormat;
283 RMdaDevSound::TSoundFormatsSupportedBuf iRecordFormatsSupported;
284 RMdaDevSound::TCurrentSoundFormatBuf iRecordFormat;
286 // DevSound capabilities
287 TMMFCapabilities iDeviceCapabilities;
288 // Current Configuration
289 TMMFCapabilities iDeviceConfig;
291 // AudioPolicy priority used to communicate with server
292 TMMFAudioPolicyPrioritySettings iAudioPolicyPrioritySettings;
294 MPlayCustomInterface* iPlayCustomInterface;
295 MRecordCustomInterface* iRecordCustomInterface;
297 // Bytes of audio data played in current play cycle
298 TInt iPlayedBytesCount;
301 TMMFDevSoundInfo iDevSoundInfo;
304 MMdaToneSynthesis* iCurrentGenerator;
305 TMdaSimpleToneGenerator iToneGen;
306 TMdaDualToneGenerator iDualToneGen;
307 TMdaDTMFGenerator iDTMFGen;
308 TMdaSequenceGenerator iSequenceGen; // Not Supported
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;
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;
325 TBool iLastBufferReceived;
327 // Holds true of Audio data given to DevSound needs to ramped up
328 CMMFDevSoundUtility* iDevSoundUtil;
330 // Fixed sequence related
331 CPtrC8Array* iFixedSequences; // Holds the fixed sequence data
332 TPtrC8 iFixedSequence; // Holds reference to current sequence
335 TInt iLeftPlayBalance;
336 TInt iRightPlayBalance;
338 TInt iLeftRecordBalance;
339 TInt iRightRecordBalance;
345 // Hardware device initialization parameters
346 THwDeviceInitParams iDevInfo;
348 TBool iFirstCallFromHwDevice;
354 MTimePlayedCustomInterface* iTimePlayedCustomInterface;
355 TTimeIntervalMicroSeconds iTimePlayed;
356 friend class CMMFDevSoundSession;
359 #include "MmfDevSoundSessionBody.inl"
361 #endif // MMFDEVSOUNDSESSIONBODY__H