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"
29 GST_DEBUG_CATEGORY_STATIC (gst_caps_debug_debug);
30 #define GST_CAT_DEFAULT gst_caps_debug_debug
35 static void gst_caps_debug_dispose (GObject * object);
36 static void gst_caps_debug_finalize (GObject * object);
38 static GstFlowReturn gst_caps_debug_sink_chain (GstPad * pad,
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);
45 static GstStateChangeReturn
46 gst_caps_debug_change_state (GstElement * element, GstStateChange transition);
50 static GstStaticPadTemplate gst_caps_debug_sink_template =
51 GST_STATIC_PAD_TEMPLATE ("sink",
56 static GstStaticPadTemplate gst_caps_debug_src_template =
57 GST_STATIC_PAD_TEMPLATE ("src",
62 /* class initialization */
64 #define DEBUG_INIT(bla) \
65 GST_DEBUG_CATEGORY_INIT (gst_caps_debug_debug, "capsdebug", 0, \
66 "debug category for capsdebug element");
68 GST_BOILERPLATE_FULL (GstCapsDebug, gst_caps_debug, GstElement,
69 GST_TYPE_ELEMENT, DEBUG_INIT);
72 gst_caps_debug_base_init (gpointer g_class)
74 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
76 gst_element_class_add_pad_template (element_class,
77 gst_static_pad_template_get (&gst_caps_debug_src_template));
78 gst_element_class_add_pad_template (element_class,
79 gst_static_pad_template_get (&gst_caps_debug_sink_template));
81 gst_element_class_set_details_simple (element_class, "Caps debug",
82 "Generic", "Debug caps negotiation", "David Schleef <ds@schleef.org>");
86 gst_caps_debug_class_init (GstCapsDebugClass * klass)
88 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
89 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
91 gobject_class->dispose = gst_caps_debug_dispose;
92 gobject_class->finalize = gst_caps_debug_finalize;
93 element_class->change_state = GST_DEBUG_FUNCPTR (gst_caps_debug_change_state);
98 gst_caps_debug_init (GstCapsDebug * capsdebug,
99 GstCapsDebugClass * capsdebug_class)
103 gst_pad_new_from_static_template (&gst_caps_debug_src_template, "src");
104 gst_pad_set_getcaps_function (capsdebug->srcpad,
105 GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
106 gst_pad_set_acceptcaps_function (capsdebug->srcpad,
107 GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
108 gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->srcpad);
111 gst_pad_new_from_static_template (&gst_caps_debug_sink_template, "sink");
112 gst_pad_set_chain_function (capsdebug->sinkpad,
113 GST_DEBUG_FUNCPTR (gst_caps_debug_sink_chain));
114 gst_pad_set_bufferalloc_function (capsdebug->sinkpad,
115 GST_DEBUG_FUNCPTR (gst_caps_debug_bufferalloc));
116 gst_pad_set_getcaps_function (capsdebug->sinkpad,
117 GST_DEBUG_FUNCPTR (gst_caps_debug_getcaps));
118 gst_pad_set_acceptcaps_function (capsdebug->sinkpad,
119 GST_DEBUG_FUNCPTR (gst_caps_debug_acceptcaps));
120 gst_element_add_pad (GST_ELEMENT (capsdebug), capsdebug->sinkpad);
125 gst_caps_debug_dispose (GObject * object)
127 /* clean up as possible. may be called multiple times */
129 G_OBJECT_CLASS (parent_class)->dispose (object);
133 gst_caps_debug_finalize (GObject * object)
135 /* clean up object here */
137 G_OBJECT_CLASS (parent_class)->finalize (object);
142 static GstStateChangeReturn
143 gst_caps_debug_change_state (GstElement * element, GstStateChange transition)
145 GstStateChangeReturn ret;
147 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
154 gst_caps_debug_sink_chain (GstPad * pad, GstBuffer * buffer)
157 GstCapsDebug *capsdebug;
159 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
161 ret = gst_pad_push (capsdebug->srcpad, buffer);
163 gst_object_unref (capsdebug);
168 #define THISPAD ((pad == capsdebug->srcpad) ? "downstream" : "upstream")
169 #define OTHERPAD ((pad == capsdebug->srcpad) ? "upstream" : "downstream")
172 gst_caps_debug_getcaps (GstPad * pad)
175 GstCapsDebug *capsdebug;
179 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
181 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
183 GST_INFO ("%s called getcaps", THISPAD);
185 caps = gst_pad_peer_get_caps (otherpad);
187 s = gst_caps_to_string (caps);
188 GST_INFO ("%s returned %s", OTHERPAD, s);
192 caps = gst_caps_new_any ();
194 gst_object_unref (capsdebug);
201 gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps)
203 GstCapsDebug *capsdebug;
208 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
210 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
212 s = gst_caps_to_string (caps);
213 GST_INFO ("%s called acceptcaps with %s", THISPAD, s);
216 ret = gst_pad_peer_accept_caps (otherpad, caps);
218 GST_INFO ("%s returned %s", OTHERPAD, ret ? "TRUE" : "FALSE");
220 gst_object_unref (capsdebug);
226 gst_caps_debug_bufferalloc (GstPad * pad, guint64 offset, guint size,
227 GstCaps * caps, GstBuffer ** buf)
229 GstCapsDebug *capsdebug;
236 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
238 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
240 newcaps = (caps != GST_PAD_CAPS (pad));
243 s = gst_caps_to_string (caps);
244 GST_INFO ("%s called bufferalloc with new caps, offset=%" G_GUINT64_FORMAT
245 " size=%d caps=%s", THISPAD, offset, size, s);
249 ret = gst_pad_alloc_buffer_and_set_caps (otherpad, offset, size, caps, buf);
252 GST_INFO ("%s returned %s", OTHERPAD, gst_flow_get_name (ret));
254 if (caps != GST_BUFFER_CAPS (*buf)) {
255 s = gst_caps_to_string (caps);
256 t = gst_caps_to_string (GST_BUFFER_CAPS (*buf));
258 ("%s returned from bufferalloc with different caps, requested=%s returned=%s",
264 gst_object_unref (capsdebug);