summaryrefslogtreecommitdiff
path: root/apps/codecs/libalac/demux.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libalac/demux.c')
-rw-r--r--apps/codecs/libalac/demux.c85
1 files changed, 42 insertions, 43 deletions
diff --git a/apps/codecs/libalac/demux.c b/apps/codecs/libalac/demux.c
index 7263a763d4..634dc01ee7 100644
--- a/apps/codecs/libalac/demux.c
+++ b/apps/codecs/libalac/demux.c
@@ -32,9 +32,11 @@
32 32
33#include <string.h> 33#include <string.h>
34#include <stdio.h> 34#include <stdio.h>
35#include <stdint.h> 35#include <inttypes.h>
36#include <stdlib.h> 36#include <stdlib.h>
37 37
38#include "../codec.h"
39
38#include "stream.h" 40#include "stream.h"
39#include "demux.h" 41#include "demux.h"
40 42
@@ -56,7 +58,7 @@ static void read_chunk_ftyp(qtmovie_t *qtmovie, size_t chunk_len)
56 size_remaining-=4; 58 size_remaining-=4;
57 if (type != MAKEFOURCC('M','4','A',' ')) 59 if (type != MAKEFOURCC('M','4','A',' '))
58 { 60 {
59 fprintf(stderr, "not M4A file\n"); 61 //fprintf(stderr, "not M4A file\n");
60 return; 62 return;
61 } 63 }
62 minor_ver = stream_read_uint32(qtmovie->stream); 64 minor_ver = stream_read_uint32(qtmovie->stream);
@@ -151,7 +153,7 @@ static void read_chunk_stsd(qtmovie_t *qtmovie, size_t chunk_len)
151 153
152 if (numentries != 1) 154 if (numentries != 1)
153 { 155 {
154 fprintf(stderr, "only expecting one entry in sample description atom!\n"); 156 //fprintf(stderr, "only expecting one entry in sample description atom!\n");
155 return; 157 return;
156 } 158 }
157 159
@@ -173,8 +175,8 @@ static void read_chunk_stsd(qtmovie_t *qtmovie, size_t chunk_len)
173 entry_remaining -= 6; 175 entry_remaining -= 6;
174 176
175 version = stream_read_uint16(qtmovie->stream); 177 version = stream_read_uint16(qtmovie->stream);
176 if (version != 1) 178 // if (version != 1)
177 fprintf(stderr, "unknown version??\n"); 179 //fprintf(stderr, "unknown version??\n");
178 entry_remaining -= 2; 180 entry_remaining -= 2;
179 181
180 /* revision level */ 182 /* revision level */
@@ -245,8 +247,8 @@ static void read_chunk_stsd(qtmovie_t *qtmovie, size_t chunk_len)
245 247
246 if (qtmovie->res->format != MAKEFOURCC('a','l','a','c')) 248 if (qtmovie->res->format != MAKEFOURCC('a','l','a','c'))
247 { 249 {
248 fprintf(stderr, "expecting 'alac' data format, got %c%c%c%c\n", 250// fprintf(stderr, "expecting 'alac' data format, got %c%c%c%c\n",
249 SPLITFOURCC(qtmovie->res->format)); 251// SPLITFOURCC(qtmovie->res->format));
250 return; 252 return;
251 } 253 }
252 } 254 }
@@ -282,7 +284,7 @@ static void read_chunk_stts(qtmovie_t *qtmovie, size_t chunk_len)
282 284
283 if (size_remaining) 285 if (size_remaining)
284 { 286 {
285 fprintf(stderr, "ehm, size remianing?\n"); 287 //fprintf(stderr, "ehm, size remianing?\n");
286 stream_skip(qtmovie->stream, size_remaining); 288 stream_skip(qtmovie->stream, size_remaining);
287 } 289 }
288} 290}
@@ -305,7 +307,7 @@ static void read_chunk_stsz(qtmovie_t *qtmovie, size_t chunk_len)
305 /* default sample size */ 307 /* default sample size */
306 if (stream_read_uint32(qtmovie->stream) != 0) 308 if (stream_read_uint32(qtmovie->stream) != 0)
307 { 309 {
308 fprintf(stderr, "i was expecting variable samples sizes\n"); 310 //fprintf(stderr, "i was expecting variable samples sizes\n");
309 stream_read_uint32(qtmovie->stream); 311 stream_read_uint32(qtmovie->stream);
310 size_remaining -= 4; 312 size_remaining -= 4;
311 return; 313 return;
@@ -326,7 +328,7 @@ static void read_chunk_stsz(qtmovie_t *qtmovie, size_t chunk_len)
326 328
327 if (size_remaining) 329 if (size_remaining)
328 { 330 {
329 fprintf(stderr, "ehm, size remianing?\n"); 331 //fprintf(stderr, "ehm, size remianing?\n");
330 stream_skip(qtmovie->stream, size_remaining); 332 stream_skip(qtmovie->stream, size_remaining);
331 } 333 }
332} 334}
@@ -343,7 +345,7 @@ static void read_chunk_stbl(qtmovie_t *qtmovie, size_t chunk_len)
343 sub_chunk_len = stream_read_uint32(qtmovie->stream); 345 sub_chunk_len = stream_read_uint32(qtmovie->stream);
344 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining) 346 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining)
345 { 347 {
346 fprintf(stderr, "strange size for chunk inside stbl\n"); 348 //fprintf(stderr, "strange size for chunk inside stbl\n");
347 return; 349 return;
348 } 350 }
349 351
@@ -366,8 +368,8 @@ static void read_chunk_stbl(qtmovie_t *qtmovie, size_t chunk_len)
366 stream_skip(qtmovie->stream, sub_chunk_len - 8); 368 stream_skip(qtmovie->stream, sub_chunk_len - 8);
367 break; 369 break;
368 default: 370 default:
369 fprintf(stderr, "(stbl) unknown chunk id: %c%c%c%c\n", 371// fprintf(stderr, "(stbl) unknown chunk id: %c%c%c%c\n",
370 SPLITFOURCC(sub_chunk_id)); 372// SPLITFOURCC(sub_chunk_id));
371 return; 373 return;
372 } 374 }
373 375
@@ -383,12 +385,12 @@ static void read_chunk_minf(qtmovie_t *qtmovie, size_t chunk_len)
383 /**** SOUND HEADER CHUNK ****/ 385 /**** SOUND HEADER CHUNK ****/
384 if (stream_read_uint32(qtmovie->stream) != 16) 386 if (stream_read_uint32(qtmovie->stream) != 16)
385 { 387 {
386 fprintf(stderr, "unexpected size in media info\n"); 388 //fprintf(stderr, "unexpected size in media info\n");
387 return; 389 return;
388 } 390 }
389 if (stream_read_uint32(qtmovie->stream) != MAKEFOURCC('s','m','h','d')) 391 if (stream_read_uint32(qtmovie->stream) != MAKEFOURCC('s','m','h','d'))
390 { 392 {
391 fprintf(stderr, "not a sound header! can't handle this.\n"); 393 //fprintf(stderr, "not a sound header! can't handle this.\n");
392 return; 394 return;
393 } 395 }
394 /* now skip the rest */ 396 /* now skip the rest */
@@ -400,7 +402,7 @@ static void read_chunk_minf(qtmovie_t *qtmovie, size_t chunk_len)
400 dinf_size = stream_read_uint32(qtmovie->stream); 402 dinf_size = stream_read_uint32(qtmovie->stream);
401 if (stream_read_uint32(qtmovie->stream) != MAKEFOURCC('d','i','n','f')) 403 if (stream_read_uint32(qtmovie->stream) != MAKEFOURCC('d','i','n','f'))
402 { 404 {
403 fprintf(stderr, "expected dinf, didn't get it.\n"); 405 //fprintf(stderr, "expected dinf, didn't get it.\n");
404 return; 406 return;
405 } 407 }
406 /* skip it */ 408 /* skip it */
@@ -413,7 +415,7 @@ static void read_chunk_minf(qtmovie_t *qtmovie, size_t chunk_len)
413 stbl_size = stream_read_uint32(qtmovie->stream); 415 stbl_size = stream_read_uint32(qtmovie->stream);
414 if (stream_read_uint32(qtmovie->stream) != MAKEFOURCC('s','t','b','l')) 416 if (stream_read_uint32(qtmovie->stream) != MAKEFOURCC('s','t','b','l'))
415 { 417 {
416 fprintf(stderr, "expected stbl, didn't get it.\n"); 418 //fprintf(stderr, "expected stbl, didn't get it.\n");
417 return; 419 return;
418 } 420 }
419 read_chunk_stbl(qtmovie, stbl_size); 421 read_chunk_stbl(qtmovie, stbl_size);
@@ -421,7 +423,7 @@ static void read_chunk_minf(qtmovie_t *qtmovie, size_t chunk_len)
421 423
422 if (size_remaining) 424 if (size_remaining)
423 { 425 {
424 fprintf(stderr, "oops\n"); 426 //fprintf(stderr, "oops\n");
425 stream_skip(qtmovie->stream, size_remaining); 427 stream_skip(qtmovie->stream, size_remaining);
426 } 428 }
427} 429}
@@ -438,7 +440,7 @@ static void read_chunk_mdia(qtmovie_t *qtmovie, size_t chunk_len)
438 sub_chunk_len = stream_read_uint32(qtmovie->stream); 440 sub_chunk_len = stream_read_uint32(qtmovie->stream);
439 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining) 441 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining)
440 { 442 {
441 fprintf(stderr, "strange size for chunk inside mdia\n"); 443 //fprintf(stderr, "strange size for chunk inside mdia\n");
442 return; 444 return;
443 } 445 }
444 446
@@ -456,8 +458,8 @@ static void read_chunk_mdia(qtmovie_t *qtmovie, size_t chunk_len)
456 read_chunk_minf(qtmovie, sub_chunk_len); 458 read_chunk_minf(qtmovie, sub_chunk_len);
457 break; 459 break;
458 default: 460 default:
459 fprintf(stderr, "(mdia) unknown chunk id: %c%c%c%c\n", 461// fprintf(stderr, "(mdia) unknown chunk id: %c%c%c%c\n",
460 SPLITFOURCC(sub_chunk_id)); 462// SPLITFOURCC(sub_chunk_id));
461 return; 463 return;
462 } 464 }
463 465
@@ -478,7 +480,7 @@ static void read_chunk_trak(qtmovie_t *qtmovie, size_t chunk_len)
478 sub_chunk_len = stream_read_uint32(qtmovie->stream); 480 sub_chunk_len = stream_read_uint32(qtmovie->stream);
479 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining) 481 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining)
480 { 482 {
481 fprintf(stderr, "strange size for chunk inside trak\n"); 483 //fprintf(stderr, "strange size for chunk inside trak\n");
482 return; 484 return;
483 } 485 }
484 486
@@ -493,8 +495,8 @@ static void read_chunk_trak(qtmovie_t *qtmovie, size_t chunk_len)
493 read_chunk_mdia(qtmovie, sub_chunk_len); 495 read_chunk_mdia(qtmovie, sub_chunk_len);
494 break; 496 break;
495 default: 497 default:
496 fprintf(stderr, "(trak) unknown chunk id: %c%c%c%c\n", 498// fprintf(stderr, "(trak) unknown chunk id: %c%c%c%c\n",
497 SPLITFOURCC(sub_chunk_id)); 499// SPLITFOURCC(sub_chunk_id));
498 return; 500 return;
499 } 501 }
500 502
@@ -533,7 +535,7 @@ static void read_chunk_moov(qtmovie_t *qtmovie, size_t chunk_len)
533 sub_chunk_len = stream_read_uint32(qtmovie->stream); 535 sub_chunk_len = stream_read_uint32(qtmovie->stream);
534 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining) 536 if (sub_chunk_len <= 1 || sub_chunk_len > size_remaining)
535 { 537 {
536 fprintf(stderr, "strange size for chunk inside moov\n"); 538 //fprintf(stderr, "strange size for chunk inside moov\n");
537 return; 539 return;
538 } 540 }
539 541
@@ -551,8 +553,8 @@ static void read_chunk_moov(qtmovie_t *qtmovie, size_t chunk_len)
551 read_chunk_udta(qtmovie, sub_chunk_len); 553 read_chunk_udta(qtmovie, sub_chunk_len);
552 break; 554 break;
553 default: 555 default:
554 fprintf(stderr, "(moov) unknown chunk id: %c%c%c%c\n", 556// fprintf(stderr, "(moov) unknown chunk id: %c%c%c%c\n",
555 SPLITFOURCC(sub_chunk_id)); 557// SPLITFOURCC(sub_chunk_id));
556 return; 558 return;
557 } 559 }
558 560
@@ -574,14 +576,11 @@ static void read_chunk_mdat(qtmovie_t *qtmovie, size_t chunk_len)
574 576
575int qtmovie_read(stream_t *file, demux_res_t *demux_res) 577int qtmovie_read(stream_t *file, demux_res_t *demux_res)
576{ 578{
577 qtmovie_t *qtmovie; 579 qtmovie_t qtmovie;
578
579 qtmovie = (qtmovie_t*)malloc(sizeof(qtmovie_t));
580 580
581 /* construct the stream */ 581 /* construct the stream */
582 qtmovie->stream = file; 582 qtmovie.stream = file;
583 583 qtmovie.res = demux_res;
584 qtmovie->res = demux_res;
585 584
586 /* read the chunks */ 585 /* read the chunks */
587 while (1) 586 while (1)
@@ -589,26 +588,26 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res)
589 size_t chunk_len; 588 size_t chunk_len;
590 fourcc_t chunk_id; 589 fourcc_t chunk_id;
591 590
592 chunk_len = stream_read_uint32(qtmovie->stream); 591 chunk_len = stream_read_uint32(qtmovie.stream);
593 if (stream_eof(qtmovie->stream)) 592 if (stream_eof(qtmovie.stream))
594 { 593 {
595 return 0; 594 return 0;
596 } 595 }
597 596
598 if (chunk_len == 1) 597 if (chunk_len == 1)
599 { 598 {
600 fprintf(stderr, "need 64bit support\n"); 599 //fprintf(stderr, "need 64bit support\n");
601 return 0; 600 return 0;
602 } 601 }
603 chunk_id = stream_read_uint32(qtmovie->stream); 602 chunk_id = stream_read_uint32(qtmovie.stream);
604 603
605 switch (chunk_id) 604 switch (chunk_id)
606 { 605 {
607 case MAKEFOURCC('f','t','y','p'): 606 case MAKEFOURCC('f','t','y','p'):
608 read_chunk_ftyp(qtmovie, chunk_len); 607 read_chunk_ftyp(&qtmovie, chunk_len);
609 break; 608 break;
610 case MAKEFOURCC('m','o','o','v'): 609 case MAKEFOURCC('m','o','o','v'):
611 read_chunk_moov(qtmovie, chunk_len); 610 read_chunk_moov(&qtmovie, chunk_len);
612 break; 611 break;
613 /* once we hit mdat we stop reading and return. 612 /* once we hit mdat we stop reading and return.
614 * this is on the assumption that there is no furhter interesting 613 * this is on the assumption that there is no furhter interesting
@@ -617,16 +616,16 @@ int qtmovie_read(stream_t *file, demux_res_t *demux_res)
617 * for the decoder. And we don't want to rely on fseek/ftell, 616 * for the decoder. And we don't want to rely on fseek/ftell,
618 * as they may not always be avilable */ 617 * as they may not always be avilable */
619 case MAKEFOURCC('m','d','a','t'): 618 case MAKEFOURCC('m','d','a','t'):
620 read_chunk_mdat(qtmovie, chunk_len); 619 read_chunk_mdat(&qtmovie, chunk_len);
621 return 1; 620 return 1;
622 621
623 /* these following atoms can be skipped !!!! */ 622 /* these following atoms can be skipped !!!! */
624 case MAKEFOURCC('f','r','e','e'): 623 case MAKEFOURCC('f','r','e','e'):
625 stream_skip(qtmovie->stream, chunk_len - 8); /* FIXME not 8 */ 624 stream_skip(qtmovie.stream, chunk_len - 8); /* FIXME not 8 */
626 break; 625 break;
627 default: 626 default:
628 fprintf(stderr, "(top) unknown chunk id: %c%c%c%c\n", 627// fprintf(stderr, "(top) unknown chunk id: %c%c%c%c\n",
629 SPLITFOURCC(chunk_id)); 628// SPLITFOURCC(chunk_id));
630 return 0; 629 return 0;
631 } 630 }
632 631