diff mbox

[FFmpeg-devel,V3,2/2] avfilter/vf_bilateral: process command to set the parameter at runtime

Message ID 1574389195-79049-1-git-send-email-leozhang@qiyi.com
State New
Headers show

Commit Message

Leo Zhang Nov. 22, 2019, 2:19 a.m. UTC
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Jun Zhao <mypopy@gmail.com>
Reviewed-by: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: leozhang <leozhang@qiyi.com>
---
 doc/filters.texi           |  4 ++++
 libavfilter/vf_bilateral.c | 23 ++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index e48f9c9..6b1a5cb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -6355,6 +6355,10 @@  Allowed range is 0 to 1. Default is 0.1.
 Set planes to filter. Default is first only.
 @end table
 
+@subsection Commands
+
+This filter supports the all above options as @ref{commands}.
+
 @section bitplanenoise
 
 Show and measure bit plane noise.
diff --git a/libavfilter/vf_bilateral.c b/libavfilter/vf_bilateral.c
index 36e53d2..b2a3487 100644
--- a/libavfilter/vf_bilateral.c
+++ b/libavfilter/vf_bilateral.c
@@ -29,6 +29,8 @@ 
 #include "internal.h"
 #include "video.h"
 
+#include <float.h>
+
 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 },
@@ -333,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 (fabsf(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;
@@ -375,4 +395,5 @@  AVFilter ff_vf_bilateral = {
     .inputs        = bilateral_inputs,
     .outputs       = bilateral_outputs,
     .flags         = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
+    .process_command = process_command,
 };