1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 #include "pv_avifile_streamlist.h"
19
PVAviFileStreamlist(PVFile * aFp,uint32 aStrListSz)20 PVAviFileStreamlist::PVAviFileStreamlist(PVFile *aFp, uint32 aStrListSz)
21 {
22 iCodecSpecificHdrDataSize = 0;
23 iStreamListSize = aStrListSz;
24 ipCodecSpecificHdrData = NULL;
25 iError = PV_AVI_FILE_PARSER_SUCCESS;
26 uint32 bytesRead = 0;
27 uint32 chunkType = 0;
28
29 while (bytesRead < iStreamListSize)
30 {
31 if ((iError = PVAviFileParserUtils::ReadNextChunkType(aFp, chunkType)) != PV_AVI_FILE_PARSER_SUCCESS)
32 {
33 PVAVIFILE_LOGINFO((0, "PVAviFileStreamlist::PVAviFileStreamlist: Unsupported chunk"));
34
35 if (PV_AVI_FILE_PARSER_UNSUPPORTED_CHUNK == iError)
36 {
37 uint32 chksz = 0;
38 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, chksz, true))
39 {
40 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
41 iError = PV_AVI_FILE_PARSER_READ_ERROR;
42 break;
43 }
44 aFp->Seek(chksz, Oscl_File::SEEKCUR);
45 bytesRead += chksz + CHUNK_SIZE + CHUNK_SIZE; // data + chunk size + chunk type
46
47 PVAVIFILE_LOGINFO((0, "PVAviFileStreamlist::PVAviFileStreamlist: Unsupported Chunk Skipped"));
48
49 iError = PV_AVI_FILE_PARSER_SUCCESS;
50 continue;
51 }
52 else
53 {
54
55 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
56 iError = PV_AVI_FILE_PARSER_READ_ERROR;
57 break;
58 }
59 }
60
61 bytesRead += CHUNK_SIZE;
62
63 if (STRH == chunkType)
64 {
65 PVAVIFILE_LOGINFO((0, "PVAviFileStreamlist::PVAviFileStreamlist: Found Stream Header"));
66
67 uint32 aviStrhSize = 0;
68 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, aviStrhSize, true))
69 {
70 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
71 iError = PV_AVI_FILE_PARSER_READ_ERROR;
72 break;
73 }
74
75 bytesRead += CHUNK_SIZE;
76
77 if (bytesRead > iStreamListSize)
78 {
79 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File & Byte Count mismatch"));
80 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
81 break;
82
83 }
84
85 if ((aviStrhSize <= 0) || (aviStrhSize > iStreamListSize))
86 {
87 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: stream header size greater than stream list size"));
88 iError = PV_AVI_FILE_PARSER_WRONG_SIZE;
89 break;
90
91 }
92
93 if ((iError = ParseStreamHeader(aFp, aviStrhSize)) != PV_AVI_FILE_PARSER_SUCCESS)
94 {
95 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: ParseStreamHeader function error"));
96 break;
97 }
98
99 bytesRead += aviStrhSize;
100 if (bytesRead > iStreamListSize)
101 {
102 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
103 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
104 break;
105
106 }
107 }
108 else if (STRF == chunkType)
109 {
110 PVAVIFILE_LOGINFO((0, "PVAviFileStreamlist::PVAviFileStreamlist: Found Stream Format Header"));
111
112 uint32 aviStrfSize = 0;
113 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, aviStrfSize, true))
114 {
115 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
116 iError = PV_AVI_FILE_PARSER_READ_ERROR;
117 break;
118 }
119
120 bytesRead += CHUNK_SIZE;
121
122 if (bytesRead > iStreamListSize)
123 {
124 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
125 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
126 break;
127
128 }
129
130 if ((aviStrfSize <= 0) || (aviStrfSize > iStreamListSize))
131 {
132 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: Stream Format Header Size Greater Than Stream List Size"));
133 iError = PV_AVI_FILE_PARSER_WRONG_SIZE;
134 break;
135
136 }
137
138 if ((iError = ParseStreamFormat(aFp, aviStrfSize)) != PV_AVI_FILE_PARSER_SUCCESS)
139 {
140 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: ParseStreamFormat returned error"));
141 break;
142 }
143
144 bytesRead += aviStrfSize;
145 if (bytesRead > iStreamListSize)
146 {
147 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
148 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
149 break;
150
151 }
152 }
153 else if (STRD == chunkType)
154 {
155 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, iCodecSpecificHdrDataSize, true))
156 {
157 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
158 iError = PV_AVI_FILE_PARSER_READ_ERROR;
159 break;
160 }
161
162 bytesRead += CHUNK_SIZE;
163
164 if ((iCodecSpecificHdrDataSize <= 0) || (iCodecSpecificHdrDataSize > iStreamListSize))
165 {
166 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
167 iError = PV_AVI_FILE_PARSER_WRONG_SIZE;
168 break;
169 }
170
171 ipCodecSpecificHdrData = NULL;
172 ipCodecSpecificHdrData = (uint8*)oscl_malloc(iCodecSpecificHdrDataSize);
173 if (!ipCodecSpecificHdrData)
174 {
175 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: Unable to allocate memory."));
176 iError = PV_AVI_FILE_PARSER_INSUFFICIENT_MEMORY;
177 break;
178 }
179 if (0 == PVAviFileParserUtils::read8(aFp, ipCodecSpecificHdrData, iCodecSpecificHdrDataSize))
180 {
181 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
182 iError = PV_AVI_FILE_PARSER_READ_ERROR;
183 break;
184 }
185
186 bytesRead += iCodecSpecificHdrDataSize;
187 if (bytesRead > iStreamListSize)
188 {
189 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
190 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
191 break;
192 }
193 }
194 else if (STRN == chunkType)
195 {
196 PVAVIFILE_LOGINFO((0, "PVAviFileStreamlist::PVAviFileStreamlist: Found stream name"));
197
198 uint32 strnSz = 0;
199 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, strnSz, true))
200 {
201 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
202 iError = PV_AVI_FILE_PARSER_READ_ERROR;
203 break;
204 }
205 bytesRead += CHUNK_SIZE;
206 if (strnSz >= MAX_STRN_SZ)
207 {
208 uint8* strn = (uint8*)oscl_malloc(strnSz);
209 if (!strn)
210 {
211 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: Unable to allocate memory."));
212 iError = PV_AVI_FILE_PARSER_INSUFFICIENT_MEMORY;
213 break;
214 }
215 if (PVAviFileParserUtils::read8(aFp, strn, strnSz) == 0)
216 {
217 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
218 iError = PV_AVI_FILE_PARSER_READ_ERROR;
219 break;
220 }
221
222 oscl_strncpy(iStreamName, (char*)strn, (MAX_STRN_SZ - 1));
223 iStreamName[MAX_STRN_SZ - 1] = '\0';
224 oscl_free(strn);
225 }
226 else
227 {
228 if (PVAviFileParserUtils::read8(aFp, (uint8*)iStreamName, strnSz) == 0)
229 {
230 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
231 iError = PV_AVI_FILE_PARSER_READ_ERROR;
232 break;
233 }
234 }
235
236 bytesRead += strnSz;
237 if (bytesRead > iStreamListSize)
238 {
239 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
240 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
241 break;
242 }
243
244 }
245 else if (JUNK == chunkType)
246 {
247 PVAVIFILE_LOGINFO((0, "PVAviFileStreamlist::PVAviFileStreamlist: Skip Junk Data"));
248
249 uint32 junkSize = 0;
250 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, junkSize, true))
251 {
252 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Read Error"));
253 iError = PV_AVI_FILE_PARSER_READ_ERROR;
254 break;
255 }
256
257 bytesRead += CHUNK_SIZE;
258 if (bytesRead > iStreamListSize)
259 {
260 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
261 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
262 break;
263 }
264
265 if ((junkSize <= 0) || (junkSize > iStreamListSize))
266 {
267 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: Junk data size more than stream list size"));
268 iError = PV_AVI_FILE_PARSER_WRONG_SIZE;
269 break;
270 }
271
272 aFp->Seek(junkSize, Oscl_File::SEEKCUR);
273 bytesRead += junkSize;
274 if (bytesRead > iStreamListSize)
275 {
276 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: File Size & Byte Count Mismatch"));
277 iError = PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
278 break;
279 }
280
281 }
282 else
283 {
284 PVAVIFILE_LOGERROR((0, "PVAviFileStreamlist::PVAviFileStreamlist: Unexpected chunk in stream list"));
285 iError = PV_AVI_FILE_PARSER_WRONG_CHUNK;
286 break;
287 }
288
289
290 } //while(bytesRead <= iStreamListSize)
291
292 }
293
294
295 PV_AVI_FILE_PARSER_ERROR_TYPE
ParseStreamHeader(PVFile * aFp,uint32 aHdrSize)296 PVAviFileStreamlist::ParseStreamHeader(PVFile *aFp, uint32 aHdrSize)
297 {
298
299 uint32 bytesRead = 0;
300
301 if (PV_AVI_FILE_PARSER_SUCCESS != PVAviFileParserUtils::read32(aFp, iStreamHdr.iStreamTypeFCC))
302 {
303 return PV_AVI_FILE_PARSER_READ_ERROR;
304 }
305
306 bytesRead += CHUNK_SIZE;
307
308 if (0 == (PVAviFileParserUtils::read8(aFp, iStreamHdr.iStreamHandler, CHUNK_SIZE)))
309 {
310 return PV_AVI_FILE_PARSER_READ_ERROR;
311 }
312
313
314 bytesRead += CHUNK_SIZE;
315
316 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iFlags)))
317 {
318 return PV_AVI_FILE_PARSER_READ_ERROR;
319 }
320
321 bytesRead += CHUNK_SIZE;
322
323 if (iStreamHdr.iFlags != 0)
324 {
325 if (iStreamHdr.iFlags & AVISF_VIDEO_PALCHANGES)
326 iStreamHdr.iIsVidPalChangeAvailable = true;
327
328 if (iStreamHdr.iFlags & AVISF_DISABLED)
329 iStreamHdr.iAVISF_Disabled = true;
330 }
331
332 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamHdr.iPriority, true)))
333 {
334 return PV_AVI_FILE_PARSER_READ_ERROR;
335 }
336
337 bytesRead += sizeof(iStreamHdr.iPriority);
338
339 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamHdr.iLanguage, true)))
340 {
341 return PV_AVI_FILE_PARSER_READ_ERROR;
342 }
343
344 bytesRead += sizeof(iStreamHdr.iPriority);
345
346 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iInitFrames, true)))
347 {
348 return PV_AVI_FILE_PARSER_READ_ERROR;
349 }
350
351 bytesRead += CHUNK_SIZE;
352
353 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iScale, true)))
354 {
355 return PV_AVI_FILE_PARSER_READ_ERROR;
356 }
357
358 bytesRead += CHUNK_SIZE;
359
360 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iRate, true)))
361 {
362 return PV_AVI_FILE_PARSER_READ_ERROR;
363 }
364
365 bytesRead += CHUNK_SIZE;
366
367 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iStart, true)))
368 {
369 return PV_AVI_FILE_PARSER_READ_ERROR;
370 }
371
372 bytesRead += CHUNK_SIZE;
373
374 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iLength, true)))
375 {
376 return PV_AVI_FILE_PARSER_READ_ERROR;
377 }
378
379 bytesRead += CHUNK_SIZE;
380
381 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iSugBufSize, true)))
382 {
383 return PV_AVI_FILE_PARSER_READ_ERROR;
384 }
385
386 bytesRead += CHUNK_SIZE;
387
388 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iQuality, true)))
389 {
390 return PV_AVI_FILE_PARSER_READ_ERROR;
391 }
392
393 bytesRead += CHUNK_SIZE;
394
395 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamHdr.iSampleSize, true)))
396 {
397 return PV_AVI_FILE_PARSER_READ_ERROR;
398 }
399
400 bytesRead += CHUNK_SIZE;
401
402 if (bytesRead > aHdrSize)
403 {
404 return PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
405 }
406 else if (bytesRead == aHdrSize)
407 {
408 return PV_AVI_FILE_PARSER_SUCCESS;
409 }
410 else // read rcFrame
411 {
412 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamHdr.ircFrame.left, true)))
413 {
414 return PV_AVI_FILE_PARSER_READ_ERROR;
415 }
416 else
417 {
418 bytesRead += sizeof(uint16);
419 }
420
421 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamHdr.ircFrame.top, true)))
422 {
423 return PV_AVI_FILE_PARSER_READ_ERROR;
424 }
425 else
426 {
427 bytesRead += sizeof(uint16);
428 }
429
430 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamHdr.ircFrame.right, true)))
431 {
432 return PV_AVI_FILE_PARSER_READ_ERROR;
433 }
434 else
435 {
436 bytesRead += sizeof(uint16);
437 }
438
439 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamHdr.ircFrame.bottom, true)))
440 {
441 return PV_AVI_FILE_PARSER_READ_ERROR;
442 }
443 else
444 {
445 bytesRead += sizeof(uint16);
446 }
447 }
448
449 if (bytesRead != aHdrSize)
450 {
451 return PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
452 }
453
454 iStreamHdr.iSamplingRate = (OsclFloat)iStreamHdr.iRate / iStreamHdr.iScale;
455
456 return PV_AVI_FILE_PARSER_SUCCESS;
457 }
458
459
460 PV_AVI_FILE_PARSER_ERROR_TYPE
ParseStreamFormat(PVFile * aFp,uint32 aHdrSize)461 PVAviFileStreamlist::ParseStreamFormat(PVFile *aFp, uint32 aHdrSize)
462 {
463 uint32 bytesRead = 0;
464 switch (iStreamHdr.iStreamTypeFCC)
465 {
466 case AUDS:
467 {
468 iStreamFmt.iType = PV_2_AUDIO;
469 }
470 break;
471 case VIDS:
472 {
473 iStreamFmt.iType = PV_2_VIDEO;
474 }
475 break;
476 case MIDI:
477 {
478 iStreamFmt.iType = MIDI;
479 }
480 break;
481 case TXTS:
482 {
483 iStreamFmt.iType = TEXT;
484 }
485 break;
486 default:
487 {
488 return PV_AVI_FILE_PARSER_ERROR_STREAM_TYPE_UNKNOWN;
489 }
490
491 }
492 ; //end switch
493
494 if (iStreamFmt.iType == PV_2_AUDIO)
495 {
496 iStreamFmt.iAudWaveFormatEx.FormatTag = 0;
497 iStreamFmt.iAudWaveFormatEx.Channels = 0;
498 iStreamFmt.iAudWaveFormatEx.SamplesPerSec = 0;
499 iStreamFmt.iAudWaveFormatEx.AvgBytesPerSec = 0;
500 iStreamFmt.iAudWaveFormatEx.BlockAlign = 0;
501 iStreamFmt.iAudWaveFormatEx.BitsPerSample = 0;
502 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamFmt.iAudWaveFormatEx.FormatTag, true)))
503 {
504 return PV_AVI_FILE_PARSER_READ_ERROR;
505 }
506
507 bytesRead += sizeof(uint16);
508 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamFmt.iAudWaveFormatEx.Channels, true)))
509 {
510 return PV_AVI_FILE_PARSER_READ_ERROR;
511 }
512
513 bytesRead += sizeof(uint16);
514 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iAudWaveFormatEx.SamplesPerSec, true)))
515 {
516 return PV_AVI_FILE_PARSER_READ_ERROR;
517 }
518
519 bytesRead += CHUNK_SIZE;
520 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iAudWaveFormatEx.AvgBytesPerSec, true)))
521 {
522 return PV_AVI_FILE_PARSER_READ_ERROR;
523 }
524
525 bytesRead += CHUNK_SIZE;
526 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamFmt.iAudWaveFormatEx.BlockAlign, true)))
527 {
528 return PV_AVI_FILE_PARSER_READ_ERROR;
529 }
530
531 bytesRead += sizeof(uint16);
532 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamFmt.iAudWaveFormatEx.BitsPerSample, true)))
533 {
534 return PV_AVI_FILE_PARSER_READ_ERROR;
535 }
536
537 bytesRead += sizeof(uint16);
538
539 if (bytesRead < aHdrSize)
540 {
541 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamFmt.iAudWaveFormatEx.Size, true)))
542 {
543 return PV_AVI_FILE_PARSER_READ_ERROR;
544 }
545 }
546 else
547 {
548 iStreamFmt.iAudWaveFormatEx.Size = 0;
549 }
550
551 }
552 else if (iStreamFmt.iType == PV_2_VIDEO)
553 {
554 iStreamFmt.iVidBitMapInfo.BmiHeader.BiSize = 0;
555 iStreamFmt.iVidBitMapInfo.BmiHeader.BiHeight = 0;
556 iStreamFmt.iVidBitMapInfo.BmiHeader.BiPlanes = 0;
557 iStreamFmt.iVidBitMapInfo.BmiHeader.BiBitCount = 0;
558 iStreamFmt.iVidBitMapInfo.BmiHeader.BiCompression = 0;
559 iStreamFmt.iVidBitMapInfo.BmiHeader.BiSizeImage = 0;
560 iStreamFmt.iVidBitMapInfo.BmiHeader.BiXPelsPerMeter = 0;
561 iStreamFmt.iVidBitMapInfo.BmiHeader.BiYPelsPerMeter = 0;
562 iStreamFmt.iVidBitMapInfo.BmiHeader.BiClrUsed = 0;
563 iStreamFmt.iVidBitMapInfo.BmiHeader.BiClrImportant = 0;
564 iStreamFmt.iVidBitMapInfo.BmiColorsCount = 0;
565 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiSize, true)))
566 {
567 return PV_AVI_FILE_PARSER_READ_ERROR;
568 }
569 bytesRead += CHUNK_SIZE;
570
571 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiWidth, true)))
572 {
573 return PV_AVI_FILE_PARSER_READ_ERROR;
574 }
575 bytesRead += CHUNK_SIZE;
576
577 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiHeight, true)))
578 {
579 return PV_AVI_FILE_PARSER_READ_ERROR;
580 }
581 bytesRead += CHUNK_SIZE;
582
583 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiPlanes, true)))
584 {
585 return PV_AVI_FILE_PARSER_READ_ERROR;
586 }
587 bytesRead += sizeof(uint16);
588
589 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read16(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiBitCount, true)))
590 {
591 return PV_AVI_FILE_PARSER_READ_ERROR;
592 }
593 bytesRead += sizeof(uint16);
594
595 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiCompression, true)))
596 {
597 return PV_AVI_FILE_PARSER_READ_ERROR;
598 }
599 bytesRead += CHUNK_SIZE;
600
601 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiSizeImage, true)))
602 {
603 return PV_AVI_FILE_PARSER_READ_ERROR;
604 }
605 bytesRead += CHUNK_SIZE;
606
607 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiXPelsPerMeter, true)))
608 {
609 return PV_AVI_FILE_PARSER_READ_ERROR;
610 }
611 bytesRead += CHUNK_SIZE;
612
613 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiYPelsPerMeter, true)))
614 {
615 return PV_AVI_FILE_PARSER_READ_ERROR;
616 }
617 bytesRead += CHUNK_SIZE;
618
619 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiClrUsed, true)))
620 {
621 return PV_AVI_FILE_PARSER_READ_ERROR;
622 }
623 bytesRead += CHUNK_SIZE;
624
625 if (PV_AVI_FILE_PARSER_SUCCESS != (PVAviFileParserUtils::read32(aFp, iStreamFmt.iVidBitMapInfo.BmiHeader.BiClrImportant, true)))
626 {
627 return PV_AVI_FILE_PARSER_READ_ERROR;
628 }
629 bytesRead += CHUNK_SIZE;
630
631 //get the color table size
632 uint32 colorTblSize = iStreamFmt.iVidBitMapInfo.BmiHeader.BiClrUsed;
633 if (colorTblSize > MAX_COLOR_TABLE_SIZE)
634 {
635 return PV_AVI_FILE_PARSER_WRONG_SIZE;
636 }
637 if (bytesRead == aHdrSize)
638 {
639 return PV_AVI_FILE_PARSER_SUCCESS;
640 }
641 else
642 {
643 if (colorTblSize == 0)
644 {
645 switch (iStreamFmt.iVidBitMapInfo.BmiHeader.BiBitCount)
646 {
647 case BIT_COUNT1:
648 {
649 colorTblSize = 2;
650 }
651 break;
652 case BIT_COUNT2:
653 {
654 colorTblSize = 4;
655 }
656 break;
657 case BIT_COUNT4:
658 {
659 colorTblSize = 16;
660 }
661 break;
662 case BIT_COUNT8:
663 {
664 colorTblSize = 256;
665 }
666 break;
667 case BIT_COUNT16:
668 case BIT_COUNT32:
669 {
670 if (BI_BITFIELDS == iStreamFmt.iVidBitMapInfo.BmiHeader.BiCompression)
671 {
672 colorTblSize = 3;
673 }
674 else if (BI_ALPHABITFIELDS == iStreamFmt.iVidBitMapInfo.BmiHeader.BiCompression)
675 {
676 colorTblSize = 4;
677 }
678 else if (BI_RGB == iStreamFmt.iVidBitMapInfo.BmiHeader.BiCompression)
679 {
680 colorTblSize = 0;
681 }
682
683 }
684 break;
685 case BIT_COUNT24:
686 {
687 colorTblSize = 0;
688 }
689 break;
690 default:
691 return PV_AVI_FILE_PARSER_WRONG_BIT_COUNT;
692 break;
693
694 } //switch
695 }
696
697 iStreamFmt.iVidBitMapInfo.BmiColorsCount = colorTblSize;
698
699 uint32 length = 1;
700 //get color table entries
701 for (uint32 ii = 0; ii < colorTblSize; ii++)
702 {
703 if (length != PVAviFileParserUtils::read8(aFp, &(iStreamFmt.iVidBitMapInfo.BmiColors[ii].Blue), length))
704 {
705 return PV_AVI_FILE_PARSER_READ_ERROR;
706 }
707 if (length != PVAviFileParserUtils::read8(aFp, &(iStreamFmt.iVidBitMapInfo.BmiColors[ii].Green), length))
708 {
709 return PV_AVI_FILE_PARSER_READ_ERROR;
710 }
711 if (length != PVAviFileParserUtils::read8(aFp, &(iStreamFmt.iVidBitMapInfo.BmiColors[ii].Red), length))
712 {
713 return PV_AVI_FILE_PARSER_READ_ERROR;
714 }
715 if (length != PVAviFileParserUtils::read8(aFp, &(iStreamFmt.iVidBitMapInfo.BmiColors[ii].Reserved), length))
716 {
717 return PV_AVI_FILE_PARSER_READ_ERROR;
718 }
719
720 }
721 } //else
722 bytesRead += colorTblSize * sizeof(RGBQuad);
723
724
725 }
726
727 if (bytesRead != aHdrSize)
728 {
729 return PV_AVI_FILE_PARSER_BYTE_COUNT_ERROR;
730 }
731
732 return PV_AVI_FILE_PARSER_SUCCESS;
733 }
734
GetStreamMimeType()735 OSCL_HeapString<OsclMemAllocator> PVAviFileStreamlist::GetStreamMimeType()
736 {
737 OSCL_HeapString<OsclMemAllocator> mime_str;
738
739 if (AUDS == iStreamHdr.iStreamTypeFCC)
740 {
741 mime_str = "audio";
742 }
743 else if (VIDS == iStreamHdr.iStreamTypeFCC)
744 {
745 mime_str = "video";
746 }
747 else if (MIDS == iStreamHdr.iStreamTypeFCC)
748 {
749 mime_str = "midi";
750 }
751 else if (TXTS == iStreamHdr.iStreamTypeFCC)
752 {
753 mime_str = "text";
754 }
755 else
756 {
757 mime_str = "unknown";
758 }
759
760 return mime_str;
761 }
762
GetHandlerType(uint8 * aHdlr,uint32 & aSize)763 bool PVAviFileStreamlist::GetHandlerType(uint8* aHdlr, uint32& aSize)
764 {
765 if (aSize < CHUNK_SIZE)
766 {
767 return false;
768 }
769
770 oscl_memcpy(aHdlr, iStreamHdr.iStreamHandler, CHUNK_SIZE);
771 aSize = CHUNK_SIZE;
772 return true;
773 }
774
GetBitsPerSample()775 uint32 PVAviFileStreamlist::GetBitsPerSample()
776 {
777 if (PV_2_AUDIO == iStreamFmt.iType)
778 {
779 return (iStreamFmt.iAudWaveFormatEx).BitsPerSample;
780 }
781 else if (PV_2_VIDEO == iStreamFmt.iType)
782
783 {
784 return (iStreamFmt.iVidBitMapInfo).BmiHeader.BiBitCount;
785 }
786 else
787 {
788 return 0;
789 }
790 }
791
GetAudioFormat()792 uint32 PVAviFileStreamlist::GetAudioFormat()
793 {
794 if (PV_2_AUDIO == iStreamFmt.iType)
795 {
796 return (iStreamFmt.iAudWaveFormatEx).FormatTag;
797 }
798 else
799 {
800 return WAVE_FORMAT_UNKNOWN;
801 }
802 }
803
GetNumAudioChannels()804 uint32 PVAviFileStreamlist::GetNumAudioChannels()
805 {
806 if (PV_2_AUDIO == iStreamFmt.iType)
807 {
808 return (iStreamFmt.iAudWaveFormatEx).Channels;
809 }
810 else
811 {
812 return 0;
813 }
814
815 }
816
GetVideoWidth()817 uint32 PVAviFileStreamlist::GetVideoWidth()
818 {
819 if (PV_2_VIDEO == iStreamFmt.iType)
820 {
821 return (iStreamFmt.iVidBitMapInfo).BmiHeader.BiWidth;
822 }
823 else
824 {
825 return 0;
826 }
827 }
828
GetVideoHeight(bool & rBottomUp)829 uint32 PVAviFileStreamlist::GetVideoHeight(bool& rBottomUp)
830 {
831 if (PV_2_VIDEO == iStreamFmt.iType)
832 {
833 int32 height = (iStreamFmt.iVidBitMapInfo).BmiHeader.BiHeight;
834 if (height < 0) //negative height
835 {
836 rBottomUp = false;
837 height = oscl_abs(height);
838 }
839 else
840 {
841 rBottomUp = true;
842 }
843
844 return ((uint32)height);
845 }
846 else
847 {
848 return 0;
849 }
850 }
851
GetFormatSpecificInfo(uint8 * & aBuff,uint32 & aSize)852 bool PVAviFileStreamlist::GetFormatSpecificInfo(uint8*& aBuff, uint32& aSize)
853 {
854 if (PV_2_AUDIO == iStreamFmt.iType)
855 {
856 aSize = sizeof(WaveFormatExStruct);
857 aBuff = OSCL_STATIC_CAST(uint8*, &(iStreamFmt.iAudWaveFormatEx));
858 }
859 else if (PV_2_VIDEO == iStreamFmt.iType)
860 {
861 aSize = sizeof(BitmapInfoHhr) + (sizeof(RGBQuad) * iStreamFmt.iVidBitMapInfo.BmiColorsCount);
862 aBuff = OSCL_STATIC_CAST(uint8*, &(iStreamFmt.iVidBitMapInfo));
863 }
864 else
865 {
866 return false;
867 }
868
869 return true;
870 }
871
GetCodecSpecificData(uint8 * & aBuff,uint32 & aSize)872 bool PVAviFileStreamlist::GetCodecSpecificData(uint8*& aBuff, uint32& aSize)
873 {
874 if (iCodecSpecificHdrDataSize > 0)
875 {
876 aBuff = ipCodecSpecificHdrData;
877 aSize = iCodecSpecificHdrDataSize;
878 }
879 else
880 {
881 return false;
882 }
883
884 return true;
885 }
886
887
888