comparison parser.c @ 4645:056127e5df89 libavcodec

remove redundancy in AC-3 parser by using common tables from ac3tab.h
author jbr
date Sun, 11 Mar 2007 02:13:05 +0000
parents 665d7cd95fd3
children 5683b496ffbc
comparison
equal deleted inserted replaced
4644:414d484f6483 4645:056127e5df89
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"
25 #include "parser.h" 26 #include "parser.h"
26 27
27 AVCodecParser *av_first_parser = NULL; 28 AVCodecParser *av_first_parser = NULL;
28 29
29 void av_register_codec_parser(AVCodecParser *parser) 30 void av_register_codec_parser(AVCodecParser *parser)
579 580
580 #define AC3_HEADER_SIZE 7 581 #define AC3_HEADER_SIZE 7
581 #define AAC_HEADER_SIZE 7 582 #define AAC_HEADER_SIZE 7
582 583
583 #ifdef CONFIG_AC3_PARSER 584 #ifdef CONFIG_AC3_PARSER
584 static const int ac3_sample_rates[4] = {
585 48000, 44100, 32000, 0
586 };
587
588 static const int ac3_frame_sizes[64][3] = {
589 { 64, 69, 96 },
590 { 64, 70, 96 },
591 { 80, 87, 120 },
592 { 80, 88, 120 },
593 { 96, 104, 144 },
594 { 96, 105, 144 },
595 { 112, 121, 168 },
596 { 112, 122, 168 },
597 { 128, 139, 192 },
598 { 128, 140, 192 },
599 { 160, 174, 240 },
600 { 160, 175, 240 },
601 { 192, 208, 288 },
602 { 192, 209, 288 },
603 { 224, 243, 336 },
604 { 224, 244, 336 },
605 { 256, 278, 384 },
606 { 256, 279, 384 },
607 { 320, 348, 480 },
608 { 320, 349, 480 },
609 { 384, 417, 576 },
610 { 384, 418, 576 },
611 { 448, 487, 672 },
612 { 448, 488, 672 },
613 { 512, 557, 768 },
614 { 512, 558, 768 },
615 { 640, 696, 960 },
616 { 640, 697, 960 },
617 { 768, 835, 1152 },
618 { 768, 836, 1152 },
619 { 896, 975, 1344 },
620 { 896, 976, 1344 },
621 { 1024, 1114, 1536 },
622 { 1024, 1115, 1536 },
623 { 1152, 1253, 1728 },
624 { 1152, 1254, 1728 },
625 { 1280, 1393, 1920 },
626 { 1280, 1394, 1920 },
627 };
628
629 static const int ac3_bitrates[64] = {
630 32, 32, 40, 40, 48, 48, 56, 56, 64, 64, 80, 80, 96, 96, 112, 112,
631 128, 128, 160, 160, 192, 192, 224, 224, 256, 256, 320, 320, 384,
632 384, 448, 448, 512, 512, 576, 576, 640, 640,
633 };
634
635 static const uint8_t ac3_channels[8] = {
636 2, 1, 2, 3, 3, 4, 4, 5
637 };
638 585
639 static const uint8_t eac3_blocks[4] = { 586 static const uint8_t eac3_blocks[4] = {
640 1, 2, 3, 6 587 1, 2, 3, 6
641 }; 588 };
642 589
670 if(bsid <= 10) { /* Normal AC-3 */ 617 if(bsid <= 10) { /* Normal AC-3 */
671 skip_bits(&bits, 16); /* crc */ 618 skip_bits(&bits, 16); /* crc */
672 fscod = get_bits(&bits, 2); 619 fscod = get_bits(&bits, 2);
673 frmsizecod = get_bits(&bits, 6); 620 frmsizecod = get_bits(&bits, 6);
674 621
675 if(fscod == 3) 622 if(fscod == 3 && frmsizecod > 37)
676 return 0; 623 return 0;
677 624
678 skip_bits(&bits, 5); /* bsid */ 625 skip_bits(&bits, 5); /* bsid */
679 skip_bits(&bits, 3); /* bsmod */ 626 skip_bits(&bits, 3); /* bsmod */
680 acmod = get_bits(&bits, 3); 627 acmod = get_bits(&bits, 3);
685 if(acmod & 2) 632 if(acmod & 2)
686 skip_bits(&bits, 2); /* dsurmod */ 633 skip_bits(&bits, 2); /* dsurmod */
687 lfeon = get_bits1(&bits); 634 lfeon = get_bits1(&bits);
688 635
689 halfratecod = FFMAX(bsid, 8) - 8; 636 halfratecod = FFMAX(bsid, 8) - 8;
690 *sample_rate = ac3_sample_rates[fscod] >> halfratecod; 637 *sample_rate = ff_ac3_freqs[fscod] >> halfratecod;
691 *bit_rate = (ac3_bitrates[frmsizecod] * 1000) >> halfratecod; 638 *bit_rate = (ff_ac3_bitratetab[frmsizecod] * 1000) >> halfratecod;
692 *channels = ac3_channels[acmod] + lfeon; 639 *channels = ff_ac3_channels[acmod] + lfeon;
693 *samples = 6 * 256; 640 *samples = 6 * 256;
694 641
695 return ac3_frame_sizes[frmsizecod][fscod] * 2; 642 return ff_ac3_frame_sizes[frmsizecod][fscod] * 2;
696 } else if (bsid > 10 && bsid <= 16) { /* Enhanced AC-3 */ 643 } else if (bsid > 10 && bsid <= 16) { /* Enhanced AC-3 */
697 strmtyp = get_bits(&bits, 2); 644 strmtyp = get_bits(&bits, 2);
698 substreamid = get_bits(&bits, 3); 645 substreamid = get_bits(&bits, 3);
699 646
700 if (strmtyp != 0 || substreamid != 0) 647 if (strmtyp != 0 || substreamid != 0)
707 numblkscod = 3; 654 numblkscod = 3;
708 655
709 if(fscod2 == 3) 656 if(fscod2 == 3)
710 return 0; 657 return 0;
711 658
712 *sample_rate = ac3_sample_rates[fscod2] / 2; 659 *sample_rate = ff_ac3_freqs[fscod2] / 2;
713 } else { 660 } else {
714 numblkscod = get_bits(&bits, 2); 661 numblkscod = get_bits(&bits, 2);
715 662
716 *sample_rate = ac3_sample_rates[fscod]; 663 *sample_rate = ff_ac3_freqs[fscod];
717 } 664 }
718 665
719 acmod = get_bits(&bits, 3); 666 acmod = get_bits(&bits, 3);
720 lfeon = get_bits1(&bits); 667 lfeon = get_bits1(&bits);
721 668
722 *samples = eac3_blocks[numblkscod] * 256; 669 *samples = eac3_blocks[numblkscod] * 256;
723 *bit_rate = frmsiz * (*sample_rate) * 16 / (*samples); 670 *bit_rate = frmsiz * (*sample_rate) * 16 / (*samples);
724 *channels = ac3_channels[acmod] + lfeon; 671 *channels = ff_ac3_channels[acmod] + lfeon;
725 672
726 return frmsiz * 2; 673 return frmsiz * 2;
727 } 674 }
728 675
729 /* Unsupported bitstream version */ 676 /* Unsupported bitstream version */
778 { 725 {
779 AC3ParseContext *s = s1->priv_data; 726 AC3ParseContext *s = s1->priv_data;
780 s->inbuf_ptr = s->inbuf; 727 s->inbuf_ptr = s->inbuf;
781 s->header_size = AC3_HEADER_SIZE; 728 s->header_size = AC3_HEADER_SIZE;
782 s->sync = ac3_sync; 729 s->sync = ac3_sync;
730 ac3_common_init();
783 return 0; 731 return 0;
784 } 732 }
785 #endif 733 #endif
786 734
787 #ifdef CONFIG_AAC_PARSER 735 #ifdef CONFIG_AAC_PARSER