/* our own printf implementation with custom extensions to %p for caps etc. */
#include "printf/printf.h"
+#include "printf/printf-extension.h"
+
+static char *gst_info_printf_pointer_extension_func (const char *format,
+ void *ptr);
#endif /* !GST_DISABLE_GST_DEBUG */
static void gst_debug_reset_threshold (gpointer category, gpointer unused);
static void gst_debug_reset_all_thresholds (void);
-#if 0
-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);
-#endif
-
struct _GstDebugMessage
{
gchar *message;
/* get time we started for debugging messages */
_priv_gst_info_start_time = gst_util_get_timestamp ();
-#if 0
- register_printf_specifier (GST_PTR_FORMAT[0], _gst_info_printf_extension_ptr,
- NULL);
- register_printf_specifier (GST_SEGMENT_FORMAT[0],
- _gst_info_printf_extension_segment, NULL);
-#endif
+ __gst_printf_pointer_extension_set_func
+ (gst_info_printf_pointer_extension_func);
/* do NOT use a single debug function before this line has been run */
GST_CAT_DEFAULT = _gst_debug_category_new ("default",
return g_strdup_printf ("%p", ptr);
}
-#if 0
static gchar *
gst_debug_print_segment (gpointer ptr)
{
}
}
}
-#endif
+
+static char *
+gst_info_printf_pointer_extension_func (const char *format, void *ptr)
+{
+ char *s = NULL;
+
+ if (format[0] == 'p' && format[1] == '\a') {
+ switch (format[2]) {
+ case 'A': /* GST_PTR_FORMAT */
+ s = gst_debug_print_object (ptr);
+ break;
+ case 'B': /* GST_SEGMENT_FORMAT */
+ s = gst_debug_print_segment (ptr);
+ break;
+ default:
+ /* must have been compiled against a newer version with an extension
+ * we don't known about yet - just ignore and fallback to %p below */
+ break;
+ }
+ }
+ if (s == NULL)
+ s = g_strdup_printf ("%p", ptr);
+
+ return s;
+}
/**
* gst_debug_construct_term_color:
g_mutex_unlock (&__dbg_functions_mutex);
}
-/*** PRINTF EXTENSIONS ********************************************************/
-
-#if 0
-static int
-_gst_info_printf_extension_ptr (FILE * stream, const struct printf_info *info,
- const void *const *args)
-{
- char *buffer;
- int len;
- void *ptr;
-
- buffer = NULL;
- ptr = *(void **) args[0];
-
- buffer = gst_debug_print_object (ptr);
- len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
- buffer);
-
- g_free (buffer);
- return len;
-}
-
-static int
-_gst_info_printf_extension_segment (FILE * stream,
- const struct printf_info *info, const void *const *args)
-{
- char *buffer;
- int len;
- void *ptr;
-
- buffer = NULL;
- ptr = *(void **) args[0];
-
- buffer = gst_debug_print_segment (ptr);
- len = fprintf (stream, "%*s", (info->left ? -info->width : info->width),
- buffer);
-
- g_free (buffer);
- return len;
-}
-#endif
-
static void
gst_info_dump_mem_line (gchar * linebuf, gsize linebuf_size,
const guint8 * mem, gsize mem_offset, gsize mem_size)
* printf format type used to debug GStreamer types.
* This can only be used on types whose size is >= sizeof(gpointer).
*/
-#define GST_PTR_FORMAT "p" /* FIXME: add suffix for differentiation */
+#define GST_PTR_FORMAT "p\aA"
/**
* GST_SEGMENT_FORMAT:
* printf format type used to debug GStreamer segments.
* This can only be used on pointers to GstSegment structures.
*/
-#define GST_SEGMENT_FORMAT "p" /* FIXME: add suffix for differentiation */
+#define GST_SEGMENT_FORMAT "p\aB"
typedef struct _GstDebugMessage GstDebugMessage;
vasnprintf.h \
printf.c \
printf.h \
+ printf-extension.c \
+ printf-extension.h \
gst-printf.h
EXTRA_DIST = README
been changed to #undef HAVE_SNPRINTF, and HAVE_ALLOCA has been changed to
GLIB_HAVE_ALLOCA_H
-We will also add support for our custom printf format specifiers.
+printf-extension.[ch] were added to provide support for custom pointer
+arguments (e.g. caps, events, etc.)
Files have also been indented with gst-indent, so this is basically a
permanent fork and any patches will have to be merged manually.
--- /dev/null
+/* GStreamer printf extension hooks
+ * Copyright (C) 2013 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "printf-extension.h"
+#include "gst-printf.h"
+#include <stdio.h>
+#include <string.h>
+
+static PrintfPointerExtensionFunc ptr_ext_func; /* NULL */
+
+void
+__gst_printf_pointer_extension_set_func (PrintfPointerExtensionFunc func)
+{
+ /* since this is internal, we don't need to worry about thread-safety */
+ ptr_ext_func = func;
+}
+
+char *
+__gst_printf_pointer_extension_serialize (const char *format, void *ptr)
+{
+ char *buf;
+
+ if (ptr_ext_func == NULL) {
+ buf = malloc (32);
+ memset (buf, 0, 32);
+ sprintf (buf, "%p", ptr);
+ } else {
+ /* note: we map malloc/free to g_malloc/g_free in gst-printf.h, so the
+ * fact that gstinfo gives us a glib-allocated string and the printf
+ * routines free it with free() and not g_free() should not be a problem */
+ buf = ptr_ext_func (format, ptr);
+ }
+ return buf;
+}
--- /dev/null
+/* GStreamer printf extension hooks
+ * Copyright (C) 2013 Tim-Philipp Müller <tim centricular net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __GST_PRINTF_EXTENSION_H_INCLUDED__
+#define __GST_PRINTF_EXTENSION_H_INCLUDED__
+
+typedef char * (*PrintfPointerExtensionFunc) (const char * format, void * ptr);
+
+/* we only need one global function, since it's only GstInfo registering extensions */
+void __gst_printf_pointer_extension_set_func (PrintfPointerExtensionFunc func);
+
+/* functions for internal printf implementation to handle the extensions */
+char * __gst_printf_pointer_extension_serialize (const char * format, void * ptr);
+
+#endif /* __GST_PRINTF_EXTENSION_H_INCLUDED__ */