os/mm/mmlibs/mmfw/inc/mmf/server/MmfAudioInput.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/inc/mmf/server/MmfAudioInput.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,270 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __MMF_AUDIOINPUT_H__
    1.20 +#define __MMF_AUDIOINPUT_H__
    1.21 +
    1.22 +// Standard EPOC32 includes required by this header file
    1.23 +#include <e32base.h>
    1.24 +#include <e32std.h>
    1.25 +
    1.26 +// Public Media Server includes
    1.27 +#include <mmf/common/mmfpaniccodes.h>
    1.28 +
    1.29 +//DevSound
    1.30 +#include <mmf/server/sounddevice.h>
    1.31 +
    1.32 +/** 
    1.33 +@publishedAll
    1.34 +@deprecated
    1.35 +*/
    1.36 +const TUint KAudioInputDefaultFrameSize = 0x1000;  //4K
    1.37 +//#define KAudioInputCanResample		//uncomment this to allow Audio Input to sample rate convert 
    1.38 +
    1.39 +
    1.40 +void Panic(TInt aPanicCode);
    1.41 +
    1.42 +
    1.43 +/**
    1.44 +@publishedAll
    1.45 +@released
    1.46 +
    1.47 +Interface class to allow dynamic linkage to CMMFAudioInput.
    1.48 +*/
    1.49 +class MMMFAudioInput : public MDataSource
    1.50 +	{
    1.51 +public:
    1.52 +
    1.53 +	//factory function
    1.54 +	inline static MMMFAudioInput* NewAudioInputL(TUid aImplementationUid, const TDesC8& aInitData);
    1.55 +
    1.56 +	//interface
    1.57 +	/**
    1.58 +	Returns the sound device.
    1.59 +
    1.60 +	@return A reference to a CMMFDevSound objector. Accessor function exposing public CMMFDevsound methods.
    1.61 +	*/
    1.62 +	virtual CMMFDevSound& SoundDevice() = 0;
    1.63 +
    1.64 +	/**
    1.65 +	Returns the number of bytes played.
    1.66 +
    1.67 +	@return	The number of bytes played. If 16-bit divide this number returned by 2 to get word length.
    1.68 +	*/
    1.69 +	virtual TInt BytesPlayed() = 0;
    1.70 +
    1.71 +	/**
    1.72 +	@deprecated
    1.73 +
    1.74 +	Gets audio from hardware device abstracted MMFDevsound (not used).
    1.75 +
    1.76 +	@param  aBuffer
    1.77 +	        The data to read in from a Hardware Device
    1.78 +	@param  aConsumer
    1.79 +	        The MDataSink consuming the data contained in aBuffer.
    1.80 +	*/
    1.81 +	virtual void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer) = 0;
    1.82 +protected:
    1.83 +	//constructor
    1.84 +	/**
    1.85 +	Protected constructor.
    1.86 +	*/
    1.87 +	inline MMMFAudioInput() : MDataSource(KUidMmfAudioInput) {};
    1.88 +	};
    1.89 +
    1.90 +/**
    1.91 +Allocates and constructs an audio input object. 
    1.92 +
    1.93 +Calls MDataSource::NewSourceL().
    1.94 +
    1.95 +@param  aImplementationUid
    1.96 +		The Implementation UID.
    1.97 +@param  aInitData
    1.98 +		The initialisation data.
    1.99 +
   1.100 +@return A new audio input object.
   1.101 +*/
   1.102 +inline MMMFAudioInput* MMMFAudioInput::NewAudioInputL( TUid aImplementationUid,  const TDesC8& aInitData )
   1.103 +	{
   1.104 +	//make sure the cast will be ok by checking the uid is what we expect
   1.105 +	__ASSERT_ALWAYS(aImplementationUid==KUidMmfAudioInput, Panic(EMMFAudioInputPanicBadUID));
   1.106 +	MMMFAudioInput* retPtr = STATIC_CAST(MMMFAudioInput*, MDataSource::NewSourceL(aImplementationUid, aInitData));
   1.107 +	return retPtr;
   1.108 +	}
   1.109 +
   1.110 +/**
   1.111 +@publishedAll
   1.112 +@released
   1.113 +
   1.114 +Concrete data source to provide microphone support.
   1.115 +
   1.116 +Intended to be used by controller plugin developers for source plugins. Uses CMMFDevSound to access
   1.117 +hardware.
   1.118 +*/
   1.119 +class CMMFAudioInput : public CBase, public MMMFAudioInput, public MDevSoundObserver
   1.120 +
   1.121 +	{
   1.122 +public:
   1.123 +
   1.124 +	static MDataSource* NewSourceL();
   1.125 +	virtual ~CMMFAudioInput();
   1.126 +	void ConstructL();
   1.127 +
   1.128 +	//MDataSource mixin implementations
   1.129 +	virtual TFourCC SourceDataTypeCode(TMediaId aMediaId);
   1.130 +	virtual void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer,TMediaId aMediaId);//called by a MDataSink to request buffer fill
   1.131 +	virtual void BufferEmptiedL(CMMFBuffer* aBuffer); //called by MDataSink to pass back emptied buffer to the source
   1.132 +	virtual TBool CanCreateSourceBuffer();
   1.133 +	virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId);
   1.134 +
   1.135 +	inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer);
   1.136 +
   1.137 +	virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference);
   1.138 +
   1.139 +	inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference);
   1.140 +	virtual TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler);
   1.141 +	virtual void SourceThreadLogoff();
   1.142 +	virtual void SourcePrimeL();
   1.143 +	virtual void SourceStopL();
   1.144 +	virtual void SourcePlayL();
   1.145 +	virtual void SourcePauseL();
   1.146 +	virtual void SetSourcePrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
   1.147 +
   1.148 +	virtual void NegotiateSourceL(MDataSink& aSink);
   1.149 +
   1.150 +	// MMMFAudioInput mixin implementations
   1.151 +	TInt BytesPlayed();
   1.152 +	void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer); //called by a FillBufferL if using HW codec
   1.153 +	CMMFDevSound& SoundDevice();
   1.154 +	virtual TInt SetSourceDataTypeCode(TFourCC aSourceFourCC, TMediaId aMediaId);
   1.155 +
   1.156 +	void LoadL();
   1.157 +
   1.158 +	//The following DataType() methods and iBufferStatus should not be used.
   1.159 +	//They are provided to maintain BC/SC with 7.0s
   1.160 +	virtual void SetDataTypeL(TFourCC aAudioType);
   1.161 +	virtual TFourCC DataType() const;
   1.162 +	/**
   1.163 +	Buffer completion status.
   1.164 +	*/
   1.165 +	TRequestStatus iBufferStatus;
   1.166 +
   1.167 +protected:
   1.168 +	virtual void ConstructSourceL( const TDesC8& aInitData ) ;
   1.169 +
   1.170 +private:
   1.171 +	inline CMMFAudioInput() {}
   1.172 +
   1.173 +	MAsyncEventHandler* iEventHandler;
   1.174 +	CMMFDevSound* iMMFDevSound;	//this is now private to stop stuff "grabbing it"
   1.175 +	
   1.176 +	//MDevSoundObserver mixin implementations
   1.177 +	virtual void InitializeComplete(TInt aError);
   1.178 +	virtual void ToneFinished(TInt aError);
   1.179 +	virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
   1.180 +	virtual void PlayError(TInt aError); 
   1.181 +	virtual void BufferToBeEmptied(CMMFBuffer* aBuffer); 
   1.182 +	virtual void RecordError(TInt aError); 
   1.183 +	virtual void ConvertError(TInt aError);
   1.184 +	virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
   1.185 +	virtual void SendEventToClient(const TMMFEvent& /*aEvent*/);
   1.186 +
   1.187 +	void ConfigDevSoundL();
   1.188 +	
   1.189 +private:
   1.190 +	
   1.191 +	enum TCodec
   1.192 +		{
   1.193 +		EUseARMCodec=0,
   1.194 +		EUseHWCodec
   1.195 +		};
   1.196 +
   1.197 +	enum TState
   1.198 +		{
   1.199 +		EIdle=0,
   1.200 +		EPaused,
   1.201 +		EDevSoundReady,
   1.202 +		EBufferEmpty
   1.203 +		};
   1.204 +
   1.205 +	enum TError
   1.206 +		{
   1.207 +		ECantCreateBuffer,
   1.208 +		EEmptyBuffer,
   1.209 +		EDevSoundNotLoaded,
   1.210 +		EUnknown
   1.211 +		}; 
   1.212 +	
   1.213 +
   1.214 +	MDataSink* iConsumer;
   1.215 +	TState iState;
   1.216 +
   1.217 +	TBool iFirstBufferRequested;
   1.218 +	TBool iFirstBufferRead;
   1.219 +
   1.220 +	TBool iDevSoundLoaded;
   1.221 +	TBool iStopped;
   1.222 +
   1.223 +	TError iError;
   1.224 +	TInt iMMFDevsoundError;
   1.225 +	TMMFPrioritySettings iPrioritySettings;
   1.226 +
   1.227 +	TUint iSinkSampleRate;
   1.228 +	TUint iSinkChannels;
   1.229 +	TFourCC iSinkFourCC;
   1.230 +	TFourCC iDataTypeCode;
   1.231 +	CMMFBuffer* iDevSoundBuf;
   1.232 +
   1.233 +	TBool iPausePending;
   1.234 +	TInt iInitializeState;	
   1.235 + 	CActiveSchedulerWait* iActiveSchedulerWait;
   1.236 +	};
   1.237 +
   1.238 +/**
   1.239 +Intended for synchronous usage (returns buffer specific to a Media Type).
   1.240 +
   1.241 +@param	aMediaId
   1.242 +        The Media ID.
   1.243 +@param	aSinkBuffer
   1.244 +        Not Used.
   1.245 +
   1.246 +@return A pointer to the CMMFBuffer source buffer.
   1.247 +*/
   1.248 +inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/)
   1.249 +{
   1.250 +	return CreateSourceBufferL(aMediaId);
   1.251 +}
   1.252 +
   1.253 +/**
   1.254 +Creates a source buffer.
   1.255 +
   1.256 +Intended for asynchronous usage (returns buffer specific to a Media Type).
   1.257 +
   1.258 +@param  aMediaId
   1.259 +        The Media ID.
   1.260 +@param  aSinkBuffer
   1.261 +        Not used.
   1.262 +@param	aReference
   1.263 +        A boolean indicating if MDataSource owns the buffer. If EFalse the the caller owns the 
   1.264 +        buffer.
   1.265 +
   1.266 +@return The source buffer.
   1.267 +*/
   1.268 +inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/, TBool &aReference)
   1.269 +{
   1.270 +	return CreateSourceBufferL(aMediaId, aReference);
   1.271 +}
   1.272 +
   1.273 +#endif