diff options
author | Anton Khirnov <anton@khirnov.net> | 2013-05-07 07:20:32 +0200 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-03-15 09:42:39 -0300 |
commit | 494760f971a41851630d7940abe914cd1115737e (patch) | |
tree | 33e017519b761fc8e6776fdc15b5fca627d02f68 /libavcodec/aacdec_template.c | |
parent | 2350a50bed6bd71c67947604f117a4dff73ebe35 (diff) |
aac: convert to new channel layout API
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/aacdec_template.c')
-rw-r--r-- | libavcodec/aacdec_template.c | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 7149b331ae..387a4acfce 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -174,7 +174,7 @@ static int frame_configure_elements(AVCodecContext *avctx) /* get output buffer */ av_frame_unref(ac->frame); - if (!avctx->channels) + if (!avctx->ch_layout.nb_channels) return 1; ac->frame->nb_samples = 2048; @@ -182,7 +182,7 @@ static int frame_configure_elements(AVCodecContext *avctx) return ret; /* map output channel pointers to AVFrame data */ - for (ch = 0; ch < avctx->channels; ch++) { + for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { if (ac->output_element[ch]) ac->output_element[ch]->ret = (INTFLOAT *)ac->frame->extended_data[ch]; } @@ -517,8 +517,7 @@ static int push_output_configuration(AACContext *ac) { static void pop_output_configuration(AACContext *ac) { if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) { ac->oc[1] = ac->oc[0]; - ac->avctx->channels = ac->oc[1].channels; - ac->avctx->channel_layout = ac->oc[1].channel_layout; + ac->avctx->ch_layout = ac->oc[1].ch_layout; output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, ac->oc[1].status, 0); } @@ -555,7 +554,14 @@ static int output_configure(AACContext *ac, } // Try to sniff a reasonable channel order, otherwise output the // channels in the order the PCE declared them. - if (avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channel_layout == AV_CH_LAYOUT_NATIVE) + ac->output_channel_order = CHANNEL_ORDER_CODED; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + if (ac->output_channel_order == CHANNEL_ORDER_DEFAULT) layout = sniff_channel_order(layout_map, tags); for (i = 0; i < tags; i++) { int type = layout_map[i][0]; @@ -577,9 +583,22 @@ static int output_configure(AACContext *ac, } } - if (layout) avctx->channel_layout = layout; - ac->oc[1].channel_layout = layout; - avctx->channels = ac->oc[1].channels = channels; + av_channel_layout_uninit(&ac->oc[1].ch_layout); + if (layout) + av_channel_layout_from_mask(&ac->oc[1].ch_layout, layout); + else { + ac->oc[1].ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + ac->oc[1].ch_layout.nb_channels = channels; + } + + av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + avctx->channels = avctx->ch_layout.nb_channels; + avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + avctx->ch_layout.u.mask : 0; +FF_ENABLE_DEPRECATION_WARNINGS +#endif ac->oc[1].status = oc_type; if (get_new_frame) { @@ -1292,12 +1311,12 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) sr = sample_rate_idx(avctx->sample_rate); ac->oc[1].m4ac.sampling_index = sr; - ac->oc[1].m4ac.channels = avctx->channels; + ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels; ac->oc[1].m4ac.sbr = -1; ac->oc[1].m4ac.ps = -1; for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) - if (ff_mpeg4audio_channels[i] == avctx->channels) + if (ff_mpeg4audio_channels[i] == avctx->ch_layout.nb_channels) break; if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { i = 0; @@ -1315,7 +1334,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) } } - if (avctx->channels > MAX_CHANNELS) { + if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); return AVERROR_INVALIDDATA; } @@ -2556,7 +2575,8 @@ static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt, av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n"); skip_bits_long(gb, 8 * cnt - 4); return res; - } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED && ac->avctx->channels == 1) { + } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED && + ac->avctx->ch_layout.nb_channels == 1) { ac->oc[1].m4ac.sbr = 1; ac->oc[1].m4ac.ps = 1; ac->avctx->profile = FF_PROFILE_AAC_HE_V2; @@ -3264,7 +3284,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, if (avctx->debug & FF_DEBUG_STARTCODE) av_log(avctx, AV_LOG_DEBUG, "Elem type:%x id:%x\n", elem_type, elem_id); - if (!avctx->channels && elem_type != TYPE_PCE) { + if (!avctx->ch_layout.nb_channels && elem_type != TYPE_PCE) { err = AVERROR_INVALIDDATA; goto fail; } @@ -3385,7 +3405,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, } } - if (!avctx->channels) { + if (!avctx->ch_layout.nb_channels) { *got_frame_ptr = 0; return 0; } @@ -3419,7 +3439,8 @@ static int aac_decode_frame_int(AVCodecContext *avctx, void *data, /* for dual-mono audio (SCE + SCE) */ is_dmono = ac->dmono_mode && sce_count == 2 && - ac->oc[1].channel_layout == (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT); + !av_channel_layout_compare(&ac->oc[1].ch_layout, + &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO); if (is_dmono) { if (ac->dmono_mode == 1) ((AVFrame *)data)->data[1] =((AVFrame *)data)->data[0]; @@ -3553,6 +3574,14 @@ static const AVOption options[] = { {"sub" , "Select Sub/Right channel", 0, AV_OPT_TYPE_CONST, {.i64= 2}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"}, {"both", "Select both channels", 0, AV_OPT_TYPE_CONST, {.i64= 0}, INT_MIN, INT_MAX, AACDEC_FLAGS, "dual_mono_mode"}, + { "channel_order", "Order in which the channels are to be exported", + offsetof(AACContext, output_channel_order), AV_OPT_TYPE_INT, + { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, AACDEC_FLAGS, "channel_order" }, + { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST, + { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = AACDEC_FLAGS, "channel_order" }, + { "coded", "order in which the channels are coded in the bitstream", + 0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = AACDEC_FLAGS, "channel_order" }, + {NULL}, }; |