From patchwork Wed Dec 8 01:06:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32138 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7046552iog; Tue, 7 Dec 2021 17:11:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxbAwb1qmgr/FbndUsttyz3zKYoc8ugwH05sggIAHp4y4PlkR8klj0kvSsS5DLkyTcmD2n X-Received: by 2002:a17:907:3e0a:: with SMTP id hp10mr3594508ejc.318.1638925886259; Tue, 07 Dec 2021 17:11:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925886; cv=none; d=google.com; s=arc-20160816; b=fjcHJ6KCmSLyY8mEACk4DKle+bLaavq+gGTxdJMKLEv8X3L95af10PKJ34hPCjJFS9 44FsvDNYU4ikj0Qv+BEFMKeVy38eOp/fEuVYT75L0dc5LiH8HkXHKqEDc1IXuDfx5OXB 3sWlq6o2JOZA2UtqyDBe8CYRx7AVqX02oqtnv+s441Q7rmA9jUxXcg67t4qs7Pynshki MCkAtr6T50e+jEO+0CLateETQXqgTqSiPKQRDmGTJicNlnUKSfko3Z3qaTe30mU/Jdyb qkvUBNaoi93TkU8RkipeD1kJEuMCJQuUaI4ykbjpvVoxQPYWwvcmXewnkWyugVNR2VNO j8UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=xraH7jSkAT0xvagAWBB5mud8Lfht5UZdEdqjAeb3VsA=; b=N0Bmzct+As0h0wnZBImU1yqJNni9jWTCqe2VMdTymvuzOjvvdcoHS/EFlacF/BuiQw K6BK9nq5k+9Gh6BUllf47Ks7gxNbKULPLKrpmQi+qalyFxdqHo3KV8LoiID6r7yW1vT2 RvBmUoNAVw7rapTsL15dBx6JDXWWAQTmHF2afIRDMOh09VFrsZcFCtP1mvj1vqa2HYhk IK7l+Eo+fgPaNfp5lMWvfEl7JObZVexbGMJ6FMnqaIO0aYsx67ToIFsL2jANWiQMo/UM em26a5oMRYBbiIMJ31yhrkDIAU533DyaLiwbAXnbKRggelHBtr8nsDKKmO+RM1EV4qdX 94hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=GUGbKjJw; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n11si3081116edx.213.2021.12.07.17.11.22; Tue, 07 Dec 2021 17:11:26 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=GUGbKjJw; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F33E468AF41; Wed, 8 Dec 2021 03:08:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6140D68AF19 for ; Wed, 8 Dec 2021 03:07:56 +0200 (EET) Received: by mail-ua1-f42.google.com with SMTP id l24so1953748uak.2 for ; Tue, 07 Dec 2021 17:07:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Lc/HqNR0Fs/vXJOgVxEklNDH/XJWxn/YiDS0VKilHBc=; b=GUGbKjJwRtE6tcAV3JrlTCNEvQRdR2gnrBoOEx99j3PQ4Coa7rimX/GzBWZzIty4zS dRy8QEwejU0GQVAwGwRCjdTIwldGyywMRUwzkRlAHS3T46znNGphA4t6AlCLioliFjoF dPYXfklJ8ThDQOUp+xGNevuiwRLSzAnfWvO5fMU8LGoki4V4m+sVsQzrhscUKanI0HXS Ttf5cnJFQheVn5KJoul709a40H3iWzqvSfHw8Tne+HMQTRGW1W8Zy82hYADWaIwhg6ka d+1utpCZWR094X6h0ByBKUY+P049FAjLpx0rlrRBx29BpX1/lVyiFZxLw83M5tYBVcBT cYWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lc/HqNR0Fs/vXJOgVxEklNDH/XJWxn/YiDS0VKilHBc=; b=y1KIRVFfM6CACM9giXhb8NWTnlFN0HN7ydsuLuGMJZ3gxqZ4EeUdou/nM7AjTyuW60 M/HrWOIEmty9+yXilaP/n14OcojeKu6l7DTzvhh8K0TVcS8oU6iXPIZpS/G6GEaWP1L9 z2XVY0jj/zH3+DNmXRiHt/n2TbHg2Q+1EWU+C3qmcBiCqUmsPee2L75NOOqvK/KvNCBT RkeBW17ZmQf1+GxS6xkK9VBWrRCiYrB+OEGJsDm2r2jP5SWD/Qy14LgTf3KTXdpYUhy7 APEctUZ9snny/AorF9xMkC+ZxPjUjP+cUAzArCSUXn+gAcUJQbJMCAJesW7a5a52MO7f JSKg== X-Gm-Message-State: AOAM531tI0cqce+x3hryywj02eI0+vYr5vXmya7aSbRdlRQv1R9rEMNU W+qRL64ZijGaDxgMTijFJULLZAfc+hgCyyG0 X-Received: by 2002:a05:6102:cd1:: with SMTP id g17mr50563964vst.55.1638925674303; Tue, 07 Dec 2021 17:07:54 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:53 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:37 -0300 Message-Id: <20211208010649.381-22-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 182/279] ac3: convert to new channel layout API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ft2mU4hzCubD From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/aac_ac3_parser.c | 6 +++ libavcodec/ac3dec.c | 57 +++++++++++++++++---------- libavcodec/ac3dec.h | 2 + libavcodec/ac3dec_fixed.c | 1 + libavcodec/ac3dec_float.c | 2 + libavcodec/ac3enc.c | 78 +++++++++++++++++++++++++++++-------- libavcodec/ac3enc.h | 4 +- libavcodec/ac3enc_fixed.c | 5 +++ libavcodec/ac3enc_float.c | 5 +++ libavcodec/eac3enc.c | 5 +++ tests/fate/ac3.mak | 16 ++++---- 11 files changed, 135 insertions(+), 46 deletions(-) diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c index cd54a0a3e2..4ce7a73972 100644 --- a/libavcodec/aac_ac3_parser.c +++ b/libavcodec/aac_ac3_parser.c @@ -97,6 +97,12 @@ get_next: avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; avctx->ch_layout.nb_channels = s->channels; } +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + avctx->channels = avctx->ch_layout.nb_channels; + avctx->channel_layout = s->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } s1->duration = s->samples; avctx->audio_service_type = s->service_type; diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index c7deb56e1c..309f11cec2 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -32,6 +32,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/crc.h" #include "libavutil/downmix_info.h" +#include "libavutil/intmath.h" #include "libavutil/opt.h" #include "libavutil/thread.h" #include "bswapdsp.h" @@ -186,6 +187,8 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) { static AVOnce init_static_once = AV_ONCE_INIT; AC3DecodeContext *s = avctx->priv_data; + const AVChannelLayout mono = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; + const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; int i, ret; s->avctx = avctx; @@ -214,12 +217,23 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; /* allow downmixing to stereo or mono */ - if (avctx->channels > 1 && - avctx->request_channel_layout == AV_CH_LAYOUT_MONO) - avctx->channels = 1; - else if (avctx->channels > 2 && - avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) - avctx->channels = 2; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channel_layout) { + av_channel_layout_uninit(&s->downmix_layout); + av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout); + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (avctx->ch_layout.nb_channels > 1 && + !av_channel_layout_compare(&s->downmix_layout, &mono)) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; + } else if (avctx->ch_layout.nb_channels > 2 && + !av_channel_layout_compare(&s->downmix_layout, &stereo)) { + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; + } s->downmixed = 1; for (i = 0; i < AC3_MAX_CHANNELS; i++) { @@ -1480,6 +1494,7 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, const SHORTFLOAT *output[AC3_MAX_CHANNELS]; enum AVMatrixEncoding matrix_encoding; AVDownmixInfo *downmix_info; + uint64_t mask; s->superframe_size = 0; @@ -1590,11 +1605,11 @@ dependent_frame: if (s->lfe_on) s->output_mode |= AC3_OUTPUT_LFEON; if (s->channels > 1 && - avctx->request_channel_layout == AV_CH_LAYOUT_MONO) { + !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO)) { s->out_channels = 1; s->output_mode = AC3_CHMODE_MONO; } else if (s->channels > 2 && - avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) { + !av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) { s->out_channels = 2; s->output_mode = AC3_CHMODE_STEREO; } @@ -1615,10 +1630,13 @@ dependent_frame: av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n"); return AVERROR_INVALIDDATA; } - avctx->channels = s->out_channels; - avctx->channel_layout = avpriv_ac3_channel_layout_tab[s->output_mode & ~AC3_OUTPUT_LFEON]; + + mask = avpriv_ac3_channel_layout_tab[s->output_mode & ~AC3_OUTPUT_LFEON]; if (s->output_mode & AC3_OUTPUT_LFEON) - avctx->channel_layout |= AV_CH_LOW_FREQUENCY; + mask |= AV_CH_LOW_FREQUENCY; + + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, mask); /* set audio service type based on bitstream mode for AC-3 */ avctx->audio_service_type = s->bitstream_mode; @@ -1714,20 +1732,20 @@ skip: channel_layout |= ff_eac3_custom_channel_map_locations[ch][1]; } } - if (av_get_channel_layout_nb_channels(channel_layout) > EAC3_MAX_CHANNELS) { + if (av_popcount64(channel_layout) > EAC3_MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Too many channels (%d) coded\n", - av_get_channel_layout_nb_channels(channel_layout)); + av_popcount64(channel_layout)); return AVERROR_INVALIDDATA; } - avctx->channel_layout = channel_layout; - avctx->channels = av_get_channel_layout_nb_channels(channel_layout); + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, channel_layout); for (ch = 0; ch < EAC3_MAX_CHANNELS; ch++) { if (s->channel_map & (1 << (EAC3_MAX_CHANNELS - ch - 1))) { if (ff_eac3_custom_channel_map_locations[ch][0]) { - int index = av_get_channel_layout_channel_index(channel_layout, - ff_eac3_custom_channel_map_locations[ch][1]); + int index = av_channel_layout_index_from_channel(&avctx->ch_layout, + ff_ctzll(ff_eac3_custom_channel_map_locations[ch][1])); if (index < 0) return AVERROR_INVALIDDATA; if (extend >= channel_map_size) @@ -1739,8 +1757,7 @@ skip: for (i = 0; i < 64; i++) { if ((1ULL << i) & ff_eac3_custom_channel_map_locations[ch][1]) { - int index = av_get_channel_layout_channel_index(channel_layout, - 1ULL << i); + int index = av_channel_layout_index_from_channel(&avctx->ch_layout, i); if (index < 0) return AVERROR_INVALIDDATA; if (extend >= channel_map_size) @@ -1759,7 +1776,7 @@ skip: if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - for (ch = 0; ch < avctx->channels; ch++) { + for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) { int map = extended_channel_map[ch]; av_assert0(ch>=AV_NUM_DATA_POINTERS || frame->extended_data[ch] == frame->data[ch]); memcpy((SHORTFLOAT *)frame->extended_data[ch], diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index 85653990cf..9444124974 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -251,6 +251,8 @@ typedef struct AC3DecodeContext { DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread DECLARE_ALIGNED(32, SHORTFLOAT, output_buffer)[EAC3_MAX_CHANNELS][AC3_BLOCK_SIZE * 6]; ///< final output buffer ///@} + + AVChannelLayout downmix_layout; } AC3DecodeContext; /** diff --git a/libavcodec/ac3dec_fixed.c b/libavcodec/ac3dec_fixed.c index 8645952621..ae433c5cc7 100644 --- a/libavcodec/ac3dec_fixed.c +++ b/libavcodec/ac3dec_fixed.c @@ -157,6 +157,7 @@ static const AVOption options[] = { { "cons_noisegen", "enable consistent noise generation", OFFSET(consistent_noise_generation), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR }, { "heavy_compr", "enable heavy dynamic range compression", OFFSET(heavy_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR }, + { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR }, { NULL}, }; diff --git a/libavcodec/ac3dec_float.c b/libavcodec/ac3dec_float.c index 573fbe75b6..2b1b359a0c 100644 --- a/libavcodec/ac3dec_float.c +++ b/libavcodec/ac3dec_float.c @@ -43,6 +43,8 @@ static const AVOption options[] = { {"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, {"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, + { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR }, + { NULL}, }; diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 034aa0beb9..30ba8bfecd 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -147,6 +147,7 @@ static uint8_t exponent_group_tab[2][3][256]; /** * List of supported channel layouts. */ +#if FF_API_OLD_CHANNEL_LAYOUT const uint64_t ff_ac3_channel_layouts[19] = { AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, @@ -168,6 +169,47 @@ const uint64_t ff_ac3_channel_layouts[19] = { AV_CH_LAYOUT_5POINT1_BACK, 0 }; +#endif + +const AVChannelLayout ff_ac3_ch_layouts[19] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_2_1, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_2_2, + AV_CHANNEL_LAYOUT_QUAD, + AV_CHANNEL_LAYOUT_4POINT0, + AV_CHANNEL_LAYOUT_5POINT0, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + { + .nb_channels = 2, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_MONO | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 3, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_STEREO | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 4, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_2_1 | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 4, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_SURROUND | AV_CH_LOW_FREQUENCY, + }, + { + .nb_channels = 5, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_4POINT0 | AV_CH_LOW_FREQUENCY, + }, + AV_CHANNEL_LAYOUT_5POINT1, + AV_CHANNEL_LAYOUT_5POINT1_BACK, + { 0 }, +}; /** * Table to remap channels from SMPTE order to AC-3 order. @@ -1797,7 +1839,7 @@ static void dprint_options(AC3EncodeContext *s) } ff_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id); ff_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt)); - av_get_channel_layout_string(strbuf, 32, s->channels, avctx->channel_layout); + av_channel_layout_describe(&avctx->ch_layout, strbuf, sizeof(strbuf)); ff_dlog(avctx, "channel_layout: %s\n", strbuf); ff_dlog(avctx, "sample_rate: %d\n", s->sample_rate); ff_dlog(avctx, "bit_rate: %d\n", s->bit_rate); @@ -2041,11 +2083,11 @@ int ff_ac3_validate_metadata(AC3EncodeContext *s) /* validate audio service type / channels combination */ if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE && - avctx->channels == 1) || + avctx->ch_layout.nb_channels == 1) || ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY || avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY || avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER) - && avctx->channels > 1)) { + && avctx->ch_layout.nb_channels > 1)) { av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the " "specified number of channels\n"); return AVERROR(EINVAL); @@ -2167,27 +2209,29 @@ av_cold int ff_ac3_encode_close(AVCodecContext *avctx) /* * Set channel information during initialization. */ -static av_cold int set_channel_info(AC3EncodeContext *s, int channels, - uint64_t *channel_layout) +static av_cold int set_channel_info(AVCodecContext *avctx) { - int ch_layout; + AC3EncodeContext *s = avctx->priv_data; + int channels = avctx->ch_layout.nb_channels; + uint64_t mask = avctx->ch_layout.u.mask; if (channels < 1 || channels > AC3_MAX_CHANNELS) return AVERROR(EINVAL); - if (*channel_layout > 0x7FF) + if (mask > 0x7FF) return AVERROR(EINVAL); - ch_layout = *channel_layout; - if (!ch_layout) - ch_layout = av_get_default_channel_layout(channels); - s->lfe_on = !!(ch_layout & AV_CH_LOW_FREQUENCY); + if (!mask) + av_channel_layout_default(&avctx->ch_layout, channels); + mask = avctx->ch_layout.u.mask; + + s->lfe_on = !!(mask & AV_CH_LOW_FREQUENCY); s->channels = channels; s->fbw_channels = channels - s->lfe_on; s->lfe_channel = s->lfe_on ? s->fbw_channels + 1 : -1; if (s->lfe_on) - ch_layout -= AV_CH_LOW_FREQUENCY; + mask -= AV_CH_LOW_FREQUENCY; - switch (ch_layout) { + switch (mask) { case AV_CH_LAYOUT_MONO: s->channel_mode = AC3_CHMODE_MONO; break; case AV_CH_LAYOUT_STEREO: s->channel_mode = AC3_CHMODE_STEREO; break; case AV_CH_LAYOUT_SURROUND: s->channel_mode = AC3_CHMODE_3F; break; @@ -2204,9 +2248,9 @@ static av_cold int set_channel_info(AC3EncodeContext *s, int channels, s->has_surround = s->channel_mode & 0x04; s->channel_map = ac3_enc_channel_map[s->channel_mode][s->lfe_on]; - *channel_layout = ch_layout; if (s->lfe_on) - *channel_layout |= AV_CH_LOW_FREQUENCY; + mask |= AV_CH_LOW_FREQUENCY; + av_channel_layout_from_mask(&avctx->ch_layout, mask); return 0; } @@ -2218,12 +2262,12 @@ static av_cold int validate_options(AC3EncodeContext *s) int i, ret, max_sr; /* validate channel layout */ - if (!avctx->channel_layout) { + if (!avctx->ch_layout.nb_channels) { av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The " "encoder will guess the layout, but it " "might be incorrect.\n"); } - ret = set_channel_info(s, avctx->channels, &avctx->channel_layout); + ret = set_channel_info(avctx); if (ret) { av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n"); return ret; diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index ec9ead8a4e..895b375936 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -265,8 +265,10 @@ typedef struct AC3EncodeContext { void (*output_frame_header)(struct AC3EncodeContext *s); } AC3EncodeContext; - +#if FF_API_OLD_CHANNEL_LAYOUT extern const uint64_t ff_ac3_channel_layouts[19]; +#endif +extern const AVChannelLayout ff_ac3_ch_layouts[19]; extern const AVOption ff_ac3_enc_options[]; extern const AVClass ff_ac3enc_class; extern const AVCodecDefault ff_ac3_enc_defaults[]; diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c index 80aa98c691..6e0abf4a26 100644 --- a/libavcodec/ac3enc_fixed.c +++ b/libavcodec/ac3enc_fixed.c @@ -119,6 +119,7 @@ static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx) } +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_ac3_fixed_encoder = { .name = "ac3_fixed", .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), @@ -134,6 +135,10 @@ const AVCodec ff_ac3_fixed_encoder = { .priv_class = &ff_ac3enc_class, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, .supported_samplerates = ff_ac3_sample_rate_tab, +#if FF_API_OLD_CHANNEL_LAYOUT .channel_layouts = ff_ac3_channel_layouts, +#endif + .ch_layouts = ff_ac3_ch_layouts, .defaults = ff_ac3_enc_defaults, }; +FF_ENABLE_DEPRECATION_WARNINGS diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c index e4a3794dd8..0e605cdf2c 100644 --- a/libavcodec/ac3enc_float.c +++ b/libavcodec/ac3enc_float.c @@ -123,6 +123,7 @@ av_cold int ff_ac3_float_encode_init(AVCodecContext *avctx) return ff_ac3_encode_init(avctx); } +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_ac3_encoder = { .name = "ac3", .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), @@ -137,7 +138,11 @@ const AVCodec ff_ac3_encoder = { AV_SAMPLE_FMT_NONE }, .priv_class = &ff_ac3enc_class, .supported_samplerates = ff_ac3_sample_rate_tab, +#if FF_API_OLD_CHANNEL_LAYOUT .channel_layouts = ff_ac3_channel_layouts, +#endif + .ch_layouts = ff_ac3_ch_layouts, .defaults = ff_ac3_enc_defaults, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; +FF_ENABLE_DEPRECATION_WARNINGS diff --git a/libavcodec/eac3enc.c b/libavcodec/eac3enc.c index 96ef00ea4f..c959aec55c 100644 --- a/libavcodec/eac3enc.c +++ b/libavcodec/eac3enc.c @@ -248,6 +248,7 @@ void ff_eac3_output_frame_header(AC3EncodeContext *s) } +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_eac3_encoder = { .name = "eac3", .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"), @@ -262,7 +263,11 @@ const AVCodec ff_eac3_encoder = { AV_SAMPLE_FMT_NONE }, .priv_class = &eac3enc_class, .supported_samplerates = ff_ac3_sample_rate_tab, +#if FF_API_OLD_CHANNEL_LAYOUT .channel_layouts = ff_ac3_channel_layouts, +#endif + .ch_layouts = ff_ac3_ch_layouts, .defaults = ff_ac3_enc_defaults, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, }; +FF_ENABLE_DEPRECATION_WARNINGS diff --git a/tests/fate/ac3.mak b/tests/fate/ac3.mak index 39b555161d..f0c3d18049 100644 --- a/tests/fate/ac3.mak +++ b/tests/fate/ac3.mak @@ -6,13 +6,13 @@ FATE_AC3 += fate-ac3-4.0 fate-ac3-4.0: CMD = pcm -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-4.0: REF = $(SAMPLES)/ac3/millers_crossing_4.0_v2.pcm -#request_channel_layout 4 -> front channel +#downmix 4.0 -> front channel FATE_AC3 += fate-ac3-4.0-downmix-mono -fate-ac3-4.0-downmix-mono: CMD = pcm -request_channel_layout 4 -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 +fate-ac3-4.0-downmix-mono: CMD = pcm -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm FATE_AC3 += fate-ac3-4.0-downmix-stereo -fate-ac3-4.0-downmix-stereo: CMD = pcm -request_channel_layout stereo -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 +fate-ac3-4.0-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-4.0-downmix-stereo: REF = $(SAMPLES)/ac3/millers_crossing_4.0_stereo_v2.pcm FATE_AC3 += fate-ac3-5.1 @@ -20,11 +20,11 @@ fate-ac3-5.1: CMD = pcm -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_v2.pcm FATE_AC3 += fate-ac3-5.1-downmix-mono -fate-ac3-5.1-downmix-mono: CMD = pcm -request_channel_layout FC -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-5.1-downmix-mono: CMD = pcm -downmix FC -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm FATE_AC3 += fate-ac3-5.1-downmix-stereo -fate-ac3-5.1-downmix-stereo: CMD = pcm -request_channel_layout 2c -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-5.1-downmix-stereo: CMD = pcm -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm FATE_AC3 += fate-ac3-fixed-2.0 @@ -32,15 +32,15 @@ fate-ac3-fixed-2.0: CMD = pcm -c ac3_fixed -i $(TARGET_SAMPLES)/ac3/monsters_inc fate-ac3-fixed-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small_v2.pcm FATE_AC3 += fate-ac3-fixed-4.0-downmix-mono -fate-ac3-fixed-4.0-downmix-mono: CMD = pcm -c ac3_fixed -request_channel_layout mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 +fate-ac3-fixed-4.0-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/millers_crossing_4.0.ac3 fate-ac3-fixed-4.0-downmix-mono: REF = $(SAMPLES)/ac3/millers_crossing_4.0_mono_v2.pcm FATE_AC3 += fate-ac3-fixed-5.1-downmix-mono -fate-ac3-fixed-5.1-downmix-mono: CMD = pcm -c ac3_fixed -request_channel_layout 4 -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-fixed-5.1-downmix-mono: CMD = pcm -c ac3_fixed -downmix mono -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-fixed-5.1-downmix-mono: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_mono_v2.pcm FATE_AC3 += fate-ac3-fixed-5.1-downmix-stereo -fate-ac3-fixed-5.1-downmix-stereo: CMD = pcm -c ac3_fixed -request_channel_layout 3 -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +fate-ac3-fixed-5.1-downmix-stereo: CMD = pcm -c ac3_fixed -downmix stereo -i $(TARGET_SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 fate-ac3-fixed-5.1-downmix-stereo: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small_stereo_v2.pcm FATE_EAC3 += fate-eac3-1