sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #ifndef SOUNDDEVICEBODY_H sl@0: #define SOUNDDEVICEBODY_H sl@0: sl@0: // INCLUDES sl@0: #include sl@0: #include "mmfdevsoundproxy.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "MmfDevSoundCIMuxUtility.h" sl@0: sl@0: /** sl@0: * This is the Body for CMMFDevSound. sl@0: * sl@0: * @lib MMFDevSound.lib sl@0: */ sl@0: sl@0: NONSHARABLE_CLASS( CMMFDevSound::CBody ) : public CBase, sl@0: public MMMFDevSoundCancelInitialize, sl@0: public MMMFDevSoundCustomInterfaceChannel, sl@0: public MMMFDevSoundCustomInterfaceObserver, sl@0: public MMMFDevSoundEmptyBuffers, sl@0: public MAutoPauseResumeSupport, sl@0: public MMMFDevSoundTimePlayed, sl@0: public MMMFDevSoundQueryIgnoresUnderflow, sl@0: public MAudioClientThreadInfo, sl@0: public MMMFDevSoundTruePause sl@0: sl@0: { sl@0: public: // Constructors and destructor sl@0: sl@0: /** sl@0: * Factory function - returning instance of the class. sl@0: */ sl@0: static CBody* NewL(); sl@0: sl@0: /** sl@0: * Destructor. sl@0: sl@0: * Deletes all objects and releases all resources owned by this sl@0: * instance. sl@0: */ sl@0: ~CBody(); sl@0: sl@0: /** sl@0: * Initializes to raw audio data PCM16 and Sampling Rate of 8 KHz. sl@0: * On completion of Initialization, calls InitializeComplete() on sl@0: * aDevSoundObserver. sl@0: * @param aDevSoundObserver. A reference to DevSound observer instance. sl@0: * @param aMode. Mode for which this object will be used. sl@0: */ sl@0: void InitializeL(MDevSoundObserver& aDevSoundObserver, sl@0: TMMFState aMode); sl@0: sl@0: /** sl@0: * Initializes DevSound object for the mode aMode for processing audio sl@0: * data with hardware device supporting FourCC aDesiredFourCC. sl@0: * @param aDevSoundObserver. A reference to DevSound observer instance. sl@0: * @param aDesiredFourCC. The CMMFHwDevice implementation FourCC code. sl@0: * @param aMode. The mode for which this object will be used sl@0: */ sl@0: void InitializeL(MDevSoundObserver& aDevSoundObserver, sl@0: TFourCC aDesiredFourCC, sl@0: TMMFState aMode); sl@0: sl@0: /** sl@0: * Returns the supported Audio settings ie. encoding, sample rates, sl@0: * mono/stereo operation, buffer size etc.. sl@0: * @return TMMFCapabilities. The device settings. sl@0: */ sl@0: inline TMMFCapabilities Capabilities(); sl@0: sl@0: /** sl@0: * Returns the current device configuration. sl@0: * @return TMMFCapabilities. The device settings. sl@0: */ sl@0: inline TMMFCapabilities Config() const; sl@0: sl@0: /** sl@0: * Configure CMMFDevSound object with the settings in aConfig. Use this sl@0: * to set sampling rate, encoding and mono/stereo. sl@0: * @param aConfig. The attribute values to which CMMFDevSound object will be configured to. sl@0: */ sl@0: inline void SetConfigL(const TMMFCapabilities& aCaps); sl@0: sl@0: /** sl@0: * Returns an integer representing the maximum volume device supports. sl@0: * This is the maximum value which can be passed to sl@0: * CMMFDevSound::SetVolume. sl@0: * @return TInt The maximum volume. This value is platform dependent but is always greater than or equal to one. sl@0: */ sl@0: inline TInt MaxVolume(); sl@0: sl@0: /** sl@0: * Returns an integer representing the current volume. sl@0: * @return TInt The current volume level. sl@0: */ sl@0: inline TInt Volume(); sl@0: sl@0: /** sl@0: * Changes the current playback volume to a specified value. The volume sl@0: * can be changed before or during playback and is effective immediately. sl@0: * @param aVolume. The volume setting. This can be any value from 0 sl@0: * to the value returned by a call to sl@0: * CMMFDevSound::MaxVolume(). If the volume is not sl@0: * within this range, the volume is automatically set sl@0: * to minimum or maximum value based on the value sl@0: * that is being passed. Setting a zero value mutes sl@0: * the sound. Setting the maximum value results in sl@0: * the loudest possible sound. sl@0: */ sl@0: inline void SetVolume(TInt aVolume); sl@0: sl@0: /** sl@0: * Returns an integer representing the maximum gain the device supports. sl@0: * This is the maximum value which can be passed to CMMFDevSound::SetGain sl@0: * @return TInt The maximum gain. This value is platform dependent but is sl@0: * always greater than or equal to one. sl@0: */ sl@0: inline TInt MaxGain(); sl@0: sl@0: /** sl@0: * Returns an integer representing the current gain. sl@0: * @return TInt The current gain level. sl@0: */ sl@0: inline TInt Gain(); sl@0: sl@0: /** sl@0: * Changes the current recording gain to a specified value. The gain can sl@0: * be changed before or during recording and is effective immediately. sl@0: * @param aGain. The gain setting. This can be any value from zero to sl@0: * the value returned by a call to sl@0: * CMMFDevSound::MaxGain(). If the volume sl@0: * is not within this range, the gain is automatically sl@0: * set to minimum or maximum value based on the value sl@0: * that is being passed. Setting a zero value mutes the sl@0: * sound. Setting the maximum value results in the sl@0: * loudest possible sound. sl@0: */ sl@0: inline void SetGain(TInt aGain); sl@0: sl@0: /** sl@0: * Returns the speaker balance set for playing. sl@0: * @param aLeftPercentage. On return contains the left speaker volume percentage. sl@0: * @param aRightPercentage. On return contains the right speaker volume percentage. sl@0: */ sl@0: inline void GetPlayBalanceL(TInt& aLeftPercentage,TInt& aRightPercentage); sl@0: sl@0: /** sl@0: * Sets the speaker balance for playing. The speaker balance can be sl@0: * changed before or during playback and is effective immediately. sl@0: * @param aLeftPercentage. The left speaker volume percentage. This sl@0: * can be any value from zero to 100. Setting sl@0: * a zero value mutes the sound on left sl@0: * speaker. sl@0: * @param aRightPercentage. The right speaker volume percentage. sl@0: * This can be any value from zero to 100. sl@0: * Setting a zero value mutes the sound on sl@0: * right speaker. sl@0: */ sl@0: inline void SetPlayBalanceL(TInt aLeftPercentage, sl@0: TInt aRightPercentage); sl@0: sl@0: /** sl@0: * Returns the microphone gain balance set for recording. sl@0: * @param aLeftPercentage On return contains the left microphone sl@0: * gain percentage. sl@0: * @param aRightPercentage On return contains the right microphone sl@0: * gain percentage. sl@0: */ sl@0: inline void GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage); sl@0: sl@0: /** sl@0: * Sets the microphone balance for recording. The microphone balance can sl@0: * be changed before or during recording and is effective immediately. sl@0: * @param aLeftPercentage. The left microphone gain percentage. This sl@0: * can be any value from zero to 100. Setting sl@0: * a zero value mutes the sound from left sl@0: * microphone. sl@0: * @param aRightPercentage. The right microphone gain percentage. sl@0: * This can be any value from zero to 100. sl@0: * Setting a zero value mutes the sound from sl@0: * right microphone. sl@0: */ sl@0: inline void SetRecordBalanceL(TInt aLeftPercentage, sl@0: TInt aRightPercentage); sl@0: sl@0: /** sl@0: * Initializes the audio device and starts the play process. This sl@0: * function queries and acquires the audio policy before initializing sl@0: * audio device. If there was an error during policy initialization, sl@0: * PlayError() function will be called on the observer with error code sl@0: * KErrAccessDenied, otherwise BufferToBeFilled() function will be called sl@0: * with a buffer reference. After reading data into the buffer reference sl@0: * passed, the client should call PlayData() to play data. sl@0: * The amount of data that can be played is specified in sl@0: * CMMFBuffer::RequestSize(). Any data that is read into buffer beyond sl@0: * this size will be ignored. sl@0: */ sl@0: inline void PlayInitL(); sl@0: sl@0: /** sl@0: * Initializes the audio device and starts the record process. This sl@0: * function queries and acquires the audio policy before initializing sl@0: * audio device. If there was an error during policy initialization, sl@0: * RecordError() function will be called on the observer with error code sl@0: * KErrAccessDenied, otherwise BufferToBeEmptied() function will be sl@0: * called with a buffer reference. This buffer contains recorded or sl@0: * encoded data. After processing data in the buffer reference passed, sl@0: * the client should call RecordData() to continue recording process. sl@0: * The amount of data that is available is specified in sl@0: * CMMFBuffer::RequestSize(). sl@0: */ sl@0: inline void RecordInitL(); sl@0: sl@0: /** sl@0: * Plays data in the buffer at the current volume. sl@0: * The client should fill the buffer with audio data before calling this sl@0: * function. The observer gets a reference to the buffer along with the sl@0: * callback function BufferToBeFilled(). When playing of the audio sample sl@0: * is complete, successfully or otherwise, the function PlayError() on sl@0: * the observer is called. sl@0: * The last buffer of the audio stream being played should have the last sl@0: * buffer flag set using CMMFBuffer::SetLastBuffer(TBool). If a sl@0: * subsequent attempt to play the clip is made, this flag will need sl@0: * resetting by the client. sl@0: */ sl@0: inline void PlayData(); sl@0: sl@0: /** sl@0: * Contine the process of recording. sl@0: * Once the buffer is filled with recorded data, the Observer gets a sl@0: * reference to the buffer along with the callback function sl@0: * BufferToBeEmptied(). After processing the buffer (copying over to a sl@0: * different buffer or writing to file) the client should call this sl@0: * function to continue the recording process. sl@0: */ sl@0: inline void RecordData(); sl@0: sl@0: /** sl@0: * Stops the ongoing operation (Play, Record, TonePlay). sl@0: */ sl@0: inline void Stop(); sl@0: sl@0: /** sl@0: * Temporarily Stops the ongoing operation (Play, Record, TonePlay). sl@0: */ sl@0: inline void Pause(); sl@0: sl@0: /** sl@0: * Returns the Sample recorded so far sl@0: * @return TInt Returns the samples recorded. sl@0: */ sl@0: inline TInt SamplesRecorded(); sl@0: sl@0: /** sl@0: * Returns the Sample played so far sl@0: * @return TInt Returns the samples played. sl@0: */ sl@0: inline TInt SamplesPlayed(); sl@0: sl@0: /** sl@0: * Initializes the audio device and starts playing a tone. The tone is sl@0: * played with the frequency and duration specified. sl@0: * Leaves on failure. sl@0: * @param aFrequency. The frequency at which the tone will be played. sl@0: * @param const TTimeIntervalMicroSeconds &aDuration The period over sl@0: * which the tone will be played. A zero value causes the no tone sl@0: * to be played. sl@0: */ sl@0: inline void PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration); sl@0: sl@0: /** sl@0: * Initializes audio device and starts playing a dual tone. Dual Tone is sl@0: * played with the specified frequencies and for the specified duration. sl@0: * @param aFrequencyOne The first frequency of dual tone. sl@0: * @param aFrequencyTwo The second frequency of dual tone. sl@0: * @param aDuration The period over which the tone will be played. sl@0: * A zero value causes the no tone to be played. sl@0: */ sl@0: inline void PlayDualToneL( sl@0: TInt aFrequencyOne, sl@0: TInt aFrequencyTwo, sl@0: const TTimeIntervalMicroSeconds& aDuration); sl@0: sl@0: /** sl@0: * Initializes the audio device and starts playing the DTMF string sl@0: * aDTMFString. sl@0: * @param aDTMFString The DTMF sequence in a descriptor. sl@0: */ sl@0: inline void PlayDTMFStringL(const TDesC& aDTMFString); sl@0: sl@0: /** sl@0: * Initializes the audio device and starts playing a tone sequence. sl@0: * @param aData The tone sequence in a descriptor. sl@0: */ sl@0: inline void PlayToneSequenceL(const TDesC8& aData); sl@0: sl@0: /** sl@0: * Defines the number of times the audio is to be repeated during the sl@0: * tone playback operation. A period of silence can follow each playing sl@0: * of a tone. The tone playing can be repeated indefinitely sl@0: * @param aRepeatCount. The number of times the tone, together with sl@0: * the trailing silence, is to be repeated. If this is set to sl@0: * KMdaRepeatForever, then the tone, together with the trailing sl@0: * silence, is repeated indefinitely or until Stop() is called. sl@0: * If this is set to zero, then the tone is not repeated. sl@0: * @param aRepeatTrailingSilence An interval of silence which will be played after each tone. sl@0: * Supported only during tone playing. sl@0: */ sl@0: inline void SetToneRepeats( sl@0: TInt aRepeatCount, sl@0: const TTimeIntervalMicroSeconds& aRepeatTrailingSilence); sl@0: sl@0: /** sl@0: * Defines the duration of tone on, tone off and tone pause to be used sl@0: * during the DTMF tone playback operation. sl@0: * Supported only during tone playing. sl@0: * @param aToneOnLength The period over which the tone will be played. sl@0: * If this is set to zero, then the tone is not played. sl@0: * @param aToneOffLength The period over which the no tone will be played. sl@0: * @param aPauseLength The period over which the tone playing will be paused. sl@0: */ sl@0: inline void SetDTMFLengths( sl@0: TTimeIntervalMicroSeconds32& aToneOnLength, sl@0: TTimeIntervalMicroSeconds32& aToneOffLength, sl@0: TTimeIntervalMicroSeconds32& aPauseLength); sl@0: sl@0: /** sl@0: * Defines the period over which the volume level is to rise smoothly sl@0: * from nothing to the normal volume level. sl@0: * The function is only available before playing. sl@0: * @param aRampDuration The period over which the volume is to rise. sl@0: * A zero value causes the tone sample to be played at the sl@0: * normal level for the full duration of the playback. sl@0: * A value, which is longer than the duration of sl@0: * the tone sample means that the sample never reaches its normal sl@0: * volume level. sl@0: */ sl@0: inline void SetVolumeRamp( sl@0: const TTimeIntervalMicroSeconds& aRampDuration); sl@0: sl@0: /** sl@0: * Defines the priority settings that should be used for this instance. sl@0: * @param aPrioritySettings. A class type representing the client's priority, sl@0: * priority preference and state sl@0: */ sl@0: inline void SetPrioritySettings( sl@0: const TMMFPrioritySettings& aPrioritySettings); sl@0: sl@0: /** sl@0: * Retrieves a custom interface to the device. sl@0: * @param aInterfaceId. The interface UID, defined with the custom sl@0: * interface. sl@0: * @return TAny* A pointer to the interface implementation, or NULL if sl@0: * the device does not implement the interface requested. The sl@0: * return value must be cast to the correct type by the user. sl@0: */ sl@0: TAny* CustomInterface(TUid aInterfaceId); sl@0: sl@0: /** sl@0: * Returns a list of the supported input datatypes that can be sent to sl@0: * DevSound for playing audio. The datatypes returned are those that the sl@0: * DevSound supports given the priority settings passed in sl@0: * aPrioritySettings. Note that if no supported data types are found this sl@0: * does not constitute failure, the function will return normally with no sl@0: * entries in aSupportedDataTypes. sl@0: * @param aSupportedDataTypes The array of supported sl@0: * data types that will be filled in by this function. The sl@0: * supported data types of the DevSound are in the form of an sl@0: * array of TFourCC codes. Any existing entries in the array will sl@0: * be overwritten on calling this function. If no supported data sl@0: * types are found given the priority settings, then the sl@0: * aSupportedDatatypes array will have zero entries. sl@0: * @param aPrioritySettings The priority settings used to determine the sl@0: * supported datatypes. Note this does not set the priority settings. sl@0: * For input datatypes the iState member of the priority settings would sl@0: * be expected to be either EMMFStatePlaying or EMMFStatePlayingRecording. sl@0: * The priority settings may effect the supported datatypes depending sl@0: * on the audio routing. sl@0: */ sl@0: inline void GetSupportedInputDataTypesL( sl@0: RArray& aSupportedDataTypesconst, sl@0: const TMMFPrioritySettings& aPrioritySettings) const; sl@0: sl@0: /** sl@0: * Returns a list of the supported output dataypes that can be received sl@0: * from DevSound for recording audio. The datatypes returned are those sl@0: * that the DevSound supports given the priority settings passed in sl@0: * aPrioritySettings. Note that if no supported data types are found this sl@0: * does not constitute failure, the function will return normally with no sl@0: * entries in aSupportedDataTypes. sl@0: * @param aSupportedDataTypes. The array of supported sl@0: * data types that will be filled in by this function. The sl@0: * supported datatypes of the DevSound are in the form of an array sl@0: * of TFourCC codes. Any existing entries in the array will be sl@0: * overwritten on calling this function. If no supported datatypes sl@0: * are found given the priority settings, then the sl@0: * aSupportedDatatypes array will have zero entries. sl@0: * @param aPrioritySettings. The priority settings used to determine the supported sl@0: * data types. Note this does not set the priority settings. For output data types the sl@0: * iState member of the priority settings would expected to be sl@0: * either EMMFStateRecording or EMMFStatePlayingRecording. The sl@0: * priority settings may effect the supported datatypes depending sl@0: * on the audio routing. sl@0: */ sl@0: inline void GetSupportedOutputDataTypesL( sl@0: RArray& aSupportedDataTypes, sl@0: const TMMFPrioritySettings& aPrioritySettings) const; sl@0: sl@0: /** sl@0: Registers the client for notification of resource avalibility. sl@0: sl@0: @param aEventType sl@0: The Notification event type for which the client needs notification. sl@0: @param aNotificationRegistrationData sl@0: The Notification Registration data has been reserved for future use and its value should be always NULL sl@0: @return An error code indicating if the function call was successful. KErrNone on success, sl@0: KErrNotSupported if the event type is not supported, KErrArgument if the notification data sl@0: is not null otherwise another of the system-wide error codes. sl@0: */ sl@0: inline TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData = KNullDesC8); sl@0: sl@0: /** sl@0: Cancels the Registered Notification. sl@0: sl@0: @param aEventType. The Event type need to cancel sl@0: @return An error code indicating if the function call was successful. KErrNone on success, KErrNotSupported sl@0: if the event type is not supported otherwise another of the system-wide error codes. sl@0: */ sl@0: inline TInt CancelRegisterAsClient(TUid aEventType); sl@0: sl@0: /** sl@0: Returns the Notification data which the client needs to resume playing. sl@0: sl@0: @param aEventType. The Event type for which to get notification data sl@0: @param aNotificationData sl@0: The reference data for which the client needs to resume the play. The actual data depends on the event type. sl@0: Note that for the event type 'KMMFEventCategoryAudioResourceAvailable' the package buffer returned sl@0: is TMMFTimeIntervalMicroSecondsPckg,but the contents should be converted to an integer and sl@0: interpreted as the data returned is samples played ,but not as a microsecond value. sl@0: @return An error code indicating if the function call was successful. KErrNone on success, otherwise sl@0: another of the system-wide error codes. sl@0: */ sl@0: inline TInt GetResourceNotificationData(TUid aEventType,TDes8& aNotificationData); sl@0: sl@0: /** sl@0: Wait for the clients to resume play back even after the default timeout expires. sl@0: Unless the client cancels the notification request or completes no other client gets sl@0: notification. sl@0: sl@0: @return An error code indicating if the function call was successful. KErrNone on success, sl@0: otherwise another of the system-wide error codes. sl@0: */ sl@0: inline TInt WillResumePlay(); sl@0: sl@0: /** sl@0: Empties the play buffers below DevSound without causing the codec to be deleted. sl@0: sl@0: @return An error code indicating if the function call was successful. KErrNone on success, sl@0: KErrNotSupported if called in a mode other than EMMFStatePlaying or if the function is otherwise not supported, sl@0: KErrNotReady if this is called before playing, sl@0: otherwise another of the system-wide error codes. sl@0: If this function is not supported, it is advised to use Stop(). sl@0: */ sl@0: inline TInt EmptyBuffers(); sl@0: sl@0: //from MMMFDevSoundCancelInitialize sl@0: /** sl@0: sl@0: Cancels the initialization process of a CMMFDevSound object sl@0: sl@0: @return An error code indicating if the function call was successful. sl@0: KErrNone on success, sl@0: KerrNotReady if this is called before InitializeL() call or after sl@0: the object has been initialized sl@0: */ sl@0: inline TInt CancelInitialize(); sl@0: sl@0: // from MMMFDevSoundCustomInterfaceChannel sl@0: /** sl@0: Implements a synchronous custom command sl@0: @param aUid sl@0: The UID of the custom command sl@0: @param aParam1 sl@0: A buffer of data to be supplied to the receiver sl@0: @param aParam2 sl@0: A buffer of data to be supplied to the receiver sl@0: @param aOutParam sl@0: A buffer that will be written into by the receiver sl@0: and returned to the client sl@0: @return the result of the custom command sl@0: */ sl@0: TInt SyncCustomCommand(TUid aUid, const TDesC8& aParam1, const TDesC8& aParam2, TDes8* aOutParam); sl@0: sl@0: /** sl@0: Implements an asynchronous custom command sl@0: @param aUid sl@0: The UID of the custom command sl@0: @param aStatus sl@0: The request status of the active object that sl@0: will be called upon the completion of the request sl@0: @param aParam1 sl@0: A buffer of data to be supplied to the receiver sl@0: @param aParam2 sl@0: A buffer of data to be supplied to the receiver sl@0: @param aOutParam sl@0: A buffer that will be written into by the receiver sl@0: and returned to the client sl@0: */ sl@0: void AsyncCustomCommand(TUid aUid, TRequestStatus& aStatus, const TDesC8& aParam1, const TDesC8& aParam2, TDes8* aOutParam); sl@0: sl@0: //from MMMFDevSoundCustomInterfaceObserver sl@0: void CloseCustomInterface(TInt aInterfaceId); sl@0: sl@0: //from MMMFDevSoundTimePlayed sl@0: TInt GetTimePlayed(TTimeIntervalMicroSeconds& aTime); sl@0: sl@0: //MMMFDevSoundQueryIgnoresUnderflow sl@0: TBool QueryIgnoresUnderflow(); sl@0: sl@0: // Set the real client thread with thread Id sl@0: TInt SetClientThreadInfo(TThreadId aTid); sl@0: sl@0: // from MMMFDevSoundTruePause sl@0: TBool IsResumeSupported(); sl@0: TInt Resume(); sl@0: protected: sl@0: sl@0: /** sl@0: * Constructor sl@0: */ sl@0: CBody(); sl@0: sl@0: /** sl@0: * Symbian constructor sl@0: */ sl@0: void ConstructL(); sl@0: sl@0: TInt FindCustomInterface(TUid aInterfaceId); sl@0: sl@0: // custom interface storage sl@0: RArray iCustomInterfaceArray; sl@0: CMMFDevSoundCIMuxUtility* iMuxUtility; sl@0: // Reference to DevSound proxy sl@0: RMMFDevSoundProxy* iDevSoundProxy; sl@0: // CI Extension sl@0: MDevSoundCIClientExtension* iCIExtension; sl@0: }; sl@0: sl@0: #include "sounddevicebody.inl" sl@0: sl@0: #endif // SOUNDDEVICEBODY_H sl@0: sl@0: // End of File