From patchwork Fri Jan 20 19:31:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40079 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3ca3:b0:b9:1511:ac2c with SMTP id b35csp1431990pzj; Fri, 20 Jan 2023 11:32:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXsRdVD5CSCtf5JbRl6acwK0DIZQ95q5Nari0fzgBqyjkwDM4P62b1GEKXqRPnMh1cOKUzao X-Received: by 2002:a17:906:d8a8:b0:84b:b481:6188 with SMTP id qc8-20020a170906d8a800b0084bb4816188mr12789279ejb.64.1674243141488; Fri, 20 Jan 2023 11:32:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674243141; cv=none; d=google.com; s=arc-20160816; b=HXQZizllb94fPArHC/r+t5ta0Ad6hZq6A/WyDyT381sncJA7zL68R4Nsg15lcLa8Ip I7WEreazP2AWp3eXf/mbvUG4wn2FwMYMSIB4j/bo6QbEESiiFvOZkBUdyEvl3LbABwXZ /STaIq3xOl6ABy01d9m/WFbM9Prb3fwZhSoD22LLs8jFYlEyrECBOxPV52X24FLLdTYl rrnrDlTkHy1ZcTF7tntwa0hBaO9+oy+aPd4FYLN6D5CFysMwW+r+MtH5SVWRB5JvPekH uhml6HjDpJ2o74SLrQMpRVhGQUN6HbKgRvosIqNP1KA9VrqCZcCvXig4gBApDOSbgAzR 6x1g== 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=E2XTVskk55KUpqRDZEa3c9veGS9SB3Gq8UoD33v7H1HkoUjWmIhabXZFAO9xKEf1L3 X5vA41YwoS7TlkG5hRVyHpOogmo1k2G6V3OS5JXWgzK3DwK/+bUIWxXYhq9zF9g1CVkk FRDKybgFhINsO5BGHj9VY85BCfwdDoRuUjz2n7FkVQJgfeotvoTHvLsOpGWdZYjNXmAT k2DbCU3NdRO/9qTME2Pv94uIv/+O0a9psbTg0Fs182hFxO39zRWy2VnHu/jGgd80d6BP D2qAEds36GIRoZYfMnTVNUZsdDXhy25DbW/C4aMHxRMcdZITVZbz7+Hdhq3o7GhAWaTj yskw== 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 qk43-20020a1709077fab00b0086f53c24d9csi23415588ejc.625.2023.01.20.11.32.10; Fri, 20 Jan 2023 11:32:21 -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 1F5A268BD18; Fri, 20 Jan 2023 21:32:06 +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 88A5168BCEE for ; Fri, 20 Jan 2023 21:31:59 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2CF8F2404F8 for ; Fri, 20 Jan 2023 20:31:59 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Yrp8XCeFxX9i for ; Fri, 20 Jan 2023 20:31:58 +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 B279E240591 for ; Fri, 20 Jan 2023 20:31:56 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B09363A0344 for ; Fri, 20 Jan 2023 20:31:48 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Jan 2023 20:31:29 +0100 Message-Id: <20230120193132.21597-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230120193132.21597-1-anton@khirnov.net> References: <20230120193132.21597-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] 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: AsQO3MmFxYmu 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,