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.
34 /***** are we in the core or not? *****/
35 #ifdef __GST_PRIVATE_H__
36 #define _GST_DEBUG_INCORE TRUE
38 #define _GST_DEBUG_INCORE FALSE
42 /* colorization stuff */
43 #ifdef GST_DEBUG_COLOR
44 #ifdef __GST_PRIVATE_H__ /* FIXME this should be some libgst.la -specific thing */
45 #define GST_DEBUG_CHAR_MODE "00"
47 #define GST_DEBUG_CHAR_MODE "01"
51 gint _gst_debug_stringhash_color(gchar *file);
55 /**********************************************************************
57 **********************************************************************/
59 const gchar * gst_get_category_name (gint category);
62 GST_CAT_GST_INIT = 0, /* Library initialization */
63 GST_CAT_COTHREADS, /* Cothread creation, etc. */
64 GST_CAT_COTHREAD_SWITCH, /* Cothread switching */
65 GST_CAT_AUTOPLUG, /* Successful autoplug results */
66 GST_CAT_AUTOPLUG_ATTEMPT, /* Attempted autoplug operations */
67 GST_CAT_PARENTAGE, /* GstBin parentage issues */
68 GST_CAT_STATES, /* State changes and such */
69 GST_CAT_PLANNING, /* Plan generation */
70 GST_CAT_SCHEDULING, /* Schedule construction */
71 GST_CAT_DATAFLOW, /* Events during actual data movement */
72 GST_CAT_BUFFER, /* Buffer creation/destruction */
73 GST_CAT_CAPS, /* Capabilities matching */
74 GST_CAT_CLOCK, /* Clocking */
75 GST_CAT_ELEMENT_PADS, /* Element pad management */
76 GST_CAT_ELEMENT_FACTORY, /* Elementfactory stuff */
77 GST_CAT_PADS, /* Pad creation/connection */
78 GST_CAT_PIPELINE, /* Pipeline stuff */
79 GST_CAT_PLUGIN_LOADING, /* Plugin loading */
80 GST_CAT_PLUGIN_ERRORS, /* Errors during plugin loading */
81 GST_CAT_PLUGIN_INFO, /* Plugin state information */
82 GST_CAT_PROPERTIES, /* Properties */
83 GST_CAT_THREAD, /* Thread creation/management */
84 GST_CAT_TYPES, /* Typing */
85 GST_CAT_XML, /* XML load/save of everything */
86 GST_CAT_NEGOTIATION, /* Caps Negotiation stuff */
87 GST_CAT_REFCOUNTING, /* Ref Counting stuff */
88 GST_CAT_EVENT, /* Event system */
89 GST_CAT_PARAMS, /* Dynamic parameters */
91 GST_CAT_CALL_TRACE = 30, /* Call tracing */
93 GST_CAT_MAX_CATEGORY = 31
96 extern const gchar *_gst_category_colors[32];
100 /**********************************************************************
102 **********************************************************************/
104 /* for include files that make too much noise normally */
105 #ifdef GST_DEBUG_FORCE_DISABLE
106 #undef GST_DEBUG_ENABLED
108 /* for applications that really really want all the noise */
109 #ifdef GST_DEBUG_FORCE_ENABLE
110 #define GST_DEBUG_ENABLED
113 /*#ifdef GST_DEBUG_ENABLED */
114 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
116 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
120 typedef void (*GstDebugHandler) (gint category,gboolean core,
121 const gchar *file,const gchar *function,
122 gint line,const gchar *debug_string,
123 void *element,gchar *string);
125 void gst_default_debug_handler (gint category,gboolean incore,
126 const gchar *file, const gchar *function,
127 gint line,const gchar *debug_string,
128 void *element,gchar *string);
130 extern guint32 _gst_debug_categories;
131 extern GstDebugHandler _gst_debug_handler;
133 /* fallback, this should probably be a 'weak' symbol or something */
134 G_GNUC_UNUSED static gchar *_debug_string = NULL;
138 #ifdef G_HAVE_ISO_VARARGS
140 #ifdef GST_DEBUG_ENABLED
141 #define GST_DEBUG(cat, ...) G_STMT_START{ \
142 if ((1<<cat) & _gst_debug_categories) \
143 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
144 NULL,g_strdup_printf( __VA_ARGS__ )); \
147 #define GST_DEBUG_ELEMENT(cat, element, ...) G_STMT_START{ \
148 if ((1<<cat) & _gst_debug_categories) \
149 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
150 element,g_strdup_printf( __VA_ARGS__ )); \
154 #define GST_DEBUG(cat, ...)
155 #define GST_DEBUG_ELEMENT(cat,element, ...)
158 #elif defined(G_HAVE_GNUC_VARARGS)
160 #ifdef GST_DEBUG_ENABLED
161 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
162 if ((1<<cat) & _gst_debug_categories) \
163 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
164 NULL,g_strdup_printf( format , ## args )); \
167 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
168 if ((1<<cat) & _gst_debug_categories) \
169 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
170 element,g_strdup_printf( format , ## args )); \
174 #define GST_DEBUG(cat,format,args...)
175 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
183 /********** some convenience macros for debugging **********/
184 #define GST_DEBUG_PAD_NAME(pad) \
185 (GST_OBJECT_PARENT(pad) != NULL) ? \
186 GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
187 "''", GST_OBJECT_NAME (pad)
189 #ifdef G_HAVE_ISO_VARARGS
191 #ifdef GST_DEBUG_COLOR
192 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "\033[00;37mentering\033[00m :" __VA_ARGS__ )
193 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "\033[00;37mleaving\033[00m :" __VA_ARGS__ )
195 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "entering :" __VA_ARGS__ )
196 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "leaving :" __VA_ARGS__ )
199 #elif defined(G_HAVE_GNUC_VARARGS)
201 #ifdef GST_DEBUG_COLOR
202 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
203 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
205 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
206 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
212 /***** Colorized debug for thread ids *****/
213 #ifdef GST_DEBUG_COLOR
214 #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
215 #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
217 #define GST_DEBUG_THREAD_FORMAT "%d"
218 #define GST_DEBUG_THREAD_ARGS(id) (id)
223 /**********************************************************************
224 * The following is a DEBUG_ENTER implementation that will wrap the
225 * function it sits at the head of. It removes the need for a
226 * DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
227 * near cothreads. We will not use it for the moment.
229 typedef void (*_debug_function_f)();
230 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
231 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
233 #ifdef G_HAVE_ISO_VARARGS
235 #define _DEBUG_ENTER_BUILTIN(...) \
236 static int _debug_in_wrapper = 0; \
237 gchar *_debug_string = ({ \
238 if (!_debug_in_wrapper) { \
239 void *_return_value; \
240 gchar *_debug_string; \
241 _debug_function_f function; \
242 void *_function_args = __builtin_apply_args(); \
243 _debug_in_wrapper = 1; \
244 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
245 _debug_string_pointer = _debug_string; \
246 fprintf(stderr,"%s: entered " FUNCTION, _debug_string); \
247 fprintf(stderr, __VA_ARGS__ ); \
248 fprintf(stderr,"\n"); \
249 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
250 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
251 _return_value = __builtin_apply(function,_function_args,64); \
252 fprintf(stderr,"%s: left " FUNCTION, _debug_string); \
253 fprintf(stderr, __VA_ARGS__); \
254 fprintf(stderr,"\n"); \
255 g_free(_debug_string); \
256 __builtin_return(_return_value); \
258 _debug_in_wrapper = 0; \
260 _debug_string_pointer; \
263 #elif defined(G_HAVE_GNUC_VARARGS)
265 #define _DEBUG_ENTER_BUILTIN(format,args...) \
266 static int _debug_in_wrapper = 0; \
267 gchar *_debug_string = ({ \
268 if (!_debug_in_wrapper) { \
269 void *_return_value; \
270 gchar *_debug_string; \
271 _debug_function_f function; \
272 void *_function_args = __builtin_apply_args(); \
273 _debug_in_wrapper = 1; \
274 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
275 _debug_string_pointer = _debug_string; \
276 fprintf(stderr,"%s: entered " FUNCTION format "\n" , _debug_string , ## args ); \
277 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
278 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
279 _return_value = __builtin_apply(function,_function_args,64); \
280 fprintf(stderr,"%s: left " FUNCTION format "\n" , _debug_string , ## args ); \
281 g_free(_debug_string); \
282 __builtin_return(_return_value); \
284 _debug_in_wrapper = 0; \
286 _debug_string_pointer; \
291 * WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
292 * somehow make the preprocessor leave the _debug_string. If it's removed, the *
293 * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
295 #ifdef G_HAVE_ISO_VARARGS
297 #define _DEBUG_BUILTIN(...) \
298 if (_debug_string != (void *)-1) { \
299 if (_debug_string) { \
300 fprintf(stderr, "%s: " _debug_string); \
301 fprintf(stderr, __VA_ARGS__); \
303 fprintf(stderr,GST_DEBUG_PREFIX(": " __VA_ARGS__)); \
307 #elif defined(G_HAVE_GNUC_VARARGS)
309 #define _DEBUG_BUILTIN(format,args...) \
310 if (_debug_string != (void *)-1) { \
312 fprintf(stderr,"%s: " format , _debug_string , ## args); \
314 fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
323 /**********************************************************************
325 **********************************************************************/
327 typedef void (*GstInfoHandler) (gint category,gboolean incore,
328 const gchar *file,const gchar *function,
329 gint line,const gchar *debug_string,
330 void *element,gchar *string);
332 void gst_default_info_handler (gint category,gboolean incore,
333 const gchar *file,const gchar *function,
334 gint line,const gchar *debug_string,
335 void *element,gchar *string);
337 extern GstInfoHandler _gst_info_handler;
338 extern guint32 _gst_info_categories;
340 /* for include files that make too much noise normally */
341 #ifdef GST_INFO_FORCE_DISABLE
342 #undef GST_INFO_ENABLED
344 /* for applications that really really want all the noise */
345 #ifdef GST_INFO_FORCE_ENABLE
346 #define GST_INFO_ENABLED
349 #ifdef G_HAVE_ISO_VARARGS
351 #ifdef GST_INFO_ENABLED
352 #define GST_INFO(cat,...) G_STMT_START{ \
353 if ((1<<cat) & _gst_info_categories) \
354 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
355 NULL,g_strdup_printf( __VA_ARGS__ )); \
358 #define GST_INFO_ELEMENT(cat,element,...) G_STMT_START{ \
359 if ((1<<cat) & _gst_info_categories) \
360 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
361 element,g_strdup_printf( __VA_ARGS__ )); \
365 #define GST_INFO(cat,...)
366 #define GST_INFO_ELEMENT(cat,element,...)
369 #elif defined(G_HAVE_GNUC_VARARGS)
371 #ifdef GST_INFO_ENABLED
372 #define GST_INFO(cat,format,args...) G_STMT_START{ \
373 if ((1<<cat) & _gst_info_categories) \
374 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
375 NULL,g_strdup_printf( format , ## args )); \
378 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
379 if ((1<<cat) & _gst_info_categories) \
380 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
381 element,g_strdup_printf( format , ## args )); \
385 #define GST_INFO(cat,format,args...)
386 #define GST_INFO_ELEMENT(cat,element,format,args...)
392 void gst_info_set_categories (guint32 categories);
393 guint32 gst_info_get_categories (void);
394 void gst_info_enable_category (gint category);
395 void gst_info_disable_category (gint category);
397 void gst_debug_set_categories (guint32 categories);
398 guint32 gst_debug_get_categories (void);
399 void gst_debug_enable_category (gint category);
400 void gst_debug_disable_category (gint category);
405 /**********************************************************************
407 **********************************************************************/
409 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
410 gint line,gchar *debug_string,
411 void *element,void *object,gchar *string);
413 void gst_default_error_handler (gchar *file,gchar *function,
414 gint line,gchar *debug_string,
415 void *element,void *object,gchar *string);
417 extern GstErrorHandler _gst_error_handler;
419 #ifdef G_HAVE_ISO_VARARGS
421 #define GST_ERROR(element,...) \
422 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
423 element,NULL,g_strdup_printf( __VA_ARGS__ ))
425 #define GST_ERROR_OBJECT(element,object,...) \
426 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
427 element,object,g_strdup_printf( __VA_ARGS__ ))
429 #elif defined(G_HAVE_GNUC_VARARGS)
431 #define GST_ERROR(element,format,args...) \
432 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
433 element,NULL,g_strdup_printf( format , ## args ))
435 #define GST_ERROR_OBJECT(element,object,format,args...) \
436 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
437 element,object,g_strdup_printf( format , ## args ))
444 /********** function pointer stuff **********/
445 extern GHashTable *__gst_function_pointers;
448 #ifdef GST_DEBUG_ENABLED
450 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
452 if (!__gst_function_pointers) __gst_function_pointers = g_hash_table_new(g_direct_hash,g_direct_equal);
453 if (!g_hash_table_lookup(__gst_function_pointers,ptr))
454 g_hash_table_insert(__gst_function_pointers,ptr,ptrname);
457 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
458 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
460 gchar * _gst_debug_nameof_funcptr (void *ptr);
462 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
463 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
466 void gst_debug_print_stack_trace (void);
468 #endif /* __GSTINFO_H__ */