windows: initial commit for terminal colors
[platform/upstream/gstreamer.git] / gst / gstinfo.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *                    2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
5  *
6  * gstinfo.h: debugging functions
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #ifndef __GSTINFO_H__
25 #define __GSTINFO_H__
26
27 #include <glib.h>
28 #include <glib-object.h>
29 #include <gst/gstconfig.h>
30
31 #ifndef M_PI
32 #define M_PI  3.14159265358979323846
33 #endif
34
35 G_BEGIN_DECLS
36
37 /**
38  * GstDebugLevel:
39  * @GST_LEVEL_NONE: No debugging level specified or desired. Used to deactivate
40  *  debugging output.
41  * @GST_LEVEL_ERROR: Error messages are to be used only when an error occured
42  *  that stops the application from keeping working correctly.
43  *  An examples is gst_element_error, which outputs a message with this priority.
44  *  It does not mean that the application is terminating as with g_errror.
45  * @GST_LEVEL_WARNING: Warning messages are to inform about abnormal behaviour
46  *  that could lead to problems or weird behaviour later on. An example of this
47  *  would be clocking issues ("your computer is pretty slow") or broken input
48  *  data ("Can't synchronize to stream.")
49  * @GST_LEVEL_INFO: Informational messages should be used to keep the developer
50  *  updated about what is happening.
51  *  Examples where this should be used are when a typefind function has
52  *  successfully determined the type of the stream or when an mp3 plugin detects
53  *  the format to be used. ("This file has mono sound.")
54  * @GST_LEVEL_DEBUG: Debugging messages should be used when something common
55  *  happens that is not the expected default behavior.
56  *  An example would be notifications about state changes or receiving/sending of
57  *  events.
58  * @GST_LEVEL_LOG: Log messages are messages that are very common but might be
59  *  useful to know. As a rule of thumb a pipeline that is iterating as expected
60  *  should never output anzthing else but LOG messages.
61  *  Examples for this are referencing/dereferencing of objects or cothread switches.
62  * @GST_LEVEL_COUNT: The number of defined debugging levels.
63  *
64  * The level defines the importance of a debugging message. The more important a
65  * message is, the greater the probability that the debugging system outputs it.
66  */
67 typedef enum {
68   GST_LEVEL_NONE = 0,
69   GST_LEVEL_ERROR,
70   GST_LEVEL_WARNING,
71   GST_LEVEL_INFO,
72   GST_LEVEL_DEBUG,
73   GST_LEVEL_LOG,
74   /* add more */
75   GST_LEVEL_COUNT
76 } GstDebugLevel;
77
78 /**
79  * GST_LEVEL_DEFAULT:
80  *
81  * Defines the default debugging level to be used with GStreamer. It is normally
82  * set to #GST_LEVEL_NONE so nothing get printed.
83  * As it can be configured at compile time, developer builds may chose to
84  * override that though.
85  * You can use this as an argument to gst_debug_set_default_threshold() to
86  * reset the debugging output to default behaviour.
87  */
88 #ifndef GST_LEVEL_DEFAULT
89 #define GST_LEVEL_DEFAULT GST_LEVEL_NONE
90 #endif
91
92 /* defines for format (colors etc)
93  * don't change them around, it uses terminal layout
94  * Terminal color strings:
95  * 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
96  * Text color codes:
97  * 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
98  * Background color codes:
99  * 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
100  */
101 /**
102  * GstDebugColorFlags:
103  * @GST_DEBUG_FG_BLACK: Use black as foreground color.
104  * @GST_DEBUG_FG_RED: Use red as foreground color.
105  * @GST_DEBUG_FG_GREEN: Use green as foreground color.
106  * @GST_DEBUG_FG_YELLOW: Use yellow as foreground color.
107  * @GST_DEBUG_FG_BLUE: Use blue as foreground color.
108  * @GST_DEBUG_FG_MAGENTA: Use magenta as foreground color.
109  * @GST_DEBUG_FG_CYAN: Use cyan as foreground color.
110  * @GST_DEBUG_FG_WHITE: Use white as foreground color.
111  * @GST_DEBUG_BG_BLACK: Use black as background color.
112  * @GST_DEBUG_BG_RED: Use red as background color.
113  * @GST_DEBUG_BG_GREEN: Use green as background color.
114  * @GST_DEBUG_BG_YELLOW: Use yellow as background color.
115  * @GST_DEBUG_BG_BLUE: Use blue as background color.
116  * @GST_DEBUG_BG_MAGENTA: Use magenta as background color.
117  * @GST_DEBUG_BG_CYAN: Use cyan as background color.
118  * @GST_DEBUG_BG_WHITE: Use white as background color.
119  * @GST_DEBUG_BOLD: Make the output bold.
120  * @GST_DEBUG_UNDERLINE: Underline the output.
121  *
122  * These are some terminal style flags you can use when creating your
123  * debugging categories to make them stand out in debugging output.
124  */
125 typedef enum {
126   /* colors */
127   GST_DEBUG_FG_BLACK            = 0x0000,
128   GST_DEBUG_FG_RED              = 0x0001,
129   GST_DEBUG_FG_GREEN            = 0x0002,
130   GST_DEBUG_FG_YELLOW           = 0x0003,
131   GST_DEBUG_FG_BLUE             = 0x0004,
132   GST_DEBUG_FG_MAGENTA          = 0x0005,
133   GST_DEBUG_FG_CYAN             = 0x0006,
134   GST_DEBUG_FG_WHITE            = 0x0007,
135   /* background colors */
136   GST_DEBUG_BG_BLACK            = 0x0000,
137   GST_DEBUG_BG_RED              = 0x0010,
138   GST_DEBUG_BG_GREEN            = 0x0020,
139   GST_DEBUG_BG_YELLOW           = 0x0030,
140   GST_DEBUG_BG_BLUE             = 0x0040,
141   GST_DEBUG_BG_MAGENTA          = 0x0050,
142   GST_DEBUG_BG_CYAN             = 0x0060,
143   GST_DEBUG_BG_WHITE            = 0x0070,
144   /* other formats */
145   GST_DEBUG_BOLD                = 0x0100,
146   GST_DEBUG_UNDERLINE           = 0x0200
147 } GstDebugColorFlags;
148
149 #define GST_DEBUG_FG_MASK       (0x000F)
150 #define GST_DEBUG_BG_MASK       (0x00F0)
151 #define GST_DEBUG_FORMAT_MASK   (0xFF00)
152
153 typedef struct _GstDebugCategory GstDebugCategory;
154 /**
155  * GstDebugCategory:
156  *
157  * This is the struct that describes the categories. Once initialized with
158  * #GST_DEBUG_CATEGORY_INIT, its values can't be changed anymore.
159  */
160 struct _GstDebugCategory {
161   /*< private >*/
162   gint                  threshold;
163   guint                 color;          /* see defines above */
164
165   const gchar *         name;
166   const gchar *         description;
167 };
168
169 /********** some convenience macros for debugging **********/
170
171 /**
172  * GST_STR_NULL:
173  * @str: The string to check.
174  *
175  * Macro to use when a string must not be NULL, but may be NULL. If the string
176  * is NULL, "(NULL)" is printed instead.
177  * In GStreamer printf string arguments may not be NULL, because on some
178  * platforms (ie Solaris) the libc crashes in that case. This includes debugging
179  * strings.
180  */
181 #define GST_STR_NULL(str) ((str) ? (str) : "(NULL)")
182
183 /* FIXME, not MT safe */
184 /**
185  * GST_DEBUG_PAD_NAME:
186  * @pad: The pad to debug.
187  *
188  * Evaluates to 2 strings, that describe the pad. Often used in debugging
189  * statements.
190  */
191 #define GST_DEBUG_PAD_NAME(pad) \
192   (pad != NULL) ?  \
193   ((GST_OBJECT_PARENT(pad) != NULL) ? \
194   GST_STR_NULL (GST_OBJECT_NAME (GST_OBJECT_PARENT(pad))) : \
195   "''" ) : "''", \
196   (pad != NULL) ? GST_STR_NULL (GST_OBJECT_NAME (pad)) : "''"
197
198 /**
199  * GST_FUNCTION:
200  *
201  * This macro should evaluate to the name of the current function and be should
202  * be defined when configuring your project, as it is compiler dependant. If it
203  * is not defined, some default value is used. It is used to provide debugging
204  * output with the function name of the message.
205  *
206  * Note that this is different from G_STRFUNC as we do not want the full
207  * function signature in C++ code.
208  */
209 #ifndef GST_FUNCTION
210 #if defined (__GNUC__) || (defined (_MSC_VER) && _MSC_VER >= 1300)
211 #  define GST_FUNCTION     ((const char*) (__FUNCTION__))
212 #elif defined (G_HAVE_ISO_VARARGS)
213 #  define GST_FUNCTION     ((const char*) (__func__))
214 #else
215 #  define GST_FUNCTION     ((const char*) ("???"))
216 #endif
217 #endif /* ifndef GST_FUNCTION */
218
219
220 typedef struct _GstDebugMessage GstDebugMessage;
221
222 /**
223  * GstLogFunction:
224  * @category: a #GstDebugCategory
225  * @level: a #GstDebugLevel
226  * @file: file name
227  * @function: function name
228  * @line: line number
229  * @object: a #GObject
230  * @message: the message
231  * @data: user data for the log function
232  *
233  * Function prototype for a logging function that can be registered with
234  * gst_debug_add_log_function().
235  * Use G_GNUC_NO_INSTRUMENT on that function.
236  */
237 typedef void (*GstLogFunction)  (GstDebugCategory * category,
238                                  GstDebugLevel      level,
239                                  const gchar      * file,
240                                  const gchar      * function,
241                                  gint               line,
242                                  GObject          * object,
243                                  GstDebugMessage  * message,
244                                  gpointer           data);
245
246 #ifndef GST_DISABLE_GST_DEBUG
247
248 /* FIXME 0.11: move this into private headers */
249 void            _gst_debug_init (void);
250
251
252 #ifdef GST_USING_PRINTF_EXTENSION
253
254 /* not using G_GNUC_PRINTF, since gcc will choke on GST_PTR_FORMAT being %P */
255 void                gst_debug_log            (GstDebugCategory * category,
256                                           GstDebugLevel      level,
257                                           const gchar      * file,
258                                           const gchar      * function,
259                                           gint               line,
260                                           GObject          * object,
261                                           const gchar      * format,
262                                           ...) G_GNUC_NO_INSTRUMENT;
263
264 #else /* GST_USING_PRINTF_EXTENSION */
265
266 void                gst_debug_log            (GstDebugCategory * category,
267                                           GstDebugLevel      level,
268                                           const gchar      * file,
269                                           const gchar      * function,
270                                           gint               line,
271                                           GObject          * object,
272                                           const gchar      * format,
273                                           ...) G_GNUC_PRINTF (7, 8) G_GNUC_NO_INSTRUMENT;
274
275 #endif /* GST_USING_PRINTF_EXTENSION */
276
277 void            gst_debug_log_valist     (GstDebugCategory * category,
278                                           GstDebugLevel      level,
279                                           const gchar      * file,
280                                           const gchar      * function,
281                                           gint                line,
282                                           GObject          * object,
283                                           const gchar      * format,
284                                           va_list            args) G_GNUC_NO_INSTRUMENT;
285
286 const gchar   * gst_debug_message_get    (GstDebugMessage  * message);
287
288 void            gst_debug_log_default    (GstDebugCategory * category,
289                                           GstDebugLevel      level,
290                                           const gchar      * file,
291                                           const gchar      * function,
292                                           gint               line,
293                                           GObject          * object,
294                                           GstDebugMessage  * message,
295                                           gpointer           unused) G_GNUC_NO_INSTRUMENT;
296
297 G_CONST_RETURN gchar *
298                 gst_debug_level_get_name (GstDebugLevel level);
299
300 void            gst_debug_add_log_function            (GstLogFunction func,
301                                                        gpointer       data);
302 guint           gst_debug_remove_log_function         (GstLogFunction func);
303 guint           gst_debug_remove_log_function_by_data (gpointer       data);
304
305 void            gst_debug_set_active  (gboolean active);
306 gboolean        gst_debug_is_active   (void);
307
308 void            gst_debug_set_colored (gboolean colored);
309 gboolean        gst_debug_is_colored  (void);
310
311 void            gst_debug_set_default_threshold     (GstDebugLevel level);
312 GstDebugLevel   gst_debug_get_default_threshold     (void);
313 void            gst_debug_set_threshold_for_name    (const gchar * name,
314                                                      GstDebugLevel level);
315 void            gst_debug_unset_threshold_for_name  (const gchar * name);
316
317 /**
318  * GST_DEBUG_CATEGORY:
319  * @cat: the category
320  *
321  * Defines a GstDebugCategory variable.
322  * This macro expands to nothing if debugging is disabled.
323  */
324 #define GST_DEBUG_CATEGORY(cat) GstDebugCategory *cat = NULL
325 /**
326  * GST_DEBUG_CATEGORY_EXTERN:
327  * @cat: the category
328  *
329  * Declares a GstDebugCategory variable as extern. Use in header files.
330  * This macro expands to nothing if debugging is disabled.
331  */
332 #define GST_DEBUG_CATEGORY_EXTERN(cat) extern GstDebugCategory *cat
333
334 /**
335  * GST_DEBUG_CATEGORY_STATIC:
336  * @cat: the category
337  *
338  * Defines a static GstDebugCategory variable.
339  * This macro expands to nothing if debugging is disabled.
340  */
341 #define GST_DEBUG_CATEGORY_STATIC(cat) static GstDebugCategory *cat = NULL
342 /* do not use this function, use the macros below */
343 GstDebugCategory *_gst_debug_category_new (const gchar * name,
344                                            guint         color,
345                                            const gchar * description);
346 /**
347  * GST_DEBUG_CATEGORY_INIT:
348  * @cat: the category to initialize.
349  * @name: the name of the category.
350  * @color: the colors to use for a color representation or 0 for no color.
351  * @description: optional description of the category.
352  *
353  * Initializes a new #GstDebugCategory with the given properties and set to
354  * the default threshold.
355  *
356  * <note>
357  * <para>
358  * This macro expands to nothing if debugging is disabled.
359  * </para>
360  * <para>
361  * When naming your category, please follow the following conventions to ensure
362  * that the pattern matching for categories works as expected. It is not
363  * earth-shattering if you don't follow these conventions, but it would be nice
364  * for everyone.
365  * </para>
366  * <para>
367  * If you define a category for a plugin or a feature of it, name the category
368  * like the feature. So if you wanted to write a "filesrc" element, you would
369  * name the category "filesrc". Use lowercase letters only.
370  * If you define more than one category for the same element, append an
371  * underscore and an identifier to your categories, like this: "filesrc_cache"
372  * </para>
373  * <para>
374  * If you create a library or an application using debugging categories, use a
375  * common prefix followed by an underscore for all your categories. GStreamer
376  * uses the GST prefix so GStreamer categories look like "GST_STATES". Be sure
377  * to include uppercase letters.
378  * </para>
379  * </note>
380  */
381 #define GST_DEBUG_CATEGORY_INIT(cat,name,color,description) G_STMT_START{\
382   if (cat == NULL)                                                      \
383     cat = _gst_debug_category_new (name,color,description);             \
384 }G_STMT_END
385
386 void    gst_debug_category_free         (GstDebugCategory *     category);
387 void    gst_debug_category_set_threshold (GstDebugCategory *    category,
388                                          GstDebugLevel          level);
389 void    gst_debug_category_reset_threshold(GstDebugCategory *   category);
390 GstDebugLevel
391         gst_debug_category_get_threshold (GstDebugCategory *    category);
392 G_CONST_RETURN gchar *
393         gst_debug_category_get_name     (GstDebugCategory *     category);
394 guint   gst_debug_category_get_color    (GstDebugCategory *     category);
395 G_CONST_RETURN gchar *
396         gst_debug_category_get_description (GstDebugCategory *  category);
397 GSList *
398         gst_debug_get_all_categories    (void);
399
400 gchar * gst_debug_construct_term_color  (guint colorinfo);
401 gint    gst_debug_construct_win_color (guint colorinfo);
402
403
404 /**
405  * GST_CAT_DEFAULT:
406  *
407  * Default gstreamer core debug log category. Please define your own.
408  */
409 GST_EXPORT GstDebugCategory *   GST_CAT_DEFAULT;
410 /* this symbol may not be used */
411 extern gboolean                 __gst_debug_enabled;
412
413 /* since 0.10.7, the min debug level, used for quickly discarding debug
414  * messages that fall under the threshold. */
415 GST_EXPORT GstDebugLevel            __gst_debug_min; 
416
417 /**
418  * GST_CAT_LEVEL_LOG:
419  * @cat: category to use
420  * @level: the severity of the message
421  * @object: the #GObject the message belongs to or NULL if none
422  * @...: A printf-style message to output
423  *
424  * Outputs a debugging message. This is the most general macro for outputting
425  * debugging messages. You will probably want to use one of the ones described
426  * below.
427  */
428 #ifdef G_HAVE_ISO_VARARGS
429 #define GST_CAT_LEVEL_LOG(cat,level,object,...) G_STMT_START{           \
430   if (G_UNLIKELY (level <= __gst_debug_min)) {                                          \
431     gst_debug_log ((cat), (level), __FILE__, GST_FUNCTION, __LINE__,    \
432         (GObject *) (object), __VA_ARGS__);                             \
433   }                                                                     \
434 }G_STMT_END
435 #else /* G_HAVE_GNUC_VARARGS */
436 #ifdef G_HAVE_GNUC_VARARGS
437 #define GST_CAT_LEVEL_LOG(cat,level,object,args...) G_STMT_START{       \
438   if (G_UNLIKELY (level <= __gst_debug_min)) {                                          \
439     gst_debug_log ((cat), (level), __FILE__, GST_FUNCTION, __LINE__,    \
440         (GObject *) (object), ##args );                                 \
441   }                                                                     \
442 }G_STMT_END
443 #else /* no variadic macros, use inline */
444 static inline void
445 GST_CAT_LEVEL_LOG_valist (GstDebugCategory * cat,
446     GstDebugLevel level, gpointer object, const char *format, va_list varargs)
447 {
448   if (G_UNLIKELY (level <= __gst_debug_min)) {
449     gst_debug_log_valist (cat, level, "", "", 0, (GObject *) object, format,
450         varargs);
451   }
452 }
453
454 static inline void
455 GST_CAT_LEVEL_LOG (GstDebugCategory * cat, GstDebugLevel level,
456     gpointer object, const char *format, ...)
457 {
458   va_list varargs;
459
460   va_start (varargs, format);
461   GST_CAT_LEVEL_LOG_valist (cat, level, object, format, varargs);
462   va_end (varargs);
463 }
464 #endif
465 #endif /* G_HAVE_ISO_VARARGS */
466
467 /**
468  * GST_CAT_ERROR_OBJECT:
469  * @cat: category to use
470  * @obj: the #GObject the message belongs to
471  * @...: printf-style message to output
472  *
473  * Output an error message belonging to the given object in the given category.
474  */
475 /**
476  * GST_CAT_WARNING_OBJECT:
477  * @cat: category to use
478  * @obj: the #GObject the message belongs to
479  * @...: printf-style message to output
480  *
481  * Output a warning message belonging to the given object in the given category.
482  */
483 /**
484  * GST_CAT_INFO_OBJECT:
485  * @cat: category to use
486  * @obj: the #GObject the message belongs to
487  * @...: printf-style message to output
488  *
489  * Output an informational message belonging to the given object in the given
490  * category.
491  */
492 /**
493  * GST_CAT_DEBUG_OBJECT:
494  * @cat: category to use
495  * @obj: the #GObject the message belongs to
496  * @...: printf-style message to output
497  *
498  * Output an debugging message belonging to the given object in the given category.
499  */
500 /**
501  * GST_CAT_LOG_OBJECT:
502  * @cat: category to use
503  * @obj: the #GObject the message belongs to
504  * @...: printf-style message to output
505  *
506  * Output an logging message belonging to the given object in the given category.
507  */
508
509
510 /**
511  * GST_CAT_ERROR:
512  * @cat: category to use
513  * @...: printf-style message to output
514  *
515  * Output an error message in the given category.
516  */
517 /**
518  * GST_CAT_WARNING:
519  * @cat: category to use
520  * @...: printf-style message to output
521  *
522  * Output an warning message in the given category.
523  */
524 /**
525  * GST_CAT_INFO:
526  * @cat: category to use
527  * @...: printf-style message to output
528  *
529  * Output an informational message in the given category.
530  */
531 /**
532  * GST_CAT_DEBUG:
533  * @cat: category to use
534  * @...: printf-style message to output
535  *
536  * Output an debugging message in the given category.
537  */
538 /**
539  * GST_CAT_LOG:
540  * @cat: category to use
541  * @...: printf-style message to output
542  *
543  * Output an logging message in the given category.
544  */
545
546
547 /**
548  * GST_ERROR_OBJECT:
549  * @obj: the #GObject the message belongs to
550  * @...: printf-style message to output
551  *
552  * Output an error message belonging to the given object in the default category.
553  */
554 /**
555  * GST_WARNING_OBJECT:
556  * @obj: the #GObject the message belongs to
557  * @...: printf-style message to output
558  *
559  * Output a warning message belonging to the given object in the default category.
560  */
561 /**
562  * GST_INFO_OBJECT:
563  * @obj: the #GObject the message belongs to
564  * @...: printf-style message to output
565  *
566  * Output an informational message belonging to the given object in the default
567  * category.
568  */
569 /**
570  * GST_DEBUG_OBJECT:
571  * @obj: the #GObject the message belongs to
572  * @...: printf-style message to output
573  *
574  * Output a debugging message belonging to the given object in the default
575  * category.
576  */
577 /**
578  * GST_LOG_OBJECT:
579  * @obj: the #GObject the message belongs to
580  * @...: printf-style message to output
581  *
582  * Output a logging message belonging to the given object in the default category.
583  */
584
585
586 /**
587  * GST_ERROR:
588  * @...: printf-style message to output
589  *
590  * Output an error message in the default category.
591  */
592 /**
593  * GST_WARNING:
594  * @...: printf-style message to output
595  *
596  * Output a warning message in the default category.
597  */
598 /**
599  * GST_INFO:
600  * @...: printf-style message to output
601  *
602  * Output an informational message in the default category.
603  */
604 /**
605  * GST_DEBUG:
606  * @...: printf-style message to output
607  *
608  * Output a debugging message in the default category.
609  */
610 /**
611  * GST_LOG:
612  * @...: printf-style message to output
613  *
614  * Output a logging message in the default category.
615  */
616
617 #ifdef G_HAVE_ISO_VARARGS
618
619 #define GST_CAT_ERROR_OBJECT(cat,obj,...)       GST_CAT_LEVEL_LOG (cat, GST_LEVEL_ERROR,   obj,  __VA_ARGS__)
620 #define GST_CAT_WARNING_OBJECT(cat,obj,...)     GST_CAT_LEVEL_LOG (cat, GST_LEVEL_WARNING, obj,  __VA_ARGS__)
621 #define GST_CAT_INFO_OBJECT(cat,obj,...)        GST_CAT_LEVEL_LOG (cat, GST_LEVEL_INFO,    obj,  __VA_ARGS__)
622 #define GST_CAT_DEBUG_OBJECT(cat,obj,...)       GST_CAT_LEVEL_LOG (cat, GST_LEVEL_DEBUG,   obj,  __VA_ARGS__)
623 #define GST_CAT_LOG_OBJECT(cat,obj,...)         GST_CAT_LEVEL_LOG (cat, GST_LEVEL_LOG,     obj,  __VA_ARGS__)
624
625 #define GST_CAT_ERROR(cat,...)                  GST_CAT_LEVEL_LOG (cat, GST_LEVEL_ERROR,   NULL, __VA_ARGS__)
626 #define GST_CAT_WARNING(cat,...)                GST_CAT_LEVEL_LOG (cat, GST_LEVEL_WARNING, NULL, __VA_ARGS__)
627 #define GST_CAT_INFO(cat,...)                   GST_CAT_LEVEL_LOG (cat, GST_LEVEL_INFO,    NULL, __VA_ARGS__)
628 #define GST_CAT_DEBUG(cat,...)                  GST_CAT_LEVEL_LOG (cat, GST_LEVEL_DEBUG,   NULL, __VA_ARGS__)
629 #define GST_CAT_LOG(cat,...)                    GST_CAT_LEVEL_LOG (cat, GST_LEVEL_LOG,     NULL, __VA_ARGS__)
630
631 #define GST_ERROR_OBJECT(obj,...)       GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_ERROR,   obj,  __VA_ARGS__)
632 #define GST_WARNING_OBJECT(obj,...)     GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_WARNING, obj,  __VA_ARGS__)
633 #define GST_INFO_OBJECT(obj,...)        GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_INFO,    obj,  __VA_ARGS__)
634 #define GST_DEBUG_OBJECT(obj,...)       GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_DEBUG,   obj,  __VA_ARGS__)
635 #define GST_LOG_OBJECT(obj,...)         GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_LOG,     obj,  __VA_ARGS__)
636
637 #define GST_ERROR(...)                  GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_ERROR,   NULL, __VA_ARGS__)
638 #define GST_WARNING(...)                GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_WARNING, NULL, __VA_ARGS__)
639 #define GST_INFO(...)                   GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_INFO,    NULL, __VA_ARGS__)
640 #define GST_DEBUG(...)                  GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_DEBUG,   NULL, __VA_ARGS__)
641 #define GST_LOG(...)                    GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_LOG,     NULL, __VA_ARGS__)
642
643 #else
644 #ifdef G_HAVE_GNUC_VARARGS
645
646 #define GST_CAT_ERROR_OBJECT(cat,obj,args...)   GST_CAT_LEVEL_LOG (cat, GST_LEVEL_ERROR,   obj,  ##args )
647 #define GST_CAT_WARNING_OBJECT(cat,obj,args...) GST_CAT_LEVEL_LOG (cat, GST_LEVEL_WARNING, obj,  ##args )
648 #define GST_CAT_INFO_OBJECT(cat,obj,args...)    GST_CAT_LEVEL_LOG (cat, GST_LEVEL_INFO,    obj,  ##args )
649 #define GST_CAT_DEBUG_OBJECT(cat,obj,args...)   GST_CAT_LEVEL_LOG (cat, GST_LEVEL_DEBUG,   obj,  ##args )
650 #define GST_CAT_LOG_OBJECT(cat,obj,args...)     GST_CAT_LEVEL_LOG (cat, GST_LEVEL_LOG,     obj,  ##args )
651
652 #define GST_CAT_ERROR(cat,args...)              GST_CAT_LEVEL_LOG (cat, GST_LEVEL_ERROR,   NULL, ##args )
653 #define GST_CAT_WARNING(cat,args...)            GST_CAT_LEVEL_LOG (cat, GST_LEVEL_WARNING, NULL, ##args )
654 #define GST_CAT_INFO(cat,args...)               GST_CAT_LEVEL_LOG (cat, GST_LEVEL_INFO,    NULL, ##args )
655 #define GST_CAT_DEBUG(cat,args...)              GST_CAT_LEVEL_LOG (cat, GST_LEVEL_DEBUG,   NULL, ##args )
656 #define GST_CAT_LOG(cat,args...)                GST_CAT_LEVEL_LOG (cat, GST_LEVEL_LOG,     NULL, ##args )
657
658 #define GST_ERROR_OBJECT(obj,args...)   GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_ERROR,   obj,  ##args )
659 #define GST_WARNING_OBJECT(obj,args...) GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_WARNING, obj,  ##args )
660 #define GST_INFO_OBJECT(obj,args...)    GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_INFO,    obj,  ##args )
661 #define GST_DEBUG_OBJECT(obj,args...)   GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_DEBUG,   obj,  ##args )
662 #define GST_LOG_OBJECT(obj,args...)     GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_LOG,     obj,  ##args )
663
664 #define GST_ERROR(args...)              GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_ERROR,   NULL, ##args )
665 #define GST_WARNING(args...)            GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_WARNING, NULL, ##args )
666 #define GST_INFO(args...)               GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_INFO,    NULL, ##args )
667 #define GST_DEBUG(args...)              GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_DEBUG,   NULL, ##args )
668 #define GST_LOG(args...)                GST_CAT_LEVEL_LOG (GST_CAT_DEFAULT, GST_LEVEL_LOG,     NULL, ##args )
669
670 #else
671 /* no variadic macros, use inline */
672 static inline void
673 GST_CAT_ERROR_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
674     ...)
675 {
676   va_list varargs;
677
678   va_start (varargs, format);
679   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_ERROR, obj, format, varargs);
680   va_end (varargs);
681 }
682
683 static inline void
684 GST_CAT_WARNING_OBJECT (GstDebugCategory * cat, gpointer obj,
685     const char *format, ...)
686 {
687   va_list varargs;
688
689   va_start (varargs, format);
690   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_WARNING, obj, format, varargs);
691   va_end (varargs);
692 }
693
694 static inline void
695 GST_CAT_INFO_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
696     ...)
697 {
698   va_list varargs;
699
700   va_start (varargs, format);
701   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_INFO, obj, format, varargs);
702   va_end (varargs);
703 }
704
705 static inline void
706 GST_CAT_DEBUG_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
707     ...)
708 {
709   va_list varargs;
710
711   va_start (varargs, format);
712   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_DEBUG, obj, format, varargs);
713   va_end (varargs);
714 }
715
716 static inline void
717 GST_CAT_LOG_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
718     ...)
719 {
720   va_list varargs;
721
722   va_start (varargs, format);
723   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_LOG, obj, format, varargs);
724   va_end (varargs);
725 }
726
727 static inline void
728 GST_CAT_ERROR (GstDebugCategory * cat, const char *format, ...)
729 {
730   va_list varargs;
731
732   va_start (varargs, format);
733   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_ERROR, NULL, format, varargs);
734   va_end (varargs);
735 }
736
737 static inline void
738 GST_CAT_WARNING (GstDebugCategory * cat, const char *format, ...)
739 {
740   va_list varargs;
741
742   va_start (varargs, format);
743   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_WARNING, NULL, format, varargs);
744   va_end (varargs);
745 }
746
747 static inline void
748 GST_CAT_INFO (GstDebugCategory * cat, const char *format, ...)
749 {
750   va_list varargs;
751
752   va_start (varargs, format);
753   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_INFO, NULL, format, varargs);
754   va_end (varargs);
755 }
756
757 static inline void
758 GST_CAT_DEBUG (GstDebugCategory * cat, const char *format, ...)
759 {
760   va_list varargs;
761
762   va_start (varargs, format);
763   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_DEBUG, NULL, format, varargs);
764   va_end (varargs);
765 }
766
767 static inline void
768 GST_CAT_LOG (GstDebugCategory * cat, const char *format, ...)
769 {
770   va_list varargs;
771
772   va_start (varargs, format);
773   GST_CAT_LEVEL_LOG_valist (cat, GST_LEVEL_LOG, NULL, format, varargs);
774   va_end (varargs);
775 }
776
777 static inline void
778 GST_ERROR_OBJECT (gpointer obj, const char *format, ...)
779 {
780   va_list varargs;
781
782   va_start (varargs, format);
783   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_ERROR, obj, format,
784       varargs);
785   va_end (varargs);
786 }
787
788 static inline void
789 GST_WARNING_OBJECT (gpointer obj, const char *format, ...)
790 {
791   va_list varargs;
792
793   va_start (varargs, format);
794   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_WARNING, obj, format,
795       varargs);
796   va_end (varargs);
797 }
798
799 static inline void
800 GST_INFO_OBJECT (gpointer obj, const char *format, ...)
801 {
802   va_list varargs;
803
804   va_start (varargs, format);
805   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_INFO, obj, format,
806       varargs);
807   va_end (varargs);
808 }
809
810 static inline void
811 GST_DEBUG_OBJECT (gpointer obj, const char *format, ...)
812 {
813   va_list varargs;
814
815   va_start (varargs, format);
816   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_DEBUG, obj, format,
817       varargs);
818   va_end (varargs);
819 }
820
821 static inline void
822 GST_LOG_OBJECT (gpointer obj, const char *format, ...)
823 {
824   va_list varargs;
825
826   va_start (varargs, format);
827   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_LOG, obj, format,
828       varargs);
829   va_end (varargs);
830 }
831
832 static inline void
833 GST_ERROR (const char *format, ...)
834 {
835   va_list varargs;
836
837   va_start (varargs, format);
838   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_ERROR, NULL, format,
839       varargs);
840   va_end (varargs);
841 }
842
843 static inline void
844 GST_WARNING (const char *format, ...)
845 {
846   va_list varargs;
847
848   va_start (varargs, format);
849   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_WARNING, NULL, format,
850       varargs);
851   va_end (varargs);
852 }
853
854 static inline void
855 GST_INFO (const char *format, ...)
856 {
857   va_list varargs;
858
859   va_start (varargs, format);
860   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_INFO, NULL, format,
861       varargs);
862   va_end (varargs);
863 }
864
865 static inline void
866 GST_DEBUG (const char *format, ...)
867 {
868   va_list varargs;
869
870   va_start (varargs, format);
871   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_DEBUG, NULL, format,
872       varargs);
873   va_end (varargs);
874 }
875
876 static inline void
877 GST_LOG (const char *format, ...)
878 {
879   va_list varargs;
880
881   va_start (varargs, format);
882   GST_CAT_LEVEL_LOG_valist (GST_CAT_DEFAULT, GST_LEVEL_LOG, NULL,
883       format, varargs);
884   va_end (varargs);
885 }
886 #endif
887 #endif
888
889
890 /********** function pointer stuff **********/
891
892 typedef void (* GstDebugFuncPtr)        (void);
893 void    _gst_debug_register_funcptr     (GstDebugFuncPtr        func,
894                                          const gchar *          ptrname);
895 G_CONST_RETURN gchar *
896         _gst_debug_nameof_funcptr       (GstDebugFuncPtr        func);
897
898 /**
899  * GST_DEBUG_FUNCPTR:
900  * @ptr: pointer to the function to register
901  *
902  * Register a pointer to a function with its name, so it can later be used by
903  * GST_DEBUG_FUNCPTR_NAME().
904  */
905 #define GST_DEBUG_FUNCPTR(ptr) \
906   (_gst_debug_register_funcptr((GstDebugFuncPtr)(ptr), #ptr) , ptr)
907
908 /**
909  * GST_DEBUG_FUNCPTR_NAME:
910  * @ptr: address of the function of which to look up the name
911  *
912  * Retrieves the name of the function, if it was previously registered with
913  * GST_DEBUG_FUNCPTR(). If not, it returns a description of the pointer.
914  *
915  * This macro returns a constant string which must not be modified or
916  * freed by the caller.
917  */
918 #define GST_DEBUG_FUNCPTR_NAME(ptr) \
919   _gst_debug_nameof_funcptr((GstDebugFuncPtr)ptr)
920
921
922 #else /* GST_DISABLE_GST_DEBUG */
923
924
925 #if defined(__GNUC__) && __GNUC__ >= 3
926 #  pragma GCC poison gst_debug_log
927 #  pragma GCC poison gst_debug_log_valist
928 #  pragma GCC poison _gst_debug_category_new
929 #endif
930
931 #define _gst_debug_init()                               /* NOP */
932
933 #define gst_debug_set_default_threshold(level)          /* NOP */
934 #define gst_debug_get_default_threshold()               (GST_LEVEL_NONE)
935
936 #define gst_debug_level_get_name(level)                         ("NONE")
937 #define gst_debug_message_get(message)                          ("NONE")
938 #define gst_debug_add_log_function(func,data)           /* NOP */
939 guint gst_debug_remove_log_function (GstLogFunction func);
940 guint gst_debug_remove_log_function_by_data (gpointer data);
941 #define gst_debug_set_active(active)                    /* NOP */
942 #define gst_debug_is_active()                           (FALSE)
943 #define gst_debug_set_colored(colored)                  /* NOP */
944 #define gst_debug_is_colored()                          (FALSE)
945 #define gst_debug_set_default_threshold(level)          /* NOP */
946 #define gst_debug_get_default_threshold()               (GST_LEVEL_NONE)
947 #define gst_debug_set_threshold_for_name(name,level)    /* NOP */
948 #define gst_debug_unset_threshold_for_name(name)        /* NOP */
949
950 #define GST_DEBUG_CATEGORY(var)                         /* NOP */
951 #define GST_DEBUG_CATEGORY_EXTERN(var)                  /* NOP */
952 #if !defined(G_HAVE_GNUC_VARARGS) && !defined(G_HAVE_ISO_VARARGS)
953 #define GST_DEBUG_CATEGORY_STATIC(var)                  static GstDebugCategory *var = NULL
954 #else
955 #define GST_DEBUG_CATEGORY_STATIC(var)                  /* NOP */
956 #endif
957 #define GST_DEBUG_CATEGORY_INIT(var,name,color,desc)    /* NOP */
958 #define gst_debug_category_free(category)               /* NOP */
959 #define gst_debug_category_set_threshold(category,level) /* NOP */
960 #define gst_debug_category_reset_threshold(category)    /* NOP */
961 #define gst_debug_category_get_threshold(category)      (GST_LEVEL_NONE)
962 #define gst_debug_category_get_name(cat)                ("")
963 #define gst_debug_category_get_color(cat)               (0)
964 #define gst_debug_category_get_description(cat)         ("")
965 #define gst_debug_get_all_categories()                  (NULL)
966 #define gst_debug_construct_term_color(colorinfo)       (g_strdup ("00"))
967 #define gst_debug_construct_win_color(colorinfo)        (0)
968
969 #ifdef G_HAVE_ISO_VARARGS
970
971 #define GST_CAT_LEVEL_LOG(cat,level,...)                /* NOP */
972
973 #define GST_CAT_ERROR_OBJECT(...)                       /* NOP */
974 #define GST_CAT_WARNING_OBJECT(...)                     /* NOP */
975 #define GST_CAT_INFO_OBJECT(...)                        /* NOP */
976 #define GST_CAT_DEBUG_OBJECT(...)                       /* NOP */
977 #define GST_CAT_LOG_OBJECT(...)                         /* NOP */
978
979 #define GST_CAT_ERROR(...)                              /* NOP */
980 #define GST_CAT_WARNING(...)                            /* NOP */
981 #define GST_CAT_INFO(...)                               /* NOP */
982 #define GST_CAT_DEBUG(...)                              /* NOP */
983 #define GST_CAT_LOG(...)                                /* NOP */
984
985 #define GST_ERROR_OBJECT(...)                           /* NOP */
986 #define GST_WARNING_OBJECT(...)                         /* NOP */
987 #define GST_INFO_OBJECT(...)                            /* NOP */
988 #define GST_DEBUG_OBJECT(...)                           /* NOP */
989 #define GST_LOG_OBJECT(...)                             /* NOP */
990
991 #define GST_ERROR(...)                                  /* NOP */
992 #define GST_WARNING(...)                                /* NOP */
993 #define GST_INFO(...)                                   /* NOP */
994 #define GST_DEBUG(...)                                  /* NOP */
995 #define GST_LOG(...)                                    /* NOP */
996
997 #else
998 #ifdef G_HAVE_GNUC_VARARGS
999
1000 #define GST_CAT_LEVEL_LOG(cat,level,args...)            /* NOP */
1001
1002 #define GST_CAT_ERROR_OBJECT(args...)                   /* NOP */
1003 #define GST_CAT_WARNING_OBJECT(args...)                 /* NOP */
1004 #define GST_CAT_INFO_OBJECT(args...)                    /* NOP */
1005 #define GST_CAT_DEBUG_OBJECT(args...)                   /* NOP */
1006 #define GST_CAT_LOG_OBJECT(args...)                     /* NOP */
1007
1008 #define GST_CAT_ERROR(args...)                          /* NOP */
1009 #define GST_CAT_WARNING(args...)                        /* NOP */
1010 #define GST_CAT_INFO(args...)                           /* NOP */
1011 #define GST_CAT_DEBUG(args...)                          /* NOP */
1012 #define GST_CAT_LOG(args...)                            /* NOP */
1013
1014 #define GST_ERROR_OBJECT(args...)                       /* NOP */
1015 #define GST_WARNING_OBJECT(args...)                     /* NOP */
1016 #define GST_INFO_OBJECT(args...)                        /* NOP */
1017 #define GST_DEBUG_OBJECT(args...)                       /* NOP */
1018 #define GST_LOG_OBJECT(args...)                         /* NOP */
1019
1020 #define GST_ERROR(args...)                              /* NOP */
1021 #define GST_WARNING(args...)                            /* NOP */
1022 #define GST_INFO(args...)                               /* NOP */
1023 #define GST_DEBUG(args...)                              /* NOP */
1024 #define GST_LOG(args...)                                /* NOP */
1025
1026 #else
1027 static inline void
1028 GST_CAT_LEVEL_LOG_valist (GstDebugCategory * cat,
1029     GstDebugLevel level, gpointer object, const char *format, va_list varargs)
1030 {
1031 }
1032
1033 static inline void
1034 GST_CAT_ERROR_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
1035     ...)
1036 {
1037 }
1038
1039 static inline void
1040 GST_CAT_WARNING_OBJECT (GstDebugCategory * cat, gpointer obj,
1041     const char *format, ...)
1042 {
1043 }
1044
1045 static inline void
1046 GST_CAT_INFO_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
1047     ...)
1048 {
1049 }
1050
1051 static inline void
1052 GST_CAT_DEBUG_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
1053     ...)
1054 {
1055 }
1056
1057 static inline void
1058 GST_CAT_LOG_OBJECT (GstDebugCategory * cat, gpointer obj, const char *format,
1059     ...)
1060 {
1061 }
1062
1063 static inline void
1064 GST_CAT_ERROR (GstDebugCategory * cat, const char *format, ...)
1065 {
1066 }
1067
1068 static inline void
1069 GST_CAT_WARNING (GstDebugCategory * cat, const char *format, ...)
1070 {
1071 }
1072
1073 static inline void
1074 GST_CAT_INFO (GstDebugCategory * cat, const char *format, ...)
1075 {
1076 }
1077
1078 static inline void
1079 GST_CAT_DEBUG (GstDebugCategory * cat, const char *format, ...)
1080 {
1081 }
1082
1083 static inline void
1084 GST_CAT_LOG (GstDebugCategory * cat, const char *format, ...)
1085 {
1086 }
1087
1088 static inline void
1089 GST_ERROR_OBJECT (gpointer obj, const char *format, ...)
1090 {
1091 }
1092
1093 static inline void
1094 GST_WARNING_OBJECT (gpointer obj, const char *format, ...)
1095 {
1096 }
1097
1098 static inline void
1099 GST_INFO_OBJECT (gpointer obj, const char *format, ...)
1100 {
1101 }
1102
1103 static inline void
1104 GST_DEBUG_OBJECT (gpointer obj, const char *format, ...)
1105 {
1106 }
1107
1108 static inline void
1109 GST_LOG_OBJECT (gpointer obj, const char *format, ...)
1110 {
1111 }
1112
1113 static inline void
1114 GST_ERROR (const char *format, ...)
1115 {
1116 }
1117
1118 static inline void
1119 GST_WARNING (const char *format, ...)
1120 {
1121 }
1122
1123 static inline void
1124 GST_INFO (const char *format, ...)
1125 {
1126 }
1127
1128 static inline void
1129 GST_DEBUG (const char *format, ...)
1130 {
1131 }
1132
1133 static inline void
1134 GST_LOG (const char *format, ...)
1135 {
1136 }
1137 #endif
1138 #endif
1139
1140 #define GST_DEBUG_FUNCPTR(ptr) (ptr)
1141 #define GST_DEBUG_FUNCPTR_NAME(ptr) (g_strdup_printf ("%p", ptr))
1142
1143 #endif /* GST_DISABLE_GST_DEBUG */
1144
1145
1146 void gst_debug_print_stack_trace (void);
1147
1148 G_END_DECLS
1149
1150 #endif /* __GSTINFO_H__ */