X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Faacdec.c;h=e436b4f2f74851ffad04d5dc3c88407c272afeb7;hb=83678dbbae64ad8c501e0c732c1117e642c25dae;hp=0c7e2c4d39a5a2a67c7f371b6d74b1a6528536a7;hpb=0289f81241e720452b5a77713488d54d3ec252d7;p=ffmpeg diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 0c7e2c4d39a..e436b4f2f74 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -93,11 +93,11 @@ #include "aac.h" #include "aactab.h" #include "aacdectab.h" +#include "adts_header.h" #include "cbrt_tablegen.h" #include "sbr.h" #include "aacsbr.h" #include "mpeg4audio.h" -#include "aacadtsdec.h" #include "libavutil/intfloat.h" #include @@ -110,6 +110,8 @@ # include "arm/aac.h" #endif +#include "libavutil/thread.h" + static VLC vlc_scalefactors; static VLC vlc_spectral[11]; @@ -291,6 +293,11 @@ static uint64_t sniff_channel_order(uint8_t (*layout_map)[3], int tags) if (num_back_channels < 0) return 0; + if (num_side_channels == 0 && num_back_channels >= 4) { + num_side_channels = 2; + num_back_channels -= 2; + } + i = 0; if (num_front_channels & 1) { e2c_vec[i] = (struct elem_to_channel) { @@ -502,7 +509,8 @@ static int set_default_channel_config(AVCodecContext *avctx, int *tags, int channel_config) { - if (channel_config < 1 || channel_config > 7) { + if (channel_config < 1 || (channel_config > 7 && channel_config < 11) || + channel_config > 12) { av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n", channel_config); @@ -559,11 +567,19 @@ static ChannelElement *get_che(AACContext *ac, int type, int elem_id) /* For indexed channel configurations map the channels solely based * on position. */ switch (ac->oc[1].m4ac.chan_config) { + case 12: case 7: if (ac->tags_mapped == 3 && type == TYPE_CPE) { ac->tags_mapped++; return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2]; } + case 11: + if (ac->tags_mapped == 2 && + ac->oc[1].m4ac.chan_config == 11 && + type == TYPE_SCE) { + ac->tags_mapped++; + return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1]; + } case 6: /* Some streams incorrectly code 5.1 audio as * SCE[0] CPE[0] CPE[1] SCE[1] @@ -989,11 +1005,56 @@ static void reset_predictor_group(PredictorState *ps, int group_num) sizeof(ff_aac_spectral_codes[num][0]), \ size); +static av_cold void aac_static_table_init(void) +{ + AAC_INIT_VLC_STATIC( 0, 304); + AAC_INIT_VLC_STATIC( 1, 270); + AAC_INIT_VLC_STATIC( 2, 550); + AAC_INIT_VLC_STATIC( 3, 300); + AAC_INIT_VLC_STATIC( 4, 328); + AAC_INIT_VLC_STATIC( 5, 294); + AAC_INIT_VLC_STATIC( 6, 306); + AAC_INIT_VLC_STATIC( 7, 268); + AAC_INIT_VLC_STATIC( 8, 510); + AAC_INIT_VLC_STATIC( 9, 366); + AAC_INIT_VLC_STATIC(10, 462); + + ff_aac_sbr_init(); + + ff_aac_tableinit(); + + INIT_VLC_STATIC(&vlc_scalefactors, 7, + FF_ARRAY_ELEMS(ff_aac_scalefactor_code), + ff_aac_scalefactor_bits, + sizeof(ff_aac_scalefactor_bits[0]), + sizeof(ff_aac_scalefactor_bits[0]), + ff_aac_scalefactor_code, + sizeof(ff_aac_scalefactor_code[0]), + sizeof(ff_aac_scalefactor_code[0]), + 352); + + + // window initialization + ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); + ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); + ff_init_ff_sine_windows(10); + ff_init_ff_sine_windows( 9); + ff_init_ff_sine_windows( 7); + + cbrt_tableinit(); +} + +static AVOnce aac_init = AV_ONCE_INIT; + static av_cold int aac_decode_init(AVCodecContext *avctx) { AACContext *ac = avctx->priv_data; int ret; + ret = ff_thread_once(&aac_init, &aac_static_table_init); + if (ret != 0) + return AVERROR_UNKNOWN; + ac->avctx = avctx; ac->oc[1].m4ac.sample_rate = avctx->sample_rate; @@ -1035,36 +1096,10 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) } } - AAC_INIT_VLC_STATIC( 0, 304); - AAC_INIT_VLC_STATIC( 1, 270); - AAC_INIT_VLC_STATIC( 2, 550); - AAC_INIT_VLC_STATIC( 3, 300); - AAC_INIT_VLC_STATIC( 4, 328); - AAC_INIT_VLC_STATIC( 5, 294); - AAC_INIT_VLC_STATIC( 6, 306); - AAC_INIT_VLC_STATIC( 7, 268); - AAC_INIT_VLC_STATIC( 8, 510); - AAC_INIT_VLC_STATIC( 9, 366); - AAC_INIT_VLC_STATIC(10, 462); - - ff_aac_sbr_init(); - - avpriv_float_dsp_init(&ac->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); + avpriv_float_dsp_init(&ac->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT); ac->random_state = 0x1f2e3d4c; - ff_aac_tableinit(); - - INIT_VLC_STATIC(&vlc_scalefactors, 7, - FF_ARRAY_ELEMS(ff_aac_scalefactor_code), - ff_aac_scalefactor_bits, - sizeof(ff_aac_scalefactor_bits[0]), - sizeof(ff_aac_scalefactor_bits[0]), - ff_aac_scalefactor_code, - sizeof(ff_aac_scalefactor_code[0]), - sizeof(ff_aac_scalefactor_code[0]), - 352); - ff_mdct_init(&ac->mdct, 11, 1, 1.0 / (32768.0 * 1024.0)); ff_mdct_init(&ac->mdct_ld, 10, 1, 1.0 / (32768.0 * 512.0)); ff_mdct_init(&ac->mdct_small, 8, 1, 1.0 / (32768.0 * 128.0)); @@ -1073,15 +1108,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; - // window initialization - ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); - ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); - ff_init_ff_sine_windows(10); - ff_init_ff_sine_windows( 9); - ff_init_ff_sine_windows( 7); - - cbrt_tableinit(); - return 0; } @@ -1220,8 +1246,7 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, return AVERROR_INVALIDDATA; } else { if (aot == AOT_ER_AAC_LD) { - av_log(ac->avctx, AV_LOG_ERROR, - "LTP in ER AAC LD not yet implemented.\n"); + avpriv_report_missing_feature(ac->avctx, "LTP in ER AAC LD"); return AVERROR_PATCHWELCOME; } if ((ics->ltp.present = get_bits(gb, 1))) @@ -1890,8 +1915,8 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, avpriv_request_sample(ac->avctx, "SSR"); return AVERROR_PATCHWELCOME; } - // I see no textual basis in the spec for this occuring after SSR gain - // control, but this is what both reference and real implmentations do + // I see no textual basis in the spec for this occurring after SSR gain + // control, but this is what both reference and real implementations do if (tns->present && er_syntax) if (decode_tns(ac, tns, gb, ics) < 0) return AVERROR_INVALIDDATA; @@ -2680,7 +2705,7 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) uint8_t layout_map[MAX_ELEM_ID*4][3]; int layout_map_tags, ret; - size = avpriv_aac_parse_header(gb, &hdr_info); + size = ff_adts_header_parse(gb, &hdr_info); if (size > 0) { if (hdr_info.num_aac_frames != 1) { avpriv_report_missing_feature(ac->avctx, @@ -2743,7 +2768,7 @@ static int aac_decode_er_frame(AVCodecContext *avctx, void *data, ac->tags_mapped = 0; - if (chan_config < 0 || chan_config >= 8) { + if (chan_config < 0 || (chan_config >= 8 && chan_config < 11) || chan_config >= 13) { avpriv_request_sample(avctx, "Unknown ER channel configuration %d", chan_config); return AVERROR_INVALIDDATA; @@ -2807,8 +2832,9 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, } } - if ((err = frame_configure_elements(avctx)) < 0) - goto fail; + if (avctx->channels) + if ((err = frame_configure_elements(avctx)) < 0) + goto fail; // The FF_PROFILE_AAC_* defines are all object_type - 1 // This may lead to an undefined profile being signaled @@ -2819,6 +2845,11 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, while ((elem_type = get_bits(gb, 3)) != TYPE_END) { elem_id = get_bits(gb, 4); + if (!avctx->channels && elem_type != TYPE_PCE) { + err = AVERROR_INVALIDDATA; + goto fail; + } + if (elem_type < TYPE_DSE) { if (!(che=get_che(ac, elem_type, elem_id))) { av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", @@ -2905,6 +2936,11 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, } } + if (!avctx->channels) { + *got_frame_ptr = 0; + return 0; + } + spectral_to_sample(ac); multiplier = (ac->oc[1].m4ac.sbr == 1) ? ac->oc[1].m4ac.ext_sample_rate > ac->oc[1].m4ac.sample_rate : 0; @@ -2946,7 +2982,7 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data, if (new_extradata) { av_free(avctx->extradata); avctx->extradata = av_mallocz(new_extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); + AV_INPUT_BUFFER_PADDING_SIZE); if (!avctx->extradata) return AVERROR(ENOMEM); avctx->extradata_size = new_extradata_size; @@ -3010,7 +3046,7 @@ static av_cold int aac_decode_close(AVCodecContext *avctx) struct LATMContext { AACContext aac_ctx; ///< containing AACContext - int initialized; ///< initilized after a valid extradata was seen + int initialized; ///< initialized after a valid extradata was seen // parser data int audio_mux_version_A; ///< LATM syntax version @@ -3066,14 +3102,14 @@ static int latm_decode_audio_specific_config(struct LATMContext *latmctx, if (avctx->extradata_size < esize) { av_free(avctx->extradata); - avctx->extradata = av_malloc(esize + FF_INPUT_BUFFER_PADDING_SIZE); + avctx->extradata = av_malloc(esize + AV_INPUT_BUFFER_PADDING_SIZE); if (!avctx->extradata) return AVERROR(ENOMEM); } avctx->extradata_size = esize; memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize); - memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE); + memset(avctx->extradata+esize, 0, AV_INPUT_BUFFER_PADDING_SIZE); } skip_bits_long(gb, bits_consumed); @@ -3192,7 +3228,7 @@ static int read_audio_mux_element(struct LATMContext *latmctx, } else if (!latmctx->aac_ctx.avctx->extradata) { av_log(latmctx->aac_ctx.avctx, AV_LOG_DEBUG, "no decoder config found\n"); - return AVERROR(EAGAIN); + return 1; } if (latmctx->audio_mux_version_A == 0) { int mux_slot_length_bytes = read_payload_length_info(latmctx, gb); @@ -3229,8 +3265,8 @@ static int latm_decode_frame(AVCodecContext *avctx, void *out, if (muxlength > avpkt->size) return AVERROR_INVALIDDATA; - if ((err = read_audio_mux_element(latmctx, &gb)) < 0) - return err; + if ((err = read_audio_mux_element(latmctx, &gb))) + return (err < 0) ? err : avpkt->size; if (!latmctx->initialized) { if (!avctx->extradata) { @@ -3295,7 +3331,8 @@ AVCodec ff_aac_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, - .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1, + .capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, .channel_layouts = aac_channel_layout, }; @@ -3316,6 +3353,7 @@ AVCodec ff_aac_latm_decoder = { .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, - .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1, + .capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, .channel_layouts = aac_channel_layout, };