sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __MMF_AUDIOINPUT_H__ sl@0: #define __MMF_AUDIOINPUT_H__ sl@0: sl@0: // Standard EPOC32 includes required by this header file sl@0: #include sl@0: #include sl@0: sl@0: // Public Media Server includes sl@0: #include sl@0: sl@0: //DevSound sl@0: #include sl@0: sl@0: /** sl@0: @publishedAll sl@0: @deprecated sl@0: */ sl@0: const TUint KAudioInputDefaultFrameSize = 0x1000; //4K sl@0: //#define KAudioInputCanResample //uncomment this to allow Audio Input to sample rate convert sl@0: sl@0: sl@0: void Panic(TInt aPanicCode); sl@0: sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Interface class to allow dynamic linkage to CMMFAudioInput. sl@0: */ sl@0: class MMMFAudioInput : public MDataSource sl@0: { sl@0: public: sl@0: sl@0: //factory function sl@0: inline static MMMFAudioInput* NewAudioInputL(TUid aImplementationUid, const TDesC8& aInitData); sl@0: sl@0: //interface sl@0: /** sl@0: Returns the sound device. sl@0: sl@0: @return A reference to a CMMFDevSound objector. Accessor function exposing public CMMFDevsound methods. sl@0: */ sl@0: virtual CMMFDevSound& SoundDevice() = 0; sl@0: sl@0: /** sl@0: Returns the number of bytes played. sl@0: sl@0: @return The number of bytes played. If 16-bit divide this number returned by 2 to get word length. sl@0: */ sl@0: virtual TInt BytesPlayed() = 0; sl@0: sl@0: /** sl@0: @deprecated sl@0: sl@0: Gets audio from hardware device abstracted MMFDevsound (not used). sl@0: sl@0: @param aBuffer sl@0: The data to read in from a Hardware Device sl@0: @param aConsumer sl@0: The MDataSink consuming the data contained in aBuffer. sl@0: */ sl@0: virtual void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer) = 0; sl@0: protected: sl@0: //constructor sl@0: /** sl@0: Protected constructor. sl@0: */ sl@0: inline MMMFAudioInput() : MDataSource(KUidMmfAudioInput) {}; sl@0: }; sl@0: sl@0: /** sl@0: Allocates and constructs an audio input object. sl@0: sl@0: Calls MDataSource::NewSourceL(). sl@0: sl@0: @param aImplementationUid sl@0: The Implementation UID. sl@0: @param aInitData sl@0: The initialisation data. sl@0: sl@0: @return A new audio input object. sl@0: */ sl@0: inline MMMFAudioInput* MMMFAudioInput::NewAudioInputL( TUid aImplementationUid, const TDesC8& aInitData ) sl@0: { sl@0: //make sure the cast will be ok by checking the uid is what we expect sl@0: __ASSERT_ALWAYS(aImplementationUid==KUidMmfAudioInput, Panic(EMMFAudioInputPanicBadUID)); sl@0: MMMFAudioInput* retPtr = STATIC_CAST(MMMFAudioInput*, MDataSource::NewSourceL(aImplementationUid, aInitData)); sl@0: return retPtr; sl@0: } sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: sl@0: Concrete data source to provide microphone support. sl@0: sl@0: Intended to be used by controller plugin developers for source plugins. Uses CMMFDevSound to access sl@0: hardware. sl@0: */ sl@0: class CMMFAudioInput : public CBase, public MMMFAudioInput, public MDevSoundObserver sl@0: sl@0: { sl@0: public: sl@0: sl@0: static MDataSource* NewSourceL(); sl@0: virtual ~CMMFAudioInput(); sl@0: void ConstructL(); sl@0: sl@0: //MDataSource mixin implementations sl@0: virtual TFourCC SourceDataTypeCode(TMediaId aMediaId); sl@0: virtual void FillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer,TMediaId aMediaId);//called by a MDataSink to request buffer fill sl@0: virtual void BufferEmptiedL(CMMFBuffer* aBuffer); //called by MDataSink to pass back emptied buffer to the source sl@0: virtual TBool CanCreateSourceBuffer(); sl@0: virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId); sl@0: sl@0: inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer); sl@0: sl@0: virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference); sl@0: sl@0: inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer, TBool &aReference); sl@0: virtual TInt SourceThreadLogon(MAsyncEventHandler& aEventHandler); sl@0: virtual void SourceThreadLogoff(); sl@0: virtual void SourcePrimeL(); sl@0: virtual void SourceStopL(); sl@0: virtual void SourcePlayL(); sl@0: virtual void SourcePauseL(); sl@0: virtual void SetSourcePrioritySettings(const TMMFPrioritySettings& aPrioritySettings); sl@0: sl@0: virtual void NegotiateSourceL(MDataSink& aSink); sl@0: sl@0: // MMMFAudioInput mixin implementations sl@0: TInt BytesPlayed(); sl@0: void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer); //called by a FillBufferL if using HW codec sl@0: CMMFDevSound& SoundDevice(); sl@0: virtual TInt SetSourceDataTypeCode(TFourCC aSourceFourCC, TMediaId aMediaId); sl@0: sl@0: void LoadL(); sl@0: sl@0: //The following DataType() methods and iBufferStatus should not be used. sl@0: //They are provided to maintain BC/SC with 7.0s sl@0: virtual void SetDataTypeL(TFourCC aAudioType); sl@0: virtual TFourCC DataType() const; sl@0: /** sl@0: Buffer completion status. sl@0: */ sl@0: TRequestStatus iBufferStatus; sl@0: sl@0: protected: sl@0: virtual void ConstructSourceL( const TDesC8& aInitData ) ; sl@0: sl@0: private: sl@0: inline CMMFAudioInput() {} sl@0: sl@0: MAsyncEventHandler* iEventHandler; sl@0: CMMFDevSound* iMMFDevSound; //this is now private to stop stuff "grabbing it" sl@0: sl@0: //MDevSoundObserver mixin implementations sl@0: virtual void InitializeComplete(TInt aError); sl@0: virtual void ToneFinished(TInt aError); sl@0: virtual void BufferToBeFilled(CMMFBuffer* aBuffer); sl@0: virtual void PlayError(TInt aError); sl@0: virtual void BufferToBeEmptied(CMMFBuffer* aBuffer); sl@0: virtual void RecordError(TInt aError); sl@0: virtual void ConvertError(TInt aError); sl@0: virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg); sl@0: virtual void SendEventToClient(const TMMFEvent& /*aEvent*/); sl@0: sl@0: void ConfigDevSoundL(); sl@0: sl@0: private: sl@0: sl@0: enum TCodec sl@0: { sl@0: EUseARMCodec=0, sl@0: EUseHWCodec sl@0: }; sl@0: sl@0: enum TState sl@0: { sl@0: EIdle=0, sl@0: EPaused, sl@0: EDevSoundReady, sl@0: EBufferEmpty sl@0: }; sl@0: sl@0: enum TError sl@0: { sl@0: ECantCreateBuffer, sl@0: EEmptyBuffer, sl@0: EDevSoundNotLoaded, sl@0: EUnknown sl@0: }; sl@0: sl@0: sl@0: MDataSink* iConsumer; sl@0: TState iState; sl@0: sl@0: TBool iFirstBufferRequested; sl@0: TBool iFirstBufferRead; sl@0: sl@0: TBool iDevSoundLoaded; sl@0: TBool iStopped; sl@0: sl@0: TError iError; sl@0: TInt iMMFDevsoundError; sl@0: TMMFPrioritySettings iPrioritySettings; sl@0: sl@0: TUint iSinkSampleRate; sl@0: TUint iSinkChannels; sl@0: TFourCC iSinkFourCC; sl@0: TFourCC iDataTypeCode; sl@0: CMMFBuffer* iDevSoundBuf; sl@0: sl@0: TBool iPausePending; sl@0: TInt iInitializeState; sl@0: CActiveSchedulerWait* iActiveSchedulerWait; sl@0: }; sl@0: sl@0: /** sl@0: Intended for synchronous usage (returns buffer specific to a Media Type). sl@0: sl@0: @param aMediaId sl@0: The Media ID. sl@0: @param aSinkBuffer sl@0: Not Used. sl@0: sl@0: @return A pointer to the CMMFBuffer source buffer. sl@0: */ sl@0: inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/) sl@0: { sl@0: return CreateSourceBufferL(aMediaId); sl@0: } sl@0: sl@0: /** sl@0: Creates a source buffer. sl@0: sl@0: Intended for asynchronous usage (returns buffer specific to a Media Type). sl@0: sl@0: @param aMediaId sl@0: The Media ID. sl@0: @param aSinkBuffer sl@0: Not used. sl@0: @param aReference sl@0: A boolean indicating if MDataSource owns the buffer. If EFalse the the caller owns the sl@0: buffer. sl@0: sl@0: @return The source buffer. sl@0: */ sl@0: inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/, TBool &aReference) sl@0: { sl@0: return CreateSourceBufferL(aMediaId, aReference); sl@0: } sl@0: sl@0: #endif