Mercurial > libavcodec.hg
comparison parser.c @ 4648:5683b496ffbc libavcodec
move AC-3 header parsing to ac3.c
| author | jbr |
|---|---|
| date | Sun, 11 Mar 2007 16:44:14 +0000 |
| parents | 056127e5df89 |
| children | 6679d37a3338 |
comparison
equal
deleted
inserted
replaced
| 4647:255affa5bae7 | 4648:5683b496ffbc |
|---|---|
| 602 | 602 |
| 603 #ifdef CONFIG_AC3_PARSER | 603 #ifdef CONFIG_AC3_PARSER |
| 604 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, | 604 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, |
| 605 int *bit_rate, int *samples) | 605 int *bit_rate, int *samples) |
| 606 { | 606 { |
| 607 unsigned int fscod, frmsizecod, acmod, bsid, lfeon, halfratecod; | 607 int err; |
| 608 unsigned int fscod, acmod, bsid, lfeon; | |
| 608 unsigned int strmtyp, substreamid, frmsiz, fscod2, numblkscod; | 609 unsigned int strmtyp, substreamid, frmsiz, fscod2, numblkscod; |
| 609 GetBitContext bits; | 610 GetBitContext bits; |
| 610 | 611 AC3HeaderInfo hdr; |
| 611 init_get_bits(&bits, buf, AC3_HEADER_SIZE * 8); | 612 |
| 612 | 613 err = ff_ac3_parse_header(buf, &hdr); |
| 613 if(get_bits(&bits, 16) != 0x0b77) | 614 |
| 615 if(err < 0 && err != -2) | |
| 614 return 0; | 616 return 0; |
| 615 | 617 |
| 616 bsid = show_bits_long(&bits, 29) & 0x1f; | 618 bsid = hdr.bsid; |
| 617 if(bsid <= 10) { /* Normal AC-3 */ | 619 if(bsid <= 10) { /* Normal AC-3 */ |
| 618 skip_bits(&bits, 16); /* crc */ | 620 *sample_rate = hdr.sample_rate; |
| 619 fscod = get_bits(&bits, 2); | 621 *bit_rate = hdr.bit_rate; |
| 620 frmsizecod = get_bits(&bits, 6); | 622 *channels = hdr.channels; |
| 621 | 623 *samples = AC3_FRAME_SIZE; |
| 622 if(fscod == 3 && frmsizecod > 37) | 624 return hdr.frame_size; |
| 623 return 0; | |
| 624 | |
| 625 skip_bits(&bits, 5); /* bsid */ | |
| 626 skip_bits(&bits, 3); /* bsmod */ | |
| 627 acmod = get_bits(&bits, 3); | |
| 628 if(acmod & 1 && acmod != 1) | |
| 629 skip_bits(&bits, 2); /* cmixlev */ | |
| 630 if(acmod & 4) | |
| 631 skip_bits(&bits, 2); /* surmixlev */ | |
| 632 if(acmod & 2) | |
| 633 skip_bits(&bits, 2); /* dsurmod */ | |
| 634 lfeon = get_bits1(&bits); | |
| 635 | |
| 636 halfratecod = FFMAX(bsid, 8) - 8; | |
| 637 *sample_rate = ff_ac3_freqs[fscod] >> halfratecod; | |
| 638 *bit_rate = (ff_ac3_bitratetab[frmsizecod] * 1000) >> halfratecod; | |
| 639 *channels = ff_ac3_channels[acmod] + lfeon; | |
| 640 *samples = 6 * 256; | |
| 641 | |
| 642 return ff_ac3_frame_sizes[frmsizecod][fscod] * 2; | |
| 643 } else if (bsid > 10 && bsid <= 16) { /* Enhanced AC-3 */ | 625 } else if (bsid > 10 && bsid <= 16) { /* Enhanced AC-3 */ |
| 626 init_get_bits(&bits, &buf[2], (AC3_HEADER_SIZE-2) * 8); | |
| 644 strmtyp = get_bits(&bits, 2); | 627 strmtyp = get_bits(&bits, 2); |
| 645 substreamid = get_bits(&bits, 3); | 628 substreamid = get_bits(&bits, 3); |
| 646 | 629 |
| 647 if (strmtyp != 0 || substreamid != 0) | 630 if (strmtyp != 0 || substreamid != 0) |
| 648 return 0; /* Currently don't support additional streams */ | 631 return 0; /* Currently don't support additional streams */ |
