From patchwork Mon Jul 31 12:02:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4542 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.85 with SMTP id 82csp2323505vsb; Mon, 31 Jul 2017 05:03:09 -0700 (PDT) X-Received: by 10.28.183.196 with SMTP id h187mr10650426wmf.134.1501502589093; Mon, 31 Jul 2017 05:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501502589; cv=none; d=google.com; s=arc-20160816; b=bw5t7mqP5CIzZEXFntfuGHzx45M2lblCKlX+VO2682YvTi2ywv9WL1SxwXJ6rRBjTB qwz0ymA2ZAO8FRPF8I6JwRQlwmvSHeCLHCOVI+qos1pIW5CHT+z/y3U/nsurT6s+/hi9 bAQyUK/AsHI/v9J31w1kby4Y32aLqMBQdkOVAxLHXZ08gRNfW5IHg2wUwXPKp/VfgptE RcyCqIWrFIMIeSqLl0ilAESr63XK62ALun+EDvHitnhFmkR9JAzuCTFkDyelX3YAcJuJ z/Xz7KEU7L9bv11BgGC2JdnkInfbebOsjdubcbWG6yjS2lPTLxwGw5/dXXealSdAf0R9 z9zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=Ir2WES4QYNPSMt/zQ0ZmuZAQDNN8dPryHelk8WRqPrY=; b=lziEl3HVFYWnkukS63LeD2hC53urfDvushTHvxeT+rBFG9xGaoaJCGcuMkuzZXR4fn A1S0j/tUJNwZE5sI1yDNY7V1zfvNa4k6S56zz52O+NxsiX0lfRjPTSG8ydoEvZLijfS9 XFp6ROqziITPhB0y4MXMkPO7Kej82FtkUYne0arJv2oHcW49tQT9kINMizWN2Fe+wFyR bNoqvBmrs5wgczZpVTXG2iEv3YAMN4NSjzT9nBQyiPzjMujdv8a4VKQTTv0kX/GolDI1 nOwP47eM4p/bW8SBdyv2Cgvp6dh9IvhvlLjrkqQ2e+E5+ygeJT3+zYKXUmvX3uSFTJ7r Oo8Q== 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 m205si8024840wmf.159.2017.07.31.05.03.08; Mon, 31 Jul 2017 05:03:09 -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 77AF568A206; Mon, 31 Jul 2017 15:02:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B321E689CD1 for ; Mon, 31 Jul 2017 15:02:29 +0300 (EEST) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v6VC2VID071499 for ; Mon, 31 Jul 2017 14:02:31 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 94273E00FB; Mon, 31 Jul 2017 14:02:31 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Jul 2017 14:02:17 +0200 Message-Id: <20170731120227.31047-4-george@nsup.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170731120227.31047-1-george@nsup.org> References: <20170731120227.31047-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Mon, 31 Jul 2017 14:02:31 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 04/14] lavfi: add a preinit callback to filters. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It is necessary for filters with child objects, to set the class and default options values. Signed-off-by: Nicolas George --- libavfilter/avfilter.c | 8 ++++++++ libavfilter/avfilter.h | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 185ba8df00..dcd975e104 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -692,6 +692,7 @@ static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, voi AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) { AVFilterContext *ret; + int preinited = 0; if (!filter) return NULL; @@ -708,6 +709,11 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) if (!ret->priv) goto err; } + if (filter->preinit) { + if (filter->preinit(ret) < 0) + goto err; + preinited = 1; + } av_opt_set_defaults(ret); if (filter->priv_class) { @@ -745,6 +751,8 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name) return ret; err: + if (preinited) + filter->uninit(ret); av_freep(&ret->inputs); av_freep(&ret->input_pads); ret->nb_inputs = 0; diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 60662c19ac..73a723d583 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -195,6 +195,21 @@ typedef struct AVFilter { */ /** + * Filter pre-initialization function + * + * This callback will be called immediately after the filter context is + * allocated, to allow allocating and initing sub-objects. + * + * If this callback is not NULL, the uninit callback will be called on + * allocation failure. + * + * @return 0 on success, + * AVERROR code on failure (but the code will be + * dropped and treated as ENOMEM by the calling code) + */ + int (*preinit)(AVFilterContext *ctx); + + /** * Filter initialization function. * * This callback will be called only once during the filter lifetime, after