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];
98 extern GStaticPrivate _gst_debug_cothread_index;
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;
139 #ifdef G_HAVE_ISO_VARARGS
141 #ifdef GST_DEBUG_ENABLED
142 #define GST_DEBUG(cat, ...) G_STMT_START{ \
143 if ((1<<cat) & _gst_debug_categories) \
144 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
145 NULL,g_strdup_printf( __VA_ARGS__ )); \
148 #define GST_DEBUG_ELEMENT(cat, element, ...) G_STMT_START{ \
149 if ((1<<cat) & _gst_debug_categories) \
150 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
151 element,g_strdup_printf( __VA_ARGS__ )); \
155 #define GST_DEBUG(cat, ...)
156 #define GST_DEBUG_ELEMENT(cat,element, ...)
159 #elif defined(G_HAVE_GNUC_VARARGS)
161 #ifdef GST_DEBUG_ENABLED
162 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
163 if ((1<<cat) & _gst_debug_categories) \
164 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
165 NULL,g_strdup_printf( format , ## args )); \
168 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
169 if ((1<<cat) & _gst_debug_categories) \
170 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
171 element,g_strdup_printf( format , ## args )); \
175 #define GST_DEBUG(cat,format,args...)
176 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
184 /********** some convenience macros for debugging **********/
185 #define GST_DEBUG_PAD_NAME(pad) \
186 (GST_OBJECT_PARENT(pad) != NULL) ? \
187 GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
188 "''", GST_OBJECT_NAME (pad)
190 #ifdef G_HAVE_ISO_VARARGS
192 #ifdef GST_DEBUG_COLOR
193 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "\033[00;37mentering\033[00m :" __VA_ARGS__ )
194 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "\033[00;37mleaving\033[00m :" __VA_ARGS__ )
196 #define GST_DEBUG_ENTER(...) GST_DEBUG( 31 , "entering :" __VA_ARGS__ )
197 #define GST_DEBUG_LEAVE(...) GST_DEBUG( 31 , "leaving :" __VA_ARGS__ )
200 #elif defined(G_HAVE_GNUC_VARARGS)
202 #ifdef GST_DEBUG_COLOR
203 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[00;37mentering\033[00m" , ##args )
204 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[00;37mleaving\033[00m" , ##args )
206 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering" , ##args )
207 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving" , ##args )
213 /***** Colorized debug for thread ids *****/
214 #ifdef GST_DEBUG_COLOR
215 #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
216 #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
218 #define GST_DEBUG_THREAD_FORMAT "%d"
219 #define GST_DEBUG_THREAD_ARGS(id) (id)
224 /**********************************************************************
225 * The following is a DEBUG_ENTER implementation that will wrap the
226 * function it sits at the head of. It removes the need for a
227 * DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
228 * near cothreads. We will not use it for the moment.
230 typedef void (*_debug_function_f)();
231 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
232 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
234 #ifdef G_HAVE_ISO_VARARGS
236 #define _DEBUG_ENTER_BUILTIN(...) \
237 static int _debug_in_wrapper = 0; \
238 gchar *_debug_string = ({ \
239 if (!_debug_in_wrapper) { \
240 void *_return_value; \
241 gchar *_debug_string; \
242 _debug_function_f function; \
243 void *_function_args = __builtin_apply_args(); \
244 _debug_in_wrapper = 1; \
245 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
246 _debug_string_pointer = _debug_string; \
247 fprintf(stderr,"%s: entered " FUNCTION, _debug_string); \
248 fprintf(stderr, __VA_ARGS__ ); \
249 fprintf(stderr,"\n"); \
250 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
251 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
252 _return_value = __builtin_apply(function,_function_args,64); \
253 fprintf(stderr,"%s: left " FUNCTION, _debug_string); \
254 fprintf(stderr, __VA_ARGS__); \
255 fprintf(stderr,"\n"); \
256 g_free(_debug_string); \
257 __builtin_return(_return_value); \
259 _debug_in_wrapper = 0; \
261 _debug_string_pointer; \
264 #elif defined(G_HAVE_GNUC_VARARGS)
266 #define _DEBUG_ENTER_BUILTIN(format,args...) \
267 static int _debug_in_wrapper = 0; \
268 gchar *_debug_string = ({ \
269 if (!_debug_in_wrapper) { \
270 void *_return_value; \
271 gchar *_debug_string; \
272 _debug_function_f function; \
273 void *_function_args = __builtin_apply_args(); \
274 _debug_in_wrapper = 1; \
275 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
276 _debug_string_pointer = _debug_string; \
277 fprintf(stderr,"%s: entered " FUNCTION format "\n" , _debug_string , ## args ); \
278 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
279 g_module_symbol(_debug_self_module,FUNCTION,(gpointer *)&function); \
280 _return_value = __builtin_apply(function,_function_args,64); \
281 fprintf(stderr,"%s: left " FUNCTION format "\n" , _debug_string , ## args ); \
282 g_free(_debug_string); \
283 __builtin_return(_return_value); \
285 _debug_in_wrapper = 0; \
287 _debug_string_pointer; \
292 * WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
293 * somehow make the preprocessor leave the _debug_string. If it's removed, the *
294 * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
296 #ifdef G_HAVE_ISO_VARARGS
298 #define _DEBUG_BUILTIN(...) \
299 if (_debug_string != (void *)-1) { \
300 if (_debug_string) { \
301 fprintf(stderr, "%s: " _debug_string); \
302 fprintf(stderr, __VA_ARGS__); \
304 fprintf(stderr,GST_DEBUG_PREFIX(": " __VA_ARGS__)); \
308 #elif defined(G_HAVE_GNUC_VARARGS)
310 #define _DEBUG_BUILTIN(format,args...) \
311 if (_debug_string != (void *)-1) { \
313 fprintf(stderr,"%s: " format , _debug_string , ## args); \
315 fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
324 /**********************************************************************
326 **********************************************************************/
328 typedef void (*GstInfoHandler) (gint category,gboolean incore,
329 const gchar *file,const gchar *function,
330 gint line,const gchar *debug_string,
331 void *element,gchar *string);
333 void gst_default_info_handler (gint category,gboolean incore,
334 const gchar *file,const gchar *function,
335 gint line,const gchar *debug_string,
336 void *element,gchar *string);
338 extern GstInfoHandler _gst_info_handler;
339 extern guint32 _gst_info_categories;
341 /* for include files that make too much noise normally */
342 #ifdef GST_INFO_FORCE_DISABLE
343 #undef GST_INFO_ENABLED
345 /* for applications that really really want all the noise */
346 #ifdef GST_INFO_FORCE_ENABLE
347 #define GST_INFO_ENABLED
350 #ifdef G_HAVE_ISO_VARARGS
352 #ifdef GST_INFO_ENABLED
353 #define GST_INFO(cat,...) G_STMT_START{ \
354 if ((1<<cat) & _gst_info_categories) \
355 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
356 NULL,g_strdup_printf( __VA_ARGS__ )); \
359 #define GST_INFO_ELEMENT(cat,element,...) G_STMT_START{ \
360 if ((1<<cat) & _gst_info_categories) \
361 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
362 element,g_strdup_printf( __VA_ARGS__ )); \
366 #define GST_INFO(cat,...)
367 #define GST_INFO_ELEMENT(cat,element,...)
370 #elif defined(G_HAVE_GNUC_VARARGS)
372 #ifdef GST_INFO_ENABLED
373 #define GST_INFO(cat,format,args...) G_STMT_START{ \
374 if ((1<<cat) & _gst_info_categories) \
375 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
376 NULL,g_strdup_printf( format , ## args )); \
379 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
380 if ((1<<cat) & _gst_info_categories) \
381 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
382 element,g_strdup_printf( format , ## args )); \
386 #define GST_INFO(cat,format,args...)
387 #define GST_INFO_ELEMENT(cat,element,format,args...)
393 void gst_info_set_categories (guint32 categories);
394 guint32 gst_info_get_categories (void);
395 void gst_info_enable_category (gint category);
396 void gst_info_disable_category (gint category);
398 void gst_debug_set_categories (guint32 categories);
399 guint32 gst_debug_get_categories (void);
400 void gst_debug_enable_category (gint category);
401 void gst_debug_disable_category (gint category);
406 /**********************************************************************
408 **********************************************************************/
410 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
411 gint line,gchar *debug_string,
412 void *element,void *object,gchar *string);
414 void gst_default_error_handler (gchar *file,gchar *function,
415 gint line,gchar *debug_string,
416 void *element,void *object,gchar *string);
418 extern GstErrorHandler _gst_error_handler;
420 #ifdef G_HAVE_ISO_VARARGS
422 #define GST_ERROR(element,...) \
423 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
424 element,NULL,g_strdup_printf( __VA_ARGS__ ))
426 #define GST_ERROR_OBJECT(element,object,...) \
427 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
428 element,object,g_strdup_printf( __VA_ARGS__ ))
430 #elif defined(G_HAVE_GNUC_VARARGS)
432 #define GST_ERROR(element,format,args...) \
433 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
434 element,NULL,g_strdup_printf( format , ## args ))
436 #define GST_ERROR_OBJECT(element,object,format,args...) \
437 _gst_error_handler(__FILE__,G_GNUC_PRETTY_FUNCTION,__LINE__,_debug_string, \
438 element,object,g_strdup_printf( format , ## args ))
445 /********** function pointer stuff **********/
446 extern GHashTable *__gst_function_pointers;
449 #ifdef GST_DEBUG_ENABLED
451 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
453 if (!__gst_function_pointers) __gst_function_pointers = g_hash_table_new(g_direct_hash,g_direct_equal);
454 if (!g_hash_table_lookup(__gst_function_pointers,ptr))
455 g_hash_table_insert(__gst_function_pointers,ptr,ptrname);
458 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
459 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
461 gchar * _gst_debug_nameof_funcptr (void *ptr);
463 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
464 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
467 void gst_debug_print_stack_trace (void);
469 #endif /* __GSTINFO_H__ */