Update contrib.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #ifndef SOUNDDEVICEBODY_H
21 #define SOUNDDEVICEBODY_H
24 #include <mmf/server/sounddevice.h>
25 #include "mmfdevsoundproxy.h"
26 #include <mmf/server/mmfdevsoundcustominterfacesupport.h>
27 #include <mmf/server/mmfdevsoundcustominterface.h>
28 #include <a3f/mmfdevsoundcustominterfaceextensions.h>
29 #include "MmfDevSoundCIMuxUtility.h"
32 * This is the Body for CMMFDevSound.
34 * @lib MMFDevSound.lib
37 NONSHARABLE_CLASS( CMMFDevSound::CBody ) : public CBase,
38 public MMMFDevSoundCancelInitialize,
39 public MMMFDevSoundCustomInterfaceChannel,
40 public MMMFDevSoundCustomInterfaceObserver,
41 public MMMFDevSoundEmptyBuffers,
42 public MAutoPauseResumeSupport,
43 public MMMFDevSoundTimePlayed,
44 public MMMFDevSoundQueryIgnoresUnderflow,
45 public MAudioClientThreadInfo,
46 public MMMFDevSoundTruePause
49 public: // Constructors and destructor
52 * Factory function - returning instance of the class.
59 * Deletes all objects and releases all resources owned by this
65 * Initializes to raw audio data PCM16 and Sampling Rate of 8 KHz.
66 * On completion of Initialization, calls InitializeComplete() on
68 * @param aDevSoundObserver. A reference to DevSound observer instance.
69 * @param aMode. Mode for which this object will be used.
71 void InitializeL(MDevSoundObserver& aDevSoundObserver,
75 * Initializes DevSound object for the mode aMode for processing audio
76 * data with hardware device supporting FourCC aDesiredFourCC.
77 * @param aDevSoundObserver. A reference to DevSound observer instance.
78 * @param aDesiredFourCC. The CMMFHwDevice implementation FourCC code.
79 * @param aMode. The mode for which this object will be used
81 void InitializeL(MDevSoundObserver& aDevSoundObserver,
82 TFourCC aDesiredFourCC,
86 * Returns the supported Audio settings ie. encoding, sample rates,
87 * mono/stereo operation, buffer size etc..
88 * @return TMMFCapabilities. The device settings.
90 inline TMMFCapabilities Capabilities();
93 * Returns the current device configuration.
94 * @return TMMFCapabilities. The device settings.
96 inline TMMFCapabilities Config() const;
99 * Configure CMMFDevSound object with the settings in aConfig. Use this
100 * to set sampling rate, encoding and mono/stereo.
101 * @param aConfig. The attribute values to which CMMFDevSound object will be configured to.
103 inline void SetConfigL(const TMMFCapabilities& aCaps);
106 * Returns an integer representing the maximum volume device supports.
107 * This is the maximum value which can be passed to
108 * CMMFDevSound::SetVolume.
109 * @return TInt The maximum volume. This value is platform dependent but is always greater than or equal to one.
111 inline TInt MaxVolume();
114 * Returns an integer representing the current volume.
115 * @return TInt The current volume level.
117 inline TInt Volume();
120 * Changes the current playback volume to a specified value. The volume
121 * can be changed before or during playback and is effective immediately.
122 * @param aVolume. The volume setting. This can be any value from 0
123 * to the value returned by a call to
124 * CMMFDevSound::MaxVolume(). If the volume is not
125 * within this range, the volume is automatically set
126 * to minimum or maximum value based on the value
127 * that is being passed. Setting a zero value mutes
128 * the sound. Setting the maximum value results in
129 * the loudest possible sound.
131 inline void SetVolume(TInt aVolume);
134 * Returns an integer representing the maximum gain the device supports.
135 * This is the maximum value which can be passed to CMMFDevSound::SetGain
136 * @return TInt The maximum gain. This value is platform dependent but is
137 * always greater than or equal to one.
139 inline TInt MaxGain();
142 * Returns an integer representing the current gain.
143 * @return TInt The current gain level.
148 * Changes the current recording gain to a specified value. The gain can
149 * be changed before or during recording and is effective immediately.
150 * @param aGain. The gain setting. This can be any value from zero to
151 * the value returned by a call to
152 * CMMFDevSound::MaxGain(). If the volume
153 * is not within this range, the gain is automatically
154 * set to minimum or maximum value based on the value
155 * that is being passed. Setting a zero value mutes the
156 * sound. Setting the maximum value results in the
157 * loudest possible sound.
159 inline void SetGain(TInt aGain);
162 * Returns the speaker balance set for playing.
163 * @param aLeftPercentage. On return contains the left speaker volume percentage.
164 * @param aRightPercentage. On return contains the right speaker volume percentage.
166 inline void GetPlayBalanceL(TInt& aLeftPercentage,TInt& aRightPercentage);
169 * Sets the speaker balance for playing. The speaker balance can be
170 * changed before or during playback and is effective immediately.
171 * @param aLeftPercentage. The left speaker volume percentage. This
172 * can be any value from zero to 100. Setting
173 * a zero value mutes the sound on left
175 * @param aRightPercentage. The right speaker volume percentage.
176 * This can be any value from zero to 100.
177 * Setting a zero value mutes the sound on
180 inline void SetPlayBalanceL(TInt aLeftPercentage,
181 TInt aRightPercentage);
184 * Returns the microphone gain balance set for recording.
185 * @param aLeftPercentage On return contains the left microphone
187 * @param aRightPercentage On return contains the right microphone
190 inline void GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage);
193 * Sets the microphone balance for recording. The microphone balance can
194 * be changed before or during recording and is effective immediately.
195 * @param aLeftPercentage. The left microphone gain percentage. This
196 * can be any value from zero to 100. Setting
197 * a zero value mutes the sound from left
199 * @param aRightPercentage. The right microphone gain percentage.
200 * This can be any value from zero to 100.
201 * Setting a zero value mutes the sound from
204 inline void SetRecordBalanceL(TInt aLeftPercentage,
205 TInt aRightPercentage);
208 * Initializes the audio device and starts the play process. This
209 * function queries and acquires the audio policy before initializing
210 * audio device. If there was an error during policy initialization,
211 * PlayError() function will be called on the observer with error code
212 * KErrAccessDenied, otherwise BufferToBeFilled() function will be called
213 * with a buffer reference. After reading data into the buffer reference
214 * passed, the client should call PlayData() to play data.
215 * The amount of data that can be played is specified in
216 * CMMFBuffer::RequestSize(). Any data that is read into buffer beyond
217 * this size will be ignored.
219 inline void PlayInitL();
222 * Initializes the audio device and starts the record process. This
223 * function queries and acquires the audio policy before initializing
224 * audio device. If there was an error during policy initialization,
225 * RecordError() function will be called on the observer with error code
226 * KErrAccessDenied, otherwise BufferToBeEmptied() function will be
227 * called with a buffer reference. This buffer contains recorded or
228 * encoded data. After processing data in the buffer reference passed,
229 * the client should call RecordData() to continue recording process.
230 * The amount of data that is available is specified in
231 * CMMFBuffer::RequestSize().
233 inline void RecordInitL();
236 * Plays data in the buffer at the current volume.
237 * The client should fill the buffer with audio data before calling this
238 * function. The observer gets a reference to the buffer along with the
239 * callback function BufferToBeFilled(). When playing of the audio sample
240 * is complete, successfully or otherwise, the function PlayError() on
241 * the observer is called.
242 * The last buffer of the audio stream being played should have the last
243 * buffer flag set using CMMFBuffer::SetLastBuffer(TBool). If a
244 * subsequent attempt to play the clip is made, this flag will need
245 * resetting by the client.
247 inline void PlayData();
250 * Contine the process of recording.
251 * Once the buffer is filled with recorded data, the Observer gets a
252 * reference to the buffer along with the callback function
253 * BufferToBeEmptied(). After processing the buffer (copying over to a
254 * different buffer or writing to file) the client should call this
255 * function to continue the recording process.
257 inline void RecordData();
260 * Stops the ongoing operation (Play, Record, TonePlay).
265 * Temporarily Stops the ongoing operation (Play, Record, TonePlay).
270 * Returns the Sample recorded so far
271 * @return TInt Returns the samples recorded.
273 inline TInt SamplesRecorded();
276 * Returns the Sample played so far
277 * @return TInt Returns the samples played.
279 inline TInt SamplesPlayed();
282 * Initializes the audio device and starts playing a tone. The tone is
283 * played with the frequency and duration specified.
285 * @param aFrequency. The frequency at which the tone will be played.
286 * @param const TTimeIntervalMicroSeconds &aDuration The period over
287 * which the tone will be played. A zero value causes the no tone
290 inline void PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
293 * Initializes audio device and starts playing a dual tone. Dual Tone is
294 * played with the specified frequencies and for the specified duration.
295 * @param aFrequencyOne The first frequency of dual tone.
296 * @param aFrequencyTwo The second frequency of dual tone.
297 * @param aDuration The period over which the tone will be played.
298 * A zero value causes the no tone to be played.
300 inline void PlayDualToneL(
303 const TTimeIntervalMicroSeconds& aDuration);
306 * Initializes the audio device and starts playing the DTMF string
308 * @param aDTMFString The DTMF sequence in a descriptor.
310 inline void PlayDTMFStringL(const TDesC& aDTMFString);
313 * Initializes the audio device and starts playing a tone sequence.
314 * @param aData The tone sequence in a descriptor.
316 inline void PlayToneSequenceL(const TDesC8& aData);
319 * Defines the number of times the audio is to be repeated during the
320 * tone playback operation. A period of silence can follow each playing
321 * of a tone. The tone playing can be repeated indefinitely
322 * @param aRepeatCount. The number of times the tone, together with
323 * the trailing silence, is to be repeated. If this is set to
324 * KMdaRepeatForever, then the tone, together with the trailing
325 * silence, is repeated indefinitely or until Stop() is called.
326 * If this is set to zero, then the tone is not repeated.
327 * @param aRepeatTrailingSilence An interval of silence which will be played after each tone.
328 * Supported only during tone playing.
330 inline void SetToneRepeats(
332 const TTimeIntervalMicroSeconds& aRepeatTrailingSilence);
335 * Defines the duration of tone on, tone off and tone pause to be used
336 * during the DTMF tone playback operation.
337 * Supported only during tone playing.
338 * @param aToneOnLength The period over which the tone will be played.
339 * If this is set to zero, then the tone is not played.
340 * @param aToneOffLength The period over which the no tone will be played.
341 * @param aPauseLength The period over which the tone playing will be paused.
343 inline void SetDTMFLengths(
344 TTimeIntervalMicroSeconds32& aToneOnLength,
345 TTimeIntervalMicroSeconds32& aToneOffLength,
346 TTimeIntervalMicroSeconds32& aPauseLength);
349 * Defines the period over which the volume level is to rise smoothly
350 * from nothing to the normal volume level.
351 * The function is only available before playing.
352 * @param aRampDuration The period over which the volume is to rise.
353 * A zero value causes the tone sample to be played at the
354 * normal level for the full duration of the playback.
355 * A value, which is longer than the duration of
356 * the tone sample means that the sample never reaches its normal
359 inline void SetVolumeRamp(
360 const TTimeIntervalMicroSeconds& aRampDuration);
363 * Defines the priority settings that should be used for this instance.
364 * @param aPrioritySettings. A class type representing the client's priority,
365 * priority preference and state
367 inline void SetPrioritySettings(
368 const TMMFPrioritySettings& aPrioritySettings);
371 * Retrieves a custom interface to the device.
372 * @param aInterfaceId. The interface UID, defined with the custom
374 * @return TAny* A pointer to the interface implementation, or NULL if
375 * the device does not implement the interface requested. The
376 * return value must be cast to the correct type by the user.
378 TAny* CustomInterface(TUid aInterfaceId);
381 * Returns a list of the supported input datatypes that can be sent to
382 * DevSound for playing audio. The datatypes returned are those that the
383 * DevSound supports given the priority settings passed in
384 * aPrioritySettings. Note that if no supported data types are found this
385 * does not constitute failure, the function will return normally with no
386 * entries in aSupportedDataTypes.
387 * @param aSupportedDataTypes The array of supported
388 * data types that will be filled in by this function. The
389 * supported data types of the DevSound are in the form of an
390 * array of TFourCC codes. Any existing entries in the array will
391 * be overwritten on calling this function. If no supported data
392 * types are found given the priority settings, then the
393 * aSupportedDatatypes array will have zero entries.
394 * @param aPrioritySettings The priority settings used to determine the
395 * supported datatypes. Note this does not set the priority settings.
396 * For input datatypes the iState member of the priority settings would
397 * be expected to be either EMMFStatePlaying or EMMFStatePlayingRecording.
398 * The priority settings may effect the supported datatypes depending
399 * on the audio routing.
401 inline void GetSupportedInputDataTypesL(
402 RArray<TFourCC>& aSupportedDataTypesconst,
403 const TMMFPrioritySettings& aPrioritySettings) const;
406 * Returns a list of the supported output dataypes that can be received
407 * from DevSound for recording audio. The datatypes returned are those
408 * that the DevSound supports given the priority settings passed in
409 * aPrioritySettings. Note that if no supported data types are found this
410 * does not constitute failure, the function will return normally with no
411 * entries in aSupportedDataTypes.
412 * @param aSupportedDataTypes. The array of supported
413 * data types that will be filled in by this function. The
414 * supported datatypes of the DevSound are in the form of an array
415 * of TFourCC codes. Any existing entries in the array will be
416 * overwritten on calling this function. If no supported datatypes
417 * are found given the priority settings, then the
418 * aSupportedDatatypes array will have zero entries.
419 * @param aPrioritySettings. The priority settings used to determine the supported
420 * data types. Note this does not set the priority settings. For output data types the
421 * iState member of the priority settings would expected to be
422 * either EMMFStateRecording or EMMFStatePlayingRecording. The
423 * priority settings may effect the supported datatypes depending
424 * on the audio routing.
426 inline void GetSupportedOutputDataTypesL(
427 RArray<TFourCC>& aSupportedDataTypes,
428 const TMMFPrioritySettings& aPrioritySettings) const;
431 Registers the client for notification of resource avalibility.
434 The Notification event type for which the client needs notification.
435 @param aNotificationRegistrationData
436 The Notification Registration data has been reserved for future use and its value should be always NULL
437 @return An error code indicating if the function call was successful. KErrNone on success,
438 KErrNotSupported if the event type is not supported, KErrArgument if the notification data
439 is not null otherwise another of the system-wide error codes.
441 inline TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData = KNullDesC8);
444 Cancels the Registered Notification.
446 @param aEventType. The Event type need to cancel
447 @return An error code indicating if the function call was successful. KErrNone on success, KErrNotSupported
448 if the event type is not supported otherwise another of the system-wide error codes.
450 inline TInt CancelRegisterAsClient(TUid aEventType);
453 Returns the Notification data which the client needs to resume playing.
455 @param aEventType. The Event type for which to get notification data
456 @param aNotificationData
457 The reference data for which the client needs to resume the play. The actual data depends on the event type.
458 Note that for the event type 'KMMFEventCategoryAudioResourceAvailable' the package buffer returned
459 is TMMFTimeIntervalMicroSecondsPckg,but the contents should be converted to an integer and
460 interpreted as the data returned is samples played ,but not as a microsecond value.
461 @return An error code indicating if the function call was successful. KErrNone on success, otherwise
462 another of the system-wide error codes.
464 inline TInt GetResourceNotificationData(TUid aEventType,TDes8& aNotificationData);
467 Wait for the clients to resume play back even after the default timeout expires.
468 Unless the client cancels the notification request or completes no other client gets
471 @return An error code indicating if the function call was successful. KErrNone on success,
472 otherwise another of the system-wide error codes.
474 inline TInt WillResumePlay();
477 Empties the play buffers below DevSound without causing the codec to be deleted.
479 @return An error code indicating if the function call was successful. KErrNone on success,
480 KErrNotSupported if called in a mode other than EMMFStatePlaying or if the function is otherwise not supported,
481 KErrNotReady if this is called before playing,
482 otherwise another of the system-wide error codes.
483 If this function is not supported, it is advised to use Stop().
485 inline TInt EmptyBuffers();
487 //from MMMFDevSoundCancelInitialize
490 Cancels the initialization process of a CMMFDevSound object
492 @return An error code indicating if the function call was successful.
494 KerrNotReady if this is called before InitializeL() call or after
495 the object has been initialized
497 inline TInt CancelInitialize();
499 // from MMMFDevSoundCustomInterfaceChannel
501 Implements a synchronous custom command
503 The UID of the custom command
505 A buffer of data to be supplied to the receiver
507 A buffer of data to be supplied to the receiver
509 A buffer that will be written into by the receiver
510 and returned to the client
511 @return the result of the custom command
513 TInt SyncCustomCommand(TUid aUid, const TDesC8& aParam1, const TDesC8& aParam2, TDes8* aOutParam);
516 Implements an asynchronous custom command
518 The UID of the custom command
520 The request status of the active object that
521 will be called upon the completion of the request
523 A buffer of data to be supplied to the receiver
525 A buffer of data to be supplied to the receiver
527 A buffer that will be written into by the receiver
528 and returned to the client
530 void AsyncCustomCommand(TUid aUid, TRequestStatus& aStatus, const TDesC8& aParam1, const TDesC8& aParam2, TDes8* aOutParam);
532 //from MMMFDevSoundCustomInterfaceObserver
533 void CloseCustomInterface(TInt aInterfaceId);
535 //from MMMFDevSoundTimePlayed
536 TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTime);
538 //MMMFDevSoundQueryIgnoresUnderflow
539 TBool QueryIgnoresUnderflow();
541 // Set the real client thread with thread Id
542 TInt SetClientThreadInfo(TThreadId aTid);
544 // from MMMFDevSoundTruePause
545 TBool IsResumeSupported();
555 * Symbian constructor
559 TInt FindCustomInterface(TUid aInterfaceId);
561 // custom interface storage
562 RArray<TMMFDevSoundCustomInterfaceData> iCustomInterfaceArray;
563 CMMFDevSoundCIMuxUtility* iMuxUtility;
564 // Reference to DevSound proxy
565 RMMFDevSoundProxy* iDevSoundProxy;
567 MDevSoundCIClientExtension* iCIExtension;
570 #include "sounddevicebody.inl"
572 #endif // SOUNDDEVICEBODY_H