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 67D02473BE for ; Fri, 5 Jan 2024 16:43:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DDD1F68CD8D; Fri, 5 Jan 2024 18:43:05 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9B04868B4D7 for ; Fri, 5 Jan 2024 18:42:55 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=nmRH/miT; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3D49513BB for ; Fri, 5 Jan 2024 17:42:55 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id g0DiyZBkjTRP for ; Fri, 5 Jan 2024 17:42:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1704472973; bh=c3OuKt4V1Q5nA4xe7OIhSVKSYzdwSh3kbMdwk6sjSfU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nmRH/miT9CS8ac5cjv47PBPGpopbh6/C2e6HMlSIDuA/3JJHmTGLWsbf61E6Cbt4b eO55uXJ7EseBRb3PjlaUKflkoSEVKrEDk+Y6d2Tll5mpnukFme0UnlkwCKTUn8nafl q7SvUwmyDS7Sz69tUl3jMkkZmkd9GoQwxQEnLA45aZB8DV//Bl+e5M0H6kUdAjpwq1 U2bFVpjQCtsvRqLsIlvq3nxbhxoX/0GxjW2JXT6yO2w64id24ooPvMADaiO5WMm/Ui CqFL/S4WosTsjy/wPrCEwbokbMkehYYJI1IDm3f2J4LZaUBQqMspeW5g+qqSLJQqF2 JBrqCaglAVrkQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (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 "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id BB82FA42 for ; Fri, 5 Jan 2024 17:42:53 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6C33A3A061F for ; Fri, 5 Jan 2024 17:42:53 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Jan 2024 17:42:47 +0100 Message-ID: <20240105164251.28935-4-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240105164251.28935-1-anton@khirnov.net> References: <20240105164251.28935-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] fftools/ffmpeg_demux: set options on codec parameters rather than decoder 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: This avoids the requirement to always have a decoder context. --- fftools/ffmpeg_demux.c | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index cacdc76a71..892094c512 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -899,19 +899,18 @@ static int choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream } } -static int guess_input_channel_layout(InputStream *ist, int guess_layout_max) +static int guess_input_channel_layout(InputStream *ist, AVCodecParameters *par, + int guess_layout_max) { - AVCodecContext *dec = ist->dec_ctx; - - if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { + if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { char layout_name[256]; - if (dec->ch_layout.nb_channels > guess_layout_max) + if (par->ch_layout.nb_channels > guess_layout_max) return 0; - av_channel_layout_default(&dec->ch_layout, dec->ch_layout.nb_channels); - if (dec->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + av_channel_layout_default(&par->ch_layout, par->ch_layout.nb_channels); + if (par->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) return 0; - av_channel_layout_describe(&dec->ch_layout, layout_name, sizeof(layout_name)); + av_channel_layout_describe(&par->ch_layout, layout_name, sizeof(layout_name)); av_log(ist, AV_LOG_WARNING, "Guessed Channel Layout: %s\n", layout_name); } return 1; @@ -1145,16 +1144,6 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) ist->user_set_discard = ist->st->discard; } - ist->dec_ctx = avcodec_alloc_context3(ist->dec); - if (!ist->dec_ctx) - return AVERROR(ENOMEM); - - ret = avcodec_parameters_to_context(ist->dec_ctx, par); - if (ret < 0) { - av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n"); - return ret; - } - if (o->bitexact) av_dict_set(&ist->decoder_opts, "flags", "+bitexact", AV_DICT_MULTIKEY); @@ -1181,7 +1170,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) case AVMEDIA_TYPE_AUDIO: { int guess_layout_max = INT_MAX; MATCH_PER_STREAM_OPT(guess_layout_max, i, guess_layout_max, ic, st); - guess_input_channel_layout(ist, guess_layout_max); + guess_input_channel_layout(ist, par, guess_layout_max); break; } case AVMEDIA_TYPE_DATA: @@ -1190,7 +1179,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st); MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st); if (canvas_size) { - ret = av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, + ret = av_parse_video_size(&par->width, &par->height, canvas_size); if (ret < 0) { av_log(ist, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size); @@ -1201,8 +1190,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) /* Compute the size of the canvas for the subtitles stream. If the subtitles codecpar has set a size, use it. Otherwise use the maximum dimensions of the video streams in the same file. */ - ist->sub2video.w = ist->dec_ctx->width; - ist->sub2video.h = ist->dec_ctx->height; + ist->sub2video.w = par->width; + ist->sub2video.h = par->height; if (!(ist->sub2video.w && ist->sub2video.h)) { for (int j = 0; j < ic->nb_streams; j++) { AVCodecParameters *par1 = ic->streams[j]->codecpar; @@ -1226,6 +1215,16 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) default: av_assert0(0); } + ist->dec_ctx = avcodec_alloc_context3(ist->dec); + if (!ist->dec_ctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(ist->dec_ctx, par); + if (ret < 0) { + av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n"); + return ret; + } + ist->par = avcodec_parameters_alloc(); if (!ist->par) return AVERROR(ENOMEM); -- 2.42.0 _______________________________________________ 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".