2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
35 /***** are we in the core or not? *****/
36 #ifdef __GST_PRIVATE_H__
37 #define _GST_DEBUG_INCORE TRUE
39 #define _GST_DEBUG_INCORE FALSE
43 /* colorization stuff */
44 #ifdef GST_DEBUG_COLOR
45 #ifdef __GST_PRIVATE_H__ /* FIXME this should be some libgst.la -specific thing */
46 #define GST_DEBUG_CHAR_MODE "00"
48 #define GST_DEBUG_CHAR_MODE "01"
52 gint _gst_debug_stringhash_color(gchar *file);
56 /**********************************************************************
58 **********************************************************************/
60 const gchar * gst_get_category_name (gint category);
63 GST_CAT_GST_INIT = 0, /* Library initialization */
64 GST_CAT_COTHREADS, /* Cothread creation, etc. */
65 GST_CAT_COTHREAD_SWITCH, /* Cothread switching */
66 GST_CAT_AUTOPLUG, /* Successful autoplug results */
67 GST_CAT_AUTOPLUG_ATTEMPT, /* Attempted autoplug operations */
68 GST_CAT_PARENTAGE, /* GstBin parentage issues */
69 GST_CAT_STATES, /* State changes and such */
70 GST_CAT_PLANNING, /* Plan generation */
71 GST_CAT_SCHEDULING, /* Schedule construction */
72 GST_CAT_DATAFLOW, /* Events during actual data movement */
73 GST_CAT_BUFFER, /* Buffer creation/destruction */
74 GST_CAT_CAPS, /* Capabilities matching */
75 GST_CAT_CLOCK, /* Clocking */
76 GST_CAT_ELEMENT_PADS, /* Element pad management */
77 GST_CAT_ELEMENTFACTORY, /* Elementfactory stuff */
78 GST_CAT_PADS, /* Pad creation/connection */
79 GST_CAT_PIPELINE, /* Pipeline stuff */
80 GST_CAT_PLUGIN_LOADING, /* Plugin loading */
81 GST_CAT_PLUGIN_ERRORS, /* Errors during plugin loading */
82 GST_CAT_PLUGIN_INFO, /* Plugin state information */
83 GST_CAT_PROPERTIES, /* Properties */
84 GST_CAT_THREAD, /* Thread creation/management */
85 GST_CAT_TYPES, /* Typing */
86 GST_CAT_XML, /* XML load/save of everything */
87 GST_CAT_NEGOTIATION, /* Caps Negotiation stuff */
88 GST_CAT_REFCOUNTING, /* Ref Counting stuff */
89 GST_CAT_EVENT, /* Event system */
90 GST_CAT_PARAMS, /* Dynamic parameters */
92 GST_CAT_CALL_TRACE = 30, /* Call tracing */
94 GST_CAT_MAX_CATEGORY = 31
97 extern const gchar *_gst_category_colors[32];
101 /**********************************************************************
103 **********************************************************************/
105 /* for include files that make too much noise normally */
106 #ifdef GST_DEBUG_FORCE_DISABLE
107 #undef GST_DEBUG_ENABLED
109 /* for applications that really really want all the noise */
110 #ifdef GST_DEBUG_FORCE_ENABLE
111 #define GST_DEBUG_ENABLED
114 /*#ifdef GST_DEBUG_ENABLED */
115 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
117 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
121 typedef void (*GstDebugHandler) (gint category,gboolean core,
122 const gchar *file,const gchar *function,
123 gint line,const gchar *debug_string,
124 void *element,gchar *string);
126 void gst_default_debug_handler (gint category,gboolean incore,
127 const gchar *file, const gchar *function,
128 gint line,const gchar *debug_string,
129 void *element,gchar *string);
131 extern guint32 _gst_debug_categories;
132 extern GstDebugHandler _gst_debug_handler;
134 /* fallback, this should probably be a 'weak' symbol or something */
135 G_GNUC_UNUSED static gchar *_debug_string = NULL;
140 #ifdef GST_DEBUG_ENABLED
141 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
142 if ((1<<cat) & _gst_debug_categories) \
143 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
144 NULL,g_strdup_printf( format , ## args )); \
147 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
148 if ((1<<cat) & _gst_debug_categories) \
149 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
150 element,g_strdup_printf( format , ## args )); \
154 #define GST_DEBUG(cat,format,args...)
155 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
161 /********** some convenience macros for debugging **********/
162 #define GST_DEBUG_PAD_NAME(pad) \
163 (GST_OBJECT_PARENT(pad) != NULL) ? \
164 GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
165 "''", GST_OBJECT_NAME (pad)
167 #ifdef GST_DEBUG_COLOR
168 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m\n" , ##args )
169 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m\n" , ##args )
171 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering\n" , ##args )
172 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving\n" , ##args )
176 /***** Colorized debug for thread ids *****/
177 #ifdef GST_DEBUG_COLOR
178 #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
179 #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
181 #define GST_DEBUG_THREAD_FORMAT "%d"
182 #define GST_DEBUG_THREAD_ARGS(id) (id)
187 /**********************************************************************
188 * The following is a DEBUG_ENTER implementation that will wrap the
189 * function it sits at the head of. It removes the need for a
190 * DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
191 * near cothreads. We will not use it for the moment.
193 typedef void (*_debug_function_f)();
194 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
195 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
197 #define _DEBUG_ENTER_BUILTIN(format,args...) \
198 static int _debug_in_wrapper = 0; \
199 gchar *_debug_string = ({ \
200 if (!_debug_in_wrapper) { \
201 void *_return_value; \
202 gchar *_debug_string; \
203 _debug_function_f function; \
204 void *_function_args = __builtin_apply_args(); \
205 _debug_in_wrapper = 1; \
206 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
207 _debug_string_pointer = _debug_string; \
208 fprintf(stderr,"%s: entered " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
209 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
210 g_module_symbol(_debug_self_module,__FUNCTION__,(gpointer *)&function); \
211 _return_value = __builtin_apply(function,_function_args,64); \
212 fprintf(stderr,"%s: left " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
213 g_free(_debug_string); \
214 __builtin_return(_return_value); \
216 _debug_in_wrapper = 0; \
218 _debug_string_pointer; \
221 * WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
222 * somehow make the preprocessor leave the _debug_string. If it's removed, the *
223 * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
224 #define _DEBUG_BUILTIN(format,args...) \
225 if (_debug_string != (void *)-1) { \
227 fprintf(stderr,"%s: " format , _debug_string , ## args); \
229 fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
236 /**********************************************************************
238 **********************************************************************/
240 typedef void (*GstInfoHandler) (gint category,gboolean incore,
241 const gchar *file,const gchar *function,
242 gint line,const gchar *debug_string,
243 void *element,gchar *string);
245 void gst_default_info_handler (gint category,gboolean incore,
246 const gchar *file,const gchar *function,
247 gint line,const gchar *debug_string,
248 void *element,gchar *string);
250 extern GstInfoHandler _gst_info_handler;
251 extern guint32 _gst_info_categories;
253 /* for include files that make too much noise normally */
254 #ifdef GST_INFO_FORCE_DISABLE
255 #undef GST_INFO_ENABLED
257 /* for applications that really really want all the noise */
258 #ifdef GST_INFO_FORCE_ENABLE
259 #define GST_INFO_ENABLED
262 #ifdef GST_INFO_ENABLED
263 #define GST_INFO(cat,format,args...) G_STMT_START{ \
264 if ((1<<cat) & _gst_info_categories) \
265 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
266 NULL,g_strdup_printf( format , ## args )); \
269 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
270 if ((1<<cat) & _gst_info_categories) \
271 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
272 element,g_strdup_printf( format , ## args )); \
276 #define GST_INFO(cat,format,args...)
277 #define GST_INFO_ELEMENT(cat,element,format,args...)
281 void gst_info_set_categories (guint32 categories);
282 guint32 gst_info_get_categories (void);
283 void gst_info_enable_category (gint category);
284 void gst_info_disable_category (gint category);
286 void gst_debug_set_categories (guint32 categories);
287 guint32 gst_debug_get_categories (void);
288 void gst_debug_enable_category (gint category);
289 void gst_debug_disable_category (gint category);
294 /**********************************************************************
296 **********************************************************************/
298 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
299 gint line,gchar *debug_string,
300 void *element,void *object,gchar *string);
302 void gst_default_error_handler (gchar *file,gchar *function,
303 gint line,gchar *debug_string,
304 void *element,void *object,gchar *string);
306 extern GstErrorHandler _gst_error_handler;
308 #define GST_ERROR(element,format,args...) \
309 _gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
310 element,NULL,g_strdup_printf( format , ## args ))
312 #define GST_ERROR_OBJECT(element,object,format,args...) \
313 _gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
314 element,object,g_strdup_printf( format , ## args ))
319 /********** function pointer stuff **********/
320 extern GHashTable *__gst_function_pointers;
323 #if GST_DEBUG_ENABLED
324 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
325 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
327 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
328 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
332 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
334 if (!__gst_function_pointers) __gst_function_pointers = g_hash_table_new(g_direct_hash,g_direct_equal);
335 if (!g_hash_table_lookup(__gst_function_pointers,ptr))
336 g_hash_table_insert(__gst_function_pointers,ptr,ptrname);
340 gchar *_gst_debug_nameof_funcptr (void *ptr);
342 void gst_debug_print_stack_trace (void);
346 #endif /* __GSTINFO_H__ */