From patchwork Wed Dec 8 01:06:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32149 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7047307iog; Tue, 7 Dec 2021 17:12:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMx/gRIj2dXIkNLlSImamCQziZwjaaFNZHwMtwEF5FnY3UOtt7JwFXF4Iy9wgRRrslOLeo X-Received: by 2002:a17:906:81cb:: with SMTP id e11mr3492320ejx.186.1638925933071; Tue, 07 Dec 2021 17:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925933; cv=none; d=google.com; s=arc-20160816; b=gTT8USux0cFxnifA5/agRV7tp/FJt1WCLopT5DxwocmmesRR39pdsBgnUYwffa0vol vOnZFQWFSEWSYiwG0z0wnUhHyoSM5VHvqDNsSxMWNVfh+/iGo9uXSDuxT4iRyb9UDQtR 7zerlQCQ/NebgBLU/JmsqU9qVqG6JAhFsc1UZse1Cte5vz7kG1OAa5HbyPq3+abeIeDo d/OtY2cfU9bpns+Hao5Gf0xktwY4iuYdHMWAVxvnerIJdMFPSo5u9dartqGA/uYNSjyj ygiAVDscyHaN/rbSzHmS81IGeD+RnbkDZluFIB0B+i3kEkzfTrqsc+VOPlDSFMSDy0+8 mltQ== 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=UVQzWWQcW8lzMP7S5X7IB21jtzoTnhkKVxKehswDZdM=; b=LlW1qKKwrxAbmvJ4zFBd7lGxEqIhv17mxYskUzaUPcsy4QICXp9MJrmEtWX2KZsAyK YL3aUk/8R2/5k7hRdQyt1xibCIZ95MLwph+ruN8gOp8qfuTzrx0So6aQDOORszk75ZIP +xOVfCQpQJDc4bT2gyINhJ6kJUIG1Ey1c9BwkuCNYvbxIBfAvLJjZ7s/5RN8IcQUCBdX 0hbXbI3NClrUqdEk1CsN4iqjk3MsLzdHpD/+2SKyqu9sv9hSeb/hgUgwURX4QbCFVIti /Kil9TcpNpiQCXQrxwJpib7n5SRcHIRBywcDeF/EtyR4OX9jyy3d6rpInc6Q6BLzfAcn 1fNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=edX4ht7p; 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 nd9si2747411ejc.154.2021.12.07.17.12.08; Tue, 07 Dec 2021 17:12:13 -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=edX4ht7p; 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 7C95168AF71; Wed, 8 Dec 2021 03:08:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ua1-f51.google.com (mail-ua1-f51.google.com [209.85.222.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA55768AF45 for ; Wed, 8 Dec 2021 03:07:59 +0200 (EET) Received: by mail-ua1-f51.google.com with SMTP id w23so1919887uao.5 for ; Tue, 07 Dec 2021 17:07:59 -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=MUJd3JvZgsGU/NSwl+dok4id6Yy/tniZxXkaxjj3eIQ=; b=edX4ht7pnurrsg6/H64rcbsq4W5HlDKAwEnRWBWN8vDO2DqF8cHXbHcW1PI2X8Mt9C AHoPxw8tlTBt2xMrnqoXCqr7ty80fVpxaOlhFkd+7UtN/35p8mXqnfVHR2PxvrxJG9j+ HVPz2oMXAoelfpdyjO7z/lPQwWtKuw6U0l2xI7CIHElwAXXAdhMkS1zl3jKugHjKjVBO dxO5v4Rm716Iht0ED4G5jrVshwqKnZWv2z20VM3BsYwi9Q0hlzmCqFVF3DknmK839Q2u GU7Zyv3l4+o1kJpY/os9/qbLqracNRFKE9LStOeNyutyYtl+S0rhfMvZqn+qJXhCgvxf ilHA== 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=MUJd3JvZgsGU/NSwl+dok4id6Yy/tniZxXkaxjj3eIQ=; b=iOW7Js+l6+DFNh2qOkLx5jRVEp8K2WqBwQBooE31AeLc6FBkyB12mYLk2sauDdr9Qv hJb1aM0svKYi3U+G7aWtU/Mqnpeker+G61XpD7/+At5un7DRY1Orx5ciljdQrtnH84J6 ZedduClO9iGOry4IuioDSsQ7+Xur/+/955EFY0YoJKi0DI7Md5iMY8NwDLAB0paZma8G 6faExUcoWNCP6TzwItzNz1NiBJnk19+DUbL3THccpyaOGzwrD+LFJPknfkqe3M0AIpG9 GnF9+fZbYKbzmnXvsWkoE8HOZQixi2fn6hT1t6e2qMDO6R9/q8bIvZpQ49LNNhYylGXI JHNA== X-Gm-Message-State: AOAM53079CbQi97UbMMv/pFWqQo8/r3DSlReBEe2pFpsBI8UwF1mDtL6 GMaLs2Z4NaWB4jFe+yhXpOwnRRU8j5VyfqmN X-Received: by 2002:a67:e0c9:: with SMTP id m9mr48770806vsl.63.1638925678202; Tue, 07 Dec 2021 17:07:58 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:57 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:40 -0300 Message-Id: <20211208010649.381-25-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 185/279] alac: 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: WmznoyNBUDj9 From: Anton Khirnov Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavcodec/alac.c | 16 ++++++---------- libavcodec/alac_data.c | 20 ++++++++++---------- libavcodec/alac_data.h | 6 ++++++ libavcodec/alacenc.c | 37 +++++++++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 28 deletions(-) diff --git a/libavcodec/alac.c b/libavcodec/alac.c index 67fc2a3e41..db1e725f66 100644 --- a/libavcodec/alac.c +++ b/libavcodec/alac.c @@ -576,21 +576,17 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) avctx->bits_per_raw_sample = alac->sample_size; avctx->sample_rate = alac->sample_rate; - if (alac->channels < 1) { + if (alac->channels < 1 || alac->channels > ALAC_MAX_CHANNELS) { av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n"); - alac->channels = avctx->channels; - } else { - if (alac->channels > ALAC_MAX_CHANNELS) - alac->channels = avctx->channels; - else - avctx->channels = alac->channels; + alac->channels = avctx->ch_layout.nb_channels; } - if (avctx->channels > ALAC_MAX_CHANNELS || avctx->channels <= 0 ) { + if (avctx->ch_layout.nb_channels > ALAC_MAX_CHANNELS || avctx->ch_layout.nb_channels <= 0 ) { avpriv_report_missing_feature(avctx, "Channel count %d", - avctx->channels); + avctx->ch_layout.nb_channels); return AVERROR_PATCHWELCOME; } - avctx->channel_layout = ff_alac_channel_layouts[alac->channels - 1]; + av_channel_layout_uninit(&avctx->ch_layout); + avctx->ch_layout = ff_alac_ch_layouts[alac->channels - 1]; if ((ret = allocate_buffers(alac)) < 0) { av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n"); diff --git a/libavcodec/alac_data.c b/libavcodec/alac_data.c index 0bcb06c075..d8ed53f444 100644 --- a/libavcodec/alac_data.c +++ b/libavcodec/alac_data.c @@ -32,16 +32,16 @@ const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNEL { 2, 6, 7, 0, 1, 4, 5, 3 } }; -const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = { - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_SURROUND, - AV_CH_LAYOUT_4POINT0, - AV_CH_LAYOUT_5POINT0_BACK, - AV_CH_LAYOUT_5POINT1_BACK, - AV_CH_LAYOUT_6POINT1_BACK, - AV_CH_LAYOUT_7POINT1_WIDE_BACK, - 0 +const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1] = { + 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, + AV_CHANNEL_LAYOUT_6POINT1_BACK, + AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK, + { 0 } }; const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5] = { diff --git a/libavcodec/alac_data.h b/libavcodec/alac_data.h index 650d6dcd15..a68a5f2648 100644 --- a/libavcodec/alac_data.h +++ b/libavcodec/alac_data.h @@ -23,6 +23,8 @@ #include +#include "libavutil/channel_layout.h" + enum AlacRawDataBlockType { /* At the moment, only SCE, CPE, LFE, and END are recognized. */ TYPE_SCE, @@ -39,7 +41,11 @@ enum AlacRawDataBlockType { extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS]; +extern const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1]; + +#if FF_API_OLD_CHANNEL_LAYOUT extern const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1]; +#endif extern const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5]; diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c index a38aa6e7d7..09af0584bc 100644 --- a/libavcodec/alacenc.c +++ b/libavcodec/alacenc.c @@ -462,14 +462,15 @@ static int write_frame(AlacEncodeContext *s, AVPacket *avpkt, uint8_t * const *samples) { PutBitContext *pb = &s->pbctx; - const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[s->avctx->channels - 1]; - const uint8_t *ch_map = ff_alac_channel_layout_offsets[s->avctx->channels - 1]; + int channels = s->avctx->ch_layout.nb_channels; + const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[channels - 1]; + const uint8_t *ch_map = ff_alac_channel_layout_offsets[channels - 1]; int ch, element, sce, cpe; init_put_bits(pb, avpkt->data, avpkt->size); ch = element = sce = cpe = 0; - while (ch < s->avctx->channels) { + while (ch < channels) { if (ch_elements[element] == TYPE_CPE) { write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]], samples[ch_map[ch + 1]]); @@ -532,7 +533,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) s->rc.rice_modifier = 4; s->max_coded_frame_size = get_max_frame_size(avctx->frame_size, - avctx->channels, + avctx->ch_layout.nb_channels, avctx->bits_per_raw_sample); avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); @@ -545,10 +546,10 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c')); AV_WB32(alac_extradata+12, avctx->frame_size); AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample); - AV_WB8 (alac_extradata+21, avctx->channels); + AV_WB8 (alac_extradata+21, avctx->ch_layout.nb_channels); AV_WB32(alac_extradata+24, s->max_coded_frame_size); AV_WB32(alac_extradata+28, - avctx->sample_rate * avctx->channels * avctx->bits_per_raw_sample); // average bitrate + avctx->sample_rate * avctx->ch_layout.nb_channels * avctx->bits_per_raw_sample); // average bitrate AV_WB32(alac_extradata+32, avctx->sample_rate); // Set relevant extradata fields @@ -585,7 +586,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->frame_size = frame->nb_samples; if (frame->nb_samples < DEFAULT_FRAME_SIZE) - max_frame_size = get_max_frame_size(s->frame_size, avctx->channels, + max_frame_size = get_max_frame_size(s->frame_size, avctx->ch_layout.nb_channels, avctx->bits_per_raw_sample); else max_frame_size = s->max_coded_frame_size; @@ -616,6 +617,21 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, return 0; } +#if FF_API_OLD_CHANNEL_LAYOUT +const uint64_t alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = { + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_SURROUND, + AV_CH_LAYOUT_4POINT0, + AV_CH_LAYOUT_5POINT0_BACK, + AV_CH_LAYOUT_5POINT1_BACK, + AV_CH_LAYOUT_6POINT1_BACK, + AV_CH_LAYOUT_7POINT1_WIDE_BACK, + 0 +}; +#endif + + #define OFFSET(x) offsetof(AlacEncodeContext, x) #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { @@ -632,6 +648,7 @@ static const AVClass alacenc_class = { .version = LIBAVUTIL_VERSION_INT, }; +FF_DISABLE_DEPRECATION_WARNINGS const AVCodec ff_alac_encoder = { .name = "alac", .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), @@ -643,9 +660,13 @@ const AVCodec ff_alac_encoder = { .encode2 = alac_encode_frame, .close = alac_encode_close, .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, - .channel_layouts = ff_alac_channel_layouts, +#if FF_API_OLD_CHANNEL_LAYOUT + .channel_layouts = alac_channel_layouts, +#endif + .ch_layouts = ff_alac_ch_layouts, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE }, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, }; +FF_ENABLE_DEPRECATION_WARNINGS