sl@0: // Copyright (c) 2003-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 TONEDATAPATH_H sl@0: #define TONEDATAPATH_H sl@0: sl@0: #include sl@0: #include "mdasoundadapter.h" sl@0: #include sl@0: #include "tonehwdevice.h" sl@0: sl@0: //message from tonedatapath to hw device observer sl@0: //to tell it to update the bytes played sl@0: #define KToneHwDeviceObserverUpdateBytesPlayed 0x101FE2A4 sl@0: sl@0: class MMMFHwDeviceObserver; sl@0: class CToneDataPath; sl@0: class CToneCodec; sl@0: sl@0: sl@0: /** sl@0: @internalTechnology sl@0: Panic codes for the Tone Data Path sl@0: */ sl@0: enum TToneDataPathPanicCode sl@0: { sl@0: /** Codec wrapper did not create an internal datapath sl@0: */ sl@0: EToneNoDataPath, sl@0: sl@0: /** Codec wrapper does not have a device handle sl@0: */ sl@0: EToneNoDevice, sl@0: sl@0: /** Codec wrapper codec returns non existant process result sl@0: */ sl@0: EToneBadCodec, sl@0: sl@0: /** Sound driver returns unexpected buffer sl@0: */ sl@0: EToneBadBuffer sl@0: }; sl@0: sl@0: sl@0: /** sl@0: * Active object used by the CToneDataPath to send data to the sound sl@0: * driver This particular active object encapsulates the asynchronous play sl@0: * function, where a buffer of data is sent to the WINS audio device, and the sl@0: * active object's RunL is called when the buffer has been consumed by the sl@0: * WINS audio device. sl@0: * @internalComponent sl@0: */ sl@0: class CToneDataPathPlayer : public CActive sl@0: { sl@0: public: sl@0: CToneDataPathPlayer(CToneDataPath& aParent, TInt aPriority); sl@0: ~CToneDataPathPlayer(); sl@0: void Start(); sl@0: void ResumePlaying(); sl@0: void PlayData(const CMMFDataBuffer& aData); sl@0: void Stop(); sl@0: virtual void RunL(); sl@0: virtual TInt RunError(TInt aError); sl@0: virtual void DoCancel(); sl@0: virtual void Error(TInt aError); sl@0: private: sl@0: CToneDataPath& iParent; sl@0: const CMMFDataBuffer* iDataFromSource; sl@0: TBool iResumePlaying; sl@0: }; sl@0: sl@0: /* sl@0: * Active object used by CToneDataPath to listening for error messages sl@0: * from the WINS audio device. If this object's RunL is called, playback has sl@0: * been terminated for some reason. The active object then sl@0: * notifies its parent the datapath, so that proper cleanup and client sl@0: * notification can occur. sl@0: * @internalComponent sl@0: */ sl@0: class CToneSoundDevPlayErrorReceiver : public CActive sl@0: { sl@0: public: sl@0: CToneSoundDevPlayErrorReceiver(CToneDataPath& aParent, TInt aPriority); sl@0: ~CToneSoundDevPlayErrorReceiver(); sl@0: void Start(); sl@0: void Stop(); sl@0: virtual void RunL(); sl@0: virtual void DoCancel(); sl@0: private: sl@0: CToneDataPath& iParent; sl@0: }; sl@0: sl@0: sl@0: class CToneDataPath : public CBase, sl@0: public MIgnoreUnderflowEventsCustomInterface sl@0: sl@0: { sl@0: public: sl@0: enum TToneDataPathState sl@0: { sl@0: EStopped, sl@0: EPlaying, sl@0: EPaused sl@0: }; sl@0: public: sl@0: static CToneDataPath* NewL(); sl@0: ~CToneDataPath(); sl@0: TInt SetObserver(MMMFHwDeviceObserver& aHwObserver); sl@0: TInt AddCodec(CToneCodec& aCodec); sl@0: TInt Start(); sl@0: void Stop(); sl@0: void Pause(); sl@0: RMdaDevSound& Device(); sl@0: void BufferFilledL(CMMFDataBuffer& aBuffer); sl@0: void BufferEmptiedL(const CMMFDataBuffer& aBuffer); sl@0: void SoundDeviceException(TInt aError); sl@0: TToneDataPathState State() {return iState;}; sl@0: TInt EmptyBuffers(); sl@0: virtual void IgnoreUnderflowEvents(); sl@0: virtual TAny* CustomInterface(TUid aInterface); sl@0: sl@0: sl@0: protected: sl@0: CToneDataPath() {}; sl@0: inline void Panic(TInt aPanicCode); sl@0: void ConstructL(); sl@0: void FillSourceBufferL(); sl@0: void FillSoundDeviceBufferL(); sl@0: sl@0: #ifdef __CYCLE_MMF_DATABUFFERS__ sl@0: CMMFDataBuffer* CycleAudioBuffer(CMMFDataBuffer* aBuffer); sl@0: #endif sl@0: sl@0: #ifdef __USE_MMF_TRANSFERBUFFERS__ sl@0: CMMFTransferBuffer* CreateTransferBufferL(TUint aBufferSize, CMMFTransferBuffer* aOldBuffer); sl@0: #endif sl@0: sl@0: #ifdef __USE_MMF_PTRBUFFERS__ sl@0: CMMFPtrBuffer* CreatePtrBufferL(TUint aBufferSize); sl@0: #endif sl@0: sl@0: protected: sl@0: TToneDataPathState iState; sl@0: MMMFHwDeviceObserver* iHwDeviceObserver; sl@0: CToneCodec* iCodec; sl@0: CToneDataPathPlayer* iAudioPlayer; sl@0: CToneSoundDevPlayErrorReceiver* iSoundDeviceErrorReceiver; sl@0: RMdaDevSound iSoundDevice; sl@0: CMMFDataBuffer* iSourceBuffer; sl@0: CMMFDataBuffer* iSoundDeviceBuffer; sl@0: TBool iNoMoreSourceData; sl@0: TBool iSinkCanReceive; sl@0: TUint iSourceBufferSize; sl@0: TUint iSoundDevBufferSize; sl@0: TBool iRampAudioSample; sl@0: sl@0: TTimeIntervalMicroSeconds iVolumeRamp; sl@0: // DEF048512 sl@0: TInt iSampleRate; sl@0: TInt iChannels; sl@0: sl@0: TInt iBuffSize; sl@0: sl@0: TBool iIgnoreUnderflow; sl@0: sl@0: #ifdef __USE_MMF_TRANSFERBUFFERS__ sl@0: RTransferBuffer* iTransferBuffer; sl@0: RTransferWindow* iTransferWindow; sl@0: #endif sl@0: sl@0: #ifdef __USE_MMF_PTRBUFFERS__ sl@0: HBufC8* iPtrBufferMemoryBlock; sl@0: #endif sl@0: sl@0: }; sl@0: sl@0: /** sl@0: * Internal panic sl@0: * @internalComponent sl@0: */ sl@0: inline void CToneDataPath::Panic(TInt aPanicCode) sl@0: { sl@0: _LIT(KTonePanicCategory, "ToneDataPath"); sl@0: User::Panic(KTonePanicCategory, aPanicCode); sl@0: } sl@0: sl@0: #endif //TONEDATAPATH_H