epoc32/include/mmf/server/mmfaudioinput.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_AUDIOINPUT_H__
    17 #define __MMF_AUDIOINPUT_H__
    18 
    19 // Standard EPOC32 includes required by this header file
    20 #include <e32base.h>
    21 #include <e32std.h>
    22 
    23 // Public Media Server includes
    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 KAudioInputDefaultFrameSize = 0x1000;  //4K
    34 //#define KAudioInputCanResample		//uncomment this to allow Audio Input to sample rate convert 
    35 
    36 
    37 void Panic(TInt aPanicCode);
    38 
    39 
    40 /**
    41 @publishedAll
    42 @released
    43 
    44 Interface class to allow dynamic linkage to CMMFAudioInput.
    45 */
    46 class MMMFAudioInput : public MDataSource
    47 	{
    48 public:
    49 
    50 	//factory function
    51 	inline static MMMFAudioInput* NewAudioInputL(TUid aImplementationUid, const TDesC8& aInitData);
    52 
    53 	//interface
    54 	/**
    55 	Returns the sound device.
    56 
    57 	@return A reference to a CMMFDevSound objector. Accessor function exposing public CMMFDevsound methods.
    58 	*/
    59 	virtual CMMFDevSound& SoundDevice() = 0;
    60 
    61 	/**
    62 	Returns the number of bytes played.
    63 
    64 	@return	The number of bytes played. If 16-bit divide this number returned by 2 to get word length.
    65 	*/
    66 	virtual TInt BytesPlayed() = 0;
    67 
    68 	/**
    69 	@deprecated
    70 
    71 	Gets audio from hardware device abstracted MMFDevsound (not used).
    72 
    73 	@param  aBuffer
    74 	        The data to read in from a Hardware Device
    75 	@param  aConsumer
    76 	        The MDataSink consuming the data contained in aBuffer.
    77 	*/
    78 	virtual void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer) = 0;
    79 protected:
    80 	//constructor
    81 	/**
    82 	Protected constructor.
    83 	*/
    84 	inline MMMFAudioInput() : MDataSource(KUidMmfAudioInput) {};
    85 	};
    86 
    87 /**
    88 Allocates and constructs an audio input object. 
    89 
    90 Calls MDataSource::NewSourceL().
    91 
    92 @param  aImplementationUid
    93 		The Implementation UID.
    94 @param  aInitData
    95 		The initialisation data.
    96 
    97 @return A new audio input object.
    98 */
    99 inline MMMFAudioInput* MMMFAudioInput::NewAudioInputL( TUid aImplementationUid,  const TDesC8& aInitData )
   100 	{
   101 	//make sure the cast will be ok by checking the uid is what we expect
   102 	__ASSERT_ALWAYS(aImplementationUid==KUidMmfAudioInput, Panic(EMMFAudioInputPanicBadUID));
   103 	MMMFAudioInput* retPtr = STATIC_CAST(MMMFAudioInput*, MDataSource::NewSourceL(aImplementationUid, aInitData));
   104 	return retPtr;
   105 	}
   106 
   107 /**
   108 @publishedAll
   109 @released
   110 
   111 Concrete data source to provide microphone support.
   112 
   113 Intended to be used by controller plugin developers for source plugins. Uses CMMFDevSound to access
   114 hardware.
   115 */
   116 class CMMFAudioInput : public CBase, public MMMFAudioInput, public MDevSoundObserver
   117 
   118 	{
   119 public:
   120 
   121 	static MDataSource* NewSourceL();
   122 	virtual ~CMMFAudioInput();
   123 	void ConstructL();
   124 
   125 	//MDataSource mixin implementations
   126 	virtual TFourCC SourceDataTypeCode(TMediaId aMediaId);
   127 	virtual void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer,TMediaId aMediaId);//called by a MDataSink to request buffer fill
   128 	virtual void BufferEmptiedL(CMMFBuffer* aBuffer); //called by MDataSink to pass back emptied buffer to the source
   129 	virtual TBool CanCreateSourceBuffer();
   130 	virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId);
   131 
   132 	inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer);
   133 
   134 	virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference);
   135 
   136 	inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference);
   137 	virtual TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler);
   138 	virtual void SourceThreadLogoff();
   139 	virtual void SourcePrimeL();
   140 	virtual void SourceStopL();
   141 	virtual void SourcePlayL();
   142 	virtual void SourcePauseL();
   143 	virtual void SetSourcePrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
   144 
   145 	virtual void NegotiateSourceL(MDataSink& aSink);
   146 
   147 	// MMMFAudioInput mixin implementations
   148 	TInt BytesPlayed();
   149 	void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer); //called by a FillBufferL if using HW codec
   150 	CMMFDevSound& SoundDevice();
   151 	virtual TInt SetSourceDataTypeCode(TFourCC aSourceFourCC, TMediaId aMediaId);
   152 
   153 	void LoadL();
   154 
   155 	//The following DataType() methods and iBufferStatus should not be used.
   156 	//They are provided to maintain BC/SC with 7.0s
   157 	virtual void SetDataTypeL(TFourCC aAudioType);
   158 	virtual TFourCC DataType() const;
   159 	/**
   160 	Buffer completion status.
   161 	*/
   162 	TRequestStatus iBufferStatus;
   163 
   164 protected:
   165 	virtual void ConstructSourceL( const TDesC8& aInitData ) ;
   166 
   167 private:
   168 	inline CMMFAudioInput() {}
   169 
   170 	MAsyncEventHandler* iEventHandler;
   171 	CMMFDevSound* iMMFDevSound;	//this is now private to stop stuff "grabbing it"
   172 	
   173 	//MDevSoundObserver mixin implementations
   174 	virtual void InitializeComplete(TInt aError);
   175 	virtual void ToneFinished(TInt aError);
   176 	virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
   177 	virtual void PlayError(TInt aError); 
   178 	virtual void BufferToBeEmptied(CMMFBuffer* aBuffer); 
   179 	virtual void RecordError(TInt aError); 
   180 	virtual void ConvertError(TInt aError);
   181 	virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
   182 	virtual void SendEventToClient(const TMMFEvent& /*aEvent*/);
   183 
   184 	void ConfigDevSoundL();
   185 	
   186 private:
   187 	
   188 	enum TCodec
   189 		{
   190 		EUseARMCodec=0,
   191 		EUseHWCodec
   192 		};
   193 
   194 	enum TState
   195 		{
   196 		EIdle=0,
   197 		EPaused,
   198 		EDevSoundReady,
   199 		EBufferEmpty
   200 		};
   201 
   202 	enum TError
   203 		{
   204 		ECantCreateBuffer,
   205 		EEmptyBuffer,
   206 		EDevSoundNotLoaded,
   207 		EUnknown
   208 		}; 
   209 	
   210 
   211 	MDataSink* iConsumer;
   212 	TState iState;
   213 
   214 	TBool iFirstBufferRequested;
   215 	TBool iFirstBufferRead;
   216 
   217 	TBool iDevSoundLoaded;
   218 	TBool iStopped;
   219 
   220 	TError iError;
   221 	TInt iMMFDevsoundError;
   222 	TMMFPrioritySettings iPrioritySettings;
   223 
   224 	TUint iSinkSampleRate;
   225 	TUint iSinkChannels;
   226 	TFourCC iSinkFourCC;
   227 	TFourCC iDataTypeCode;
   228 	CMMFBuffer* iDevSoundBuf;
   229 
   230 	TBool iPausePending;
   231 	TInt iInitializeState;	
   232  	CActiveSchedulerWait* iActiveSchedulerWait;
   233 	};
   234 
   235 /**
   236 Intended for synchronous usage (returns buffer specific to a Media Type).
   237 
   238 @param	aMediaId
   239         The Media ID.
   240 @param	aSinkBuffer
   241         Not Used.
   242 
   243 @return A pointer to the CMMFBuffer source buffer.
   244 */
   245 inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/)
   246 {
   247 	return CreateSourceBufferL(aMediaId);
   248 }
   249 
   250 /**
   251 Creates a source buffer.
   252 
   253 Intended for asynchronous usage (returns buffer specific to a Media Type).
   254 
   255 @param  aMediaId
   256         The Media ID.
   257 @param  aSinkBuffer
   258         Not used.
   259 @param	aReference
   260         A boolean indicating if MDataSource owns the buffer. If EFalse the the caller owns the 
   261         buffer.
   262 
   263 @return The source buffer.
   264 */
   265 inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/, TBool &aReference)
   266 {
   267 	return CreateSourceBufferL(aMediaId, aReference);
   268 }
   269 
   270 #endif