win32: remove outdated build cruft
[platform/upstream/gst-plugins-good.git] / gst / debugutils / gstcapsdebug.c
1 /* GStreamer
2  * Copyright (C) 2010 David Schleef <ds@schleef.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gst/gst.h>
26 #include <gst/gst.h>
27 #include "gstcapsdebug.h"
28
29 GST_DEBUG_CATEGORY_STATIC (gst_caps_debug_debug);
30 #define GST_CAT_DEFAULT gst_caps_debug_debug
31
32 /* prototypes */
33
34
35 static void gst_caps_debug_dispose (GObject * object);
36 static void gst_caps_debug_finalize (GObject * object);
37
38 static GstFlowReturn gst_caps_debug_sink_chain (GstPad * pad,
39     GstBuffer * buffer);
40 static GstCaps *gst_caps_debug_getcaps (GstPad * pad);
41 static gboolean gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps);
42 static GstFlowReturn gst_caps_debug_bufferalloc (GstPad * pad,
43     guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
44
45 static GstStateChangeReturn
46 gst_caps_debug_change_state (GstElement * element, GstStateChange transition);
47
48 /* pad templates */
49
50 static GstStaticPadTemplate gst_caps_debug_sink_template =
51 GST_STATIC_PAD_TEMPLATE ("sink",
52     GST_PAD_SINK,
53     GST_PAD_ALWAYS,
54     GST_STATIC_CAPS_ANY);
55
56 static GstStaticPadTemplate gst_caps_debug_src_template =
57 GST_STATIC_PAD_TEMPLATE ("src",
58     GST_PAD_SRC,
59     GST_PAD_ALWAYS,
60     GST_STATIC_CAPS_ANY);
61
62 /* class initialization */
63
64 #define gst_caps_debug_parent_class parent_class
65 G_DEFINE_TYPE (GstCapsDebug, gst_caps_debug, GST_TYPE_ELEMENT);
66
67 static void
68 gst_caps_debug_class_init (GstCapsDebugClass * klass)
69 {
70   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
71   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
72
73   gobject_class->dispose = gst_caps_debug_dispose;
74   gobject_class->finalize = gst_caps_debug_finalize;
75   element_class->change_state = GST_DEBUG_FUNCPTR (gst_caps_debug_change_state);
76
77   GST_DEBUG_CATEGORY_INIT (gst_caps_debug_debug, "capsdebug", 0,
78       "debug category for capsdebug element");
79
80   gst_element_class_add_pad_template (element_class,
81       gst_static_pad_template_get (&gst_caps_debug_src_template));
82   gst_element_class_add_pad_template (element_class,
83       gst_static_pad_template_get (&gst_caps_debug_sink_template));
84
85   gst_element_class_set_static_metadata (element_class, "Caps debug",
86       "Generic", "Debug caps negotiation", "David Schleef <ds@schleef.org>");
87 }
88
89 static void
90 gst_caps_debug_init (GstCapsDebug * capsdebug)
91 {
92
93   capsdebug->srcpad =
94       gst_pad_new_from_static_template (&gst_caps_debug_src_template, "src");
95   gst_pad_set_getcaps_function (capsdebug->srcpad,
96       GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
97   gst_pad_set_acceptcaps_function (capsdebug->srcpad,
98       GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
99   gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->srcpad);
100
101   capsdebug->sinkpad =
102       gst_pad_new_from_static_template (&gst_caps_debug_sink_template, "sink");
103   gst_pad_set_chain_function (capsdebug->sinkpad,
104       GST_DEBUG_FUNCPTR (gst_caps_debug_sink_chain));
105   gst_pad_set_bufferalloc_function (capsdebug->sinkpad,
106       GST_DEBUG_FUNCPTR (gst_caps_debug_bufferalloc));
107   gst_pad_set_getcaps_function (capsdebug->sinkpad,
108       GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
109   gst_pad_set_acceptcaps_function (capsdebug->sinkpad,
110       GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
111   gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->sinkpad);
112
113 }
114
115 void
116 gst_caps_debug_dispose (GObject * object)
117 {
118   /* clean up as possible.  may be called multiple times */
119
120   G_OBJECT_CLASS (parent_class)->dispose (object);
121 }
122
123 void
124 gst_caps_debug_finalize (GObject * object)
125 {
126   /* clean up object here */
127
128   G_OBJECT_CLASS (parent_class)->finalize (object);
129 }
130
131
132
133 static GstStateChangeReturn
134 gst_caps_debug_change_state (GstElement * element, GstStateChange transition)
135 {
136   GstStateChangeReturn ret;
137
138   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
139
140   return ret;
141 }
142
143
144 static GstFlowReturn
145 gst_caps_debug_sink_chain (GstPad * pad, GstBuffer * buffer)
146 {
147   GstFlowReturn ret;
148   GstCapsDebug *capsdebug;
149
150   capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
151
152   ret = gst_pad_push (capsdebug->srcpad, buffer);
153
154   gst_object_unref (capsdebug);
155
156   return ret;
157 }
158
159 #define THISPAD ((pad == capsdebug->srcpad) ? "downstream" : "upstream")
160 #define OTHERPAD ((pad == capsdebug->srcpad) ? "upstream" : "downstream")
161
162 static GstCaps *
163 gst_caps_debug_getcaps (GstPad * pad)
164 {
165   GstCaps *caps;
166   GstCapsDebug *capsdebug;
167   gchar *s;
168   GstPad *otherpad;
169
170   capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
171   otherpad =
172       (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
173
174   GST_INFO ("%s called getcaps", THISPAD);
175
176   caps = gst_pad_peer_get_caps (otherpad);
177
178   s = gst_caps_to_string (caps);
179   GST_INFO ("%s returned %s", OTHERPAD, s);
180   g_free (s);
181
182   if (caps == NULL)
183     caps = gst_caps_new_any ();
184
185   gst_object_unref (capsdebug);
186
187   return caps;
188 }
189
190
191 static gboolean
192 gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps)
193 {
194   GstCapsDebug *capsdebug;
195   gchar *s;
196   gboolean ret;
197   GstPad *otherpad;
198
199   capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
200   otherpad =
201       (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
202
203   s = gst_caps_to_string (caps);
204   GST_INFO ("%s called acceptcaps with %s", THISPAD, s);
205   g_free (s);
206
207   ret = gst_pad_peer_accept_caps (otherpad, caps);
208
209   GST_INFO ("%s returned %s", OTHERPAD, ret ? "TRUE" : "FALSE");
210
211   gst_object_unref (capsdebug);
212
213   return ret;
214 }
215
216 static GstFlowReturn
217 gst_caps_debug_bufferalloc (GstPad * pad, guint64 offset, guint size,
218     GstCaps * caps, GstBuffer ** buf)
219 {
220   GstCapsDebug *capsdebug;
221   gchar *s;
222   gchar *t;
223   GstFlowReturn ret;
224   GstPad *otherpad;
225   gboolean newcaps;
226
227   capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
228   otherpad =
229       (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
230
231   newcaps = (caps != GST_PAD_CAPS (pad));
232
233   if (newcaps) {
234     s = gst_caps_to_string (caps);
235     GST_INFO ("%s called bufferalloc with new caps, offset=%" G_GUINT64_FORMAT
236         " size=%d caps=%s", THISPAD, offset, size, s);
237     g_free (s);
238   }
239
240   ret = gst_pad_alloc_buffer_and_set_caps (otherpad, offset, size, caps, buf);
241
242   if (newcaps) {
243     GST_INFO ("%s returned %s", OTHERPAD, gst_flow_get_name (ret));
244   }
245   if (caps != GST_BUFFER_CAPS (*buf)) {
246     s = gst_caps_to_string (caps);
247     t = gst_caps_to_string (GST_BUFFER_CAPS (*buf));
248     GST_INFO
249         ("%s returned from bufferalloc with different caps, requested=%s returned=%s",
250         OTHERPAD, s, t);
251     g_free (s);
252     g_free (t);
253   }
254
255   gst_object_unref (capsdebug);
256
257   return ret;
258 }