|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The functions in this module implements the specific behavior |
|
15 * for the play controller decoder class for configuration of |
|
16 * hardware accelerated codec. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "AACAudioPlayControllerDecoder.h" |
|
23 #include "DebugMacros.h" |
|
24 #include <Mmfcodec.h> |
|
25 |
|
26 #include <MmfPanicCodes.h> |
|
27 |
|
28 // New eAAC+ custom interface is used only when using DSP decoder and |
|
29 // the eAAC+ feature is turned on. |
|
30 #ifdef __AAC_PLUS_DECODER_PLUGIN |
|
31 #include <EAacPlusDecoderIntfc.h> |
|
32 #else |
|
33 #include <AacDecoderConfig.h> |
|
34 #include <AudioConfig.h> |
|
35 #endif |
|
36 |
|
37 #include <EAacPlusDecoderIntfc.h> |
|
38 //#include "EAacPlusFrameParser.h" |
|
39 |
|
40 // CONSTANT |
|
41 const TUint KMaxAacFrameSize = 1536; |
|
42 const TUint KSizeOfInBuffer = 2*KMaxAacFrameSize; |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // C++ default constructor can NOT contain any code, that |
|
48 // might leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CAACAudioPlayControllerDecoder::CAACAudioPlayControllerDecoder() |
|
52 : CAdvancedAudioDecoder(CActive::EPriorityStandard) |
|
53 { |
|
54 DP0(_L("CAACAudioPlayControllerDecoder::CAACAudioPlayControllerDecoder - Hardware Accelerated")); |
|
55 iMaxFrameSize = KMaxAacFrameSize; |
|
56 iSizeOfInBuffer = KSizeOfInBuffer; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CAACAudioPlayControllerDecoder::ConstructL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CAACAudioPlayControllerDecoder::ConstructL() |
|
65 { |
|
66 DP0(_L("CAACAudioPlayControllerDecoder::ConstructL")); |
|
67 |
|
68 iAacUtil = CEAacPlusUtil::NewL(); |
|
69 iFrameTable = CFrameTable::NewL(); |
|
70 |
|
71 RenderEnable(); |
|
72 UnMarkPlayEnd(); |
|
73 Enable(); |
|
74 |
|
75 CActiveScheduler::Add(this); |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // C++ default constructor can NOT contain any code, that |
|
80 // might leave. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CAACAudioPlayControllerDecoder* CAACAudioPlayControllerDecoder::NewL() |
|
84 { |
|
85 DP0(_L("CAACAudioPlayControllerDecoder::NewL()")); |
|
86 |
|
87 CAACAudioPlayControllerDecoder* self = new(ELeave) CAACAudioPlayControllerDecoder(); |
|
88 CleanupStack::PushL(self); |
|
89 self->ConstructL(); |
|
90 CleanupStack::Pop(self); |
|
91 return self; |
|
92 } |
|
93 |
|
94 // Destructor |
|
95 CAACAudioPlayControllerDecoder::~CAACAudioPlayControllerDecoder() |
|
96 { |
|
97 DP0(_L("CAACAudioPlayControllerDecoder::~CAACAudioPlayControllerDecoder")); |
|
98 |
|
99 delete iAacUtil; |
|
100 delete iFrameTable; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CAACAudioPlayControllerDecoder::SetConfigL |
|
105 // Sets configuration data and configures the codec. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TInt CAACAudioPlayControllerDecoder::CodecConfig(RArray<TInt>& aCodecConfigData) |
|
109 { |
|
110 DP0(_L("CAACAudioPlayControllerDecoder::SetConfigL")); |
|
111 |
|
112 TInt status = KErrNone; |
|
113 |
|
114 aCodecConfigData[11] = reinterpret_cast<TInt>(iFrameTable); |
|
115 iFormatType = (CEAacPlusUtil::TEAacPlusFormatType)(aCodecConfigData[12]); |
|
116 |
|
117 if (!iMMFDevSound) |
|
118 { |
|
119 _LIT(KAudioPlayControllerDecoderPanicCategory, "AACAudioPlayControllerDecoder"); |
|
120 User::Panic(KAudioPlayControllerDecoderPanicCategory, EMMFAudioOutputDevSoundNotLoaded); |
|
121 } |
|
122 |
|
123 #ifdef __AAC_PLUS_DECODER_PLUGIN |
|
124 //uses new eAAC+ interface |
|
125 |
|
126 DP0(_L("CAACAudioPlayControllerDecoder::SetConfigL eAAC+ intfc")); |
|
127 CEAacPlusDecoderIntfc::TAudioObjectType objType(CEAacPlusDecoderIntfc::ENull); |
|
128 TInt count = aCodecConfigData.Count(); |
|
129 ASSERT(count > 2); |
|
130 |
|
131 DP1(_L("CAACAudioPlayControllerDecoder::SetConfigL, aCodecConfigData[2] = %d"), aCodecConfigData[2]); |
|
132 |
|
133 switch (aCodecConfigData[2]) |
|
134 { |
|
135 case 1: |
|
136 objType = CEAacPlusDecoderIntfc::EAacLc; |
|
137 break; |
|
138 case 3: |
|
139 objType = CEAacPlusDecoderIntfc::EAacLtp; |
|
140 break; |
|
141 default: |
|
142 return status = KErrNotSupported; |
|
143 } |
|
144 |
|
145 CEAacPlusDecoderIntfc* aacPlusDecCustomInterface(NULL); |
|
146 TRAP_IGNORE(aacPlusDecCustomInterface = CEAacPlusDecoderIntfc::NewL(*iMMFDevSound)); |
|
147 if (!aacPlusDecCustomInterface) |
|
148 { |
|
149 DP0(_L("CAACAudioPlayControllerDecoder::SetConfigL eAAC+ intfc not supported")); |
|
150 return KErrNotSupported; |
|
151 } |
|
152 |
|
153 aacPlusDecCustomInterface->SetAudioObjectType(objType); |
|
154 aacPlusDecCustomInterface->SetInputSamplingFrequency(aCodecConfigData[5]); |
|
155 aacPlusDecCustomInterface->SetNumOfChannels(aCodecConfigData[1]); |
|
156 aacPlusDecCustomInterface->SetSbr(EFalse); |
|
157 aacPlusDecCustomInterface->SetDownSampledMode(EFalse); |
|
158 |
|
159 if (objType == CEAacPlusDecoderIntfc::EAacLc) |
|
160 { |
|
161 if ((aCodecConfigData[10] == 5) || //AAC + SBR |
|
162 (aCodecConfigData[10] == 6)) //AAC + SBR + PS |
|
163 { |
|
164 aacPlusDecCustomInterface->SetSbr(ETrue); |
|
165 } |
|
166 |
|
167 if ((aCodecConfigData[7] == 1) && //DSM |
|
168 ((aCodecConfigData[10] == 5) || //AAC + SBR |
|
169 (aCodecConfigData[10] == 6))) //AAC + SBR + PS |
|
170 { |
|
171 aacPlusDecCustomInterface->SetDownSampledMode(ETrue); |
|
172 } |
|
173 } |
|
174 |
|
175 status = aacPlusDecCustomInterface->ApplyConfig(); |
|
176 delete aacPlusDecCustomInterface; |
|
177 DP1(_L("CAACAudioPlayControllerDecoder::SetConfigL, ApplyConfig status = %d"), status); |
|
178 |
|
179 #else // __AAC_PLUS_DECODER_PLUGIN |
|
180 //uses old AAC interface |
|
181 |
|
182 DP0(_L("CAACAudioPlayControllerDecoder::SetConfigL AAC intfc")); |
|
183 TAudioConfig aacAudioConfig; // AAC Configuration structure |
|
184 |
|
185 // Profile Data is comming from AAC Codec |
|
186 // For That Codec... AAC Profile object type is Main=0; LC=1, SSR=2; LTP=3 (Based on Old AAC Codec) |
|
187 // Custom Interface Profile ENUMS are based on MPEG4 Audio Object Types which is |
|
188 // ENull=0;EAacMain=1;EAacLc=2;EAacSsr=3;EAacLtp=4;ESbr=5.. So the Codec Audio Object Type is |
|
189 // one off from MPEG4 Object Type. |
|
190 |
|
191 ASSERT(aCodecConfigData.Count() > 2); |
|
192 |
|
193 DP1(_L("CAACAudioPlayControllerDecoder::SetConfigL, aCodecConfigData[2] = %d"), aCodecConfigData[2]); |
|
194 |
|
195 switch (aCodecConfigData[2]) // So Map Old Object Type to the New MPEG4 Object Type |
|
196 { |
|
197 case 0: // Old Codec Object Type 0 (Main) |
|
198 aacAudioConfig.iAudioObjectType = TAudioConfig::EAacMain; |
|
199 break; |
|
200 case 1:// Old Codec Object Type 1 (LC) |
|
201 aacAudioConfig.iAudioObjectType = TAudioConfig::EAacLc; |
|
202 break; |
|
203 case 2:// Old Codec Object Type 2 (SSR) |
|
204 aacAudioConfig.iAudioObjectType = TAudioConfig::EAacSsr; |
|
205 break; |
|
206 case 3:// Old Codec Object Type 3 (LTP) |
|
207 aacAudioConfig.iAudioObjectType = TAudioConfig::EAacLtp; |
|
208 break; |
|
209 case 4: |
|
210 aacAudioConfig.iAudioObjectType = TAudioConfig::ESbr; |
|
211 break; |
|
212 default: |
|
213 return status = KErrNotSupported; |
|
214 } |
|
215 |
|
216 CAacDecoderConfig* aacDecCustomInterface(NULL);// Creates a custom interface |
|
217 |
|
218 //Calls the custom on devsound Devsound will return the handle to the custom interface proxy |
|
219 TRAP(status, aacDecCustomInterface = CAacDecoderConfig::NewL(*iMMFDevSound)); |
|
220 if (status != KErrNone) |
|
221 { |
|
222 return status; |
|
223 } |
|
224 status = aacDecCustomInterface->SetAudioConfig(aacAudioConfig); |
|
225 delete aacDecCustomInterface; // We have the handle so we Delete the Custom Interface and Adptation should Not delete this |
|
226 |
|
227 DP1(_L("CAACAudioPlayControllerDecoder::SetConfigL SetAudioConfig, status = %d"), status); |
|
228 |
|
229 #endif //__AAC_PLUS_DECODER_PLUGIN |
|
230 |
|
231 if (status != KErrNone) |
|
232 { |
|
233 return status; |
|
234 } |
|
235 |
|
236 // pass FrameTable Handle to CMMFCodec so that it can build the table |
|
237 aCodecConfigData[11] = reinterpret_cast<TInt>(iFrameTable); |
|
238 |
|
239 |
|
240 CEAacPlusUtil::TEAacPlusFormatType formatType = static_cast<CEAacPlusUtil::TEAacPlusFormatType>(aCodecConfigData[12]); |
|
241 TInt inSampFreq = aCodecConfigData[5]; |
|
242 TInt outSampFreq = aCodecConfigData[9]; |
|
243 TInt numSampPerFrame = aCodecConfigData[4]; |
|
244 |
|
245 // CEAacPlusUtil::TEAacPlusFrameLenConfig iFrameLenConfig; |
|
246 iFrameLenConfig.iFormatType = formatType; |
|
247 iFrameLenConfig.iSamplingFrequency = inSampFreq; |
|
248 iFrameLenConfig.iObjectType = objType; |
|
249 iAacUtil->Config(iFrameLenConfig); |
|
250 if(inSampFreq!=outSampFreq) |
|
251 { |
|
252 numSampPerFrame =2*numSampPerFrame; |
|
253 } |
|
254 |
|
255 // TInt sampFreq = ((RArray<TInt>&) aConfigData)[5]; |
|
256 // TInt samplesPerFrame = ((RArray<TInt>&) aConfigData)[8]; |
|
257 // iFrameTable->InitFrameTable(sampFreq, samplesPerFrame); |
|
258 iFrameTable->InitFrameTable(outSampFreq, numSampPerFrame); |
|
259 |
|
260 return status; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CAACAudioPlayControllerDecoder::IsHwAccelerated |
|
265 // Always return true when no soft codec is used. |
|
266 // ----------------------------------------------------------------------------- |
|
267 // |
|
268 TBool CAACAudioPlayControllerDecoder::IsHwAccelerated() |
|
269 { |
|
270 DP0(_L ("CAACAudioPlayControllerDecoder::IsHwAccelerated true")); |
|
271 return ETrue; |
|
272 } |
|
273 |
|
274 void CAACAudioPlayControllerDecoder::ResetL() |
|
275 { |
|
276 DP0(_L ("CAACAudioPlayControllerDecoder::Reset - Enter")); |
|
277 |
|
278 delete[] iOutBuffer; |
|
279 delete[] iInBuffer; |
|
280 |
|
281 iInBuffer = NULL; |
|
282 iOutBuffer = NULL; |
|
283 iInBufferCount = 0; |
|
284 iOutBufferCount = 0; |
|
285 iOutBufferPtr = NULL; |
|
286 iOutFrameLength = KMaxAacFrameSize; // since data is not decoded |
|
287 iInBuffer = new (ELeave) TUint8[KSizeOfInBuffer]; |
|
288 |
|
289 iOutBuffer = new (ELeave) TUint8[iOutFrameLength]; |
|
290 iOutBufferPtr = iOutBuffer; |
|
291 |
|
292 iAccLen = 0; |
|
293 |
|
294 iAacUtil->Config(iFrameLenConfig); |
|
295 iEnabled = ETrue; |
|
296 DP0(_L ("CAACAudioPlayControllerDecoder::Reset - Exit")); |
|
297 } |
|
298 |
|
299 TCodecProcessResult CAACAudioPlayControllerDecoder::ProcessL(CMMFBuffer& aSrc, CMMFBuffer& aDst) |
|
300 { |
|
301 DP0(_L ("CAACAudioPlayControllerDecoder::ProcessL")); |
|
302 return CAdvancedAudioDecoder::ProcessHwL(aSrc, aDst); |
|
303 } |
|
304 |
|
305 TInt CAACAudioPlayControllerDecoder::FrameLength(const TUint8* aBuf, TInt aBufLen, TInt& aFrameLength) |
|
306 { |
|
307 TInt stat; |
|
308 TInt frameLen; |
|
309 stat = iAacUtil->GetAacFrameLength(aBuf, aBufLen, frameLen); |
|
310 aFrameLength = frameLen; |
|
311 return stat; |
|
312 } |
|
313 |
|
314 // ----------------------------------------------------------------------------- |
|
315 // CAACAudioPlayControllerDecoder::SeekSync |
|
316 // ----------------------------------------------------------------------------- |
|
317 TInt CAACAudioPlayControllerDecoder::SeekSync(TUint8* aBuf, TInt aBufLen) |
|
318 { // should return aBufLen if not found |
|
319 DP0(_L("CAACAudioPlayControllerDecoder::SeekSync")); |
|
320 TInt syncPos = aBufLen; |
|
321 if (iFormatType == 2) // ADTS=2 |
|
322 { |
|
323 syncPos = SeekAdtsSync(aBuf, aBufLen); |
|
324 } |
|
325 return syncPos; |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CAACAudioPlayControllerDecoder::SeekAdtsSync |
|
330 // ----------------------------------------------------------------------------- |
|
331 TInt CAACAudioPlayControllerDecoder::SeekAdtsSync(TUint8* aBuf, TInt aBufLen) |
|
332 { // should return aBufLen if not found |
|
333 DP0(_L("CMMFeAacPlusTo16PcmCodec::SeekSync")); |
|
334 const TInt KNotFound = aBufLen; // sync not found position |
|
335 TInt syncPos = KNotFound; |
|
336 TInt seekLen = 0; |
|
337 |
|
338 while (seekLen < aBufLen) |
|
339 { |
|
340 if (IsValidAdtsFrame(aBuf+seekLen, aBufLen-seekLen)) |
|
341 { |
|
342 syncPos = seekLen; |
|
343 break; |
|
344 } |
|
345 seekLen++; |
|
346 } |
|
347 return syncPos; |
|
348 } |
|
349 |
|
350 TBool CAACAudioPlayControllerDecoder::IsValidAdtsFrame(const TUint8* aPtr, TInt aBufLen) |
|
351 { |
|
352 DP0(_L("CAACAudioPlayControllerDecoder::IsValidAdtsFrame")); |
|
353 if (aBufLen < 6) |
|
354 { |
|
355 return EFalse; |
|
356 } |
|
357 |
|
358 if (((aPtr[0] == 0xFF) && ((aPtr[1] >> 4) == 0xF) && // Check syncword FFF |
|
359 ((aPtr[1] >> 1) & 0x3) == 0)) // Check layer == 0 |
|
360 { |
|
361 TInt frameLen = 0; |
|
362 frameLen = (aPtr[3] & 0x3) << 11; |
|
363 frameLen |= aPtr[4] << 3; |
|
364 frameLen |= ((aPtr[5] >> 5) & 0x7); |
|
365 |
|
366 if (!frameLen || (frameLen > (aBufLen-4))) |
|
367 return EFalse; |
|
368 |
|
369 // Check next frame |
|
370 if (aBufLen - frameLen >= 2) |
|
371 { |
|
372 const TUint8* nextFramePtr = aPtr + frameLen; |
|
373 if ((((nextFramePtr[0] == 0xFF) && ((nextFramePtr[1] >> 4) == 0xF)) && // Check syncword FFF |
|
374 ((nextFramePtr[1] >> 1) & 0x3) == 0)) // Check layer == 0 |
|
375 return ETrue; |
|
376 } |
|
377 } |
|
378 return EFalse; |
|
379 } |
|
380 |
|
381 |
|
382 TInt CAACAudioPlayControllerDecoder::CodecCmd(TCodecCmd /*aCmd*/) |
|
383 { |
|
384 return KErrNotSupported; |
|
385 } |
|
386 |
|
387 // End of file |