os/mm/mmlibs/mmfw/inc/mmf/server/MmfAudioOutput.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2002-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 __MMF_AUDIOOUTPUT_H__
sl@0
    17
#define __MMF_AUDIOOUTPUT_H__
sl@0
    18
sl@0
    19
// Standard EPOC32 includes required by this header file
sl@0
    20
#include <e32base.h>
sl@0
    21
#include <e32std.h>
sl@0
    22
sl@0
    23
sl@0
    24
#include <mmf/common/mmfpaniccodes.h>
sl@0
    25
sl@0
    26
//DevSound
sl@0
    27
#include <mmf/server/sounddevice.h>
sl@0
    28
sl@0
    29
/** 
sl@0
    30
@publishedAll
sl@0
    31
@deprecated
sl@0
    32
*/
sl@0
    33
const TUint KAudioOutputDefaultFrameSize = 0x1000;
sl@0
    34
sl@0
    35
sl@0
    36
void Panic(TInt aPanicCode);
sl@0
    37
sl@0
    38
/**
sl@0
    39
@publishedAll
sl@0
    40
@released
sl@0
    41
sl@0
    42
Interface class to allow dynamic linkage to CMMFAudioOutput.
sl@0
    43
*/
sl@0
    44
class MMMFAudioOutput : public MDataSink
sl@0
    45
	{
sl@0
    46
public:
sl@0
    47
	//factory function
sl@0
    48
	/**
sl@0
    49
	Gets a new audio output object.
sl@0
    50
sl@0
    51
	@param  aImplementationUid
sl@0
    52
	        The implementation UID.
sl@0
    53
	@param  aInitData
sl@0
    54
	        The initialisation data.
sl@0
    55
sl@0
    56
	@return The audio output object.
sl@0
    57
	*/
sl@0
    58
	inline static MMMFAudioOutput* NewAudioOutputL(TUid aImplementationUid, const TDesC8& aInitData);
sl@0
    59
	//interface
sl@0
    60
sl@0
    61
	/**
sl@0
    62
	Returns the sound device.
sl@0
    63
sl@0
    64
	Accessor function exposing public CMMFDevsound methods.
sl@0
    65
sl@0
    66
	@return	A reference to a CMMFDevSound objector.
sl@0
    67
	*/
sl@0
    68
	virtual CMMFDevSound& SoundDevice() = 0;
sl@0
    69
sl@0
    70
	/**
sl@0
    71
	Returns the number of bytes played.
sl@0
    72
sl@0
    73
	@return	The number of bytes played. If 16-bit divide this number returned by 2 to get word
sl@0
    74
	        length.
sl@0
    75
	*/
sl@0
    76
	virtual TInt BytesPlayed() = 0;
sl@0
    77
sl@0
    78
	/**
sl@0
    79
	@deprecated
sl@0
    80
sl@0
    81
	Gets audio from hardware device abstracted MMFDevsound (not used).
sl@0
    82
sl@0
    83
	@param	aBuffer
sl@0
    84
			The data to read in from a Hardware Device
sl@0
    85
	@param	aSupplier
sl@0
    86
			The MDataSink consuming the data contained in aBuffer.
sl@0
    87
	*/
sl@0
    88
	virtual void HWEmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier)=0;//called by a EmptyBufferL if using HW codec
sl@0
    89
protected:
sl@0
    90
	//constructor
sl@0
    91
	/**
sl@0
    92
	Protected constructor.
sl@0
    93
	*/
sl@0
    94
	MMMFAudioOutput() : MDataSink(KUidMmfAudioOutput) {}
sl@0
    95
	};
sl@0
    96
sl@0
    97
inline MMMFAudioOutput* MMMFAudioOutput::NewAudioOutputL( TUid aImplementationUid,  const TDesC8& aInitData )
sl@0
    98
	{
sl@0
    99
	//make sure the cast will be ok by checking the uid is what we expect
sl@0
   100
	__ASSERT_ALWAYS(aImplementationUid==KUidMmfAudioOutput, Panic(EMMFAudioOutputPanicBadUID));
sl@0
   101
	MMMFAudioOutput* retPtr = STATIC_CAST(MMMFAudioOutput*, MDataSink::NewSinkL(aImplementationUid, aInitData));
sl@0
   102
	return retPtr;
sl@0
   103
	}
sl@0
   104
sl@0
   105
/**
sl@0
   106
@publishedAll
sl@0
   107
@released
sl@0
   108
sl@0
   109
The interface into DevSound.
sl@0
   110
sl@0
   111
Abstract data sink class providing an interface into hardware sound output.
sl@0
   112
sl@0
   113
Uses CMMFDevSound to access such output.
sl@0
   114
*/
sl@0
   115
class CMMFChannelAndSampleRateConverterFactory;
sl@0
   116
class CMMFChannelAndSampleRateConverter;
sl@0
   117
class CMMFAudioOutput : public CBase, public MMMFAudioOutput, public MDevSoundObserver
sl@0
   118
sl@0
   119
	{
sl@0
   120
public:
sl@0
   121
	static MDataSink* NewSinkL() ;
sl@0
   122
	virtual ~CMMFAudioOutput();
sl@0
   123
	void ConstructL();
sl@0
   124
sl@0
   125
	//MDataSink mixin implementations
sl@0
   126
	virtual TFourCC SinkDataTypeCode(TMediaId aMediaId); //used by data path MDataSource/Sink for codec matching
sl@0
   127
	virtual void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId);//called by a MDataSource to empty a buffer
sl@0
   128
	virtual void BufferFilledL(CMMFBuffer* aBuffer); //called by MDataSource to pass back full buffer to the sink
sl@0
   129
	virtual TBool CanCreateSinkBuffer();
sl@0
   130
	virtual CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool &aReference);
sl@0
   131
	virtual TInt SinkThreadLogon(MAsyncEventHandler& aEventHandler);
sl@0
   132
	virtual void SinkThreadLogoff();
sl@0
   133
	virtual void SinkPrimeL();
sl@0
   134
	virtual void SinkPauseL();
sl@0
   135
	virtual void SinkPlayL();
sl@0
   136
	virtual void SinkStopL();
sl@0
   137
	virtual void SetSinkPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
sl@0
   138
	virtual void NegotiateL(MDataSource& aSource);
sl@0
   139
	// MMMFAudioOutput mixin implementations
sl@0
   140
	TInt BytesPlayed();
sl@0
   141
	void HWEmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier);//called by a EmptyBufferL if using HW codec
sl@0
   142
	CMMFDevSound& SoundDevice();
sl@0
   143
	virtual TInt SetSinkDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId);
sl@0
   144
sl@0
   145
	//The following DataType() methods should not be used.
sl@0
   146
	//They are provided to maintain BC/SC with 7.0s
sl@0
   147
	virtual void SetDataTypeL(TFourCC aAudioType);
sl@0
   148
	virtual TFourCC DataType() const;
sl@0
   149
sl@0
   150
protected:
sl@0
   151
	virtual void ConstructSinkL( const TDesC8& aInitData ) ;
sl@0
   152
sl@0
   153
private:
sl@0
   154
	inline CMMFAudioOutput() {}
sl@0
   155
sl@0
   156
	void ConfigDevSoundL();
sl@0
   157
	void LoadL();
sl@0
   158
	TInt State();
sl@0
   159
sl@0
   160
	//MDevSoundObserver mixin implementations	
sl@0
   161
	virtual void InitializeComplete(TInt aError);
sl@0
   162
	virtual void ToneFinished(TInt aError); 
sl@0
   163
	virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
sl@0
   164
	virtual void PlayError(TInt aError); 
sl@0
   165
	virtual void BufferToBeEmptied(CMMFBuffer* aBuffer); 
sl@0
   166
	virtual void RecordError(TInt aError); 
sl@0
   167
	virtual void ConvertError(TInt aError);
sl@0
   168
	virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
sl@0
   169
	virtual void SendEventToClient(const TMMFEvent& /*aEvent*/);
sl@0
   170
sl@0
   171
public:
sl@0
   172
	virtual TBool IsResumeSupported();
sl@0
   173
sl@0
   174
private:
sl@0
   175
	MAsyncEventHandler* iEventHandler;
sl@0
   176
	CMMFDevSound* iMMFDevSound;	//this is now private to stop stuff "grabbing it"
sl@0
   177
	CMMFBuffer* iAudioBuffer;
sl@0
   178
	TInt iInitializeState;	
sl@0
   179
	enum TState
sl@0
   180
		{
sl@0
   181
		EIdle=0,
sl@0
   182
		EDevSoundReady,
sl@0
   183
		EPaused
sl@0
   184
		};
sl@0
   185
sl@0
   186
	enum TError
sl@0
   187
		{
sl@0
   188
		ECantCreateBuffer,
sl@0
   189
		EEmptyBuffer,
sl@0
   190
		EDevSoundNotLoaded,
sl@0
   191
		ERecordNotSupported,
sl@0
   192
		EDevSoundError,
sl@0
   193
		EUnknown
sl@0
   194
		};
sl@0
   195
sl@0
   196
	MDataSource* iSupplier;
sl@0
   197
	TState iState;
sl@0
   198
sl@0
   199
	TBool iCanSendBuffers;
sl@0
   200
	TBool iPlayStarted;
sl@0
   201
	TBool iDevSoundLoaded;
sl@0
   202
sl@0
   203
	TError iError;
sl@0
   204
	TInt iMMFDevsoundError;
sl@0
   205
	TMMFPrioritySettings iPrioritySettings;
sl@0
   206
sl@0
   207
	TUint iSourceSampleRate; 
sl@0
   208
	TUint iSourceChannels;
sl@0
   209
	TFourCC iSourceFourCC;
sl@0
   210
	TFourCC iDataTypeCode;
sl@0
   211
	CMMFDataBuffer* iDevSoundBuffer;
sl@0
   212
sl@0
   213
	TMMFCapabilities iDevSoundConfig;
sl@0
   214
sl@0
   215
 	TBool iNeedsSWConversion;
sl@0
   216
	TUint iSWConvertSampleRate;
sl@0
   217
	TUint iSWConvertChannels;
sl@0
   218
 	CMMFChannelAndSampleRateConverterFactory* iChannelAndSampleRateConverterFactory;
sl@0
   219
 	CMMFChannelAndSampleRateConverter* iChannelAndSampleRateConverter;
sl@0
   220
 	CMMFDataBuffer* iConvertBuffer;
sl@0
   221
 	CMMFBuffer* iBufferToEmpty;
sl@0
   222
 	CActiveSchedulerWait* iActiveSchedulerWait;
sl@0
   223
	};
sl@0
   224
sl@0
   225
#endif