From patchwork Mon Jul 31 12:02:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4539 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.85 with SMTP id 82csp2323668vsb; Mon, 31 Jul 2017 05:03:17 -0700 (PDT) X-Received: by 10.28.191.74 with SMTP id p71mr10974759wmf.45.1501502597856; Mon, 31 Jul 2017 05:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501502597; cv=none; d=google.com; s=arc-20160816; b=p/x9F4zz1Prg9oaEj3moyGE8xy+mrXfCFdMKUmyL7sIZ/IoR1eunuH84Vk8tQMAHd0 T+HVOMxasu9FYN70wNKQBLmoNUmuS4Zy3FTmUyrHqmNdZNp7/O2XLE23/rm8kf88MFKU buIOXojMliYiDDBtsOe4+SHfTdRaiUrjpmJgISwEZzPDutZZ+/pqfy8NBDJp7HfaNSOy qrllAPIR2IWld/HGqHOwD2fJZ6S1Gq4mtZsLdS+3+dM6ttmpnybUFu5Ir9xAIWkeVHBJ oJABbTNKaKpINVdaUufjqZdJlsg1fz9F5tZzmCvoUbFgXi880TSyCEtKnO6z30lGriFK SygQ== 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=WDISUNxQV48nZ6Y1cSVJKl87o6mdG1qF5n+zoEzv+EE=; b=HVEw6Hj4v5OclSyl33eRcRsSbcTOAapfTepsZorNJMMZuHwWhdFMxxJXTj8kMfhCHw caXylkWjb0qkTGJlKoROcTCkHf7zC4ctZZ9srZpq4YI7ajN5EuwhG3zeSlRp8CAk6qz2 qXtkiEG/U7LRyHyLtdPMjWl2buPoCY4FnlOm0S+urDLiqpAGxoqWfYHOFqzDqr2HEK54 wSDbuznxrq1V4m1ZRO2dfFDmtdHyrlAgBLbSPrjn4/Wn16CuuwtwdCGRja9AIqI0kRAR o51Hzg8ry9K+IiTi1Dlna72ztXtCxPgaqF8BCjtW4GwdlvhFV27s/0RiXft3u+xvW7iM R8iw== 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 x19si8000294wme.73.2017.07.31.05.03.17; Mon, 31 Jul 2017 05:03:17 -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 D61BF68988E; 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 D380168A1E3 for ; Mon, 31 Jul 2017 15:02:30 +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 v6VC2W97071511 for ; Mon, 31 Jul 2017 14:02:33 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id C0439E00FB; Mon, 31 Jul 2017 14:02:32 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Jul 2017 14:02:19 +0200 Message-Id: <20170731120227.31047-6-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:33 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 06/14] lavfi/framesync2: add common options. 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" Also add functions and macros to help filters chaining these options to their own. Signed-off-by: Nicolas George --- libavfilter/framesync2.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++-- libavfilter/framesync2.h | 44 +++++++++++++++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 3 deletions(-) diff --git a/libavfilter/framesync2.c b/libavfilter/framesync2.c index b968679c42..59c753c072 100644 --- a/libavfilter/framesync2.c +++ b/libavfilter/framesync2.c @@ -19,24 +19,43 @@ */ #include "libavutil/avassert.h" +#include "libavutil/opt.h" #include "avfilter.h" #include "filters.h" #include "framesync2.h" #include "internal.h" #define OFFSET(member) offsetof(FFFrameSync, member) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM + +enum EOFAction { + EOF_ACTION_REPEAT, + EOF_ACTION_ENDALL, + EOF_ACTION_PASS +}; static const char *framesync_name(void *ptr) { return "framesync"; } +static const AVOption framesync_options[] = { + { "eof_action", "Action to take when encountering EOF from secondary input ", + OFFSET(opt_eof_action), AV_OPT_TYPE_INT, { .i64 = EOF_ACTION_REPEAT }, + EOF_ACTION_REPEAT, EOF_ACTION_PASS, .flags = FLAGS, "eof_action" }, + { "repeat", "Repeat the previous frame.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_REPEAT }, .flags = FLAGS, "eof_action" }, + { "endall", "End both streams.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_ENDALL }, .flags = FLAGS, "eof_action" }, + { "pass", "Pass through the main input.", 0, AV_OPT_TYPE_CONST, { .i64 = EOF_ACTION_PASS }, .flags = FLAGS, "eof_action" }, + { "shortest", "force termination when the shortest input terminates", OFFSET(opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, + { "repeatlast", "repeat overlay of the last overlay frame", OFFSET(opt_repeatlast), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS }, + { NULL } +}; static const AVClass framesync_class = { .version = LIBAVUTIL_VERSION_INT, .class_name = "framesync", .item_name = framesync_name, .category = AV_CLASS_CATEGORY_FILTER, - .option = NULL, + .option = framesync_options, .parent_log_context_offset = OFFSET(parent), }; @@ -48,6 +67,19 @@ enum { static int consume_from_fifos(FFFrameSync *fs); +const AVClass *framesync2_get_class(void) +{ + return &framesync_class; +} + +void ff_framesync2_preinit(FFFrameSync *fs) +{ + if (fs->class) + return; + fs->class = &framesync_class; + av_opt_set_defaults(fs); +} + int ff_framesync2_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in) { /* For filters with several outputs, we will not be able to assume which @@ -55,7 +87,7 @@ int ff_framesync2_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in) ff_outlink_set_status(). To be designed when needed. */ av_assert0(parent->nb_outputs == 1); - fs->class = &framesync_class; + ff_framesync2_preinit(fs); fs->parent = parent; fs->nb_in = nb_in; @@ -93,6 +125,25 @@ int ff_framesync2_configure(FFFrameSync *fs) unsigned i; int64_t gcd, lcm; + if (!fs->opt_repeatlast || fs->opt_eof_action == EOF_ACTION_PASS) { + fs->opt_repeatlast = 0; + fs->opt_eof_action = EOF_ACTION_PASS; + } + if (fs->opt_shortest || fs->opt_eof_action == EOF_ACTION_ENDALL) { + fs->opt_shortest = 1; + fs->opt_eof_action = EOF_ACTION_ENDALL; + } + if (fs->opt_shortest) { + for (i = 0; i < fs->nb_in; i++) + fs->in[i].after = EXT_STOP; + } + if (!fs->opt_repeatlast) { + for (i = 1; i < fs->nb_in; i++) { + fs->in[i].after = EXT_NULL; + fs->in[i].sync = 0; + } + } + if (!fs->time_base.num) { for (i = 0; i < fs->nb_in; i++) { if (fs->in[i].sync) { diff --git a/libavfilter/framesync2.h b/libavfilter/framesync2.h index d24bd7abe8..5a43e0c4bd 100644 --- a/libavfilter/framesync2.h +++ b/libavfilter/framesync2.h @@ -196,12 +196,30 @@ typedef struct FFFrameSync { */ FFFrameSyncIn *in; + int opt_repeatlast; + int opt_shortest; + int opt_eof_action; + } FFFrameSync; /** - * Initialize a frame sync structure. + * Get the class for the framesync2 object. + */ +const AVClass *framesync2_get_class(void); + +/** + * Pre-initialize a frame sync structure. * + * It sets the class pointer and inits the options to their default values. * The entire structure is expected to be already set to 0. + * This step is optional, but necessary to use the options. + */ +void ff_framesync2_preinit(FFFrameSync *fs); + +/** + * Initialize a frame sync structure. + * + * The entire structure is expected to be already set to 0 or preinited. * * @param fs frame sync structure to initialize * @param parent parent AVFilterContext object @@ -265,4 +283,28 @@ int ff_framesync2_init_dualinput(FFFrameSync *fs, AVFilterContext *parent); */ int ff_framesync2_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1); +#define FRAMESYNC_DEFINE_CLASS(name, context, field) \ +static int name##_framesync_preinit(AVFilterContext *ctx) { \ + context *s = ctx->priv; \ + ff_framesync2_preinit(&s->field); \ + return 0; \ +} \ +static const AVClass *name##_child_class_next(const AVClass *prev) { \ + return prev ? NULL : framesync2_get_class(); \ +} \ +static void *name##_child_next(void *obj, void *prev) { \ + context *s = obj; \ + s->fs.class = framesync2_get_class(); /* FIXME */ \ + return prev ? NULL : &s->field; \ +} \ +static const AVClass name##_class = { \ + .class_name = #name, \ + .item_name = av_default_item_name, \ + .option = name##_options, \ + .version = LIBAVUTIL_VERSION_INT, \ + .category = AV_CLASS_CATEGORY_FILTER, \ + .child_class_next = name##_child_class_next, \ + .child_next = name##_child_next, \ +} + #endif /* AVFILTER_FRAMESYNC2_H */