From patchwork Thu Aug 10 11:46:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4679 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp2309051vsu; Thu, 10 Aug 2017 04:48:37 -0700 (PDT) X-Received: by 10.28.14.149 with SMTP id 143mr6926631wmo.102.1502365717073; Thu, 10 Aug 2017 04:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502365717; cv=none; d=google.com; s=arc-20160816; b=Xyxql2lZ57JymWf5rLqnGMhMZOunmUyrcHUn6d8+GCywkkVKfmIIDKaAKf/bZ3vMT+ 3Os+wp1Z30bg/JJ3k6LAaDbOTumhk//0tmHfiP9ywBaZD6tcE8ry3n5g8xHuFA+Gc2fm kBKrJDXrncK2e9P25ZW0wcXzCwso/rt0jGTLhuvHyt+0Cz4NE0+sITprIFsJcZy95qy6 Y+pSkq0UyZVZrXaDDaeqip7AyAWXneid5wq3MLpHOq5LmUhjM/cvFTNT7Vt/GfchTSNq +Ed31IO3qw5xCrgU0pG+Oxhq5PxPaKEsfaNY3tuF+lpthjAqc3grTTeg0b40wLBg2581 zHVg== 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=a2DNB651Y4VMYKN970olbLP6ganQUK3d16xVZVy9kLU=; b=xwJniuvlvMG7g5+fR/x5RUbIUnjsGPjztzmqK0+r8b/zTpF5oTLKDcLksaKtjF2qOF 3QTDjTUjMLDkLJHiMpHnIKY5SLuP/1tHUBCUpZuS0RJPWFucZyp/bpPmBGzrnW6nS356 bIYSYOMX773R6kIugW4m0SG91e2WtI/9VAihjt8840tLShisDvzbaY0jdYf8HmKWMuSz Rh0lIIsYIIJb+pUeWS1LFfz7kbmCCNA26gRsuX//YGZurdjdC2q0F4eDWx5gffki7YKN Sf3KgCKURZeBtl1QJOwufdDPahaQhoM3hIMVs4f75j427u08qPnspuk/4bjmdzP8rLqh 9U3A== 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 l75si4731147wma.15.2017.08.10.04.48.36; Thu, 10 Aug 2017 04:48:37 -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 50C95689CF1; Thu, 10 Aug 2017 14:46:57 +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 F00DF689B5C for ; Thu, 10 Aug 2017 14:46:53 +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 v7ABkuMt043753 for ; Thu, 10 Aug 2017 13:46:56 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 2F1D8E00F5; Thu, 10 Aug 2017 13:46:56 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Aug 2017 13:46:39 +0200 Message-Id: <20170810114642.26779-13-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:56 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 13/16] lavfi/vf_psnr: convert to framesync2. 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/Makefile | 2 +- libavfilter/vf_psnr.c | 50 +++++++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 24 deletions(-) Unchanged. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index f6cc8e9e95..605df917a3 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -259,7 +259,7 @@ OBJS-$(CONFIG_PP_FILTER) += vf_pp.o OBJS-$(CONFIG_PP7_FILTER) += vf_pp7.o OBJS-$(CONFIG_PREMULTIPLY_FILTER) += vf_premultiply.o framesync2.o OBJS-$(CONFIG_PREWITT_FILTER) += vf_convolution.o -OBJS-$(CONFIG_PSNR_FILTER) += vf_psnr.o dualinput.o framesync.o +OBJS-$(CONFIG_PSNR_FILTER) += vf_psnr.o framesync2.o OBJS-$(CONFIG_PULLUP_FILTER) += vf_pullup.o OBJS-$(CONFIG_QP_FILTER) += vf_qp.o OBJS-$(CONFIG_RANDOM_FILTER) += vf_random.o diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c index 6ab21d8e22..a8eb315445 100644 --- a/libavfilter/vf_psnr.c +++ b/libavfilter/vf_psnr.c @@ -29,16 +29,16 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avfilter.h" -#include "dualinput.h" #include "drawutils.h" #include "formats.h" +#include "framesync2.h" #include "internal.h" #include "psnr.h" #include "video.h" typedef struct PSNRContext { const AVClass *class; - FFDualInputContext dinput; + FFFrameSync fs; double mse, min_mse, max_mse, mse_comp[4]; uint64_t nb_frames; FILE *stats_file; @@ -68,7 +68,7 @@ static const AVOption psnr_options[] = { { NULL } }; -AVFILTER_DEFINE_CLASS(psnr); +FRAMESYNC_DEFINE_CLASS(psnr, PSNRContext, fs); static inline unsigned pow_2(unsigned base) { @@ -142,13 +142,21 @@ static void set_meta(AVDictionary **metadata, const char *key, char comp, float } } -static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, - const AVFrame *ref) +static int do_psnr(FFFrameSync *fs) { + AVFilterContext *ctx = fs->parent; PSNRContext *s = ctx->priv; + AVFrame *main, *ref; double comp_mse[4], mse = 0; - int j, c; - AVDictionary **metadata = &main->metadata; + int ret, j, c; + AVDictionary **metadata; + + ret = ff_framesync2_dualinput_get(fs, &main, &ref); + if (ret < 0) + return ret; + if (!ref) + return ff_filter_frame(ctx->outputs[0], main); + metadata = &main->metadata; compute_images_mse(s, (const uint8_t **)main->data, main->linesize, (const uint8_t **)ref->data, ref->linesize, @@ -214,7 +222,7 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, fprintf(s->stats_file, "\n"); } - return main; + return ff_filter_frame(ctx->outputs[0], main); } static av_cold int init(AVFilterContext *ctx) @@ -245,7 +253,7 @@ static av_cold int init(AVFilterContext *ctx) } } - s->dinput.process = do_psnr; + s->fs.on_event = do_psnr; return 0; } @@ -331,27 +339,24 @@ static int config_output(AVFilterLink *outlink) AVFilterLink *mainlink = ctx->inputs[0]; int ret; + ret = ff_framesync2_init_dualinput(&s->fs, ctx); + if (ret < 0) + return ret; outlink->w = mainlink->w; outlink->h = mainlink->h; outlink->time_base = mainlink->time_base; outlink->sample_aspect_ratio = mainlink->sample_aspect_ratio; outlink->frame_rate = mainlink->frame_rate; - if ((ret = ff_dualinput_init(ctx, &s->dinput)) < 0) + if ((ret = ff_framesync2_configure(&s->fs)) < 0) return ret; return 0; } -static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref) +static int activate(AVFilterContext *ctx) { - PSNRContext *s = inlink->dst->priv; - return ff_dualinput_filter_frame(&s->dinput, inlink, inpicref); -} - -static int request_frame(AVFilterLink *outlink) -{ - PSNRContext *s = outlink->src->priv; - return ff_dualinput_request_frame(&s->dinput, outlink); + PSNRContext *s = ctx->priv; + return ff_framesync2_activate(&s->fs); } static av_cold void uninit(AVFilterContext *ctx) @@ -375,7 +380,7 @@ static av_cold void uninit(AVFilterContext *ctx) get_psnr(s->min_mse, 1, s->average_max)); } - ff_dualinput_uninit(&s->dinput); + ff_framesync2_uninit(&s->fs); if (s->stats_file && s->stats_file != stdout) fclose(s->stats_file); @@ -385,11 +390,9 @@ static const AVFilterPad psnr_inputs[] = { { .name = "main", .type = AVMEDIA_TYPE_VIDEO, - .filter_frame = filter_frame, },{ .name = "reference", .type = AVMEDIA_TYPE_VIDEO, - .filter_frame = filter_frame, .config_props = config_input_ref, }, { NULL } @@ -400,7 +403,6 @@ static const AVFilterPad psnr_outputs[] = { .name = "default", .type = AVMEDIA_TYPE_VIDEO, .config_props = config_output, - .request_frame = request_frame, }, { NULL } }; @@ -408,9 +410,11 @@ static const AVFilterPad psnr_outputs[] = { AVFilter ff_vf_psnr = { .name = "psnr", .description = NULL_IF_CONFIG_SMALL("Calculate the PSNR between two video streams."), + .preinit = psnr_framesync_preinit, .init = init, .uninit = uninit, .query_formats = query_formats, + .activate = activate, .priv_size = sizeof(PSNRContext), .priv_class = &psnr_class, .inputs = psnr_inputs,