From 2cb16ad7aa773c7b1415cd599524727ad874c4b8 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Tue, 30 Jun 2009 11:26:34 +0300 Subject: [PATCH] info: allow getting other log categories. Fixes #587417 Add a new macro GST_DEBUG_CATEGORY_GET to get a log category by name. This allows plugins to use e.g. core categories like PERFORMANCE or CLOCK. API: GST_DEBUG_CATEGORY_GET --- docs/gst/gstreamer-sections.txt | 1 + gst/gstinfo.c | 15 +++++++++++++++ gst/gstinfo.h | 39 ++++++++++++++++++++++++++++++++++++++- win32/common/libgstreamer.def | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 8c3e8e4..d994ea5 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -970,6 +970,7 @@ GST_DEBUG_CATEGORY GST_DEBUG_CATEGORY_EXTERN GST_DEBUG_CATEGORY_STATIC GST_DEBUG_CATEGORY_INIT +GST_DEBUG_CATEGORY_GET gst_debug_category_free gst_debug_category_set_threshold gst_debug_category_reset_threshold diff --git a/gst/gstinfo.c b/gst/gstinfo.c index e5f8243..f34eeb0 100644 --- a/gst/gstinfo.c +++ b/gst/gstinfo.c @@ -1470,6 +1470,21 @@ gst_debug_get_all_categories (void) return ret; } +GstDebugCategory * +_gst_debug_get_category (const gchar * name) +{ + GstDebugCategory *ret = NULL; + GSList *node; + + for (node = __categories; node; node = g_slist_next (node)) { + ret = (GstDebugCategory *) node->data; + if (!strcmp (name, ret->name)) { + return ret; + } + } + return NULL; +} + /*** FUNCTION POINTERS ********************************************************/ static GHashTable *__gst_function_pointers; /* NULL */ diff --git a/gst/gstinfo.h b/gst/gstinfo.h index d739480..925d932 100644 --- a/gst/gstinfo.h +++ b/gst/gstinfo.h @@ -350,7 +350,8 @@ void gst_debug_unset_threshold_for_name (const gchar * name); * This macro expands to nothing if debugging is disabled. */ #define GST_DEBUG_CATEGORY_STATIC(cat) static GstDebugCategory *cat = NULL -/* do not use this function, use the macros below */ + +/* do not use this function, use the GST_DEBUG_CATEGORY_INIT macro below */ GstDebugCategory *_gst_debug_category_new (const gchar * name, guint color, const gchar * description); @@ -408,6 +409,41 @@ G_CONST_RETURN gchar * GSList * gst_debug_get_all_categories (void); +/* do not use this function, use the GST_DEBUG_CATEGORY_GET macro below */ +GstDebugCategory *_gst_debug_get_category (const gchar *name); + +/** + * GST_DEBUG_CATEGORY_GET: + * @cat: the category to initialize. + * @name: log category name + * + * Lookup an exiting #GstDebugCategory by its @name and sets @cat. If category + * is not found, but %GST_CAT_DEFAULT is defined, that is assigned to @cat. + * Otherwise cat will be NULL. + * + * |[ + * GST_DEBUG_CATEGORY_STATIC (gst_myplugin_debug); + * #define GST_CAT_DEFAULT gst_myplugin_debug + * GST_DEBUG_CATEGORY_STATIC (GST_CAT_PERFORMANCE); + * ... + * GST_DEBUG_CATEGORY_INIT (gst_myplugin_debug, "myplugin", 0, "nice element"); + * GST_DEBUG_CATEGORY_GET (GST_CAT_PERFORMANCE, "performance); + * ]| + */ +#ifdef GST_CAT_DEFAULT +#define GST_DEBUG_CATEGORY_GET(cat,name) G_STMT_START{\ + cat = _gst_debug_get_category (name); \ + if (!cat) { \ + cat = GST_CAT_DEFAULT; \ + } \ +}G_STMT_END +#else +#define GST_DEBUG_CATEGORY_GET(cat,name) G_STMT_START{\ + cat = _gst_debug_get_category (name); \ +}G_STMT_END +#endif + + gchar * gst_debug_construct_term_color (guint colorinfo); gint gst_debug_construct_win_color (guint colorinfo); @@ -1126,6 +1162,7 @@ guint gst_debug_remove_log_function_by_data (gpointer data); #define GST_DEBUG_CATEGORY_STATIC(var) /* NOP */ #endif #define GST_DEBUG_CATEGORY_INIT(var,name,color,desc) /* NOP */ +#define GST_DEBUG_CATEGORY_GET(var,name) /* NOP */ #define gst_debug_category_free(category) /* NOP */ #define gst_debug_category_set_threshold(category,level) /* NOP */ #define gst_debug_category_reset_threshold(category) /* NOP */ diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index c737da9..231dcd3 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -39,6 +39,7 @@ EXPORTS _gst_debug_bin_to_dot_file_with_ts _gst_debug_category_new _gst_debug_dump_mem + _gst_debug_get_category _gst_debug_nameof_funcptr _gst_debug_register_funcptr _gst_element_error_printf -- 2.7.4