From patchwork Sun Jul 30 22:51:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4524 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.85 with SMTP id 82csp1772482vsb; Sun, 30 Jul 2017 15:51:18 -0700 (PDT) X-Received: by 10.223.164.20 with SMTP id d20mr10637507wra.183.1501455078230; Sun, 30 Jul 2017 15:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501455078; cv=none; d=google.com; s=arc-20160816; b=RUF6V2Uo4/A9l1jVPiL3GlY8FKkCrSe8nN0JcPEQLN5a5KKkl4Ccr++i9rH2gOU3vT gWob1EIh2XAh4R7E2cx5/4UsvPDfkcu0sctXbaUzCJHL7AGuP65palONAj2bd/w1MMNC GcED99sNYKZ7VQRMTqfKbJiw2I6PwoaN3T5Ki0LLhTQ+LbecjIFl3xeE20C5IbV5mftm E7k9qfDgcOMbYcuSMQtpEGwKKu7n5bdCoA+QeIKlEzPLq6d7jtZRVsaz6GF2SL3EkGUU 1XsWw3261xNcfaYN8l6uXiD+acIGTu8tgW14n/M94byVtFnXThm0mhyctGiN6MV4eOy5 7TPg== 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:message-id:date:to:from:delivered-to :arc-authentication-results; bh=9IBzL2/E6Z4CTZwIp8/QrbUMUrPhDlYhuRHLd1NTjg8=; b=lYVQKMB8Pfk+sdkJ3H4eD1g2mH/xwgOG2+P3E5fGGQhL1LzYqfCtSRUUm14FQG+AFy MuI9UOfuJKEfJtf3GUG61G3365RTLvaThvRAcjkoapcm2u2pDuOrFngAu184G8gOsz+m 65yK7o8BZkaFNUkKiPlhDjHE5aac3SapPURSVgF2qTo2yyh5RSyRJGuBocZ2eH9abQwV FeV3hrjjh6Cfx128lPpndSmJa/UwIJE6X1hANOmUx+Ka5Jf3Yb+h93uv8ufbY3OYqlkh QaaHWpRzd67zbRR62/ApsVjQd7exWvW+IGgKuVjMvRtQzRpb4Don/70QFL4xJjT2g6j4 CeVg== 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 7si21923898wrd.171.2017.07.30.15.51.17; Sun, 30 Jul 2017 15:51:18 -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 42CD968A0DF; Mon, 31 Jul 2017 01:51:12 +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 7BA35689FDC for ; Mon, 31 Jul 2017 01:51:06 +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 v6UMp8aC076091 for ; Mon, 31 Jul 2017 00:51:08 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 1BF2DE00D6; Mon, 31 Jul 2017 00:51:08 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Jul 2017 00:51:03 +0200 Message-Id: <20170730225106.31923-1-george@nsup.org> X-Mailer: git-send-email 2.13.2 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef2.ens.fr [129.199.96.32]); Mon, 31 Jul 2017 00:51:08 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/4] 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(+) With this patch and the next, I think we will be able to get rid of the init_dict callback and the ugly options forwarding code in a few filters. 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