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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __MMF_AUDIOINPUT_H__
17 #define __MMF_AUDIOINPUT_H__
19 // Standard EPOC32 includes required by this header file
23 // Public Media Server includes
24 #include <mmfaudioiointerfaceuids.hrh>
25 #include <mmf/common/mmfpaniccodes.h>
28 #include <mmf/server/sounddevice.h>
34 const TUint KAudioInputDefaultFrameSize = 0x1000; //4K
35 //#define KAudioInputCanResample //uncomment this to allow Audio Input to sample rate convert
38 void Panic(TInt aPanicCode);
45 Interface class to allow dynamic linkage to CMMFAudioInput.
47 class MMMFAudioInput : public MDataSource
52 inline static MMMFAudioInput* NewAudioInputL(TUid aImplementationUid, const TDesC8& aInitData);
56 Returns the sound device.
58 @return A reference to a CMMFDevSound objector. Accessor function exposing public CMMFDevsound methods.
60 virtual CMMFDevSound& SoundDevice() = 0;
63 Returns the number of bytes played.
65 @return The number of bytes played. If 16-bit divide this number returned by 2 to get word length.
67 virtual TInt BytesPlayed() = 0;
72 Gets audio from hardware device abstracted MMFDevsound (not used).
75 The data to read in from a Hardware Device
77 The MDataSink consuming the data contained in aBuffer.
79 virtual void HWFillBufferL(CMMFBuffer* aBuffer, MDataSink* aConsumer) = 0;
83 Protected constructor.
85 inline MMMFAudioInput() : MDataSource(KUidMmfAudioInput) {};
89 Allocates and constructs an audio input object.
91 Calls MDataSource::NewSourceL().
93 @param aImplementationUid
94 The Implementation UID.
96 The initialisation data.
98 @return A new audio input object.
100 inline MMMFAudioInput* MMMFAudioInput::NewAudioInputL( TUid aImplementationUid, const TDesC8& aInitData )
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));
112 Concrete data source to provide microphone support.
114 Intended to be used by controller plugin developers for source plugins. Uses CMMFDevSound to access
117 class CMMFAudioInput : public CBase, public MMMFAudioInput, public MDevSoundObserver
122 static MDataSource* NewSourceL();
123 virtual ~CMMFAudioInput();
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);
133 inline virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& aSinkBuffer);
135 virtual CMMFBuffer* CreateSourceBufferL(TMediaId aMediaId, TBool &aReference);
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);
146 virtual void NegotiateSourceL(MDataSink& aSink);
148 // MMMFAudioInput mixin implementations
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);
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;
161 Buffer completion status.
163 TRequestStatus iBufferStatus;
166 virtual void ConstructSourceL( const TDesC8& aInitData ) ;
169 inline CMMFAudioInput() {}
171 MAsyncEventHandler* iEventHandler;
172 CMMFDevSound* iMMFDevSound; //this is now private to stop stuff "grabbing it"
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*/);
185 void ConfigDevSoundL();
212 MDataSink* iConsumer;
215 TBool iFirstBufferRequested;
216 TBool iFirstBufferRead;
218 TBool iDevSoundLoaded;
222 TInt iMMFDevsoundError;
223 TMMFPrioritySettings iPrioritySettings;
225 TUint iSinkSampleRate;
228 TFourCC iDataTypeCode;
229 CMMFBuffer* iDevSoundBuf;
232 TInt iInitializeState;
233 CActiveSchedulerWait* iActiveSchedulerWait;
237 Intended for synchronous usage (returns buffer specific to a Media Type).
244 @return A pointer to the CMMFBuffer source buffer.
246 inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/)
248 return CreateSourceBufferL(aMediaId);
252 Creates a source buffer.
254 Intended for asynchronous usage (returns buffer specific to a Media Type).
261 A boolean indicating if MDataSource owns the buffer. If EFalse the the caller owns the
264 @return The source buffer.
266 inline CMMFBuffer* CMMFAudioInput::CreateSourceBufferL(TMediaId aMediaId, CMMFBuffer& /*aSinkBuffer*/, TBool &aReference)
268 return CreateSourceBufferL(aMediaId, aReference);