sl@0: // Copyright (c) 2004-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: #ifndef __MMFBTDEVSOUNDSESSIONBODY__H__ sl@0: #define __MMFBTDEVSOUNDSESSIONBODY__H__ sl@0: sl@0: #include sl@0: #include sl@0: #include "MmfBtDevSoundSession.h" sl@0: #include "MmfBtDevSoundSessionXtnd.h" sl@0: #include "BtToneGenerator.h" sl@0: #include "MmfBtAudioPolicyProxy.h" sl@0: #include "MmfBtDevSoundInfo.h" sl@0: #include "BtDevSoundUtility.h" sl@0: #include "mdasound.h" sl@0: sl@0: //controls buffer sizes sl@0: const TInt KDevSoundDefaultFrameSize = 0x1000; sl@0: const TInt KDevSoundMinFrameSize = 0x800; //2K sl@0: const TInt KDevSoundMaxFrameSize = 0x4000; //16K sl@0: const TInt KDevSoundDeltaFrameSize = 0x800; //2K sl@0: const TInt KDevSoundFramesPerSecond = 4; sl@0: const TUid KUidBTHeadsetRepository = {0x102070D7}; sl@0: sl@0: sl@0: //Forward references: sl@0: class CDevSoundPlayer; sl@0: class CDevSoundError; sl@0: class CDevSoundRecorder; sl@0: class CDevSoundRecordError; sl@0: class CMMFDevSoundProxyXtnd; sl@0: sl@0: class CMMFHwDevice; sl@0: class CMMFHwDeviceObserver; sl@0: class MPlayCustomInterface; sl@0: class MRecordCustomInterface; sl@0: class TBTDevAddr; sl@0: sl@0: /* sl@0: * AO to handle asynch RoutingSoundDevice Initialisation sl@0: * sl@0: */ sl@0: class CRoutingSoundDeviceHandler : public CActive sl@0: { sl@0: public: sl@0: static CRoutingSoundDeviceHandler* NewL(MDevSoundObserver* aObserver); sl@0: ~CRoutingSoundDeviceHandler(); sl@0: void Start(); sl@0: private: sl@0: void RunL(); sl@0: void DoCancel(); sl@0: CRoutingSoundDeviceHandler(MDevSoundObserver* aObserver); sl@0: void ConstructL(); sl@0: private: sl@0: MDevSoundObserver* iObserver; // Not owned sl@0: }; sl@0: sl@0: /* sl@0: * sl@0: * Reference internals for CMMFDevSound sl@0: * @internalComponent sl@0: * sl@0: */ sl@0: class CMMFDevSoundSvrImp; sl@0: NONSHARABLE_CLASS( CMMFDevSoundSvrImp ) : public CBase, public MMMFHwDeviceObserver sl@0: { sl@0: public: sl@0: static CMMFDevSoundSvrImp* NewL(CMMFDevSoundSessionXtnd* aParent); sl@0: ~CMMFDevSoundSvrImp(); sl@0: sl@0: // Initializes to raw audio data PCM16 and Sampling Rate of 8 KHz. sl@0: void InitializeL(MDevSoundObserver& aDevSoundObserver, TMMFState aMode); sl@0: // Initializes with hardware device and mode (play, record, convert) sl@0: void InitializeL(MDevSoundObserver& aDevSoundObserver, TUid aHWDev, TMMFState aMode); sl@0: // Initializes with chain of hardware devices and mode (play, record, convert) sl@0: void InitializeL(MDevSoundObserver& aDevSoundObserver, CArrayPtr aHWDevArray, TMMFState aMode); sl@0: // Initializes with hardware device associated with specific FourCC code sl@0: // and desired mode (play, record, convert) sl@0: void InitializeL(MDevSoundObserver& aDevSoundObserver, TFourCC aDesiredFourCC, TMMFState aMode); sl@0: sl@0: // Returns device capabilities sl@0: TMMFCapabilities Capabilities(); sl@0: // Returns device configuration sl@0: TMMFCapabilities Config() const; sl@0: // Sets device configuration sl@0: void SetConfigL(const TMMFCapabilities& aCaps); sl@0: sl@0: // Returns maximum play volume device supports sl@0: TInt MaxVolume(); sl@0: // Returns play volume device is configured to sl@0: TInt Volume(); sl@0: // Sets device play volume sl@0: void SetVolume(TInt aVolume); sl@0: sl@0: // Returns maximum record gain device supports sl@0: TInt MaxGain(); sl@0: // Returns record gain device is configured to sl@0: TInt Gain(); sl@0: // Sets device record gain sl@0: void SetGain(TInt aGain); sl@0: sl@0: // Returns play balance sl@0: void GetPlayBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage); sl@0: // Sets play balance sl@0: void SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage); sl@0: sl@0: // Returns record balance sl@0: void GetRecordBalanceL(TInt& aLeftPercentage, TInt& aRightPercentage); sl@0: // Sets record balance sl@0: void SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage); sl@0: sl@0: // Initializes audio device and start play process sl@0: void PlayInitL(); sl@0: // Initializes audio device and start record process sl@0: void RecordInitL(const RMmfIpcMessage& aMessage); sl@0: // Plays the data in the buffer sl@0: void PlayData(); sl@0: // Records data into buffer sl@0: void RecordData(const RMmfIpcMessage& aMessage); sl@0: // Stops the ongoing operation sl@0: void Stop(); sl@0: // Tempororily Stops the ongoing operation sl@0: void Pause(); sl@0: sl@0: // Returns the Sample recorded so far sl@0: TInt SamplesRecorded(); sl@0: // Returns the Sample played so far sl@0: TInt SamplesPlayed(); sl@0: sl@0: // Initializes device and start playing tone sl@0: void PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration); sl@0: // Initializes device and start playing dual tone sl@0: void PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration); sl@0: // Initializes device and start playing DTMF String sl@0: void PlayDTMFStringL(const TDesC& aDTMFString); sl@0: // Initializes device and start playing tone sequence sl@0: void PlayToneSequenceL(const TDesC8& aData); sl@0: // Initializes device and start playing fixed sequence sl@0: void PlayFixedSequenceL(TInt aSequenceNumber); sl@0: sl@0: // Sets tone repeat attributes sl@0: void SetToneRepeats(TInt aRepeatCount, sl@0: const TTimeIntervalMicroSeconds& aRepeatTrailingSilence); sl@0: // Sets DTMF tone attributes sl@0: void SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength, sl@0: TTimeIntervalMicroSeconds32& aToneOffLength, sl@0: TTimeIntervalMicroSeconds32& aPauseLength); sl@0: // Sets volume ramp for playing sl@0: void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); sl@0: // Sets priority settings sl@0: void SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings); sl@0: sl@0: // Provides interface for converting data in buffer sl@0: void ConvertInitL(); sl@0: // Converts data in the buffer sl@0: void ConvertData(); sl@0: sl@0: // Provides interface for sending custom commands for the audio device sl@0: TAny* CustomInterface(TUid aInterfaceId); sl@0: sl@0: // Provides interface for querying fixed sequence count sl@0: TInt FixedSequenceCount(); sl@0: // Provides interface for querying fixed sequence name sl@0: const TDesC& FixedSequenceName(TInt aSequenceNumber); sl@0: // Gets the supported input datatypes sl@0: void GetSupportedInputDataTypesL(RArray& aSupportedDataTypesconst, const TMMFPrioritySettings& aPrioritySettings) const; sl@0: // Gets the supported output datatypes sl@0: void GetSupportedOutputDataTypesL(RArray& aSupportedDataTypes, const TMMFPrioritySettings& aPrioritySettings) const; sl@0: sl@0: // Interface for Audio Policy sl@0: // Sets id for this DevSound instance sl@0: void SetDevSoundId(TInt aDevSoundId); sl@0: // Returns info about this DevSound instance sl@0: TMMFDevSoundInfo DevSoundInfo(); sl@0: // Called by Audio Policy Server when play reqeust is granted sl@0: void StartPlayDataL(); sl@0: // Called by Audio Policy Server when record reqeust is granted sl@0: void StartRecordDataL(); sl@0: // Called by Audio Policy Server when play tone reqeust is granted sl@0: void StartPlayToneL(); sl@0: // Called by Audio Policy Server when play dual tone request is granted sl@0: void StartPlayDualToneL(); sl@0: // Called by Audio Policy Server when play DTMF reqeust is granted sl@0: void StartPlayDTMFStringL(); sl@0: // Called by Audio Policy Server when play tone sequence reqeust is granted sl@0: void StartPlayToneSequenceL(); sl@0: // Called by Audio Policy Server when DevSound instance looses device sl@0: void SendEventToClient(const TMMFEvent& aEvent); sl@0: // Updates the total bytes played from audio device sl@0: void UpdateBytesPlayed(); sl@0: sl@0: // CMMFHwDevice implementation: sl@0: TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer); sl@0: TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer); sl@0: TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg); sl@0: void Stopped(); sl@0: void Error(TInt aError); sl@0: // CMMFHwDevice implementation ends sl@0: sl@0: //provides interface for register a notification event sl@0: TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData = KNullDesC8); sl@0: //provides interface to cancel the registered notification sl@0: TInt CancelRegisterAsClient(TUid aEventType); sl@0: //Gets the notification data for client to resume sl@0: TInt GetResourceNotificationData(TUid aEventType, TDes8& aNotificationData); sl@0: //waits for the client to resume playback even after the timeout expires sl@0: TInt WillResumePlay(); sl@0: sl@0: private: sl@0: // So that nobody can extend sl@0: CMMFDevSoundSvrImp(CMMFDevSoundSessionXtnd* aParent); sl@0: // Second phase constructor sl@0: void Construct3L(RServer2& aPolicyServerHandle); sl@0: void PreInitializeL(); sl@0: // Initializes format based on format supported sl@0: TInt InitializeFormat(RMdaDevSound::TSoundFormatsSupportedBuf& aSupportedFormat, sl@0: RMdaDevSound::TCurrentSoundFormatBuf& aFormat); sl@0: // Request Policy sl@0: void RequestPolicy(); sl@0: // Play tone sl@0: void DoPlayL(); sl@0: // Sets active tone sl@0: void SetActiveToneBuffer(); sl@0: // Fills free tone buffer with tone data sl@0: TInt FillFreeToneBuffer(); sl@0: // Updates the state of audio policy based on the audio policy settings sl@0: TInt UpdatePolicyState(); sl@0: // HwDevice implementation begins sl@0: TInt InitTask(); sl@0: // Returns Sampling Frequency the device is currently configured to sl@0: TInt SamplingFrequency(); sl@0: // Returns number of channels the device is currently configured to sl@0: TInt NumberOfChannels(); sl@0: //returns the number of bytes in each audio sample sl@0: TInt BytesPerAudioSample(); sl@0: // HwDevice implementation ends sl@0: TInt SetDeviceVolume(TInt aVolume); sl@0: TInt SetPlayFormat(RMdaDevSound::TCurrentSoundFormatBuf& aPlayFormat); sl@0: TInt SetRecordFormat(RMdaDevSound::TCurrentSoundFormatBuf& aRecordFormat); sl@0: TInt SetDeviceRecordLevel(TInt aGain); sl@0: TInt SetDeviceVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); sl@0: sl@0: private: sl@0: sl@0: CMMFDevSoundSessionXtnd& iParent; sl@0: sl@0: //Objects (owned or referred to): sl@0: RMMFAudioPolicyProxy* iAudioPolicyProxy; sl@0: CMMFAudioPolicyRequest* iAudioPolicyRequest; sl@0: MDevSoundObserver* iDevSoundObserver; sl@0: sl@0: // Handles receiving events sl@0: CMMFDevSoundEventHandler* iDevSoundEventHandler; sl@0: sl@0: //WINS Sound Device Structures sl@0: RMdaDevSound::TSoundFormatsSupportedBuf iPlayFormatsSupported; sl@0: RMdaDevSound::TCurrentSoundFormatBuf iPlayFormat; sl@0: RMdaDevSound::TSoundFormatsSupportedBuf iRecordFormatsSupported; sl@0: RMdaDevSound::TCurrentSoundFormatBuf iRecordFormat; sl@0: sl@0: // DevSound capabilities sl@0: TMMFCapabilities iDeviceCapabilities; sl@0: // Current Configuration sl@0: TMMFCapabilities iDeviceConfig; sl@0: sl@0: // AudioPolicy priority used to communicate with server sl@0: TMMFAudioPolicyPrioritySettings iAudioPolicyPrioritySettings; sl@0: sl@0: MPlayCustomInterface* iPlayCustomInterface; sl@0: MRecordCustomInterface* iRecordCustomInterface; sl@0: sl@0: // Bytes of audio data played in current play cycle sl@0: TInt iPlayedBytesCount; sl@0: // Bytes of audio data recorded in current record cycle sl@0: TInt iRecordedBytesCount; sl@0: TInt iGain; sl@0: TInt iVolume; sl@0: TMMFDevSoundInfo iDevSoundInfo; sl@0: sl@0: //Tone Stuff: sl@0: MMdaToneSynthesis* iCurrentGenerator; sl@0: TMdaSimpleToneGenerator iToneGen; sl@0: TMdaDualToneGenerator iDualToneGen; sl@0: TMdaDTMFGenerator iDTMFGen; sl@0: TMdaSequenceGenerator iSequenceGen; // Not Supported sl@0: TInt iRepeatCount; sl@0: TTimeIntervalMicroSeconds iRepeatTrailingSilence; sl@0: TTimeIntervalMicroSeconds iRampDuration; sl@0: // Double buffer tone playing sl@0: CMMFDataBuffer* iToneBuffer1; sl@0: CMMFDataBuffer* iToneBuffer2; sl@0: // Reference to current tone buffer playing sl@0: CMMFDataBuffer* iActiveToneBuffer; sl@0: sl@0: // Hardware device implementation sl@0: CMMFHwDevice2* iCMMFHwDevice; sl@0: sl@0: // Mode in which DevSound instance will be used for sl@0: TMMFState iMode; sl@0: // Reference to hardware buffer sl@0: CMMFDataBuffer* iHwDeviceBuffer; sl@0: sl@0: TBool iLastBufferReceived; sl@0: sl@0: // Holds true of Audio data given to DevSound needs to ramped up sl@0: CMMFDevSoundUtility* iDevSoundUtil; sl@0: sl@0: // Fixed sequence related sl@0: CPtrC8Array* iFixedSequences; // Holds the fixed sequence data sl@0: TPtrC8 iFixedSequence; // Holds reference to current sequence sl@0: sl@0: // Balance sl@0: TInt iLeftPlayBalance; sl@0: TInt iRightPlayBalance; sl@0: sl@0: TInt iLeftRecordBalance; sl@0: TInt iRightRecordBalance; sl@0: sl@0: TBool iPaused; sl@0: sl@0: TUid iHwDeviceID; sl@0: sl@0: // Hardware device initialization parameters sl@0: THwDeviceInitParams iDevInfo; sl@0: sl@0: TBool iFirstCallFromHwDevice; sl@0: sl@0: // AO to manage the initialisation of the RoutingSoundDevice sl@0: CRoutingSoundDeviceHandler* iRSDHandler; sl@0: sl@0: friend class CMMFDevSoundSession; sl@0: }; sl@0: sl@0: #include "MmfBtDevSoundSessionBody.inl" sl@0: sl@0: #endif // __MMFBTDEVSOUNDSESSIONBODY__H__