[FFmpeg-devel,02/14] avfilter/avfilter: add ff_filter_process_command()

Submitted by Paul B Mahol on Oct. 9, 2019, 10:16 a.m.

Details

Message ID 20191009101705.7072-2-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol Oct. 9, 2019, 10:16 a.m.
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/avfilter.c | 13 +++++++++++++
 libavfilter/internal.h |  7 +++++++
 2 files changed, 20 insertions(+)

Comments

Michael Niedermayer Oct. 9, 2019, 5:03 p.m.
On Wed, Oct 09, 2019 at 12:16:53PM +0200, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavfilter/avfilter.c | 13 +++++++++++++
>  libavfilter/internal.h |  7 +++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 93e866b79c..4d462d4e0a 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -884,6 +884,19 @@ static int process_options(AVFilterContext *ctx, AVDictionary **options,
>      return count;
>  }
>  
> +int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
> +                              const char *arg, char *res, int res_len, int flags)
> +{
> +    const AVOption *o;
> +
> +    if (!ctx->filter->priv_class)
> +        return 0;
> +    o = av_opt_find2(ctx->priv, cmd, NULL, AV_OPT_FLAG_COMMAND_PARAM | AV_OPT_FLAG_FILTERING_PARAM, AV_OPT_SEARCH_CHILDREN, NULL);
> +    if (!o)
> +        return AVERROR(ENOSYS);
> +    return av_opt_set(ctx->priv, cmd, arg, 0);
> +}

I am just puzzled why we did not do this before already. I do remember disliking
all the command code ...

patch LGTM but please give others time to comment before applying

thx

[...]
Moritz Barsnick Oct. 10, 2019, 9:35 a.m.
On Wed, Oct 09, 2019 at 12:16:53 +0200, Paul B Mahol wrote:
> +int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
> +                              const char *arg, char *res, int res_len, int flags)

Are res and res_len reserved for future use? I didn't put this through
a compiler, but I don't see them being used in this function.

Cheers,
Moritz
Moritz Barsnick Oct. 10, 2019, 9:45 a.m.
On Thu, Oct 10, 2019 at 11:35:29 +0200, Moritz Barsnick wrote:
> On Wed, Oct 09, 2019 at 12:16:53 +0200, Paul B Mahol wrote:
> > +int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
> > +                              const char *arg, char *res, int res_len, int flags)
>
> Are res and res_len reserved for future use? I didn't put this through
> a compiler, but I don't see them being used in this function.

Ah, forget it, it's for compatibility with the callback API.
(Not sure whether the compiler will warn though.)

Moritz

Patch hide | download patch | download mbox

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 93e866b79c..4d462d4e0a 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -884,6 +884,19 @@  static int process_options(AVFilterContext *ctx, AVDictionary **options,
     return count;
 }
 
+int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
+                              const char *arg, char *res, int res_len, int flags)
+{
+    const AVOption *o;
+
+    if (!ctx->filter->priv_class)
+        return 0;
+    o = av_opt_find2(ctx->priv, cmd, NULL, AV_OPT_FLAG_COMMAND_PARAM | AV_OPT_FLAG_FILTERING_PARAM, AV_OPT_SEARCH_CHILDREN, NULL);
+    if (!o)
+        return AVERROR(ENOSYS);
+    return av_opt_set(ctx->priv, cmd, arg, 0);
+}
+
 int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
 {
     int ret = 0;
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 498bd3328d..1d77808082 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -411,6 +411,13 @@  static inline int ff_norm_qscale(int qscale, int type)
  */
 int ff_filter_get_nb_threads(AVFilterContext *ctx);
 
+/**
+ * Generic processing of user supplied commands that are set
+ * in the same way as the filter options.
+ */
+int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
+                              const char *arg, char *res, int res_len, int flags);
+
 /**
  * Perform any additional setup required for hardware frames.
  *