---
 cmdutils.c |   24 ++++++++++++++++++++++
 cmdutils.h |    3 ++
 ffplay.c   |   63 +++++++++++++++++++++++++++++------------------------------
 3 files changed, 58 insertions(+), 32 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index a301bcf..66f279b 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -899,6 +899,30 @@ FILE *get_preset_file(char *filename, size_t filename_size,
     return f;
 }
 
+AVMetadata **setup_find_stream_info_opts(AVFormatContext *s)
+{
+    int i;
+    AVMetadata **opts;
+
+    if (!s->nb_streams)
+        return NULL;
+    opts = av_mallocz(s->nb_streams * sizeof(*opts));
+    for (i = 0; i < s->nb_streams; i++) {
+        AVCodecContext *dec = s->streams[i]->codec;
+        switch (dec->codec_type) {
+        case AVMEDIA_TYPE_AUDIO:
+            avmeta_copy(&opts[i], audio_opts, 0);
+            break;
+        case AVMEDIA_TYPE_VIDEO:
+            avmeta_copy(&opts[i], video_opts, 0);
+            break;
+        case AVMEDIA_TYPE_SUBTITLE:
+            avmeta_copy(&opts[i], sub_opts, 0);
+        }
+    }
+    return opts;
+}
+
 #if CONFIG_AVFILTER
 
 static int ffsink_init(AVFilterContext *ctx, const char *args, void *opaque)
diff --git a/cmdutils.h b/cmdutils.h
index 514d6b9..29bc74a 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -153,6 +153,9 @@ void parse_options(int argc, char **argv, const OptionDef 
*options,
 
 void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec);
 
+/** Set AVCodecContext options for avformat_find_stream_info */
+AVMetadata **setup_find_stream_info_opts(AVFormatContext *s);
+
 /**
  * Print an error message to stderr, indicating filename and a human
  * readable description of the error code err.
diff --git a/ffplay.c b/ffplay.c
index c3dc970..a851328 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -27,6 +27,7 @@
 #include "libavutil/colorspace.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/meta.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/samplefmt.h"
 #include "libavformat/avformat.h"
@@ -2195,11 +2196,19 @@ static int stream_component_open(VideoState *is, int 
stream_index)
     AVCodecContext *avctx;
     AVCodec *codec;
     SDL_AudioSpec wanted_spec, spec;
+    AVMetadata *opts = NULL;
+    AVMetadataTag *t;
 
     if (stream_index < 0 || stream_index >= ic->nb_streams)
         return -1;
     avctx = ic->streams[stream_index]->codec;
 
+    switch (avctx->codec_type) {
+    case AVMEDIA_TYPE_VIDEO:    opts = video_opts; break;
+    case AVMEDIA_TYPE_AUDIO:    opts = audio_opts; break;
+    case AVMEDIA_TYPE_SUBTITLE: opts = sub_opts;   break;
+    }
+
     /* prepare audio output */
     if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
         if (avctx->channels > 0) {
@@ -2224,11 +2233,13 @@ static int stream_component_open(VideoState *is, int 
stream_index)
     avctx->error_concealment= error_concealment;
     avctx->thread_count= thread_count;
 
-    set_context_opts(avctx, avcodec_opts[avctx->codec_type], 0, codec);
-
     if (!codec ||
-        avcodec_open(avctx, codec) < 0)
+        avcodec_open2(avctx, codec, &opts) < 0)
         return -1;
+    if ((t = avmeta_get(opts, "", NULL, AV_METADATA_IGNORE_SUFFIX))) {
+        av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
+        return AVERROR_OPTION_NOT_FOUND;
+    }
 
     /* prepare audio output */
     if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
@@ -2377,11 +2388,14 @@ static int decode_thread(void *arg)
     int err, i, ret;
     int st_index[AVMEDIA_TYPE_NB];
     AVPacket pkt1, *pkt = &pkt1;
-    AVFormatParameters params, *ap = &params;
     int eof=0;
     int pkt_in_play_range = 0;
+    AVMetadata **opts;
+    AVMetadataTag *t;
+    int orig_nb_streams;
 
     ic = avformat_alloc_context();
+    ic->iformat = is->iformat;
 
     memset(st_index, -1, sizeof(st_index));
     is->video_stream = -1;
@@ -2391,50 +2405,35 @@ static int decode_thread(void *arg)
     global_video_state = is;
     avio_set_interrupt_cb(decode_interrupt_cb);
 
-    memset(ap, 0, sizeof(*ap));
-
-    ap->prealloced_context = 1;
-    ap->width = frame_width;
-    ap->height= frame_height;
-    ap->time_base= (AVRational){1, 25};
-    ap->pix_fmt = frame_pix_fmt;
-
-    set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL);
-
-    err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
+    err = avformat_open_input(&ic, is->filename, &format_opts);
     if (err < 0) {
         print_error(is->filename, err);
         ret = -1;
         goto fail;
     }
+    if ((t = avmeta_get(format_opts, "", NULL, AV_METADATA_IGNORE_SUFFIX))) {
+        av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
+        ret = AVERROR_OPTION_NOT_FOUND;
+        goto fail;
+    }
     is->ic = ic;
 
     if(genpts)
         ic->flags |= AVFMT_FLAG_GENPTS;
 
-    /* Set AVCodecContext options so they will be seen by 
av_find_stream_info() */
-    for (i = 0; i < ic->nb_streams; i++) {
-        AVCodecContext *dec = ic->streams[i]->codec;
-        switch (dec->codec_type) {
-        case AVMEDIA_TYPE_AUDIO:
-            set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO],
-                             AV_OPT_FLAG_AUDIO_PARAM | 
AV_OPT_FLAG_DECODING_PARAM,
-                             NULL);
-            break;
-        case AVMEDIA_TYPE_VIDEO:
-            set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO],
-                             AV_OPT_FLAG_VIDEO_PARAM | 
AV_OPT_FLAG_DECODING_PARAM,
-                             NULL);
-            break;
-        }
-    }
+    opts = setup_find_stream_info_opts(ic);
+    orig_nb_streams = ic->nb_streams;
 
-    err = av_find_stream_info(ic);
+    err = avformat_find_stream_info(ic, opts);
     if (err < 0) {
         fprintf(stderr, "%s: could not find codec parameters\n", is->filename);
         ret = -1;
         goto fail;
     }
+    for (i = 0; i < orig_nb_streams; i++)
+        avmeta_free(&opts[i]);
+    av_freep(&opts);
+
     if(ic->pb)
         ic->pb->eof_reached= 0; //FIXME hack, ffplay maybe should not use 
url_feof() to test for the end
 
-- 
1.7.5.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to