tracer: use a macros for the enabled check
[platform/upstream/gstreamer.git] / gst / gsttracer.h
1 /* GStreamer
2  * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
3  *
4  * gsttracer.h: tracing subsystem
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21
22 #ifndef __GST_TRACER_H__
23 #define __GST_TRACER_H__
24
25 #include <glib.h>
26 #include <glib-object.h>
27 #include <gst/gstconfig.h>
28 #include <gst/gstbin.h>
29
30 G_BEGIN_DECLS
31
32 #ifndef GST_DISABLE_GST_DEBUG
33
34 /* hook flags and ids */
35
36 typedef enum
37 {
38   GST_TRACER_HOOK_NONE      = 0,
39   GST_TRACER_HOOK_BUFFERS   = (1 << 0),
40   GST_TRACER_HOOK_EVENTS    = (1 << 1),
41   GST_TRACER_HOOK_MESSAGES  = (1 << 2),
42   GST_TRACER_HOOK_QUERIES   = (1 << 3),
43   GST_TRACER_HOOK_TOPOLOGY  = (1 << 4),
44   /*
45   GST_TRACER_HOOK_TIMER
46   */
47   GST_TRACER_HOOK_ALL       = (1 << 5) - 1
48 } GstTracerHook;
49
50 typedef enum
51 {
52   GST_TRACER_HOOK_ID_BUFFERS = 0,
53   GST_TRACER_HOOK_ID_EVENTS,
54   GST_TRACER_HOOK_ID_MESSAGES,
55   GST_TRACER_HOOK_ID_QUERIES,
56   GST_TRACER_HOOK_ID_TOPLOGY,
57   /*
58   GST_TRACER_HOOK_ID_TIMER
59   */
60   GST_TRACER_HOOK_ID_LAST
61 } GstTracerHookId;
62
63 typedef enum
64 {
65   GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE = 0,
66   GST_TRACER_MESSAGE_ID_PAD_PUSH_POST,
67   GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE,
68   GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST,
69   GST_TRACER_MESSAGE_ID_LAST
70 } GstTracerMessageId;
71
72 /* tracing plugins */
73
74 typedef struct _GstTracer GstTracer;
75 typedef struct _GstTracerPrivate GstTracerPrivate;
76 typedef struct _GstTracerClass GstTracerClass;
77
78 #define GST_TYPE_TRACER            (gst_tracer_get_type())
79 #define GST_TRACER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TRACER,GstTracer))
80 #define GST_TRACER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TRACER,GstTracerClass))
81 #define GST_IS_TRACER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TRACER))
82 #define GST_IS_TRACER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TRACER))
83 #define GST_TRACER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_TRACER,GstTracerClass))
84 #define GST_TRACER_CAST(obj)       ((GstTracer *)(obj))
85
86 struct _GstTracer {
87   GstObject        parent;
88   /*< private >*/
89   GstTracerPrivate *priv;
90   gpointer _gst_reserved[GST_PADDING];
91 };
92
93 typedef void (*GstTracerInvokeFunction) (GstTracer * self, GstTracerHookId hid,
94     GstTracerMessageId mid, va_list var_args);
95
96 struct _GstTracerClass {
97   GstObjectClass parent_class;
98   
99   /* plugin vmethods */
100   GstTracerInvokeFunction invoke;
101   
102   /*< private >*/
103   gpointer _gst_reserved[GST_PADDING];
104 };
105
106 GType gst_tracer_get_type          (void);
107
108 /* tracing hooks */
109
110 void _priv_gst_tracer_init (void);
111 void _priv_gst_tracer_deinit (void);
112
113 gboolean gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type);
114 void gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...);
115
116 extern gboolean _priv_tracer_enabled;
117 extern GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST];
118
119 #define GST_TRACER_IS_ENABLED(id) \
120   (_priv_tracer_enabled && (_priv_tracers[id] != NULL))
121
122 /* tracing hooks */
123
124 #define GST_TRACER_PAD_PUSH_PRE(pad, buffer) G_STMT_START{ \
125   if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
126     gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
127         GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE, gst_util_get_timestamp (), \
128         pad, buffer); \
129   } \
130 }G_STMT_END
131
132 #define GST_TRACER_PAD_PUSH_POST(pad, res) G_STMT_START{ \
133   if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
134     gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
135         GST_TRACER_MESSAGE_ID_PAD_PUSH_POST, gst_util_get_timestamp (), \
136         pad, res); \
137   } \
138 }G_STMT_END
139
140 #define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list) G_STMT_START{ \
141   if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
142     gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
143         GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE, gst_util_get_timestamp (), \
144         pad, list); \
145   } \
146 }G_STMT_END
147
148 #define GST_TRACER_PAD_PUSH_LIST_POST(pad, res) G_STMT_START{ \
149   if (GST_TRACER_IS_ENABLED(GST_TRACER_HOOK_ID_BUFFERS)) { \
150     gst_tracer_dispatch (GST_TRACER_HOOK_ID_BUFFERS, \
151         GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST, gst_util_get_timestamp (), \
152         pad, res); \
153   } \
154 }G_STMT_END
155
156 #else /* !GST_DISABLE_GST_DEBUG */
157
158 #define GST_TRACER_PAD_PUSH_PRE(pad, buffer)
159 #define GST_TRACER_PAD_PUSH_POST(pad, res)
160 #define GST_TRACER_PAD_PUSH_LIST_PRE(pad, list)
161 #define GST_TRACER_PAD_PUSH_LIST_POST(pad, res)
162
163 #endif /* GST_DISABLE_GST_DEBUG */
164
165 G_END_DECLS
166
167 #endif /* __GST_TRACER_H__ */
168