[FFmpeg-devel] [PATCH] lavu/opt: add av_opt_bprint()

Stefano Sabatini stefasab at gmail.com
Tue Nov 6 12:42:48 CET 2012


---
 libavutil/opt.c |   25 ++++++++++++++++++++++++-
 libavutil/opt.h |    6 ++++++
 2 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 11e757e..640459a 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -27,7 +27,7 @@
 
 #include "avutil.h"
 #include "avstring.h"
-#include "common.h"
+#include "bprint.h"
 #include "opt.h"
 #include "eval.h"
 #include "dict.h"
@@ -1027,6 +1027,22 @@ void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
     return (uint8_t*)obj + opt->offset;
 }
 
+void av_opt_bprint(struct AVBPrint *bp, void *obj)
+{
+    const AVOption *opt = NULL;
+    int is_first = 1;
+
+    while (opt = av_opt_next(obj, opt)) {
+        uint8_t *val;
+        av_opt_get(obj, opt->name, AV_OPT_SEARCH_CHILDREN, &val);
+        if (opt->offset) {
+            av_bprintf(bp, "%s%s=%s", is_first ? "" : " : ", opt->name, val);
+            av_freep(&val);
+        }
+        is_first = 0;
+    }
+}
+
 #ifdef TEST
 
 #undef printf
@@ -1079,6 +1095,7 @@ static const AVClass test_class = {
 int main(void)
 {
     int i;
+    AVBPrint bp;
 
     printf("\nTesting av_set_options_string()\n");
     {
@@ -1126,6 +1143,12 @@ int main(void)
                 av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);
             printf("\n");
         }
+
+        av_bprint_init(&bp, 1, AV_BPRINT_SIZE_UNLIMITED);
+        av_opt_bprint(&bp, &test_ctx);
+        printf("test_ctx = %s\n", bp.str);
+        av_bprint_clear(&bp);
+
         av_freep(&test_ctx.string);
     }
 
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 4a3b7f5..e97beaf 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -663,6 +663,12 @@ int av_opt_get_q     (void *obj, const char *name, int search_flags, AVRational
  *          or written to.
  */
 void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name);
+
+struct AVBPrint;
+/**
+ * Append a compact description of a context to a bprint buffer.
+ */
+void av_opt_bprint(struct AVBPrint *bp, void *obj);
 /**
  * @}
  */
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list