From patchwork Fri Oct 14 10:15:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38736 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp244475pzb; Fri, 14 Oct 2022 03:19:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM404+0A1if/obibiXLtL5LN04iq+ipugusvBiSIAwSfhVNFimIgrM2LH/w319od3rajg/zh X-Received: by 2002:a17:907:1c1a:b0:78d:426c:2828 with SMTP id nc26-20020a1709071c1a00b0078d426c2828mr3073605ejc.331.1665742760896; Fri, 14 Oct 2022 03:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665742760; cv=none; d=google.com; s=arc-20160816; b=qpRH4/595LbCx5DGcbIiUnqkqiCZrP0Ry5rinPgeF+d6wmbfOA82gQCHNnO/lx9FmG 7kNgQvGhfNQhLAkopuYpVfhHZoJgc0eD1X+QcOcFigLIv6x0GoJdGeMnbBQTz5kjDRrt vKleN4C8cV/eKlx1tap3gA5tu3EY1I8ZGxYPoDLXh4rx6MX3bQLV4F7K2DFHo6CtPJGv a11NiPAvTXZku+cj97sxOaQaOyWJinnAYZBniQXq1uNZg/Ios4MmRQAFLPNvwXsc+Xg+ V6BG9Pt4Hh3LiQR+pubJKHizEY48sv1iP9NqkqjyK5HBoKH4zQWbxS/i7UAspVj5Tj3q fRbg== 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:delivered-to; bh=W0lm8uErJDcBdrtxLHMhjiorpmGU/glaSl54Y61hWZM=; b=HZryrQ+FnIHIu/GTDTjefZZ5N4gyTA2bl3NSQOQkZFq8x78s0seSB/UkREgFmi+yg+ aEYmoKKCkcxUqI+bKVqd2YIZG+lKIg3Upw4vp17vVXyQwcX6lNEtn07Y9Lh5Z/+OtcSk mlNi1jGnst2aXFwRwrfsbdhsrJXwsdZB6PKqKFIkce17Dv0Pd6nZp8Zfo5763Hc0O6sZ 29H7+pUB8DUsXgp+nhw1aS7bsB/15cAspebKl+J+irJFVE6g/FVMZp6XAFHB3M6qLHCQ t661Ixo3WMgPeOp6ez8hf8CRA73Al5qyL2nwROkIFjv4jcQ9c8y5HGPZQEhf5hA+Ft4S wR1A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ka14-20020a170907990e00b0078358970513si1721247ejc.367.2022.10.14.03.19.20; Fri, 14 Oct 2022 03:19:20 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F27068BD94; Fri, 14 Oct 2022 13:18:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E592C68BD81 for ; Fri, 14 Oct 2022 13:18:30 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9D04F2405F9 for ; Fri, 14 Oct 2022 12:18:28 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id pp20XfomJNq4 for ; Fri, 14 Oct 2022 12:18:28 +0200 (CEST) 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 mail0.khirnov.net (Postfix) with ESMTPS id ED1BE240591 for ; Fri, 14 Oct 2022 12:18:24 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2B2343A168D for ; Fri, 14 Oct 2022 12:18:24 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 14 Oct 2022 12:15:45 +0200 Message-Id: <20221014101548.3486-6-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221014101548.3486-1-anton@khirnov.net> References: <20221013134904.10104-1-anton@khirnov.net> <20221014101548.3486-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/22] fftools/ffmpeg: free output streams in of_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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: hIrwTyYH3DOh Output streams are now children of OutputFile, so it makes more sense to free them there. --- fftools/ffmpeg.c | 55 +------------------------------------------- fftools/ffmpeg_mux.c | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 54 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4e9ea731ff..ceb26145a3 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -502,52 +502,6 @@ static int decode_interrupt_cb(void *ctx) const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }; -static void ost_free(OutputStream **post) -{ - OutputStream *ost = *post; - - if (!ost) - return; - - if (ost->logfile) { - if (fclose(ost->logfile)) - av_log(NULL, AV_LOG_ERROR, - "Error closing logfile, loss of information possible: %s\n", - av_err2str(AVERROR(errno))); - ost->logfile = NULL; - } - - av_bsf_free(&ost->bsf_ctx); - - av_frame_free(&ost->filtered_frame); - av_frame_free(&ost->sq_frame); - av_frame_free(&ost->last_frame); - av_packet_free(&ost->pkt); - av_dict_free(&ost->encoder_opts); - - av_freep(&ost->forced_keyframes); - av_expr_free(ost->forced_keyframes_pexpr); - av_freep(&ost->avfilter); - av_freep(&ost->logfile_prefix); - av_freep(&ost->forced_kf_pts); - av_freep(&ost->apad); - av_freep(&ost->disposition); - -#if FFMPEG_OPT_MAP_CHANNEL - av_freep(&ost->audio_channels_map); - ost->audio_channels_mapped = 0; -#endif - - av_dict_free(&ost->sws_dict); - av_dict_free(&ost->swr_opts); - - if (ost->enc_ctx) - av_freep(&ost->enc_ctx->stats_in); - avcodec_free_context(&ost->enc_ctx); - - av_freep(post); -} - static void ffmpeg_cleanup(int ret) { int i, j; @@ -598,15 +552,8 @@ static void ffmpeg_cleanup(int ret) av_freep(&filtergraphs); /* close files */ - for (i = 0; i < nb_output_files; i++) { - OutputFile *of = output_files[i]; - - for (int j = 0; j < of->nb_streams; j++) - ost_free(&of->streams[j]); - av_freep(&of->streams); - + for (i = 0; i < nb_output_files; i++) of_close(&output_files[i]); - } free_input_threads(); for (i = 0; i < nb_input_files; i++) { diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index a110691f6a..032b2ac34c 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -623,6 +623,52 @@ int of_write_trailer(OutputFile *of) return 0; } +static void ost_free(OutputStream **post) +{ + OutputStream *ost = *post; + + if (!ost) + return; + + if (ost->logfile) { + if (fclose(ost->logfile)) + av_log(NULL, AV_LOG_ERROR, + "Error closing logfile, loss of information possible: %s\n", + av_err2str(AVERROR(errno))); + ost->logfile = NULL; + } + + av_bsf_free(&ost->bsf_ctx); + + av_frame_free(&ost->filtered_frame); + av_frame_free(&ost->sq_frame); + av_frame_free(&ost->last_frame); + av_packet_free(&ost->pkt); + av_dict_free(&ost->encoder_opts); + + av_freep(&ost->forced_keyframes); + av_expr_free(ost->forced_keyframes_pexpr); + av_freep(&ost->avfilter); + av_freep(&ost->logfile_prefix); + av_freep(&ost->forced_kf_pts); + av_freep(&ost->apad); + av_freep(&ost->disposition); + +#if FFMPEG_OPT_MAP_CHANNEL + av_freep(&ost->audio_channels_map); + ost->audio_channels_mapped = 0; +#endif + + av_dict_free(&ost->sws_dict); + av_dict_free(&ost->swr_opts); + + if (ost->enc_ctx) + av_freep(&ost->enc_ctx->stats_in); + avcodec_free_context(&ost->enc_ctx); + + av_freep(post); +} + static void fc_close(AVFormatContext **pfc) { AVFormatContext *fc = *pfc; @@ -663,6 +709,11 @@ void of_close(OutputFile **pof) av_fifo_freep2(&ms->muxing_queue); } av_freep(&mux->streams); + + for (int i = 0; i < of->nb_streams; i++) + ost_free(&of->streams[i]); + av_freep(&of->streams); + av_dict_free(&mux->opts); av_packet_free(&mux->sq_pkt);