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 #include "cothreads.h"
37 /***** are we in the core or not? *****/
38 #ifdef __GST_PRIVATE_H__
39 #define _GST_DEBUG_INCORE TRUE
41 #define _GST_DEBUG_INCORE FALSE
45 /* colorization stuff */
46 #ifdef GST_DEBUG_COLOR
47 #ifdef __GST_PRIVATE_H__ /* FIXME this should be some libgst.la -specific thing */
48 #define GST_DEBUG_CHAR_MODE "00"
50 #define GST_DEBUG_CHAR_MODE "01"
54 gint _gst_debug_stringhash_color(gchar *file);
58 /**********************************************************************
60 **********************************************************************/
62 const gchar * gst_get_category_name (gint category);
65 GST_CAT_GST_INIT = 0, /* Library initialization */
66 GST_CAT_COTHREADS, /* Cothread creation, etc. */
67 GST_CAT_COTHREAD_SWITCH, /* Cothread switching */
68 GST_CAT_AUTOPLUG, /* Successful autoplug results */
69 GST_CAT_AUTOPLUG_ATTEMPT, /* Attempted autoplug operations */
70 GST_CAT_PARENTAGE, /* GstBin parentage issues */
71 GST_CAT_STATES, /* State changes and such */
72 GST_CAT_PLANNING, /* Plan generation */
73 GST_CAT_SCHEDULING, /* Schedule construction */
74 GST_CAT_DATAFLOW, /* Events during actual data movement */
75 GST_CAT_BUFFER, /* Buffer creation/destruction */
76 GST_CAT_CAPS, /* Capabilities matching */
77 GST_CAT_CLOCK, /* Clocking */
78 GST_CAT_ELEMENT_PADS, /* Element pad management */
79 GST_CAT_ELEMENTFACTORY, /* Elementfactory stuff */
80 GST_CAT_PADS, /* Pad creation/connection */
81 GST_CAT_PIPELINE, /* Pipeline stuff */
82 GST_CAT_PLUGIN_LOADING, /* Plugin loading */
83 GST_CAT_PLUGIN_ERRORS, /* Errors during plugin loading */
84 GST_CAT_PLUGIN_INFO, /* Plugin state information */
85 GST_CAT_PROPERTIES, /* Properties */
86 GST_CAT_THREAD, /* Thread creation/management */
87 GST_CAT_TYPES, /* Typing */
88 GST_CAT_XML, /* XML load/save of everything */
89 GST_CAT_NEGOTIATION, /* Caps Negotiation stuff */
90 GST_CAT_REFCOUNTING, /* Ref Counting stuff */
91 GST_CAT_EVENT, /* Event system */
92 GST_CAT_PARAMS, /* Dynamic parameters */
94 GST_CAT_CALL_TRACE = 30, /* Call tracing */
96 GST_CAT_MAX_CATEGORY = 31
99 extern const gchar *_gst_category_colors[32];
103 /**********************************************************************
105 **********************************************************************/
107 /* for include files that make too much noise normally */
108 #ifdef GST_DEBUG_FORCE_DISABLE
109 #undef GST_DEBUG_ENABLED
111 /* for applications that really really want all the noise */
112 #ifdef GST_DEBUG_FORCE_ENABLE
113 #define GST_DEBUG_ENABLED
116 /*#ifdef GST_DEBUG_ENABLED */
117 #define GST_DEBUG_ENABLE_CATEGORIES 0xffffffff
119 /*#define GST_DEBUG_ENABLE_CATEGORIES 0x00000000 */
123 typedef void (*GstDebugHandler) (gint category,gboolean core,
124 const gchar *file,const gchar *function,
125 gint line,const gchar *debug_string,
126 void *element,gchar *string);
128 void gst_default_debug_handler (gint category,gboolean incore,
129 const gchar *file, const gchar *function,
130 gint line,const gchar *debug_string,
131 void *element,gchar *string);
133 extern guint32 _gst_debug_categories;
134 extern GstDebugHandler _gst_debug_handler;
136 /* fallback, this should probably be a 'weak' symbol or something */
137 G_GNUC_UNUSED static gchar *_debug_string = NULL;
142 #ifdef GST_DEBUG_ENABLED
143 #define GST_DEBUG(cat,format,args...) G_STMT_START{ \
144 if ((1<<cat) & _gst_debug_categories) \
145 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
146 NULL,g_strdup_printf( format , ## args )); \
149 #define GST_DEBUG_ELEMENT(cat,element,format,args...) G_STMT_START{ \
150 if ((1<<cat) & _gst_debug_categories) \
151 _gst_debug_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
152 element,g_strdup_printf( format , ## args )); \
156 #define GST_DEBUG(cat,format,args...)
157 #define GST_DEBUG_ELEMENT(cat,element,format,args...)
163 /********** some convenience macros for debugging **********/
164 #define GST_DEBUG_PAD_NAME(pad) \
165 (GST_OBJECT_PARENT(pad) != NULL) ? \
166 GST_OBJECT_NAME (GST_OBJECT_PARENT(pad)) : \
167 "''", GST_OBJECT_NAME (pad)
169 #ifdef GST_DEBUG_COLOR
170 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": \033[01;37mentering\033[00m\n" , ##args )
171 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": \033[01;37mleaving\033[00m\n" , ##args )
173 #define GST_DEBUG_ENTER(format, args...) GST_DEBUG( 31 , format ": entering\n" , ##args )
174 #define GST_DEBUG_LEAVE(format, args...) GST_DEBUG( 31 , format ": leaving\n" , ##args )
178 /***** Colorized debug for thread ids *****/
179 #ifdef GST_DEBUG_COLOR
180 #define GST_DEBUG_THREAD_FORMAT "\033[00;%dm%d\033[00m"
181 #define GST_DEBUG_THREAD_ARGS(id) ( ((id) < 0) ? 37 : ((id) % 6 + 31) ), (id)
183 #define GST_DEBUG_THREAD_FORMAT "%d"
184 #define GST_DEBUG_THREAD_ARGS(id) (id)
189 /**********************************************************************
190 * The following is a DEBUG_ENTER implementation that will wrap the
191 * function it sits at the head of. It removes the need for a
192 * DEBUG_LEAVE call. However, it segfaults whenever it gets anywhere
193 * near cothreads. We will not use it for the moment.
195 typedef void (*_debug_function_f)();
196 G_GNUC_UNUSED static gchar *_debug_string_pointer = NULL;
197 G_GNUC_UNUSED static GModule *_debug_self_module = NULL;
199 #define _DEBUG_ENTER_BUILTIN(format,args...) \
200 static int _debug_in_wrapper = 0; \
201 gchar *_debug_string = ({ \
202 if (!_debug_in_wrapper) { \
203 void *_return_value; \
204 gchar *_debug_string; \
205 _debug_function_f function; \
206 void *_function_args = __builtin_apply_args(); \
207 _debug_in_wrapper = 1; \
208 _debug_string = g_strdup_printf(GST_DEBUG_PREFIX("")); \
209 _debug_string_pointer = _debug_string; \
210 fprintf(stderr,"%s: entered " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
211 if (_debug_self_module == NULL) _debug_self_module = g_module_open(NULL,0); \
212 g_module_symbol(_debug_self_module,__FUNCTION__,(gpointer *)&function); \
213 _return_value = __builtin_apply(function,_function_args,64); \
214 fprintf(stderr,"%s: left " __PRETTY_FUNCTION__ format "\n" , _debug_string , ## args ); \
215 g_free(_debug_string); \
216 __builtin_return(_return_value); \
218 _debug_in_wrapper = 0; \
220 _debug_string_pointer; \
223 * WARNING: there's a gcc CPP bug lurking in here. The extra space before the ##args *
224 * somehow make the preprocessor leave the _debug_string. If it's removed, the *
225 * _debug_string somehow gets stripped along with the ##args, and that's all she wrote. *
226 #define _DEBUG_BUILTIN(format,args...) \
227 if (_debug_string != (void *)-1) { \
229 fprintf(stderr,"%s: " format , _debug_string , ## args); \
231 fprintf(stderr,GST_DEBUG_PREFIX(": " format , ## args)); \
238 /**********************************************************************
240 **********************************************************************/
242 typedef void (*GstInfoHandler) (gint category,gboolean incore,
243 const gchar *file,const gchar *function,
244 gint line,const gchar *debug_string,
245 void *element,gchar *string);
247 void gst_default_info_handler (gint category,gboolean incore,
248 const gchar *file,const gchar *function,
249 gint line,const gchar *debug_string,
250 void *element,gchar *string);
252 extern GstInfoHandler _gst_info_handler;
253 extern guint32 _gst_info_categories;
255 /* for include files that make too much noise normally */
256 #ifdef GST_INFO_FORCE_DISABLE
257 #undef GST_INFO_ENABLED
259 /* for applications that really really want all the noise */
260 #ifdef GST_INFO_FORCE_ENABLE
261 #define GST_INFO_ENABLED
264 #ifdef GST_INFO_ENABLED
265 #define GST_INFO(cat,format,args...) G_STMT_START{ \
266 if ((1<<cat) & _gst_info_categories) \
267 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
268 NULL,g_strdup_printf( format , ## args )); \
271 #define GST_INFO_ELEMENT(cat,element,format,args...) G_STMT_START{ \
272 if ((1<<cat) & _gst_info_categories) \
273 _gst_info_handler(cat,_GST_DEBUG_INCORE,__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
274 element,g_strdup_printf( format , ## args )); \
278 #define GST_INFO(cat,format,args...)
279 #define GST_INFO_ELEMENT(cat,element,format,args...)
283 void gst_info_set_categories (guint32 categories);
284 guint32 gst_info_get_categories (void);
285 void gst_info_enable_category (gint category);
286 void gst_info_disable_category (gint category);
288 void gst_debug_set_categories (guint32 categories);
289 guint32 gst_debug_get_categories (void);
290 void gst_debug_enable_category (gint category);
291 void gst_debug_disable_category (gint category);
296 /**********************************************************************
298 **********************************************************************/
300 typedef void (*GstErrorHandler) (gchar *file,gchar *function,
301 gint line,gchar *debug_string,
302 void *element,void *object,gchar *string);
304 void gst_default_error_handler (gchar *file,gchar *function,
305 gint line,gchar *debug_string,
306 void *element,void *object,gchar *string);
308 extern GstErrorHandler _gst_error_handler;
310 #define GST_ERROR(element,format,args...) \
311 _gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
312 element,NULL,g_strdup_printf( format , ## args ))
314 #define GST_ERROR_OBJECT(element,object,format,args...) \
315 _gst_error_handler(__FILE__,__PRETTY_FUNCTION__,__LINE__,_debug_string, \
316 element,object,g_strdup_printf( format , ## args ))
321 /********** function pointer stuff **********/
322 extern GHashTable *__gst_function_pointers;
325 #if GST_DEBUG_ENABLED
326 #define GST_DEBUG_FUNCPTR(ptr) _gst_debug_register_funcptr((void *)(ptr), #ptr)
327 #define GST_DEBUG_FUNCPTR_NAME(ptr) _gst_debug_nameof_funcptr((void *)ptr)
329 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
330 #define GST_DEBUG_FUNCPTR_NAME(ptr) ""
334 _gst_debug_register_funcptr (void *ptr, gchar *ptrname)
336 if (!__gst_function_pointers) __gst_function_pointers = g_hash_table_new(g_direct_hash,g_direct_equal);
337 if (!g_hash_table_lookup(__gst_function_pointers,ptr))
338 g_hash_table_insert(__gst_function_pointers,ptr,ptrname);
342 gchar *_gst_debug_nameof_funcptr (void *ptr);
344 void gst_debug_print_stack_trace (void);
348 #endif /* __GSTINFO_H__ */