3 * Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
4 * Copyright (C) 2002 David A. Schleef <ds@schleef.org>
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.
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.
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
32 #define GST_TYPE_NEGOTIATION \
33 (gst_gst_negotiation_get_type())
34 #define GST_NEGOTIATION(obj) \
35 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NEGOTIATION,GstNegotiation))
36 #define GST_NEGOTIATION_CLASS(klass) \
37 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NEGOTIATION,GstNegotiation))
38 #define GST_IS_NEGOTIATION(obj) \
39 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NEGOTIATION))
40 #define GST_IS_NEGOTIATION_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NEGOTIATION))
43 typedef struct _GstNegotiation GstNegotiation;
44 typedef struct _GstNegotiationClass GstNegotiationClass;
46 struct _GstNegotiation
50 GstPad *sinkpad, *srcpad;
55 struct _GstNegotiationClass
57 GstElementClass parent_class;
60 GType gst_gst_negotiation_get_type (void);
63 static const GstElementDetails plugin_details =
64 GST_ELEMENT_DETAILS ("Negotiation",
66 "This element acts like identity, except that one can control how "
68 "David A. Schleef <ds@schleef.org>");
70 /* Filter signals and args */
83 static GstStaticPadTemplate gst_negotiation_sink_factory =
84 GST_STATIC_PAD_TEMPLATE ("sink",
89 static GstStaticPadTemplate gst_negotiation_src_factory =
90 GST_STATIC_PAD_TEMPLATE ("src",
95 static void gst_negotiation_base_init (gpointer g_class);
96 static void gst_negotiation_class_init (GstNegotiationClass * klass);
97 static void gst_negotiation_init (GstNegotiation * filter);
99 static GstCaps *gst_negotiation_getcaps (GstPad * pad);
100 static GstPadLinkReturn gst_negotiation_pad_link (GstPad * pad,
101 const GstCaps * caps);
103 static void gst_negotiation_set_property (GObject * object, guint prop_id,
104 const GValue * value, GParamSpec * pspec);
105 static void gst_negotiation_get_property (GObject * object, guint prop_id,
106 GValue * value, GParamSpec * pspec);
108 static void gst_negotiation_update_caps (GstNegotiation * negotiation);
109 static void gst_negotiation_chain (GstPad * pad, GstData * _data);
111 static GstElementClass *parent_class = NULL;
114 gst_gst_negotiation_get_type (void)
116 static GType plugin_type = 0;
119 static const GTypeInfo plugin_info = {
120 sizeof (GstNegotiationClass),
121 gst_negotiation_base_init,
123 (GClassInitFunc) gst_negotiation_class_init,
126 sizeof (GstNegotiation),
128 (GInstanceInitFunc) gst_negotiation_init,
131 plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
132 "GstNegotiation", &plugin_info, 0);
138 gst_negotiation_base_init (gpointer g_class)
140 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
142 gst_element_class_add_pad_template (element_class,
143 gst_static_pad_template_get (&gst_negotiation_sink_factory));
144 gst_element_class_add_pad_template (element_class,
145 gst_static_pad_template_get (&gst_negotiation_src_factory));
146 gst_element_class_set_details (element_class, &plugin_details);
150 gst_negotiation_class_init (GstNegotiationClass * klass)
152 GObjectClass *gobject_class;
153 GstElementClass *gstelement_class;
155 gobject_class = (GObjectClass *) klass;
156 gstelement_class = (GstElementClass *) klass;
158 parent_class = g_type_class_peek_parent (klass);
160 gobject_class->set_property = gst_negotiation_set_property;
161 gobject_class->get_property = gst_negotiation_get_property;
163 g_object_class_install_property (gobject_class, ARG_ALLOWED_CAPS,
164 g_param_spec_boxed ("allowed-caps", "Caps",
165 "The range of formats allowed by " "this element's peers",
166 GST_TYPE_CAPS, G_PARAM_READABLE));
170 gst_negotiation_init (GstNegotiation * filter)
173 gst_pad_new_from_static_template (&gst_negotiation_sink_factory, "sink");
174 gst_pad_set_getcaps_function (filter->sinkpad, gst_negotiation_getcaps);
175 gst_pad_set_link_function (filter->sinkpad, gst_negotiation_pad_link);
177 gst_pad_new_from_static_template (&gst_negotiation_src_factory, "src");
178 gst_pad_set_getcaps_function (filter->srcpad, gst_negotiation_getcaps);
179 gst_pad_set_link_function (filter->srcpad, gst_negotiation_pad_link);
181 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
182 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
183 gst_pad_set_chain_function (filter->sinkpad, gst_negotiation_chain);
187 gst_negotiation_getcaps (GstPad * pad)
189 GstNegotiation *negotiation = GST_NEGOTIATION (gst_pad_get_parent (pad));
193 otherpad = (pad == negotiation->sinkpad) ? negotiation->srcpad :
194 negotiation->sinkpad;
196 caps = gst_pad_get_allowed_caps (otherpad);
198 GST_ERROR ("getcaps called on %" GST_PTR_FORMAT ", returning %"
199 GST_PTR_FORMAT, pad, caps);
201 gst_negotiation_update_caps (negotiation);
202 gst_object_unref (negotiation);
207 static GstPadLinkReturn
208 gst_negotiation_pad_link (GstPad * pad, const GstCaps * caps)
210 GstNegotiation *negotiation = GST_NEGOTIATION (gst_pad_get_parent (pad));
212 GstPadLinkReturn ret;
214 otherpad = (pad == negotiation->sinkpad) ? negotiation->srcpad :
215 negotiation->sinkpad;
217 ret = gst_pad_try_set_caps (otherpad, caps);
219 GST_ERROR ("pad_link called on %" GST_PTR_FORMAT " with caps %"
220 GST_PTR_FORMAT ", returning %d", pad, caps, ret);
221 gst_object_unref (negotiation);
227 gst_negotiation_update_caps (GstNegotiation * negotiation)
233 srccaps = gst_pad_get_allowed_caps (negotiation->srcpad);
234 sinkcaps = gst_pad_get_allowed_caps (negotiation->sinkpad);
236 icaps = gst_caps_intersect (srccaps, sinkcaps);
237 gst_caps_free (srccaps);
238 gst_caps_free (sinkcaps);
240 gst_caps_replace (&negotiation->caps, icaps);
241 g_object_notify (G_OBJECT (negotiation), "allowed-caps");
242 GST_DEBUG ("notify %" GST_PTR_FORMAT, icaps);
246 gst_negotiation_chain (GstPad * pad, GstData * _data)
248 GstNegotiation *negotiation = GST_NEGOTIATION (gst_pad_get_parent (pad));
250 gst_pad_push (negotiation->srcpad, _data);
251 gst_object_unref (negotiation);
255 gst_negotiation_set_property (GObject * object, guint prop_id,
256 const GValue * value, GParamSpec * pspec)
258 GstNegotiation *filter;
260 g_return_if_fail (GST_IS_NEGOTIATION (object));
261 filter = GST_NEGOTIATION (object);
265 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
271 gst_negotiation_get_property (GObject * object, guint prop_id,
272 GValue * value, GParamSpec * pspec)
274 GstNegotiation *filter;
276 g_return_if_fail (GST_IS_NEGOTIATION (object));
277 filter = GST_NEGOTIATION (object);
280 case ARG_ALLOWED_CAPS:
281 g_value_set_boxed (value, filter->caps);
284 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
290 gst_negotiation_plugin_init (GstPlugin * plugin)
292 if (!gst_element_register (plugin, "negotiation", GST_RANK_NONE,
293 GST_TYPE_NEGOTIATION))