sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#ifndef AUDIOCODEC_H
|
sl@0
|
20 |
#define AUDIOCODEC_H
|
sl@0
|
21 |
|
sl@0
|
22 |
#include <e32base.h>
|
sl@0
|
23 |
#include <mmf/server/mmfhwdevice.h>
|
sl@0
|
24 |
#include <mmf/server/mmfhwdevicesetup.h>
|
sl@0
|
25 |
#include <mmf/server/sounddevice.h>
|
sl@0
|
26 |
#include <a3f/a3f_trace_utils.h>
|
sl@0
|
27 |
#include <a3f/a3fbase.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
#include "hwdeviceimplementationuids.hrh"
|
sl@0
|
30 |
|
sl@0
|
31 |
#include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
|
sl@0
|
32 |
|
sl@0
|
33 |
#include "moutputport.h"
|
sl@0
|
34 |
#include "minputport.h"
|
sl@0
|
35 |
#include "mgainhelper.h"
|
sl@0
|
36 |
#include "mstreampositioncontrol.h"
|
sl@0
|
37 |
|
sl@0
|
38 |
#include <a3f/msynccisupport.h>
|
sl@0
|
39 |
#include <a3f/maudiocodec.h>
|
sl@0
|
40 |
|
sl@0
|
41 |
#define KFOURCCLENGTH 4
|
sl@0
|
42 |
|
sl@0
|
43 |
|
sl@0
|
44 |
enum TMode
|
sl@0
|
45 |
{
|
sl@0
|
46 |
// Decoder mode
|
sl@0
|
47 |
EDecode = 0x01,
|
sl@0
|
48 |
// And vice versa
|
sl@0
|
49 |
EEncode = 0x02
|
sl@0
|
50 |
};
|
sl@0
|
51 |
|
sl@0
|
52 |
class TSampleRateTableEntry
|
sl@0
|
53 |
{
|
sl@0
|
54 |
public:
|
sl@0
|
55 |
TInt iSampleRateValue;
|
sl@0
|
56 |
TMMFSampleRate iSampleRate;
|
sl@0
|
57 |
};
|
sl@0
|
58 |
|
sl@0
|
59 |
class TAudioModeTableEntry
|
sl@0
|
60 |
{
|
sl@0
|
61 |
public:
|
sl@0
|
62 |
TMMFMonoStereo iAudioModeValue;
|
sl@0
|
63 |
TUid iAudioMode;
|
sl@0
|
64 |
};
|
sl@0
|
65 |
|
sl@0
|
66 |
const TInt KMaxModeIndex = 1;
|
sl@0
|
67 |
|
sl@0
|
68 |
|
sl@0
|
69 |
|
sl@0
|
70 |
class MAudioCodecAdaptationObserver;
|
sl@0
|
71 |
class CFourCCConvertor;
|
sl@0
|
72 |
|
sl@0
|
73 |
/////
|
sl@0
|
74 |
//This is the reference implementation of Phyisical AudioCodec
|
sl@0
|
75 |
//@lib audiocodec.lib
|
sl@0
|
76 |
///
|
sl@0
|
77 |
|
sl@0
|
78 |
// TODO: Check if those interfaces MInputPort, MOutputPort should be replaced by MMMFAudioDataSupplier, MMMFAudioDataConsumer
|
sl@0
|
79 |
|
sl@0
|
80 |
|
sl@0
|
81 |
NONSHARABLE_CLASS(CAudioCodec) :public CActive,
|
sl@0
|
82 |
public MMMFHwDeviceObserver,
|
sl@0
|
83 |
public MInputPort, // Adaptation interface
|
sl@0
|
84 |
public MOutputPort, // Adaptation interface
|
sl@0
|
85 |
public MGainHelper, // Adaptation interface
|
sl@0
|
86 |
public MCustomInterfaceSupport, // A3F interface
|
sl@0
|
87 |
public MStreamPositionControl // Adaptation interface
|
sl@0
|
88 |
{
|
sl@0
|
89 |
friend class CAudioGainControl;
|
sl@0
|
90 |
public:
|
sl@0
|
91 |
|
sl@0
|
92 |
/////
|
sl@0
|
93 |
// Create a new instance.
|
sl@0
|
94 |
//
|
sl@0
|
95 |
// @param aTypeId.
|
sl@0
|
96 |
// @return CAudioCodec* a pointer to the created instance.
|
sl@0
|
97 |
///
|
sl@0
|
98 |
|
sl@0
|
99 |
IMPORT_C static CAudioCodec* NewL(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor);
|
sl@0
|
100 |
|
sl@0
|
101 |
// Check if this would be removed
|
sl@0
|
102 |
/////
|
sl@0
|
103 |
// Structure to hold hw device init parameters
|
sl@0
|
104 |
///
|
sl@0
|
105 |
class THwDeviceInitArgs
|
sl@0
|
106 |
{
|
sl@0
|
107 |
public:
|
sl@0
|
108 |
TUint8 iPolicyId;
|
sl@0
|
109 |
TInt iEapStreamId;
|
sl@0
|
110 |
};
|
sl@0
|
111 |
|
sl@0
|
112 |
/////
|
sl@0
|
113 |
// Destructor.
|
sl@0
|
114 |
//
|
sl@0
|
115 |
// Deletes all objects and releases all resource owned by this instance.
|
sl@0
|
116 |
///
|
sl@0
|
117 |
virtual ~CAudioCodec();
|
sl@0
|
118 |
|
sl@0
|
119 |
|
sl@0
|
120 |
IMPORT_C TInt SetFormat(TUid aFormat);
|
sl@0
|
121 |
IMPORT_C TInt RegisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver);
|
sl@0
|
122 |
IMPORT_C void UnregisterAudioCodecObserver(MAudioCodecAdaptationObserver& aObserver);
|
sl@0
|
123 |
IMPORT_C TInt Initialize();
|
sl@0
|
124 |
IMPORT_C TInt Load(TInt aSampleRate, TUid aMode);
|
sl@0
|
125 |
IMPORT_C TInt Start();
|
sl@0
|
126 |
IMPORT_C TInt Pause();
|
sl@0
|
127 |
IMPORT_C TInt Stop();
|
sl@0
|
128 |
|
sl@0
|
129 |
|
sl@0
|
130 |
|
sl@0
|
131 |
// From MOutputPort
|
sl@0
|
132 |
TInt GetOutputPort(MOutputPort*& aOutputPort);
|
sl@0
|
133 |
|
sl@0
|
134 |
// From MInputPort
|
sl@0
|
135 |
TInt GetInputPort(MInputPort*& aInputPort);
|
sl@0
|
136 |
|
sl@0
|
137 |
// From MCustomInterfaceSupport
|
sl@0
|
138 |
virtual TInt RequestCustomInterface(TUid aUid, TAny*& aPtr);
|
sl@0
|
139 |
virtual TInt RegisterObserver(MCustomInterfaceSupportObserver& aObserver);
|
sl@0
|
140 |
virtual void UnRegisterObserver(MCustomInterfaceSupportObserver& aObserver);
|
sl@0
|
141 |
|
sl@0
|
142 |
// from base class MInputPort
|
sl@0
|
143 |
virtual TInt EmptyBuffer(CMMFBuffer* aBuffer, MOutputPort* aSupplier);
|
sl@0
|
144 |
virtual TInt BufferFilled(CMMFBuffer* aBuffer);
|
sl@0
|
145 |
virtual TInt SetOutput(MOutputPort* aOutput);
|
sl@0
|
146 |
virtual TInt RemoveOutput(MOutputPort* aOutput);
|
sl@0
|
147 |
|
sl@0
|
148 |
// from base class MOutputPort
|
sl@0
|
149 |
virtual TInt FillBuffer(CMMFBuffer* aBuffer, MInputPort* aConsumer);
|
sl@0
|
150 |
virtual TInt BufferEmptied(CMMFBuffer* aBuffer);
|
sl@0
|
151 |
virtual TInt SetInput(MInputPort* aInput);
|
sl@0
|
152 |
virtual TInt RemoveInput(MInputPort* aInput);
|
sl@0
|
153 |
virtual TInt FlushBuffer(MFlushHandlerObserver* aFlushObserver);
|
sl@0
|
154 |
|
sl@0
|
155 |
// from base class MMMFHwDeviceObserver
|
sl@0
|
156 |
virtual TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
|
sl@0
|
157 |
virtual TInt EmptyThisHwBuffer(CMMFBuffer& aHwBuffer);
|
sl@0
|
158 |
virtual TInt MsgFromHwDevice(TUid aMessageType, const TDesC8& aMsg);
|
sl@0
|
159 |
virtual void Stopped();
|
sl@0
|
160 |
virtual void Error(TInt aError);
|
sl@0
|
161 |
|
sl@0
|
162 |
// from base class MGainHelper
|
sl@0
|
163 |
TInt GetGain(TInt& aGain) const;
|
sl@0
|
164 |
TInt SetGain(RArray<TAudioChannelGain>& aChannels);
|
sl@0
|
165 |
TInt ConfigureRamp(TUid aRampOperation, const TTimeIntervalMicroSeconds& aRampDuration);
|
sl@0
|
166 |
|
sl@0
|
167 |
// from base class MStreamPositionControl
|
sl@0
|
168 |
TInt GetControlPosition(TTimeIntervalMicroSeconds& aPosition);
|
sl@0
|
169 |
void ResetControlPosition();
|
sl@0
|
170 |
|
sl@0
|
171 |
|
sl@0
|
172 |
TInt ResolveMode(TUid aMode);
|
sl@0
|
173 |
TInt GetSupportedSampleRates(RArray<TInt>& aSupportedRates);
|
sl@0
|
174 |
TInt GetSupportedModes(RArray<TUid>& aSupportedModes);
|
sl@0
|
175 |
|
sl@0
|
176 |
//Return the supported values to the client
|
sl@0
|
177 |
IMPORT_C TInt SupportedModes(RArray<TUid>& aSupportedModes);
|
sl@0
|
178 |
IMPORT_C TInt SupportedRates(RArray<TInt>& aSupportedRates);
|
sl@0
|
179 |
|
sl@0
|
180 |
protected:
|
sl@0
|
181 |
// from CActive
|
sl@0
|
182 |
void RunL();
|
sl@0
|
183 |
void DoCancel();
|
sl@0
|
184 |
TInt RunError(TInt aError);
|
sl@0
|
185 |
|
sl@0
|
186 |
TInt LoadHwDevice();
|
sl@0
|
187 |
TInt InitHwDevice();
|
sl@0
|
188 |
TInt SetHwDeviceConfig();
|
sl@0
|
189 |
void FourCCToHwDeviceUidL(TFourCC aFourCC, TMode aMode, TUid &aHWDev);
|
sl@0
|
190 |
|
sl@0
|
191 |
TBool IsDataTypeMatch(CImplementationInformation* aHwDeviceResourceEntry,
|
sl@0
|
192 |
const TDesC8& aHwMatchFourCC, TMode aState);
|
sl@0
|
193 |
|
sl@0
|
194 |
// TODO: This will be replaced, when the new mechanism to get the supported configuration
|
sl@0
|
195 |
// will be defined
|
sl@0
|
196 |
/////
|
sl@0
|
197 |
// Reads hw device parameters from resource files.
|
sl@0
|
198 |
// @return error code.
|
sl@0
|
199 |
///
|
sl@0
|
200 |
TInt ReadResourceRates(RArray<TInt>& aRates);
|
sl@0
|
201 |
TInt ReadResourceModes(RArray<TUid>& aModes);
|
sl@0
|
202 |
|
sl@0
|
203 |
void UpdateBytesPlayed();
|
sl@0
|
204 |
|
sl@0
|
205 |
private:
|
sl@0
|
206 |
void ConstructL();
|
sl@0
|
207 |
|
sl@0
|
208 |
CAudioCodec(TUid aTypeId, const CFourCCConvertor& aFourCCConvertor);
|
sl@0
|
209 |
|
sl@0
|
210 |
private:
|
sl@0
|
211 |
TUid iType;
|
sl@0
|
212 |
// Indicates if this is an encoder or decoder
|
sl@0
|
213 |
TMode iMode;
|
sl@0
|
214 |
|
sl@0
|
215 |
// The codec format
|
sl@0
|
216 |
TUid iFormat;
|
sl@0
|
217 |
|
sl@0
|
218 |
// Resolved HwDevice Uid
|
sl@0
|
219 |
TUid iDeviceUid;
|
sl@0
|
220 |
|
sl@0
|
221 |
//
|
sl@0
|
222 |
|
sl@0
|
223 |
MPlayCustomInterface* iPlayCustomInterface;
|
sl@0
|
224 |
|
sl@0
|
225 |
MRecordCustomInterface* iRecordCustomInterface;
|
sl@0
|
226 |
|
sl@0
|
227 |
// HwDevice init parameters
|
sl@0
|
228 |
THwDeviceInitParams iHwDeviceInitParams;
|
sl@0
|
229 |
THwDeviceInitArgs iHwDeviceInitArgs;
|
sl@0
|
230 |
|
sl@0
|
231 |
// CI observers
|
sl@0
|
232 |
RPointerArray<MCustomInterfaceSupportObserver> iCISupportObservers;
|
sl@0
|
233 |
|
sl@0
|
234 |
enum THwDeviceState
|
sl@0
|
235 |
{
|
sl@0
|
236 |
EIdle,
|
sl@0
|
237 |
ERunning,
|
sl@0
|
238 |
EPaused,
|
sl@0
|
239 |
EStopped
|
sl@0
|
240 |
};
|
sl@0
|
241 |
|
sl@0
|
242 |
TBool iLastBuffer;
|
sl@0
|
243 |
THwDeviceState iHwDeviceState;
|
sl@0
|
244 |
TBool iLastBufferAck;
|
sl@0
|
245 |
TInt iRequest;
|
sl@0
|
246 |
TInt iErrorRates;
|
sl@0
|
247 |
TInt iErrorModes;
|
sl@0
|
248 |
TInt iSampleRateConfig;
|
sl@0
|
249 |
TUid iModeConfig;
|
sl@0
|
250 |
|
sl@0
|
251 |
CMMFHwDevice* iHwDevice;
|
sl@0
|
252 |
CMMFDataBuffer* iAdaptationBuffer;
|
sl@0
|
253 |
|
sl@0
|
254 |
MOutputPort* iOutputPort;
|
sl@0
|
255 |
MInputPort* iInputPort;
|
sl@0
|
256 |
TInt64 iPosition;
|
sl@0
|
257 |
TInt64 iPlayedBytesCount;
|
sl@0
|
258 |
|
sl@0
|
259 |
CFourCCConvertor* iFourCCConvertor;
|
sl@0
|
260 |
RPointerArray<MAudioCodecAdaptationObserver> iAudioCodecObservers;
|
sl@0
|
261 |
MIgnoreUnderflowEventsCustomInterface* iIgnoreUnderflowInterface;
|
sl@0
|
262 |
TUid iRampOperation;
|
sl@0
|
263 |
TTimeIntervalMicroSeconds iRampDuration;
|
sl@0
|
264 |
};
|
sl@0
|
265 |
|
sl@0
|
266 |
/*
|
sl@0
|
267 |
* Updates the total bytes played.
|
sl@0
|
268 |
*
|
sl@0
|
269 |
*/
|
sl@0
|
270 |
inline void CAudioCodec::UpdateBytesPlayed()
|
sl@0
|
271 |
{
|
sl@0
|
272 |
if (iPlayCustomInterface)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
iPlayedBytesCount = iPlayCustomInterface->BytesPlayed();
|
sl@0
|
275 |
}
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
#endif // AUDIOCODEC_H
|