diff --git a/gst/Makefile.am b/gst/Makefile.am index f45e413b03..dda710f133 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -117,6 +117,7 @@ libgstreamer_@GST_API_VERSION@_la_SOURCES = \ $(GST_TRACE_SRC) \ gsttracer.c \ gsttracerfactory.c \ + gsttracerutils.c \ gsttypefind.c \ gsttypefindfactory.c \ gsturi.c \ @@ -222,6 +223,7 @@ gst_headers = \ gsttocsetter.h \ gsttracer.h \ gsttracerfactory.h \ + gsttracerutils.h \ gsttypefind.h \ gsttypefindfactory.h \ gsturi.h \ diff --git a/gst/gst.h b/gst/gst.h index c9ffed55b8..a9c7dc4b76 100644 --- a/gst/gst.h +++ b/gst/gst.h @@ -77,7 +77,6 @@ #include #include #include -#include #include #include #include diff --git a/gst/gst_private.h b/gst/gst_private.h index 39e2245875..384dc7b437 100644 --- a/gst/gst_private.h +++ b/gst/gst_private.h @@ -62,6 +62,8 @@ extern const char g_log_domain_gstreamer[]; #include "gstdatetime.h" +#include "gsttracerutils.h" + G_BEGIN_DECLS /* used by gstparse.c and grammar.y */ diff --git a/gst/gstelement.c b/gst/gstelement.c index ae43812946..2a783371ad 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -90,7 +90,7 @@ #include "gstutils.h" #include "gstinfo.h" #include "gstquark.h" -#include "gsttracer.h" +#include "gsttracerutils.h" #include "gstvalue.h" #include "gst-i18n-lib.h" #include "glib-compat-private.h" diff --git a/gst/gstpad.c b/gst/gstpad.c index c31f4961b0..0a56c6baec 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -94,7 +94,7 @@ #include "gstutils.h" #include "gstinfo.h" #include "gsterror.h" -#include "gsttracer.h" +#include "gsttracerutils.h" #include "gstvalue.h" #include "glib-compat-private.h" diff --git a/gst/gstregistrychunks.c b/gst/gstregistrychunks.c index c88152d12a..7712fcf60e 100644 --- a/gst/gstregistrychunks.c +++ b/gst/gstregistrychunks.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include diff --git a/gst/gsttracer.c b/gst/gsttracer.c index 065ca3abbb..42ec2b66c7 100644 --- a/gst/gsttracer.c +++ b/gst/gsttracer.c @@ -1,7 +1,7 @@ /* GStreamer * Copyright (C) 2013 Stefan Sauer * - * gsttracer.h: tracing subsystem + * gsttracer.c: tracer base class * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,28 +21,20 @@ /** * SECTION:gsttracer - * @short_description: Tracing subsystem - * - * The tracing subsystem provides hooks in the core library and API for modules - * to attach to them. + * @short_description: Tracing base class * * Tracing modules will subclass #GstTracer and register through * gst_tracer_register(). Modules can attach to various hook-types - see * #GstTracerHook. When invoked they receive hook specific contextual data, * which they must not modify. - * - * The user can activate tracers by setting the environment variable GST_TRACE - * to a ';' separated list of tracers. */ +#define GST_USE_UNSTABLE_API + #include "gst_private.h" #include "gstenumtypes.h" -#include "gstregistry.h" #include "gsttracer.h" #include "gsttracerfactory.h" -#include "gstutils.h" - -#ifndef GST_DISABLE_GST_DEBUG GST_DEBUG_CATEGORY_EXTERN (tracer_debug); #define GST_CAT_DEFAULT tracer_debug @@ -138,7 +130,7 @@ gst_tracer_get_property (GObject * object, guint prop_id, } } -static void +void gst_tracer_invoke (GstTracer * self, GstTracerHookId hid, GstTracerMessageId mid, va_list var_args) { @@ -206,115 +198,6 @@ gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type) return TRUE; } -/* tracing helpers */ - -gboolean _priv_tracer_enabled = FALSE; -/* TODO(ensonic): use GPtrArray ? */ -GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, }; - -/* Initialize the debugging system */ -void -_priv_gst_tracer_init (void) -{ - const gchar *env = g_getenv ("GST_TRACE"); - - if (env != NULL && *env != '\0') { - GstRegistry *registry = gst_registry_get (); - GstPluginFeature *feature; - GstTracerFactory *factory; - GstTracerHook mask; - GstTracer *tracer; - gchar **t = g_strsplit_set (env, ";", 0); - gint i = 0, j; - gchar *params; - - GST_INFO ("enabling tracers: '%s'", env); - - while (t[i]) { - // check t[i] for params - if ((params = strchr (t[i], '('))) { - gchar *end = strchr (¶ms[1], ')'); - *params = '\0'; - params++; - if (end) - *end = '\0'; - } else { - params = NULL; - } - - GST_INFO ("checking tracer: '%s'", t[i]); - - if ((feature = gst_registry_lookup_feature (registry, t[i]))) { - factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature)); - if (factory) { - GST_INFO_OBJECT (factory, "creating tracer: type-id=%u", - (guint) factory->type); - - tracer = g_object_new (factory->type, "params", params, NULL); - g_object_get (tracer, "mask", &mask, NULL); - - if (mask) { - /* add to lists according to mask */ - j = 0; - while (mask && (j < GST_TRACER_HOOK_ID_LAST)) { - if (mask & 1) { - _priv_tracers[j] = g_list_prepend (_priv_tracers[j], - gst_object_ref (tracer)); - GST_WARNING_OBJECT (tracer, "added tracer to hook %d", j); - } - mask >>= 1; - j++; - } - - _priv_tracer_enabled = TRUE; - } else { - GST_WARNING_OBJECT (tracer, - "tracer with zero mask won't have any effect"); - } - gst_object_unref (tracer); - } else { - GST_WARNING_OBJECT (feature, - "loading plugin containing feature %s failed!", t[i]); - } - } else { - GST_WARNING ("no tracer named '%s'", t[i]); - } - i++; - } - g_strfreev (t); - } -} - -void -_priv_gst_tracer_deinit (void) -{ - gint i; - GList *node; - - /* shutdown tracers for final reports */ - for (i = 0; i < GST_TRACER_HOOK_ID_LAST; i++) { - for (node = _priv_tracers[i]; node; node = g_list_next (node)) { - gst_object_unref (node->data); - } - g_list_free (_priv_tracers[i]); - _priv_tracers[i] = NULL; - } - _priv_tracer_enabled = FALSE; -} - -void -gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...) -{ - va_list var_args; - GList *node; - - for (node = _priv_tracers[hid]; node; node = g_list_next (node)) { - va_start (var_args, mid); - gst_tracer_invoke (node->data, hid, mid, var_args); - va_end (var_args); - } -} - /* tracing module helpers */ void @@ -328,5 +211,3 @@ gst_tracer_log_trace (GstStructure * s) g_free (data); gst_structure_free (s); } - -#endif /* GST_DISABLE_GST_DEBUG */ diff --git a/gst/gsttracer.h b/gst/gsttracer.h index 99f1982deb..02e2ec0a1a 100644 --- a/gst/gsttracer.h +++ b/gst/gsttracer.h @@ -1,7 +1,7 @@ /* GStreamer * Copyright (C) 2013 Stefan Sauer * - * gsttracer.h: tracing subsystem + * gsttracer.h: tracer base class * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,63 +22,18 @@ #ifndef __GST_TRACER_H__ #define __GST_TRACER_H__ +#ifndef GST_USE_UNSTABLE_API +#warning "The tracer subsystem is unstable API and may change in future." +#warning "You can define GST_USE_UNSTABLE_API to avoid this warning." +#endif + #include #include #include -#include +#include G_BEGIN_DECLS -#ifndef GST_DISABLE_GST_DEBUG - -/* hook flags and ids */ - -typedef enum -{ - GST_TRACER_HOOK_NONE = 0, - GST_TRACER_HOOK_BUFFERS = (1 << 0), - GST_TRACER_HOOK_EVENTS = (1 << 1), - GST_TRACER_HOOK_MESSAGES = (1 << 2), - GST_TRACER_HOOK_QUERIES = (1 << 3), - GST_TRACER_HOOK_TOPOLOGY = (1 << 4), - /* - GST_TRACER_HOOK_TIMER - */ - GST_TRACER_HOOK_ALL = (1 << 5) - 1 -} GstTracerHook; - -typedef enum -{ - GST_TRACER_HOOK_ID_BUFFERS = 0, - GST_TRACER_HOOK_ID_EVENTS, - GST_TRACER_HOOK_ID_MESSAGES, - GST_TRACER_HOOK_ID_QUERIES, - GST_TRACER_HOOK_ID_TOPLOGY, - /* - GST_TRACER_HOOK_ID_TIMER - */ - GST_TRACER_HOOK_ID_LAST -} GstTracerHookId; - -typedef enum -{ - GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE = 0, - GST_TRACER_MESSAGE_ID_PAD_PUSH_POST, - GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE, - GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST, - GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_PRE, - GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_POST, - GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_PRE, - GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_POST, - GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_PRE, - GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_POST, - GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_PRE, - GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_POST, - GST_TRACER_MESSAGE_ID_LAST -} GstTracerMessageId; - -/* tracing plugins */ - typedef struct _GstTracer GstTracer; typedef struct _GstTracerPrivate GstTracerPrivate; typedef struct _GstTracerClass GstTracerClass; @@ -111,150 +66,11 @@ struct _GstTracerClass { gpointer _gst_reserved[GST_PADDING]; }; +void gst_tracer_invoke (GstTracer * self, GstTracerHookId hid, + GstTracerMessageId mid, va_list var_args); + GType gst_tracer_get_type (void); -/* tracing hooks */ - -void _priv_gst_tracer_init (void); -void _priv_gst_tracer_deinit (void); - -/* tracing modules */ - -gboolean gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type); - -/* tracing helpers */ - -void gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...); - -/* tracing module helpers */ - -void gst_tracer_log_trace (GstStructure * s); - -extern gboolean _priv_tracer_enabled; -extern GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST]; - -extern GstClockTime _priv_gst_info_start_time; -#define GST_TRACER_IS_ENABLED(id) \ - (_priv_tracer_enabled && (_priv_tracers[id] != NULL)) - -#define GST_TRACER_TS \ - GST_CLOCK_DIFF (_priv_gst_info_start_time, gst_util_get_timestamp ()) - -/* tracing hooks */ - -#define GST_TRACER_PAD_PUSH_PRE(pad, buffer) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ - GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE, GST_TRACER_TS, \ - pad, buffer); \ - } \ -}G_STMT_END - -#define GST_TRACER_PAD_PUSH_POST(pad, res) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ - GST_TRACER_MESSAGE_ID_PAD_PUSH_POST, GST_TRACER_TS, \ - pad, res); \ - } \ -}G_STMT_END - -#define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ - GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE, GST_TRACER_TS, \ - pad, list); \ - } \ -}G_STMT_END - -#define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ - GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST, GST_TRACER_TS, \ - pad, res); \ - } \ -}G_STMT_END - -#define GST_TRACER_PAD_PULL_RANGE_PRE(pad, offset, size) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ - GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_PRE, GST_TRACER_TS, \ - pad, offset, size); \ - } \ -}G_STMT_END - -#define GST_TRACER_PAD_PULL_RANGE_POST(pad, buffer, res) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ - GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_POST, GST_TRACER_TS, \ - pad, buffer, res); \ - } \ -}G_STMT_END - -#define GST_TRACER_PAD_PUSH_EVENT_PRE(pad, event) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_EVENTS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_EVENTS, \ - GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_PRE, GST_TRACER_TS, \ - pad, event); \ - } \ -}G_STMT_END - -#define GST_TRACER_PAD_PUSH_EVENT_POST(pad, res) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_EVENTS)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_EVENTS, \ - GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_POST, GST_TRACER_TS, \ - pad, res); \ - } \ -}G_STMT_END - -#define GST_TRACER_ELEMENT_POST_MESSAGE_PRE(element, message) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_MESSAGES)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_MESSAGES, \ - GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_PRE, GST_TRACER_TS, \ - element, message); \ - } \ -}G_STMT_END - -#define GST_TRACER_ELEMENT_POST_MESSAGE_POST(element, res) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_MESSAGES)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_MESSAGES, \ - GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_POST, GST_TRACER_TS, \ - element, res); \ - } \ -}G_STMT_END - -#define GST_TRACER_ELEMENT_QUERY_PRE(element, query) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_QUERIES)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_QUERIES, \ - GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_PRE, GST_TRACER_TS, \ - element, query); \ - } \ -}G_STMT_END - -#define GST_TRACER_ELEMENT_QUERY_POST(element, res) G_STMT_START{ \ - if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_QUERIES)) { \ - gst_tracer_dispatch (GST_TRACER_HOOK_ID_QUERIES, \ - GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_POST, GST_TRACER_TS, \ - element, res); \ - } \ -}G_STMT_END - -#else /* !GST_DISABLE_GST_DEBUG */ - -#define GST_TRACER_PAD_PUSH_PRE(pad, buffer) -#define GST_TRACER_PAD_PUSH_POST(pad, res) -#define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) -#define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) -#define GST_TRACER_PAD_PULL_RANGE_PRE(pad, offset, size) -#define GST_TRACER_PAD_PULL_RANGE_POST(pad, buffer, res) -#define GST_TRACER_PAD_PUSH_EVENT_PRE(pad, event) -#define GST_TRACER_PAD_PUSH_EVENT_POST(pad, res) -#define GST_TRACER_ELEMENT_POST_MESSAGE_PRE(element, message) -#define GST_TRACER_ELEMENT_POST_MESSAGE_POST(element, res) -#define GST_TRACER_ELEMENT_QUERY_PRE(element, query) -#define GST_TRACER_ELEMENT_QUERY_POST(element, res) - -#endif /* GST_DISABLE_GST_DEBUG */ - G_END_DECLS #endif /* __GST_TRACER_H__ */ diff --git a/gst/gsttracerfactory.c b/gst/gsttracerfactory.c index 9cdbb86f13..ec7ba5387d 100644 --- a/gst/gsttracerfactory.c +++ b/gst/gsttracerfactory.c @@ -29,7 +29,6 @@ #include "gst_private.h" #include "gstinfo.h" -#include "gsttracer.h" #include "gsttracerfactory.h" #include "gstregistry.h" diff --git a/gst/gsttracerfactory.h b/gst/gsttracerfactory.h index 2bfe481b16..8e9370c397 100644 --- a/gst/gsttracerfactory.h +++ b/gst/gsttracerfactory.h @@ -25,7 +25,6 @@ #include #include #include -#include G_BEGIN_DECLS diff --git a/gst/gsttracerutils.c b/gst/gsttracerutils.c new file mode 100644 index 0000000000..ed83f82902 --- /dev/null +++ b/gst/gsttracerutils.c @@ -0,0 +1,151 @@ +/* GStreamer + * Copyright (C) 2013 Stefan Sauer + * + * gsttracerutils.c: tracing subsystem + * + * 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. + */ + +/** + * SECTION:gsttracerutils + * @short_description: Tracing subsystem + * + * The tracing subsystem provides hooks in the core library and API for modules + * to attach to them. + * + * The user can activate tracers by setting the environment variable GST_TRACE + * to a ';' separated list of tracers. + */ + +#define GST_USE_UNSTABLE_API + +#include "gst_private.h" +#include "gsttracer.h" +#include "gsttracerfactory.h" +#include "gsttracerutils.h" + +#ifndef GST_DISABLE_GST_DEBUG + +/* tracing helpers */ + +gboolean _priv_tracer_enabled = FALSE; +/* TODO(ensonic): use array of GPtrArray* ? */ +GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, }; + +/* Initialize the tracing system */ +void +_priv_gst_tracer_init (void) +{ + const gchar *env = g_getenv ("GST_TRACE"); + + if (env != NULL && *env != '\0') { + GstRegistry *registry = gst_registry_get (); + GstPluginFeature *feature; + GstTracerFactory *factory; + GstTracerHook mask; + GstObject *tracer; + gchar **t = g_strsplit_set (env, ";", 0); + gint i = 0, j; + gchar *params; + + GST_INFO ("enabling tracers: '%s'", env); + + while (t[i]) { + // check t[i] for params + if ((params = strchr (t[i], '('))) { + gchar *end = strchr (¶ms[1], ')'); + *params = '\0'; + params++; + if (end) + *end = '\0'; + } else { + params = NULL; + } + + GST_INFO ("checking tracer: '%s'", t[i]); + + if ((feature = gst_registry_lookup_feature (registry, t[i]))) { + factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature)); + if (factory) { + GST_INFO_OBJECT (factory, "creating tracer: type-id=%u", + (guint) factory->type); + + tracer = g_object_new (factory->type, "params", params, NULL); + g_object_get (tracer, "mask", &mask, NULL); + + if (mask) { + /* add to lists according to mask */ + j = 0; + while (mask && (j < GST_TRACER_HOOK_ID_LAST)) { + if (mask & 1) { + _priv_tracers[j] = g_list_prepend (_priv_tracers[j], + gst_object_ref (tracer)); + GST_WARNING_OBJECT (tracer, "added tracer to hook %d", j); + } + mask >>= 1; + j++; + } + + _priv_tracer_enabled = TRUE; + } else { + GST_WARNING_OBJECT (tracer, + "tracer with zero mask won't have any effect"); + } + gst_object_unref (tracer); + } else { + GST_WARNING_OBJECT (feature, + "loading plugin containing feature %s failed!", t[i]); + } + } else { + GST_WARNING ("no tracer named '%s'", t[i]); + } + i++; + } + g_strfreev (t); + } +} + +void +_priv_gst_tracer_deinit (void) +{ + gint i; + GList *node; + + /* shutdown tracers for final reports */ + for (i = 0; i < GST_TRACER_HOOK_ID_LAST; i++) { + for (node = _priv_tracers[i]; node; node = g_list_next (node)) { + gst_object_unref (node->data); + } + g_list_free (_priv_tracers[i]); + _priv_tracers[i] = NULL; + } + _priv_tracer_enabled = FALSE; +} + +void +gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...) +{ + va_list var_args; + GList *node; + + for (node = _priv_tracers[hid]; node; node = g_list_next (node)) { + va_start (var_args, mid); + gst_tracer_invoke (node->data, hid, mid, var_args); + va_end (var_args); + } +} + +#endif /* GST_DISABLE_GST_DEBUG */ diff --git a/gst/gsttracerutils.h b/gst/gsttracerutils.h new file mode 100644 index 0000000000..c3bd5f35a6 --- /dev/null +++ b/gst/gsttracerutils.h @@ -0,0 +1,225 @@ +/* GStreamer + * Copyright (C) 2013 Stefan Sauer + * + * gsttracerutils.h: tracing subsystem + * + * 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_TRACER_UTILS_H__ +#define __GST_TRACER_UTILS_H__ + +#include +#include +#include +#include + +G_BEGIN_DECLS + +#ifndef GST_DISABLE_GST_DEBUG + +/* hook flags and ids */ + +typedef enum +{ + GST_TRACER_HOOK_NONE = 0, + GST_TRACER_HOOK_BUFFERS = (1 << 0), + GST_TRACER_HOOK_EVENTS = (1 << 1), + GST_TRACER_HOOK_MESSAGES = (1 << 2), + GST_TRACER_HOOK_QUERIES = (1 << 3), + GST_TRACER_HOOK_TOPOLOGY = (1 << 4), + /* + GST_TRACER_HOOK_TIMER + */ + GST_TRACER_HOOK_ALL = (1 << 5) - 1 +} GstTracerHook; + +typedef enum +{ + GST_TRACER_HOOK_ID_BUFFERS = 0, + GST_TRACER_HOOK_ID_EVENTS, + GST_TRACER_HOOK_ID_MESSAGES, + GST_TRACER_HOOK_ID_QUERIES, + GST_TRACER_HOOK_ID_TOPLOGY, + /* + GST_TRACER_HOOK_ID_TIMER + */ + GST_TRACER_HOOK_ID_LAST +} GstTracerHookId; + +typedef enum +{ + GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE = 0, + GST_TRACER_MESSAGE_ID_PAD_PUSH_POST, + GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE, + GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST, + GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_PRE, + GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_POST, + GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_PRE, + GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_POST, + GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_PRE, + GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_POST, + GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_PRE, + GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_POST, + GST_TRACER_MESSAGE_ID_LAST +} GstTracerMessageId; + +/* tracing hooks */ + +void _priv_gst_tracer_init (void); +void _priv_gst_tracer_deinit (void); + +/* tracing modules */ + +gboolean gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type); + +/* tracing helpers */ + +void gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...); + +/* tracing module helpers */ + +void gst_tracer_log_trace (GstStructure * s); + +extern gboolean _priv_tracer_enabled; +extern GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST]; + +#define GST_TRACER_IS_ENABLED(id) \ + (_priv_tracer_enabled && (_priv_tracers[id] != NULL)) + +#define GST_TRACER_TS \ + GST_CLOCK_DIFF (_priv_gst_info_start_time, gst_util_get_timestamp ()) + +/* tracing hooks */ + +#define GST_TRACER_PAD_PUSH_PRE(pad, buffer) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ + GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE, GST_TRACER_TS, \ + pad, buffer); \ + } \ +}G_STMT_END + +#define GST_TRACER_PAD_PUSH_POST(pad, res) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ + GST_TRACER_MESSAGE_ID_PAD_PUSH_POST, GST_TRACER_TS, \ + pad, res); \ + } \ +}G_STMT_END + +#define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ + GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE, GST_TRACER_TS, \ + pad, list); \ + } \ +}G_STMT_END + +#define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ + GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST, GST_TRACER_TS, \ + pad, res); \ + } \ +}G_STMT_END + +#define GST_TRACER_PAD_PULL_RANGE_PRE(pad, offset, size) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ + GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_PRE, GST_TRACER_TS, \ + pad, offset, size); \ + } \ +}G_STMT_END + +#define GST_TRACER_PAD_PULL_RANGE_POST(pad, buffer, res) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \ + GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_POST, GST_TRACER_TS, \ + pad, buffer, res); \ + } \ +}G_STMT_END + +#define GST_TRACER_PAD_PUSH_EVENT_PRE(pad, event) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_EVENTS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_EVENTS, \ + GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_PRE, GST_TRACER_TS, \ + pad, event); \ + } \ +}G_STMT_END + +#define GST_TRACER_PAD_PUSH_EVENT_POST(pad, res) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_EVENTS)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_EVENTS, \ + GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_POST, GST_TRACER_TS, \ + pad, res); \ + } \ +}G_STMT_END + +#define GST_TRACER_ELEMENT_POST_MESSAGE_PRE(element, message) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_MESSAGES)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_MESSAGES, \ + GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_PRE, GST_TRACER_TS, \ + element, message); \ + } \ +}G_STMT_END + +#define GST_TRACER_ELEMENT_POST_MESSAGE_POST(element, res) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_MESSAGES)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_MESSAGES, \ + GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_POST, GST_TRACER_TS, \ + element, res); \ + } \ +}G_STMT_END + +#define GST_TRACER_ELEMENT_QUERY_PRE(element, query) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_QUERIES)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_QUERIES, \ + GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_PRE, GST_TRACER_TS, \ + element, query); \ + } \ +}G_STMT_END + +#define GST_TRACER_ELEMENT_QUERY_POST(element, res) G_STMT_START{ \ + if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_QUERIES)) { \ + gst_tracer_dispatch (GST_TRACER_HOOK_ID_QUERIES, \ + GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_POST, GST_TRACER_TS, \ + element, res); \ + } \ +}G_STMT_END + +#else /* !GST_DISABLE_GST_DEBUG */ + +#define GST_TRACER_PAD_PUSH_PRE(pad, buffer) +#define GST_TRACER_PAD_PUSH_POST(pad, res) +#define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) +#define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) +#define GST_TRACER_PAD_PULL_RANGE_PRE(pad, offset, size) +#define GST_TRACER_PAD_PULL_RANGE_POST(pad, buffer, res) +#define GST_TRACER_PAD_PUSH_EVENT_PRE(pad, event) +#define GST_TRACER_PAD_PUSH_EVENT_POST(pad, res) +#define GST_TRACER_ELEMENT_POST_MESSAGE_PRE(element, message) +#define GST_TRACER_ELEMENT_POST_MESSAGE_POST(element, res) +#define GST_TRACER_ELEMENT_QUERY_PRE(element, query) +#define GST_TRACER_ELEMENT_QUERY_POST(element, res) + +#endif /* GST_DISABLE_GST_DEBUG */ + +G_END_DECLS + +#endif /* __GST_TRACER_UTILS_H__ */ + diff --git a/plugins/tracers/Makefile.am b/plugins/tracers/Makefile.am index 87db74cac6..07c510a77f 100644 --- a/plugins/tracers/Makefile.am +++ b/plugins/tracers/Makefile.am @@ -15,7 +15,8 @@ libgstcoretracers_la_SOURCES = \ gststats.c \ gsttracers.c -libgstcoretracers_la_CFLAGS = $(GST_OBJ_CFLAGS) +libgstcoretracers_la_CFLAGS = $(GST_OBJ_CFLAGS) \ + -DGST_USE_UNSTABLE_API libgstcoretracers_la_LIBADD = \ $(top_builddir)/gst/printf/libgstprintf.la \ $(GST_OBJ_LIBS) diff --git a/plugins/tracers/gstlatency.h b/plugins/tracers/gstlatency.h index efcab6b6fd..e234303336 100644 --- a/plugins/tracers/gstlatency.h +++ b/plugins/tracers/gstlatency.h @@ -23,6 +23,7 @@ #define __GST_LATENCY_TRACER_H__ #include +#include G_BEGIN_DECLS diff --git a/plugins/tracers/gstlog.h b/plugins/tracers/gstlog.h index 827f2aaf21..6f0dd7fdc7 100644 --- a/plugins/tracers/gstlog.h +++ b/plugins/tracers/gstlog.h @@ -23,6 +23,7 @@ #define __GST_LOG_TRACER_H__ #include +#include G_BEGIN_DECLS diff --git a/plugins/tracers/gstrusage.h b/plugins/tracers/gstrusage.h index e73515df0f..b13fb85ffc 100644 --- a/plugins/tracers/gstrusage.h +++ b/plugins/tracers/gstrusage.h @@ -23,6 +23,7 @@ #define __GST_RUSAGE_TRACER_H__ #include +#include G_BEGIN_DECLS diff --git a/plugins/tracers/gststats.h b/plugins/tracers/gststats.h index 97ae176529..a5f2d67870 100644 --- a/plugins/tracers/gststats.h +++ b/plugins/tracers/gststats.h @@ -23,6 +23,7 @@ #define __GST_STATS_TRACER_H__ #include +#include G_BEGIN_DECLS