AVOption are checked right after found in config file.
It allows to report exact line in config file.

Options provided more than once are threated as errors.

It also fixes flag options handing.
Flags may occur more than once in config file.

Signed-off-by: Lukasz Marek <lukasz.m.lu...@gmail.com>
---
 ffserver_config.c | 44 +++++++++++++++++++++++++++++++++-----------
 ffserver_config.h |  1 +
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/ffserver_config.c b/ffserver_config.c
index 045b791..cc8ee48 100644
--- a/ffserver_config.c
+++ b/ffserver_config.c
@@ -344,6 +344,27 @@ static int ffserver_set_float_param(float *dest, const 
char *value, float factor
     return AVERROR(EINVAL);
 }
 
+static int ffserver_save_avoption(const char *opt, const char *arg, 
AVDictionary **dict,
+                                  int type, FFServerConfig *config, int 
line_num)
+{
+    int ret = 0;
+    AVDictionaryEntry *e;
+    const AVOption *o = av_opt_find(config->dummy_ctx, opt, NULL, type, 
AV_OPT_SEARCH_CHILDREN);
+    if (!o) {
+        report_config_error(config->filename, line_num, AV_LOG_ERROR, 
&config->errors, "Option not found: %s\n", opt);
+    } else if ((ret = av_opt_set(config->dummy_ctx, opt, arg, 
AV_OPT_SEARCH_CHILDREN)) < 0) {
+        report_config_error(config->filename, line_num, AV_LOG_ERROR, 
&config->errors, "Invalid value for option %s (%s): %s\n", opt, arg, 
av_err2str(ret));
+    } else if ((e = av_dict_get(*dict, opt, NULL, 0))) {
+        if ((o->type == AV_OPT_TYPE_FLAGS) && arg && (arg[0] == '+' || arg[0] 
== '-'))
+            return av_dict_set(dict, opt, arg, AV_DICT_APPEND);
+        report_config_error(config->filename, line_num, AV_LOG_ERROR, 
&config->errors,
+                                "Redeclaring value of the option %s, previous 
value: %s\n", opt, e->value);
+    } else if (av_dict_set(dict, opt, arg, 0) < 0) {
+        return AVERROR(ENOMEM);
+    }
+    return 0;
+}
+
 #define ERROR(...)   report_config_error(config->filename, line_num, 
AV_LOG_ERROR,   &config->errors,   __VA_ARGS__)
 #define WARNING(...) report_config_error(config->filename, line_num, 
AV_LOG_WARNING, &config->warnings, __VA_ARGS__)
 
@@ -517,7 +538,6 @@ static int ffserver_parse_config_feed(FFServerConfig 
*config, const char *cmd, c
 static int ffserver_apply_stream_config(AVCodecContext *enc, const 
AVDictionary *conf, AVDictionary **opts)
 {
     AVDictionaryEntry *e;
-    int ret = 0;
 
     /* Return values from ffserver_set_*_param are ignored.
        Values are initially parsed and checked before inserting to 
AVDictionary. */
@@ -589,13 +609,8 @@ static int ffserver_apply_stream_config(AVCodecContext 
*enc, const AVDictionary
         ffserver_set_int_param(&enc->bit_rate, e->value, 0, INT_MIN, INT_MAX, 
NULL, 0, NULL);
 
     av_opt_set_dict2(enc, opts, AV_OPT_SEARCH_CHILDREN);
-    e = NULL;
-    while (e = av_dict_get(*opts, "", e, AV_DICT_IGNORE_SUFFIX)) {
-        av_log(NULL, AV_LOG_ERROR, "Provided AVOption '%s' doesn't match any 
existing option.\n", e->key);
-        ret = AVERROR(EINVAL);
-    }
 
-    return ret;
+    return 0;
 }
 
 static int ffserver_parse_config_stream(FFServerConfig *config, const char 
*cmd, const char **p,
@@ -613,6 +628,11 @@ static int ffserver_parse_config_stream(FFServerConfig 
*config, const char *cmd,
         stream = av_mallocz(sizeof(FFServerStream));
         if (!stream)
             return AVERROR(ENOMEM);
+        config->dummy_ctx = avcodec_alloc_context3(NULL);
+        if (!config->dummy_ctx) {
+            av_free(stream);
+            return AVERROR(ENOMEM);
+        }
         ffserver_get_arg(stream->filename, sizeof(stream->filename), p);
         q = strrchr(stream->filename, '>');
         if (q)
@@ -806,14 +826,14 @@ static int ffserver_parse_config_stream(FFServerConfig 
*config, const char *cmd,
             goto nomem;
     } else if (!av_strcasecmp(cmd, "AVOptionVideo") ||
                !av_strcasecmp(cmd, "AVOptionAudio")) {
-        AVDictionary **dict;
+        int ret;
         ffserver_get_arg(arg, sizeof(arg), p);
         ffserver_get_arg(arg2, sizeof(arg2), p);
         if (!av_strcasecmp(cmd, "AVOptionVideo"))
-            dict = &config->video_opts;
+            ret = ffserver_save_avoption(arg, arg2, &config->video_opts, 
AV_OPT_FLAG_VIDEO_PARAM ,config, line_num);
         else
-            dict = &config->audio_opts;
-        if (av_dict_set(dict, arg, arg2, 0) < 0)
+            ret = ffserver_save_avoption(arg, arg2, &config->audio_opts, 
AV_OPT_FLAG_AUDIO_PARAM ,config, line_num);
+        if (ret < 0)
             goto nomem;
     } else if (!av_strcasecmp(cmd, "AVPresetVideo") ||
                !av_strcasecmp(cmd, "AVPresetAudio")) {
@@ -911,6 +931,7 @@ static int ffserver_parse_config_stream(FFServerConfig 
*config, const char *cmd,
         av_dict_free(&config->video_conf);
         av_dict_free(&config->audio_opts);
         av_dict_free(&config->audio_conf);
+        avcodec_free_context(&config->dummy_ctx);
         *pstream = NULL;
     } else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, 
"ReadOnlyFile")) {
         ffserver_get_arg(stream->feed_filename, sizeof(stream->feed_filename), 
p);
@@ -924,6 +945,7 @@ static int ffserver_parse_config_stream(FFServerConfig 
*config, const char *cmd,
     av_dict_free(&config->video_conf);
     av_dict_free(&config->audio_opts);
     av_dict_free(&config->audio_conf);
+    avcodec_free_context(&config->dummy_ctx);
     return AVERROR(ENOMEM);
 }
 
diff --git a/ffserver_config.h b/ffserver_config.h
index f29f07f..c684fb5 100644
--- a/ffserver_config.h
+++ b/ffserver_config.h
@@ -113,6 +113,7 @@ typedef struct FFServerConfig {
     AVDictionary *video_conf;     /* Values stored in video 
AVCodecContext.fields */
     AVDictionary *audio_opts;     /* AVOptions for audio encoder */
     AVDictionary *audio_conf;     /* Values stored in audio 
AVCodecContext.fields */
+    AVCodecContext *dummy_ctx;    /* Used internally to test AVOptions, not to 
be used anywere else */
 } FFServerConfig;
 
 void ffserver_get_arg(char *buf, int buf_size, const char **pp);
-- 
1.9.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to