From patchwork Thu Aug 10 11:46:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4681 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp2309208vsu; Thu, 10 Aug 2017 04:48:46 -0700 (PDT) X-Received: by 10.28.74.133 with SMTP id n5mr8315313wmi.137.1502365726116; Thu, 10 Aug 2017 04:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502365726; cv=none; d=google.com; s=arc-20160816; b=Zol9OUJj9h24k/equ8NqWbwUydqK7JnumcObAb9RcOqI1TCbkSlYsB7aG678t8YUig kS8TSYhPSvQ0n5vmyfmPB/82Img2ydAYRJoYxx4vWe1pwicPsWQDnGNZTJ+OEytso5jE L28MRP7N9BoWnlyGheXbDenGuJmpQgPNgnIB2rBGn7wdKGG7BTb3BU26ydMw6zibxnJF /7e7L7yeb3tDEwEf/1TLtRDTF9Llcvp2tvieOa4hBkFog5Ebt0zOZnDs2NuTUsGTaZIs rxj85G5NdWw/FLx8HNJifZbUNBYUaGxRf0wnB75s4YQFlMTli7KOBpb15qhdURmQdJz4 GafQ== 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=moJHZy4GEZugijphdmwXbTvpzVqYS4bk7qjipG3/q04=; b=zbAO5YQpXrIlqjiP8hAgroppokXJEo3A19MGNsWukOrN30FV1NbvF73a4DRUVg+1u0 BVVBp7O9kzTWkXeQOPq3vVHANS4RIduHDH27csgzhP5fXTymrMfys+Bi9vc//3QHZPcw 5r6wDIl3AaVmZSAwF7JxUhqRSHmO5kmur0aYYLZ2CPDiVvXQu6S97GM0ELb4K5oThkAX 9Oky6ZivZHEfD5oll7jcbS6xgRinFSdtw7rlcirP2mPnjzMJlS6r7MMXigC0KTYQHnTF /j+kOe81f9s8JUrAMmnE1qVYRNAj9CFkUgz0vXYB3p6lenfdmWtlksE/kNB/a8zQ+cbw dl4w== 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 50si5025820wrw.341.2017.08.10.04.48.45; Thu, 10 Aug 2017 04:48:46 -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 C0B49689D04; Thu, 10 Aug 2017 14:46:58 +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 1A28A689C70 for ; Thu, 10 Aug 2017 14:46:55 +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 v7ABkvwu043765 for ; Thu, 10 Aug 2017 13:46:57 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id 4A12AE00FB; Thu, 10 Aug 2017 13:46:57 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 10 Aug 2017 13:46:40 +0200 Message-Id: <20170810114642.26779-14-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:57 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 14/16] vf_ssim: 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_ssim.c | 52 ++++++++++++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 26 deletions(-) Unchanged. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 605df917a3..b988cdcd4f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -300,7 +300,7 @@ OBJS-$(CONFIG_SMARTBLUR_FILTER) += vf_smartblur.o OBJS-$(CONFIG_SOBEL_FILTER) += vf_convolution.o OBJS-$(CONFIG_SPLIT_FILTER) += split.o OBJS-$(CONFIG_SPP_FILTER) += vf_spp.o -OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o dualinput.o framesync.o +OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync2.o OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o OBJS-$(CONFIG_STREAMSELECT_FILTER) += f_streamselect.o framesync2.o OBJS-$(CONFIG_SUBTITLES_FILTER) += vf_subtitles.o diff --git a/libavfilter/vf_ssim.c b/libavfilter/vf_ssim.c index 371f6dba70..5f5bed7a0e 100644 --- a/libavfilter/vf_ssim.c +++ b/libavfilter/vf_ssim.c @@ -38,16 +38,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 "ssim.h" #include "video.h" typedef struct SSIMContext { const AVClass *class; - FFDualInputContext dinput; + FFFrameSync fs; FILE *stats_file; char *stats_file_str; int nb_components; @@ -78,7 +78,7 @@ static const AVOption ssim_options[] = { { NULL } }; -AVFILTER_DEFINE_CLASS(ssim); +FRAMESYNC_DEFINE_CLASS(ssim, SSIMContext, fs); static void set_meta(AVDictionary **metadata, const char *key, char comp, float d) { @@ -282,13 +282,21 @@ static double ssim_db(double ssim, double weight) return 10 * log10(weight / (weight - ssim)); } -static AVFrame *do_ssim(AVFilterContext *ctx, AVFrame *main, - const AVFrame *ref) +static int do_ssim(FFFrameSync *fs) { - AVDictionary **metadata = &main->metadata; + AVFilterContext *ctx = fs->parent; SSIMContext *s = ctx->priv; + AVFrame *main, *ref; + AVDictionary **metadata; float c[4], ssimv = 0.0; - int i; + int ret, i; + + 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; s->nb_frames++; @@ -320,7 +328,7 @@ static AVFrame *do_ssim(AVFilterContext *ctx, AVFrame *main, fprintf(s->stats_file, "All:%f (%f)\n", ssimv, ssim_db(ssimv, 1.0)); } - return main; + return ff_filter_frame(ctx->outputs[0], main); } static av_cold int init(AVFilterContext *ctx) @@ -343,9 +351,7 @@ static av_cold int init(AVFilterContext *ctx) } } - s->dinput.process = do_ssim; - s->dinput.shortest = 1; - s->dinput.repeatlast = 0; + s->fs.on_event = do_ssim; return 0; } @@ -425,28 +431,25 @@ 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 *buf) +static int activate(AVFilterContext *ctx) { - SSIMContext *s = inlink->dst->priv; - return ff_dualinput_filter_frame(&s->dinput, inlink, buf); -} - -static int request_frame(AVFilterLink *outlink) -{ - SSIMContext *s = outlink->src->priv; - return ff_dualinput_request_frame(&s->dinput, outlink); + SSIMContext *s = ctx->priv; + return ff_framesync2_activate(&s->fs); } static av_cold void uninit(AVFilterContext *ctx) @@ -466,7 +469,7 @@ static av_cold void uninit(AVFilterContext *ctx) s->ssim_total / s->nb_frames, ssim_db(s->ssim_total, s->nb_frames)); } - ff_dualinput_uninit(&s->dinput); + ff_framesync2_uninit(&s->fs); if (s->stats_file && s->stats_file != stdout) fclose(s->stats_file); @@ -478,11 +481,9 @@ static const AVFilterPad ssim_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 } @@ -493,7 +494,6 @@ static const AVFilterPad ssim_outputs[] = { .name = "default", .type = AVMEDIA_TYPE_VIDEO, .config_props = config_output, - .request_frame = request_frame, }, { NULL } }; @@ -501,9 +501,11 @@ static const AVFilterPad ssim_outputs[] = { AVFilter ff_vf_ssim = { .name = "ssim", .description = NULL_IF_CONFIG_SMALL("Calculate the SSIM between two video streams."), + .preinit = ssim_framesync_preinit, .init = init, .uninit = uninit, .query_formats = query_formats, + .activate = activate, .priv_size = sizeof(SSIMContext), .priv_class = &ssim_class, .inputs = ssim_inputs,