os/mm/mmhais/refacladapt/src/tonehwdevice/tonedatapath.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmhais/refacladapt/src/tonehwdevice/tonedatapath.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,199 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef TONEDATAPATH_H
    1.20 +#define TONEDATAPATH_H
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +#include "mdasoundadapter.h"
    1.24 +#include <mmf/server/mmfdatabuffer.h>
    1.25 +#include "tonehwdevice.h"
    1.26 +
    1.27 +//message from  tonedatapath to hw device observer
    1.28 +//to tell it to update the bytes played 
    1.29 +#define KToneHwDeviceObserverUpdateBytesPlayed	0x101FE2A4
    1.30 +
    1.31 +class MMMFHwDeviceObserver;
    1.32 +class CToneDataPath;
    1.33 +class CToneCodec;
    1.34 +
    1.35 +
    1.36 +/**
    1.37 +@internalTechnology
    1.38 +Panic codes for the Tone Data Path
    1.39 +*/
    1.40 +enum TToneDataPathPanicCode
    1.41 +	{
    1.42 +	/** Codec wrapper did not create an internal datapath
    1.43 +	*/
    1.44 +	EToneNoDataPath,
    1.45 +
    1.46 +	/** Codec wrapper does not have a device handle
    1.47 +	*/
    1.48 +	EToneNoDevice,
    1.49 +
    1.50 +	/** Codec wrapper codec returns non existant process result
    1.51 +	*/
    1.52 +	EToneBadCodec,
    1.53 +
    1.54 +	/** Sound driver returns unexpected buffer
    1.55 +	*/
    1.56 +	EToneBadBuffer
    1.57 +	};
    1.58 +
    1.59 +
    1.60 +/**
    1.61 + * Active object used by the CToneDataPath to send data to the sound
    1.62 + * driver  This particular active object encapsulates the asynchronous play 
    1.63 + * function, where a buffer of data is sent to the WINS audio device, and the
    1.64 + * active object's RunL is called when the buffer has been consumed by the 
    1.65 + * WINS audio device.
    1.66 + * @internalComponent
    1.67 + */
    1.68 +class CToneDataPathPlayer : public CActive
    1.69 +	{
    1.70 +public:
    1.71 +	CToneDataPathPlayer(CToneDataPath& aParent, TInt aPriority);
    1.72 +	~CToneDataPathPlayer();
    1.73 +	void Start();
    1.74 +	void ResumePlaying();
    1.75 +	void PlayData(const CMMFDataBuffer& aData);
    1.76 +	void Stop();
    1.77 +	virtual void RunL();
    1.78 +	virtual TInt RunError(TInt aError);
    1.79 +	virtual void DoCancel();
    1.80 +	virtual void Error(TInt aError);
    1.81 +private:
    1.82 +	CToneDataPath& iParent;
    1.83 +	const CMMFDataBuffer* iDataFromSource;
    1.84 +	TBool iResumePlaying;
    1.85 +	};
    1.86 +
    1.87 +/*
    1.88 +* Active object used by CToneDataPath to listening for error messages
    1.89 +* from the WINS audio device.  If this object's RunL is called, playback has 
    1.90 +* been terminated for some reason.  The active object then 
    1.91 +* notifies its parent the datapath, so that proper cleanup and client 
    1.92 +* notification can occur.
    1.93 +* @internalComponent
    1.94 +*/
    1.95 +class CToneSoundDevPlayErrorReceiver : public CActive
    1.96 +	{
    1.97 +public:
    1.98 +	CToneSoundDevPlayErrorReceiver(CToneDataPath& aParent, TInt aPriority);
    1.99 +	~CToneSoundDevPlayErrorReceiver();
   1.100 +	void Start();
   1.101 +	void Stop();
   1.102 +	virtual void RunL();
   1.103 +	virtual void DoCancel();
   1.104 +private:
   1.105 +	CToneDataPath& iParent;
   1.106 +	};
   1.107 +
   1.108 +
   1.109 +class CToneDataPath : public CBase,
   1.110 +					  public MIgnoreUnderflowEventsCustomInterface
   1.111 +
   1.112 +	{ 
   1.113 +public: 
   1.114 +	enum TToneDataPathState
   1.115 +	{
   1.116 +	EStopped,
   1.117 +	EPlaying,
   1.118 +	EPaused
   1.119 +	};
   1.120 +public:	
   1.121 +	static CToneDataPath* NewL();
   1.122 +	~CToneDataPath(); 
   1.123 +	TInt SetObserver(MMMFHwDeviceObserver& aHwObserver);
   1.124 +	TInt AddCodec(CToneCodec& aCodec);
   1.125 +	TInt Start();
   1.126 +	void Stop();
   1.127 +	void Pause();
   1.128 +	RMdaDevSound& Device();
   1.129 +	void BufferFilledL(CMMFDataBuffer& aBuffer);
   1.130 +	void BufferEmptiedL(const CMMFDataBuffer& aBuffer);
   1.131 +	void SoundDeviceException(TInt aError);
   1.132 +	TToneDataPathState State() {return iState;};
   1.133 +	TInt EmptyBuffers();
   1.134 +	virtual void IgnoreUnderflowEvents();
   1.135 +	virtual TAny* CustomInterface(TUid aInterface);
   1.136 +
   1.137 +
   1.138 +protected:	
   1.139 +	CToneDataPath() {};
   1.140 +	inline void Panic(TInt aPanicCode);
   1.141 +	void ConstructL();
   1.142 +	void FillSourceBufferL();
   1.143 +	void FillSoundDeviceBufferL();
   1.144 +	
   1.145 +#ifdef __CYCLE_MMF_DATABUFFERS__
   1.146 +	CMMFDataBuffer* CycleAudioBuffer(CMMFDataBuffer* aBuffer);
   1.147 +#endif
   1.148 +
   1.149 +#ifdef __USE_MMF_TRANSFERBUFFERS__
   1.150 +	CMMFTransferBuffer* CreateTransferBufferL(TUint aBufferSize, CMMFTransferBuffer* aOldBuffer);
   1.151 +#endif
   1.152 +
   1.153 +#ifdef __USE_MMF_PTRBUFFERS__
   1.154 +	CMMFPtrBuffer* CreatePtrBufferL(TUint aBufferSize);
   1.155 +#endif
   1.156 +
   1.157 +protected: 
   1.158 +	TToneDataPathState iState;
   1.159 +	MMMFHwDeviceObserver* iHwDeviceObserver;
   1.160 +	CToneCodec* iCodec;
   1.161 +	CToneDataPathPlayer* iAudioPlayer;
   1.162 +	CToneSoundDevPlayErrorReceiver* iSoundDeviceErrorReceiver;
   1.163 +	RMdaDevSound iSoundDevice;
   1.164 +	CMMFDataBuffer* iSourceBuffer;
   1.165 +	CMMFDataBuffer* iSoundDeviceBuffer;
   1.166 +	TBool iNoMoreSourceData;
   1.167 +	TBool iSinkCanReceive;
   1.168 +	TUint iSourceBufferSize;
   1.169 +	TUint iSoundDevBufferSize;
   1.170 +	TBool iRampAudioSample;
   1.171 +	
   1.172 +	TTimeIntervalMicroSeconds iVolumeRamp;
   1.173 +	// DEF048512
   1.174 +	TInt iSampleRate;
   1.175 +	TInt iChannels;
   1.176 +	
   1.177 +	TInt iBuffSize;
   1.178 +
   1.179 +	TBool iIgnoreUnderflow;
   1.180 +
   1.181 +#ifdef __USE_MMF_TRANSFERBUFFERS__
   1.182 +	RTransferBuffer* iTransferBuffer;
   1.183 +	RTransferWindow* iTransferWindow;
   1.184 +#endif
   1.185 +
   1.186 +#ifdef __USE_MMF_PTRBUFFERS__
   1.187 +	HBufC8* iPtrBufferMemoryBlock;
   1.188 +#endif
   1.189 +
   1.190 +	};
   1.191 +
   1.192 +/**
   1.193 + * Internal panic
   1.194 + * @internalComponent
   1.195 + */
   1.196 +inline void CToneDataPath::Panic(TInt aPanicCode)
   1.197 +	{
   1.198 +	_LIT(KTonePanicCategory, "ToneDataPath");
   1.199 +	User::Panic(KTonePanicCategory, aPanicCode);
   1.200 +	}
   1.201 +
   1.202 +#endif //TONEDATAPATH_H