[FFmpeg-cvslog] avutil: add get_category() for the case where one AVClass can have more than 1 category

Michael Niedermayer git at videolan.org
Tue Jun 19 17:25:38 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sun Jun  3 22:39:54 2012 +0200| [e69263cd01380b7b20b92588dcac324bf776b59f] | committer: Michael Niedermayer

avutil: add get_category() for the case where one AVClass can have more than 1 category

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavutil/avutil.h |    2 +-
 libavutil/log.c    |   17 +++++++++++++----
 libavutil/log.h    |    8 ++++++++
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 169dc54..8819425 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -153,7 +153,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 58
+#define LIBAVUTIL_VERSION_MINOR 59
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/log.c b/libavutil/log.c
index 30f2ccd..e520a7b 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -121,6 +121,11 @@ const char *av_default_item_name(void *ptr)
     return (*(AVClass **) ptr)->class_name;
 }
 
+AVClassCategory av_default_get_category(void *ptr)
+{
+    return (*(AVClass **) ptr)->category;
+}
+
 static void sanitize(uint8_t *line){
     while(*line){
         if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
@@ -129,12 +134,16 @@ static void sanitize(uint8_t *line){
     }
 }
 
-static int get_category(AVClass *avc){
+static int get_category(void *ptr){
+    AVClass *avc = *(AVClass **) ptr;
     if(    !avc
         || (avc->version&0xFF)<100
-        ||  avc->version < (51 << 16 | 56 << 8)
+        ||  avc->version < (51 << 16 | 59 << 8)
         ||  avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16;
 
+    if(avc->get_category)
+        return avc->get_category(ptr) + 16;
+
     return avc->category + 16;
 }
 
@@ -151,12 +160,12 @@ static void format_line(void *ptr, int level, const char *fmt, va_list vl,
             if (parent && *parent) {
                 snprintf(part[0], part_size, "[%s @ %p] ",
                          (*parent)->item_name(parent), parent);
-                if(type) type[0] = get_category(*parent);
+                if(type) type[0] = get_category(((uint8_t *) ptr) + avc->parent_log_context_offset);
             }
         }
         snprintf(part[1], part_size, "[%s @ %p] ",
                  avc->item_name(ptr), ptr);
-        if(type) type[1] = get_category(avc);
+        if(type) type[1] = get_category(ptr);
     }
 
     vsnprintf(part[2], part_size, fmt, vl);
diff --git a/libavutil/log.h b/libavutil/log.h
index 951c60b..8d9601a 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -102,9 +102,16 @@ typedef struct AVClass {
 
     /**
      * Category used for visualization (like color)
+     * This is only set if the category is equal for all objects using this class.
      * available since version (51 << 16 | 56 << 8 | 100)
      */
     AVClassCategory category;
+
+    /**
+     * Callback to return the category.
+     * available since version (51 << 16 | 59 << 8 | 100)
+     */
+    AVClassCategory (*get_category)(void* ctx);
 } AVClass;
 
 /* av_log API */
@@ -167,6 +174,7 @@ void av_log_set_level(int);
 void av_log_set_callback(void (*)(void*, int, const char*, va_list));
 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
 const char* av_default_item_name(void* ctx);
+AVClassCategory av_default_get_category(void *ptr);
 
 /**
  * Format a line of log the same way as the default callback.



More information about the ffmpeg-cvslog mailing list