Mercurial > libavcodec.hg
comparison parser.c @ 4855:40f3a7f2b1fd libavcodec
Move AC3 header parsing code together with the rest of the AC3 parsing code.
| author | diego |
|---|---|
| date | Sun, 15 Apr 2007 12:32:36 +0000 |
| parents | 841ecebff8c8 |
| children | 5fc99f2a111b |
comparison
equal
deleted
inserted
replaced
| 4854:9f1c90ce5d9d | 4855:40f3a7f2b1fd |
|---|---|
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 */ | 21 */ |
| 22 #include "avcodec.h" | 22 #include "avcodec.h" |
| 23 #include "mpegvideo.h" | 23 #include "mpegvideo.h" |
| 24 #include "mpegaudio.h" | 24 #include "mpegaudio.h" |
| 25 #include "ac3.h" | |
| 26 #include "parser.h" | 25 #include "parser.h" |
| 27 | 26 |
| 28 AVCodecParser *av_first_parser = NULL; | 27 AVCodecParser *av_first_parser = NULL; |
| 29 | 28 |
| 30 void av_register_codec_parser(AVCodecParser *parser) | 29 void av_register_codec_parser(AVCodecParser *parser) |
| 603 0, 1, 2, 3, 4, 5, 6, 8 | 602 0, 1, 2, 3, 4, 5, 6, 8 |
| 604 }; | 603 }; |
| 605 #endif | 604 #endif |
| 606 | 605 |
| 607 #ifdef CONFIG_AC3_PARSER | 606 #ifdef CONFIG_AC3_PARSER |
| 607 int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr) | |
| 608 { | |
| 609 GetBitContext gbc; | |
| 610 | |
| 611 memset(hdr, 0, sizeof(*hdr)); | |
| 612 | |
| 613 init_get_bits(&gbc, buf, 54); | |
| 614 | |
| 615 hdr->sync_word = get_bits(&gbc, 16); | |
| 616 if(hdr->sync_word != 0x0B77) | |
| 617 return -1; | |
| 618 | |
| 619 /* read ahead to bsid to make sure this is AC-3, not E-AC-3 */ | |
| 620 hdr->bsid = show_bits_long(&gbc, 29) & 0x1F; | |
| 621 if(hdr->bsid > 10) | |
| 622 return -2; | |
| 623 | |
| 624 hdr->crc1 = get_bits(&gbc, 16); | |
| 625 hdr->fscod = get_bits(&gbc, 2); | |
| 626 if(hdr->fscod == 3) | |
| 627 return -3; | |
| 628 | |
| 629 hdr->frmsizecod = get_bits(&gbc, 6); | |
| 630 if(hdr->frmsizecod > 37) | |
| 631 return -4; | |
| 632 | |
| 633 skip_bits(&gbc, 5); // skip bsid, already got it | |
| 634 | |
| 635 hdr->bsmod = get_bits(&gbc, 3); | |
| 636 hdr->acmod = get_bits(&gbc, 3); | |
| 637 if((hdr->acmod & 1) && hdr->acmod != 1) { | |
| 638 hdr->cmixlev = get_bits(&gbc, 2); | |
| 639 } | |
| 640 if(hdr->acmod & 4) { | |
| 641 hdr->surmixlev = get_bits(&gbc, 2); | |
| 642 } | |
| 643 if(hdr->acmod == 2) { | |
| 644 hdr->dsurmod = get_bits(&gbc, 2); | |
| 645 } | |
| 646 hdr->lfeon = get_bits1(&gbc); | |
| 647 | |
| 648 hdr->halfratecod = FFMAX(hdr->bsid, 8) - 8; | |
| 649 hdr->sample_rate = ff_ac3_freqs[hdr->fscod] >> hdr->halfratecod; | |
| 650 hdr->bit_rate = (ff_ac3_bitratetab[hdr->frmsizecod>>1] * 1000) >> hdr->halfratecod; | |
| 651 hdr->channels = ff_ac3_channels[hdr->acmod] + hdr->lfeon; | |
| 652 hdr->frame_size = ff_ac3_frame_sizes[hdr->frmsizecod][hdr->fscod] * 2; | |
| 653 | |
| 654 return 0; | |
| 655 } | |
| 656 | |
| 608 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, | 657 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, |
| 609 int *bit_rate, int *samples) | 658 int *bit_rate, int *samples) |
| 610 { | 659 { |
| 611 int err; | 660 int err; |
| 612 unsigned int fscod, acmod, bsid, lfeon; | 661 unsigned int fscod, acmod, bsid, lfeon; |
