diff options
Diffstat (limited to 'apps/codecs/libm4a/demux.c')
-rw-r--r-- | apps/codecs/libm4a/demux.c | 155 |
1 files changed, 96 insertions, 59 deletions
diff --git a/apps/codecs/libm4a/demux.c b/apps/codecs/libm4a/demux.c index 1beeced8e6..44261fdef6 100644 --- a/apps/codecs/libm4a/demux.c +++ b/apps/codecs/libm4a/demux.c | |||
@@ -55,12 +55,14 @@ static void read_chunk_ftyp(qtmovie_t *qtmovie, size_t chunk_len) | |||
55 | { | 55 | { |
56 | fourcc_t type; | 56 | fourcc_t type; |
57 | uint32_t minor_ver; | 57 | uint32_t minor_ver; |
58 | size_t size_remaining = chunk_len - 8; /* FIXME: can't hardcode 8, size may be 64bit */ | 58 | size_t size_remaining = chunk_len - 8; |
59 | 59 | ||
60 | type = stream_read_uint32(qtmovie->stream); | 60 | type = stream_read_uint32(qtmovie->stream); |
61 | size_remaining-=4; | 61 | size_remaining-=4; |
62 | if ((type != MAKEFOURCC('M','4','A',' ')) && | 62 | if ((type != MAKEFOURCC('M','4','A',' ')) && |
63 | (type != MAKEFOURCC('m','p','4','2'))) | 63 | (type != MAKEFOURCC('m','p','4','2')) && |
64 | (type != MAKEFOURCC('3','g','p','6')) && | ||
65 | (type != MAKEFOURCC('q','t',' ',' '))) | ||
64 | { | 66 | { |
65 | DEBUGF("not M4A file\n"); | 67 | DEBUGF("not M4A file\n"); |
66 | return; | 68 | return; |
@@ -80,7 +82,7 @@ static void read_chunk_ftyp(qtmovie_t *qtmovie, size_t chunk_len) | |||
80 | static void read_chunk_tkhd(qtmovie_t *qtmovie, size_t chunk_len) | 82 | static void read_chunk_tkhd(qtmovie_t *qtmovie, size_t chunk_len) |
81 | { | 83 | { |
82 | /* don't need anything from here atm, skip */ | 84 | /* don't need anything from here atm, skip */ |
83 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 85 | size_t size_remaining = chunk_len - 8; |
84 | 86 | ||
85 | stream_skip(qtmovie->stream, size_remaining); | 87 | stream_skip(qtmovie->stream, size_remaining); |
86 | } | 88 | } |
@@ -88,7 +90,7 @@ static void read_chunk_tkhd(qtmovie_t *qtmovie, size_t chunk_len) | |||
88 | static void read_chunk_mdhd(qtmovie_t *qtmovie, size_t chunk_len) | 90 | static void read_chunk_mdhd(qtmovie_t *qtmovie, size_t chunk_len) |
89 | { | 91 | { |
90 | /* don't need anything from here atm, skip */ | 92 | /* don't need anything from here atm, skip */ |
91 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 93 | size_t size_remaining = chunk_len - 8; |
92 | 94 | ||
93 | stream_skip(qtmovie->stream, size_remaining); | 95 | stream_skip(qtmovie->stream, size_remaining); |
94 | } | 96 | } |
@@ -97,7 +99,7 @@ static void read_chunk_mdhd(qtmovie_t *qtmovie, size_t chunk_len) | |||
97 | static void read_chunk_hdlr(qtmovie_t *qtmovie, size_t chunk_len) | 99 | static void read_chunk_hdlr(qtmovie_t *qtmovie, size_t chunk_len) |
98 | { | 100 | { |
99 | fourcc_t comptype, compsubtype; | 101 | fourcc_t comptype, compsubtype; |
100 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 102 | size_t size_remaining = chunk_len - 8; |
101 | 103 | ||
102 | int strlen; | 104 | int strlen; |
103 | char str[256] = {0}; | 105 | char str[256] = {0}; |
@@ -196,7 +198,6 @@ static bool read_chunk_esds(qtmovie_t *qtmovie, size_t chunk_len) | |||
196 | temp=stream_read_int32(qtmovie->stream);//0x15000414 ???? | 198 | temp=stream_read_int32(qtmovie->stream);//0x15000414 ???? |
197 | maxBitrate = stream_read_int32(qtmovie->stream); | 199 | maxBitrate = stream_read_int32(qtmovie->stream); |
198 | avgBitrate = stream_read_int32(qtmovie->stream); | 200 | avgBitrate = stream_read_int32(qtmovie->stream); |
199 | |||
200 | DEBUGF("audioType=%d, maxBitrate=%d, avgBitrate=%d\n",audioType,maxBitrate,avgBitrate); | 201 | DEBUGF("audioType=%d, maxBitrate=%d, avgBitrate=%d\n",audioType,maxBitrate,avgBitrate); |
201 | 202 | ||
202 | /* get and verify DecSpecificInfoTag */ | 203 | /* get and verify DecSpecificInfoTag */ |
@@ -224,7 +225,7 @@ static bool read_chunk_stsd(qtmovie_t *qtmovie, size_t chunk_len) | |||
224 | unsigned int i; | 225 | unsigned int i; |
225 | int j; | 226 | int j; |
226 | uint32_t numentries; | 227 | uint32_t numentries; |
227 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 228 | size_t size_remaining = chunk_len - 8; |
228 | 229 | ||
229 | /* version */ | 230 | /* version */ |
230 | stream_read_uint8(qtmovie->stream); | 231 | stream_read_uint8(qtmovie->stream); |
@@ -247,7 +248,6 @@ static bool read_chunk_stsd(qtmovie_t *qtmovie, size_t chunk_len) | |||
247 | for (i = 0; i < numentries; i++) | 248 | for (i = 0; i < numentries; i++) |
248 | { | 249 | { |
249 | uint32_t entry_size; | 250 | uint32_t entry_size; |
250 | uint16_t version; | ||
251 | 251 | ||
252 | uint32_t entry_remaining; | 252 | uint32_t entry_remaining; |
253 | 253 | ||
@@ -259,43 +259,20 @@ static bool read_chunk_stsd(qtmovie_t *qtmovie, size_t chunk_len) | |||
259 | 259 | ||
260 | /* sound info: */ | 260 | /* sound info: */ |
261 | 261 | ||
262 | stream_skip(qtmovie->stream, 6); /* reserved */ | 262 | /* reserved + data reference index + sound version + reserved */ |
263 | entry_remaining -= 6; | 263 | stream_skip(qtmovie->stream, 6 + 2 + 2 + 6); |
264 | 264 | entry_remaining -= 6 + 2 + 2 + 6; | |
265 | version = stream_read_uint16(qtmovie->stream); | ||
266 | // if (version != 1) | ||
267 | //fprintf(stderr, "unknown version??\n"); | ||
268 | entry_remaining -= 2; | ||
269 | |||
270 | /* revision level */ | ||
271 | stream_read_uint16(qtmovie->stream); | ||
272 | /* vendor */ | ||
273 | stream_read_uint32(qtmovie->stream); | ||
274 | entry_remaining -= 6; | ||
275 | |||
276 | /* EH?? spec doesn't say theres an extra 16 bits here.. but there is! */ | ||
277 | stream_read_uint16(qtmovie->stream); | ||
278 | entry_remaining -= 2; | ||
279 | 265 | ||
280 | qtmovie->res->num_channels = stream_read_uint16(qtmovie->stream); | 266 | qtmovie->res->num_channels = stream_read_uint16(qtmovie->stream); |
281 | 267 | qtmovie->res->sound_sample_size = stream_read_uint16(qtmovie->stream); | |
282 | qtmovie->res->sample_size = stream_read_uint16(qtmovie->stream); | ||
283 | entry_remaining -= 4; | 268 | entry_remaining -= 4; |
284 | 269 | ||
285 | /* compression id */ | ||
286 | stream_read_uint16(qtmovie->stream); | ||
287 | /* packet size */ | 270 | /* packet size */ |
288 | stream_read_uint16(qtmovie->stream); | ||
289 | entry_remaining -= 4; | ||
290 | |||
291 | /* sample rate - 32bit fixed point = 16bit?? */ | ||
292 | qtmovie->res->sample_rate = stream_read_uint16(qtmovie->stream); | ||
293 | entry_remaining -= 2; | ||
294 | |||
295 | /* skip 2 */ | ||
296 | stream_skip(qtmovie->stream, 2); | 271 | stream_skip(qtmovie->stream, 2); |
297 | entry_remaining -= 2; | 272 | qtmovie->res->sound_sample_rate = stream_read_uint32(qtmovie->stream); |
298 | 273 | /* reserved size */ | |
274 | stream_skip(qtmovie->stream, 2); | ||
275 | entry_remaining -= 8; | ||
299 | 276 | ||
300 | /* remaining is codec data */ | 277 | /* remaining is codec data */ |
301 | 278 | ||
@@ -372,7 +349,7 @@ static void read_chunk_stts(qtmovie_t *qtmovie, size_t chunk_len) | |||
372 | { | 349 | { |
373 | unsigned int i; | 350 | unsigned int i; |
374 | uint32_t numentries; | 351 | uint32_t numentries; |
375 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 352 | size_t size_remaining = chunk_len - 8; |
376 | 353 | ||
377 | /* version */ | 354 | /* version */ |
378 | stream_read_uint8(qtmovie->stream); | 355 | stream_read_uint8(qtmovie->stream); |
@@ -407,7 +384,7 @@ static void read_chunk_stsz(qtmovie_t *qtmovie, size_t chunk_len) | |||
407 | { | 384 | { |
408 | unsigned int i; | 385 | unsigned int i; |
409 | uint32_t numentries; | 386 | uint32_t numentries; |
410 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 387 | size_t size_remaining = chunk_len - 8; |
411 | 388 | ||
412 | /* version */ | 389 | /* version */ |
413 | stream_read_uint8(qtmovie->stream); | 390 | stream_read_uint8(qtmovie->stream); |
@@ -447,9 +424,73 @@ static void read_chunk_stsz(qtmovie_t *qtmovie, size_t chunk_len) | |||
447 | } | 424 | } |
448 | } | 425 | } |
449 | 426 | ||
427 | static void read_chunk_stsc(qtmovie_t *qtmovie, size_t chunk_len) | ||
428 | { | ||
429 | unsigned int i; | ||
430 | uint32_t numentries; | ||
431 | size_t size_remaining = chunk_len - 8; | ||
432 | |||
433 | /* version + flags */ | ||
434 | stream_read_uint32(qtmovie->stream); | ||
435 | size_remaining -= 4; | ||
436 | |||
437 | numentries = stream_read_uint32(qtmovie->stream); | ||
438 | size_remaining -= 4; | ||
439 | |||
440 | qtmovie->res->num_sample_to_chunks = numentries; | ||
441 | qtmovie->res->sample_to_chunk = malloc(numentries * | ||
442 | sizeof(*qtmovie->res->sample_to_chunk)); | ||
443 | |||
444 | for (i = 0; i < numentries; i++) | ||
445 | { | ||
446 | qtmovie->res->sample_to_chunk[i].first_chunk = | ||
447 | stream_read_uint32(qtmovie->stream); | ||
448 | qtmovie->res->sample_to_chunk[i].num_samples = | ||
449 | stream_read_uint32(qtmovie->stream); | ||
450 | stream_read_uint32(qtmovie->stream); | ||
451 | size_remaining -= 12; | ||
452 | } | ||
453 | |||
454 | if (size_remaining) | ||
455 | { | ||
456 | DEBUGF("ehm, size remianing?\n"); | ||
457 | stream_skip(qtmovie->stream, size_remaining); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | static void read_chunk_stco(qtmovie_t *qtmovie, size_t chunk_len) | ||
462 | { | ||
463 | unsigned int i; | ||
464 | uint32_t numentries; | ||
465 | size_t size_remaining = chunk_len - 8; | ||
466 | |||
467 | /* version + flags */ | ||
468 | stream_read_uint32(qtmovie->stream); | ||
469 | size_remaining -= 4; | ||
470 | |||
471 | numentries = stream_read_uint32(qtmovie->stream); | ||
472 | size_remaining -= 4; | ||
473 | |||
474 | qtmovie->res->num_chunk_offsets = numentries; | ||
475 | qtmovie->res->chunk_offset = malloc(numentries * | ||
476 | sizeof(*qtmovie->res->chunk_offset)); | ||
477 | |||
478 | for (i = 0; i < numentries; i++) | ||
479 | { | ||
480 | qtmovie->res->chunk_offset[i] = stream_read_uint32(qtmovie->stream); | ||
481 | size_remaining -= 4; | ||
482 | } | ||
483 | |||
484 | if (size_remaining) | ||
485 | { | ||
486 | DEBUGF("ehm, size remianing?\n"); | ||
487 | stream_skip(qtmovie->stream, size_remaining); | ||
488 | } | ||
489 | } | ||
490 | |||
450 | static bool read_chunk_stbl(qtmovie_t *qtmovie, size_t chunk_len) | 491 | static bool read_chunk_stbl(qtmovie_t *qtmovie, size_t chunk_len) |
451 | { | 492 | { |
452 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 493 | size_t size_remaining = chunk_len - 8; |
453 | 494 | ||
454 | while (size_remaining) | 495 | while (size_remaining) |
455 | { | 496 | { |
@@ -479,14 +520,15 @@ static bool read_chunk_stbl(qtmovie_t *qtmovie, size_t chunk_len) | |||
479 | read_chunk_stsz(qtmovie, sub_chunk_len); | 520 | read_chunk_stsz(qtmovie, sub_chunk_len); |
480 | break; | 521 | break; |
481 | case MAKEFOURCC('s','t','s','c'): | 522 | case MAKEFOURCC('s','t','s','c'): |
523 | read_chunk_stsc(qtmovie, sub_chunk_len); | ||
524 | break; | ||
482 | case MAKEFOURCC('s','t','c','o'): | 525 | case MAKEFOURCC('s','t','c','o'): |
483 | /* skip these, no indexing for us! */ | 526 | read_chunk_stco(qtmovie, sub_chunk_len); |
484 | stream_skip(qtmovie->stream, sub_chunk_len - 8); | ||
485 | break; | 527 | break; |
486 | default: | 528 | default: |
487 | DEBUGF("(stbl) unknown chunk id: %c%c%c%c\n", | 529 | DEBUGF("(stbl) unknown chunk id: %c%c%c%c\n", |
488 | SPLITFOURCC(sub_chunk_id)); | 530 | SPLITFOURCC(sub_chunk_id)); |
489 | stream_skip(qtmovie->stream, sub_chunk_len - 8); /* FIXME not 8 */ | 531 | stream_skip(qtmovie->stream, sub_chunk_len - 8); |
490 | } | 532 | } |
491 | 533 | ||
492 | size_remaining -= sub_chunk_len; | 534 | size_remaining -= sub_chunk_len; |
@@ -497,7 +539,7 @@ static bool read_chunk_stbl(qtmovie_t *qtmovie, size_t chunk_len) | |||
497 | static bool read_chunk_minf(qtmovie_t *qtmovie, size_t chunk_len) | 539 | static bool read_chunk_minf(qtmovie_t *qtmovie, size_t chunk_len) |
498 | { | 540 | { |
499 | size_t dinf_size, stbl_size; | 541 | size_t dinf_size, stbl_size; |
500 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 542 | size_t size_remaining = chunk_len - 8; |
501 | uint32_t i; | 543 | uint32_t i; |
502 | 544 | ||
503 | /**** SOUND HEADER CHUNK ****/ | 545 | /**** SOUND HEADER CHUNK ****/ |
@@ -553,7 +595,7 @@ static bool read_chunk_minf(qtmovie_t *qtmovie, size_t chunk_len) | |||
553 | 595 | ||
554 | static bool read_chunk_mdia(qtmovie_t *qtmovie, size_t chunk_len) | 596 | static bool read_chunk_mdia(qtmovie_t *qtmovie, size_t chunk_len) |
555 | { | 597 | { |
556 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 598 | size_t size_remaining = chunk_len - 8; |
557 | 599 | ||
558 | while (size_remaining) | 600 | while (size_remaining) |
559 | { | 601 | { |
@@ -597,7 +639,7 @@ static bool read_chunk_mdia(qtmovie_t *qtmovie, size_t chunk_len) | |||
597 | /* 'trak' - a movie track - contains other atoms */ | 639 | /* 'trak' - a movie track - contains other atoms */ |
598 | static bool read_chunk_trak(qtmovie_t *qtmovie, size_t chunk_len) | 640 | static bool read_chunk_trak(qtmovie_t *qtmovie, size_t chunk_len) |
599 | { | 641 | { |
600 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 642 | size_t size_remaining = chunk_len - 8; |
601 | 643 | ||
602 | while (size_remaining) | 644 | while (size_remaining) |
603 | { | 645 | { |
@@ -639,7 +681,7 @@ static bool read_chunk_trak(qtmovie_t *qtmovie, size_t chunk_len) | |||
639 | static void read_chunk_mvhd(qtmovie_t *qtmovie, size_t chunk_len) | 681 | static void read_chunk_mvhd(qtmovie_t *qtmovie, size_t chunk_len) |
640 | { | 682 | { |
641 | /* don't need anything from here atm, skip */ | 683 | /* don't need anything from here atm, skip */ |
642 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 684 | size_t size_remaining = chunk_len - 8; |
643 | 685 | ||
644 | stream_skip(qtmovie->stream, size_remaining); | 686 | stream_skip(qtmovie->stream, size_remaining); |
645 | } | 687 | } |
@@ -648,7 +690,7 @@ static void read_chunk_mvhd(qtmovie_t *qtmovie, size_t chunk_len) | |||
648 | static void read_chunk_udta(qtmovie_t *qtmovie, size_t chunk_len) | 690 | static void read_chunk_udta(qtmovie_t *qtmovie, size_t chunk_len) |
649 | { | 691 | { |
650 | /* don't need anything from here atm, skip */ | 692 | /* don't need anything from here atm, skip */ |
651 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 693 | size_t size_remaining = chunk_len - 8; |
652 | 694 | ||
653 | stream_skip(qtmovie->stream, size_remaining); | 695 | stream_skip(qtmovie->stream, size_remaining); |
654 | } | 696 | } |
@@ -656,7 +698,7 @@ static void read_chunk_udta(qtmovie_t *qtmovie, size_t chunk_len) | |||
656 | /* 'moov' movie atom - contains other atoms */ | 698 | /* 'moov' movie atom - contains other atoms */ |
657 | static bool read_chunk_moov(qtmovie_t *qtmovie, size_t chunk_len) | 699 | static bool read_chunk_moov(qtmovie_t *qtmovie, size_t chunk_len) |
658 | { | 700 | { |
659 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 701 | size_t size_remaining = chunk_len - 8; |
660 | 702 | ||
661 | while (size_remaining) | 703 | while (size_remaining) |
662 | { | 704 | { |
@@ -688,7 +730,7 @@ static bool read_chunk_moov(qtmovie_t *qtmovie, size_t chunk_len) | |||
688 | default: | 730 | default: |
689 | DEBUGF("(moov) unknown chunk id: %c%c%c%c\n", | 731 | DEBUGF("(moov) unknown chunk id: %c%c%c%c\n", |
690 | SPLITFOURCC(sub_chunk_id)); | 732 | SPLITFOURCC(sub_chunk_id)); |
691 | stream_skip(qtmovie->stream, sub_chunk_len - 8); /* FIXME not 8 */ | 733 | stream_skip(qtmovie->stream, sub_chunk_len - 8); |
692 | } | 734 | } |
693 | 735 | ||
694 | size_remaining -= sub_chunk_len; | 736 | size_remaining -= sub_chunk_len; |
@@ -698,14 +740,9 @@ static bool read_chunk_moov(qtmovie_t *qtmovie, size_t chunk_len) | |||
698 | 740 | ||
699 | static void read_chunk_mdat(qtmovie_t *qtmovie, size_t chunk_len) | 741 | static void read_chunk_mdat(qtmovie_t *qtmovie, size_t chunk_len) |
700 | { | 742 | { |
701 | size_t size_remaining = chunk_len - 8; /* FIXME WRONG */ | 743 | size_t size_remaining = chunk_len - 8; |
702 | 744 | ||
703 | qtmovie->res->mdat_len = size_remaining; | 745 | qtmovie->res->mdat_len = size_remaining; |
704 | #if 0 | ||
705 | qtmovie->res->mdat = malloc(size_remaining); | ||
706 | |||
707 | stream_read(qtmovie->stream, size_remaining, qtmovie->res->mdat); | ||
708 | #endif | ||
709 | } | 746 | } |
710 | 747 | ||
711 | int qtmovie_read(stream_t *file, demux_res_t *demux_res) | 748 | int qtmovie_read(stream_t *file, demux_res_t *demux_res) |
@@ -760,7 +797,7 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res) | |||
760 | 797 | ||
761 | /* these following atoms can be skipped !!!! */ | 798 | /* these following atoms can be skipped !!!! */ |
762 | case MAKEFOURCC('f','r','e','e'): | 799 | case MAKEFOURCC('f','r','e','e'): |
763 | stream_skip(qtmovie.stream, chunk_len - 8); /* FIXME not 8 */ | 800 | stream_skip(qtmovie.stream, chunk_len - 8); |
764 | break; | 801 | break; |
765 | default: | 802 | default: |
766 | //DEBUGF("(top) unknown chunk id: %c%c%c%c\n",SPLITFOURCC(chunk_id)); | 803 | //DEBUGF("(top) unknown chunk id: %c%c%c%c\n",SPLITFOURCC(chunk_id)); |