From patchwork Tue Jan 17 17:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40064 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1d43:b0:b8:6755:f97e with SMTP id cs3csp1991741pzb; Tue, 17 Jan 2023 09:05:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtvxyb+sbv3AuzDp+D1qMMSQ90RNsDHwCpzoqyVzbPWkW/8JEYYxuDYTtU48/k6LhFOvlWr X-Received: by 2002:a05:6402:4305:b0:46c:e558:ce60 with SMTP id m5-20020a056402430500b0046ce558ce60mr5187029edc.22.1673975125667; Tue, 17 Jan 2023 09:05:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673975125; cv=none; d=google.com; s=arc-20160816; b=ACguYhznsUNhKxhdLPNP4pdgl9h5PQgKWFgCHdANxonMu9tjYpxLbDdX1U7lMOqmNu YoYFhSTk3k9SywYcdAEeqf4oFJBC22AG2D7+UbEIuoDOJ6Xhxa54RpHoOHJlLRtmbFfg mBvVd+QANoO/IuhuYenGWDwpY5BcxNpHLbp9v78o908b3rf65KyBpf8XuRKcR5oGNenv okeixQQiAPdBoWrkNHsM/8wtl0vnaLvrwK8RJOHmpT76JDynpzl5UKr6L6AbksMigLJs tUdRWope6oL6Ee1Vb7z8+izSFQyW96olPqsXXwGJwcBP8lbBwmCQd1sXCMhZ9s5g5r4V EncQ== 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=WlzJ4Gyu1g5ehedbTHOBoIE/lKUJ5S4vrNPPGGtC7xc=; b=yFXbVQgepNwa55nvMPFtDDAGL8wPbiROdMsA6dWpMXO5rNYSjyvkDKRYqy8Sdfxo1k he768TYd3WRLbqdGw+3Sx43BNHkgoeYhaw26qJxH/HEnkxmekWKM72C7BRX+rB4N5LB8 ssEkSpmOeLfpzImxbgDs/8JUXYaG1/VRgzTvoy+ObgYJuw4jQ7YDmmB6TIZitGPCxD6Q G/jQa6DUz6n3va2MOURYzLRLzmXYCGJ5Hkon+7RzdHkS4yI+8lQYubEoH0GsIVmuUZ+K fE6lgDOkQoaoGlY057Kz0nRgrYv/4+zNMlztnxjd5oOJGyw1rxbVLExYW44kijKprawH rIbQ== 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 b14-20020a0564021f0e00b0049e054594e4si9457973edb.397.2023.01.17.09.05.25; Tue, 17 Jan 2023 09:05:25 -0800 (PST) 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 29FFE68BE7A; Tue, 17 Jan 2023 19:05:20 +0200 (EET) 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 3BA7368BE1A for ; Tue, 17 Jan 2023 19:05:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 69DD22404F8 for ; Tue, 17 Jan 2023 18:05:13 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id wNIkgo5bcTus for ; Tue, 17 Jan 2023 18:05:12 +0100 (CET) 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 DB36E240183 for ; Tue, 17 Jan 2023 18:05:12 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 887833A0344 for ; Tue, 17 Jan 2023 18:05:06 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Jan 2023 18:04:59 +0100 Message-Id: <20230117170500.4053-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230117170500.4053-1-anton@khirnov.net> References: <20230117170500.4053-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC PATCH 2/3] lavfi/avfilter: track whether a filter has been initialized 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: fuzlDh8O8e93 Refuse to link uninitialized filters or initialize a filter twice. --- libavfilter/avfilter.c | 12 ++++++++++++ libavfilter/internal.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 86b275dc4f..619b96f5ac 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -158,6 +158,11 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, src->outputs[srcpad] || dst->inputs[dstpad]) return AVERROR(EINVAL); + if (!src->internal->initialized || !dst->internal->initialized) { + av_log(src, AV_LOG_ERROR, "Filters must be initialized before linking.\n"); + return AVERROR(EINVAL); + } + if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) { av_log(src, AV_LOG_ERROR, "Media type mismatch between the '%s' filter output pad %d (%s) and the '%s' filter input pad %d (%s)\n", @@ -872,6 +877,11 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) { int ret = 0; + if (ctx->internal->initialized) { + av_log(ctx, AV_LOG_ERROR, "Filter already initialized\n"); + return AVERROR(EINVAL); + } + ret = av_opt_set_dict2(ctx, options, AV_OPT_SEARCH_CHILDREN); if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n"); @@ -898,6 +908,8 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) return ret; } + ctx->internal->initialized = 1; + return 0; } diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 2ec41917f7..8b232a8d8f 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -137,6 +137,10 @@ struct AVFilterGraphInternal { struct AVFilterInternal { avfilter_execute_func *execute; + + // 1 when avfilter_init_*() was successfully called on this filter + // 0 otherwise + int initialized; }; static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func,