From 34ec5b80d45fd8573639b040595eb02220f0fdce Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Mon, 3 Aug 2009 17:37:58 +0100 Subject: [debug] Add a debugging insfrastructure. Steal the GTK+/Clutter way of doing debug categories and messages. The CLUTTER_GST_DEBUG environment variable can contain a comma separated list of categories. Debugging messages with then be printed if the library has been compiled with this feature enabled. Note that this feature is always built-in by default, --disable-debug will disable it tough. --- clutter-gst/Makefile.am | 45 ++++++++++------ clutter-gst/clutter-gst-debug.c | 81 ++++++++++++++++++++++++++++ clutter-gst/clutter-gst-debug.h | 116 ++++++++++++++++++++++++++++++++++++++++ clutter-gst/clutter-gst-util.c | 11 ++++ 4 files changed, 237 insertions(+), 16 deletions(-) create mode 100644 clutter-gst/clutter-gst-debug.c create mode 100644 clutter-gst/clutter-gst-debug.h (limited to 'clutter-gst') diff --git a/clutter-gst/Makefile.am b/clutter-gst/Makefile.am index f4b843d..0074d8e 100644 --- a/clutter-gst/Makefile.am +++ b/clutter-gst/Makefile.am @@ -1,34 +1,47 @@ +NULL = # SUBDIRS = shaders source_h = \ - $(srcdir)/clutter-gst-video-texture.h \ - $(srcdir)/clutter-gst-video-sink.h \ $(srcdir)/clutter-gst-audio.h \ $(srcdir)/clutter-gst-util.h \ - $(srcdir)/clutter-gst-version.h + $(srcdir)/clutter-gst-version.h \ + $(srcdir)/clutter-gst-video-sink.h \ + $(srcdir)/clutter-gst-video-texture.h \ + $(NULL) -source_priv_h = $(srcdir)/clutter-gst-shaders.h +source_priv_h = \ + $(srcdir)/clutter-gst-debug.h \ + $(srcdir)/clutter-gst-shaders.h \ + $(NULL) -source_c = clutter-gst-video-texture.c \ - clutter-gst-video-sink.c \ - clutter-gst-audio.c \ - clutter-gst-util.c +source_c = \ + clutter-gst-audio.c \ + clutter-gst-debug.c \ + clutter-gst-video-sink.c \ + clutter-gst-video-texture.c \ + clutter-gst-util.c \ + $(NULL) libclutter_gst_@CLUTTER_GST_MAJORMINOR@_la_SOURCES = $(MARSHALFILES) \ $(source_c) \ $(source_priv_h) \ $(source_h) -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_builddir)/clutter-gst/shaders \ - -I$(top_srcdir)/clutter-gst/shaders \ - -DG_LOG_DOMAIN=\"Clutter-Gst\" \ - $(MAINTAINER_CFLAGS) \ - @CLUTTER_GST_CFLAGS@ \ - $(GST_CFLAGS) +INCLUDES = \ + -I$(top_srcdir) \ + -I$(top_builddir)/clutter-gst/shaders \ + -I$(top_srcdir)/clutter-gst/shaders \ + $(NULL) + +AM_CFLAGS = \ + -DG_LOG_DOMAIN=\"Clutter-Gst\" \ + $(MAINTAINER_CFLAGS) \ + $(CLUTTER_GST_DEBUG_CFLAGS) \ + $(CLUTTER_GST_CFLAGS) \ + $(GST_CFLAGS) \ + $(NULL) lib_LTLIBRARIES = libclutter-gst-@CLUTTER_GST_MAJORMINOR@.la diff --git a/clutter-gst/clutter-gst-debug.c b/clutter-gst/clutter-gst-debug.c new file mode 100644 index 0000000..4179f70 --- /dev/null +++ b/clutter-gst/clutter-gst-debug.c @@ -0,0 +1,81 @@ +/* + * Clutter-GStreamer. + * + * GStreamer integration library for Clutter. + * + * clutter-gst-debug.c - Some debug related functions, private to the library. + * + * Authored By Damien Lespiau + * + * Copyright (C) 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include "clutter-gst-debug.h" + +#ifdef CLUTTER_GST_ENABLE_DEBUG + +guint clutter_gst_debug_flags = 0; /* global clutter-gst debug flag */ + +static GTimer *clutter_gst_timer; + +static const GDebugKey clutter_gst_debug_keys[] = { + { "misc", CLUTTER_GST_DEBUG_MISC }, +}; + +/** + * clutter_gst_get_timestamp: + * + * Returns the approximate number of microseconds passed since Clutter-Gst was + * intialized. + * + * Return value: Number of microseconds since clutter_gst_init() was called. + */ +gulong +_clutter_gst_get_timestamp (void) +{ + gdouble seconds; + + seconds = g_timer_elapsed (clutter_gst_timer, NULL); + + return (gulong)(seconds / 1.0e-6); +} + +gboolean _clutter_gst_debug_init (void) +{ + const char *env_string; + + env_string = g_getenv ("CLUTTER_GST_DEBUG"); + + clutter_gst_timer = g_timer_new (); + g_timer_start (clutter_gst_timer); + + if (env_string == NULL) + return TRUE; + + clutter_gst_debug_flags = + g_parse_debug_string (env_string, + clutter_gst_debug_keys, + G_N_ELEMENTS (clutter_gst_debug_keys)); + + return TRUE; +} + +#endif /* CLUTTER_GST_ENABLE_DEBUG */ + diff --git a/clutter-gst/clutter-gst-debug.h b/clutter-gst/clutter-gst-debug.h new file mode 100644 index 0000000..d818906 --- /dev/null +++ b/clutter-gst/clutter-gst-debug.h @@ -0,0 +1,116 @@ +/* + * Clutter-GStreamer. + * + * GStreamer integration library for Clutter. + * + * clutter-gst-debug.h - Debugging (printf) functions + * + * Copyright (C) 2006-2008 OpenedHand + * Copyright (C) 2009 Intel Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __CLUTTER_GST_DEBUG_H__ +#define __CLUTTER_GST_DEBUG_H__ + +#include +#include "clutter-gst-util.h" + +G_BEGIN_DECLS + +#ifdef CLUTTER_GST_ENABLE_DEBUG + +typedef enum { + CLUTTER_GST_DEBUG_MISC = 1 << 0, +} ClutterDebugFlag; + +#ifdef __GNUC__ + +#define CLUTTER_GST_NOTE(type,x,a...) \ + G_STMT_START { \ + if (clutter_gst_debug_flags & CLUTTER_GST_DEBUG_##type) \ + { g_message ("[" #type "] " G_STRLOC ": " x, ##a); } \ + } G_STMT_END + +#define CLUTTER_GST_TIMESTAMP(type,x,a...) \ + G_STMT_START { \ + if (clutter_gst_debug_flags & CLUTTER_GST_DEBUG_##type) \ + { g_message ("[" #type "]" " %li:" G_STRLOC ": " \ + x, _clutter_gst_get_timestamp(), ##a); } \ + } G_STMT_END + +#else /* !__GNUC__ */ + +/* Try the C99 version; unfortunately, this does not allow us to pass + * empty arguments to the macro, which means we have to + * do an intemediate printf. + */ +#define CLUTTER_GST_NOTE(type,...) \ + G_STMT_START { \ + if (clutter_gst_debug_flags & CLUTTER_GST_DEBUG_##type) \ + { \ + gchar * _fmt = g_strdup_printf (__VA_ARGS__); \ + g_message ("[" #type "] " G_STRLOC ": %s",_fmt); \ + g_free (_fmt); \ + } \ + } G_STMT_END + +#define CLUTTER_GST_TIMESTAMP(type,...) \ +G_STMT_START { \ + if (clutter_gst_debug_flags & CLUTTER_GST_DEBUG_##type) \ + { \ + gchar * _fmt = g_strdup_printf (__VA_ARGS__); \ + g_message ("[" #type "]" " %li:" G_STRLOC ": %s", \ + _clutter_gst_get_timestamp(), _fmt); \ + g_free (_fmt); \ + } \ +} G_STMT_END + +#endif /* __GNUC__ */ + +#define CLUTTER_GST_MARK() CLUTTER_GST_NOTE(MISC, "== mark ==") + +#define CLUTTER_GST_GLERR() \ +G_STMT_START { \ + if (clutter_gst_debug_flags & CLUTTER_GST_DEBUG_GL) \ + { GLenum _err = glGetError (); /* roundtrip */ \ + if (_err != GL_NO_ERROR) \ + g_warning (G_STRLOC ": GL Error %x", _err); \ + } \ +} G_STMT_END + +/* We do not even define those (private) symbols when debug is disabled. + * This is to ensure the debug code is not shiped with the library when + * disabled */ + +extern guint clutter_gst_debug_flags; + +gulong _clutter_gst_get_timestamp (void); +gboolean _clutter_gst_debug_init (void); + +#else /* !CLUTTER_GST_ENABLE_DEBUG */ + +#define CLUTTER_GST_NOTE(type,...) G_STMT_START { } G_STMT_END +#define CLUTTER_GST_MARK() G_STMT_START { } G_STMT_END +#define CLUTTER_GST_GLERR() G_STMT_START { } G_STMT_END +#define CLUTTER_GST_TIMESTAMP(type,...) G_STMT_START { } G_STMT_END + +#endif /* CLUTTER_GST_ENABLE_DEBUG */ + +G_END_DECLS + +#endif /* __CLUTTER_GST_DEBUG_H__ */ diff --git a/clutter-gst/clutter-gst-util.c b/clutter-gst/clutter-gst-util.c index bead296..855ee37 100644 --- a/clutter-gst/clutter-gst-util.c +++ b/clutter-gst/clutter-gst-util.c @@ -97,6 +97,7 @@ #include #include +#include "clutter-gst-debug.h" #include "clutter-gst-util.h" static gboolean clutter_gst_is_initialized = FALSE; @@ -126,6 +127,11 @@ clutter_gst_init (int *argc, gst_init (argc, argv); retval = clutter_init (argc, argv); + /* initialize debugging infrastructure */ +#ifdef CLUTTER_GST_ENABLE_DEBUG + _clutter_gst_debug_init(); +#endif + clutter_gst_is_initialized = TRUE; return retval; @@ -186,6 +192,11 @@ clutter_gst_init_with_args (int *argc, if (!res) return CLUTTER_INIT_ERROR_INTERNAL; + /* initialize debugging infrastructure */ +#ifdef CLUTTER_GST_ENABLE_DEBUG + _clutter_gst_debug_init (); +#endif + clutter_gst_is_initialized = TRUE; return CLUTTER_INIT_SUCCESS; -- cgit v1.2.1