[2/4] libavformat: Set options on demuxer AVFormatContexts after initializing the input

Message ID 1332161256-4284-2-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö March 19, 2012, 12:47 p.m.
This is in preparation for adding support for demuxer specific
defaults, where the input format needs to be known before setting
the defaults, which should be done before applying the user provided
options.
---
 libavformat/utils.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

Comments

Anton Khirnov March 19, 2012, 1:55 p.m. | #1
On Mon, 19 Mar 2012 14:47:36 +0200, Martin Storsjö <martin@martin.st> wrote:
> This is in preparation for adding support for demuxer specific
> defaults, where the input format needs to be known before setting
> the defaults, which should be done before applying the user provided
> options.
> ---

Looks ok.

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index f67d2d4..e2d940c 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -527,13 +527,30 @@  int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
     if (fmt)
         s->iformat = fmt;
 
-    if (options)
+    if (options) {
+        static const char* early_set_options[] = {
+            "probesize", NULL
+        };
+        const char** ptr;
         av_dict_copy(&tmp, *options, 0);
+        /* Set these options before calling init_input. We only set
+         * the options actually used by init_input, setting the rest
+         * of the options later after we've initialized them with
+         * demuxer specific defaults. */
+        for (ptr = early_set_options; *ptr; ptr++) {
+            AVDictionaryEntry* entry = av_dict_get(tmp, *ptr, NULL, 0);
+            if (entry) {
+                int ret = av_opt_set(s, entry->key, entry->value, 0);
+                if (ret == 0)
+                    av_dict_set(&tmp, *ptr, NULL, 0);
+            }
+        }
+    }
 
-    if ((ret = av_opt_set_dict(s, &tmp)) < 0)
+    if ((ret = init_input(s, filename, &tmp)) < 0)
         goto fail;
 
-    if ((ret = init_input(s, filename, &tmp)) < 0)
+    if ((ret = av_opt_set_dict(s, &tmp)) < 0)
         goto fail;
 
     /* check filename in case an image number is expected */