From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6038B42E67 for ; Thu, 13 Jan 2022 02:34:42 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 980B668B62B; Thu, 13 Jan 2022 04:03:16 +0200 (EET) Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F26E068B5E1 for ; Thu, 13 Jan 2022 04:03:05 +0200 (EET) Received: by mail-qv1-f53.google.com with SMTP id q3so5131747qvc.7 for ; Wed, 12 Jan 2022 18:03:05 -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=pPMHVQKGOvlnZKWety3BpMCodDzWQPkU5S0zTs8imk37fBHBGQmjmmYtZ2TjjEqgec SY43zHE1FW5FYK5sTUCUABVJidZ7TtkJqSX1kHVhy6DoKd6ie2Ds1L+ATXU07e8fw4Oc 25C2XsBFp1ocgRDZfHEONwmUzXrfA3ODCGcWKxQtXbNgs6XQKPaIEbvnblFVhgmDq7rh ahfPZ/bkbBNDZh1AC4cp9tUW9soY0MfGwlt8bTeRs7vSWViWr3xvgrTvGVDgFin1/Mqa 9+s39VjgQj0M7vmwcVpO8genAO1cdNUSLfizmN09FOiYZAWkOAMVs/HT7Bcct1gMs1c2 OuPg== 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=Mj2wECyYDrIQjp0NJHztSG+sgSIUFjtz6L9tFl7KjUPhoDQTJm+YkUoXFncF8eeEQE 2JydQSfDp066Etn+Ue/6luTUokkXileXodxHwNG/HaUjPKzzUaY7FfJGeB+kV/3deynx BazwzsXJuDlQNZycw4JDIJsnVKsoXgoufR9aFCLV+GfZGNElzSlujS5XbPPUhZmRZJXf KXLVm9c43iloash7ulu1w2K1PIqGUnJSSncGh7F+8IEf3mckPQ6xqJezWx6US5UEhfOg VYTTg3d5J/uDHk7WebdNTJuVad9lB6B8zUmzlyew013ipClIcwH5TsvvCVINzBEP/E1v VGQw== X-Gm-Message-State: AOAM533AVDGAhBnzKTAf2G6tMPwk8fQxZlqJsWDW8bjdUeX/F3Gn4gWt ahM6GJngkDe/fsy2pFyD9BljRrChucw= X-Google-Smtp-Source: ABdhPJzJ9ilRuOr1JFPym/pJswHqzhJHRzPKDP3wGyW2CS7U5Pivolq+KVbNZ6DVr5jiGWC5zT7Kug== X-Received: by 2002:ad4:5de9:: with SMTP id jn9mr2092358qvb.87.1642039384586; Wed, 12 Jan 2022 18:03:04 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id v1sm1045961qtc.95.2022.01.12.18.03.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:03:04 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:02:19 -0300 Message-Id: <20220113020242.661-7-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 186/281] 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".