From patchwork Mon Jul 31 12:02:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 4544 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.85 with SMTP id 82csp2324894vsb; Mon, 31 Jul 2017 05:04:22 -0700 (PDT) X-Received: by 10.223.132.100 with SMTP id 91mr1592943wrf.187.1501502662837; Mon, 31 Jul 2017 05:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501502662; cv=none; d=google.com; s=arc-20160816; b=w6vDpr0nyh/wl6H5iQd+TPq3g6U0kdL5LUckEcavawe8L3bB4x0eniMjZAA2HlP8+T WO4w9uuD5S+F6PKsTHT1gLPp0W6GFFYkkzaJVnhCnlmD0xFvfc9dnWkgnMfX/oxKIAON ZmBWSDUYcn2CUdr3oWOxhSruRhfJ0vMZfxU2T6LfyUQcqmTTs06jgiznHHzDNvuXe4Q9 UOoFzdaGdm9Cpte51IIGo+Sqt816gST0N3CTkb7ZQjH/cZj6vgwW1Koorrf2sO6edDKB jX9QwFJdr5POJvJJQMXEAkSH1UgI37D4itYnP5UA66Oa+fENv6FKI4oDwYQwVwmufcNQ dPaw== 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=kZ5KjiBxbC59Vpsz9MlqG8YTTvEHjWFYW/Yzu1bLGJg=; b=CdqO9w8n7IqBJ/oa+wpuuqefYWALTiFRqGOZBTHqEJPseyiTrO/a4gO/2lhhWRo0tf eqQuI/oPPAeq+mb9Twdts6Jqqm14IOWQcP+4/u6mHOo9rUiqgxCm8u851HaBpY6hEnSz oLYNgOm4nsIDVcA/BbkZXiyhS4vrTNK8ye91CnNpF8QFyXUFN3BZFyhkcRQ6M0t3D8k6 PizS3TGjjODrBwl2+UR7TBzlr9wxBSRhpXfFYJZ5NpaunTovExJ+Fw+tnzTbeLtmzQ+X lsmYl+Rr1FILExgukKmMAQHwmRo/BexZjyh6uSbfJEnTWbAwfjyqs3tciEXjwJl6hKsK /8+w== 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 q38si22593610wrb.453.2017.07.31.05.04.22; Mon, 31 Jul 2017 05:04:22 -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 7A08868A247; Mon, 31 Jul 2017 15:02:43 +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 F286A68A1EC for ; Mon, 31 Jul 2017 15:02:33 +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 v6VC2Z5S071540 for ; Mon, 31 Jul 2017 14:02:36 +0200 (CEST) Received: by phare.normalesup.org (Postfix, from userid 1001) id DBA82E00FB; Mon, 31 Jul 2017 14:02:35 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 Jul 2017 14:02:24 +0200 Message-Id: <20170731120227.31047-11-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:36 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 11/14] lavfi/vf_paletteuse: 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_paletteuse.c | 59 ++++++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index a62339992f..4e4201e2b6 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -248,7 +248,7 @@ OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o framesync2.o OBJS-$(CONFIG_OWDENOISE_FILTER) += vf_owdenoise.o OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o OBJS-$(CONFIG_PALETTEGEN_FILTER) += vf_palettegen.o -OBJS-$(CONFIG_PALETTEUSE_FILTER) += vf_paletteuse.o dualinput.o framesync.o +OBJS-$(CONFIG_PALETTEUSE_FILTER) += vf_paletteuse.o framesync2.o OBJS-$(CONFIG_PERMS_FILTER) += f_perms.o OBJS-$(CONFIG_PERSPECTIVE_FILTER) += vf_perspective.o OBJS-$(CONFIG_PHASE_FILTER) += vf_phase.o diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c index b25c6a9eac..063873536b 100644 --- a/libavfilter/vf_paletteuse.c +++ b/libavfilter/vf_paletteuse.c @@ -27,8 +27,10 @@ #include "libavutil/internal.h" #include "libavutil/opt.h" #include "libavutil/qsort.h" -#include "dualinput.h" #include "avfilter.h" +#include "filters.h" +#include "framesync2.h" +#include "internal.h" enum dithering_mode { DITHERING_NONE, @@ -80,7 +82,7 @@ typedef int (*set_frame_func)(struct PaletteUseContext *s, AVFrame *out, AVFrame typedef struct PaletteUseContext { const AVClass *class; - FFDualInputContext dinput; + FFFrameSync fs; struct cache_node cache[CACHE_SIZE]; /* lookup cache */ struct color_node map[AVPALETTE_COUNT]; /* 3D-Tree (KD-Tree with K=3) for reverse colormap */ uint32_t palette[AVPALETTE_COUNT]; @@ -129,6 +131,8 @@ static const AVOption paletteuse_options[] = { AVFILTER_DEFINE_CLASS(paletteuse); +static int load_apply_palette(FFFrameSync *fs); + static int query_formats(AVFilterContext *ctx) { static const enum AVPixelFormat in_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE}; @@ -900,11 +904,18 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; PaletteUseContext *s = ctx->priv; + ret = ff_framesync2_init_dualinput(&s->fs, ctx); + if (ret < 0) + return ret; + s->fs.opt_repeatlast = 1; // only 1 frame in the palette + s->fs.in[1].before = s->fs.in[1].after = EXT_INFINITY; + s->fs.on_event = load_apply_palette; + outlink->w = ctx->inputs[0]->w; outlink->h = ctx->inputs[0]->h; outlink->time_base = ctx->inputs[0]->time_base; - if ((ret = ff_dualinput_init(ctx, &s->dinput)) < 0) + if ((ret = ff_framesync2_configure(&s->fs)) < 0) return ret; return 0; } @@ -951,21 +962,31 @@ static void load_palette(PaletteUseContext *s, const AVFrame *palette_frame) s->palette_loaded = 1; } -static AVFrame *load_apply_palette(AVFilterContext *ctx, AVFrame *main, - const AVFrame *second) +static int load_apply_palette(FFFrameSync *fs) { + AVFilterContext *ctx = fs->parent; AVFilterLink *inlink = ctx->inputs[0]; PaletteUseContext *s = ctx->priv; + AVFrame *main, *second, *out; + int ret; + + ret = ff_framesync2_dualinput_get(fs, &main, &second); + if (ret < 0) + return ret; + if (!main || !second) { + ret = AVERROR_BUG; + goto error; + } if (!s->palette_loaded) { load_palette(s, second); } - return apply_palette(inlink, main); -} + out = apply_palette(inlink, main); + return ff_filter_frame(ctx->outputs[0], out); -static int filter_frame(AVFilterLink *inlink, AVFrame *in) -{ - PaletteUseContext *s = inlink->dst->priv; - return ff_dualinput_filter_frame(&s->dinput, inlink, in); +error: + av_frame_free(&main); + av_frame_free(&second); + return ret; } #define DEFINE_SET_FRAME(color_search, name, value) \ @@ -1013,9 +1034,6 @@ static int dither_value(int p) static av_cold int init(AVFilterContext *ctx) { PaletteUseContext *s = ctx->priv; - s->dinput.repeatlast = 1; // only 1 frame in the palette - s->dinput.skip_initial_unpaired = 1; - s->dinput.process = load_apply_palette; s->set_frame = set_frame_lut[s->color_search_method][s->dither]; @@ -1030,10 +1048,10 @@ static av_cold int init(AVFilterContext *ctx) return 0; } -static int request_frame(AVFilterLink *outlink) +static int activate(AVFilterContext *ctx) { - PaletteUseContext *s = outlink->src->priv; - return ff_dualinput_request_frame(&s->dinput, outlink); + PaletteUseContext *s = ctx->priv; + return ff_framesync2_activate(&s->fs); } static av_cold void uninit(AVFilterContext *ctx) @@ -1041,7 +1059,7 @@ static av_cold void uninit(AVFilterContext *ctx) int i; PaletteUseContext *s = ctx->priv; - ff_dualinput_uninit(&s->dinput); + ff_framesync2_uninit(&s->fs); for (i = 0; i < CACHE_SIZE; i++) av_freep(&s->cache[i].entries); av_frame_free(&s->last_in); @@ -1052,13 +1070,10 @@ static const AVFilterPad paletteuse_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, - .filter_frame = filter_frame, - .needs_writable = 1, // for error diffusal dithering },{ .name = "palette", .type = AVMEDIA_TYPE_VIDEO, .config_props = config_input_palette, - .filter_frame = filter_frame, }, { NULL } }; @@ -1068,7 +1083,6 @@ static const AVFilterPad paletteuse_outputs[] = { .name = "default", .type = AVMEDIA_TYPE_VIDEO, .config_props = config_output, - .request_frame = request_frame, }, { NULL } }; @@ -1080,6 +1094,7 @@ AVFilter ff_vf_paletteuse = { .query_formats = query_formats, .init = init, .uninit = uninit, + .activate = activate, .inputs = paletteuse_inputs, .outputs = paletteuse_outputs, .priv_class = &paletteuse_class,