From patchwork Fri Oct 14 10:15:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38733 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp244291pzb; Fri, 14 Oct 2022 03:18:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76AGDdKPIygC6h9kh/KtVaGkk9Smwwp4XeptiDNj3YxuEuh6l0qibOz1/8ll6mOQ0uAK+u X-Received: by 2002:a05:6402:350f:b0:45d:1d86:9ec9 with SMTP id b15-20020a056402350f00b0045d1d869ec9mr2286354edd.266.1665742733293; Fri, 14 Oct 2022 03:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665742733; cv=none; d=google.com; s=arc-20160816; b=Bg83P/1qpiLibQBuf+KGNFQpwe/Yjm+H+wQ+I40FwhOhoc6FHBR9DGYVybUB16ZtiC 4ARBIzsshyi3dVRsK8c/3nq5xa7EhA0+llXkgwQGC+nIpcsguO9i1VSJGjgvn63ZXerK aAwkCUd4beTMGh+PGhRDQL1GaNWLfVhCMNQvNpxdytyq/VDbWZkFhUT8MMe4ox9wkBql bBo7A8CxIlk+W3F7S7X2BlkB7ghUHd43lI1LBVbTpJMi0w6hpR58V+30oJ+ePA2c5diA fhbFb8S2tIAO/+LoZOQhMJenG70kTKt9k8/oCAGJhodajZ46h2yTeLh3zVlk0Vjo1j6/ x2Cw== 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=VC5yty/YOKuSgQT1vbRN9y3daup3V4r2Tfm58L9s5co=; b=khp1DjuFMf686uj5KX4PLxRZurVz+iEN65m0OO7po1lgu7rYRRAX83bDO1J4xvwsfT bObXm19vfBzJt2LTg3hjTNTHU2oasZ7qkZxv6DbdUQ2lXYhC2AApVuXg+yDcj6SKVKFV 4yvfvpGbYfiJcceeuzXppr0YgagwjQ5ZWbZqnvZJGum+zEWjSjbd4Gp8rhYIsqMt6WVz MBmOK7qxhFC2s1gHRkna9d8LDEsS/SVYocEX4XShT/vUSFMRF8FxYyoCUx1GQ6r+X0hz /DKQFKa6BiAOW2rMXOoRDYr7YWNeq0xhYBByf5R2B2ZuKFo9ePNwzcNTqxK7IFn/95DP DdXQ== 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 b20-20020a17090636d400b00781cde43588si1911363ejc.58.2022.10.14.03.18.52; Fri, 14 Oct 2022 03:18:53 -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 01ADE68BDAC; Fri, 14 Oct 2022 13:18:35 +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 BF4F468BD72 for ; Fri, 14 Oct 2022 13:18:26 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 754B02404F8 for ; Fri, 14 Oct 2022 12:18:26 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tnEPlRGa4NIw for ; Fri, 14 Oct 2022 12:18:24 +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 E16C32404F7 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 08A0C3A015F 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:40 +0200 Message-Id: <20221014101548.3486-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013134904.10104-1-anton@khirnov.net> References: <20221013134904.10104-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/22] fftools/ffmpeg: move freeing an output stream into a separate function 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: xwSfYsfE4fvx --- fftools/ffmpeg.c | 69 ++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 46d2912d07..afbfff6ba2 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -504,6 +504,41 @@ 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; + + 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); + +#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; @@ -557,39 +592,9 @@ static void ffmpeg_cleanup(int ret) for (i = 0; i < nb_output_files; i++) of_close(&output_files[i]); - for (i = 0; i < nb_output_streams; i++) { - OutputStream *ost = output_streams[i]; - - if (!ost) - continue; - - 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); - -#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); + for (i = 0; i < nb_output_streams; i++) + ost_free(&output_streams[i]); - av_freep(&output_streams[i]); - } free_input_threads(); for (i = 0; i < nb_input_files; i++) { avformat_close_input(&input_files[i]->ctx);