[Ffmpeg-cvslog] r6108 - in trunk: ffmpeg.c libavformat/avformat.h libavformat/utils.c

nicodvb subversion
Sun Aug 27 14:14:14 CEST 2006


Author: nicodvb
Date: Sun Aug 27 14:14:13 2006
New Revision: 6108

Modified:
   trunk/ffmpeg.c
   trunk/libavformat/avformat.h
   trunk/libavformat/utils.c

Log:
initial support for AVOption in AVFormatContext

Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c	(original)
+++ trunk/ffmpeg.c	Sun Aug 27 14:14:13 2006
@@ -252,6 +252,7 @@
 const char **opt_names=NULL;
 int opt_name_count=0;
 AVCodecContext *avctx_opts;
+AVFormatContext *avformat_opts;
 
 static AVBitStreamFilterContext *video_bitstream_filters=NULL;
 static AVBitStreamFilterContext *audio_bitstream_filters=NULL;
@@ -2780,7 +2781,10 @@
                    !strcmp( filename, "/dev/stdin" );
 
     /* get default parameters from command line */
+    ic = av_alloc_format_context();
+
     memset(ap, 0, sizeof(*ap));
+    ap->prealloced_context = 1;
     ap->sample_rate = audio_sample_rate;
     ap->channels = audio_channels;
     ap->time_base.den = frame_rate;
@@ -2797,6 +2801,12 @@
     if(pgmyuv_compatibility_hack)
         ap->video_codec_id= CODEC_ID_PGMYUV;
 
+    for(i=0; i<opt_name_count; i++){
+        AVOption *opt;
+        double d= av_get_double(avformat_opts, opt_names[i], &opt);
+        if(d==d && (opt->flags&AV_OPT_FLAG_DECODING_PARAM))
+            av_set_double(ic, opt_names[i], d);
+    }
     /* open the input file with generic libav function */
     err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
     if (err < 0) {
@@ -3929,6 +3939,8 @@
 static int opt_default(const char *opt, const char *arg){
     AVOption *o= av_set_string(avctx_opts, opt, arg);
     if(!o)
+        o = av_set_string(avformat_opts, opt, arg);
+    if(!o)
         return -1;
 
 //    av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avctx_opts, opt, NULL), (int)av_get_int(avctx_opts, opt, NULL));
@@ -4191,6 +4203,7 @@
                       OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB,
                       OPT_EXPERT);
     av_opt_show(avctx_opts, NULL);
+    av_opt_show(avformat_opts, NULL);
 
     exit(1);
 }
@@ -4208,6 +4221,7 @@
     av_register_all();
 
     avctx_opts= avcodec_alloc_context();
+    avformat_opts = av_alloc_format_context();
 
     if (argc <= 1)
         show_help();

Modified: trunk/libavformat/avformat.h
==============================================================================
--- trunk/libavformat/avformat.h	(original)
+++ trunk/libavformat/avformat.h	Sun Aug 27 14:14:13 2006
@@ -112,6 +112,7 @@
                                   mpeg2ts_raw is TRUE */
     int initial_pause:1;       /* do not begin to play the stream
                                   immediately (RTSP only) */
+    int prealloced_context:1;
     enum CodecID video_codec_id;
     enum CodecID audio_codec_id;
 } AVFormatParameters;

Modified: trunk/libavformat/utils.c
==============================================================================
--- trunk/libavformat/utils.c	(original)
+++ trunk/libavformat/utils.c	Sun Aug 27 14:14:13 2006
@@ -18,6 +18,7 @@
  */
 #include "avformat.h"
 #include "allformats.h"
+#include "opt.h"
 
 #undef NDEBUG
 #include <assert.h>
@@ -453,13 +454,28 @@
     else return "NULL";
 }
 
-static const AVClass av_format_context_class = { "AVFormatContext", format_to_name };
+#define OFFSET(x) (int)&((AVFormatContext*)0)->x
+#define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C
+//these names are too long to be readable
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[]={
+{NULL},
+};
+
+static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options };
+
+void avformat_get_context_defaults(AVFormatContext *s){
+    memset(s, 0, sizeof(AVFormatContext));
+}
 
 AVFormatContext *av_alloc_format_context(void)
 {
     AVFormatContext *ic;
     ic = av_mallocz(sizeof(AVFormatContext));
     if (!ic) return ic;
+    avformat_get_context_defaults(ic);
     ic->av_class = &av_format_context_class;
     return ic;
 }
@@ -481,7 +497,10 @@
         memset(ap, 0, sizeof(default_ap));
     }
 
-    ic = av_alloc_format_context();
+    if(!ap->prealloced_context)
+        ic = av_alloc_format_context();
+    else
+        ic = *ic_ptr;
     if (!ic) {
         err = AVERROR_NOMEM;
         goto fail;




More information about the ffmpeg-cvslog mailing list