[FFmpeg-cvslog] AVOptions: deprecate av_opt_set_defaults2

Anton Khirnov git at videolan.org
Wed Sep 7 23:07:26 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun Sep  4 11:42:41 2011 +0200| [79eff9132581af69fbbd2674337b75fad29aa306] | committer: Anton Khirnov

AVOptions: deprecate av_opt_set_defaults2

It's a hack which was created to allow for multiple options with
different defaults to refer to same field (e.g. 'b' vs 'ab'). There is
no need for it anymore.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=79eff9132581af69fbbd2674337b75fad29aa306
---

 libavcodec/options.c      |    9 +--------
 libavfilter/vf_drawtext.c |    2 +-
 libavfilter/vsrc_movie.c  |    2 +-
 libavutil/avutil.h        |    3 +++
 libavutil/opt.c           |   16 ++++++++++------
 libavutil/opt.h           |    4 ++++
 6 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/libavcodec/options.c b/libavcodec/options.c
index 098778a..7d14beb 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -519,19 +519,12 @@ static const AVOption options[]={
 static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options, LIBAVUTIL_VERSION_INT, OFFSET(log_level_offset), .opt_find = opt_find};
 
 void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){
-    int flags=0;
     memset(s, 0, sizeof(AVCodecContext));
 
     s->av_class= &av_codec_context_class;
 
     s->codec_type = codec_type;
-    if(codec_type == AVMEDIA_TYPE_AUDIO)
-        flags= AV_OPT_FLAG_AUDIO_PARAM;
-    else if(codec_type == AVMEDIA_TYPE_VIDEO)
-        flags= AV_OPT_FLAG_VIDEO_PARAM;
-    else if(codec_type == AVMEDIA_TYPE_SUBTITLE)
-        flags= AV_OPT_FLAG_SUBTITLE_PARAM;
-    av_opt_set_defaults2(s, flags, flags);
+    av_opt_set_defaults(s);
 
     s->time_base= (AVRational){0,1};
     s->get_buffer= avcodec_default_get_buffer;
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index ed4b100..3e16baf 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -223,7 +223,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     Glyph *glyph;
 
     dtext->class = &drawtext_class;
-    av_opt_set_defaults2(dtext, 0, 0);
+    av_opt_set_defaults(dtext);
     dtext->fontcolor_string = av_strdup("black");
     dtext->boxcolor_string = av_strdup("white");
     dtext->shadowcolor_string = av_strdup("black");
diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c
index b018ba7..a5d5572 100644
--- a/libavfilter/vsrc_movie.c
+++ b/libavfilter/vsrc_movie.c
@@ -164,7 +164,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
     MovieContext *movie = ctx->priv;
     int ret;
     movie->class = &movie_class;
-    av_opt_set_defaults2(movie, 0, 0);
+    av_opt_set_defaults(movie);
 
     if (args)
         movie->file_name = av_get_token(&args, ":");
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 2459410..3f92679 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -66,6 +66,9 @@
 #ifndef FF_API_AV_FIFO_PEEK
 #define FF_API_AV_FIFO_PEEK             (LIBAVUTIL_VERSION_MAJOR < 52)
 #endif
+#ifndef FF_API_OLD_AVOPTIONS
+#define FF_API_OLD_AVOPTIONS            (LIBAVUTIL_VERSION_MAJOR < 52)
+#endif
 
 /**
  * Return the LIBAVUTIL_VERSION_INT constant.
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 0dd58a7..160da8d 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -414,12 +414,21 @@ int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
     return 0;
 }
 
+void av_opt_set_defaults(void *s)
+{
+#if FF_API_OLD_AVOPTIONS
+    av_opt_set_defaults2(s, 0, 0);
+}
+
 void av_opt_set_defaults2(void *s, int mask, int flags)
 {
+#endif
     const AVOption *opt = NULL;
     while ((opt = av_next_option(s, opt)) != NULL) {
+#if FF_API_OLD_AVOPTIONS
         if ((opt->flags & mask) != flags)
             continue;
+#endif
         switch (opt->type) {
             case FF_OPT_TYPE_CONST:
                 /* Nothing to be done here */
@@ -461,11 +470,6 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
     }
 }
 
-void av_opt_set_defaults(void *s)
-{
-    av_opt_set_defaults2(s, 0, 0);
-}
-
 /**
  * Store the value in the field in ctx that is named like key.
  * ctx must be an AVClass context, storing is done using AVOptions.
@@ -648,7 +652,7 @@ int main(void)
         };
 
         test_ctx.class = &test_class;
-        av_opt_set_defaults2(&test_ctx, 0, 0);
+        av_opt_set_defaults(&test_ctx);
         test_ctx.string = av_strdup("default");
 
         av_log_set_level(AV_LOG_DEBUG);
diff --git a/libavutil/opt.h b/libavutil/opt.h
index f8eea6b..c6a5919 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -166,7 +166,11 @@ int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
  * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
  */
 void av_opt_set_defaults(void *s);
+
+#if FF_API_OLD_AVOPTIONS
+attribute_deprecated
 void av_opt_set_defaults2(void *s, int mask, int flags);
+#endif
 
 /**
  * Parse the key/value pairs list in opts. For each key/value pair



More information about the ffmpeg-cvslog mailing list