tracers: eliminate var_args
[platform/upstream/gstreamer.git] / plugins / tracers / gstlog.c
1 /* GStreamer
2  * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
3  *
4  * gstlog.c: tracing module that logs events
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  * SECTION:gstlog
23  * @short_description: log hook event
24  *
25  * A tracing module that logs all data from all hooks. 
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #  include "config.h"
30 #endif
31
32 #include "gstlog.h"
33
34 #include <gst/printf/printf.h>
35
36 GST_DEBUG_CATEGORY_STATIC (gst_log_debug);
37 #define GST_CAT_DEFAULT gst_log_debug
38 GST_DEBUG_CATEGORY_STATIC (GST_CAT_BUFFER);
39 GST_DEBUG_CATEGORY_STATIC (GST_CAT_BUFFER_LIST);
40 GST_DEBUG_CATEGORY_STATIC (GST_CAT_EVENT);
41 GST_DEBUG_CATEGORY_STATIC (GST_CAT_MESSAGE);
42 GST_DEBUG_CATEGORY_STATIC (GST_CAT_QUERY);
43
44 #define _do_init \
45     GST_DEBUG_CATEGORY_INIT (gst_log_debug, "log", 0, "log tracer"); \
46     GST_DEBUG_CATEGORY_GET (GST_CAT_BUFFER, "GST_BUFFER"); \
47     GST_DEBUG_CATEGORY_GET (GST_CAT_BUFFER_LIST, "GST_BUFFER_LIST"); \
48     GST_DEBUG_CATEGORY_GET (GST_CAT_EVENT, "GST_EVENT"); \
49     GST_DEBUG_CATEGORY_GET (GST_CAT_MESSAGE, "GST_MESSAGE"); \
50     GST_DEBUG_CATEGORY_GET (GST_CAT_QUERY, "query");
51 #define gst_log_tracer_parent_class parent_class
52 G_DEFINE_TYPE_WITH_CODE (GstLogTracer, gst_log_tracer, GST_TYPE_TRACER,
53     _do_init);
54
55 static void
56 do_log (GstDebugCategory * cat, const char *fmt, ...)
57 {
58   va_list var_args;
59
60   va_start (var_args, fmt);
61   gst_debug_log_valist (cat, GST_LEVEL_TRACE, "", "", 0, NULL, fmt, var_args);
62   va_end (var_args);
63 }
64
65 static void
66 do_push_buffer_pre (GstTracer * self, guint64 ts, GstPad * pad,
67     GstBuffer * buffer)
68 {
69   do_log (GST_CAT_BUFFER,
70       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT,
71       ts, pad, buffer);
72 }
73
74 static void
75 do_push_buffer_post (GstTracer * self, guint64 ts, GstPad * pad,
76     GstFlowReturn res)
77 {
78   do_log (GST_CAT_BUFFER,
79       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d", ts, pad, res);
80 }
81
82 static void
83 do_push_buffer_list_pre (GstTracer * self, guint64 ts, GstPad * pad,
84     GstBufferList * list)
85 {
86   do_log (GST_CAT_BUFFER_LIST,
87       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", list=%p", ts, pad, list);
88 }
89
90 static void
91 do_push_buffer_list_post (GstTracer * self, guint64 ts, GstPad * pad,
92     GstFlowReturn res)
93 {
94   do_log (GST_CAT_BUFFER_LIST,
95       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d", ts, pad, res);
96 }
97
98 static void
99 do_pull_range_pre (GstTracer * self, guint64 ts, GstPad * pad, guint64 offset,
100     guint size)
101 {
102   do_log (GST_CAT_BUFFER,
103       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", offset=%" G_GUINT64_FORMAT
104       ", size=%u", ts, pad, offset, size);
105 }
106
107 static void
108 do_pull_range_post (GstTracer * self, guint64 ts, GstPad * pad,
109     GstBuffer * buffer, GstFlowReturn res)
110 {
111   do_log (GST_CAT_BUFFER,
112       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT
113       ", res=%d", ts, pad, buffer, res);
114 }
115
116 static void
117 do_push_event_pre (GstTracer * self, guint64 ts, GstPad * pad, GstEvent * event)
118 {
119   do_log (GST_CAT_EVENT,
120       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", event=%" GST_PTR_FORMAT,
121       ts, pad, event);
122 }
123
124 static void
125 do_push_event_post (GstTracer * self, guint64 ts, GstPad * pad, gboolean res)
126 {
127   do_log (GST_CAT_EVENT,
128       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d", ts, pad, res);
129 }
130
131 static void
132 do_post_message_pre (GstTracer * self, guint64 ts, GstElement * elem,
133     GstMessage * msg)
134 {
135   do_log (GST_CAT_EVENT,
136       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", message=%"
137       GST_PTR_FORMAT, ts, elem, msg);
138 }
139
140 static void
141 do_post_message_post (GstTracer * self, guint64 ts, GstElement * elem,
142     gboolean res)
143 {
144   do_log (GST_CAT_EVENT,
145       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", res=%d", ts, elem,
146       res);
147 }
148
149 static void
150 do_query_pre (GstTracer * self, guint64 ts, GstElement * elem, GstQuery * query)
151 {
152   do_log (GST_CAT_QUERY,
153       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", query=%"
154       GST_PTR_FORMAT, ts, elem, query);
155 }
156
157 static void
158 do_query_post (GstTracer * self, guint64 ts, GstElement * elem, gboolean res)
159 {
160   do_log (GST_CAT_QUERY,
161       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", res=%d", ts, elem,
162       res);
163 }
164
165
166 /* tracer class */
167
168 static void
169 gst_log_tracer_class_init (GstLogTracerClass * klass)
170 {
171 }
172
173 static void
174 gst_log_tracer_init (GstLogTracer * self)
175 {
176   GstTracer *tracer = GST_TRACER (self);
177
178   gst_tracer_register_hook (tracer, "pad-push-pre",
179       G_CALLBACK (do_push_buffer_pre));
180   gst_tracer_register_hook (tracer, "pad-push-post",
181       G_CALLBACK (do_push_buffer_post));
182   gst_tracer_register_hook (tracer, "pad-push-list-pre",
183       G_CALLBACK (do_push_buffer_list_pre));
184   gst_tracer_register_hook (tracer, "pad-push-list-post",
185       G_CALLBACK (do_push_buffer_list_post));
186   gst_tracer_register_hook (tracer, "pad-pull-range-pre",
187       G_CALLBACK (do_pull_range_pre));
188   gst_tracer_register_hook (tracer, "pad-pull-range-post",
189       G_CALLBACK (do_pull_range_post));
190   gst_tracer_register_hook (tracer, "pad-push-event-pre",
191       G_CALLBACK (do_push_event_pre));
192   gst_tracer_register_hook (tracer, "pad-push-event-post",
193       G_CALLBACK (do_push_event_post));
194   gst_tracer_register_hook (tracer, "element-post-message-pre",
195       G_CALLBACK (do_post_message_pre));
196   gst_tracer_register_hook (tracer, "element-post-message-post",
197       G_CALLBACK (do_post_message_post));
198   gst_tracer_register_hook (tracer, "element-query-pre",
199       G_CALLBACK (do_query_pre));
200   gst_tracer_register_hook (tracer, "element-query-post",
201       G_CALLBACK (do_query_post));
202 }