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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __MMF_AUDIOOUTPUT_H__
17 #define __MMF_AUDIOOUTPUT_H__
19 // Standard EPOC32 includes required by this header file
24 #include <mmf/common/mmfpaniccodes.h>
27 #include <mmf/server/sounddevice.h>
33 const TUint KAudioOutputDefaultFrameSize = 0x1000;
36 void Panic(TInt aPanicCode);
42 Interface class to allow dynamic linkage to CMMFAudioOutput.
44 class MMMFAudioOutput : public MDataSink
49 Gets a new audio output object.
51 @param aImplementationUid
52 The implementation UID.
54 The initialisation data.
56 @return The audio output object.
58 inline static MMMFAudioOutput* NewAudioOutputL(TUid aImplementationUid, const TDesC8& aInitData);
62 Returns the sound device.
64 Accessor function exposing public CMMFDevsound methods.
66 @return A reference to a CMMFDevSound objector.
68 virtual CMMFDevSound& SoundDevice() = 0;
71 Returns the number of bytes played.
73 @return The number of bytes played. If 16-bit divide this number returned by 2 to get word
76 virtual TInt BytesPlayed() = 0;
81 Gets audio from hardware device abstracted MMFDevsound (not used).
84 The data to read in from a Hardware Device
86 The MDataSink consuming the data contained in aBuffer.
88 virtual void HWEmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier)=0;//called by a EmptyBufferL if using HW codec
92 Protected constructor.
94 MMMFAudioOutput() : MDataSink(KUidMmfAudioOutput) {}
97 inline MMMFAudioOutput* MMMFAudioOutput::NewAudioOutputL( TUid aImplementationUid, const TDesC8& aInitData )
99 //make sure the cast will be ok by checking the uid is what we expect
100 __ASSERT_ALWAYS(aImplementationUid==KUidMmfAudioOutput, Panic(EMMFAudioOutputPanicBadUID));
101 MMMFAudioOutput* retPtr = STATIC_CAST(MMMFAudioOutput*, MDataSink::NewSinkL(aImplementationUid, aInitData));
109 The interface into DevSound.
111 Abstract data sink class providing an interface into hardware sound output.
113 Uses CMMFDevSound to access such output.
115 class CMMFChannelAndSampleRateConverterFactory;
116 class CMMFChannelAndSampleRateConverter;
117 class CMMFAudioOutput : public CBase, public MMMFAudioOutput, public MDevSoundObserver
121 static MDataSink* NewSinkL() ;
122 virtual ~CMMFAudioOutput();
125 //MDataSink mixin implementations
126 virtual TFourCC SinkDataTypeCode(TMediaId aMediaId); //used by data path MDataSource/Sink for codec matching
127 virtual void EmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier, TMediaId aMediaId);//called by a MDataSource to empty a buffer
128 virtual void BufferFilledL(CMMFBuffer* aBuffer); //called by MDataSource to pass back full buffer to the sink
129 virtual TBool CanCreateSinkBuffer();
130 virtual CMMFBuffer* CreateSinkBufferL(TMediaId aMediaId, TBool &aReference);
131 virtual TInt SinkThreadLogon(MAsyncEventHandler& aEventHandler);
132 virtual void SinkThreadLogoff();
133 virtual void SinkPrimeL();
134 virtual void SinkPauseL();
135 virtual void SinkPlayL();
136 virtual void SinkStopL();
137 virtual void SetSinkPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
138 virtual void NegotiateL(MDataSource& aSource);
139 // MMMFAudioOutput mixin implementations
141 void HWEmptyBufferL(CMMFBuffer* aBuffer, MDataSource* aSupplier);//called by a EmptyBufferL if using HW codec
142 CMMFDevSound& SoundDevice();
143 virtual TInt SetSinkDataTypeCode(TFourCC aSinkFourCC, TMediaId aMediaId);
145 //The following DataType() methods should not be used.
146 //They are provided to maintain BC/SC with 7.0s
147 virtual void SetDataTypeL(TFourCC aAudioType);
148 virtual TFourCC DataType() const;
151 virtual void ConstructSinkL( const TDesC8& aInitData ) ;
154 inline CMMFAudioOutput() {}
156 void ConfigDevSoundL();
160 //MDevSoundObserver mixin implementations
161 virtual void InitializeComplete(TInt aError);
162 virtual void ToneFinished(TInt aError);
163 virtual void BufferToBeFilled(CMMFBuffer* aBuffer);
164 virtual void PlayError(TInt aError);
165 virtual void BufferToBeEmptied(CMMFBuffer* aBuffer);
166 virtual void RecordError(TInt aError);
167 virtual void ConvertError(TInt aError);
168 virtual void DeviceMessage(TUid aMessageType, const TDesC8& aMsg);
169 virtual void SendEventToClient(const TMMFEvent& /*aEvent*/);
172 virtual TBool IsResumeSupported();
175 MAsyncEventHandler* iEventHandler;
176 CMMFDevSound* iMMFDevSound; //this is now private to stop stuff "grabbing it"
177 CMMFBuffer* iAudioBuffer;
178 TInt iInitializeState;
196 MDataSource* iSupplier;
199 TBool iCanSendBuffers;
201 TBool iDevSoundLoaded;
204 TInt iMMFDevsoundError;
205 TMMFPrioritySettings iPrioritySettings;
207 TUint iSourceSampleRate;
208 TUint iSourceChannels;
209 TFourCC iSourceFourCC;
210 TFourCC iDataTypeCode;
211 CMMFDataBuffer* iDevSoundBuffer;
213 TMMFCapabilities iDevSoundConfig;
215 TBool iNeedsSWConversion;
216 TUint iSWConvertSampleRate;
217 TUint iSWConvertChannels;
218 CMMFChannelAndSampleRateConverterFactory* iChannelAndSampleRateConverterFactory;
219 CMMFChannelAndSampleRateConverter* iChannelAndSampleRateConverter;
220 CMMFDataBuffer* iConvertBuffer;
221 CMMFBuffer* iBufferToEmpty;
222 CActiveSchedulerWait* iActiveSchedulerWait;