Ticket #13211: mythtv-29-aac-6-channel-audio-backport.patch
File mythtv-29-aac-6-channel-audio-backport.patch, 19.8 KB (added by , 8 years ago) |
---|
-
mythtv/external/FFmpeg/libavcodec/aacdec_template.c
Patch for bug #13211 "MythTV needs a backport from FFmpeg 3.3/3.4 to make German DVB-T2 HD with 5.1 audio work" https://code.mythtv.org/trac/ticket/13211 diff --git a/mythtv/external/FFmpeg/libavcodec/aacdec_template.c b/mythtv/external/FFmpeg/libavcodec/aacdec_template.c index 883ed527f7..f8a8dc4332 100644
a b static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) 406 406 /** 407 407 * Save current output configuration if and only if it has been locked. 408 408 */ 409 static void push_output_configuration(AACContext *ac) { 409 static int push_output_configuration(AACContext *ac) { 410 int pushed = 0; 411 410 412 if (ac->oc[1].status == OC_LOCKED || ac->oc[0].status == OC_NONE) { 411 413 ac->oc[0] = ac->oc[1]; 414 pushed = 1; 412 415 } 413 416 ac->oc[1].status = OC_NONE; 417 return pushed; 414 418 } 415 419 416 420 /** … … static int output_configure(AACContext *ac, 452 456 int id = layout_map[i][1]; 453 457 id_map[type][id] = type_counts[type]++; 454 458 if (id_map[type][id] >= MAX_ELEM_ID) { 455 avpriv_request_sample(ac->avctx, " Remapped id too large\n");459 avpriv_request_sample(ac->avctx, "Too large remapped id"); 456 460 return AVERROR_PATCHWELCOME; 457 461 } 458 462 } … … static void decode_channel_map(uint8_t layout_map[][3], 715 719 } 716 720 } 717 721 722 static inline void relative_align_get_bits(GetBitContext *gb, 723 int reference_position) { 724 int n = (reference_position - get_bits_count(gb) & 7); 725 if (n) 726 skip_bits(gb, n); 727 } 728 718 729 /** 719 730 * Decode program configuration element; reference: table 4.2. 720 731 * … … static void decode_channel_map(uint8_t layout_map[][3], 722 733 */ 723 734 static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, 724 735 uint8_t (*layout_map)[3], 725 GetBitContext *gb )736 GetBitContext *gb, int byte_align_ref) 726 737 { 727 738 int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc; 728 739 int sampling_index; … … static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, 770 781 decode_channel_map(layout_map + tags, AAC_CHANNEL_CC, gb, num_cc); 771 782 tags += num_cc; 772 783 773 align_get_bits(gb);784 relative_align_get_bits(gb, byte_align_ref); 774 785 775 786 /* comment field, first byte is length */ 776 787 comment_len = get_bits(gb, 8) * 8; … … static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, 792 803 */ 793 804 static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, 794 805 GetBitContext *gb, 806 int get_bit_alignment, 795 807 MPEG4AudioConfig *m4ac, 796 808 int channel_config) 797 809 { … … static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx, 815 827 816 828 if (channel_config == 0) { 817 829 skip_bits(gb, 4); // element_instance_tag 818 tags = decode_pce(avctx, m4ac, layout_map, gb );830 tags = decode_pce(avctx, m4ac, layout_map, gb, get_bit_alignment); 819 831 if (tags < 0) 820 832 return tags; 821 833 } else { … … static int decode_eld_specific_config(AACContext *ac, AVCodecContext *avctx, 937 949 * @param ac pointer to AACContext, may be null 938 950 * @param avctx pointer to AVCCodecContext, used for logging 939 951 * @param m4ac pointer to MPEG4AudioConfig, used for parsing 940 * @param data pointer tobuffer holding an audio specific config941 * @param bit_size size of audio specific config or data in bits952 * @param gb buffer holding an audio specific config 953 * @param get_bit_alignment relative alignment for byte align operations 942 954 * @param sync_extension look for an appended sync extension 943 955 * 944 956 * @return Returns error status or number of consumed bits. <0 - error 945 957 */ 946 static int decode_audio_specific_config(AACContext *ac, 947 AVCodecContext *avctx, 948 MPEG4AudioConfig *m4ac, 949 const uint8_t *data, int64_t bit_size, 950 int sync_extension) 958 static int decode_audio_specific_config_gb(AACContext *ac, 959 AVCodecContext *avctx, 960 MPEG4AudioConfig *m4ac, 961 GetBitContext *gb, 962 int get_bit_alignment, 963 int sync_extension) 951 964 { 952 GetBitContext gb;953 965 int i, ret; 966 GetBitContext gbc = *gb; 954 967 955 if (bit_size < 0 || bit_size > INT_MAX) {956 av_log(avctx, AV_LOG_ERROR, "Audio specific config size is invalid\n");968 /* function ff_mpeg4audio_get_config_gb is not avaible in FFmpeg 3.2 */ 969 if ((i = ff_mpeg4audio_get_config_gb(m4ac, &gbc, sync_extension)) < 0) 957 970 return AVERROR_INVALIDDATA; 958 }959 960 ff_dlog(avctx, "audio specific config size %d\n", (int)bit_size >> 3);961 for (i = 0; i < bit_size >> 3; i++)962 ff_dlog(avctx, "%02x ", data[i]);963 ff_dlog(avctx, "\n");964 971 965 if ((ret = init_get_bits(&gb, data, bit_size)) < 0)966 return ret;967 968 if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size,969 sync_extension)) < 0)970 return AVERROR_INVALIDDATA;971 972 if (m4ac->sampling_index > 12) { 972 973 av_log(avctx, AV_LOG_ERROR, 973 974 "invalid sampling rate index %d\n", … … static int decode_audio_specific_config(AACContext *ac, 982 983 return AVERROR_INVALIDDATA; 983 984 } 984 985 985 skip_bits_long( &gb, i);986 skip_bits_long(gb, i); 986 987 987 988 switch (m4ac->object_type) { 988 989 case AOT_AAC_MAIN: … … static int decode_audio_specific_config(AACContext *ac, 990 991 case AOT_AAC_LTP: 991 992 case AOT_ER_AAC_LC: 992 993 case AOT_ER_AAC_LD: 993 if ((ret = decode_ga_specific_config(ac, avctx, &gb,994 if ((ret = decode_ga_specific_config(ac, avctx, gb, get_bit_alignment, 994 995 m4ac, m4ac->chan_config)) < 0) 995 996 return ret; 996 997 break; 997 998 case AOT_ER_AAC_ELD: 998 if ((ret = decode_eld_specific_config(ac, avctx, &gb,999 if ((ret = decode_eld_specific_config(ac, avctx, gb, 999 1000 m4ac, m4ac->chan_config)) < 0) 1000 1001 return ret; 1001 1002 break; … … static int decode_audio_specific_config(AACContext *ac, 1013 1014 m4ac->sample_rate, m4ac->sbr, 1014 1015 m4ac->ps); 1015 1016 1016 return get_bits_count(&gb); 1017 return get_bits_count(gb); 1018 } 1019 1020 static int decode_audio_specific_config(AACContext *ac, 1021 AVCodecContext *avctx, 1022 MPEG4AudioConfig *m4ac, 1023 const uint8_t *data, int64_t bit_size, 1024 int sync_extension) 1025 { 1026 int i, ret; 1027 GetBitContext gb; 1028 1029 if (bit_size < 0 || bit_size > INT_MAX) { 1030 av_log(avctx, AV_LOG_ERROR, "Audio specific config size is invalid\n"); 1031 return AVERROR_INVALIDDATA; 1032 } 1033 1034 ff_dlog(avctx, "audio specific config size %d\n", (int)bit_size >> 3); 1035 for (i = 0; i < bit_size >> 3; i++) 1036 ff_dlog(avctx, "%02x ", data[i]); 1037 ff_dlog(avctx, "\n"); 1038 1039 if ((ret = init_get_bits(&gb, data, bit_size)) < 0) 1040 return ret; 1041 1042 /* if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, */ 1043 /* sync_extension)) < 0) */ 1044 /* return AVERROR_INVALIDDATA; */ 1045 1046 return decode_audio_specific_config_gb(ac, avctx, m4ac, &gb, 0, 1047 sync_extension); 1017 1048 } 1018 1049 1019 1050 /** … … static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, 1255 1286 const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac; 1256 1287 const int aot = m4ac->object_type; 1257 1288 const int sampling_index = m4ac->sampling_index; 1289 int ret_fail = AVERROR_INVALIDDATA; 1290 1258 1291 if (aot != AOT_ER_AAC_ELD) { 1259 1292 if (get_bits1(gb)) { 1260 1293 av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n"); … … static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, 1305 1338 ics->num_swb = ff_aac_num_swb_512[sampling_index]; 1306 1339 ics->tns_max_bands = ff_tns_max_bands_512[sampling_index]; 1307 1340 } 1308 if (!ics->num_swb || !ics->swb_offset) 1309 return AVERROR_BUG; 1341 if (!ics->num_swb || !ics->swb_offset) { 1342 ret_fail = AVERROR_BUG; 1343 goto fail; 1344 } 1310 1345 } else { 1311 1346 ics->swb_offset = ff_swb_offset_1024[sampling_index]; 1312 1347 ics->num_swb = ff_aac_num_swb_1024[sampling_index]; … … static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, 1330 1365 if (aot == AOT_ER_AAC_LD) { 1331 1366 av_log(ac->avctx, AV_LOG_ERROR, 1332 1367 "LTP in ER AAC LD not yet implemented.\n"); 1333 return AVERROR_PATCHWELCOME; 1368 ret_fail = AVERROR_PATCHWELCOME; 1369 goto fail; 1334 1370 } 1335 1371 if ((ics->ltp.present = get_bits(gb, 1))) 1336 1372 decode_ltp(&ics->ltp, gb, ics->max_sfb); … … static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, 1349 1385 return 0; 1350 1386 fail: 1351 1387 ics->max_sfb = 0; 1352 return AVERROR_INVALIDDATA;1388 return ret_fail; 1353 1389 } 1354 1390 1355 1391 /** … … static int decode_ics(AACContext *ac, SingleChannelElement *sce, 1936 1972 global_gain = get_bits(gb, 8); 1937 1973 1938 1974 if (!common_window && !scale_flag) { 1939 if (decode_ics_info(ac, ics, gb) < 0) 1940 return AVERROR_INVALIDDATA; 1975 ret = decode_ics_info(ac, ics, gb); 1976 if (ret < 0) 1977 goto fail; 1941 1978 } 1942 1979 1943 1980 if ((ret = decode_band_types(ac, sce->band_type, 1944 1981 sce->band_type_run_end, gb, ics)) < 0) 1945 return ret;1982 goto fail; 1946 1983 if ((ret = decode_scalefactors(ac, sce->sf, gb, global_gain, ics, 1947 1984 sce->band_type, sce->band_type_run_end)) < 0) 1948 return ret;1985 goto fail; 1949 1986 1950 1987 pulse_present = 0; 1951 1988 if (!scale_flag) { … … static int decode_ics(AACContext *ac, SingleChannelElement *sce, 1953 1990 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { 1954 1991 av_log(ac->avctx, AV_LOG_ERROR, 1955 1992 "Pulse tool not allowed in eight short sequence.\n"); 1956 return AVERROR_INVALIDDATA; 1993 ret = AVERROR_INVALIDDATA; 1994 goto fail; 1957 1995 } 1958 1996 if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) { 1959 1997 av_log(ac->avctx, AV_LOG_ERROR, 1960 1998 "Pulse data corrupt or invalid.\n"); 1961 return AVERROR_INVALIDDATA; 1999 ret = AVERROR_INVALIDDATA; 2000 goto fail; 1962 2001 } 1963 2002 } 1964 2003 tns->present = get_bits1(gb); 1965 if (tns->present && !er_syntax) 1966 if (decode_tns(ac, tns, gb, ics) < 0) 1967 return AVERROR_INVALIDDATA; 2004 if (tns->present && !er_syntax) { 2005 ret = decode_tns(ac, tns, gb, ics); 2006 if (ret < 0) 2007 goto fail; 2008 } 1968 2009 if (!eld_syntax && get_bits1(gb)) { 1969 2010 avpriv_request_sample(ac->avctx, "SSR"); 1970 return AVERROR_PATCHWELCOME; 2011 ret = AVERROR_PATCHWELCOME; 2012 goto fail; 1971 2013 } 1972 2014 // I see no textual basis in the spec for this occurring after SSR gain 1973 2015 // control, but this is what both reference and real implmentations do 1974 if (tns->present && er_syntax) 1975 if (decode_tns(ac, tns, gb, ics) < 0) 1976 return AVERROR_INVALIDDATA; 2016 if (tns->present && er_syntax) { 2017 ret = decode_tns(ac, tns, gb, ics); 2018 if (ret < 0) 2019 goto fail; 2020 } 1977 2021 } 1978 2022 1979 if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, 1980 &pulse, ics, sce->band_type) < 0) 1981 return AVERROR_INVALIDDATA; 2023 ret = decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, 2024 &pulse, ics, sce->band_type); 2025 if (ret < 0) 2026 goto fail; 1982 2027 1983 2028 if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window) 1984 2029 apply_prediction(ac, sce); 1985 2030 1986 2031 return 0; 2032 fail: 2033 tns->present = 0; 2034 return ret; 1987 2035 } 1988 2036 1989 2037 /** … … static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) 2155 2203 coup->coupling_point += get_bits1(gb) || (coup->coupling_point >> 1); 2156 2204 2157 2205 sign = get_bits(gb, 1); 2158 scale = AAC_RENAME(cce_scale)[get_bits(gb, 2)]; 2206 #if USE_FIXED 2207 scale = get_bits(gb, 2); 2208 #else 2209 scale = cce_scale[get_bits(gb, 2)]; 2210 #endif 2159 2211 2160 2212 if ((ret = decode_ics(ac, sce, gb, 0, 0))) 2161 2213 return ret; … … static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) 2169 2221 cge = coup->coupling_point == AFTER_IMDCT ? 1 : get_bits1(gb); 2170 2222 gain = cge ? get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60: 0; 2171 2223 gain_cache = GET_GAIN(scale, gain); 2224 #if USE_FIXED 2225 if ((abs(gain_cache)-1024) >> 3 > 30) 2226 return AVERROR(ERANGE); 2227 #endif 2172 2228 } 2173 2229 if (coup->coupling_point == AFTER_IMDCT) { 2174 2230 coup->gain[c][0] = gain_cache; … … static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che) 2186 2242 t >>= 1; 2187 2243 } 2188 2244 gain_cache = GET_GAIN(scale, t) * s; 2245 #if USE_FIXED 2246 if ((abs(gain_cache)-1024) >> 3 > 30) 2247 return AVERROR(ERANGE); 2248 #endif 2189 2249 } 2190 2250 } 2191 2251 coup->gain[c][idx] = gain_cache; … … static int aac_decode_frame_int(AVCodecContext *avctx, void *data, 2923 2983 { 2924 2984 AACContext *ac = avctx->priv_data; 2925 2985 ChannelElement *che = NULL, *che_prev = NULL; 2926 enum RawDataBlockType elem_type, elem_type_prev= TYPE_END;2986 enum RawDataBlockType elem_type, che_prev_type = TYPE_END; 2927 2987 int err, elem_id; 2928 2988 int samples = 0, multiplier, audio_found = 0, pce_found = 0; 2929 2989 int is_dmono, sce_count = 0; 2990 int payload_alignment; 2930 2991 2931 2992 ac->frame = data; 2932 2993 … … static int aac_decode_frame_int(AVCodecContext *avctx, void *data, 2949 3010 // This may lead to an undefined profile being signaled 2950 3011 ac->avctx->profile = ac->oc[1].m4ac.object_type - 1; 2951 3012 3013 payload_alignment = get_bits_count(gb); 2952 3014 ac->tags_mapped = 0; 2953 3015 // parse 2954 3016 while ((elem_type = get_bits(gb, 3)) != TYPE_END) { … … static int aac_decode_frame_int(AVCodecContext *avctx, void *data, 3002 3064 case TYPE_PCE: { 3003 3065 uint8_t layout_map[MAX_ELEM_ID*4][3]; 3004 3066 int tags; 3005 push_output_configuration(ac); 3006 tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb); 3067 3068 int pushed = push_output_configuration(ac); 3069 if (pce_found && !pushed) { 3070 err = AVERROR_INVALIDDATA; 3071 goto fail; 3072 } 3073 3074 tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb, 3075 payload_alignment); 3007 3076 if (tags < 0) { 3008 3077 err = tags; 3009 3078 break; … … static int aac_decode_frame_int(AVCodecContext *avctx, void *data, 3011 3080 if (pce_found) { 3012 3081 av_log(avctx, AV_LOG_ERROR, 3013 3082 "Not evaluating a further program_config_element as this construct is dubious at best.\n"); 3083 pop_output_configuration(ac); 3014 3084 } else { 3015 3085 err = output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1); 3016 3086 if (!err) … … static int aac_decode_frame_int(AVCodecContext *avctx, void *data, 3029 3099 goto fail; 3030 3100 } 3031 3101 while (elem_id > 0) 3032 elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, elem_type_prev);3102 elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, che_prev_type); 3033 3103 err = 0; /* FIXME */ 3034 3104 break; 3035 3105 … … static int aac_decode_frame_int(AVCodecContext *avctx, void *data, 3038 3108 break; 3039 3109 } 3040 3110 3041 che_prev = che; 3042 elem_type_prev = elem_type; 3111 if (elem_type < TYPE_DSE) { 3112 che_prev = che; 3113 che_prev_type = elem_type; 3114 } 3043 3115 3044 3116 if (err) 3045 3117 goto fail; -
mythtv/external/FFmpeg/libavcodec/mpeg4audio.c
diff --git a/mythtv/external/FFmpeg/libavcodec/mpeg4audio.c b/mythtv/external/FFmpeg/libavcodec/mpeg4audio.c index 188d843eee..84f384eeb6 100644
a b static inline int get_sample_rate(GetBitContext *gb, int *index) 78 78 avpriv_mpeg4audio_sample_rates[*index]; 79 79 } 80 80 81 int ff_mpeg4audio_get_config_gb(MPEG4AudioConfig *c, GetBitContext *gb, 82 int sync_extension) 83 { 84 int specific_config_bitindex, ret; 85 int start_bit_index = get_bits_count(gb); 86 c->object_type = get_object_type(gb); 87 c->sample_rate = get_sample_rate(gb, &c->sampling_index); 88 c->chan_config = get_bits(gb, 4); 89 if (c->chan_config < FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) 90 c->channels = ff_mpeg4audio_channels[c->chan_config]; 91 c->sbr = -1; 92 c->ps = -1; 93 if (c->object_type == AOT_SBR || (c->object_type == AOT_PS && 94 // check for W6132 Annex YYYY draft MP3onMP4 95 !(show_bits(gb, 3) & 0x03 && !(show_bits(gb, 9) & 0x3F)))) { 96 if (c->object_type == AOT_PS) 97 c->ps = 1; 98 c->ext_object_type = AOT_SBR; 99 c->sbr = 1; 100 c->ext_sample_rate = get_sample_rate(gb, &c->ext_sampling_index); 101 c->object_type = get_object_type(gb); 102 if (c->object_type == AOT_ER_BSAC) 103 c->ext_chan_config = get_bits(gb, 4); 104 } else { 105 c->ext_object_type = AOT_NULL; 106 c->ext_sample_rate = 0; 107 } 108 specific_config_bitindex = get_bits_count(gb); 109 110 if (c->object_type == AOT_ALS) { 111 skip_bits(gb, 5); 112 if (show_bits_long(gb, 24) != MKBETAG('\0','A','L','S')) 113 skip_bits_long(gb, 24); 114 115 specific_config_bitindex = get_bits_count(gb); 116 117 ret = parse_config_ALS(gb, c); 118 if (ret < 0) 119 return ret; 120 } 121 122 if (c->ext_object_type != AOT_SBR && sync_extension) { 123 while (get_bits_left(gb) > 15) { 124 if (show_bits(gb, 11) == 0x2b7) { // sync extension 125 get_bits(gb, 11); 126 c->ext_object_type = get_object_type(gb); 127 if (c->ext_object_type == AOT_SBR && (c->sbr = get_bits1(gb)) == 1) { 128 c->ext_sample_rate = get_sample_rate(gb, &c->ext_sampling_index); 129 if (c->ext_sample_rate == c->sample_rate) 130 c->sbr = -1; 131 } 132 if (get_bits_left(gb) > 11 && get_bits(gb, 11) == 0x548) 133 c->ps = get_bits1(gb); 134 break; 135 } else 136 get_bits1(gb); // skip 1 bit 137 } 138 } 139 140 //PS requires SBR 141 if (!c->sbr) 142 c->ps = 0; 143 //Limit implicit PS to the HE-AACv2 Profile 144 if ((c->ps == -1 && c->object_type != AOT_AAC_LC) || c->channels & ~0x01) 145 c->ps = 0; 146 147 return specific_config_bitindex - start_bit_index; 148 } 149 81 150 int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, 82 151 int bit_size, int sync_extension) 83 152 {