[PATCH 1/2] Deprecate av_opt_show() in favor of a new function av_opt_show2(), which allows to specify only a subset of all the options to show.

Stefano Sabatini stefano.sabatini-lala
Wed Sep 1 00:09:39 CEST 2010


---
 ffmpeg.c             |    6 +++---
 libavcodec/avcodec.h |    1 +
 libavcodec/opt.c     |   19 ++++++++++++++-----
 libavcodec/opt.h     |   20 +++++++++++++++++++-
 4 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/ffmpeg.c b/ffmpeg.c
index f2f1067..63ccbc2 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -3909,11 +3909,11 @@ static void show_help(void)
                       OPT_GRAB,
                       OPT_GRAB);
     printf("\n");
-    av_opt_show(avcodec_opts[0], NULL);
+    av_opt_show2(avcodec_opts[0], NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
     printf("\n");
-    av_opt_show(avformat_opts, NULL);
+    av_opt_show2(avformat_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
     printf("\n");
-    av_opt_show(sws_opts, NULL);
+    av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
 }
 
 static void opt_target(const char *arg)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index b4b0cec..4bb0592 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -50,6 +50,7 @@
 #ifndef FF_API_PALETTE_CONTROL
 #define FF_API_PALETTE_CONTROL  (LIBAVCODEC_VERSION_MAJOR < 54)
 #endif
+#define FF_API_OPT_SHOW         (LIBAVCODEC_VERSION_MAJOR < 53)
 
 #define AV_NOPTS_VALUE          INT64_C(0x8000000000000000)
 #define AV_TIME_BASE            1000000
diff --git a/libavcodec/opt.c b/libavcodec/opt.c
index 128d95d..e3b2a0b 100644
--- a/libavcodec/opt.c
+++ b/libavcodec/opt.c
@@ -319,12 +319,13 @@ int64_t av_get_int(void *obj, const char *name, const AVOption **o_out){
     return num*intnum/den;
 }
 
-static void opt_list(void *obj, void *av_log_obj, const char *unit)
+static void opt_list(void *obj, void *av_log_obj, const char *unit,
+                     int req_flags, int rej_flags)
 {
     const AVOption *opt=NULL;
 
     while((opt= av_next_option(obj, opt))){
-        if(!(opt->flags & (AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM)))
+        if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
             continue;
 
         /* Don't print CONST's on level one.
@@ -383,22 +384,30 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit)
             av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
         av_log(av_log_obj, AV_LOG_INFO, "\n");
         if (opt->unit && opt->type != FF_OPT_TYPE_CONST) {
-            opt_list(obj, av_log_obj, opt->unit);
+            opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
         }
     }
 }
 
-int av_opt_show(void *obj, void *av_log_obj){
+int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
+{
     if(!obj)
         return -1;
 
     av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name);
 
-    opt_list(obj, av_log_obj, NULL);
+    opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
 
     return 0;
 }
 
+#if FF_API_OPT_SHOW
+int av_opt_show(void *obj, void *av_log_obj){
+    return av_opt_show2(obj, av_log_obj,
+                        AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
+}
+#endif
+
 /** Set the values of the AVCodecContext or AVFormatContext structure.
  * They are set to the defaults specified in the according AVOption options
  * array default_val field.
diff --git a/libavcodec/opt.h b/libavcodec/opt.h
index 9f0da72..d115b4d 100644
--- a/libavcodec/opt.h
+++ b/libavcodec/opt.h
@@ -204,7 +204,25 @@ AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
 int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
 const AVOption *av_next_option(void *obj, const AVOption *last);
-int av_opt_show(void *obj, void *av_log_obj);
+
+#if FF_API_OPT_SHOW < 53
+/**
+ * @deprecated Use av_opt_show2() instead.
+ */
+attribute_deprecated int av_opt_show(void *obj, void *av_log_obj);
+#endif
+
+/**
+ * Show the obj options.
+ *
+ * @param req_flags requested flags for the options to show. Only the
+ * options for which it is at least opt->flags & req_flags are shown.
+ * @param rej_flags rejected flags for the options to show. Only the
+ * options for which it is !(opt->flags & req_flags) are shown.
+ * @param av_log_obj log context to use for showing the options
+ */
+int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
+
 void av_opt_set_defaults(void *s);
 void av_opt_set_defaults2(void *s, int mask, int flags);
 
-- 
1.7.1


--WhfpMioaduB5tiZL--



More information about the ffmpeg-devel mailing list