From patchwork Mon Jul 31 12:02:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4533 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.85 with SMTP id 82csp2322943vsb; Mon, 31 Jul 2017 05:02:40 -0700 (PDT) X-Received: by 10.28.146.146 with SMTP id u140mr1591761wmd.38.1501502560620; Mon, 31 Jul 2017 05:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501502560; cv=none; d=google.com; s=arc-20160816; b=VT/qxQUryijL1NvRR9JhOrs0S5vavy80qY9ihlJFJ1hcRJD1dti4WNCYYEAxc8liAk 2B1SQWNL0ru7OpXsD14ZjAbicNKxsbB37F99NWgqL0pSATuWZbnKnmhgCvyFKZEcKxXt 8MyhqBgUFtofP2ir4b0txh5MCIzEG6EftU+KP0abZirAQ2gsirLSwOiXsyQdIcHPHoqx rhAG/KtdRkEHEv2mgcSkMnqvb72xhc4hQpkgYNS4YLhFVnOR7lT8tzvIP4yAtQC9KZ5w lPTyBwUCexMi3F1aZGOVdGH8W1W3i7SAjdoAtTyjawOHLwQkhs/eWtjlcTMnPka37gKn NtyA== 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=HgeN78hGzuBS3Kfk2iXGwLj+DmJ3e+ZXFOtZYKPtLIs=; b=C7gpTilV3nwwhbHqwSSSMxXSXkDwkCm7XHjkCf6/6lj2OVUn/bHE5kN5SyX4tfBkIn WrCtSLa3pI0A83vZnPsvHiYWrkwnns4B7oe1b9V9ptKID6x2RM0xOyKNRrHmBcOLQi+H m8PEbuJ6R6ec5MUtoF7M8ZP2j/bB5YhTixfWrYG2LKCzqrOabKRyoRjw/Fe7lEztgG2V DwxORnA4Xt22NgpKDJPWkjqbDSaKJO1Wg6ToekwLqZm+RCILhjroCsgRK61FghliNUoy 4vjP/dGQw2d7sWknsbDuUpNmvR+/zkIEMyPBSi0PBVzz961Tr9I1XQC3BwHbK/dL71Ry JIgQ== 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 f186si392018wme.238.2017.07.31.05.02.40; Mon, 31 Jul 2017 05:02:40 -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 2391768A1E9; Mon, 31 Jul 2017 15:02:35 +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 77C72689C96 for ; Mon, 31 Jul 2017 15:02:28 +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 v6VC2Uag071486 for ; Mon, 31 Jul 2017 14:02:30 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 630C3E00FB; Mon, 31 Jul 2017 14:02:30 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Jul 2017 14:02:15 +0200 Message-Id: <20170731120227.31047-2-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:30 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 02/14] lavfi/framesync2: add dualinput helper functions. 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" Signed-off-by: Nicolas George --- libavfilter/framesync2.c | 84 ++++++++++++++++++++++++++++++++++++------------ libavfilter/framesync2.h | 20 ++++++++++++ 2 files changed, 83 insertions(+), 21 deletions(-) Nothing changed much. diff --git a/libavfilter/framesync2.c b/libavfilter/framesync2.c index 0e9f6f210c..b968679c42 100644 --- a/libavfilter/framesync2.c +++ b/libavfilter/framesync2.c @@ -46,6 +46,8 @@ enum { STATE_EOF, }; +static int consume_from_fifos(FFFrameSync *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 @@ -127,30 +129,20 @@ int ff_framesync2_configure(FFFrameSync *fs) return 0; } -static void framesync_advance(FFFrameSync *fs) +static int framesync_advance(FFFrameSync *fs) { - int latest; unsigned i; int64_t pts; + int ret; - if (fs->eof) - return; - while (!fs->frame_ready) { - latest = -1; - for (i = 0; i < fs->nb_in; i++) { - if (!fs->in[i].have_next) { - if (latest < 0 || fs->in[i].pts < fs->in[latest].pts) - latest = i; - } - } - if (latest >= 0) { - fs->in_request = latest; - break; - } + while (!(fs->frame_ready || fs->eof)) { + ret = consume_from_fifos(fs); + if (ret <= 0) + return ret; - pts = fs->in[0].pts_next; - for (i = 1; i < fs->nb_in; i++) - if (fs->in[i].pts_next < pts) + pts = INT64_MAX; + for (i = 0; i < fs->nb_in; i++) + if (fs->in[i].have_next && fs->in[i].pts_next < pts) pts = fs->in[i].pts_next; if (pts == INT64_MAX) { framesync_eof(fs); @@ -181,6 +173,7 @@ static void framesync_advance(FFFrameSync *fs) fs->frame_ready = 0; fs->pts = pts; } + return 0; } static int64_t framesync_pts_extrapolate(FFFrameSync *fs, unsigned in, @@ -264,7 +257,7 @@ void ff_framesync2_uninit(FFFrameSync *fs) av_freep(&fs->in); } -int ff_framesync2_activate(FFFrameSync *fs) +static int consume_from_fifos(FFFrameSync *fs) { AVFilterContext *ctx = fs->parent; AVFrame *frame = NULL; @@ -300,8 +293,16 @@ int ff_framesync2_activate(FFFrameSync *fs) ff_inlink_request_frame(ctx->inputs[i]); return 0; } + return 1; +} - framesync_advance(fs); +int ff_framesync2_activate(FFFrameSync *fs) +{ + int ret; + + ret = framesync_advance(fs); + if (ret < 0) + return ret; if (fs->eof || !fs->frame_ready) return 0; ret = fs->on_event(fs); @@ -311,3 +312,44 @@ int ff_framesync2_activate(FFFrameSync *fs) return 0; } + +int ff_framesync2_init_dualinput(FFFrameSync *fs, AVFilterContext *parent) +{ + int ret; + + ret = ff_framesync2_init(fs, parent, 2); + if (ret < 0) + return ret; + fs->in[0].time_base = parent->inputs[0]->time_base; + fs->in[1].time_base = parent->inputs[1]->time_base; + fs->in[0].sync = 2; + fs->in[0].before = EXT_STOP; + fs->in[0].after = EXT_INFINITY; + fs->in[1].sync = 1; + fs->in[1].before = EXT_NULL; + fs->in[1].after = EXT_INFINITY; + return 0; +} + +int ff_framesync2_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1) +{ + AVFilterContext *ctx = fs->parent; + AVFrame *mainpic = NULL, *secondpic = NULL; + int ret = 0; + + if ((ret = ff_framesync2_get_frame(fs, 0, &mainpic, 1)) < 0 || + (ret = ff_framesync2_get_frame(fs, 1, &secondpic, 0)) < 0) { + av_frame_free(&mainpic); + return ret; + } + ret = ff_inlink_make_frame_writable(ctx->inputs[0], &mainpic); + if (ret < 0) + return ret; + av_assert0(mainpic); + mainpic->pts = av_rescale_q(fs->pts, fs->time_base, ctx->outputs[0]->time_base); + if (ctx->is_disabled) + secondpic = NULL; + *f0 = mainpic; + *f1 = secondpic; + return 0; +} diff --git a/libavfilter/framesync2.h b/libavfilter/framesync2.h index 2b37636ebb..d24bd7abe8 100644 --- a/libavfilter/framesync2.h +++ b/libavfilter/framesync2.h @@ -245,4 +245,24 @@ int ff_framesync2_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, */ int ff_framesync2_activate(FFFrameSync *fs); +/** + * Initialize a frame sync structure for dualinput. + * + * Compared to generic framesync, dualinput assumes the first input is the + * main one and the filtering is performed on it. The first input will be + * the only one with sync set and generic timeline support will just pass it + * unchanged when disabled. + * + * Equivalent to ff_framesync2_init(fs, parent, 2) then setting the time + * base, sync and ext modes on the inputs. + */ +int ff_framesync2_init_dualinput(FFFrameSync *fs, AVFilterContext *parent); + +/** + * @param f0 used to return the main frame + * @param f1 used to return the second frame, or NULL if disabled + * @return >=0 for success or AVERROR code + */ +int ff_framesync2_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1); + #endif /* AVFILTER_FRAMESYNC2_H */