From patchwork Thu Oct 24 09:18:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: leozhang X-Patchwork-Id: 15935 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 4D4B64475AC for ; Thu, 24 Oct 2019 12:18:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2AEDD68B1DF; Thu, 24 Oct 2019 12:18:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smg-sh-01.qiyi.com (unknown [101.227.12.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7ACBD68B145 for ; Thu, 24 Oct 2019 12:18:24 +0300 (EEST) X-AuditID: 65e30cac-29bff70000001275-c8-5db16c58a8b8 Received: from mail.iqiyi.com (Unknown_Domain [10.11.69.96]) by smg-sh-01.qiyi.com (Qiyi mail Gateway) with SMTP id D3.77.04725.85C61BD5; Thu, 24 Oct 2019 17:18:16 +0800 (HKT) From: leozhang To: Date: Thu, 24 Oct 2019 17:18:12 +0800 Message-ID: <1571908692-30876-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.13.40.147] X-ClientProxiedBy: BJ-CAS24.iqiyi.pps (10.15.221.33) To EXCH20.iqiyi.pps (10.16.148.50) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNLMWRmVeSWpSXmKPExsXCxe2aoBuRszHWoHufmMW3T2eYHRg9/iza zBLAGMVtk5RYUhacmZ6nb5fAnXH+4DLGgl9yFYvWr2dvYGyV6GLk5JAQMJGYtWUFSxcjF4eQ wEZGicbu52wgCTYBJYn1K6aygtgiArISq/9NAYsLC0RJ/J/5kxHEZhFQlZj1qI0dxOYVcJSY NHU/I8RQBYkpD98zg9icAk4S37vWgM0RAqqZsOsyI0S9oMTJmU9YQGxmAQmJgy9eMEPUyEk8 /fWLBWbO095nzBB2pMSVlQ/YJzDyz0LSPgtJ+wJGplWMQsW56brFGboGhnqFmZWZesn5uZsY geGU+phnzQ7GZzucDzEKcDAq8fBWTN8QK8SaWFZcmXuIUYKDWUmEd7faxlgh3pTEyqrUovz4 otKc1OJDjNIcLErivEeTgFIC6YklqdmpqQWpRTBZJg5OkG4uKZHi1LyU1KLE0pKMeFCoxxcD g12qgTFfKnQG75tpVTUh77lcdI3fnG0vjQiepRbcOVft8NYKo3fB6oyO9p7VaknneeZuv3dk +5fOKaH59akpD65HW5x5fzsjdroCzwqe+bpyf7hWn2X9eT/3G9fUOwtbdryffEHq3ptdmszP 8pmrDgst0rnOw3jOpv1vrNizY0eZjj9eNnEl0Lk/0pVYijMSDbWYi4oTAfkDgpY+AgAA Subject: [FFmpeg-devel] [PATCH V3] 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 | 57 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/libavfilter/vf_bilateral.c b/libavfilter/vf_bilateral.c index 3c9d800..4d7bf68 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,24 @@ 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; + float old_sigmaR = s->sigmaR; + + if ((ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags)) < 0) { + return ret; + } + + if (fabs(old_sigmaR - s->sigmaR) > FLT_EPSILON && (ret = init_lut(s)) < 0) { + s->sigmaR = old_sigmaR; + } + + return ret; +} + static av_cold void uninit(AVFilterContext *ctx) { BilateralContext *s = ctx->priv; @@ -358,13 +386,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, };