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 gst_caps_debug_parent_class parent_class
65 G_DEFINE_TYPE (GstCapsDebug, gst_caps_debug, GST_TYPE_ELEMENT);
68 gst_caps_debug_class_init (GstCapsDebugClass * klass)
70 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
71 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
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);
77 GST_DEBUG_CATEGORY_INIT (gst_caps_debug_debug, "capsdebug", 0,
78 "debug category for capsdebug element");
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));
85 gst_element_class_set_static_metadata (element_class, "Caps debug",
86 "Generic", "Debug caps negotiation", "David Schleef <ds@schleef.org>");
90 gst_caps_debug_init (GstCapsDebug * capsdebug)
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);
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);
116 gst_caps_debug_dispose (GObject * object)
118 /* clean up as possible. may be called multiple times */
120 G_OBJECT_CLASS (parent_class)->dispose (object);
124 gst_caps_debug_finalize (GObject * object)
126 /* clean up object here */
128 G_OBJECT_CLASS (parent_class)->finalize (object);
133 static GstStateChangeReturn
134 gst_caps_debug_change_state (GstElement * element, GstStateChange transition)
136 GstStateChangeReturn ret;
138 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
145 gst_caps_debug_sink_chain (GstPad * pad, GstBuffer * buffer)
148 GstCapsDebug *capsdebug;
150 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
152 ret = gst_pad_push (capsdebug->srcpad, buffer);
154 gst_object_unref (capsdebug);
159 #define THISPAD ((pad == capsdebug->srcpad) ? "downstream" : "upstream")
160 #define OTHERPAD ((pad == capsdebug->srcpad) ? "upstream" : "downstream")
163 gst_caps_debug_getcaps (GstPad * pad)
166 GstCapsDebug *capsdebug;
170 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
172 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
174 GST_INFO ("%s called getcaps", THISPAD);
176 caps = gst_pad_peer_get_caps (otherpad);
178 s = gst_caps_to_string (caps);
179 GST_INFO ("%s returned %s", OTHERPAD, s);
183 caps = gst_caps_new_any ();
185 gst_object_unref (capsdebug);
192 gst_caps_debug_acceptcaps (GstPad * pad, GstCaps * caps)
194 GstCapsDebug *capsdebug;
199 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
201 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
203 s = gst_caps_to_string (caps);
204 GST_INFO ("%s called acceptcaps with %s", THISPAD, s);
207 ret = gst_pad_peer_accept_caps (otherpad, caps);
209 GST_INFO ("%s returned %s", OTHERPAD, ret ? "TRUE" : "FALSE");
211 gst_object_unref (capsdebug);
217 gst_caps_debug_bufferalloc (GstPad * pad, guint64 offset, guint size,
218 GstCaps * caps, GstBuffer ** buf)
220 GstCapsDebug *capsdebug;
227 capsdebug = GST_CAPS_DEBUG (gst_pad_get_parent (pad));
229 (pad == capsdebug->srcpad) ? capsdebug->sinkpad : capsdebug->srcpad;
231 newcaps = (caps != GST_PAD_CAPS (pad));
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);
240 ret = gst_pad_alloc_buffer_and_set_caps (otherpad, offset, size, caps, buf);
243 GST_INFO ("%s returned %s", OTHERPAD, gst_flow_get_name (ret));
245 if (caps != GST_BUFFER_CAPS (*buf)) {
246 s = gst_caps_to_string (caps);
247 t = gst_caps_to_string (GST_BUFFER_CAPS (*buf));
249 ("%s returned from bufferalloc with different caps, requested=%s returned=%s",
255 gst_object_unref (capsdebug);