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