1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <f32file.h> |
|
23 #include "AudCommon.h" |
|
24 #include "ProcConstants.h" |
|
25 #include "AWBConstants.h" |
|
26 #include "ProcMP4InFileHandler.h" |
|
27 #include "mp4aud.h" |
|
28 #include "ProcAACFrameHandler.h" |
|
29 #include "ProcAMRFrameHandler.h" |
|
30 #include "ProcAWBFrameHandler.h" |
|
31 #include "audconstants.h" |
|
32 |
|
33 |
|
34 |
|
35 #include "ProcTools.h" |
|
36 //#include "aacenc_interface.h" |
|
37 |
|
38 // Debug print macro |
|
39 #if defined _DEBUG |
|
40 #include <e32svr.h> |
|
41 #define PRINT(x) RDebug::Print x; |
|
42 #else |
|
43 #define PRINT(x) |
|
44 #endif |
|
45 |
|
46 // Max coded AAC frame size (768 bytes per channel) |
|
47 const TUint KMaxAACFrameSize(1536); |
|
48 |
|
49 |
|
50 CProcMP4InFileHandler* CProcMP4InFileHandler::NewL(const TDesC& aFileName, |
|
51 RFile* aFileHandle, |
|
52 CAudClip* aClip, TInt aReadBufferSize, |
|
53 TInt aTargetSampleRate, |
|
54 TChannelMode aChannelMode) |
|
55 { |
|
56 |
|
57 CProcMP4InFileHandler* self = NewLC(aFileName, aFileHandle, aClip, aReadBufferSize, |
|
58 aTargetSampleRate, aChannelMode); |
|
59 CleanupStack::Pop(self); |
|
60 return self; |
|
61 |
|
62 } |
|
63 |
|
64 CProcMP4InFileHandler* CProcMP4InFileHandler::NewLC(const TDesC& aFileName, |
|
65 RFile* aFileHandle, |
|
66 CAudClip* aClip, TInt aReadBufferSize, |
|
67 TInt aTargetSampleRate, |
|
68 TChannelMode aChannelMode) |
|
69 |
|
70 { |
|
71 |
|
72 CProcMP4InFileHandler* self = new (ELeave) CProcMP4InFileHandler(); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(aFileName, aFileHandle, aClip, aReadBufferSize, |
|
75 aTargetSampleRate, aChannelMode); |
|
76 return self; |
|
77 |
|
78 } |
|
79 |
|
80 void CProcMP4InFileHandler::GetPropertiesL(TAudFileProperties* aProperties) |
|
81 { |
|
82 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL in") )); |
|
83 if (iProperties != 0) |
|
84 { |
|
85 *aProperties = *iProperties; |
|
86 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL use cached properties, out") )); |
|
87 return; |
|
88 } |
|
89 |
|
90 if (iProperties == 0) |
|
91 { |
|
92 iProperties = new (ELeave) TAudFileProperties; |
|
93 } |
|
94 |
|
95 mp4_u32 audiolength = 0; |
|
96 mp4_u32 audiotype = 0; |
|
97 mp4_u8 framespersample = 0; |
|
98 mp4_u32 timescale = 0; |
|
99 mp4_u32 averagebitrate = 0; |
|
100 |
|
101 aProperties->iFileFormat = EAudFormatUnrecognized; |
|
102 aProperties->iAudioType = EAudTypeUnrecognized; |
|
103 aProperties->iDuration = 0; |
|
104 aProperties->iSamplingRate = 0; |
|
105 aProperties->iBitrate = 0; |
|
106 aProperties->iChannelMode = EAudChannelModeNotRecognized; |
|
107 aProperties->iBitrateMode = EAudBitrateModeNotRecognized; |
|
108 aProperties->iAudioTypeExtension = EAudExtensionTypeNoExtension; |
|
109 aProperties->iFrameLen = 0; |
|
110 aProperties->iFrameDuration = 0; |
|
111 aProperties->iFrameCount = 0; |
|
112 aProperties->iNumFramesPerSample = 1; |
|
113 aProperties->iAACObjectType = EAudAACObjectTypeNone; |
|
114 |
|
115 MP4Err err = MP4ParseRequestAudioDescription(iParser, |
|
116 &audiolength, |
|
117 &audiotype, |
|
118 &framespersample, |
|
119 ×cale, |
|
120 &averagebitrate); |
|
121 |
|
122 |
|
123 if (err == MP4_OK) |
|
124 { |
|
125 if (audiotype == MP4_TYPE_MPEG4_AUDIO) |
|
126 { |
|
127 |
|
128 aProperties->iAudioType = EAudAAC_MPEG4; |
|
129 aProperties->iBitrateMode = EAudVariable; |
|
130 |
|
131 } |
|
132 else if (audiotype == MP4_TYPE_AMR_NB) |
|
133 { |
|
134 aProperties->iAudioType = EAudAMR; |
|
135 aProperties->iBitrateMode = EAudVariable; |
|
136 |
|
137 } |
|
138 else if (audiotype == MP4_TYPE_AMR_WB) |
|
139 { |
|
140 aProperties->iAudioType = EAudAMRWB; |
|
141 aProperties->iBitrateMode = EAudVariable; |
|
142 |
|
143 } |
|
144 aProperties->iBitrate = averagebitrate; |
|
145 |
|
146 // casting for PC-Lint |
|
147 TInt64 ti = (TInt64)(TInt)(audiolength*1000); |
|
148 TTimeIntervalMicroSeconds TTaudiolength(ti); |
|
149 |
|
150 aProperties->iDuration = TTaudiolength; |
|
151 aProperties->iFileFormat = EAudFormatMP4; |
|
152 //aProperties->iFrameLen = framespersample; |
|
153 |
|
154 |
|
155 } |
|
156 else if (err == MP4_NO_AUDIO) |
|
157 { |
|
158 aProperties->iAudioType = EAudNoAudio; |
|
159 *iProperties = *aProperties; |
|
160 return; |
|
161 |
|
162 //User::Leave(KErrGeneral); |
|
163 } |
|
164 else |
|
165 { |
|
166 // a special case: there may be audio track but it is empty; if type was recognized, mark as no audio |
|
167 if ( (audiotype == MP4_TYPE_MPEG4_AUDIO) || (audiotype == MP4_TYPE_AMR_NB) || (audiotype == MP4_TYPE_AMR_WB)) |
|
168 { |
|
169 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL problems with getting audio description, mark no audio since audio type was recognized"))); |
|
170 aProperties->iAudioType = EAudNoAudio; |
|
171 *iProperties = *aProperties; |
|
172 } |
|
173 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL out with MP4Err %d"), err )); |
|
174 return; |
|
175 |
|
176 } |
|
177 |
|
178 const TInt KMaxBufferSize = 128; |
|
179 |
|
180 mp4_u8 *buffer = new (ELeave) mp4_u8[KMaxBufferSize]; |
|
181 CleanupStack::PushL(buffer); |
|
182 |
|
183 mp4_u32 decspecinfosize = 0; |
|
184 |
|
185 err = MP4ParseReadAudioDecoderSpecificInfo( |
|
186 iParser, |
|
187 buffer, |
|
188 KMaxBufferSize, |
|
189 &decspecinfosize); |
|
190 |
|
191 |
|
192 mp4AACTransportHandle mp4AAC_ff; |
|
193 |
|
194 if (err == MP4_OK && aProperties->iAudioType == EAudAAC_MPEG4) |
|
195 { |
|
196 |
|
197 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL AAC found") )); |
|
198 |
|
199 TInt ret = ReadMP4AudioConfig(buffer, |
|
200 decspecinfosize, |
|
201 &mp4AAC_ff); |
|
202 if (ret != TRUE) |
|
203 { |
|
204 aProperties->iFileFormat = EAudFormatUnrecognized; |
|
205 aProperties->iAudioType = EAudTypeUnrecognized; |
|
206 User::Leave(KErrNotSupported); |
|
207 } |
|
208 |
|
209 // ProgConfig progCfg = mp4AAC_ff.progCfg; |
|
210 AudioSpecificInfo audioInfo = mp4AAC_ff.audioInfo; |
|
211 aProperties->iSamplingRate = audioInfo.samplingFrequency; |
|
212 // TInt tmp = mp4AAC_ff.progCfg.coupling.num_ele; |
|
213 |
|
214 // Check that the sample rate is supported |
|
215 if( (aProperties->iSamplingRate != KAedSampleRate8kHz) && |
|
216 (aProperties->iSamplingRate != KAedSampleRate11kHz) && |
|
217 (aProperties->iSamplingRate != KAedSampleRate16kHz) && |
|
218 (aProperties->iSamplingRate != KAedSampleRate22kHz) && |
|
219 (aProperties->iSamplingRate != KAedSampleRate24kHz) && |
|
220 (aProperties->iSamplingRate != KAedSampleRate32kHz) && |
|
221 (aProperties->iSamplingRate != KAedSampleRate44kHz) && |
|
222 (aProperties->iSamplingRate != KAedSampleRate48kHz) ) |
|
223 { |
|
224 User::Leave(KErrNotSupported); |
|
225 } |
|
226 |
|
227 if (audioInfo.channelConfiguration == 2) |
|
228 { |
|
229 aProperties->iChannelMode = EAudStereo; |
|
230 } |
|
231 else if (audioInfo.channelConfiguration == 1) |
|
232 { |
|
233 |
|
234 aProperties->iChannelMode = EAudSingleChannel; |
|
235 } |
|
236 else |
|
237 { |
|
238 aProperties->iChannelMode = EAudChannelModeNotRecognized; |
|
239 } |
|
240 |
|
241 if (mp4AAC_ff.audioInfo.samplingFreqIdx != |
|
242 mp4AAC_ff.progCfg.sample_rate_idx) |
|
243 { |
|
244 aProperties->iFileFormat = EAudFormatUnrecognized; |
|
245 aProperties->iAudioType = EAudTypeUnrecognized; |
|
246 aProperties->iDuration = 0; |
|
247 aProperties->iSamplingRate = 0; |
|
248 aProperties->iBitrate = 0; |
|
249 aProperties->iChannelMode = EAudChannelModeNotRecognized; |
|
250 aProperties->iBitrateMode = EAudBitrateModeNotRecognized; |
|
251 aProperties->iFrameLen = 0; |
|
252 aProperties->iFrameDuration = 0; |
|
253 aProperties->iFrameCount = 0; |
|
254 aProperties->iNumFramesPerSample = 1; |
|
255 CleanupStack::PopAndDestroy(buffer); |
|
256 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL audio not recognized, out") )); |
|
257 User::Leave(KErrNotSupported); |
|
258 return; |
|
259 } |
|
260 |
|
261 |
|
262 |
|
263 iFrameInfo->iSampleRateID = static_cast<TUint8>(mp4AAC_ff.progCfg.sample_rate_idx); |
|
264 iFrameInfo->iSampleRateID = static_cast<TUint8>(mp4AAC_ff.audioInfo.samplingFreqIdx); |
|
265 |
|
266 |
|
267 iFrameInfo->iProfileID = static_cast<TUint8>(mp4AAC_ff.progCfg.profile); |
|
268 |
|
269 aProperties->iAACObjectType = TAudAACObjectType(iFrameInfo->iProfileID); |
|
270 |
|
271 if (aProperties->iChannelMode == EAudStereo) |
|
272 { |
|
273 iFrameInfo->iNumChannels = 2; |
|
274 } |
|
275 else if (aProperties->iChannelMode == EAudSingleChannel) |
|
276 { |
|
277 iFrameInfo->iNumChannels = 1; |
|
278 } |
|
279 else |
|
280 { |
|
281 iFrameInfo->iNumChannels = 0; |
|
282 } |
|
283 |
|
284 |
|
285 iFrameInfo->iIs960 = mp4AAC_ff.audioInfo.gaInfo.FrameLengthFlag; |
|
286 |
|
287 iFrameInfo->iNumCouplingChannels = 0; |
|
288 |
|
289 iFrameInfo->isSBR = 0; |
|
290 iFrameInfo->iIsParametricStereo = 0; |
|
291 |
|
292 /* |
|
293 * Get frame parameters for eAAC+ codec. It is possible that the bitstream |
|
294 * is plain AAC but we don't know it before the 1st frame is parsed! |
|
295 */ |
|
296 |
|
297 HBufC8* frame = 0; |
|
298 TInt size = 0; |
|
299 |
|
300 TInt32 time = 0; |
|
301 |
|
302 // Set the iProperties as GetEncAudioFrameL is using it!! |
|
303 *iProperties = *aProperties; |
|
304 if(GetEncAudioFrameL(frame, size, time)) |
|
305 { |
|
306 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL check AAC+ parameters") )); |
|
307 |
|
308 TUint8* buf = const_cast<TUint8*>(frame->Right(frame->Size()).Ptr()); |
|
309 CProcAACFrameHandler::GetEnhancedAACPlusParametersL(buf, frame->Size(), aProperties, iFrameInfo); |
|
310 delete frame; |
|
311 frame = 0; |
|
312 } |
|
313 |
|
314 } |
|
315 else if (err == MP4_OK && aProperties->iAudioType == EAudAMR) |
|
316 { |
|
317 aProperties->iChannelMode = EAudSingleChannel; |
|
318 aProperties->iSamplingRate = 8000; |
|
319 |
|
320 } |
|
321 else if (err == MP4_OK && aProperties->iAudioType == EAudAMRWB) |
|
322 { |
|
323 aProperties->iChannelMode = EAudSingleChannel; |
|
324 aProperties->iSamplingRate = 16000; |
|
325 |
|
326 } |
|
327 |
|
328 TInt frameAmount = 0; |
|
329 TInt frameSize = 0; |
|
330 TInt frameDuration = 0; |
|
331 |
|
332 |
|
333 TInt rv = ETrue; |
|
334 |
|
335 *iProperties = *aProperties; |
|
336 rv = GetAudioFrameInfoL(frameAmount, frameDuration, frameSize, aProperties); |
|
337 |
|
338 if (rv) |
|
339 { |
|
340 aProperties->iFrameCount = frameAmount; |
|
341 aProperties->iFrameLen = frameSize; |
|
342 |
|
343 // casting for PC-Lint |
|
344 TInt64 durMicro = (TInt64) (TInt) frameDuration*1000; |
|
345 aProperties->iFrameDuration = durMicro; |
|
346 |
|
347 } |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 *iProperties = *aProperties; |
|
354 |
|
355 |
|
356 CleanupStack::PopAndDestroy(buffer); |
|
357 |
|
358 PRINT((_L("CProcMP4InFileHandler::GetPropertiesL out") )); |
|
359 } |
|
360 |
|
361 |
|
362 TBool CProcMP4InFileHandler::SeekAudioFrame(TInt32 aTime) |
|
363 { |
|
364 |
|
365 mp4_u32 position = static_cast<TUint32>(aTime); |
|
366 mp4_u32 audioPosition = 0; |
|
367 |
|
368 mp4_u32 videoPosition = 0; |
|
369 mp4_bool keyframe = EFalse; |
|
370 |
|
371 if (iMP4ReadBuffer != 0) |
|
372 { |
|
373 delete[] iMP4ReadBuffer; |
|
374 iMP4ReadBuffer = 0; |
|
375 iMP4ReadBufferPos = 0; |
|
376 iMP4ReadBufferSize = 0; |
|
377 } |
|
378 |
|
379 MP4Err err = MP4ParseSeek(iParser, |
|
380 position, |
|
381 &audioPosition, |
|
382 &videoPosition, |
|
383 keyframe); |
|
384 |
|
385 if (err == MP4_OK) |
|
386 { |
|
387 |
|
388 iCurrentTimeMilliseconds = audioPosition; |
|
389 iLastTimeStamp = audioPosition - I64INT(iProperties->iFrameDuration.Int64()/1000); |
|
390 aTime = audioPosition; |
|
391 return ETrue; |
|
392 } |
|
393 else |
|
394 { |
|
395 return EFalse; |
|
396 } |
|
397 } |
|
398 |
|
399 TBool CProcMP4InFileHandler::SeekCutInFrame() |
|
400 { |
|
401 |
|
402 iCurrentTimeMilliseconds = iCutInTime; |
|
403 return SeekAudioFrame(iCutInTime); |
|
404 } |
|
405 |
|
406 |
|
407 |
|
408 TBool CProcMP4InFileHandler::SetNormalizingGainL(const CProcFrameHandler* aFrameHandler) |
|
409 { |
|
410 |
|
411 |
|
412 if (iProperties->iAudioType == EAudAAC_MPEG4) |
|
413 { |
|
414 |
|
415 HBufC8* point = 0; |
|
416 TInt siz; |
|
417 TInt32 tim = 0; |
|
418 TInt maxGain = 0; |
|
419 RArray<TInt> gains; |
|
420 TInt maxAverage = 0; |
|
421 TInt tmpGain = 0; |
|
422 TInt gainCounter = 0; |
|
423 TInt timeNow = 0; |
|
424 while(GetEncAudioFrameL(point, siz, tim)) |
|
425 { |
|
426 |
|
427 aFrameHandler->GetGainL(point, gains, maxGain); |
|
428 timeNow += tim; |
|
429 |
|
430 for (TInt a = 0 ; a < gains.Count() ; a++) |
|
431 { |
|
432 tmpGain += gains[a]; |
|
433 gainCounter++; |
|
434 } |
|
435 gains.Reset(); |
|
436 |
|
437 if (timeNow > 1000) |
|
438 { |
|
439 if (tmpGain/gainCounter > maxAverage) |
|
440 { |
|
441 maxAverage = tmpGain/gainCounter; |
|
442 } |
|
443 |
|
444 timeNow = 0; |
|
445 tmpGain = 0; |
|
446 gainCounter = 0; |
|
447 } |
|
448 |
|
449 delete point; |
|
450 |
|
451 } |
|
452 |
|
453 // bigger value makes normalizing more efficient, but makes |
|
454 // dynamic compression more likely to occur |
|
455 TInt NormalizingFactor = 175; |
|
456 if (iProperties->iBitrate > 20000 && iProperties->iBitrate < 40000) |
|
457 { |
|
458 |
|
459 // 32 kBit/s |
|
460 NormalizingFactor = 170; |
|
461 |
|
462 } |
|
463 else if (iProperties->iBitrate > 80000 && iProperties->iBitrate < 110000) |
|
464 { |
|
465 // 96 kBit/s |
|
466 NormalizingFactor = 170; |
|
467 |
|
468 } |
|
469 |
|
470 |
|
471 else if (iProperties->iBitrate > 110000 && iProperties->iBitrate < 140000) |
|
472 { |
|
473 // 128 kBit/s |
|
474 if (iProperties->iChannelMode == EAudSingleChannel) |
|
475 NormalizingFactor = 160; |
|
476 else |
|
477 NormalizingFactor = 170; |
|
478 |
|
479 } |
|
480 else if (iProperties->iBitrate > 150000) |
|
481 { |
|
482 // 256 kBit/s |
|
483 if (iProperties->iChannelMode == EAudSingleChannel) |
|
484 NormalizingFactor = 150; |
|
485 else |
|
486 NormalizingFactor = 165; |
|
487 |
|
488 } |
|
489 else |
|
490 { |
|
491 |
|
492 if (iProperties->iChannelMode == EAudSingleChannel) |
|
493 NormalizingFactor = 170; |
|
494 |
|
495 } |
|
496 |
|
497 |
|
498 TInt gainBoost = (NormalizingFactor-maxAverage)*3; |
|
499 |
|
500 if (gainBoost < 0) gainBoost = 0; |
|
501 |
|
502 iNormalizingMargin = static_cast<TInt8>(gainBoost); |
|
503 |
|
504 |
|
505 } |
|
506 |
|
507 else if (iProperties->iAudioType == EAudAMR) |
|
508 { |
|
509 HBufC8* point = 0; |
|
510 TInt siz; |
|
511 TInt32 tim = 0; |
|
512 TInt8 margin = 0; |
|
513 TInt minMargin = KMaxTInt; |
|
514 TInt tmpGain = 0; |
|
515 TInt frameCounter = 0; |
|
516 while(GetEncAudioFrameL(point, siz, tim)) |
|
517 |
|
518 { |
|
519 aFrameHandler->GetNormalizingMargin(point, margin); |
|
520 tmpGain += margin; |
|
521 |
|
522 delete point; |
|
523 point = 0; |
|
524 frameCounter++; |
|
525 if (frameCounter > 1) |
|
526 { |
|
527 tmpGain = tmpGain/3; |
|
528 |
|
529 if (tmpGain < minMargin) |
|
530 { |
|
531 minMargin = tmpGain; |
|
532 } |
|
533 |
|
534 frameCounter = 0; |
|
535 tmpGain = 0; |
|
536 } |
|
537 } |
|
538 |
|
539 iNormalizingMargin = static_cast<TInt8>(minMargin); |
|
540 } |
|
541 return ETrue; |
|
542 |
|
543 } |
|
544 |
|
545 TBool CProcMP4InFileHandler::ReadAudioDecoderSpecificInfoL(HBufC8*& aBytes, TInt aBufferSize) |
|
546 { |
|
547 |
|
548 |
|
549 aBytes = HBufC8::NewL(aBufferSize); |
|
550 |
|
551 CleanupStack::PushL(aBytes); |
|
552 |
|
553 mp4_u8 *buffer = new (ELeave) mp4_u8[aBufferSize]; |
|
554 mp4_u32 decspecinfosize = 0; |
|
555 |
|
556 MP4Err err = MP4ParseReadAudioDecoderSpecificInfo( |
|
557 iParser, |
|
558 buffer, |
|
559 aBufferSize, |
|
560 &decspecinfosize); |
|
561 |
|
562 if (err == MP4_OK) |
|
563 { |
|
564 |
|
565 for (TUint a = 0 ; a < decspecinfosize ; a++) |
|
566 { |
|
567 aBytes->Des().Append(buffer[a]); |
|
568 } |
|
569 } |
|
570 else |
|
571 { |
|
572 delete[] buffer; |
|
573 buffer = 0; |
|
574 CleanupStack::PopAndDestroy(aBytes); |
|
575 aBytes = 0; |
|
576 return EFalse;; |
|
577 } |
|
578 |
|
579 delete[] buffer; |
|
580 buffer = 0; |
|
581 |
|
582 CleanupStack::Pop(aBytes); |
|
583 return ETrue; |
|
584 |
|
585 |
|
586 } |
|
587 |
|
588 |
|
589 CProcMP4InFileHandler::~CProcMP4InFileHandler() |
|
590 { |
|
591 if (iFileOpen) |
|
592 { |
|
593 MP4ParseClose(iParser); |
|
594 } |
|
595 if (iSilentFrame != 0) |
|
596 { |
|
597 delete iSilentFrame; |
|
598 } |
|
599 |
|
600 if (iFrameInfo != 0) |
|
601 { |
|
602 delete iFrameInfo; |
|
603 iFrameInfo = 0; |
|
604 } |
|
605 |
|
606 if (iMP4ReadBuffer != 0) |
|
607 { |
|
608 delete[] iMP4ReadBuffer; |
|
609 } |
|
610 |
|
611 delete iDecoder; |
|
612 |
|
613 delete iFrameHandler; |
|
614 |
|
615 } |
|
616 |
|
617 |
|
618 void CProcMP4InFileHandler::ConstructL(const TDesC& aFileName, |
|
619 RFile* aFileHandle, |
|
620 CAudClip* aClip, |
|
621 TInt /*aReadBufferSize*/, |
|
622 TInt aTargetSampleRate, |
|
623 TChannelMode aChannelMode) |
|
624 { |
|
625 //InitAndOpenFileL(aFileName, aCutInTime, aReadBufferSize); |
|
626 |
|
627 iFrameInfo = new (ELeave) TAACFrameHandlerInfo; |
|
628 |
|
629 |
|
630 // init a raw silent frame |
|
631 // in other in file handlers it is created in CProcInFileHandler |
|
632 |
|
633 const TInt KBitsPerSample = 16; |
|
634 |
|
635 TInt samplesIn20ms = ((iTargetSampleRate) * |
|
636 (KBitsPerSample)/8)/50; |
|
637 |
|
638 if (iChannelMode == EAudStereo) |
|
639 { |
|
640 samplesIn20ms *= 2; |
|
641 |
|
642 } |
|
643 if (samplesIn20ms % 2 != 0) samplesIn20ms--; |
|
644 |
|
645 iRawSilentFrame = HBufC8::NewL(samplesIn20ms); |
|
646 |
|
647 iRawSilentFrame->Des().SetLength(samplesIn20ms); |
|
648 iRawSilentFrame->Des().Fill(0); |
|
649 |
|
650 iRawSilentFrameDuration = 20; |
|
651 |
|
652 |
|
653 iClip = aClip; |
|
654 |
|
655 iTargetSampleRate = aTargetSampleRate; |
|
656 iChannelMode = aChannelMode; |
|
657 |
|
658 if (iParser == 0) |
|
659 { |
|
660 |
|
661 MP4Err err; |
|
662 if (aFileHandle) |
|
663 { |
|
664 err = MP4ParseOpenFileHandle(&iParser, aFileHandle); |
|
665 } |
|
666 else |
|
667 { |
|
668 TBuf<258> temp(aFileName); |
|
669 temp.ZeroTerminate(); |
|
670 MP4FileName name = (MP4FileName)(temp.Ptr()); |
|
671 err = MP4ParseOpen(&iParser , name); |
|
672 } |
|
673 |
|
674 if (err == MP4_FILE_ERROR) |
|
675 { |
|
676 User::Leave(KErrNotFound); |
|
677 } |
|
678 else if (err != MP4_OK) |
|
679 { |
|
680 User::Leave(KErrGeneral); |
|
681 } |
|
682 iFileOpen = ETrue; |
|
683 |
|
684 } |
|
685 |
|
686 TAudFileProperties prop; |
|
687 GetPropertiesL(&prop); |
|
688 |
|
689 if (prop.iAudioType == EAudAAC_MPEG4) |
|
690 { |
|
691 // generate a silent frame ------------------> |
|
692 |
|
693 if (iProperties->iChannelMode == EAudSingleChannel) |
|
694 { |
|
695 |
|
696 iSilentFrame = HBufC8::NewL(KSilentMonoAACFrameLenght); |
|
697 iSilentFrame->Des().Append(KSilentMonoAACFrame, KSilentMonoAACFrameLenght); |
|
698 |
|
699 } |
|
700 else if (iProperties->iChannelMode == EAudStereo) |
|
701 { |
|
702 |
|
703 iSilentFrame = HBufC8::NewL(KSilentStereoAACFrameLenght); |
|
704 iSilentFrame->Des().Append(KSilentStereoAACFrame, KSilentStereoAACFrameLenght); |
|
705 |
|
706 |
|
707 } |
|
708 else |
|
709 { |
|
710 User::Leave(KErrNotSupported); |
|
711 } |
|
712 |
|
713 |
|
714 mp4_u32 frameDurationMilli = ProcTools::MilliSeconds(iProperties->iFrameDuration); |
|
715 |
|
716 |
|
717 iSilentFrameDuration = frameDurationMilli; |
|
718 |
|
719 |
|
720 |
|
721 // <------------------generate a silent frame |
|
722 |
|
723 iFrameHandler = CProcAACFrameHandler::NewL(*iFrameInfo); |
|
724 |
|
725 } |
|
726 else if (prop.iAudioType == EAudAMR) |
|
727 { |
|
728 const TInt KSilentFrameSize = 13; |
|
729 |
|
730 TUint8 silentFrame[KSilentFrameSize]= |
|
731 { |
|
732 0x04,0x63,0x3C,0xC7,0xF0,0x03,0x04,0x39,0xFF,0xE0, |
|
733 0x00,0x00,0x00 |
|
734 }; |
|
735 |
|
736 |
|
737 iSilentFrame = HBufC8::NewL(KSilentFrameSize); |
|
738 iSilentFrame->Des().Append(silentFrame, KSilentFrameSize); |
|
739 iSilentFrameDuration = 20; |
|
740 |
|
741 |
|
742 iFrameHandler = CProcAMRFrameHandler::NewL(); |
|
743 |
|
744 } |
|
745 else if (prop.iAudioType == EAudAMRWB) |
|
746 { |
|
747 TUint8 sf[18] = {0x04,0x10,0x20,0x00,0x21, |
|
748 0x1C,0x14,0xD0,0x11,0x40,0x4C,0xC1,0xA0, |
|
749 0x50,0x00,0x00,0x44,0x30}; |
|
750 iSilentFrame = HBufC8::NewL(18); |
|
751 iSilentFrame->Des().Append(sf,18); |
|
752 iSilentFrameDuration = 20; |
|
753 |
|
754 iFrameHandler = CProcAWBFrameHandler::NewL(); |
|
755 |
|
756 } |
|
757 else if (prop.iAudioType == EAudNoAudio ) |
|
758 { |
|
759 iDecodingPossible = EFalse; |
|
760 return; |
|
761 } |
|
762 |
|
763 if (aClip != 0) |
|
764 { |
|
765 iCutInTime = ProcTools::MilliSeconds(aClip->CutInTime()); |
|
766 |
|
767 } |
|
768 |
|
769 iDecoder = CProcDecoder::NewL(); |
|
770 |
|
771 iDecodingPossible = iDecoder->InitL(*iProperties, aTargetSampleRate, aChannelMode); |
|
772 |
|
773 if (iClip != 0 && iClip->Normalizing()) |
|
774 { |
|
775 SetNormalizingGainL(iFrameHandler); |
|
776 } |
|
777 |
|
778 |
|
779 } |
|
780 |
|
781 CProcMP4InFileHandler::CProcMP4InFileHandler() : CProcInFileHandler(), iParser(0), |
|
782 iLastTimeStamp(0), iFrameInfo(0) |
|
783 { |
|
784 |
|
785 } |
|
786 |
|
787 TBool CProcMP4InFileHandler::GetAudioFrameInfoL(TInt& aFrameAmount, |
|
788 TInt& aAverageFrameDuration, |
|
789 TInt& aAverageFrameSize, |
|
790 TAudFileProperties* aProperties) |
|
791 { |
|
792 |
|
793 PRINT((_L("CProcMP4InFileHandler::GetAudioFrameInfoL in"))); |
|
794 mp4_u32 audiolength = 0; |
|
795 mp4_u32 audiotype = 0; |
|
796 |
|
797 mp4_u8 framespersample = 0; |
|
798 mp4_u32 timescale = 0; |
|
799 mp4_u32 averagebitrate = 0; |
|
800 |
|
801 if (aProperties->iSamplingRate == 0) return KErrNotSupported; |
|
802 |
|
803 MP4Err err = MP4ParseRequestAudioDescription(iParser, &audiolength, &audiotype, |
|
804 &framespersample, ×cale, &averagebitrate); |
|
805 |
|
806 |
|
807 if (aProperties->iAudioType == EAudAMR) |
|
808 { |
|
809 aAverageFrameDuration = 20; |
|
810 |
|
811 } |
|
812 else if(aProperties->iAudioType == EAudAMRWB) |
|
813 { |
|
814 aAverageFrameDuration = 20; |
|
815 |
|
816 } |
|
817 else if(aProperties->iAudioType == EAudAAC_MPEG4) |
|
818 { |
|
819 |
|
820 aAverageFrameDuration = (1024*1000)/(aProperties->iSamplingRate); |
|
821 |
|
822 } |
|
823 else |
|
824 { |
|
825 User::Leave(KErrNotSupported); |
|
826 } |
|
827 |
|
828 aFrameAmount = TInt((TInt)audiolength/aAverageFrameDuration); |
|
829 |
|
830 mp4_u32 lastPosition = 0; |
|
831 |
|
832 err = MP4ParseGetLastPosition(iParser, &lastPosition); |
|
833 |
|
834 SeekAudioFrame(0); |
|
835 |
|
836 |
|
837 if (err != MP4_OK) |
|
838 { |
|
839 return EFalse; |
|
840 |
|
841 } |
|
842 |
|
843 // ignore the first 2 frames |
|
844 HBufC8* frame; |
|
845 TInt size = 0; |
|
846 TInt32 time = 0; |
|
847 |
|
848 |
|
849 if(GetEncAudioFrameL(frame, size, time)) |
|
850 { |
|
851 |
|
852 if (aProperties->iAudioType == EAudAAC_MPEG4) |
|
853 { |
|
854 |
|
855 /* |
|
856 * Read the eAAC+ parameters. Please note that the decoder specific |
|
857 * configuration information does, in case of explicit signalling, |
|
858 * signal the presence of SBR bitstream elements but not completely |
|
859 * the configuration of the SBR. For example, parametric stereo is |
|
860 * signalled only at the bitstream level (due to backwards comptibility |
|
861 * reasons). |
|
862 */ |
|
863 |
|
864 TUint8* buf = const_cast<TUint8*>(frame->Right(frame->Size()).Ptr()); |
|
865 CProcAACFrameHandler::GetEnhancedAACPlusParametersL(buf, size, aProperties, iFrameInfo); |
|
866 |
|
867 } |
|
868 delete frame; |
|
869 frame = 0; |
|
870 } |
|
871 |
|
872 if (GetEncAudioFrameL(frame, size, time)) |
|
873 { |
|
874 delete frame; |
|
875 frame = 0; |
|
876 } |
|
877 |
|
878 // calculate the average of the next 100 frames |
|
879 |
|
880 TInt32 timeSum = 0; |
|
881 TInt32 sizeSum = 0; |
|
882 TInt divider = 0; |
|
883 TInt maxFrameNr = 100; |
|
884 if ( aFrameAmount < 100 ) |
|
885 { |
|
886 maxFrameNr = aFrameAmount; |
|
887 } |
|
888 |
|
889 |
|
890 for (TInt a = 0 ; a < maxFrameNr ; a++) |
|
891 { |
|
892 if (GetEncAudioFrameL(frame, size, time)) |
|
893 { |
|
894 timeSum += time; |
|
895 sizeSum += size; |
|
896 divider++; |
|
897 delete frame; |
|
898 frame = 0; |
|
899 } |
|
900 else |
|
901 { |
|
902 |
|
903 if ( a > 0 ) |
|
904 { |
|
905 PRINT((_L("CProcMP4InFileHandler::GetAudioFrameInfoL breaking the loop since less than 100 frames in input (%d)"),a)); |
|
906 break; |
|
907 } |
|
908 else |
|
909 { |
|
910 PRINT((_L("CProcMP4InFileHandler::GetAudioFrameInfoL can't get any frames from input"))); |
|
911 SeekAudioFrame(lastPosition); |
|
912 return EFalse; |
|
913 } |
|
914 } |
|
915 |
|
916 } |
|
917 |
|
918 if (divider > 0) |
|
919 { |
|
920 aAverageFrameDuration = static_cast<TInt>(timeSum/divider); |
|
921 aAverageFrameSize = static_cast<TInt>(sizeSum/divider); |
|
922 } |
|
923 |
|
924 SeekAudioFrame(lastPosition); |
|
925 |
|
926 PRINT((_L("CProcMP4InFileHandler::GetAudioFrameInfoL out"))); |
|
927 return ETrue; |
|
928 } |
|
929 |
|
930 |
|
931 TBool CProcMP4InFileHandler::GetEncAudioFrameL(HBufC8*& aFrame, TInt& aSize, TInt32& aTime) |
|
932 { |
|
933 PRINT((_L("CProcMP4InFileHandler::GetEncAudioFrameL in"))); |
|
934 if (iParser == 0) |
|
935 { |
|
936 aFrame = 0; |
|
937 return EFalse; |
|
938 } |
|
939 |
|
940 mp4_u32 type = 0; |
|
941 if (iProperties->iAudioType == EAudAAC_MPEG4) |
|
942 type = MP4_TYPE_MPEG4_AUDIO; |
|
943 else if (iProperties->iAudioType == EAudAMR) |
|
944 { |
|
945 type = MP4_TYPE_AMR_NB; |
|
946 if (iMP4ReadBuffer != 0 && iMP4ReadBufferSize > 0 && iMP4ReadBufferPos < iMP4ReadBufferSize) |
|
947 { |
|
948 // we can just read a frame from in-buffer |
|
949 aTime = 20; |
|
950 TBool ret = ReadOneAMRFrameL(aFrame); |
|
951 |
|
952 if (iClip != 0 && iFrameHandler != 0) |
|
953 { |
|
954 TRAPD(err0, ManipulateGainL(aFrame)); |
|
955 if (err0 != KErrNone) |
|
956 { |
|
957 // something went wrong with the gain manipulation |
|
958 // continue by returning the original frame |
|
959 } |
|
960 |
|
961 } |
|
962 PRINT((_L("CProcMP4InFileHandler::GetEncAudioFrameL out from AMRNB branch"))); |
|
963 return ret; |
|
964 } |
|
965 else |
|
966 { |
|
967 // if nothing more to read in the inBuffer |
|
968 delete[] iMP4ReadBuffer; |
|
969 iMP4ReadBuffer = 0; |
|
970 iMP4ReadBufferPos = 0; |
|
971 iMP4ReadBufferSize = 0; |
|
972 } |
|
973 |
|
974 |
|
975 // see if stuff left in the read buffer |
|
976 } |
|
977 |
|
978 else if (iProperties->iAudioType == EAudAMRWB) |
|
979 { |
|
980 type = MP4_TYPE_AMR_WB; |
|
981 |
|
982 if (iMP4ReadBuffer != 0 && iMP4ReadBufferSize > 0 && iMP4ReadBufferPos < iMP4ReadBufferSize) |
|
983 { |
|
984 // we can just read a frame from in-buffer |
|
985 aTime = 20; |
|
986 TBool ret = ReadOneAWBFrameL(aFrame); |
|
987 |
|
988 if (iClip != 0 && iFrameHandler != 0) |
|
989 { |
|
990 TRAPD(err0, ManipulateGainL(aFrame)); |
|
991 if (err0 != KErrNone) |
|
992 { |
|
993 // something went wrong with the gain manipulation |
|
994 // continue by returning the original frame |
|
995 } |
|
996 |
|
997 } |
|
998 PRINT((_L("CProcMP4InFileHandler::GetEncAudioFrameL out from AMRWB branch"))); |
|
999 return ret; |
|
1000 } |
|
1001 |
|
1002 } |
|
1003 |
|
1004 |
|
1005 |
|
1006 mp4_u32 framesize = 0; |
|
1007 mp4_u32 audiosize = 0; |
|
1008 mp4_u32 timestamp = 0; |
|
1009 mp4_u32 returnedframes = 0; |
|
1010 mp4_u32 timestamp2 = 0; |
|
1011 |
|
1012 MP4Err err =MP4ParseNextFrameSize(iParser, type, &framesize); |
|
1013 if (err == MP4_OK) |
|
1014 { |
|
1015 |
|
1016 // some error handling |
|
1017 if (type == MP4_TYPE_MPEG4_AUDIO && (framesize > KMaxAACFrameSize)) |
|
1018 { |
|
1019 // we got too many bytes for some reason... |
|
1020 delete[] iMP4ReadBuffer; |
|
1021 iMP4ReadBuffer = 0; |
|
1022 iMP4ReadBufferSize = 0; |
|
1023 iMP4ReadBufferPos = 0; |
|
1024 PRINT((_L("CProcClipInfoAO::CProcMP4InFileHandler::GetEncAudioFrameL out, too many bytes for AAC %d"), framesize )); |
|
1025 return EFalse; |
|
1026 |
|
1027 } |
|
1028 |
|
1029 |
|
1030 iMP4ReadBufferSize = framesize; |
|
1031 delete[] iMP4ReadBuffer; |
|
1032 iMP4ReadBuffer = 0; |
|
1033 iMP4ReadBuffer = new (ELeave) mp4_u8[framesize]; |
|
1034 iMP4ReadBufferPos = 0; |
|
1035 |
|
1036 err = MP4ParseReadAudioFrames(iParser, |
|
1037 iMP4ReadBuffer, |
|
1038 framesize, |
|
1039 &audiosize, |
|
1040 ×tamp, |
|
1041 &returnedframes, |
|
1042 ×tamp2); |
|
1043 |
|
1044 if (err == MP4_OK) |
|
1045 { |
|
1046 aSize = framesize; |
|
1047 aTime = timestamp - iLastTimeStamp; |
|
1048 iCurrentTimeMilliseconds = timestamp; |
|
1049 iLastTimeStamp = timestamp; |
|
1050 |
|
1051 if (type == MP4_TYPE_MPEG4_AUDIO) |
|
1052 { |
|
1053 aFrame = HBufC8::NewL(audiosize); |
|
1054 aFrame->Des().Append(iMP4ReadBuffer, audiosize); |
|
1055 |
|
1056 } |
|
1057 else if (type == MP4_TYPE_AMR_NB) |
|
1058 { |
|
1059 aTime = 20; |
|
1060 ReadOneAMRFrameL(aFrame); |
|
1061 } |
|
1062 else if (type == MP4_TYPE_AMR_WB) |
|
1063 { |
|
1064 aTime = 20; |
|
1065 ReadOneAWBFrameL(aFrame); |
|
1066 } |
|
1067 } |
|
1068 else |
|
1069 { |
|
1070 delete[] iMP4ReadBuffer; |
|
1071 iMP4ReadBuffer = 0; |
|
1072 iMP4ReadBufferSize = 0; |
|
1073 iMP4ReadBufferPos = 0; |
|
1074 PRINT((_L("CProcMP4InFileHandler::GetEncAudioFrameL out since MP4ParseReadAudioFrames failed"))); |
|
1075 return EFalse; |
|
1076 |
|
1077 } |
|
1078 |
|
1079 // delete if MP4AUDIO. |
|
1080 // AMR frames will be read from buffer as MP4 library |
|
1081 // might have returned more than one AMR-frames |
|
1082 if (type == MP4_TYPE_MPEG4_AUDIO) |
|
1083 { |
|
1084 delete[] iMP4ReadBuffer; |
|
1085 iMP4ReadBuffer = 0; |
|
1086 iMP4ReadBufferSize = 0; |
|
1087 iMP4ReadBufferPos = 0; |
|
1088 } |
|
1089 |
|
1090 } |
|
1091 else |
|
1092 { |
|
1093 PRINT((_L("CProcMP4InFileHandler::GetEncAudioFrameL out since MP4ParseNextFrameSize failed, error %d"),err)); |
|
1094 return EFalse; |
|
1095 |
|
1096 } |
|
1097 |
|
1098 TInt err2 = KErrNone; |
|
1099 |
|
1100 if (iProperties->iAudioTypeExtension == EAudExtensionTypeNoExtension) |
|
1101 { |
|
1102 |
|
1103 // AAC Plus is manipulated in time domain |
|
1104 |
|
1105 if (iClip != 0 && iFrameHandler != 0) |
|
1106 { |
|
1107 TRAP(err2, ManipulateGainL(aFrame)); |
|
1108 } |
|
1109 |
|
1110 } |
|
1111 |
|
1112 if (err2 != KErrNone) |
|
1113 { |
|
1114 // something went wrong with the gain manipulation |
|
1115 // continue by returning the original frame |
|
1116 } |
|
1117 aSize = aFrame->Size(); |
|
1118 |
|
1119 PRINT((_L("CProcMP4InFileHandler::GetEncAudioFrameL out successfully"))); |
|
1120 return ETrue; |
|
1121 } |
|
1122 |
|
1123 |
|
1124 TBool CProcMP4InFileHandler::ReadTimeScale(mp4_u32& aTimescale) |
|
1125 { |
|
1126 |
|
1127 mp4_u32 audiolength = 0; |
|
1128 mp4_u32 audiotype = 0; |
|
1129 mp4_u8 framespersample = 0; |
|
1130 mp4_u32 timescale = 0; |
|
1131 mp4_u32 averagebitrate = 0; |
|
1132 |
|
1133 MP4Err err = MP4ParseRequestAudioDescription(iParser, |
|
1134 &audiolength, |
|
1135 &audiotype, |
|
1136 &framespersample, |
|
1137 ×cale, |
|
1138 &averagebitrate); |
|
1139 |
|
1140 |
|
1141 |
|
1142 if (err == MP4_OK) |
|
1143 { |
|
1144 aTimescale = timescale; |
|
1145 return ETrue; |
|
1146 } |
|
1147 else |
|
1148 { |
|
1149 return EFalse; |
|
1150 } |
|
1151 |
|
1152 } |
|
1153 |
|
1154 |
|
1155 MP4Err CProcMP4InFileHandler::ParseRequestAudioDescription( |
|
1156 mp4_u32 *aAudiolength, |
|
1157 mp4_u32 *aAudiotype, |
|
1158 mp4_u8 *aFramespersample, |
|
1159 mp4_u32 *aTimescale, |
|
1160 mp4_u32 *aAveragebitrate) |
|
1161 |
|
1162 { |
|
1163 |
|
1164 return MP4ParseRequestAudioDescription(iParser, |
|
1165 aAudiolength, |
|
1166 aAudiotype, |
|
1167 aFramespersample, |
|
1168 aTimescale, |
|
1169 aAveragebitrate); |
|
1170 |
|
1171 } |
|
1172 |
|
1173 |
|
1174 TBool CProcMP4InFileHandler::GetInfoForFrameHandler(TAACFrameHandlerInfo& aAACInfo) |
|
1175 { |
|
1176 if (iParser == 0) |
|
1177 { |
|
1178 return EFalse; |
|
1179 } |
|
1180 |
|
1181 aAACInfo.iIs960 = iFrameInfo->iIs960; |
|
1182 aAACInfo.iIsParametricStereo = iFrameInfo->iIsParametricStereo; |
|
1183 aAACInfo.iNumChannels = iFrameInfo->iNumChannels; |
|
1184 aAACInfo.iNumCouplingChannels = iFrameInfo->iNumCouplingChannels; |
|
1185 aAACInfo.iProfileID = iFrameInfo->iProfileID; |
|
1186 aAACInfo.iSampleRateID = iFrameInfo->iSampleRateID; |
|
1187 aAACInfo.isSBR = iFrameInfo->isSBR; |
|
1188 |
|
1189 |
|
1190 mp4_u8 *buffer = 0; |
|
1191 |
|
1192 const TInt bufSize = 64; |
|
1193 TRAPD(nerr, buffer = new (ELeave) mp4_u8[bufSize]) |
|
1194 |
|
1195 if (nerr != KErrNone) |
|
1196 { |
|
1197 delete[] buffer; |
|
1198 return EFalse; |
|
1199 } |
|
1200 |
|
1201 |
|
1202 mp4_u32 decspecinfosize = 0; |
|
1203 |
|
1204 MP4Err err = MP4ParseReadAudioDecoderSpecificInfo( |
|
1205 iParser, |
|
1206 buffer, |
|
1207 64, |
|
1208 &decspecinfosize); |
|
1209 |
|
1210 |
|
1211 if (err == MP4_OK) |
|
1212 { |
|
1213 |
|
1214 mp4AACTransportHandle mp4AAC_ff; |
|
1215 int16 err2 = ReadMP4AudioConfig(buffer, |
|
1216 decspecinfosize, |
|
1217 &mp4AAC_ff); |
|
1218 if (err2 != TRUE) |
|
1219 { |
|
1220 |
|
1221 delete[] buffer; |
|
1222 return EFalse; |
|
1223 |
|
1224 } |
|
1225 |
|
1226 aAACInfo.iSampleRateID = static_cast<TUint8>(mp4AAC_ff.progCfg.sample_rate_idx); |
|
1227 aAACInfo.iSampleRateID = static_cast<TUint8>(mp4AAC_ff.audioInfo.samplingFreqIdx); |
|
1228 |
|
1229 aAACInfo.iProfileID = static_cast<TUint8>(mp4AAC_ff.progCfg.profile); |
|
1230 |
|
1231 if (iProperties->iChannelMode == EAudStereo) |
|
1232 { |
|
1233 aAACInfo.iNumChannels = 2; |
|
1234 } |
|
1235 else if (iProperties->iChannelMode == EAudSingleChannel) |
|
1236 { |
|
1237 aAACInfo.iNumChannels = 1; |
|
1238 } |
|
1239 else |
|
1240 { |
|
1241 aAACInfo.iNumChannels = 0; |
|
1242 } |
|
1243 |
|
1244 |
|
1245 aAACInfo.iIs960 = mp4AAC_ff.audioInfo.gaInfo.FrameLengthFlag; |
|
1246 |
|
1247 aAACInfo.iNumCouplingChannels = 0; |
|
1248 |
|
1249 aAACInfo.iIsParametricStereo = 0; |
|
1250 aAACInfo.isSBR = 0; |
|
1251 |
|
1252 } |
|
1253 |
|
1254 else |
|
1255 { |
|
1256 |
|
1257 delete[] buffer; |
|
1258 return EFalse; |
|
1259 |
|
1260 } |
|
1261 |
|
1262 delete[] buffer; |
|
1263 return ETrue; |
|
1264 |
|
1265 |
|
1266 |
|
1267 } |
|
1268 |
|
1269 |
|
1270 |
|
1271 |
|
1272 TBool CProcMP4InFileHandler::ReadOneAMRFrameL(HBufC8*& aOneAMRFrame) |
|
1273 { |
|
1274 if (iMP4ReadBuffer == 0 || iMP4ReadBufferSize < 1 |
|
1275 || iMP4ReadBufferPos >= iMP4ReadBufferSize) |
|
1276 { |
|
1277 aOneAMRFrame = 0; |
|
1278 return EFalse; |
|
1279 } |
|
1280 |
|
1281 |
|
1282 TInt readSize = 0; |
|
1283 TUint8 dec_mode = (enum Mode)((iMP4ReadBuffer[iMP4ReadBufferPos] & 0x0078) >> 3); |
|
1284 |
|
1285 switch (dec_mode) |
|
1286 { |
|
1287 case 0: |
|
1288 readSize = 12; |
|
1289 break; |
|
1290 case 1: |
|
1291 readSize = 13; |
|
1292 break; |
|
1293 case 2: |
|
1294 readSize = 15; |
|
1295 break; |
|
1296 case 3: |
|
1297 readSize = 17; |
|
1298 break; |
|
1299 case 4: |
|
1300 readSize = 19; |
|
1301 break; |
|
1302 case 5: |
|
1303 readSize = 20; |
|
1304 break; |
|
1305 case 6: |
|
1306 readSize = 26; |
|
1307 break; |
|
1308 case 7: |
|
1309 readSize = 31; |
|
1310 break; |
|
1311 case 8: |
|
1312 readSize = 5; |
|
1313 break; |
|
1314 case 15: |
|
1315 readSize = 0; |
|
1316 break; |
|
1317 default: |
|
1318 readSize = 0; |
|
1319 break; |
|
1320 }; |
|
1321 |
|
1322 aOneAMRFrame = HBufC8::NewL(readSize+1); |
|
1323 |
|
1324 // TPtr8 tmpDes((TPtr8)aOneAMRFrame->Des()); |
|
1325 |
|
1326 TInt lastByte = iMP4ReadBufferPos + readSize; |
|
1327 |
|
1328 for (; iMP4ReadBufferPos <= lastByte ; iMP4ReadBufferPos++) |
|
1329 { |
|
1330 |
|
1331 aOneAMRFrame->Des().Append(iMP4ReadBuffer[iMP4ReadBufferPos]); |
|
1332 } |
|
1333 // iMP4ReadBufferPos++; |
|
1334 |
|
1335 return ETrue; |
|
1336 |
|
1337 } |
|
1338 |
|
1339 TBool CProcMP4InFileHandler::ReadOneAWBFrameL(HBufC8*& aOneAWBFrame) |
|
1340 { |
|
1341 if (iMP4ReadBuffer == 0 || iMP4ReadBufferSize < 1 |
|
1342 || iMP4ReadBufferPos >= iMP4ReadBufferSize) |
|
1343 { |
|
1344 aOneAWBFrame = 0; |
|
1345 return EFalse; |
|
1346 } |
|
1347 TUint8 toc = iMP4ReadBuffer[iMP4ReadBufferPos]; |
|
1348 TUint8 mode = static_cast<TUint8>((toc >> 3) & 0x0F); |
|
1349 |
|
1350 TInt readSize = KAWBPacked_size[mode]; |
|
1351 |
|
1352 aOneAWBFrame = HBufC8::NewL(readSize+1); |
|
1353 |
|
1354 TInt lastByte = iMP4ReadBufferPos + readSize; |
|
1355 |
|
1356 for (; iMP4ReadBufferPos <= lastByte ; iMP4ReadBufferPos++) |
|
1357 { |
|
1358 |
|
1359 aOneAWBFrame->Des().Append(iMP4ReadBuffer[iMP4ReadBufferPos]); |
|
1360 } |
|
1361 |
|
1362 return ETrue; |
|
1363 |
|
1364 } |
|
1365 |
|