From patchwork Wed Apr 19 19:52:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41274 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp744878pzb; Wed, 19 Apr 2023 12:56:06 -0700 (PDT) X-Google-Smtp-Source: AKy350ZCrByN01qouXsoiCSRqaLZBijgaC2J648O8r8LcJeP/jeFWkfzdXHij8AhzFFjD74GNTte X-Received: by 2002:a17:906:ccd2:b0:94e:4fac:d92b with SMTP id ot18-20020a170906ccd200b0094e4facd92bmr15983408ejb.58.1681934166298; Wed, 19 Apr 2023 12:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681934166; cv=none; d=google.com; s=arc-20160816; b=gHwsn7ykflnR1J9yfr9mXvq1ars/pG6p5KzSA5Ppi5fWg0WWqgYQKARmF4eHOijZEP wCBrq+KSB4Mik2L6GK3bdBRVifadmjLbKTI/+0B7BHMGX/VILAs82ehsd5FrC4qeFlHU 3XEdsfFuvHniStArWbOcG/mp35C0Tdq16XXgMmYmQpV10poit8RQmKJsxtb7U34dQ1V9 ubILUWj1EP2sWr1GWNgpk+EstjmazcGAhL+bSkWOZeScBX/aYE1TcEqQcuwEZqo9FcVQ LiO3WYhleIjatJtV3LaUR7t1N+BE/D2WxzIq4Dr2wEVYp2xc4AT0m9M56pgNUS6RSdMG iOcA== 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=px/5JBpvqOdVkN0wRrF5gUQVIqFagbuTPwRW9MeznW0=; b=wB2P2xWPACNoFfBEhOUdiMNtwH3cxLMlEh8LUl2JaYAGXUwrXN88jdVWUXKYh7vA/M rpLNpzuWsXGTQds1CfM13+qRJhnFQn5dRpgIb4NqHrGpj8Y1g6DfLL20BI/FqDmf9h88 obY6aVkTEranSO9ss+RtpJCGv+IszmpIaWzfc6N2F73V38IE3qvSjyHgIFVGR+yQPCdP nWsEpbiEzSySpB0ZAOTyts2OBf6fl37zoNkT74UU0dX9SuzphRNJGcO9vyqDCC/AN0d7 U9ZVeKpnM2iVwxlVFIUVVqmL3OHFFqD9ppZ+v0LS1uQxOx5DgP5OChPO5fbfpPyb6Su/ x1ow== 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 r1-20020a056402018100b0050476f7c049si15156218edv.682.2023.04.19.12.56.05; Wed, 19 Apr 2023 12:56:06 -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 8A16468BF8F; Wed, 19 Apr 2023 22:53:25 +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 7412C68BEC0 for ; Wed, 19 Apr 2023 22:53:08 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 37C952404F8 for ; Wed, 19 Apr 2023 21:53:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Pw_pC5FSarCx for ; Wed, 19 Apr 2023 21:53:07 +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 93CB8240D1F for ; Wed, 19 Apr 2023 21:52:56 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4764E3A0787 for ; Wed, 19 Apr 2023 21:52:56 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 19 Apr 2023 21:52:39 +0200 Message-Id: <20230419195243.2974-21-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230419195243.2974-1-anton@khirnov.net> References: <20230419195243.2974-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/25] fftools/ffmpeg: move freeing a filtergraph 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: NxaOXiDCxmJb --- fftools/ffmpeg.c | 42 +++------------------------------------ fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_filter.c | 44 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 248c22a4ff..2bf3ba5c74 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -487,51 +487,15 @@ const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }; static void ffmpeg_cleanup(int ret) { - int i, j; + int i; if (do_benchmark) { int maxrss = getmaxrss() / 1024; av_log(NULL, AV_LOG_INFO, "bench: maxrss=%ikB\n", maxrss); } - for (i = 0; i < nb_filtergraphs; i++) { - FilterGraph *fg = filtergraphs[i]; - avfilter_graph_free(&fg->graph); - for (j = 0; j < fg->nb_inputs; j++) { - InputFilter *ifilter = fg->inputs[j]; - struct InputStream *ist = ifilter->ist; - - if (ifilter->frame_queue) { - AVFrame *frame; - while (av_fifo_read(ifilter->frame_queue, &frame, 1) >= 0) - av_frame_free(&frame); - av_fifo_freep2(&ifilter->frame_queue); - } - av_freep(&ifilter->displaymatrix); - if (ist->sub2video.sub_queue) { - AVSubtitle sub; - while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0) - avsubtitle_free(&sub); - av_fifo_freep2(&ist->sub2video.sub_queue); - } - av_buffer_unref(&ifilter->hw_frames_ctx); - av_freep(&ifilter->name); - av_freep(&fg->inputs[j]); - } - av_freep(&fg->inputs); - for (j = 0; j < fg->nb_outputs; j++) { - OutputFilter *ofilter = fg->outputs[j]; - - avfilter_inout_free(&ofilter->out_tmp); - av_freep(&ofilter->name); - av_channel_layout_uninit(&ofilter->ch_layout); - av_freep(&fg->outputs[j]); - } - av_freep(&fg->outputs); - av_freep(&fg->graph_desc); - - av_freep(&filtergraphs[i]); - } + for (i = 0; i < nb_filtergraphs; i++) + fg_free(&filtergraphs[i]); av_freep(&filtergraphs); /* close files */ diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 07c1fc7ed6..95591f4bba 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -814,6 +814,8 @@ int ifilter_has_all_input_formats(FilterGraph *fg); */ FilterGraph *fg_create(char *graph_desc); +void fg_free(FilterGraph **pfg); + /** * Perform a step of transcoding for the specified filter graph. * diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index c39cf43774..cfd93a0f9d 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -189,6 +189,50 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg) return ofilter; } +void fg_free(FilterGraph **pfg) +{ + FilterGraph *fg = *pfg; + + if (!fg) + return; + + avfilter_graph_free(&fg->graph); + for (int j = 0; j < fg->nb_inputs; j++) { + InputFilter *ifilter = fg->inputs[j]; + struct InputStream *ist = ifilter->ist; + + if (ifilter->frame_queue) { + AVFrame *frame; + while (av_fifo_read(ifilter->frame_queue, &frame, 1) >= 0) + av_frame_free(&frame); + av_fifo_freep2(&ifilter->frame_queue); + } + av_freep(&ifilter->displaymatrix); + if (ist->sub2video.sub_queue) { + AVSubtitle sub; + while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0) + avsubtitle_free(&sub); + av_fifo_freep2(&ist->sub2video.sub_queue); + } + av_buffer_unref(&ifilter->hw_frames_ctx); + av_freep(&ifilter->name); + av_freep(&fg->inputs[j]); + } + av_freep(&fg->inputs); + for (int j = 0; j < fg->nb_outputs; j++) { + OutputFilter *ofilter = fg->outputs[j]; + + avfilter_inout_free(&ofilter->out_tmp); + av_freep(&ofilter->name); + av_channel_layout_uninit(&ofilter->ch_layout); + av_freep(&fg->outputs[j]); + } + av_freep(&fg->outputs); + av_freep(&fg->graph_desc); + + av_freep(pfg); +} + FilterGraph *fg_create(char *graph_desc) { FilterGraph *fg;