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 |
|
22 #include "ProcVisProcessor.h" |
|
23 #include "audconstants.h" |
|
24 |
|
25 #include "ProcMP4InFileHandler.h" |
|
26 #include "ProcADTSInFileHandler.h" |
|
27 #include "ProcMP3InFileHandler.h" |
|
28 #include "ProcAWBInFileHandler.h" |
|
29 #include "ProcWAVInFileHandler.h" |
|
30 #include "ProcAMRInFileHandler.h" |
|
31 |
|
32 |
|
33 #include "ProcAMRFrameHandler.h" |
|
34 #include "ProcAACFrameHandler.h" |
|
35 #include "ProcMP3FrameHandler.h" |
|
36 #include "ProcAWBFrameHandler.h" |
|
37 #include "ProcWAVFrameHandler.h" |
|
38 |
|
39 CProcVisProcessor* CProcVisProcessor::NewL() |
|
40 { |
|
41 |
|
42 |
|
43 CProcVisProcessor* self = new (ELeave) CProcVisProcessor(); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 CProcVisProcessor* CProcVisProcessor::NewLC() |
|
51 { |
|
52 CProcVisProcessor* self = new (ELeave) CProcVisProcessor(); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 CProcVisProcessor::~CProcVisProcessor() |
|
60 { |
|
61 |
|
62 if (iVisualization != 0) |
|
63 { |
|
64 delete[] iVisualization; |
|
65 } |
|
66 if (iInFile != 0) |
|
67 { |
|
68 delete iInFile; |
|
69 } |
|
70 if (iFrameHandler != 0) |
|
71 { |
|
72 delete iFrameHandler; |
|
73 } |
|
74 |
|
75 } |
|
76 |
|
77 void CProcVisProcessor::VisualizeClipL(const CAudClipInfo* aClipInfo, TInt aSize) |
|
78 { |
|
79 |
|
80 // initialize... |
|
81 iClipInfo = aClipInfo; |
|
82 iVisualizationSize = aSize; |
|
83 iVisualization = new (ELeave) TInt8[iVisualizationSize]; |
|
84 |
|
85 |
|
86 if (aClipInfo->Properties().iFileFormat == EAudFormatAMR) |
|
87 { |
|
88 CProcInFileHandler* inFileHandler = CProcAMRInFileHandler::NewL(aClipInfo->FileName(), |
|
89 aClipInfo->FileHandle(), |
|
90 0, 2048); |
|
91 iInFile = inFileHandler; |
|
92 iFrameHandler = CProcAMRFrameHandler::NewL(); |
|
93 TAudFileProperties properties; |
|
94 inFileHandler->GetPropertiesL(&properties); |
|
95 inFileHandler->SetPropertiesL(properties); |
|
96 iFrameAmount = properties.iFrameCount; |
|
97 inFileHandler->SeekAudioFrame(0); |
|
98 } |
|
99 else if (aClipInfo->Properties().iFileFormat == EAudFormatAMRWB) |
|
100 { |
|
101 CProcInFileHandler* inFileHandler = CProcAWBInFileHandler::NewL(aClipInfo->FileName(), |
|
102 aClipInfo->FileHandle(), |
|
103 0, 2048); |
|
104 iInFile = inFileHandler; |
|
105 iFrameHandler = CProcAWBFrameHandler::NewL(); |
|
106 TAudFileProperties properties; |
|
107 inFileHandler->GetPropertiesL(&properties); |
|
108 inFileHandler->SetPropertiesL(properties); |
|
109 iFrameAmount = properties.iFrameCount; |
|
110 inFileHandler->SeekAudioFrame(0); |
|
111 } |
|
112 else if (aClipInfo->Properties().iFileFormat == EAudFormatMP3) |
|
113 { |
|
114 CProcInFileHandler* inFileHandler = CProcMP3InFileHandler::NewL(aClipInfo->FileName(), |
|
115 aClipInfo->FileHandle(), |
|
116 0, 2048); |
|
117 iInFile = inFileHandler; |
|
118 iFrameHandler = CProcMP3FrameHandler::NewL(); |
|
119 TAudFileProperties properties; |
|
120 inFileHandler->GetPropertiesL(&properties); |
|
121 inFileHandler->SetPropertiesL(properties); |
|
122 iFrameAmount = properties.iFrameCount; |
|
123 inFileHandler->SeekAudioFrame(0); |
|
124 } |
|
125 else if (aClipInfo->Properties().iFileFormat == EAudFormatWAV) |
|
126 { |
|
127 CProcInFileHandler* inFileHandler = CProcWAVInFileHandler::NewL(aClipInfo->FileName(), |
|
128 aClipInfo->FileHandle(), |
|
129 0, 8192); |
|
130 iInFile = inFileHandler; |
|
131 TAudFileProperties properties; |
|
132 inFileHandler->GetPropertiesL(&properties); |
|
133 inFileHandler->SetPropertiesL(properties); |
|
134 iFrameAmount = properties.iFrameCount; |
|
135 inFileHandler->SeekAudioFrame(0); |
|
136 iFrameHandler = CProcWAVFrameHandler::NewL(properties.iNumberOfBitsPerSample); |
|
137 } |
|
138 |
|
139 |
|
140 else if (aClipInfo->Properties().iFileFormat == EAudFormatMP4 && |
|
141 aClipInfo->Properties().iAudioType == EAudAAC_MPEG4) |
|
142 { |
|
143 |
|
144 CProcInFileHandler* inFileHandler = CProcMP4InFileHandler::NewL(aClipInfo->FileName(), |
|
145 aClipInfo->FileHandle(), |
|
146 0, 8192); |
|
147 |
|
148 iInFile = inFileHandler; |
|
149 TAudFileProperties properties; |
|
150 |
|
151 inFileHandler->GetPropertiesL(&properties); |
|
152 |
|
153 inFileHandler->SetPropertiesL(properties); |
|
154 //inFileHandler->SetPropertiesL(properties); |
|
155 iFrameAmount = properties.iFrameCount; |
|
156 inFileHandler->SeekAudioFrame(0); |
|
157 |
|
158 TAACFrameHandlerInfo frameInfo; |
|
159 CProcMP4InFileHandler* MP4inFileHandler = static_cast<CProcMP4InFileHandler*>(inFileHandler); |
|
160 MP4inFileHandler->GetInfoForFrameHandler(frameInfo); |
|
161 |
|
162 iFrameHandler = CProcAACFrameHandler::NewL(frameInfo); |
|
163 |
|
164 } |
|
165 else if (aClipInfo->Properties().iFileFormat == EAudFormatMP4 && |
|
166 (aClipInfo->Properties().iAudioType == EAudAMR)) |
|
167 { |
|
168 |
|
169 CProcInFileHandler* inFileHandler = CProcMP4InFileHandler::NewL(aClipInfo->FileName(), |
|
170 aClipInfo->FileHandle(), |
|
171 0, 8092); |
|
172 |
|
173 iInFile = inFileHandler; |
|
174 TAudFileProperties properties; |
|
175 |
|
176 inFileHandler->GetPropertiesL(&properties); |
|
177 |
|
178 inFileHandler->SetPropertiesL(properties); |
|
179 //inFileHandler->SetPropertiesL(properties); |
|
180 iFrameAmount = properties.iFrameCount; |
|
181 inFileHandler->SeekAudioFrame(0); |
|
182 |
|
183 iFrameHandler = CProcAMRFrameHandler::NewL(); |
|
184 |
|
185 } |
|
186 else if (aClipInfo->Properties().iFileFormat == EAudFormatMP4 && |
|
187 (aClipInfo->Properties().iAudioType == EAudAMRWB)) |
|
188 { |
|
189 |
|
190 CProcInFileHandler* inFileHandler = CProcMP4InFileHandler::NewL(aClipInfo->FileName(), |
|
191 aClipInfo->FileHandle(), |
|
192 0, 8092); |
|
193 |
|
194 iInFile = inFileHandler; |
|
195 TAudFileProperties properties; |
|
196 |
|
197 inFileHandler->GetPropertiesL(&properties); |
|
198 |
|
199 inFileHandler->SetPropertiesL(properties); |
|
200 //inFileHandler->SetPropertiesL(properties); |
|
201 iFrameAmount = properties.iFrameCount; |
|
202 inFileHandler->SeekAudioFrame(0); |
|
203 |
|
204 iFrameHandler = CProcAWBFrameHandler::NewL(); |
|
205 |
|
206 } |
|
207 else if (aClipInfo->Properties().iFileFormat == EAudFormatAAC_ADTS && |
|
208 aClipInfo->Properties().iAudioType == EAudAAC_MPEG4 |
|
209 ) |
|
210 { |
|
211 |
|
212 CProcInFileHandler* inFileHandler = CProcADTSInFileHandler::NewL(aClipInfo->FileName(), |
|
213 aClipInfo->FileHandle(), |
|
214 0, 8092); |
|
215 |
|
216 |
|
217 |
|
218 iInFile = inFileHandler; |
|
219 TAudFileProperties properties; |
|
220 |
|
221 inFileHandler->GetPropertiesL(&properties); |
|
222 |
|
223 inFileHandler->SetPropertiesL(properties); |
|
224 iFrameAmount = properties.iFrameCount; |
|
225 inFileHandler->SeekAudioFrame(0); |
|
226 |
|
227 TAACFrameHandlerInfo frameInfo; |
|
228 CProcADTSInFileHandler* ADTSinFileHandler = static_cast<CProcADTSInFileHandler*>(inFileHandler); |
|
229 ADTSinFileHandler->GetInfoForFrameHandler(frameInfo); |
|
230 |
|
231 iFrameHandler = CProcAACFrameHandler::NewL(frameInfo); |
|
232 |
|
233 } |
|
234 |
|
235 |
|
236 } |
|
237 |
|
238 TBool CProcVisProcessor::VisualizeClipPieceL(TInt &aProgress) |
|
239 { |
|
240 |
|
241 if (iInFile == 0) |
|
242 return ETrue; |
|
243 |
|
244 if (iVisualizationPos >= iVisualizationSize) |
|
245 { |
|
246 if (iInFile != 0) |
|
247 { |
|
248 delete iInFile; |
|
249 iInFile = 0; |
|
250 } |
|
251 |
|
252 if (iFrameHandler != 0) |
|
253 { |
|
254 delete iFrameHandler; |
|
255 iFrameHandler = 0; |
|
256 } |
|
257 return ETrue; |
|
258 } |
|
259 |
|
260 HBufC8* point = 0; |
|
261 TInt siz; |
|
262 TInt32 tim = 0; |
|
263 |
|
264 RArray<TInt> gains; |
|
265 |
|
266 TAudType audType = iClipInfo->Properties().iAudioType; |
|
267 |
|
268 |
|
269 TInt maxGain = 0; |
|
270 TInt gainAmount = 0; |
|
271 TInt divider = 0; |
|
272 for (TInt b = 0 ; b < 2 ; b++) |
|
273 { |
|
274 gains.Reset(); |
|
275 |
|
276 |
|
277 TBool decReq = iInFile->DecodingRequired(); |
|
278 iInFile->SetDecodingRequired(EFalse); |
|
279 TBool tmp = EFalse; |
|
280 |
|
281 if (!iInFile->GetAudioFrameL(point, siz, tim, tmp)) |
|
282 { |
|
283 iInFile->SetDecodingRequired(decReq); |
|
284 |
|
285 delete iInFile; |
|
286 iInFile = 0; |
|
287 delete iFrameHandler; |
|
288 iFrameHandler = 0; |
|
289 return ETrue; |
|
290 |
|
291 } |
|
292 iInFile->SetDecodingRequired(decReq); |
|
293 CleanupStack::PushL(point); |
|
294 |
|
295 iFramesProcessed++; |
|
296 if (siz > 0) |
|
297 { |
|
298 |
|
299 |
|
300 iFrameHandler->GetGainL(point, gains, maxGain); |
|
301 |
|
302 if (point != NULL) |
|
303 { |
|
304 CleanupStack::PopAndDestroy(point); |
|
305 } |
|
306 |
|
307 |
|
308 if (audType == EAudAMR || audType == EAudAMRWB) |
|
309 { |
|
310 |
|
311 for (TInt c = 0 ; c < gains.Count() ; c++) |
|
312 { |
|
313 if (gains[c] > gainAmount) |
|
314 { |
|
315 gainAmount = gains[c]; |
|
316 } |
|
317 |
|
318 //gainAmount+=gains[c]; |
|
319 } |
|
320 } |
|
321 else if (audType == EAudAAC_MPEG4) |
|
322 { |
|
323 for (TInt c = 0 ; c < gains.Count() ; c++) |
|
324 { |
|
325 if (gains[c] > gainAmount) |
|
326 { |
|
327 gainAmount = gains[c]; |
|
328 } |
|
329 |
|
330 //gainAmount+=gains[c]; |
|
331 } |
|
332 } |
|
333 else if (audType == EAudMP3) |
|
334 { |
|
335 for (TInt c = 0 ; c < gains.Count() ; c++) |
|
336 { |
|
337 |
|
338 gainAmount+=gains[c]; |
|
339 divider++; |
|
340 } |
|
341 //gainAmount /= gains.Count(); |
|
342 } |
|
343 else if (audType == EAudWAV) |
|
344 { |
|
345 for (TInt c = 0 ; c < gains.Count() ; c++) |
|
346 { |
|
347 |
|
348 gainAmount+=gains[c]; |
|
349 divider++; |
|
350 } |
|
351 //gainAmount /= gains.Count(); |
|
352 } |
|
353 |
|
354 } |
|
355 |
|
356 else |
|
357 { |
|
358 CleanupStack::PopAndDestroy(point); |
|
359 // silent frame |
|
360 gains.Append(0); |
|
361 gains.Append(0); |
|
362 maxGain = 1; |
|
363 } |
|
364 } |
|
365 |
|
366 |
|
367 if (audType == EAudMP3 && divider > 0) gainAmount/= divider; |
|
368 if (audType == EAudWAV && divider > 0) gainAmount/= divider; |
|
369 |
|
370 |
|
371 |
|
372 iVisualizationProcessed = (iFramesProcessed*KAedMaxVisualizationResolution)/iFrameAmount; |
|
373 |
|
374 |
|
375 while (iVisualizationWritten <= iVisualizationProcessed) |
|
376 { |
|
377 if (iVisualizationPos >= iVisualizationSize) |
|
378 { |
|
379 break; |
|
380 } |
|
381 |
|
382 if (audType == EAudAAC_MPEG4) |
|
383 { |
|
384 |
|
385 TReal ga(gainAmount-100); |
|
386 TReal exponent= ga/36; |
|
387 TReal visResult(0); |
|
388 Math::Pow(visResult, 10, exponent); |
|
389 |
|
390 TInt16 visR = 0; |
|
391 TInt err = Math::Int(visR, visResult); |
|
392 |
|
393 if (visR > 127) visR = 127; |
|
394 |
|
395 if (err == KErrNone) |
|
396 { |
|
397 iVisualization[iVisualizationPos] = static_cast<TInt8>(visR); |
|
398 } |
|
399 else |
|
400 { |
|
401 iVisualization[iVisualizationPos] = 0; |
|
402 |
|
403 } |
|
404 |
|
405 } |
|
406 else |
|
407 { |
|
408 TInt visValue = (127*gainAmount)/maxGain; |
|
409 |
|
410 if (visValue < 0) |
|
411 { |
|
412 visValue = 0; |
|
413 } |
|
414 else if (visValue > KMaxTInt8) |
|
415 { |
|
416 visValue = KMaxTInt8; |
|
417 } |
|
418 |
|
419 iVisualization[iVisualizationPos] = static_cast<TInt8>(visValue); |
|
420 } |
|
421 iVisualizationPos++; |
|
422 iVisualizationWritten = (KAedMaxVisualizationResolution*iVisualizationPos)/iVisualizationSize; |
|
423 } |
|
424 |
|
425 |
|
426 gains.Reset(); |
|
427 aProgress = iVisualizationWritten/(KAedMaxVisualizationResolution/100); // convert resolution to percentages |
|
428 return EFalse; |
|
429 |
|
430 |
|
431 } |
|
432 |
|
433 void CProcVisProcessor::GetFinalVisualizationL(TInt8*& aVisualization, TInt& aSize) |
|
434 { |
|
435 |
|
436 if (iVisualization == 0) |
|
437 { |
|
438 User::Leave(KErrNotReady); |
|
439 } |
|
440 |
|
441 aVisualization = new (ELeave) TInt8[iVisualizationSize]; |
|
442 |
|
443 for (TInt a = 0 ; a < iVisualizationSize ; a++) |
|
444 { |
|
445 aVisualization[a] = iVisualization[a]; |
|
446 } |
|
447 aSize = iVisualizationSize; |
|
448 |
|
449 delete[] iVisualization; |
|
450 iVisualization = 0; |
|
451 |
|
452 } |
|
453 |
|
454 |
|
455 void CProcVisProcessor::ConstructL() |
|
456 { |
|
457 |
|
458 } |
|
459 |
|
460 CProcVisProcessor::CProcVisProcessor() |
|
461 { |
|
462 |
|
463 } |
|
464 |
|