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 B9337405B3 for ; Fri, 25 Feb 2022 11:46:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F24F68B349; Fri, 25 Feb 2022 13:46:14 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D266D68B117 for ; Fri, 25 Feb 2022 13:46:07 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 0F1F1240179 for ; Fri, 25 Feb 2022 12:46:07 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tGLMClvzDsrk for ; Fri, 25 Feb 2022 12:46:02 +0100 (CET) Received: from lain.red.khirnov.net (lain.red.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.red.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id EA0242400F5 for ; Fri, 25 Feb 2022 12:46:01 +0100 (CET) Received: by lain.red.khirnov.net (Postfix, from userid 1000) id 510C21601AD; Fri, 25 Feb 2022 12:46:02 +0100 (CET) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <20220113020518.730-20-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> <20220113020518.730-20-jamrial@gmail.com> Mail-Followup-To: FFmpeg development discussions and patches Date: Fri, 25 Feb 2022 12:46:02 +0100 Message-ID: <164578956230.19727.15993257979019139773@lain.red.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 229/281] libopus: 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: Quoting James Almer (2022-01-13 03:05:08) > From: Anton Khirnov > > Signed-off-by: James Almer > --- > libavcodec/libopusdec.c | 39 +++++++++++++----------- > libavcodec/libopusenc.c | 65 ++++++++++++++++++++++------------------ > libavcodec/vorbis.h | 3 ++ > libavcodec/vorbis_data.c | 18 +++++++++++ > 4 files changed, 79 insertions(+), 46 deletions(-) > > diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c > index 86ef715205..abffd5f463 100644 > --- a/libavcodec/libopusdec.c > +++ b/libavcodec/libopusdec.c > @@ -50,55 +50,60 @@ struct libopus_context { > static av_cold int libopus_decode_init(AVCodecContext *avc) > { > struct libopus_context *opus = avc->priv_data; > - int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled; > + int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled, channels; > uint8_t mapping_arr[8] = { 0, 1 }, *mapping; > > - avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->channels == 1) ? 1 : 2; > - if (avc->channels <= 0) { > + channels = avc->extradata_size >= 10 ? avc->extradata[9] : (channels == 1) ? 1 : 2; ^^^^^^^^ uninitialized read this is meant to use the user-provided value > diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c > index 45b23fcbb5..401a2c17c8 100644 > --- a/libavcodec/libopusenc.c > +++ b/libavcodec/libopusenc.c > @@ -91,7 +91,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count, > const uint8_t *channel_mapping) > { > uint8_t *p = avctx->extradata; > - int channels = avctx->channels; > + int channels = avctx->ch_layout.nb_channels; > > bytestream_put_buffer(&p, "OpusHead", 8); > bytestream_put_byte(&p, 1); /* Version */ > @@ -180,9 +180,9 @@ static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc, > > static int libopus_check_max_channels(AVCodecContext *avctx, > int max_channels) { > - if (avctx->channels > max_channels) { > + if (avctx->ch_layout.nb_channels > max_channels) { > av_log(avctx, AV_LOG_ERROR, "Opus mapping family undefined for %d channels.\n", > - avctx->channels); > + avctx->ch_layout.nb_channels); > return AVERROR(EINVAL); > } > > @@ -190,21 +190,26 @@ static int libopus_check_max_channels(AVCodecContext *avctx, > } > > static int libopus_check_vorbis_layout(AVCodecContext *avctx, int mapping_family) { > - av_assert2(avctx->channels < FF_ARRAY_ELEMS(ff_vorbis_channel_layouts)); > + av_assert2(avctx->ch_layout.nb_channels < FF_ARRAY_ELEMS(ff_vorbis_ch_layouts)); > > - if (!avctx->channel_layout) { > + if (avctx->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { > av_log(avctx, AV_LOG_WARNING, > "No channel layout specified. Opus encoder will use Vorbis " > - "channel layout for %d channels.\n", avctx->channels); > - } else if (avctx->channel_layout != ff_vorbis_channel_layouts[avctx->channels - 1]) { > - char name[32]; > - av_get_channel_layout_string(name, sizeof(name), avctx->channels, > - avctx->channel_layout); > - av_log(avctx, AV_LOG_ERROR, > - "Invalid channel layout %s for specified mapping family %d.\n", > - name, mapping_family); > + "channel layout for %d channels.\n", avctx->ch_layout.nb_channels); > + } else { > + AVChannelLayout chl; > + av_channel_layout_copy(&chl, &ff_vorbis_ch_layouts[avctx->ch_layout.nb_channels - 1]); chl is garbage, while av_channel_layout_copy() uninits it is the copy even necessary? Why not pass ff_vorbis_ch_layouts to compare directly? -- Anton Khirnov _______________________________________________ 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".