gstreamer_core/gst/gstinfo.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
     1 /* GStreamer
     1 /* GStreamer
     2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
     2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
     3  *                    2000 Wim Taymans <wtay@chello.be>
     3  *                    2000 Wim Taymans <wtay@chello.be>
     4  *                    2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
     4  *                    2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
     5  * Copyright (C) 2008-2009 Tim-Philipp Müller <tim centricular net>
       
     6  *
     5  *
     7  * gstinfo.c: debugging functions
     6  * gstinfo.c: debugging functions
     8  *
     7  *
     9  * This library is free software; you can redistribute it and/or
     8  * This library is free software; you can redistribute it and/or
    10  * modify it under the terms of the GNU Library General Public
     9  * modify it under the terms of the GNU Library General Public
    84  *
    83  *
    85  * Please note that there are naming conventions for the names of debugging
    84  * Please note that there are naming conventions for the names of debugging
    86  * categories. These are explained at GST_DEBUG_CATEGORY_INIT().
    85  * categories. These are explained at GST_DEBUG_CATEGORY_INIT().
    87  */
    86  */
    88 
    87 
    89 #define GST_INFO_C
       
    90 
       
    91 #include "gst_private.h"
    88 #include "gst_private.h"
    92 #include "gstinfo.h"
    89 #include "gstinfo.h"
    93 
    90 
    94 #ifndef GST_DISABLE_GST_DEBUG
    91 #ifndef GST_DISABLE_GST_DEBUG
    95 
    92 
   105 #endif
   102 #endif
   106 #ifdef HAVE_PROCESS_H
   103 #ifdef HAVE_PROCESS_H
   107 #  include <process.h>          /* getpid on win32 */
   104 #  include <process.h>          /* getpid on win32 */
   108 #endif
   105 #endif
   109 #include <string.h>             /* G_VA_COPY */
   106 #include <string.h>             /* G_VA_COPY */
   110 #ifdef G_OS_WIN32
       
   111 #  define WIN32_LEAN_AND_MEAN   /* prevents from including too many things */
       
   112 #  include <windows.h>          /* GetStdHandle, windows console */
       
   113 #endif
       
   114 
   107 
   115 #include "gst_private.h"
   108 #include "gst_private.h"
   116 #include "gstutils.h"
   109 #include "gstutils.h"
   117 #include "gstquark.h"
       
   118 #include "gstsegment.h"
   110 #include "gstsegment.h"
   119 #ifdef HAVE_VALGRIND_H
   111 #ifdef HAVE_VALGRIND
   120 #  include <valgrind/valgrind.h>
   112 #  include <valgrind/valgrind.h>
   121 #endif
   113 #endif
   122 #include <glib/gprintf.h>       /* g_sprintf */
   114 #include <glib/gprintf.h>       /* g_sprintf */
   123 #endif /* !GST_DISABLE_GST_DEBUG */
   115 
   124 #ifdef __SYMBIAN32__
   116 #ifdef __SYMBIAN32__
   125 #include <glib_global.h>
   117 #include <glib_global.h>
   126 
   118 #endif
   127 #endif
       
   128 /* we want these symbols exported even if debug is disabled, to maintain
       
   129  * ABI compatibility. Unless GST_REMOVE_DISABLED is defined. */
       
   130 #if !defined(GST_DISABLE_GST_DEBUG) || !defined(GST_REMOVE_DISABLED)
       
   131 
       
   132 /* disabled by default, as soon as some threshold is set > NONE,
       
   133  * it becomes enabled. */
       
   134 gboolean __gst_debug_enabled = FALSE;
       
   135 EXPORT_C GstDebugLevel __gst_debug_min ;// = GST_LEVEL_NONE;
       
   136 
       
   137 EXPORT_C GstDebugCategory *GST_CAT_DEFAULT ;// = NULL;
       
   138 
       
   139 EXPORT_C GstDebugCategory *GST_CAT_GST_INIT ;// = NULL;
       
   140 EXPORT_C GstDebugCategory *GST_CAT_AUTOPLUG ;// = NULL;
       
   141 EXPORT_C GstDebugCategory *GST_CAT_AUTOPLUG_ATTEMPT ;// = NULL;
       
   142 EXPORT_C GstDebugCategory *GST_CAT_PARENTAGE ;// = NULL;
       
   143 EXPORT_C GstDebugCategory *GST_CAT_STATES ;// = NULL;
       
   144 EXPORT_C GstDebugCategory *GST_CAT_SCHEDULING ;// = NULL;
       
   145 
       
   146 EXPORT_C GstDebugCategory *GST_CAT_BUFFER ;// = NULL;
       
   147 EXPORT_C GstDebugCategory *GST_CAT_BUFFER_LIST ;// = NULL;
       
   148 EXPORT_C GstDebugCategory *GST_CAT_BUS ;// = NULL;
       
   149 EXPORT_C GstDebugCategory *GST_CAT_CAPS ;// = NULL;
       
   150 EXPORT_C GstDebugCategory *GST_CAT_CLOCK ;// = NULL;
       
   151 EXPORT_C GstDebugCategory *GST_CAT_ELEMENT_PADS ;// = NULL;
       
   152 EXPORT_C GstDebugCategory *GST_CAT_PADS ;// = NULL;
       
   153 EXPORT_C GstDebugCategory *GST_CAT_PERFORMANCE ;// = NULL;
       
   154 EXPORT_C GstDebugCategory *GST_CAT_PIPELINE ;// = NULL;
       
   155 EXPORT_C GstDebugCategory *GST_CAT_PLUGIN_LOADING ;// = NULL;
       
   156 EXPORT_C GstDebugCategory *GST_CAT_PLUGIN_INFO ;// = NULL;
       
   157 EXPORT_C GstDebugCategory *GST_CAT_PROPERTIES ;// = NULL;
       
   158 EXPORT_C GstDebugCategory *GST_CAT_TYPES ;// = NULL;
       
   159 EXPORT_C GstDebugCategory *GST_CAT_XML ;// = NULL;
       
   160 EXPORT_C GstDebugCategory *GST_CAT_NEGOTIATION ;// = NULL;
       
   161 EXPORT_C GstDebugCategory *GST_CAT_REFCOUNTING ;// = NULL;
       
   162 EXPORT_C GstDebugCategory *GST_CAT_ERROR_SYSTEM ;// = NULL;
       
   163 EXPORT_C GstDebugCategory *GST_CAT_EVENT ;// = NULL;
       
   164 EXPORT_C GstDebugCategory *GST_CAT_MESSAGE ;// = NULL;
       
   165 EXPORT_C GstDebugCategory *GST_CAT_PARAMS ;// = NULL;
       
   166 EXPORT_C GstDebugCategory *GST_CAT_CALL_TRACE ;// = NULL;
       
   167 EXPORT_C GstDebugCategory *GST_CAT_SIGNAL ;// = NULL;
       
   168 EXPORT_C GstDebugCategory *GST_CAT_PROBE ;// = NULL;
       
   169 EXPORT_C GstDebugCategory *GST_CAT_REGISTRY ;// = NULL;
       
   170 EXPORT_C GstDebugCategory *GST_CAT_QOS ;// = NULL;
       
   171 
       
   172 #endif /* !defined(GST_DISABLE_GST_DEBUG) || !defined(GST_REMOVE_DISABLED) */
       
   173 
       
   174 #ifndef GST_DISABLE_GST_DEBUG
       
   175 
   119 
   176 /* underscore is to prevent conflict with GST_CAT_DEBUG define */
   120 /* underscore is to prevent conflict with GST_CAT_DEBUG define */
   177 GST_DEBUG_CATEGORY_STATIC (_GST_CAT_DEBUG);
   121 GST_DEBUG_CATEGORY_STATIC (_GST_CAT_DEBUG);
   178 
   122 
   179 /* time of initialization, so we get useful debugging output times
   123 /* time of initialization, so we get useful debugging output times
   217 #ifdef HAVE_PRINTF_EXTENSION
   161 #ifdef HAVE_PRINTF_EXTENSION
   218 static int _gst_info_printf_extension_ptr (FILE * stream,
   162 static int _gst_info_printf_extension_ptr (FILE * stream,
   219     const struct printf_info *info, const void *const *args);
   163     const struct printf_info *info, const void *const *args);
   220 static int _gst_info_printf_extension_segment (FILE * stream,
   164 static int _gst_info_printf_extension_segment (FILE * stream,
   221     const struct printf_info *info, const void *const *args);
   165     const struct printf_info *info, const void *const *args);
   222 #if HAVE_REGISTER_PRINTF_SPECIFIER
       
   223 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
       
   224     size_t n, int *argtypes, int *size);
       
   225 #else
       
   226 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
   166 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
   227     size_t n, int *argtypes);
   167     size_t n, int *argtypes);
   228 #endif
       
   229 #endif
   168 #endif
   230 
   169 
   231 struct _GstDebugMessage
   170 struct _GstDebugMessage
   232 {
   171 {
   233   gchar *message;
   172   gchar *message;
   257 }
   196 }
   258 LogFuncEntry;
   197 LogFuncEntry;
   259 static GStaticMutex __log_func_mutex = G_STATIC_MUTEX_INIT;
   198 static GStaticMutex __log_func_mutex = G_STATIC_MUTEX_INIT;
   260 static GSList *__log_functions = NULL;
   199 static GSList *__log_functions = NULL;
   261 
   200 
   262 #define PRETTY_TAGS_DEFAULT  TRUE
       
   263 static gboolean pretty_tags = PRETTY_TAGS_DEFAULT;
       
   264 
       
   265 static gint __default_level;
   201 static gint __default_level;
   266 static gint __use_color;
   202 static gint __use_color;
       
   203 
       
   204 /* disabled by default, as soon as some threshold is set > NONE,
       
   205  * it becomes enabled. */
       
   206 gboolean __gst_debug_enabled = FALSE;
       
   207 GstDebugLevel __gst_debug_min = GST_LEVEL_NONE;
       
   208 
       
   209 GstDebugCategory *GST_CAT_DEFAULT = NULL;
       
   210 
       
   211 GstDebugCategory *GST_CAT_GST_INIT = NULL;
       
   212 GstDebugCategory *GST_CAT_AUTOPLUG = NULL;
       
   213 GstDebugCategory *GST_CAT_AUTOPLUG_ATTEMPT = NULL;
       
   214 GstDebugCategory *GST_CAT_PARENTAGE = NULL;
       
   215 GstDebugCategory *GST_CAT_STATES = NULL;
       
   216 GstDebugCategory *GST_CAT_SCHEDULING = NULL;
       
   217 
       
   218 GstDebugCategory *GST_CAT_BUFFER = NULL;
       
   219 GstDebugCategory *GST_CAT_BUS = NULL;
       
   220 GstDebugCategory *GST_CAT_CAPS = NULL;
       
   221 GstDebugCategory *GST_CAT_CLOCK = NULL;
       
   222 GstDebugCategory *GST_CAT_ELEMENT_PADS = NULL;
       
   223 GstDebugCategory *GST_CAT_PADS = NULL;
       
   224 GstDebugCategory *GST_CAT_PIPELINE = NULL;
       
   225 GstDebugCategory *GST_CAT_PLUGIN_LOADING = NULL;
       
   226 GstDebugCategory *GST_CAT_PLUGIN_INFO = NULL;
       
   227 GstDebugCategory *GST_CAT_PROPERTIES = NULL;
       
   228 GstDebugCategory *GST_CAT_TYPES = NULL;
       
   229 GstDebugCategory *GST_CAT_XML = NULL;
       
   230 GstDebugCategory *GST_CAT_NEGOTIATION = NULL;
       
   231 GstDebugCategory *GST_CAT_REFCOUNTING = NULL;
       
   232 GstDebugCategory *GST_CAT_ERROR_SYSTEM = NULL;
       
   233 GstDebugCategory *GST_CAT_EVENT = NULL;
       
   234 GstDebugCategory *GST_CAT_MESSAGE = NULL;
       
   235 GstDebugCategory *GST_CAT_PARAMS = NULL;
       
   236 GstDebugCategory *GST_CAT_CALL_TRACE = NULL;
       
   237 GstDebugCategory *GST_CAT_SIGNAL = NULL;
       
   238 GstDebugCategory *GST_CAT_PROBE = NULL;
       
   239 GstDebugCategory *GST_CAT_REGISTRY = NULL;
       
   240 GstDebugCategory *GST_CAT_QOS = NULL;
   267 
   241 
   268 /* FIXME: export this? */
   242 /* FIXME: export this? */
   269 #ifdef __SYMBIAN32__
   243 #ifdef __SYMBIAN32__
   270 EXPORT_C
   244 EXPORT_C
   271 #endif
   245 #endif
   280     GST_VG_INSIDE
   254     GST_VG_INSIDE
   281   }
   255   }
   282   in_valgrind = GST_VG_UNCHECKED;
   256   in_valgrind = GST_VG_UNCHECKED;
   283 
   257 
   284   if (in_valgrind == GST_VG_UNCHECKED) {
   258   if (in_valgrind == GST_VG_UNCHECKED) {
   285 #ifdef HAVE_VALGRIND_H
   259 #ifdef HAVE_VALGRIND
   286     if (RUNNING_ON_VALGRIND) {
   260     if (RUNNING_ON_VALGRIND) {
   287       GST_CAT_INFO (GST_CAT_GST_INIT, "we're running inside valgrind");
   261       GST_CAT_INFO (GST_CAT_GST_INIT, "we're running inside valgrind");
   288       printf ("GStreamer has detected that it is running inside valgrind.\n");
   262       printf ("GStreamer has detected that it is running inside valgrind.\n");
   289       printf ("It might now take different code paths to ease debugging.\n");
   263       printf ("It might now take different code paths to ease debugging.\n");
   290       printf ("Of course, this may also lead to different bugs.\n");
   264       printf ("Of course, this may also lead to different bugs.\n");
   313 #endif
   287 #endif
   314 
   288 
   315 void
   289 void
   316 _gst_debug_init (void)
   290 _gst_debug_init (void)
   317 {
   291 {
   318   const gchar *env;
   292   gst_atomic_int_set (&__default_level, GST_LEVEL_DEFAULT);
   319 
   293   gst_atomic_int_set (&__use_color, 1);
   320   g_atomic_int_set (&__default_level, GST_LEVEL_DEFAULT);
   294 
   321 #ifndef __SYMBIAN32__
       
   322   g_atomic_int_set (&__use_color, 1);
       
   323 #else
       
   324   g_atomic_int_set (&__use_color, 0);
       
   325 #endif
       
   326   /* get time we started for debugging messages */
   295   /* get time we started for debugging messages */
   327   _priv_gst_info_start_time = gst_util_get_timestamp ();
   296   _priv_gst_info_start_time = gst_util_get_timestamp ();
   328 
   297 
   329 #ifdef HAVE_PRINTF_EXTENSION
   298 #ifdef HAVE_PRINTF_EXTENSION
   330 #if HAVE_REGISTER_PRINTF_SPECIFIER
       
   331   register_printf_specifier (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
       
   332       _gst_info_printf_extension_arginfo);
       
   333   register_printf_specifier (GST_SEGMENT_FORMAT[0],
       
   334       _gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
       
   335 #else
       
   336   register_printf_function (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
   299   register_printf_function (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
   337       _gst_info_printf_extension_arginfo);
   300       _gst_info_printf_extension_arginfo);
   338   register_printf_function (GST_SEGMENT_FORMAT[0],
   301   register_printf_function (GST_SEGMENT_FORMAT[0],
   339       _gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
   302       _gst_info_printf_extension_segment, _gst_info_printf_extension_arginfo);
   340 #endif
       
   341 #endif
   303 #endif
   342 
   304 
   343   /* do NOT use a single debug function before this line has been run */
   305   /* do NOT use a single debug function before this line has been run */
   344   GST_CAT_DEFAULT = _gst_debug_category_new ("default",
   306   GST_CAT_DEFAULT = _gst_debug_category_new ("default",
   345       GST_DEBUG_UNDERLINE, NULL);
   307       GST_DEBUG_UNDERLINE, NULL);
   361       GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL);
   323       GST_DEBUG_BOLD | GST_DEBUG_FG_RED, NULL);
   362   GST_CAT_SCHEDULING = _gst_debug_category_new ("GST_SCHEDULING",
   324   GST_CAT_SCHEDULING = _gst_debug_category_new ("GST_SCHEDULING",
   363       GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA, NULL);
   325       GST_DEBUG_BOLD | GST_DEBUG_FG_MAGENTA, NULL);
   364   GST_CAT_BUFFER = _gst_debug_category_new ("GST_BUFFER",
   326   GST_CAT_BUFFER = _gst_debug_category_new ("GST_BUFFER",
   365       GST_DEBUG_BOLD | GST_DEBUG_BG_GREEN, NULL);
   327       GST_DEBUG_BOLD | GST_DEBUG_BG_GREEN, NULL);
   366   GST_CAT_BUFFER_LIST = _gst_debug_category_new ("GST_BUFFER_LIST",
       
   367       GST_DEBUG_BOLD | GST_DEBUG_BG_GREEN, NULL);
       
   368   GST_CAT_BUS = _gst_debug_category_new ("GST_BUS", GST_DEBUG_BG_YELLOW, NULL);
   328   GST_CAT_BUS = _gst_debug_category_new ("GST_BUS", GST_DEBUG_BG_YELLOW, NULL);
   369   GST_CAT_CAPS = _gst_debug_category_new ("GST_CAPS",
   329   GST_CAT_CAPS = _gst_debug_category_new ("GST_CAPS",
   370       GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
   330       GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
   371   GST_CAT_CLOCK = _gst_debug_category_new ("GST_CLOCK",
   331   GST_CAT_CLOCK = _gst_debug_category_new ("GST_CLOCK",
   372       GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, NULL);
   332       GST_DEBUG_BOLD | GST_DEBUG_FG_YELLOW, NULL);
   373   GST_CAT_ELEMENT_PADS = _gst_debug_category_new ("GST_ELEMENT_PADS",
   333   GST_CAT_ELEMENT_PADS = _gst_debug_category_new ("GST_ELEMENT_PADS",
   374       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
   334       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
   375   GST_CAT_PADS = _gst_debug_category_new ("GST_PADS",
   335   GST_CAT_PADS = _gst_debug_category_new ("GST_PADS",
   376       GST_DEBUG_BOLD | GST_DEBUG_FG_RED | GST_DEBUG_BG_RED, NULL);
       
   377   GST_CAT_PERFORMANCE = _gst_debug_category_new ("GST_PERFORMANCE",
       
   378       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
   336       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
   379   GST_CAT_PIPELINE = _gst_debug_category_new ("GST_PIPELINE",
   337   GST_CAT_PIPELINE = _gst_debug_category_new ("GST_PIPELINE",
   380       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
   338       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
   381   GST_CAT_PLUGIN_LOADING = _gst_debug_category_new ("GST_PLUGIN_LOADING",
   339   GST_CAT_PLUGIN_LOADING = _gst_debug_category_new ("GST_PLUGIN_LOADING",
   382       GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN, NULL);
   340       GST_DEBUG_BOLD | GST_DEBUG_FG_CYAN, NULL);
   411   GST_CAT_QOS = _gst_debug_category_new ("GST_QOS", 0, "QoS");
   369   GST_CAT_QOS = _gst_debug_category_new ("GST_QOS", 0, "QoS");
   412 
   370 
   413 
   371 
   414   /* print out the valgrind message if we're in valgrind */
   372   /* print out the valgrind message if we're in valgrind */
   415   _priv_gst_in_valgrind ();
   373   _priv_gst_in_valgrind ();
   416 
       
   417   env = g_getenv ("GST_DEBUG_OPTIONS");
       
   418   if (env != NULL) {
       
   419     if (strstr (env, "full_tags") || strstr (env, "full-tags"))
       
   420       pretty_tags = FALSE;
       
   421     else if (strstr (env, "pretty_tags") || strstr (env, "pretty-tags"))
       
   422       pretty_tags = TRUE;
       
   423   }
       
   424 }
   374 }
   425 
   375 
   426 /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
   376 /* we can't do this further above, because we initialize the GST_CAT_DEFAULT struct */
   427 #define GST_CAT_DEFAULT _GST_CAT_DEBUG
   377 #define GST_CAT_DEFAULT _GST_CAT_DEBUG
   428 
   378 
   480 {
   430 {
   481   GstDebugMessage message;
   431   GstDebugMessage message;
   482   LogFuncEntry *entry;
   432   LogFuncEntry *entry;
   483   GSList *handler;
   433   GSList *handler;
   484 
   434 
   485 #ifdef _MSC_VER
       
   486   gchar *file_basename;
       
   487 #endif
       
   488 
       
   489   g_return_if_fail (category != NULL);
   435   g_return_if_fail (category != NULL);
   490   g_return_if_fail (file != NULL);
   436   g_return_if_fail (file != NULL);
   491   g_return_if_fail (function != NULL);
   437   g_return_if_fail (function != NULL);
   492   g_return_if_fail (format != NULL);
   438   g_return_if_fail (format != NULL);
   493 
       
   494 #ifdef _MSC_VER
       
   495   /*
       
   496    * The predefined macro __FILE__ is always the exact path given to the
       
   497    * compiler with MSVC, which may or may not be the basename.  We work
       
   498    * around it at runtime to improve the readability.
       
   499    */
       
   500   file = file_basename = g_path_get_basename (file);
       
   501 #endif
       
   502 
   439 
   503   message.message = NULL;
   440   message.message = NULL;
   504   message.format = format;
   441   message.format = format;
   505   G_VA_COPY (message.arguments, args);
   442   G_VA_COPY (message.arguments, args);
   506 
   443 
   511     entry->func (category, level, file, function, line, object, &message,
   448     entry->func (category, level, file, function, line, object, &message,
   512         entry->user_data);
   449         entry->user_data);
   513   }
   450   }
   514   g_free (message.message);
   451   g_free (message.message);
   515   va_end (message.arguments);
   452   va_end (message.arguments);
   516 
       
   517 #ifdef _MSC_VER
       
   518   g_free (file_basename);
       
   519 #endif
       
   520 }
   453 }
   521 
   454 
   522 /**
   455 /**
   523  * gst_debug_message_get:
   456  * gst_debug_message_get:
   524  * @message: a debug message
   457  * @message: a debug message
   539     message->message = g_strdup_vprintf (message->format, message->arguments);
   472     message->message = g_strdup_vprintf (message->format, message->arguments);
   540   }
   473   }
   541   return message->message;
   474   return message->message;
   542 }
   475 }
   543 
   476 
   544 #define MAX_BUFFER_DUMP_STRING_LEN  100
       
   545 
       
   546 /* structure_to_pretty_string:
       
   547  * @structure: a #GstStructure
       
   548  *
       
   549  * Converts @structure to a human-readable string representation. Basically
       
   550  * the same as gst_structure_to_string(), but if the structure contains large
       
   551  * buffers such as images the hex representation of those buffers will be
       
   552  * shortened so that the string remains readable.
       
   553  *
       
   554  * Returns: a newly-allocated string. g_free() when no longer needed.
       
   555  */
       
   556 static gchar *
       
   557 structure_to_pretty_string (const GstStructure * s)
       
   558 {
       
   559   gchar *str, *pos, *end;
       
   560 
       
   561   str = gst_structure_to_string (s);
       
   562   if (str == NULL)
       
   563     return NULL;
       
   564 
       
   565   pos = str;
       
   566   while ((pos = strstr (pos, "(buffer)"))) {
       
   567     guint count = 0;
       
   568 
       
   569     pos += strlen ("(buffer)");
       
   570     for (end = pos; *end != '\0' && *end != ';' && *end != ' '; ++end)
       
   571       ++count;
       
   572     if (count > MAX_BUFFER_DUMP_STRING_LEN) {
       
   573       memcpy (pos + MAX_BUFFER_DUMP_STRING_LEN - 6, "..", 2);
       
   574       memcpy (pos + MAX_BUFFER_DUMP_STRING_LEN - 4, pos + count - 4, 4);
       
   575       g_memmove (pos + MAX_BUFFER_DUMP_STRING_LEN, pos + count,
       
   576           strlen (pos + count) + 1);
       
   577       pos += MAX_BUFFER_DUMP_STRING_LEN;
       
   578     }
       
   579   }
       
   580 
       
   581   return str;
       
   582 }
       
   583 
       
   584 static inline gchar *
       
   585 gst_info_structure_to_string (GstStructure * s)
       
   586 {
       
   587   if (G_UNLIKELY (pretty_tags && s->name == GST_QUARK (TAGLIST)))
       
   588     return structure_to_pretty_string (s);
       
   589   else
       
   590     return gst_structure_to_string (s);
       
   591 }
       
   592 
   477 
   593 static gchar *
   478 static gchar *
   594 gst_debug_print_object (gpointer ptr)
   479 gst_debug_print_object (gpointer ptr)
   595 {
   480 {
   596   GObject *object = (GObject *) ptr;
   481   GObject *object = (GObject *) ptr;
   614   }
   499   }
   615   if (*(GType *) ptr == GST_TYPE_CAPS) {
   500   if (*(GType *) ptr == GST_TYPE_CAPS) {
   616     return gst_caps_to_string ((GstCaps *) ptr);
   501     return gst_caps_to_string ((GstCaps *) ptr);
   617   }
   502   }
   618   if (*(GType *) ptr == GST_TYPE_STRUCTURE) {
   503   if (*(GType *) ptr == GST_TYPE_STRUCTURE) {
   619     return gst_info_structure_to_string ((GstStructure *) ptr);
   504     return gst_structure_to_string ((GstStructure *) ptr);
   620   }
   505   }
   621 #ifdef USE_POISONING
   506 #ifdef USE_POISONING
   622   if (*(guint32 *) ptr == 0xffffffff) {
   507   if (*(guint32 *) ptr == 0xffffffff) {
   623     return g_strdup_printf ("<poisoned@%p>", ptr);
   508     return g_strdup_printf ("<poisoned@%p>", ptr);
   624   }
   509   }
   635   if (GST_IS_MESSAGE (object)) {
   520   if (GST_IS_MESSAGE (object)) {
   636     GstMessage *msg = GST_MESSAGE_CAST (object);
   521     GstMessage *msg = GST_MESSAGE_CAST (object);
   637     gchar *s, *ret;
   522     gchar *s, *ret;
   638 
   523 
   639     if (msg->structure) {
   524     if (msg->structure) {
   640       s = gst_info_structure_to_string (msg->structure);
   525       s = gst_structure_to_string (msg->structure);
   641     } else {
   526     } else {
   642       s = g_strdup ("(NULL)");
   527       s = g_strdup ("(NULL)");
   643     }
   528     }
   644 
   529 
   645     ret = g_strdup_printf ("%s message from element '%s': %s",
   530     ret = g_strdup_printf ("%s message from element '%s': %s",
   646         GST_MESSAGE_TYPE_NAME (msg), (msg->src != NULL) ?
   531         GST_MESSAGE_TYPE_NAME (msg), (msg->src != NULL) ?
   647         GST_ELEMENT_NAME (msg->src) : "(NULL)", s);
   532         GST_ELEMENT_NAME (msg->src) : "(NULL)", s);
   648     g_free (s);
   533     g_free (s);
   649     return ret;
   534     return ret;
   650   }
       
   651   if (GST_IS_QUERY (object)) {
       
   652     GstQuery *query = GST_QUERY_CAST (object);
       
   653 
       
   654     if (query->structure) {
       
   655       return gst_info_structure_to_string (query->structure);
       
   656     } else {
       
   657       const gchar *query_type_name;
       
   658 
       
   659       query_type_name = gst_query_type_get_name (query->type);
       
   660       if (G_LIKELY (query_type_name != NULL)) {
       
   661         return g_strdup_printf ("%s query", query_type_name);
       
   662       } else {
       
   663         return g_strdup_printf ("query of unknown type %d", query->type);
       
   664       }
       
   665     }
       
   666   }
   535   }
   667 
   536 
   668   return g_strdup_printf ("%p", ptr);
   537   return g_strdup_printf ("%p", ptr);
   669 }
   538 }
   670 
   539 
   752 
   621 
   753   return g_string_free (color, FALSE);
   622   return g_string_free (color, FALSE);
   754 }
   623 }
   755 
   624 
   756 /**
   625 /**
   757  * gst_debug_construct_win_color:
       
   758  * @colorinfo: the color info
       
   759  *
       
   760  * Constructs an integer that can be used for getting the desired color in
       
   761  * windows' terminals (cmd.exe). As there is no mean to underline, we simply
       
   762  * ignore this attribute.
       
   763  *
       
   764  * This function returns 0 on non-windows machines.
       
   765  *
       
   766  * Returns: an integer containing the color definition
       
   767  *
       
   768  * Since: 0.10.23
       
   769  */
       
   770 #ifdef __SYMBIAN32__
       
   771 EXPORT_C
       
   772 #endif
       
   773 
       
   774 gint
       
   775 gst_debug_construct_win_color (guint colorinfo)
       
   776 {
       
   777   gint color = 0;
       
   778 #ifdef G_OS_WIN32
       
   779   static const guchar ansi_to_win_fg[8] = {
       
   780     0,                          /* black   */
       
   781     FOREGROUND_RED,             /* red     */
       
   782     FOREGROUND_GREEN,           /* green   */
       
   783     FOREGROUND_RED | FOREGROUND_GREEN,  /* yellow  */
       
   784     FOREGROUND_BLUE,            /* blue    */
       
   785     FOREGROUND_RED | FOREGROUND_BLUE,   /* magenta */
       
   786     FOREGROUND_GREEN | FOREGROUND_BLUE, /* cyan    */
       
   787     FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE /* white   */
       
   788   };
       
   789   static const guchar ansi_to_win_bg[8] = {
       
   790     0,
       
   791     BACKGROUND_RED,
       
   792     BACKGROUND_GREEN,
       
   793     BACKGROUND_RED | BACKGROUND_GREEN,
       
   794     BACKGROUND_BLUE,
       
   795     BACKGROUND_RED | BACKGROUND_BLUE,
       
   796     BACKGROUND_GREEN | FOREGROUND_BLUE,
       
   797     BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
       
   798   };
       
   799 
       
   800   /* we draw black as white, as cmd.exe can only have black bg */
       
   801   if (colorinfo == 0) {
       
   802     return ansi_to_win_fg[7];
       
   803   }
       
   804 
       
   805   if (colorinfo & GST_DEBUG_BOLD) {
       
   806     color |= FOREGROUND_INTENSITY;
       
   807   }
       
   808   if (colorinfo & GST_DEBUG_FG_MASK) {
       
   809     color |= ansi_to_win_fg[colorinfo & GST_DEBUG_FG_MASK];
       
   810   }
       
   811   if (colorinfo & GST_DEBUG_BG_MASK) {
       
   812     color |= ansi_to_win_bg[(colorinfo & GST_DEBUG_BG_MASK) >> 4];
       
   813   }
       
   814 #endif
       
   815   return color;
       
   816 }
       
   817 
       
   818 /* width of %p varies depending on actual value of pointer, which can make
       
   819  * output unevenly aligned if multiple threads are involved, hence the %14p
       
   820  * (should really be %18p, but %14p seems a good compromise between too many
       
   821  * white spaces and likely unalignment on my system) */
       
   822 #if defined (GLIB_SIZEOF_VOID_P) && GLIB_SIZEOF_VOID_P == 8
       
   823 #define PTR_FMT "%14p"
       
   824 #else
       
   825 #define PTR_FMT "%10p"
       
   826 #endif
       
   827 #define PID_FMT "%5d"
       
   828 #define CAT_FMT "%20s %s:%d:%s:%s"
       
   829 
       
   830 #ifdef G_OS_WIN32
       
   831 static const guchar levelcolormap[GST_LEVEL_COUNT] = {
       
   832   /* GST_LEVEL_NONE */
       
   833   FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
       
   834   /* GST_LEVEL_ERROR */
       
   835   FOREGROUND_RED | FOREGROUND_INTENSITY,
       
   836   /* GST_LEVEL_WARNING */
       
   837   FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
       
   838   /* GST_LEVEL_INFO */
       
   839   FOREGROUND_GREEN | FOREGROUND_INTENSITY,
       
   840   /* GST_LEVEL_DEBUG */
       
   841   FOREGROUND_GREEN | FOREGROUND_BLUE,
       
   842   /* GST_LEVEL_LOG */
       
   843   FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
       
   844   /* GST_LEVEL_FIXME */
       
   845   FOREGROUND_RED | FOREGROUND_GREEN,
       
   846   /* placeholder for log level 7 */
       
   847   0,
       
   848   /* placeholder for log level 8 */
       
   849   0,
       
   850   /* GST_LEVEL_MEMDUMP */
       
   851   FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
       
   852 };
       
   853 
       
   854 static const guchar available_colors[] = {
       
   855   FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_RED | FOREGROUND_GREEN,
       
   856   FOREGROUND_BLUE, FOREGROUND_RED | FOREGROUND_BLUE,
       
   857   FOREGROUND_GREEN | FOREGROUND_BLUE,
       
   858 };
       
   859 #else
       
   860 static const gchar *levelcolormap[GST_LEVEL_COUNT] = {
       
   861   "\033[37m",                   /* GST_LEVEL_NONE */
       
   862   "\033[31;01m",                /* GST_LEVEL_ERROR */
       
   863   "\033[33;01m",                /* GST_LEVEL_WARNING */
       
   864   "\033[32;01m",                /* GST_LEVEL_INFO */
       
   865   "\033[36m",                   /* GST_LEVEL_DEBUG */
       
   866   "\033[37m",                   /* GST_LEVEL_LOG */
       
   867   "\033[33;01m",                /* GST_LEVEL_FIXME */
       
   868   "\033[37m",                   /* placeholder for log level 7 */
       
   869   "\033[37m",                   /* placeholder for log level 8 */
       
   870   "\033[37m"                    /* GST_LEVEL_MEMDUMP */
       
   871 };
       
   872 #endif
       
   873 
       
   874 /**
       
   875  * gst_debug_log_default:
   626  * gst_debug_log_default:
   876  * @category: category to log
   627  * @category: category to log
   877  * @level: level of the message
   628  * @level: level of the message
   878  * @file: the file that emitted the message, usually the __FILE__ identifier
   629  * @file: the file that emitted the message, usually the __FILE__ identifier
   879  * @function: the function that emitted the message
   630  * @function: the function that emitted the message
   896 void
   647 void
   897 gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
   648 gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
   898     const gchar * file, const gchar * function, gint line,
   649     const gchar * file, const gchar * function, gint line,
   899     GObject * object, GstDebugMessage * message, gpointer unused)
   650     GObject * object, GstDebugMessage * message, gpointer unused)
   900 {
   651 {
       
   652   gchar *color = NULL;
       
   653   gchar *clear;
       
   654   gchar *obj = NULL;
       
   655   gchar pidcolor[10];
       
   656   const gchar *levelcolor;
   901   gint pid;
   657   gint pid;
   902   GstClockTime elapsed;
   658   GstClockTime elapsed;
   903   gchar *obj = NULL;
   659   gboolean free_color = TRUE;
   904   gboolean free_obj = TRUE;
   660   gboolean free_obj = TRUE;
   905   gboolean is_colored;
   661   static const gchar *levelcolormap[] = {
       
   662     "\033[37m",                 /* GST_LEVEL_NONE */
       
   663     "\033[31;01m",              /* GST_LEVEL_ERROR */
       
   664     "\033[33;01m",              /* GST_LEVEL_WARNING */
       
   665     "\033[32;01m",              /* GST_LEVEL_INFO */
       
   666     "\033[36m",                 /* GST_LEVEL_DEBUG */
       
   667     "\033[37m"                  /* GST_LEVEL_LOG */
       
   668   };
   906 
   669 
   907   if (level > gst_debug_category_get_threshold (category))
   670   if (level > gst_debug_category_get_threshold (category))
   908     return;
   671     return;
   909 
   672 
   910   pid = getpid ();
   673   pid = getpid ();
   911   is_colored = gst_debug_is_colored ();
   674 
   912 
   675   /* color info */
   913   elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
   676   if (gst_debug_is_colored ()) {
   914       gst_util_get_timestamp ());
   677     color = gst_debug_construct_term_color (gst_debug_category_get_color
       
   678         (category));
       
   679     clear = "\033[00m";
       
   680     g_sprintf (pidcolor, "\033[3%1dm", pid % 6 + 31);
       
   681     levelcolor = levelcolormap[level];
       
   682   } else {
       
   683     color = "\0";
       
   684     free_color = FALSE;
       
   685     clear = "";
       
   686     pidcolor[0] = '\0';
       
   687     levelcolor = "\0";
       
   688   }
   915 
   689 
   916   if (object) {
   690   if (object) {
   917     obj = gst_debug_print_object (object);
   691     obj = gst_debug_print_object (object);
   918   } else {
   692   } else {
   919     obj = "\0";
   693     obj = "\0";
   920     free_obj = FALSE;
   694     free_obj = FALSE;
   921   }
   695   }
   922 
   696 
   923   if (is_colored) {
   697   elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
   924 #ifndef G_OS_WIN32
   698       gst_util_get_timestamp ());
   925     /* colors, non-windows */
   699 
   926     gchar *color = NULL;
   700   /*
   927     gchar *clear;
   701      g_printerr ("%s (%p - %" GST_TIME_FORMAT ") %s%20s%s(%s%5d%s) %s%s(%d):%s:%s%s %s\n",
   928     gchar pidcolor[10];
   702      gst_debug_level_get_name (level), g_thread_self (),
   929     const gchar *levelcolor;
   703      GST_TIME_ARGS (elapsed), color,
   930 
   704      gst_debug_category_get_name (category), clear, pidcolor, pid, clear,
   931     color = gst_debug_construct_term_color (gst_debug_category_get_color
   705      color, file, line, function, obj, clear, gst_debug_message_get (message));
   932         (category));
   706    */
   933     clear = "\033[00m";
   707 
   934     g_sprintf (pidcolor, "\033[3%1dm", pid % 6 + 31);
   708   g_printerr ("%" GST_TIME_FORMAT
   935     levelcolor = levelcolormap[level];
   709       " %s%5d%s %p %s%s%s %s%20s %s:%d:%s:%s%s %s\n", GST_TIME_ARGS (elapsed),
   936 
   710       pidcolor, pid, clear, g_thread_self (), levelcolor,
   937 #ifdef __SYMBIAN32__
   711       gst_debug_level_get_name (level), clear, color,
   938     g_printerr ("%" GST_TIME_FORMAT
   712       gst_debug_category_get_name (category), file, line, function, obj, clear,
   939         " %s%5d%s %10p %s%s%s %s%20s %s:%d:%s:%s%s %s\n", GST_TIME_ARGS (elapsed),
   713       gst_debug_message_get (message));
   940         pidcolor, pid, clear, g_thread_self (), levelcolor,
   714 
   941         gst_debug_level_get_name (level), clear, color,
   715   if (free_color)
   942         gst_debug_category_get_name (category), file, line, function, obj, clear,
       
   943         gst_debug_message_get (message));
       
   944 #else
       
   945 #define PRINT_FMT " %s"PID_FMT"%s "PTR_FMT" %s%s%s %s"CAT_FMT"%s %s\n"
       
   946     g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
       
   947         pidcolor, pid, clear, g_thread_self (), levelcolor,
       
   948         gst_debug_level_get_name (level), clear, color,
       
   949         gst_debug_category_get_name (category), file, line, function, obj,
       
   950         clear, gst_debug_message_get (message));
       
   951 #undef PRINT_FMT
       
   952 #endif //__SYMBIAN32__
       
   953     
       
   954     g_free (color);
   716     g_free (color);
   955 #else
       
   956     /* colors, windows. We take a lock to keep colors and content together.
       
   957      * Maybe there is a better way but for now this will do the right
       
   958      * thing. */
       
   959     static GStaticMutex win_print_mutex = G_STATIC_MUTEX_INIT;
       
   960     const gint clear = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
       
   961 #define SET_COLOR(c) \
       
   962   SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c));
       
   963     g_static_mutex_lock (&win_print_mutex);
       
   964     /* timestamp */
       
   965     g_printerr ("%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
       
   966     /* pid */
       
   967     SET_COLOR (available_colors[pid % G_N_ELEMENTS (available_colors)]);
       
   968     g_printerr (PID_FMT, pid);
       
   969     /* thread */
       
   970     SET_COLOR (clear);
       
   971     g_printerr (" " PTR_FMT " ", g_thread_self ());
       
   972     /* level */
       
   973     SET_COLOR (levelcolormap[level]);
       
   974     g_printerr ("%s ", gst_debug_level_get_name (level));
       
   975     /* category */
       
   976     SET_COLOR (gst_debug_construct_win_color (gst_debug_category_get_color
       
   977             (category)));
       
   978     g_printerr (CAT_FMT, gst_debug_category_get_name (category),
       
   979         file, line, function, obj);
       
   980     /* message */
       
   981     SET_COLOR (clear);
       
   982     g_printerr (" %s\n", gst_debug_message_get (message));
       
   983     g_static_mutex_unlock (&win_print_mutex);
       
   984 #endif
       
   985   } else {
       
   986     /* no color, all platforms */
       
   987 #define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
       
   988     g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed), pid,
       
   989         g_thread_self (), gst_debug_level_get_name (level),
       
   990         gst_debug_category_get_name (category), file, line, function, obj,
       
   991         gst_debug_message_get (message));
       
   992 #undef PRINT_FMT
       
   993   }
       
   994 
       
   995   if (free_obj)
   717   if (free_obj)
   996     g_free (obj);
   718     g_free (obj);
   997 }
   719 }
   998 
   720 
   999 /**
   721 /**
  1013 {
   735 {
  1014   switch (level) {
   736   switch (level) {
  1015     case GST_LEVEL_NONE:
   737     case GST_LEVEL_NONE:
  1016       return "";
   738       return "";
  1017     case GST_LEVEL_ERROR:
   739     case GST_LEVEL_ERROR:
  1018       return "ERROR  ";
   740       return "ERROR";
  1019     case GST_LEVEL_WARNING:
   741     case GST_LEVEL_WARNING:
  1020       return "WARN   ";
   742       return "WARN ";
  1021     case GST_LEVEL_INFO:
   743     case GST_LEVEL_INFO:
  1022       return "INFO   ";
   744       return "INFO ";
  1023     case GST_LEVEL_DEBUG:
   745     case GST_LEVEL_DEBUG:
  1024       return "DEBUG  ";
   746       return "DEBUG";
  1025     case GST_LEVEL_LOG:
   747     case GST_LEVEL_LOG:
  1026       return "LOG    ";
   748       return "LOG  ";
  1027     case GST_LEVEL_FIXME:
       
  1028       return "FIXME  ";
       
  1029     case GST_LEVEL_MEMDUMP:
       
  1030       return "MEMDUMP";
       
  1031     default:
   749     default:
  1032       g_warning ("invalid level specified for gst_debug_level_get_name");
   750       g_warning ("invalid level specified for gst_debug_level_get_name");
  1033       return "";
   751       return "";
  1034   }
   752   }
  1035 }
   753 }
  1097 
   815 
  1098   g_static_mutex_lock (&__log_func_mutex);
   816   g_static_mutex_lock (&__log_func_mutex);
  1099   new = __log_functions;
   817   new = __log_functions;
  1100   while ((found = g_slist_find_custom (new, data, func))) {
   818   while ((found = g_slist_find_custom (new, data, func))) {
  1101     if (new == __log_functions) {
   819     if (new == __log_functions) {
  1102       /* make a copy when we have the first hit, so that we modify the copy and
       
  1103        * make that the new list later */
       
  1104       new = g_slist_copy (new);
   820       new = g_slist_copy (new);
  1105       continue;
   821       continue;
  1106     }
   822     }
  1107     g_free (found->data);
   823     g_free (found->data);
  1108     new = g_slist_delete_link (new, found);
   824     new = g_slist_delete_link (new, found);
  1181 #endif
   897 #endif
  1182 
   898 
  1183 void
   899 void
  1184 gst_debug_set_colored (gboolean colored)
   900 gst_debug_set_colored (gboolean colored)
  1185 {
   901 {
  1186   g_atomic_int_set (&__use_color, colored ? 1 : 0);
   902   gst_atomic_int_set (&__use_color, colored ? 1 : 0);
  1187 }
   903 }
  1188 
   904 
  1189 /**
   905 /**
  1190  * gst_debug_is_colored:
   906  * gst_debug_is_colored:
  1191  *
   907  *
  1256 #endif
   972 #endif
  1257 
   973 
  1258 void
   974 void
  1259 gst_debug_set_default_threshold (GstDebugLevel level)
   975 gst_debug_set_default_threshold (GstDebugLevel level)
  1260 {
   976 {
  1261   g_atomic_int_set (&__default_level, level);
   977   gst_atomic_int_set (&__default_level, level);
  1262   gst_debug_reset_all_thresholds ();
   978   gst_debug_reset_all_thresholds ();
  1263 }
   979 }
  1264 
   980 
  1265 /**
   981 /**
  1266  * gst_debug_get_default_threshold:
   982  * gst_debug_get_default_threshold:
  1276 GstDebugLevel
   992 GstDebugLevel
  1277 gst_debug_get_default_threshold (void)
   993 gst_debug_get_default_threshold (void)
  1278 {
   994 {
  1279   return (GstDebugLevel) g_atomic_int_get (&__default_level);
   995   return (GstDebugLevel) g_atomic_int_get (&__default_level);
  1280 }
   996 }
  1281 
       
  1282 static void
   997 static void
  1283 gst_debug_reset_threshold (gpointer category, gpointer unused)
   998 gst_debug_reset_threshold (gpointer category, gpointer unused)
  1284 {
   999 {
  1285   GstDebugCategory *cat = (GstDebugCategory *) category;
  1000   GstDebugCategory *cat = (GstDebugCategory *) category;
  1286   GSList *walk;
  1001   GSList *walk;
  1301   gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
  1016   gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
  1302 
  1017 
  1303 exit:
  1018 exit:
  1304   g_static_mutex_unlock (&__level_name_mutex);
  1019   g_static_mutex_unlock (&__level_name_mutex);
  1305 }
  1020 }
  1306 
       
  1307 static void
  1021 static void
  1308 gst_debug_reset_all_thresholds (void)
  1022 gst_debug_reset_all_thresholds (void)
  1309 {
  1023 {
  1310   g_static_mutex_lock (&__cat_mutex);
  1024   g_static_mutex_lock (&__cat_mutex);
  1311   g_slist_foreach (__categories, gst_debug_reset_threshold, NULL);
  1025   g_slist_foreach (__categories, gst_debug_reset_threshold, NULL);
  1312   g_static_mutex_unlock (&__cat_mutex);
  1026   g_static_mutex_unlock (&__cat_mutex);
  1313 }
  1027 }
  1314 
       
  1315 static void
  1028 static void
  1316 for_each_threshold_by_entry (gpointer data, gpointer user_data)
  1029 for_each_threshold_by_entry (gpointer data, gpointer user_data)
  1317 {
  1030 {
  1318   GstDebugCategory *cat = (GstDebugCategory *) data;
  1031   GstDebugCategory *cat = (GstDebugCategory *) data;
  1319   LevelNameEntry *entry = (LevelNameEntry *) user_data;
  1032   LevelNameEntry *entry = (LevelNameEntry *) user_data;
  1413   if (description != NULL) {
  1126   if (description != NULL) {
  1414     cat->description = g_strdup (description);
  1127     cat->description = g_strdup (description);
  1415   } else {
  1128   } else {
  1416     cat->description = g_strdup ("no description");
  1129     cat->description = g_strdup ("no description");
  1417   }
  1130   }
  1418   g_atomic_int_set (&cat->threshold, 0);
  1131   gst_atomic_int_set (&cat->threshold, 0);
  1419   gst_debug_reset_threshold (cat, NULL);
  1132   gst_debug_reset_threshold (cat, NULL);
  1420 
  1133 
  1421   /* add to category list */
  1134   /* add to category list */
  1422   g_static_mutex_lock (&__cat_mutex);
  1135   g_static_mutex_lock (&__cat_mutex);
  1423   __categories = g_slist_prepend (__categories, cat);
  1136   __categories = g_slist_prepend (__categories, cat);
  1479   if (level > __gst_debug_min) {
  1192   if (level > __gst_debug_min) {
  1480     __gst_debug_enabled = TRUE;
  1193     __gst_debug_enabled = TRUE;
  1481     __gst_debug_min = level;
  1194     __gst_debug_min = level;
  1482   }
  1195   }
  1483 
  1196 
  1484   g_atomic_int_set (&category->threshold, level);
  1197   gst_atomic_int_set (&category->threshold, level);
  1485 }
  1198 }
  1486 
  1199 
  1487 /**
  1200 /**
  1488  * gst_debug_category_reset_threshold:
  1201  * gst_debug_category_reset_threshold:
  1489  * @category: a #GstDebugCategory to reset threshold of.
  1202  * @category: a #GstDebugCategory to reset threshold of.
  1598   g_static_mutex_lock (&__cat_mutex);
  1311   g_static_mutex_lock (&__cat_mutex);
  1599   ret = g_slist_copy (__categories);
  1312   ret = g_slist_copy (__categories);
  1600   g_static_mutex_unlock (&__cat_mutex);
  1313   g_static_mutex_unlock (&__cat_mutex);
  1601 
  1314 
  1602   return ret;
  1315   return ret;
  1603 }
       
  1604 #ifdef __SYMBIAN32__
       
  1605 EXPORT_C
       
  1606 #endif
       
  1607 
       
  1608 
       
  1609 GstDebugCategory *
       
  1610 _gst_debug_get_category (const gchar * name)
       
  1611 {
       
  1612   GstDebugCategory *ret = NULL;
       
  1613   GSList *node;
       
  1614 
       
  1615   for (node = __categories; node; node = g_slist_next (node)) {
       
  1616     ret = (GstDebugCategory *) node->data;
       
  1617     if (!strcmp (name, ret->name)) {
       
  1618       return ret;
       
  1619     }
       
  1620   }
       
  1621   return NULL;
       
  1622 }
  1316 }
  1623 
  1317 
  1624 /*** FUNCTION POINTERS ********************************************************/
  1318 /*** FUNCTION POINTERS ********************************************************/
  1625 
  1319 
  1626 static GHashTable *__gst_function_pointers;     /* NULL */
  1320 static GHashTable *__gst_function_pointers;     /* NULL */
  1731 
  1425 
  1732   g_free (buffer);
  1426   g_free (buffer);
  1733   return len;
  1427   return len;
  1734 }
  1428 }
  1735 
  1429 
  1736 #if HAVE_REGISTER_PRINTF_SPECIFIER
       
  1737 static int
       
  1738 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
       
  1739     int *argtypes, int *size)
       
  1740 #else
       
  1741 static int
  1430 static int
  1742 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
  1431 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
  1743     int *argtypes)
  1432     int *argtypes)
  1744 #endif
  1433 {
  1745 {
  1434   if (n > 0)
  1746   if (n > 0) {
       
  1747     argtypes[0] = PA_POINTER;
  1435     argtypes[0] = PA_POINTER;
  1748 #if HAVE_REGISTER_PRINTF_SPECIFIER
       
  1749     *size = sizeof (gpointer);
       
  1750 #endif
       
  1751   }
       
  1752   return 1;
  1436   return 1;
  1753 }
  1437 }
  1754 #endif /* HAVE_PRINTF_EXTENSION */
  1438 #endif /* HAVE_PRINTF_EXTENSION */
  1755 
  1439 
  1756 static void
       
  1757 gst_info_dump_mem_line (gchar * linebuf, gsize linebuf_size,
       
  1758     const guint8 * mem, gsize mem_offset, gsize mem_size)
       
  1759 {
       
  1760   gchar hexstr[50], ascstr[18], digitstr[4];
       
  1761 
       
  1762   if (mem_size > 16)
       
  1763     mem_size = 16;
       
  1764 
       
  1765   hexstr[0] = '\0';
       
  1766   ascstr[0] = '\0';
       
  1767 
       
  1768   if (mem != NULL) {
       
  1769     guint i = 0;
       
  1770 
       
  1771     mem += mem_offset;
       
  1772     while (i < mem_size) {
       
  1773       ascstr[i] = (g_ascii_isprint (mem[i])) ? mem[i] : '.';
       
  1774       g_snprintf (digitstr, sizeof (digitstr), "%02x ", mem[i]);
       
  1775       g_strlcat (hexstr, digitstr, sizeof (hexstr));
       
  1776       ++i;
       
  1777     }
       
  1778     ascstr[i] = '\0';
       
  1779   }
       
  1780 
       
  1781   g_snprintf (linebuf, linebuf_size, "%08x: %-48.48s %-16.16s",
       
  1782       (guint) mem_offset, hexstr, ascstr);
       
  1783 }
       
  1784 #ifdef __SYMBIAN32__
       
  1785 EXPORT_C
       
  1786 #endif
       
  1787 
       
  1788 
       
  1789 void
       
  1790 _gst_debug_dump_mem (GstDebugCategory * cat, const gchar * file,
       
  1791     const gchar * func, gint line, GObject * obj, const gchar * msg,
       
  1792     const guint8 * data, guint length)
       
  1793 {
       
  1794   guint off = 0;
       
  1795 
       
  1796   gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, "--------"
       
  1797       "-------------------------------------------------------------------");
       
  1798 
       
  1799   if (msg != NULL && *msg != '\0') {
       
  1800     gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, msg);
       
  1801   }
       
  1802 
       
  1803   while (off < length) {
       
  1804     gchar buf[128];
       
  1805 
       
  1806     /* gst_info_dump_mem_line will process 16 bytes at most */
       
  1807     gst_info_dump_mem_line (buf, sizeof (buf), data, off, length - off);
       
  1808     gst_debug_log (cat, GST_LEVEL_MEMDUMP, file, func, line, obj, "%s", buf);
       
  1809     off += 16;
       
  1810   }
       
  1811 
       
  1812   gst_debug_log ((cat), GST_LEVEL_MEMDUMP, file, func, line, obj, "--------"
       
  1813       "-------------------------------------------------------------------");
       
  1814 }
       
  1815 
       
  1816 #else /* !GST_DISABLE_GST_DEBUG */
  1440 #else /* !GST_DISABLE_GST_DEBUG */
  1817 #ifdef GST_REMOVE_DISABLED
       
  1818 
       
  1819 GstDebugCategory *
       
  1820 _gst_debug_category_new (const gchar * name, guint color,
       
  1821     const gchar * description)
       
  1822 {
       
  1823   return NULL;
       
  1824 }
       
  1825 #ifdef __SYMBIAN32__
       
  1826 EXPORT_C
       
  1827 #endif
       
  1828 
       
  1829 
       
  1830 void
       
  1831 _gst_debug_register_funcptr (gpointer func, const gchar * ptrname)
       
  1832 {
       
  1833 }
       
  1834 
       
  1835 /* This function MUST NOT return NULL */
       
  1836 #ifdef __SYMBIAN32__
       
  1837 EXPORT_C
       
  1838 #endif
       
  1839 
       
  1840 const gchar *
       
  1841 _gst_debug_nameof_funcptr (gpointer func)
       
  1842 {
       
  1843   return "(NULL)";
       
  1844 }
       
  1845 #ifdef __SYMBIAN32__
       
  1846 EXPORT_C
       
  1847 #endif
       
  1848 
       
  1849 
       
  1850 void
       
  1851 gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
       
  1852     const gchar * file, const gchar * function, gint line,
       
  1853     GObject * object, const gchar * format, ...)
       
  1854 {
       
  1855 }
       
  1856 #ifdef __SYMBIAN32__
       
  1857 EXPORT_C
       
  1858 #endif
       
  1859 
       
  1860 
       
  1861 void
       
  1862 gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
       
  1863     const gchar * file, const gchar * function, gint line,
       
  1864     GObject * object, const gchar * format, va_list args)
       
  1865 {
       
  1866 }
       
  1867 #ifdef __SYMBIAN32__
       
  1868 EXPORT_C
       
  1869 #endif
       
  1870 
       
  1871 
       
  1872 const gchar *
       
  1873 gst_debug_message_get (GstDebugMessage * message)
       
  1874 {
       
  1875   return "";
       
  1876 }
       
  1877 #ifdef __SYMBIAN32__
       
  1878 EXPORT_C
       
  1879 #endif
       
  1880 
       
  1881 
       
  1882 void
       
  1883 gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
       
  1884     const gchar * file, const gchar * function, gint line,
       
  1885     GObject * object, GstDebugMessage * message, gpointer unused)
       
  1886 {
       
  1887 }
       
  1888 #ifdef __SYMBIAN32__
       
  1889 EXPORT_C
       
  1890 #endif
       
  1891 
       
  1892 
       
  1893 G_CONST_RETURN gchar *
       
  1894 gst_debug_level_get_name (GstDebugLevel level)
       
  1895 {
       
  1896   return "NONE";
       
  1897 }
       
  1898 #ifdef __SYMBIAN32__
       
  1899 EXPORT_C
       
  1900 #endif
       
  1901 
       
  1902 
       
  1903 void
       
  1904 gst_debug_add_log_function (GstLogFunction func, gpointer data)
       
  1905 {
       
  1906 }
       
  1907 #ifdef __SYMBIAN32__
       
  1908 EXPORT_C
       
  1909 #endif
       
  1910 
       
  1911 
       
  1912 guint
  1441 guint
  1913 gst_debug_remove_log_function (GstLogFunction func)
  1442 gst_debug_remove_log_function (GstLogFunction func)
  1914 {
  1443 {
  1915   return 0;
  1444   return 0;
  1916 }
  1445 }
  1917 #ifdef __SYMBIAN32__
       
  1918 EXPORT_C
       
  1919 #endif
       
  1920 
       
  1921 
  1446 
  1922 guint
  1447 guint
  1923 gst_debug_remove_log_function_by_data (gpointer data)
  1448 gst_debug_remove_log_function_by_data (gpointer data)
  1924 {
  1449 {
  1925   return 0;
  1450   return 0;
  1926 }
  1451 }
  1927 #ifdef __SYMBIAN32__
       
  1928 EXPORT_C
       
  1929 #endif
       
  1930 
       
  1931 
       
  1932 void
       
  1933 gst_debug_set_active (gboolean active)
       
  1934 {
       
  1935 }
       
  1936 #ifdef __SYMBIAN32__
       
  1937 EXPORT_C
       
  1938 #endif
       
  1939 
       
  1940 
       
  1941 gboolean
       
  1942 gst_debug_is_active (void)
       
  1943 {
       
  1944   return FALSE;
       
  1945 }
       
  1946 #ifdef __SYMBIAN32__
       
  1947 EXPORT_C
       
  1948 #endif
       
  1949 
       
  1950 
       
  1951 void
       
  1952 gst_debug_set_colored (gboolean colored)
       
  1953 {
       
  1954 }
       
  1955 #ifdef __SYMBIAN32__
       
  1956 EXPORT_C
       
  1957 #endif
       
  1958 
       
  1959 
       
  1960 gboolean
       
  1961 gst_debug_is_colored (void)
       
  1962 {
       
  1963   return FALSE;
       
  1964 }
       
  1965 #ifdef __SYMBIAN32__
       
  1966 EXPORT_C
       
  1967 #endif
       
  1968 
       
  1969 
       
  1970 void
       
  1971 gst_debug_set_default_threshold (GstDebugLevel level)
       
  1972 {
       
  1973 }
       
  1974 #ifdef __SYMBIAN32__
       
  1975 EXPORT_C
       
  1976 #endif
       
  1977 
       
  1978 
       
  1979 GstDebugLevel
       
  1980 gst_debug_get_default_threshold (void)
       
  1981 {
       
  1982   return GST_LEVEL_NONE;
       
  1983 }
       
  1984 #ifdef __SYMBIAN32__
       
  1985 EXPORT_C
       
  1986 #endif
       
  1987 
       
  1988 
       
  1989 void
       
  1990 gst_debug_set_threshold_for_name (const gchar * name, GstDebugLevel level)
       
  1991 {
       
  1992 }
       
  1993 #ifdef __SYMBIAN32__
       
  1994 EXPORT_C
       
  1995 #endif
       
  1996 
       
  1997 
       
  1998 void
       
  1999 gst_debug_unset_threshold_for_name (const gchar * name)
       
  2000 {
       
  2001 }
       
  2002 #ifdef __SYMBIAN32__
       
  2003 EXPORT_C
       
  2004 #endif
       
  2005 
       
  2006 
       
  2007 void
       
  2008 gst_debug_category_free (GstDebugCategory * category)
       
  2009 {
       
  2010 }
       
  2011 #ifdef __SYMBIAN32__
       
  2012 EXPORT_C
       
  2013 #endif
       
  2014 
       
  2015 
       
  2016 void
       
  2017 gst_debug_category_set_threshold (GstDebugCategory * category,
       
  2018     GstDebugLevel level)
       
  2019 {
       
  2020 }
       
  2021 #ifdef __SYMBIAN32__
       
  2022 EXPORT_C
       
  2023 #endif
       
  2024 
       
  2025 
       
  2026 void
       
  2027 gst_debug_category_reset_threshold (GstDebugCategory * category)
       
  2028 {
       
  2029 }
       
  2030 #ifdef __SYMBIAN32__
       
  2031 EXPORT_C
       
  2032 #endif
       
  2033 
       
  2034 
       
  2035 GstDebugLevel
       
  2036 gst_debug_category_get_threshold (GstDebugCategory * category)
       
  2037 {
       
  2038   return GST_LEVEL_NONE;
       
  2039 }
       
  2040 #ifdef __SYMBIAN32__
       
  2041 EXPORT_C
       
  2042 #endif
       
  2043 
       
  2044 
       
  2045 G_CONST_RETURN gchar *
       
  2046 gst_debug_category_get_name (GstDebugCategory * category)
       
  2047 {
       
  2048   return "";
       
  2049 }
       
  2050 #ifdef __SYMBIAN32__
       
  2051 EXPORT_C
       
  2052 #endif
       
  2053 
       
  2054 
       
  2055 guint
       
  2056 gst_debug_category_get_color (GstDebugCategory * category)
       
  2057 {
       
  2058   return 0;
       
  2059 }
       
  2060 #ifdef __SYMBIAN32__
       
  2061 EXPORT_C
       
  2062 #endif
       
  2063 
       
  2064 
       
  2065 G_CONST_RETURN gchar *
       
  2066 gst_debug_category_get_description (GstDebugCategory * category)
       
  2067 {
       
  2068   return "";
       
  2069 }
       
  2070 #ifdef __SYMBIAN32__
       
  2071 EXPORT_C
       
  2072 #endif
       
  2073 
       
  2074 
       
  2075 GSList *
       
  2076 gst_debug_get_all_categories (void)
       
  2077 {
       
  2078   return NULL;
       
  2079 }
       
  2080 
       
  2081 GstDebugCategory *
       
  2082 _gst_debug_get_category (const gchar * name)
       
  2083 {
       
  2084   return NULL;
       
  2085 }
       
  2086 #ifdef __SYMBIAN32__
       
  2087 EXPORT_C
       
  2088 #endif
       
  2089 
       
  2090 
       
  2091 gchar *
       
  2092 gst_debug_construct_term_color (guint colorinfo)
       
  2093 {
       
  2094   return g_strdup ("00");
       
  2095 }
       
  2096 
       
  2097 gint
       
  2098 gst_debug_construct_win_color (guint colorinfo)
       
  2099 {
       
  2100   return 0;
       
  2101 }
       
  2102 #ifdef __SYMBIAN32__
       
  2103 EXPORT_C
       
  2104 #endif
       
  2105 
       
  2106 
  1452 
  2107 gboolean
  1453 gboolean
  2108 _priv_gst_in_valgrind (void)
  1454 _priv_gst_in_valgrind (void)
  2109 {
  1455 {
  2110   return FALSE;
  1456   return FALSE;
  2111 }
  1457 }
  2112 
  1458 
  2113 void
       
  2114 _gst_debug_dump_mem (GstDebugCategory * cat, const gchar * file,
       
  2115     const gchar * func, gint line, GObject * obj, const gchar * msg,
       
  2116     const guint8 * data, guint length)
       
  2117 {
       
  2118 }
       
  2119 #endif /* GST_REMOVE_DISABLED */
       
  2120 #endif /* GST_DISABLE_GST_DEBUG */
  1459 #endif /* GST_DISABLE_GST_DEBUG */
  2121 
  1460 
  2122 
  1461 
  2123 #ifdef GST_ENABLE_FUNC_INSTRUMENTATION
  1462 #ifdef GST_ENABLE_FUNC_INSTRUMENTATION
  2124 /* FIXME make this thread specific */
  1463 /* FIXME make this thread specific */
  2182 
  1521 
  2183     walk = g_slist_next (walk);
  1522     walk = g_slist_next (walk);
  2184   }
  1523   }
  2185 }
  1524 }
  2186 #else
  1525 #else
  2187 #ifdef __SYMBIAN32__
       
  2188 EXPORT_C
       
  2189 #endif
       
  2190 void
  1526 void
  2191 gst_debug_print_stack_trace (void)
  1527 gst_debug_print_stack_trace (void)
  2192 {
  1528 {
  2193   /* nothing because it's compiled out */
  1529   /* nothing because it's compiled out */
  2194 }
  1530 }
  2212 }
  1548 }
  2213 #ifdef __SYMBIAN32__
  1549 #ifdef __SYMBIAN32__
  2214 EXPORT_C
  1550 EXPORT_C
  2215 #endif
  1551 #endif
  2216 
  1552 
  2217 GstDebugLevel*   gst_debug_min()
       
  2218 {
       
  2219     return &__gst_debug_min;
       
  2220 }
       
  2221 #ifdef __SYMBIAN32__
       
  2222 EXPORT_C
       
  2223 #endif
       
  2224 
       
  2225 GstDebugCategory** _GST_CAT_QOS()
  1553 GstDebugCategory** _GST_CAT_QOS()
  2226 {
  1554 {
  2227 	return &GST_CAT_QOS;
  1555 	return &GST_CAT_QOS;
  2228 }
  1556 }
  2229 #ifdef __SYMBIAN32__
  1557 #ifdef __SYMBIAN32__