2 * Copyright (C) 2010 David Schleef <ds@schleef.org>
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.
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.
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
27 #include "gstcapsdebug.h"
32 static void gst_caps_debug_set_property (GObject * object,
33 guint property_id, const GValue * value, GParamSpec * pspec);
34 static void gst_caps_debug_get_property (GObject * object,
35 guint property_id, GValue * value, GParamSpec * pspec);
36 static void gst_caps_debug_dispose (GObject * object);
37 static void gst_caps_debug_finalize (GObject * object);
39 static GstFlowReturn gst_caps_debug_sink_chain (GstPad * pad,
41 static GstCaps *gst_caps_debug_getcaps (GstPad * pad);
42 static gboolean gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps);
43 static GstFlowReturn gst_caps_debug_bufferalloc (GstPad * pad,
44 guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
46 static GstStateChangeReturn
47 gst_caps_debug_change_state (GstElement * element, GstStateChange transition);
56 static GstStaticPadTemplate gst_caps_debug_sink_template =
57 GST_STATIC_PAD_TEMPLATE ("sink",
62 static GstStaticPadTemplate gst_caps_debug_src_template =
63 GST_STATIC_PAD_TEMPLATE ("src",
68 /* class initialization */
70 GST_BOILERPLATE (GstCapsDebug, gst_caps_debug, GstElement, GST_TYPE_ELEMENT);
73 gst_caps_debug_base_init (gpointer g_class)
75 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
77 gst_element_class_add_pad_template (element_class,
78 gst_static_pad_template_get (&gst_caps_debug_src_template));
79 gst_element_class_add_pad_template (element_class,
80 gst_static_pad_template_get (&gst_caps_debug_sink_template));
82 gst_element_class_set_details_simple (element_class, "Caps debug",
83 "Generic", "Debug caps negotiation", "David Schleef <ds@schleef.org>");
87 gst_caps_debug_class_init (GstCapsDebugClass * klass)
89 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
90 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
92 gobject_class->set_property = gst_caps_debug_set_property;
93 gobject_class->get_property = gst_caps_debug_get_property;
94 gobject_class->dispose = gst_caps_debug_dispose;
95 gobject_class->finalize = gst_caps_debug_finalize;
96 element_class->change_state = GST_DEBUG_FUNCPTR (gst_caps_debug_change_state);
101 gst_caps_debug_init (GstCapsDebug * capsdebug,
102 GstCapsDebugClass * capsdebug_class)
106 gst_pad_new_from_template (gst_static_pad_template_get
107 (&gst_caps_debug_src_template), "src");
108 gst_pad_set_getcaps_function (capsdebug->srcpad,
109 GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
110 gst_pad_set_acceptcaps_function (capsdebug->srcpad,
111 GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
112 gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->srcpad);
115 gst_pad_new_from_template (gst_static_pad_template_get
116 (&gst_caps_debug_sink_template), "sink");
117 gst_pad_set_chain_function (capsdebug->sinkpad,
118 GST_DEBUG_FUNCPTR (gst_caps_debug_sink_chain));
119 gst_pad_set_bufferalloc_function (capsdebug->sinkpad,
120 GST_DEBUG_FUNCPTR (gst_caps_debug_bufferalloc));
121 gst_pad_set_getcaps_function (capsdebug->sinkpad,
122 GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
123 gst_pad_set_acceptcaps_function (capsdebug->sinkpad,
124 GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
125 gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->sinkpad);
130 gst_caps_debug_set_property (GObject * object, guint property_id,
131 const GValue * value, GParamSpec * pspec)
133 GstCapsDebug *capsdebug;
135 g_return_if_fail (GST_IS_CAPS_DEBUG (object));
136 capsdebug = GST_CAPS_DEBUG (object);
138 switch (property_id) {
140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
146 gst_caps_debug_get_property (GObject * object, guint property_id,
147 GValue * value, GParamSpec * pspec)
149 GstCapsDebug *capsdebug;
151 g_return_if_fail (GST_IS_CAPS_DEBUG (object));
152 capsdebug = GST_CAPS_DEBUG (object);
154 switch (property_id) {
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
162 gst_caps_debug_dispose (GObject * object)
164 GstCapsDebug *capsdebug;
166 g_return_if_fail (GST_IS_CAPS_DEBUG (object));
167 capsdebug = GST_CAPS_DEBUG (object);
169 /* clean up as possible. may be called multiple times */
171 G_OBJECT_CLASS (parent_class)->dispose (object);
175 gst_caps_debug_finalize (GObject * object)
177 GstCapsDebug *capsdebug;
179 g_return_if_fail (GST_IS_CAPS_DEBUG (object));
180 capsdebug = GST_CAPS_DEBUG (object);
182 /* clean up object here */
184 G_OBJECT_CLASS (parent_class)->finalize (object);
189 static GstStateChangeReturn
190 gst_caps_debug_change_state (GstElement * element, GstStateChange transition)
192 GstStateChangeReturn ret;
194 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
196 return GST_STATE_CHANGE_SUCCESS;
201 gst_caps_debug_sink_chain (GstPad * pad, GstBuffer * buffer)
204 GstCapsDebug *capsdebug;
206 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
208 ret = gst_pad_push (capsdebug->srcpad, buffer);
210 gst_object_unref (capsdebug);
215 #define THISPAD ((pad == capsdebug->srcpad) ? "downstream" : "upstream")
216 #define OTHERPAD ((pad == capsdebug->srcpad) ? "upstream" : "downstream")
219 gst_caps_debug_getcaps (GstPad * pad)
222 GstCapsDebug *capsdebug;
226 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
228 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
230 GST_INFO ("%s called getcaps", THISPAD);
232 caps = gst_pad_peer_get_caps (otherpad);
234 s = gst_caps_to_string (caps);
235 GST_INFO ("%s returned %s", OTHERPAD, s);
239 caps = gst_caps_new_any ();
241 gst_object_unref (capsdebug);
248 gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps)
250 GstCapsDebug *capsdebug;
255 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
257 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
259 s = gst_caps_to_string (caps);
260 GST_INFO ("%s called acceptcaps with %s", THISPAD, s);
263 ret = gst_pad_peer_accept_caps (otherpad, caps);
265 GST_INFO ("%s returned %s", OTHERPAD, ret ? "TRUE" : "FALSE");
267 gst_object_unref (capsdebug);
273 gst_caps_debug_bufferalloc (GstPad * pad, guint64 offset, guint size,
274 GstCaps * caps, GstBuffer ** buf)
276 GstCapsDebug *capsdebug;
283 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
285 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
287 newcaps = (caps != GST_PAD_CAPS (pad));
290 s = gst_caps_to_string (caps);
291 GST_INFO ("%s called bufferalloc with new caps, offset=%" G_GUINT64_FORMAT
292 " size=%d caps=%s", THISPAD, offset, size, s);
296 ret = gst_pad_alloc_buffer_and_set_caps (otherpad, offset, size, caps, buf);
299 GST_INFO ("%s returned %s", OTHERPAD, gst_flow_get_name (ret));
301 if (caps != GST_BUFFER_CAPS (*buf)) {
302 s = gst_caps_to_string (caps);
303 t = gst_caps_to_string (GST_BUFFER_CAPS (*buf));
305 ("%s returned from bufferalloc with different caps, requested=%s returned=%s",
311 gst_object_unref (capsdebug);