From patchwork Thu Aug 10 11:46:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4677 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp2307827vsu; Thu, 10 Aug 2017 04:47:40 -0700 (PDT) X-Received: by 10.28.168.86 with SMTP id r83mr6803544wme.150.1502365659966; Thu, 10 Aug 2017 04:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502365659; cv=none; d=google.com; s=arc-20160816; b=H34IWecPxNMxO6DeVUflsZ8JXH/jgbrQtmgvx62dSgpFXdMukjAPcUEG8UGJUEcrBl 5qUzLjJnL8Oc8ApP2PTRnCsCtBUWTJX+fcoI+HcwQKeuPeCOqzH8h0HCKcEhS7BB9D4w hURd7W9l5yYSBklVHKYw0wZPIojeyec9cIzOuB//M5i5Xk5zf7Xja47uYvHevCo4/2jc /Tpqd35LZTmWglZ6Qa7LwXGs3LMC4sfI/8FymZ7hGVreLFIqCXhpSMt+/HPbdSBq5sWr ttPIUFLbQQMicgp9ni9L81hsZHp+RQ0nWQXo7aG62bJbl/7qoOO2JNvLKNVvkly1RZwy 93XQ== 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=DnIdylNQnqHjFvO44Kuz6MKIqFNgsKNZ5se5Ak7qZdk=; b=VaVQR3+LgOyF1cqxB//5R0HqguHfCh+oxfBYAjCryoP1XutC3yhxSbENLzdKuv+3t6 pS6ooIsMl+8obkpCrR/gA+qZ3fVSBIawn07ZJfcmsIOhrh7R+uGIYr3Fsw2FNJEhl0oB hQDNpGlSQUPYa0UFPuyXCD5uX/cqmE2ABVd0bb9yVpHkB3w/Nc7OLoXGeW9oN4qx6RGv D8jaXtaHlxj5heHICOpUaL8dSnmn0s8vKiV99aM96R8LCMXVH+7648RhpSe7fwPHBpyA gfqaPLQxug5y5YptC2hTwbwyX8O8dPT2ww60eefTvWSkt4xM00912Mdl3CokDqORJDnR +QhA== 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 m127si4704402wmm.115.2017.08.10.04.47.39; Thu, 10 Aug 2017 04:47:39 -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 EC70D689C6C; Thu, 10 Aug 2017 14:46:52 +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 6A5DC689C2C for ; Thu, 10 Aug 2017 14:46:46 +0300 (EEST) Received: from phare.normalesup.org (archicubes.ens.fr [129.199.129.80]) by nef2.ens.fr (8.13.6/1.01.28121999) with ESMTP id v7ABkmsV043679 for ; Thu, 10 Aug 2017 13:46:48 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id A899BE00F5; Thu, 10 Aug 2017 13:46:48 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Aug 2017 13:46:31 +0200 Message-Id: <20170810114642.26779-5-george@nsup.org> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170810114642.26779-1-george@nsup.org> References: <20170810114642.26779-1-george@nsup.org> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Thu, 10 Aug 2017 13:46:49 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 05/16] 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(+) Unchanged. 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