From patchwork Thu Jan 13 02:05:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33493 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp41562iog; Wed, 12 Jan 2022 18:41:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjLUuaWM80AFePMQ9VQUEfuRD6FCEQW2F98q+MTOnFoEveo+DMtumVcRDPhEWc/PKg6S5A X-Received: by 2002:a17:907:1b24:: with SMTP id mp36mr1961312ejc.487.1642041697015; Wed, 12 Jan 2022 18:41:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041697; cv=none; d=google.com; s=arc-20160816; b=iUuwzYQrmRanCY7JExTyg6lA0/xyqjSjL6dr98F7dlry6kW6xyFf3Ym0gwauqaJyQp 48YTD+8T1nxe6ug3OpJMRFNYCQ4BsrNod2s72yoSzJY0DVkgaDq7mUz+mgzCAOV+hIHd EiF55HXcSMNZNGDDCJPd/ru5+0TjIZwVJ7ePsOF9vGRWAm/yy62N0pwWOY2Iaovsrq8y Wd350JwLTxB146Pbayl6kC+NtwXMHbiiUqmLldryaRU4uchyuz2qFtn8/pwFuTqoKl97 741d6aFcuVmdSheAW5oZx8VRYGW1yTSJgbyb4xPBP1nBAXSxUYC14nb+jMeESiFJRRPi pi0A== 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=2Cjwj0axNpwIiGztT8aHjRiDjCFxzfHP1vYtcFWX0WQ=; b=KTHeMZJ2lKnzTA4LIedfcqDLPfiUarSOD8zLNt3eh+9JpxP+nJ53EcdObOPxq8HcrL 9Pgy1c91bupST+q1IEAXFTwpphVZ0PACFEoqm2YrEerxQb538uz5dwunfBXdoTAJLSIK h5Q87NY75inEeAG/N2nq6QiLtYTPLwChTsP2S+50RBXEgpwMH2fBc87U+cyF2a75r6l+ rYS31eMgjtbxbPIOxhzfGQj8UKEgqwzwU6D1kqHUz5c8NBtQjl7kUMHXmao3CqBCKD/q e0h80gKWfFy4Qrz9ART4tEEzkYn91UG4CCFYNLlbHuPyJdF960SExNMjNrFgUn5sUIQ+ uHJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=hJQevTb4; 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 p6si791904ejy.187.2022.01.12.18.41.36; Wed, 12 Jan 2022 18:41:37 -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=hJQevTb4; 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 D835F68B8A1; Thu, 13 Jan 2022 04:05:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 167B868B860 for ; Thu, 13 Jan 2022 04:05:50 +0200 (EET) Received: by mail-qt1-f172.google.com with SMTP id h15so984940qtx.0 for ; Wed, 12 Jan 2022 18:05:49 -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=ZzS3l7zCdXcI9/1nF8hnUMTGF5xGAaZjrw60ev0jBuU=; b=hJQevTb4XJt7Jm8k6Y/os7UjBvB3cvLosHXhZpBsDQSblIZsvHx15PlU0RdxJRGvUF wJoRmKjILQTddntZRPeQWx+t3luAKuVp42Pvr/O/EHQS+ucvrx3jFngvHghMdCxGWB6w YWvpUh9R4wUFKV4nnGngmkhkHeJD6GiEeMxH0szO5AjcTIUul9Opq4QuGSDi28X1p4Bf Su9chFIZlMzKRvU7KovqkWn2gwWXhhTdA+Fui92EE410Ei7jWfVTT4Bn/EsuBzHysrol xlSd5fgE7UlWS7B0Lb2U7AzShxIQYtN4FDiOyoPHf49pd5CP4xqgOHCcvGXumlZU9lBh /qdw== 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=ZzS3l7zCdXcI9/1nF8hnUMTGF5xGAaZjrw60ev0jBuU=; b=CLA5cvufv9iqhxoMfJXAL0/q5HiQlKg81JZ2xMcby063TlmZnkWIyRpbt7vfi8WyeB yiYddRYjPRwvbCx1LtbHzpWJsqDD2I61XGxO5zzs1THMW309/3mxa/xxvYEuuZE8Ka8+ tgYNYpPYVuInwr/i6oqVs++pTXDzJNzXvcs+GuOTOVnIu2/hJRwiFgzHdDbozBJwvBxI Ffojyno/BrrHI+SQz1S9pJw9wZ8Re2bvIDQmFjLcgV9ObdF2OQnJPTya/Qb63vddb4ru 5dgUIYQcAemY1Z3FU97RVrWi/U23f+n5Brwhv72Sk9zyB5LhxZAspWfzvcwb6EyQkMmm 3Zyw== X-Gm-Message-State: AOAM533e601Yb6moeGz9ELZ1v874a5TXXqRXmP4S5YRsWD4zxmneGTxV G127uJsBUadkB8XSkz0ZMVvNGoACByA= X-Received: by 2002:a05:622a:148:: with SMTP id v8mr2022090qtw.438.1642039548605; Wed, 12 Jan 2022 18:05:48 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id k9sm1264556qko.29.2022.01.12.18.05.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:05:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:05:03 -0300 Message-Id: <20220113020518.730-15-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 224/281] libfdk-aac: 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: vzkEJ1oFvJgo From: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/libfdk-aacdec.c | 32 ++++++++++++++++++++------------ libavcodec/libfdk-aacenc.c | 35 +++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c index ffa1fdcce3..1a38aefff9 100644 --- a/libavcodec/libfdk-aacdec.c +++ b/libavcodec/libfdk-aacdec.c @@ -58,6 +58,7 @@ typedef struct FDKAACDecContext { int drc_cut; int level_limit; int output_delay; + AVChannelLayout downmix_layout; } FDKAACDecContext; @@ -88,6 +89,7 @@ static const AVOption fdk_aac_dec_options[] = { { "drc_effect","Dynamic Range Control: effect type, where e.g. [0] is none and [6] is general", OFFSET(drc_effect), AV_OPT_TYPE_INT, { .i64 = -1}, -1, 8, AD, NULL }, #endif + { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = AD }, { NULL } }; @@ -197,17 +199,15 @@ static int get_stream_info(AVCodecContext *avctx) ch_error = 1; } } - if (!ch_error && - av_get_channel_layout_nb_channels(ch_layout) != info->numChannels) { + + av_channel_layout_uninit(&avctx->ch_layout); + av_channel_layout_from_mask(&avctx->ch_layout, ch_layout); + if (!ch_error && avctx->ch_layout.nb_channels != info->numChannels) { av_log(avctx, AV_LOG_WARNING, "unsupported channel configuration\n"); ch_error = 1; } if (ch_error) - avctx->channel_layout = 0; - else - avctx->channel_layout = ch_layout; - - avctx->channels = info->numChannels; + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; return 0; } @@ -249,11 +249,19 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx) return AVERROR_UNKNOWN; } - if (avctx->request_channel_layout > 0 && - avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) { +#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 (s->downmix_layout.nb_channels > 0 && + s->downmix_layout.order != AV_CHANNEL_ORDER_NATIVE) { int downmix_channels = -1; - switch (avctx->request_channel_layout) { + switch (s->downmix_layout.u.mask) { case AV_CH_LAYOUT_STEREO: case AV_CH_LAYOUT_STEREO_DOWNMIX: downmix_channels = 2; @@ -262,7 +270,7 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx) downmix_channels = 1; break; default: - av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n"); + av_log(avctx, AV_LOG_WARNING, "Invalid downmix option\n"); break; } @@ -385,7 +393,7 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data, avctx->time_base); memcpy(frame->extended_data[0], s->decoder_buffer, - avctx->channels * avctx->frame_size * + avctx->ch_layout.nb_channels * avctx->frame_size * av_get_bytes_per_sample(avctx->sample_fmt)); *got_frame_ptr = 1; diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 7ee2f13ac7..d43f45d9ee 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -128,7 +128,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) int aot = FF_PROFILE_AAC_LOW + 1; int sce = 0, cpe = 0; - if ((err = aacEncOpen(&s->handle, 0, avctx->channels)) != AACENC_OK) { + if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) { av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n", aac_get_error(err)); goto error; @@ -159,7 +159,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) goto error; } - switch (avctx->channels) { + switch (avctx->ch_layout.nb_channels) { case 1: mode = MODE_1; sce = 1; cpe = 0; break; case 2: #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0 @@ -193,7 +193,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) case 8: sce = 2; cpe = 3; - if (avctx->channel_layout == AV_CH_LAYOUT_7POINT1) { + if (avctx->ch_layout.u.mask == AV_CH_LAYOUT_7POINT1) { mode = MODE_7_1_REAR_SURROUND; } else { // MODE_1_2_2_2_1 and MODE_7_1_FRONT_CENTER use the same channel layout @@ -203,7 +203,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) #endif default: av_log(avctx, AV_LOG_ERROR, - "Unsupported number of channels %d\n", avctx->channels); + "Unsupported number of channels %d\n", avctx->ch_layout.nb_channels); goto error; } @@ -375,9 +375,9 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, in_args.numInSamples = -1; } else { in_ptr = frame->data[0]; - in_buffer_size = 2 * avctx->channels * frame->nb_samples; + in_buffer_size = 2 * avctx->ch_layout.nb_channels * frame->nb_samples; - in_args.numInSamples = avctx->channels * frame->nb_samples; + in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples; /* add current frame to the queue */ if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) @@ -392,7 +392,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, in_buf.bufElSizes = &in_buffer_element_size; /* The maximum packet size is 6144 bits aka 768 bytes per channel. */ - ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->channels)); + ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->ch_layout.nb_channels)); if (ret < 0) return ret; @@ -440,6 +440,7 @@ static const AVCodecDefault aac_encode_defaults[] = { { NULL } }; +#if FF_API_OLD_CHANNEL_LAYOUT static const uint64_t aac_channel_layout[] = { AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, @@ -453,6 +454,21 @@ static const uint64_t aac_channel_layout[] = { #endif 0, }; +#endif /* FF_API_OLD_CHANNEL_LAYOUT */ + +static const AVChannelLayout aac_ch_layouts[16] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_4POINT0, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + AV_CHANNEL_LAYOUT_5POINT1_BACK, +#ifdef AACENCODER_LIB_VL0 + AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK, + AV_CHANNEL_LAYOUT_7POINT1, +#endif + { 0 }, +}; static const int aac_sample_rates[] = { 96000, 88200, 64000, 48000, 44100, 32000, @@ -475,6 +491,9 @@ const AVCodec ff_libfdk_aac_encoder = { .defaults = aac_encode_defaults, .profiles = profiles, .supported_samplerates = aac_sample_rates, - .channel_layouts = aac_channel_layout, .wrapper_name = "libfdk", +#if FF_API_OLD_CHANNEL_LAYOUT + .channel_layouts = aac_channel_layout, +#endif + .ch_layouts = aac_ch_layouts, };