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