Update contrib.
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 #include <mmf/server/mmfhwdevice.h>
24 #include <mmf/server/mmfhwdevicesetup.h>
25 #include <mmf/server/sounddevice.h>
26 #include <a3f/a3f_trace_utils.h>
27 #include <a3f/a3fbase.h>
29 #include "hwdeviceimplementationuids.hrh"
31 #include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
33 #include "moutputport.h"
34 #include "minputport.h"
35 #include "mgainhelper.h"
36 #include "mstreampositioncontrol.h"
38 #include <a3f/msynccisupport.h>
39 #include <a3f/maudiocodec.h>
41 #define KFOURCCLENGTH 4
52 class TSampleRateTableEntry
55 TInt iSampleRateValue;
56 TMMFSampleRate iSampleRate;
59 class TAudioModeTableEntry
62 TMMFMonoStereo iAudioModeValue;
66 const TInt KMaxModeIndex = 1;
70 class MAudioCodecAdaptationObserver;
71 class CFourCCConvertor;
74 //This is the reference implementation of Phyisical AudioCodec
78 // TODO: Check if those interfaces MInputPort, MOutputPort should be replaced by MMMFAudioDataSupplier, MMMFAudioDataConsumer
81 NONSHARABLE_CLASS(CAudioCodec) :public CActive,
82 public MMMFHwDeviceObserver,
83 public MInputPort, // Adaptation interface
84 public MOutputPort, // Adaptation interface
85 public MGainHelper, // Adaptation interface
86 public MCustomInterfaceSupport, // A3F interface
87 public MStreamPositionControl // Adaptation interface
89 friend class CAudioGainControl;
93 // Create a new instance.
96 // @return CAudioCodec* a pointer to the created instance.
99 IMPORT_C static CAudioCodec* NewL(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor);
101 // Check if this would be removed
103 // Structure to hold hw device init parameters
105 class THwDeviceInitArgs
115 // Deletes all objects and releases all resource owned by this instance.
117 virtual ~CAudioCodec();
120 IMPORT_C TInt SetFormat(TUid aFormat);
121 IMPORT_C TInt RegisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver);
122 IMPORT_C void UnregisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver);
123 IMPORT_C TInt Initialize();
124 IMPORT_C TInt Load(TInt aSampleRate, TUid aMode);
125 IMPORT_C TInt Start();
126 IMPORT_C TInt Pause();
127 IMPORT_C TInt Stop();
132 TInt GetOutputPort(MOutputPort*& aOutputPort);
135 TInt GetInputPort(MInputPort*& aInputPort);
137 // From MCustomInterfaceSupport
138 virtual TInt RequestCustomInterface(TUid aUid, TAny*& aPtr);
139 virtual TInt RegisterObserver(MCustomInterfaceSupportObserver& aObserver);
140 virtual void UnRegisterObserver(MCustomInterfaceSupportObserver& aObserver);
142 // from base class MInputPort
143 virtual TInt EmptyBuffer(CMMFBuffer* aBuffer, MOutputPort* aSupplier);
144 virtual TInt BufferFilled(CMMFBuffer* aBuffer);
145 virtual TInt SetOutput(MOutputPort* aOutput);
146 virtual TInt RemoveOutput(MOutputPort* aOutput);
148 // from base class MOutputPort
149 virtual TInt FillBuffer(CMMFBuffer* aBuffer, MInputPort* aConsumer);
150 virtual TInt BufferEmptied(CMMFBuffer* aBuffer);
151 virtual TInt SetInput(MInputPort* aInput);
152 virtual TInt RemoveInput(MInputPort* aInput);
153 virtual TInt FlushBuffer(MFlushHandlerObserver* aFlushObserver);
155 // from base class MMMFHwDeviceObserver
156 virtual TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
157 virtual TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer);
158 virtual TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg);
159 virtual void Stopped();
160 virtual void Error(TInt aError);
162 // from base class MGainHelper
163 TInt GetGain(TInt& aGain) const;
164 TInt SetGain(RArray<TAudioChannelGain>& aChannels);
165 TInt ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration);
167 // from base class MStreamPositionControl
168 TInt GetControlPosition(TTimeIntervalMicroSeconds& aPosition);
169 void ResetControlPosition();
172 TInt ResolveMode(TUid aMode);
173 TInt GetSupportedSampleRates(RArray<TInt>& aSupportedRates);
174 TInt GetSupportedModes(RArray<TUid>& aSupportedModes);
176 //Return the supported values to the client
177 IMPORT_C TInt SupportedModes(RArray<TUid>& aSupportedModes);
178 IMPORT_C TInt SupportedRates(RArray<TInt>& aSupportedRates);
184 TInt RunError(TInt aError);
188 TInt SetHwDeviceConfig();
189 void FourCCToHwDeviceUidL(TFourCC aFourCC, TMode aMode, TUid &aHWDev);
191 TBool IsDataTypeMatch(CImplementationInformation* aHwDeviceResourceEntry,
192 const TDesC8& aHwMatchFourCC, TMode aState);
194 // TODO: This will be replaced, when the new mechanism to get the supported configuration
197 // Reads hw device parameters from resource files.
198 // @return error code.
200 TInt ReadResourceRates(RArray<TInt>& aRates);
201 TInt ReadResourceModes(RArray<TUid>& aModes);
203 void UpdateBytesPlayed();
208 CAudioCodec(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor);
212 // Indicates if this is an encoder or decoder
218 // Resolved HwDevice Uid
223 MPlayCustomInterface* iPlayCustomInterface;
225 MRecordCustomInterface* iRecordCustomInterface;
227 // HwDevice init parameters
228 THwDeviceInitParams iHwDeviceInitParams;
229 THwDeviceInitArgs iHwDeviceInitArgs;
232 RPointerArray<MCustomInterfaceSupportObserver> iCISupportObservers;
243 THwDeviceState iHwDeviceState;
244 TBool iLastBufferAck;
248 TInt iSampleRateConfig;
251 CMMFHwDevice* iHwDevice;
252 CMMFDataBuffer* iAdaptationBuffer;
254 MOutputPort* iOutputPort;
255 MInputPort* iInputPort;
257 TInt64 iPlayedBytesCount;
259 CFourCCConvertor* iFourCCConvertor;
260 RPointerArray<MAudioCodecAdaptationObserver> iAudioCodecObservers;
261 MIgnoreUnderflowEventsCustomInterface* iIgnoreUnderflowInterface;
263 TTimeIntervalMicroSeconds iRampDuration;
267 * Updates the total bytes played.
270 inline void CAudioCodec::UpdateBytesPlayed()
272 if (iPlayCustomInterface)
274 iPlayedBytesCount = iPlayCustomInterface->BytesPlayed();
278 #endif // AUDIOCODEC_H