From b2af4bc807cfc62d61213c6050aac26ec8a1e675 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 29 May 2019 08:13:23 +0200 Subject: dca: convert to new channel layout API Signed-off-by: James Almer --- libavcodec/dcadec.c | 71 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 21 deletions(-) (limited to 'libavcodec/dcadec.c') diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c index 49b52f805f..3fc9b35699 100644 --- a/libavcodec/dcadec.c +++ b/libavcodec/dcadec.c @@ -43,13 +43,17 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask 13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4, 5, }; + DCAContext *s = avctx->priv_data; + int dca_ch, wav_ch, nchannels = 0; - if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) { + av_channel_layout_uninit(&avctx->ch_layout); + if (s->output_channel_order == CHANNEL_ORDER_CODED) { for (dca_ch = 0; dca_ch < DCA_SPEAKER_COUNT; dca_ch++) if (dca_mask & (1U << dca_ch)) ch_remap[nchannels++] = dca_ch; - avctx->channel_layout = dca_mask; + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = nchannels; } else { int wav_mask = 0; int wav_map[18]; @@ -71,10 +75,18 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask for (wav_ch = 0; wav_ch < 18; wav_ch++) if (wav_mask & (1 << wav_ch)) ch_remap[nchannels++] = wav_map[wav_ch]; - avctx->channel_layout = wav_mask; + + av_channel_layout_from_mask(&avctx->ch_layout, wav_mask); } - avctx->channels = nchannels; +#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 + return nchannels; } @@ -350,23 +362,28 @@ static av_cold int dcadec_init(AVCodecContext *avctx) s->crctab = av_crc_get_table(AV_CRC_16_CCITT); - switch (avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE) { - case 0: - s->request_channel_layout = 0; - break; - case AV_CH_LAYOUT_STEREO: - case AV_CH_LAYOUT_STEREO_DOWNMIX: - s->request_channel_layout = DCA_SPEAKER_LAYOUT_STEREO; - break; - case AV_CH_LAYOUT_5POINT0: - s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT0; - break; - case AV_CH_LAYOUT_5POINT1: - s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT1; - break; - default: - av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n"); - break; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) + s->output_channel_order = CHANNEL_ORDER_CODED; + + if (avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE) { + av_channel_layout_uninit(&s->downmix_layout); + av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + if (s->downmix_layout.nb_channels) { + if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) || + !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)) + s->request_channel_layout = DCA_SPEAKER_LAYOUT_STEREO; + else if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) + s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT0; + else if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) + s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT1; + else + av_log(avctx, AV_LOG_WARNING, "Invalid downmix layout\n"); } ff_thread_once(&init_static_once, dcadec_init_static); @@ -379,6 +396,18 @@ static av_cold int dcadec_init(AVCodecContext *avctx) static const AVOption dcadec_options[] = { { "core_only", "Decode core only without extensions", OFFSET(core_only), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, PARAM }, + + { "channel_order", "Order in which the channels are to be exported", + OFFSET(output_channel_order), AV_OPT_TYPE_INT, + { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, PARAM, "channel_order" }, + { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST, + { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = PARAM, "channel_order" }, + { "coded", "order in which the channels are coded in the bitstream", + 0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = PARAM, "channel_order" }, + + { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), + AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PARAM }, + { NULL } }; -- cgit v1.2.3