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