Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst / gstinfo.c
index e80da43..ca4c003 100644 (file)
@@ -90,6 +90,9 @@
 #include "gst_private.h"
 #include "gstinfo.h"
 
+#undef gst_debug_remove_log_function
+#undef gst_debug_add_log_function
+
 #ifndef GST_DISABLE_GST_DEBUG
 
 #ifdef HAVE_DLFCN_H
 #  include <printf.h>
 #endif
 #include <stdio.h>              /* fprintf */
+#include <glib/gstdio.h>
+#include <errno.h>
 #ifdef HAVE_UNISTD_H
 #  include <unistd.h>           /* getpid on UNIX */
 #endif
 #include "gstutils.h"
 #include "gstquark.h"
 #include "gstsegment.h"
-#ifdef HAVE_VALGRIND_H
+#ifdef HAVE_VALGRIND_VALGRIND_H
 #  include <valgrind/valgrind.h>
 #endif
 #include <glib/gprintf.h>       /* g_sprintf */
@@ -153,7 +158,6 @@ GstDebugCategory *GST_CAT_PLUGIN_LOADING = NULL;
 GstDebugCategory *GST_CAT_PLUGIN_INFO = NULL;
 GstDebugCategory *GST_CAT_PROPERTIES = NULL;
 GstDebugCategory *GST_CAT_TYPES = NULL;
-GstDebugCategory *GST_CAT_XML = NULL;
 GstDebugCategory *GST_CAT_NEGOTIATION = NULL;
 GstDebugCategory *GST_CAT_REFCOUNTING = NULL;
 GstDebugCategory *GST_CAT_ERROR_SYSTEM = NULL;
@@ -218,7 +222,7 @@ static int _gst_info_printf_extension_ptr (FILE * stream,
     const struct printf_info *info, const void *const *args);
 static int _gst_info_printf_extension_segment (FILE * stream,
     const struct printf_info *info, const void *const *args);
-#if HAVE_REGISTER_PRINTF_SPECIFIER
+#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
 static int _gst_info_printf_extension_arginfo (const struct printf_info *info,
     size_t n, int *argtypes, int *size);
 #else
@@ -261,8 +265,10 @@ static GSList *__log_functions = NULL;
 #define PRETTY_TAGS_DEFAULT  TRUE
 static gboolean pretty_tags = PRETTY_TAGS_DEFAULT;
 
-static gint __default_level;
-static gint __use_color;
+static volatile gint G_GNUC_MAY_ALIAS __default_level = GST_LEVEL_DEFAULT;
+static volatile gint G_GNUC_MAY_ALIAS __use_color = 1;
+
+static FILE *log_file;
 
 /* FIXME: export this? */
 gboolean
@@ -277,7 +283,7 @@ _priv_gst_in_valgrind (void)
   in_valgrind = GST_VG_UNCHECKED;
 
   if (in_valgrind == GST_VG_UNCHECKED) {
-#ifdef HAVE_VALGRIND_H
+#ifdef HAVE_VALGRIND_VALGRIND_H
     if (RUNNING_ON_VALGRIND) {
       GST_CAT_INFO (GST_CAT_GST_INIT, "we're running inside valgrind");
       printf ("GStreamer has detected that it is running inside valgrind.\n");
@@ -294,7 +300,7 @@ _priv_gst_in_valgrind (void)
     g_assert (in_valgrind == GST_VG_NO_VALGRIND ||
         in_valgrind == GST_VG_INSIDE);
   }
-  return (in_valgrind == GST_VG_INSIDE) ? TRUE : FALSE;
+  return (in_valgrind == GST_VG_INSIDE);
 }
 
 /**
@@ -308,14 +314,27 @@ _gst_debug_init (void)
 {
   const gchar *env;
 
-  g_atomic_int_set (&__default_level, GST_LEVEL_DEFAULT);
-  g_atomic_int_set (&__use_color, 1);
+  env = g_getenv ("GST_DEBUG_FILE");
+  if (env != NULL && *env != '\0') {
+    if (strcmp (env, "-") == 0) {
+      log_file = stdout;
+    } else {
+      log_file = g_fopen (env, "w");
+      if (log_file == NULL) {
+        g_printerr ("Could not open log file '%s' for writing: %s\n", env,
+            g_strerror (errno));
+        log_file = stderr;
+      }
+    }
+  } else {
+    log_file = stderr;
+  }
 
   /* get time we started for debugging messages */
   _priv_gst_info_start_time = gst_util_get_timestamp ();
 
 #ifdef HAVE_PRINTF_EXTENSION
-#if HAVE_REGISTER_PRINTF_SPECIFIER
+#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
   register_printf_specifier (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
       _gst_info_printf_extension_arginfo);
   register_printf_specifier (GST_SEGMENT_FORMAT[0],
@@ -374,8 +393,6 @@ _gst_debug_init (void)
       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLUE, NULL);
   GST_CAT_TYPES = _gst_debug_category_new ("GST_TYPES",
       GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
-  GST_CAT_XML = _gst_debug_category_new ("GST_XML",
-      GST_DEBUG_BOLD | GST_DEBUG_FG_WHITE | GST_DEBUG_BG_RED, NULL);
   GST_CAT_NEGOTIATION = _gst_debug_category_new ("GST_NEGOTIATION",
       GST_DEBUG_BOLD | GST_DEBUG_FG_BLUE, NULL);
   GST_CAT_REFCOUNTING = _gst_debug_category_new ("GST_REFCOUNTING",
@@ -422,7 +439,8 @@ _gst_debug_init (void)
  * @file: the file that emitted the message, usually the __FILE__ identifier
  * @function: the function that emitted the message
  * @line: the line from that the message was emitted, usually __LINE__
- * @object: the object this message relates to or NULL if none
+ * @object: (transfer none) (allow-none): the object this message relates to,
+ *     or NULL if none
  * @format: a printf style format string
  * @...: optional arguments for the format
  *
@@ -441,6 +459,31 @@ gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
   va_end (var_args);
 }
 
+#ifdef _MSC_VER
+/* based on g_basename(), which we can't use because it was deprecated */
+static inline const gchar *
+gst_path_basename (const gchar * file_name)
+{
+  register const gchar *base;
+
+  base = strrchr (file_name, G_DIR_SEPARATOR);
+
+  {
+    const gchar *q = strrchr (file_name, '/');
+    if (base == NULL || (q != NULL && q > base))
+      base = q;
+  }
+
+  if (base)
+    return base + 1;
+
+  if (g_ascii_isalpha (file_name[0]) && file_name[1] == ':')
+    return file_name + 2;
+
+  return file_name;
+}
+#endif
+
 /**
  * gst_debug_log_valist:
  * @category: category to log
@@ -448,7 +491,8 @@ gst_debug_log (GstDebugCategory * category, GstDebugLevel level,
  * @file: the file that emitted the message, usually the __FILE__ identifier
  * @function: the function that emitted the message
  * @line: the line from that the message was emitted, usually __LINE__
- * @object: the object this message relates to or NULL if none
+ * @object: (transfer none) (allow-none): the object this message relates to,
+ *     or NULL if none
  * @format: a printf style format string
  * @args: optional arguments for the format
  *
@@ -463,22 +507,16 @@ gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
   LogFuncEntry *entry;
   GSList *handler;
 
-#ifdef _MSC_VER
-  gchar *file_basename;
-#endif
-
   g_return_if_fail (category != NULL);
   g_return_if_fail (file != NULL);
   g_return_if_fail (function != NULL);
   g_return_if_fail (format != NULL);
 
-#ifdef _MSC_VER
-  /*
-   * The predefined macro __FILE__ is always the exact path given to the
+  /* The predefined macro __FILE__ is always the exact path given to the
    * compiler with MSVC, which may or may not be the basename.  We work
-   * around it at runtime to improve the readability.
-   */
-  file = file_basename = g_path_get_basename (file);
+   * around it at runtime to improve the readability. */
+#ifdef _MSC_VER
+  file = gst_path_basename (file);
 #endif
 
   message.message = NULL;
@@ -494,10 +532,6 @@ gst_debug_log_valist (GstDebugCategory * category, GstDebugLevel level,
   }
   g_free (message.message);
   va_end (message.arguments);
-
-#ifdef _MSC_VER
-  g_free (file_basename);
-#endif
 }
 
 /**
@@ -559,7 +593,7 @@ structure_to_pretty_string (const GstStructure * s)
 }
 
 static inline gchar *
-gst_info_structure_to_string (GstStructure * s)
+gst_info_structure_to_string (const GstStructure * s)
 {
   if (G_UNLIKELY (pretty_tags && s->name == GST_QUARK (TAGLIST)))
     return structure_to_pretty_string (s);
@@ -590,10 +624,10 @@ gst_debug_print_object (gpointer ptr)
     return g_strdup ("(NULL)");
   }
   if (*(GType *) ptr == GST_TYPE_CAPS) {
-    return gst_caps_to_string ((GstCaps *) ptr);
+    return gst_caps_to_string ((const GstCaps *) ptr);
   }
   if (*(GType *) ptr == GST_TYPE_STRUCTURE) {
-    return gst_info_structure_to_string ((GstStructure *) ptr);
+    return gst_info_structure_to_string ((const GstStructure *) ptr);
   }
 #ifdef USE_POISONING
   if (*(guint32 *) ptr == 0xffffffff) {
@@ -612,9 +646,12 @@ gst_debug_print_object (gpointer ptr)
   if (GST_IS_MESSAGE (object)) {
     GstMessage *msg = GST_MESSAGE_CAST (object);
     gchar *s, *ret;
+    const GstStructure *structure;
+
+    structure = gst_message_get_structure (msg);
 
-    if (msg->structure) {
-      s = gst_info_structure_to_string (msg->structure);
+    if (structure) {
+      s = gst_info_structure_to_string (structure);
     } else {
       s = g_strdup ("(NULL)");
     }
@@ -627,9 +664,12 @@ gst_debug_print_object (gpointer ptr)
   }
   if (GST_IS_QUERY (object)) {
     GstQuery *query = GST_QUERY_CAST (object);
+    const GstStructure *structure;
 
-    if (query->structure) {
-      return gst_info_structure_to_string (query->structure);
+    structure = gst_query_get_structure (query);
+
+    if (structure) {
+      return gst_info_structure_to_string (structure);
     } else {
       const gchar *query_type_name;
 
@@ -641,6 +681,24 @@ gst_debug_print_object (gpointer ptr)
       }
     }
   }
+  if (GST_IS_EVENT (object)) {
+    GstEvent *event = GST_EVENT_CAST (object);
+    gchar *s, *ret;
+    GstStructure *structure;
+
+    structure = (GstStructure *) gst_event_get_structure (event);
+    if (structure) {
+      s = gst_info_structure_to_string (structure);
+    } else {
+      s = g_strdup ("(NULL)");
+    }
+
+    ret = g_strdup_printf ("%s event at time %"
+        GST_TIME_FORMAT ": %s",
+        GST_EVENT_TYPE_NAME (event), GST_TIME_ARGS (event->timestamp), s);
+    g_free (s);
+    return ret;
+  }
 
   return g_strdup_printf ("%p", ptr);
 }
@@ -663,13 +721,11 @@ gst_debug_print_segment (gpointer ptr)
     }
     case GST_FORMAT_TIME:{
       return g_strdup_printf ("time segment start=%" GST_TIME_FORMAT
-          ", stop=%" GST_TIME_FORMAT ", last_stop=%" GST_TIME_FORMAT
-          ", duration=%" GST_TIME_FORMAT ", rate=%f, applied_rate=%f"
-          ", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
+          ", stop=%" GST_TIME_FORMAT ", rate=%f, applied_rate=%f"
+          ", flags=0x%02x, time=%" GST_TIME_FORMAT ", base=%" GST_TIME_FORMAT,
           GST_TIME_ARGS (segment->start), GST_TIME_ARGS (segment->stop),
-          GST_TIME_ARGS (segment->last_stop), GST_TIME_ARGS (segment->duration),
           segment->rate, segment->applied_rate, (guint) segment->flags,
-          GST_TIME_ARGS (segment->time), GST_TIME_ARGS (segment->accum));
+          GST_TIME_ARGS (segment->time), GST_TIME_ARGS (segment->base));
     }
     default:{
       const gchar *format_name;
@@ -678,13 +734,11 @@ gst_debug_print_segment (gpointer ptr)
       if (G_UNLIKELY (format_name == NULL))
         format_name = "(UNKNOWN FORMAT)";
       return g_strdup_printf ("%s segment start=%" G_GINT64_FORMAT
-          ", stop=%" G_GINT64_FORMAT ", last_stop=%" G_GINT64_FORMAT
-          ", duration=%" G_GINT64_FORMAT ", rate=%f, applied_rate=%f"
-          ", flags=0x%02x, time=%" GST_TIME_FORMAT ", accum=%" GST_TIME_FORMAT,
-          format_name, segment->start, segment->stop, segment->last_stop,
-          segment->duration, segment->rate, segment->applied_rate,
-          (guint) segment->flags, GST_TIME_ARGS (segment->time),
-          GST_TIME_ARGS (segment->accum));
+          ", stop=%" G_GINT64_FORMAT ", rate=%f, applied_rate=%f"
+          ", flags=0x%02x, time=%" GST_TIME_FORMAT ", base=%" GST_TIME_FORMAT,
+          format_name, segment->start, segment->stop, segment->rate,
+          segment->applied_rate, (guint) segment->flags,
+          GST_TIME_ARGS (segment->time), GST_TIME_ARGS (segment->base));
     }
   }
 }
@@ -699,7 +753,8 @@ gst_debug_print_segment (gpointer ptr)
  * terminals.
  * You need to free the string after use.
  *
- * Returns: a string containing the color definition
+ * Returns: (transfer full) (type gchar*): a string containing the color
+ *     definition
  */
 gchar *
 gst_debug_construct_term_color (guint colorinfo)
@@ -812,8 +867,8 @@ static const guchar levelcolormap[GST_LEVEL_COUNT] = {
   FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
   /* GST_LEVEL_FIXME */
   FOREGROUND_RED | FOREGROUND_GREEN,
-  /* placeholder for log level 7 */
-  0,
+  /* GST_LEVEL_TRACE */
+  FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,
   /* placeholder for log level 8 */
   0,
   /* GST_LEVEL_MEMDUMP */
@@ -834,7 +889,7 @@ static const gchar *levelcolormap[GST_LEVEL_COUNT] = {
   "\033[36m",                   /* GST_LEVEL_DEBUG */
   "\033[37m",                   /* GST_LEVEL_LOG */
   "\033[33;01m",                /* GST_LEVEL_FIXME */
-  "\033[37m",                   /* placeholder for log level 7 */
+  "\033[37m",                   /* GST_LEVEL_TRACE */
   "\033[37m",                   /* placeholder for log level 8 */
   "\033[37m"                    /* GST_LEVEL_MEMDUMP */
 };
@@ -848,12 +903,15 @@ static const gchar *levelcolormap[GST_LEVEL_COUNT] = {
  * @function: the function that emitted the message
  * @line: the line from that the message was emitted, usually __LINE__
  * @message: the actual message
- * @object: the object this message relates to or NULL if none
+ * @object: (transfer none) (allow-none): the object this message relates to,
+ *     or NULL if none
  * @unused: an unused variable, reserved for some user_data.
  *
  * The default logging handler used by GStreamer. Logging functions get called
  * whenever a macro like GST_DEBUG or similar is used. This function outputs the
- * message and additional info using the glib error handler.
+ * message and additional info to stderr (or the log file specified via the
+ * GST_DEBUG_FILE environment variable).
+ *
  * You can add other handlers by using gst_debug_add_log_function().
  * And you can remove this handler by calling
  * gst_debug_remove_log_function(gst_debug_log_default);
@@ -866,7 +924,6 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
   gint pid;
   GstClockTime elapsed;
   gchar *obj = NULL;
-  gboolean free_obj = TRUE;
   gboolean is_colored;
 
   if (level > gst_debug_category_get_threshold (category))
@@ -875,21 +932,20 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
   pid = getpid ();
   is_colored = gst_debug_is_colored ();
 
-  elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
-      gst_util_get_timestamp ());
-
   if (object) {
     obj = gst_debug_print_object (object);
   } else {
-    obj = "\0";
-    free_obj = FALSE;
+    obj = g_strdup ("");
   }
 
+  elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
+      gst_util_get_timestamp ());
+
   if (is_colored) {
 #ifndef G_OS_WIN32
     /* colors, non-windows */
     gchar *color = NULL;
-    gchar *clear;
+    const gchar *clear;
     gchar pidcolor[10];
     const gchar *levelcolor;
 
@@ -900,11 +956,12 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
     levelcolor = levelcolormap[level];
 
 #define PRINT_FMT " %s"PID_FMT"%s "PTR_FMT" %s%s%s %s"CAT_FMT"%s %s\n"
-    g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
+    fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
         pidcolor, pid, clear, g_thread_self (), levelcolor,
         gst_debug_level_get_name (level), clear, color,
         gst_debug_category_get_name (category), file, line, function, obj,
         clear, gst_debug_message_get (message));
+    fflush (log_file);
 #undef PRINT_FMT
     g_free (color);
 #else
@@ -913,42 +970,50 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
      * thing. */
     static GStaticMutex win_print_mutex = G_STATIC_MUTEX_INIT;
     const gint clear = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
-#define SET_COLOR(c) \
-  SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c));
+#define SET_COLOR(c) G_STMT_START { \
+  if (log_file == stderr) \
+    SetConsoleTextAttribute (GetStdHandle (STD_ERROR_HANDLE), (c)); \
+  } G_STMT_END
     g_static_mutex_lock (&win_print_mutex);
     /* timestamp */
-    g_printerr ("%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
+    fprintf (log_file, "%" GST_TIME_FORMAT " ", GST_TIME_ARGS (elapsed));
+    fflush (log_file);
     /* pid */
     SET_COLOR (available_colors[pid % G_N_ELEMENTS (available_colors)]);
-    g_printerr (PID_FMT, pid);
+    fprintf (log_file, PID_FMT, pid);
+    fflush (log_file);
     /* thread */
     SET_COLOR (clear);
-    g_printerr (" " PTR_FMT " ", g_thread_self ());
+    fprintf (log_file, " " PTR_FMT " ", g_thread_self ());
+    fflush (log_file);
     /* level */
     SET_COLOR (levelcolormap[level]);
-    g_printerr ("%s ", gst_debug_level_get_name (level));
+    fprintf (log_file, "%s ", gst_debug_level_get_name (level));
+    fflush (log_file);
     /* category */
     SET_COLOR (gst_debug_construct_win_color (gst_debug_category_get_color
             (category)));
-    g_printerr (CAT_FMT, gst_debug_category_get_name (category),
+    fprintf (log_file, CAT_FMT, gst_debug_category_get_name (category),
         file, line, function, obj);
+    fflush (log_file);
     /* message */
     SET_COLOR (clear);
-    g_printerr (" %s\n", gst_debug_message_get (message));
+    fprintf (log_file, " %s\n", gst_debug_message_get (message));
+    fflush (log_file);
     g_static_mutex_unlock (&win_print_mutex);
 #endif
   } else {
     /* no color, all platforms */
 #define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n"
-    g_printerr ("%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed), pid,
-        g_thread_self (), gst_debug_level_get_name (level),
+    fprintf (log_file, "%" GST_TIME_FORMAT PRINT_FMT, GST_TIME_ARGS (elapsed),
+        pid, g_thread_self (), gst_debug_level_get_name (level),
         gst_debug_category_get_name (category), file, line, function, obj,
         gst_debug_message_get (message));
+    fflush (log_file);
 #undef PRINT_FMT
   }
 
-  if (free_obj)
-    g_free (obj);
+  g_free (obj);
 }
 
 /**
@@ -977,6 +1042,8 @@ gst_debug_level_get_name (GstDebugLevel level)
       return "LOG    ";
     case GST_LEVEL_FIXME:
       return "FIXME  ";
+    case GST_LEVEL_TRACE:
+      return "TRACE  ";
     case GST_LEVEL_MEMDUMP:
       return "MEMDUMP";
     default:
@@ -988,10 +1055,10 @@ gst_debug_level_get_name (GstDebugLevel level)
 /**
  * gst_debug_add_log_function:
  * @func: the function to use
- * @data: user data
+ * @data: (closure): user data
  *
  * Adds the logging function to the list of logging functions.
- * Be sure to use G_GNUC_NO_INSTRUMENT on that function, it is needed.
+ * Be sure to use #G_GNUC_NO_INSTRUMENT on that function, it is needed.
  */
 void
 gst_debug_add_log_function (GstLogFunction func, gpointer data)
@@ -999,9 +1066,10 @@ gst_debug_add_log_function (GstLogFunction func, gpointer data)
   LogFuncEntry *entry;
   GSList *list;
 
-  g_return_if_fail (func != NULL);
+  if (func == NULL)
+    func = gst_debug_log_default;
 
-  entry = g_new (LogFuncEntry, 1);
+  entry = g_slice_new (LogFuncEntry);
   entry->func = func;
   entry->user_data = data;
   /* FIXME: we leak the old list here - other threads might access it right now
@@ -1051,7 +1119,7 @@ gst_debug_remove_with_compare_func (GCompareFunc func, gpointer data)
       new = g_slist_copy (new);
       continue;
     }
-    g_free (found->data);
+    g_slice_free (LogFuncEntry, found->data);
     new = g_slist_delete_link (new, found);
     removals++;
   }
@@ -1075,7 +1143,8 @@ gst_debug_remove_log_function (GstLogFunction func)
 {
   guint removals;
 
-  g_return_val_if_fail (func != NULL, 0);
+  if (func == NULL)
+    func = gst_debug_log_default;
 
   removals =
       gst_debug_remove_with_compare_func
@@ -1114,11 +1183,13 @@ gst_debug_remove_log_function_by_data (gpointer data)
  * @colored: Whether to use colored output or not
  *
  * Sets or unsets the use of coloured debugging output.
+ *
+ * This function may be called before gst_init().
  */
 void
 gst_debug_set_colored (gboolean colored)
 {
-  g_atomic_int_set (&__use_color, colored ? 1 : 0);
+  g_atomic_int_set (&__use_color, (gint) colored);
 }
 
 /**
@@ -1131,7 +1202,7 @@ gst_debug_set_colored (gboolean colored)
 gboolean
 gst_debug_is_colored (void)
 {
-  return g_atomic_int_get (&__use_color) == 0 ? FALSE : TRUE;
+  return (gboolean) g_atomic_int_get (&__use_color);
 }
 
 /**
@@ -1173,6 +1244,8 @@ gst_debug_is_active (void)
  *
  * Sets the default threshold to the given level and updates all categories to
  * use this threshold.
+ *
+ * This function may be called before gst_init().
  */
 void
 gst_debug_set_default_threshold (GstDebugLevel level)
@@ -1257,7 +1330,7 @@ gst_debug_set_threshold_for_name (const gchar * name, GstDebugLevel level)
   g_return_if_fail (name != NULL);
 
   pat = g_pattern_spec_new (name);
-  entry = g_new (LevelNameEntry, 1);
+  entry = g_slice_new (LevelNameEntry);
   entry->pat = pat;
   entry->level = level;
   g_static_mutex_lock (&__level_name_mutex);
@@ -1292,7 +1365,7 @@ gst_debug_unset_threshold_for_name (const gchar * name)
     if (g_pattern_spec_equal (entry->pat, pat)) {
       __level_name = g_slist_remove_link (__level_name, walk);
       g_pattern_spec_free (entry->pat);
-      g_free (entry);
+      g_slice_free (LevelNameEntry, entry);
       g_slist_free_1 (walk);
       walk = __level_name;
     }
@@ -1310,7 +1383,7 @@ _gst_debug_category_new (const gchar * name, guint color,
 
   g_return_val_if_fail (name != NULL, NULL);
 
-  cat = g_new (GstDebugCategory, 1);
+  cat = g_slice_new (GstDebugCategory);
   cat->name = g_strdup (name);
   cat->color = color;
   if (description != NULL) {
@@ -1348,7 +1421,7 @@ gst_debug_category_free (GstDebugCategory * category)
 
   g_free ((gpointer) category->name);
   g_free ((gpointer) category->description);
-  g_free (category);
+  g_slice_free (GstDebugCategory, category);
 }
 
 /**
@@ -1459,7 +1532,8 @@ gst_debug_category_get_description (GstDebugCategory * category)
  * may change anytime.
  * The caller has to free the list after use.
  *
- * Returns: the list of categories
+ * Returns: (transfer container) (element-type Gst.DebugCategory): the list of
+ *     debug categories
  */
 GSList *
 gst_debug_get_all_categories (void)
@@ -1493,12 +1567,9 @@ _gst_debug_get_category (const gchar * name)
 static GHashTable *__gst_function_pointers;     /* NULL */
 static GStaticMutex __dbg_functions_mutex = G_STATIC_MUTEX_INIT;
 
-const gchar *
-_gst_debug_nameof_funcptr (GstDebugFuncPtr ptr)
-    G_GNUC_NO_INSTRUMENT;
-
 /* This function MUST NOT return NULL */
-     const gchar *_gst_debug_nameof_funcptr (GstDebugFuncPtr func)
+const gchar *
+_gst_debug_nameof_funcptr (GstDebugFuncPtr func)
 {
   gchar *ptrname;
 
@@ -1592,7 +1663,7 @@ _gst_info_printf_extension_segment (FILE * stream,
   return len;
 }
 
-#if HAVE_REGISTER_PRINTF_SPECIFIER
+#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
 static int
 _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
     int *argtypes, int *size)
@@ -1604,7 +1675,7 @@ _gst_info_printf_extension_arginfo (const struct printf_info *info, size_t n,
 {
   if (n > 0) {
     argtypes[0] = PA_POINTER;
-#if HAVE_REGISTER_PRINTF_SPECIFIER
+#ifdef HAVE_REGISTER_PRINTF_SPECIFIER
     *size = sizeof (gpointer);
 #endif
   }
@@ -1679,13 +1750,13 @@ _gst_debug_category_new (const gchar * name, guint color,
 }
 
 void
-_gst_debug_register_funcptr (gpointer func, const gchar * ptrname)
+_gst_debug_register_funcptr (GstDebugFuncPtr func, const gchar * ptrname)
 {
 }
 
 /* This function MUST NOT return NULL */
 const gchar *
-_gst_debug_nameof_funcptr (gpointer func)
+_gst_debug_nameof_funcptr (GstDebugFuncPtr func)
 {
   return "(NULL)";
 }
@@ -1717,7 +1788,7 @@ gst_debug_log_default (GstDebugCategory * category, GstDebugLevel level,
 {
 }
 
-G_CONST_RETURN gchar *
+const gchar *
 gst_debug_level_get_name (GstDebugLevel level)
 {
   return "NONE";
@@ -1805,7 +1876,7 @@ gst_debug_category_get_threshold (GstDebugCategory * category)
   return GST_LEVEL_NONE;
 }
 
-G_CONST_RETURN gchar *
+const gchar *
 gst_debug_category_get_name (GstDebugCategory * category)
 {
   return "";
@@ -1817,7 +1888,7 @@ gst_debug_category_get_color (GstDebugCategory * category)
   return 0;
 }
 
-G_CONST_RETURN gchar *
+const gchar *
 gst_debug_category_get_description (GstDebugCategory * category)
 {
   return "";