From patchwork Thu Oct 24 06:09:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: leozhang X-Patchwork-Id: 15934 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3D943448816 for ; Thu, 24 Oct 2019 09:09:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 11D2468AFFB; Thu, 24 Oct 2019 09:09:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smg-bj-02.qiyi.com (unknown [202.108.14.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2AA7268A97D for ; Thu, 24 Oct 2019 09:09:20 +0300 (EEST) X-AuditID: ca6c0e64-aa9ff70000007f7f-d0-5db1400d5364 Received: from mail.iqiyi.com (Unknown_Domain [10.11.69.97]) by smg-bj-02.qiyi.com (Qiyi mail Gateway) with SMTP id 6E.FD.32639.D0041BD5; Thu, 24 Oct 2019 14:09:17 +0800 (HKT) From: leozhang To: Date: Thu, 24 Oct 2019 14:09:13 +0800 Message-ID: <1571897353-156056-1-git-send-email-leozhang@qiyi.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1571834065-74094-1-git-send-email-leozhang@qiyi.com> References: <1571834065-74094-1-git-send-email-leozhang@qiyi.com> MIME-Version: 1.0 X-Originating-IP: [10.39.144.216] X-ClientProxiedBy: BJ-CAS25.iqiyi.pps (10.11.50.117) To EXCH20.iqiyi.pps (10.16.148.50) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNLMWRmVeSWpSXmKPExsXCxe2aqMvrsDHWYPEGI4tvn84wOzB6/Fm0 mSWAMYrbJimxpCw4Mz1P3y6BO+P93n2sBV/kK/5teMTawHhQoouRk0NCwERi+5mHLF2MXBxC AhsZJTYfm84OkmATUJJYv2IqK4gtIiArsfrfFDYQW1ggSuLvq70sIDaLgKpEz7rrjCA2r4CT xPydHxkhhipITHn4nhnE5gSKf+9aAzZHSMBRYsKuy1D1ghInZz4Bm8MsICFx8MULZogaOYmn v36xQMxRlHj14B0ThB0psfzCDtYJjPyzkLTPQtK+gJFpFaNQcW66blKWroGRXmFmZaZecn7u JkZgOJ3K4UvZwXhwvvMhRgEORiUe3o6oDbFCrIllxZW5hxglOJiVRHh3q22MFeJNSaysSi3K jy8qzUktPsQozcGiJM7Lf3R9rJBAemJJanZqakFqEUyWiYMTpJtLSqQ4NS8ltSixtCQjHhTq 8cXAYJdqYNw3nW9hy47QrpKm4i+2Og8YNKbk6X2JPeAcqpbZd9nVxoXz0vmGj3O6shukbZfH Mc2RSj+n1tgXxbzu2PW12x6/6zR7rT/pcdrnf+/NeeU21fOkyORxVVg94XFmOXL0yo2oMyxq 8gLKBREPY1onGLgpf/5SVNWkFfJrutP65O1b4vNSDlnWKLEUZyQaajEXFScCAEiIvYw+AgAA Subject: [FFmpeg-devel] [PATCH V2] avfilter/vf_bilateral: process command to set the parameter at runtime 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Reviewed-by: Paul B Mahol Reviewed-by: Jun Zhao Signed-off-by: leozhang --- libavfilter/vf_bilateral.c | 60 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/libavfilter/vf_bilateral.c b/libavfilter/vf_bilateral.c index 3c9d800..87843eb 100644 --- a/libavfilter/vf_bilateral.c +++ b/libavfilter/vf_bilateral.c @@ -29,6 +29,8 @@ #include "internal.h" #include "video.h" +#include + typedef struct BilateralContext { const AVClass *class; @@ -54,7 +56,7 @@ typedef struct BilateralContext { } BilateralContext; #define OFFSET(x) offsetof(BilateralContext, x) -#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption bilateral_options[] = { { "sigmaS", "set spatial sigma", OFFSET(sigmaS), AV_OPT_TYPE_FLOAT, {.dbl=0.1}, 0.0, 10, FLAGS }, @@ -91,19 +93,27 @@ static int query_formats(AVFilterContext *ctx) return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts)); } -static int config_input(AVFilterLink *inlink) +static int init_lut(BilateralContext *s) { - BilateralContext *s = inlink->dst->priv; - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); float inv_sigma_range; - s->depth = desc->comp[0].depth; inv_sigma_range = 1.0f / (s->sigmaR * ((1 << s->depth) - 1)); //compute a lookup table for (int i = 0; i < (1 << s->depth); i++) s->range_table[i] = expf(-i * inv_sigma_range); + return 0; +} + +static int config_input(AVFilterLink *inlink) +{ + BilateralContext *s = inlink->dst->priv; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); + + s->depth = desc->comp[0].depth; + init_lut(s); + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); s->planewidth[0] = s->planewidth[3] = inlink->w; s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); @@ -325,6 +335,27 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return ff_filter_frame(outlink, out); } +static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, + char *res, int res_len, int flags) +{ + BilateralContext *s = ctx->priv; + int ret = 0; + + if ( !strcmp(cmd, "sigmaS") || !(strcmp(cmd, "sigmaR")) + || !strcmp(cmd, "planes")) { + float old_sigmaR = s->sigmaR; + + ret = av_opt_set(s, cmd, args, 0); + if (!ret && fabs(old_sigmaR - s->sigmaR) > FLT_EPSILON && (ret = init_lut(s)) < 0) { + s->sigmaR = old_sigmaR; + } + } else { + ret = AVERROR(ENOSYS); + } + + return ret; +} + static av_cold void uninit(AVFilterContext *ctx) { BilateralContext *s = ctx->priv; @@ -358,13 +389,14 @@ static const AVFilterPad bilateral_outputs[] = { }; AVFilter ff_vf_bilateral = { - .name = "bilateral", - .description = NULL_IF_CONFIG_SMALL("Apply Bilateral filter."), - .priv_size = sizeof(BilateralContext), - .priv_class = &bilateral_class, - .uninit = uninit, - .query_formats = query_formats, - .inputs = bilateral_inputs, - .outputs = bilateral_outputs, - .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, + .name = "bilateral", + .description = NULL_IF_CONFIG_SMALL("Apply Bilateral filter."), + .priv_size = sizeof(BilateralContext), + .priv_class = &bilateral_class, + .uninit = uninit, + .query_formats = query_formats, + .inputs = bilateral_inputs, + .outputs = bilateral_outputs, + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, + .process_command = process_command, };