comparison parser.c @ 4397:acb9faabab8d libavcodec

Allows the AC3 parser to read the frame size and codec parameters from E-AC3 streams, allowing them to be correctly demuxed. Currently it only identifies the primary substream, and will skip over any additional dependent or independent substreams. Patch by Ian Caulfield % ian P caulfield A gmail P com % Original thread: date: Jan 19, 2007 9:55 AM subject: Re: [Ffmpeg-devel] [PATCH] Correctly parse headers of E-AC3 streams
author gpoirier
date Wed, 24 Jan 2007 15:31:48 +0000
parents a0c0c7bebd64
children d8ccac15e9d3
comparison
equal deleted inserted replaced
4396:8e78248586b0 4397:acb9faabab8d
630 32, 32, 40, 40, 48, 48, 56, 56, 64, 64, 80, 80, 96, 96, 112, 112, 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, 631 128, 128, 160, 160, 192, 192, 224, 224, 256, 256, 320, 320, 384,
632 384, 448, 448, 512, 512, 576, 576, 640, 640, 632 384, 448, 448, 512, 512, 576, 576, 640, 640,
633 }; 633 };
634 634
635 static const int ac3_channels[8] = { 635 static const uint8_t ac3_channels[8] = {
636 2, 1, 2, 3, 3, 4, 4, 5 636 2, 1, 2, 3, 3, 4, 4, 5
637 }; 637 };
638
639 static const uint8_t eac3_blocks[4] = {
640 1, 2, 3, 6
641 };
642
638 #endif /* CONFIG_AC3_PARSER */ 643 #endif /* CONFIG_AC3_PARSER */
639 644
640 #ifdef CONFIG_AAC_PARSER 645 #ifdef CONFIG_AAC_PARSER
641 static const int aac_sample_rates[16] = { 646 static const int aac_sample_rates[16] = {
642 96000, 88200, 64000, 48000, 44100, 32000, 647 96000, 88200, 64000, 48000, 44100, 32000,
651 #ifdef CONFIG_AC3_PARSER 656 #ifdef CONFIG_AC3_PARSER
652 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,
653 int *bit_rate, int *samples) 658 int *bit_rate, int *samples)
654 { 659 {
655 unsigned int fscod, frmsizecod, acmod, bsid, lfeon; 660 unsigned int fscod, frmsizecod, acmod, bsid, lfeon;
661 unsigned int strmtyp, substreamid, frmsiz, fscod2, numblkscod;
656 GetBitContext bits; 662 GetBitContext bits;
657 663
658 init_get_bits(&bits, buf, AC3_HEADER_SIZE * 8); 664 init_get_bits(&bits, buf, AC3_HEADER_SIZE * 8);
659 665
660 if(get_bits(&bits, 16) != 0x0b77) 666 if(get_bits(&bits, 16) != 0x0b77)
661 return 0; 667 return 0;
662 668
669 bsid = show_bits_long(&bits, 29) & 0x1f;
670 if(bsid <= 8) { /* Normal AC-3 */
663 skip_bits(&bits, 16); /* crc */ 671 skip_bits(&bits, 16); /* crc */
664 fscod = get_bits(&bits, 2); 672 fscod = get_bits(&bits, 2);
665 frmsizecod = get_bits(&bits, 6); 673 frmsizecod = get_bits(&bits, 6);
666 674
667 if(!ac3_sample_rates[fscod]) 675 if(fscod == 3)
668 return 0; 676 return 0;
669 677
670 bsid = get_bits(&bits, 5); 678 skip_bits(&bits, 5); /* bsid */
671 if(bsid > 8)
672 return 0;
673 skip_bits(&bits, 3); /* bsmod */ 679 skip_bits(&bits, 3); /* bsmod */
674 acmod = get_bits(&bits, 3); 680 acmod = get_bits(&bits, 3);
675 if(acmod & 1 && acmod != 1) 681 if(acmod & 1 && acmod != 1)
676 skip_bits(&bits, 2); /* cmixlev */ 682 skip_bits(&bits, 2); /* cmixlev */
677 if(acmod & 4) 683 if(acmod & 4)
684 *bit_rate = ac3_bitrates[frmsizecod] * 1000; 690 *bit_rate = ac3_bitrates[frmsizecod] * 1000;
685 *channels = ac3_channels[acmod] + lfeon; 691 *channels = ac3_channels[acmod] + lfeon;
686 *samples = 6 * 256; 692 *samples = 6 * 256;
687 693
688 return ac3_frame_sizes[frmsizecod][fscod] * 2; 694 return ac3_frame_sizes[frmsizecod][fscod] * 2;
695 } else if (bsid >= 10 && bsid <= 16) { /* Enhanced AC-3 */
696 strmtyp = get_bits(&bits, 2);
697 substreamid = get_bits(&bits, 3);
698
699 if (strmtyp != 0 || substreamid != 0)
700 return 0; /* Currently don't support additional streams */
701
702 frmsiz = get_bits(&bits, 11) + 1;
703 fscod = get_bits(&bits, 2);
704 if (fscod == 3) {
705 fscod2 = get_bits(&bits, 2);
706 numblkscod = 3;
707
708 if(fscod2 == 3)
709 return 0;
710
711 *sample_rate = ac3_sample_rates[fscod2] / 2;
712 } else {
713 numblkscod = get_bits(&bits, 2);
714
715 *sample_rate = ac3_sample_rates[fscod];
716 }
717
718 acmod = get_bits(&bits, 3);
719 lfeon = get_bits1(&bits);
720
721 *samples = eac3_blocks[numblkscod] * 256;
722 *bit_rate = frmsiz * (*sample_rate) * 16 / (*samples);
723 *channels = ac3_channels[acmod] + lfeon;
724
725 return frmsiz * 2;
726 }
727
728 /* Unsupported bitstream version */
729 return 0;
689 } 730 }
690 #endif /* CONFIG_AC3_PARSER */ 731 #endif /* CONFIG_AC3_PARSER */
691 732
692 #ifdef CONFIG_AAC_PARSER 733 #ifdef CONFIG_AAC_PARSER
693 static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate, 734 static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,