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