From patchwork Mon May 31 07:55:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 27999 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2657006iof; Mon, 31 May 2021 00:57:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKOKuavgeOzpAKFZqx145qUinPcaOOcAaN21DJjAV46U2RV3oeO/creI7lHFpApF4EOiLC X-Received: by 2002:a17:906:2844:: with SMTP id s4mr21554565ejc.263.1622447860678; Mon, 31 May 2021 00:57:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622447860; cv=none; d=google.com; s=arc-20160816; b=BHSIAtd/d6kUvEcEsR4+yDlWfXi2eghb7CK6qCvNwk/ULQbUDhWL4hTsVx8jjP5mC/ Ar9OdKxyIhItk/ghDFLg0eFtQ+ONNiDb1tkxU2kiLndFCdOlTPUPqh9gNWs/IFp2b98+ 3/90c8Qpvtt+HscpOe+c36n0dfOcMGCW2jmwtvmLdU4mlIdP8syygNWOkJQzqaDro/Jh ARGgIc0lBoQGni+r6PSXLlgZieu988SMOry3/F377uwVK8nqm7q7u5pjk/pztlcgxJYA 2y+ASesfrOPIs8FxciiXakCwjMEAmReJP+fDJM2oOc+MpVG7GoPbINWWhvEK9PUv6wqJ PIEw== 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=+Us3PRQMDckKaf9BnnfSPZsWM93AzpZgJh7xzLZ1+64=; b=LKNmNmeTBl+RSxZM83DysWvJhXUymXAnae0O71CmwLiiFJRrAWLSTr8wsL1+zERBkG Mws0palRVeb4296er+crZrMq9VVZv8SavxjkgFvomX7r0YHHxv84lyzJd9A31sjGddAu ppzWcWdGKDiKEFNL9i8pny/3AsBjjqzE8qbyZOM1fuDlPN12VqhItO4X0xMJP0rnV058 09WtkQklL6zbSCueiAR5ZEfJN65ftqr2p2vll8NBYDiU7Q2S9qYAYSvx2HtTnEGTparu 3CwSGM5PFSIRFey5FIaQWtIV3/Cen9yW2wEpOben8BNCG+LbfqXzWyi9lcwdpv0VjF+t RJYA== 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 p3si11605901ejz.123.2021.05.31.00.57.40; Mon, 31 May 2021 00:57:40 -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 B0FCC689922; Mon, 31 May 2021 10:55:42 +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 30F8868814B for ; Mon, 31 May 2021 10:55:29 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 85B872406A0 for ; Mon, 31 May 2021 09:55:27 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id JM9shjm3C-ye for ; Mon, 31 May 2021 09:55:26 +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 52F0A2406A4 for ; Mon, 31 May 2021 09:55:22 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2E04A3A18C1; Mon, 31 May 2021 09:55:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 May 2021 09:55:12 +0200 Message-Id: <20210531075515.19544-21-anton@khirnov.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531075515.19544-1-anton@khirnov.net> References: <20210531075515.19544-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/24] lavfi/vf_scale: factorize freeing the sws contexts 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: WQQMYu17D9EW --- libavfilter/vf_scale.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 759499395f..8516919556 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -328,16 +328,24 @@ static av_cold int init_dict(AVFilterContext *ctx, AVDictionary **opts) return 0; } +static void scaler_free(ScaleContext *s) +{ + sws_freeContext(s->sws); + sws_freeContext(s->isws[0]); + sws_freeContext(s->isws[1]); + + s->sws = NULL; + s->isws[0] = NULL; + s->isws[1] = NULL; +} + static av_cold void uninit(AVFilterContext *ctx) { ScaleContext *scale = ctx->priv; av_expr_free(scale->w_pexpr); av_expr_free(scale->h_pexpr); scale->w_pexpr = scale->h_pexpr = NULL; - sws_freeContext(scale->sws); - sws_freeContext(scale->isws[0]); - sws_freeContext(scale->isws[1]); - scale->sws = NULL; + scaler_free(scale); av_dict_free(&scale->opts); } @@ -512,13 +520,8 @@ static int config_props(AVFilterLink *outlink) if (outfmt == AV_PIX_FMT_PAL8) outfmt = AV_PIX_FMT_BGR8; scale->output_is_pal = av_pix_fmt_desc_get(outfmt)->flags & AV_PIX_FMT_FLAG_PAL; - if (scale->sws) - sws_freeContext(scale->sws); - if (scale->isws[0]) - sws_freeContext(scale->isws[0]); - if (scale->isws[1]) - sws_freeContext(scale->isws[1]); - scale->isws[0] = scale->isws[1] = scale->sws = NULL; + scaler_free(scale); + if (inlink0->w == outlink->w && inlink0->h == outlink->h && !scale->out_color_matrix &&