diff mbox series

[FFmpeg-devel,1/5] lavfi/avfilter: export process_options()

Message ID 20230120193132.21597-1-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,1/5] lavfi/avfilter: export process_options() | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Jan. 20, 2023, 7:31 p.m. UTC
Also, replace an AVFilterContext argument with a logging context+private
class, as those are the only things needed in this function.

Will be useful in future commits.
---
 libavfilter/avfilter.c | 20 ++++++++++----------
 libavfilter/internal.h | 13 +++++++++++++
 2 files changed, 23 insertions(+), 10 deletions(-)

Comments

Anton Khirnov Jan. 27, 2023, 4:47 p.m. UTC | #1
If nobody has further comments, I would like to push this set next week.
Nicolas George Jan. 27, 2023, 4:48 p.m. UTC | #2
Anton Khirnov (12023-01-27):
> If nobody has further comments, I would like to push this set next week.

I have already said I would have comments.
Anton Khirnov Jan. 27, 2023, 4:51 p.m. UTC | #3
Quoting Nicolas George (2023-01-27 17:48:02)
> Anton Khirnov (12023-01-27):
> > If nobody has further comments, I would like to push this set next week.
> 
> I have already said I would have comments.

Send them then.
It's been almost two weeks since my initial RFC, and the code is quite
straightforward.
Nicolas George Jan. 27, 2023, 4:53 p.m. UTC | #4
Anton Khirnov (12023-01-27):
> Send them then.
> It's been almost two weeks since my initial RFC,

And if you have to wait ten more weeks for a proper review, you will
wait ten more weeks.

>						   and the code is quite
> straightforward.

No, it is not. I have seen likely flaws, but I need time to make sure.
diff mbox series

Patch

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index c2ecdffa6f..86b275dc4f 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -797,8 +797,8 @@  int ff_filter_get_nb_threads(AVFilterContext *ctx)
     return ctx->graph->nb_threads;
 }
 
-static int process_options(AVFilterContext *ctx, AVDictionary **options,
-                           const char *args)
+int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
+                        AVDictionary **options, const char *args)
 {
     const AVOption *o = NULL;
     int ret;
@@ -812,8 +812,8 @@  static int process_options(AVFilterContext *ctx, AVDictionary **options,
     while (*args) {
         const char *shorthand = NULL;
 
-        if (ctx->filter->priv_class)
-            o = av_opt_next(ctx->priv, o);
+        if (priv_class)
+            o = av_opt_next(&priv_class, o);
         if (o) {
             if (o->type == AV_OPT_TYPE_CONST || o->offset == offset)
                 continue;
@@ -826,9 +826,9 @@  static int process_options(AVFilterContext *ctx, AVDictionary **options,
                                    &parsed_key, &value);
         if (ret < 0) {
             if (ret == AVERROR(EINVAL))
-                av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", args);
+                av_log(logctx, AV_LOG_ERROR, "No option name near '%s'\n", args);
             else
-                av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", args,
+                av_log(logctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", args,
                        av_err2str(ret));
             return ret;
         }
@@ -838,13 +838,13 @@  static int process_options(AVFilterContext *ctx, AVDictionary **options,
             key = parsed_key;
 
             /* discard all remaining shorthand */
-            if (ctx->filter->priv_class)
-                while ((o = av_opt_next(ctx->priv, o)));
+            if (priv_class)
+                while ((o = av_opt_next(&priv_class, o)));
         } else {
             key = shorthand;
         }
 
-        av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
+        av_log(logctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
 
         av_dict_set(options, key, value, AV_DICT_MULTIKEY);
 
@@ -908,7 +908,7 @@  int avfilter_init_str(AVFilterContext *filter, const char *args)
     int ret = 0;
 
     if (args && *args) {
-        ret = process_options(filter, &options, args);
+        ret = ff_filter_opt_parse(filter, filter->filter->priv_class, &options, args);
         if (ret < 0)
             goto fail;
     }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index aaf2c6c584..2ec41917f7 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -405,4 +405,17 @@  int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
 int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
                              int default_pool_size);
 
+/**
+ * Parse filter options into a dictionary.
+ *
+ * @param logctx context for logging
+ * @param priv_class a filter's private class for shorthand options or NULL
+ * @param options dictionary to store parsed options in
+ * @param args options string to parse
+ *
+ * @return a non-negative number on success, a negative error code on failure
+ */
+int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
+                        AVDictionary **options, const char *args);
+
 #endif /* AVFILTER_INTERNAL_H */