mmhais/refacladapt/src/tonehwdevice/tonedatapath.h
changeset 0 79dd3e2336a0
equal deleted inserted replaced
-1:000000000000 0:79dd3e2336a0
       
     1 // Copyright (c) 2003-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef TONEDATAPATH_H
       
    17 #define TONEDATAPATH_H
       
    18 
       
    19 #include <e32base.h>
       
    20 #include "mdasoundadapter.h"
       
    21 #include <mmf/server/mmfdatabuffer.h>
       
    22 #include "tonehwdevice.h"
       
    23 
       
    24 //message from  tonedatapath to hw device observer
       
    25 //to tell it to update the bytes played 
       
    26 #define KToneHwDeviceObserverUpdateBytesPlayed	0x101FE2A4
       
    27 
       
    28 class MMMFHwDeviceObserver;
       
    29 class CToneDataPath;
       
    30 class CToneCodec;
       
    31 
       
    32 
       
    33 /**
       
    34 @internalTechnology
       
    35 Panic codes for the Tone Data Path
       
    36 */
       
    37 enum TToneDataPathPanicCode
       
    38 	{
       
    39 	/** Codec wrapper did not create an internal datapath
       
    40 	*/
       
    41 	EToneNoDataPath,
       
    42 
       
    43 	/** Codec wrapper does not have a device handle
       
    44 	*/
       
    45 	EToneNoDevice,
       
    46 
       
    47 	/** Codec wrapper codec returns non existant process result
       
    48 	*/
       
    49 	EToneBadCodec,
       
    50 
       
    51 	/** Sound driver returns unexpected buffer
       
    52 	*/
       
    53 	EToneBadBuffer
       
    54 	};
       
    55 
       
    56 
       
    57 /**
       
    58  * Active object used by the CToneDataPath to send data to the sound
       
    59  * driver  This particular active object encapsulates the asynchronous play 
       
    60  * function, where a buffer of data is sent to the WINS audio device, and the
       
    61  * active object's RunL is called when the buffer has been consumed by the 
       
    62  * WINS audio device.
       
    63  * @internalComponent
       
    64  */
       
    65 class CToneDataPathPlayer : public CActive
       
    66 	{
       
    67 public:
       
    68 	CToneDataPathPlayer(CToneDataPath& aParent, TInt aPriority);
       
    69 	~CToneDataPathPlayer();
       
    70 	void Start();
       
    71 	void ResumePlaying();
       
    72 	void PlayData(const CMMFDataBuffer& aData);
       
    73 	void Stop();
       
    74 	virtual void RunL();
       
    75 	virtual TInt RunError(TInt aError);
       
    76 	virtual void DoCancel();
       
    77 	virtual void Error(TInt aError);
       
    78 private:
       
    79 	CToneDataPath& iParent;
       
    80 	const CMMFDataBuffer* iDataFromSource;
       
    81 	TBool iResumePlaying;
       
    82 	};
       
    83 
       
    84 /*
       
    85 * Active object used by CToneDataPath to listening for error messages
       
    86 * from the WINS audio device.  If this object's RunL is called, playback has 
       
    87 * been terminated for some reason.  The active object then 
       
    88 * notifies its parent the datapath, so that proper cleanup and client 
       
    89 * notification can occur.
       
    90 * @internalComponent
       
    91 */
       
    92 class CToneSoundDevPlayErrorReceiver : public CActive
       
    93 	{
       
    94 public:
       
    95 	CToneSoundDevPlayErrorReceiver(CToneDataPath& aParent, TInt aPriority);
       
    96 	~CToneSoundDevPlayErrorReceiver();
       
    97 	void Start();
       
    98 	void Stop();
       
    99 	virtual void RunL();
       
   100 	virtual void DoCancel();
       
   101 private:
       
   102 	CToneDataPath& iParent;
       
   103 	};
       
   104 
       
   105 
       
   106 class CToneDataPath : public CBase,
       
   107 					  public MIgnoreUnderflowEventsCustomInterface
       
   108 
       
   109 	{ 
       
   110 public: 
       
   111 	enum TToneDataPathState
       
   112 	{
       
   113 	EStopped,
       
   114 	EPlaying,
       
   115 	EPaused
       
   116 	};
       
   117 public:	
       
   118 	static CToneDataPath* NewL();
       
   119 	~CToneDataPath(); 
       
   120 	TInt SetObserver(MMMFHwDeviceObserver& aHwObserver);
       
   121 	TInt AddCodec(CToneCodec& aCodec);
       
   122 	TInt Start();
       
   123 	void Stop();
       
   124 	void Pause();
       
   125 	RMdaDevSound& Device();
       
   126 	void BufferFilledL(CMMFDataBuffer& aBuffer);
       
   127 	void BufferEmptiedL(const CMMFDataBuffer& aBuffer);
       
   128 	void SoundDeviceException(TInt aError);
       
   129 	TToneDataPathState State() {return iState;};
       
   130 	TInt EmptyBuffers();
       
   131 	virtual void IgnoreUnderflowEvents();
       
   132 	virtual TAny* CustomInterface(TUid aInterface);
       
   133 
       
   134 
       
   135 protected:	
       
   136 	CToneDataPath() {};
       
   137 	inline void Panic(TInt aPanicCode);
       
   138 	void ConstructL();
       
   139 	void FillSourceBufferL();
       
   140 	void FillSoundDeviceBufferL();
       
   141 	
       
   142 #ifdef __CYCLE_MMF_DATABUFFERS__
       
   143 	CMMFDataBuffer* CycleAudioBuffer(CMMFDataBuffer* aBuffer);
       
   144 #endif
       
   145 
       
   146 #ifdef __USE_MMF_TRANSFERBUFFERS__
       
   147 	CMMFTransferBuffer* CreateTransferBufferL(TUint aBufferSize, CMMFTransferBuffer* aOldBuffer);
       
   148 #endif
       
   149 
       
   150 #ifdef __USE_MMF_PTRBUFFERS__
       
   151 	CMMFPtrBuffer* CreatePtrBufferL(TUint aBufferSize);
       
   152 #endif
       
   153 
       
   154 protected: 
       
   155 	TToneDataPathState iState;
       
   156 	MMMFHwDeviceObserver* iHwDeviceObserver;
       
   157 	CToneCodec* iCodec;
       
   158 	CToneDataPathPlayer* iAudioPlayer;
       
   159 	CToneSoundDevPlayErrorReceiver* iSoundDeviceErrorReceiver;
       
   160 	RMdaDevSound iSoundDevice;
       
   161 	CMMFDataBuffer* iSourceBuffer;
       
   162 	CMMFDataBuffer* iSoundDeviceBuffer;
       
   163 	TBool iNoMoreSourceData;
       
   164 	TBool iSinkCanReceive;
       
   165 	TUint iSourceBufferSize;
       
   166 	TUint iSoundDevBufferSize;
       
   167 	TBool iRampAudioSample;
       
   168 	
       
   169 	TTimeIntervalMicroSeconds iVolumeRamp;
       
   170 	// DEF048512
       
   171 	TInt iSampleRate;
       
   172 	TInt iChannels;
       
   173 	
       
   174 	TInt iBuffSize;
       
   175 
       
   176 	TBool iIgnoreUnderflow;
       
   177 
       
   178 #ifdef __USE_MMF_TRANSFERBUFFERS__
       
   179 	RTransferBuffer* iTransferBuffer;
       
   180 	RTransferWindow* iTransferWindow;
       
   181 #endif
       
   182 
       
   183 #ifdef __USE_MMF_PTRBUFFERS__
       
   184 	HBufC8* iPtrBufferMemoryBlock;
       
   185 #endif
       
   186 
       
   187 	};
       
   188 
       
   189 /**
       
   190  * Internal panic
       
   191  * @internalComponent
       
   192  */
       
   193 inline void CToneDataPath::Panic(TInt aPanicCode)
       
   194 	{
       
   195 	_LIT(KTonePanicCategory, "ToneDataPath");
       
   196 	User::Panic(KTonePanicCategory, aPanicCode);
       
   197 	}
       
   198 
       
   199 #endif //TONEDATAPATH_H