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 5D0BA483CB for ; Thu, 1 Feb 2024 08:30:21 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE20D68CF68; Thu, 1 Feb 2024 10:29:58 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6489068CC0A for ; Thu, 1 Feb 2024 10:29:49 +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=LRMTOR1t; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 7B67143CE for ; Thu, 1 Feb 2024 09:29:48 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 964i5SNeSbOo for ; Thu, 1 Feb 2024 09:29:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1706776187; bh=asvHcBuc3i/L/f5neHywLkPqB8tNVJyyAN/ctnkxLX0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LRMTOR1tq6dIkYSpS9G1XV3yS8h78+V6RABAcF89EY1ixUOK7kJ+lk0zEDFT4C5ep ueLYxPzSb67lnSRZrPf/DFZdOnfAR0BqPZ6o/RX7eGhCLunpLcjwufmEE2lEnxHkk3 NdaW2+jYVYlrNpHVgQPJLddCCoypOwo2JtxrRzDfNtVoYAhXFRQXjOX7IbGRt1ubK6 mXpJs51JkWpqaenxVfRKSEcfI66XO47wwxVqJ3vA7ALP7Vv/kn7mFndlNoYFBFY9Dt dQCHlzWOb9jKqJuf9EzJA4F/joSEt1Zz8z0gXrk5J1ihsZ4diiEYul0AeocGkNv7ia CTkz5L4OPpLgw== 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 5F2D4DFB for ; Thu, 1 Feb 2024 09:29:47 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 21C613A0A03 for ; Thu, 1 Feb 2024 09:29:41 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 1 Feb 2024 09:29:37 +0100 Message-ID: <20240201082938.16687-3-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240201082938.16687-1-anton@khirnov.net> References: <20240201082938.16687-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] lavf/demux: stop calling avcodec_close() 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: Replace it with recreating the codec context. This is the last remaining blocker for deprecating avcodec_close(). --- libavformat/demux.c | 53 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index 6f640b92b1..c1640c459c 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -1250,6 +1250,52 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts) return av_rescale(ts, st->time_base.num * st->codecpar->sample_rate, st->time_base.den); } +static int codec_close(FFStream *sti) +{ + AVCodecContext *avctx_new = NULL; + AVCodecParameters *par_tmp = NULL; + int ret = 0; + + avctx_new = avcodec_alloc_context3(sti->avctx->codec); + if (!avctx_new) { + ret = AVERROR(ENOMEM); + goto fail; + } + + par_tmp = avcodec_parameters_alloc(); + if (!par_tmp) { + ret = AVERROR(ENOMEM); + goto fail; + } + + ret = avcodec_parameters_from_context(par_tmp, sti->avctx); + if (ret < 0) + goto fail; + + ret = avcodec_parameters_to_context(avctx_new, par_tmp); + if (ret < 0) + goto fail; + + avctx_new->pkt_timebase = sti->avctx->pkt_timebase; + +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS + avctx_new->ticks_per_frame = sti->avctx->ticks_per_frame; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + avcodec_free_context(&sti->avctx); + sti->avctx = avctx_new; + + avctx_new = NULL; + +fail: + avcodec_free_context(&avctx_new); + avcodec_parameters_free(&par_tmp); + + return ret; +} + static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { FFFormatContext *const si = ffformatcontext(s); @@ -1286,7 +1332,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (sti->need_context_update) { if (avcodec_is_open(sti->avctx)) { av_log(s, AV_LOG_DEBUG, "Demuxer context update while decoder is open, closing and trying to re-open\n"); - avcodec_close(sti->avctx); + codec_close(sti); sti->info->found_decoder = 0; } @@ -3017,10 +3063,7 @@ find_stream_info_err: av_freep(&sti->info->duration_error); av_freep(&sti->info); } - avcodec_close(sti->avctx); - // FIXME: avcodec_close() frees AVOption settable fields which includes ch_layout, - // so we need to restore it. - av_channel_layout_copy(&sti->avctx->ch_layout, &st->codecpar->ch_layout); + codec_close(sti); av_bsf_free(&sti->extract_extradata.bsf); } if (ic->pb) { -- 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".