Mercurial > libavcodec.hg
comparison ac3dec.c @ 7026:4bd2ccb0619e libavcodec
store cpl_in_use for all blocks in decode context
author | jbr |
---|---|
date | Sat, 07 Jun 2008 22:30:43 +0000 |
parents | 40a2db8dbaa2 |
children | 1edec36c02c5 |
comparison
equal
deleted
inserted
replaced
7025:acf98a472f74 | 7026:4bd2ccb0619e |
---|---|
709 int fbw_channels = s->fbw_channels; | 709 int fbw_channels = s->fbw_channels; |
710 int channel_mode = s->channel_mode; | 710 int channel_mode = s->channel_mode; |
711 int i, bnd, seg, ch; | 711 int i, bnd, seg, ch; |
712 int different_transforms; | 712 int different_transforms; |
713 int downmix_output; | 713 int downmix_output; |
714 int cpl_in_use; | |
714 GetBitContext *gbc = &s->gbc; | 715 GetBitContext *gbc = &s->gbc; |
715 uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; | 716 uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; |
716 | 717 |
717 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); | 718 memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); |
718 | 719 |
744 } while(i--); | 745 } while(i--); |
745 | 746 |
746 /* coupling strategy */ | 747 /* coupling strategy */ |
747 if (get_bits1(gbc)) { | 748 if (get_bits1(gbc)) { |
748 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); | 749 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
749 s->cpl_in_use = get_bits1(gbc); | 750 cpl_in_use = get_bits1(gbc); |
750 if (s->cpl_in_use) { | 751 if (cpl_in_use) { |
751 /* coupling in use */ | 752 /* coupling in use */ |
752 int cpl_begin_freq, cpl_end_freq; | 753 int cpl_begin_freq, cpl_end_freq; |
753 | 754 |
754 if (channel_mode < AC3_CHMODE_STEREO) { | 755 if (channel_mode < AC3_CHMODE_STEREO) { |
755 av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n"); | 756 av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n"); |
787 s->channel_in_cpl[ch] = 0; | 788 s->channel_in_cpl[ch] = 0; |
788 } | 789 } |
789 } else if (!blk) { | 790 } else if (!blk) { |
790 av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n"); | 791 av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n"); |
791 return -1; | 792 return -1; |
792 } | 793 } else { |
794 cpl_in_use = s->cpl_in_use[blk-1]; | |
795 } | |
796 s->cpl_in_use[blk] = cpl_in_use; | |
793 | 797 |
794 /* coupling coordinates */ | 798 /* coupling coordinates */ |
795 if (s->cpl_in_use) { | 799 if (cpl_in_use) { |
796 int cpl_coords_exist = 0; | 800 int cpl_coords_exist = 0; |
797 | 801 |
798 for (ch = 1; ch <= fbw_channels; ch++) { | 802 for (ch = 1; ch <= fbw_channels; ch++) { |
799 if (s->channel_in_cpl[ch]) { | 803 if (s->channel_in_cpl[ch]) { |
800 if (get_bits1(gbc)) { | 804 if (get_bits1(gbc)) { |
826 | 830 |
827 /* stereo rematrixing strategy and band structure */ | 831 /* stereo rematrixing strategy and band structure */ |
828 if (channel_mode == AC3_CHMODE_STEREO) { | 832 if (channel_mode == AC3_CHMODE_STEREO) { |
829 if (get_bits1(gbc)) { | 833 if (get_bits1(gbc)) { |
830 s->num_rematrixing_bands = 4; | 834 s->num_rematrixing_bands = 4; |
831 if(s->cpl_in_use && s->start_freq[CPL_CH] <= 61) | 835 if(cpl_in_use && s->start_freq[CPL_CH] <= 61) |
832 s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); | 836 s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); |
833 for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) | 837 for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) |
834 s->rematrixing_flags[bnd] = get_bits1(gbc); | 838 s->rematrixing_flags[bnd] = get_bits1(gbc); |
835 } else if (!blk) { | 839 } else if (!blk) { |
836 av_log(s->avctx, AV_LOG_ERROR, "new rematrixing strategy must be present in block 0\n"); | 840 av_log(s->avctx, AV_LOG_ERROR, "new rematrixing strategy must be present in block 0\n"); |
839 } | 843 } |
840 | 844 |
841 /* exponent strategies for each channel */ | 845 /* exponent strategies for each channel */ |
842 s->exp_strategy[CPL_CH] = EXP_REUSE; | 846 s->exp_strategy[CPL_CH] = EXP_REUSE; |
843 s->exp_strategy[s->lfe_ch] = EXP_REUSE; | 847 s->exp_strategy[s->lfe_ch] = EXP_REUSE; |
844 for (ch = !s->cpl_in_use; ch <= s->channels; ch++) { | 848 for (ch = !cpl_in_use; ch <= s->channels; ch++) { |
845 s->exp_strategy[ch] = get_bits(gbc, 2 - (ch == s->lfe_ch)); | 849 s->exp_strategy[ch] = get_bits(gbc, 2 - (ch == s->lfe_ch)); |
846 if(s->exp_strategy[ch] != EXP_REUSE) | 850 if(s->exp_strategy[ch] != EXP_REUSE) |
847 bit_alloc_stages[ch] = 3; | 851 bit_alloc_stages[ch] = 3; |
848 } | 852 } |
849 | 853 |
867 s->num_exp_groups[ch] = (s->end_freq[ch]+group_size-4) / group_size; | 871 s->num_exp_groups[ch] = (s->end_freq[ch]+group_size-4) / group_size; |
868 if(blk > 0 && s->end_freq[ch] != prev) | 872 if(blk > 0 && s->end_freq[ch] != prev) |
869 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); | 873 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
870 } | 874 } |
871 } | 875 } |
872 if (s->cpl_in_use && s->exp_strategy[CPL_CH] != EXP_REUSE) { | 876 if (cpl_in_use && s->exp_strategy[CPL_CH] != EXP_REUSE) { |
873 s->num_exp_groups[CPL_CH] = (s->end_freq[CPL_CH] - s->start_freq[CPL_CH]) / | 877 s->num_exp_groups[CPL_CH] = (s->end_freq[CPL_CH] - s->start_freq[CPL_CH]) / |
874 (3 << (s->exp_strategy[CPL_CH] - 1)); | 878 (3 << (s->exp_strategy[CPL_CH] - 1)); |
875 } | 879 } |
876 | 880 |
877 /* decode exponents for each channel */ | 881 /* decode exponents for each channel */ |
878 for (ch = !s->cpl_in_use; ch <= s->channels; ch++) { | 882 for (ch = !cpl_in_use; ch <= s->channels; ch++) { |
879 if (s->exp_strategy[ch] != EXP_REUSE) { | 883 if (s->exp_strategy[ch] != EXP_REUSE) { |
880 s->dexps[ch][0] = get_bits(gbc, 4) << !ch; | 884 s->dexps[ch][0] = get_bits(gbc, 4) << !ch; |
881 decode_exponents(gbc, s->exp_strategy[ch], | 885 decode_exponents(gbc, s->exp_strategy[ch], |
882 s->num_exp_groups[ch], s->dexps[ch][0], | 886 s->num_exp_groups[ch], s->dexps[ch][0], |
883 &s->dexps[ch][s->start_freq[ch]+!!ch]); | 887 &s->dexps[ch][s->start_freq[ch]+!!ch]); |
891 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; | 895 s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; |
892 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; | 896 s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; |
893 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; | 897 s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; |
894 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; | 898 s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; |
895 s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; | 899 s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; |
896 for(ch=!s->cpl_in_use; ch<=s->channels; ch++) | 900 for(ch=!cpl_in_use; ch<=s->channels; ch++) |
897 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); | 901 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
898 } else if (!blk) { | 902 } else if (!blk) { |
899 av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n"); | 903 av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n"); |
900 return -1; | 904 return -1; |
901 } | 905 } |
902 | 906 |
903 /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ | 907 /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ |
904 if (get_bits1(gbc)) { | 908 if (get_bits1(gbc)) { |
905 int csnr; | 909 int csnr; |
906 csnr = (get_bits(gbc, 6) - 15) << 4; | 910 csnr = (get_bits(gbc, 6) - 15) << 4; |
907 for (ch = !s->cpl_in_use; ch <= s->channels; ch++) { /* snr offset and fast gain */ | 911 for (ch = !cpl_in_use; ch <= s->channels; ch++) { /* snr offset and fast gain */ |
908 s->snr_offset[ch] = (csnr + get_bits(gbc, 4)) << 2; | 912 s->snr_offset[ch] = (csnr + get_bits(gbc, 4)) << 2; |
909 s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; | 913 s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; |
910 } | 914 } |
911 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); | 915 memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); |
912 } else if (!blk) { | 916 } else if (!blk) { |
913 av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n"); | 917 av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n"); |
914 return -1; | 918 return -1; |
915 } | 919 } |
916 | 920 |
917 /* coupling leak information */ | 921 /* coupling leak information */ |
918 if (s->cpl_in_use) { | 922 if (cpl_in_use) { |
919 if (get_bits1(gbc)) { | 923 if (get_bits1(gbc)) { |
920 s->bit_alloc_params.cpl_fast_leak = get_bits(gbc, 3); | 924 s->bit_alloc_params.cpl_fast_leak = get_bits(gbc, 3); |
921 s->bit_alloc_params.cpl_slow_leak = get_bits(gbc, 3); | 925 s->bit_alloc_params.cpl_slow_leak = get_bits(gbc, 3); |
922 bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); | 926 bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); |
923 } else if (!blk) { | 927 } else if (!blk) { |
927 } | 931 } |
928 | 932 |
929 /* delta bit allocation information */ | 933 /* delta bit allocation information */ |
930 if (get_bits1(gbc)) { | 934 if (get_bits1(gbc)) { |
931 /* delta bit allocation exists (strategy) */ | 935 /* delta bit allocation exists (strategy) */ |
932 for (ch = !s->cpl_in_use; ch <= fbw_channels; ch++) { | 936 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { |
933 s->dba_mode[ch] = get_bits(gbc, 2); | 937 s->dba_mode[ch] = get_bits(gbc, 2); |
934 if (s->dba_mode[ch] == DBA_RESERVED) { | 938 if (s->dba_mode[ch] == DBA_RESERVED) { |
935 av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); | 939 av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); |
936 return -1; | 940 return -1; |
937 } | 941 } |
938 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); | 942 bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); |
939 } | 943 } |
940 /* channel delta offset, len and bit allocation */ | 944 /* channel delta offset, len and bit allocation */ |
941 for (ch = !s->cpl_in_use; ch <= fbw_channels; ch++) { | 945 for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { |
942 if (s->dba_mode[ch] == DBA_NEW) { | 946 if (s->dba_mode[ch] == DBA_NEW) { |
943 s->dba_nsegs[ch] = get_bits(gbc, 3); | 947 s->dba_nsegs[ch] = get_bits(gbc, 3); |
944 for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) { | 948 for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) { |
945 s->dba_offsets[ch][seg] = get_bits(gbc, 5); | 949 s->dba_offsets[ch][seg] = get_bits(gbc, 5); |
946 s->dba_lengths[ch][seg] = get_bits(gbc, 4); | 950 s->dba_lengths[ch][seg] = get_bits(gbc, 4); |
955 s->dba_mode[ch] = DBA_NONE; | 959 s->dba_mode[ch] = DBA_NONE; |
956 } | 960 } |
957 } | 961 } |
958 | 962 |
959 /* Bit allocation */ | 963 /* Bit allocation */ |
960 for(ch=!s->cpl_in_use; ch<=s->channels; ch++) { | 964 for(ch=!cpl_in_use; ch<=s->channels; ch++) { |
961 if(bit_alloc_stages[ch] > 2) { | 965 if(bit_alloc_stages[ch] > 2) { |
962 /* Exponent mapping into PSD and PSD integration */ | 966 /* Exponent mapping into PSD and PSD integration */ |
963 ff_ac3_bit_alloc_calc_psd(s->dexps[ch], | 967 ff_ac3_bit_alloc_calc_psd(s->dexps[ch], |
964 s->start_freq[ch], s->end_freq[ch], | 968 s->start_freq[ch], s->end_freq[ch], |
965 s->psd[ch], s->band_psd[ch]); | 969 s->psd[ch], s->band_psd[ch]); |