2 * Copyright (C) <2012> Intel Corporation
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.
23 * @short_description: Simple base class for platform-specific policy implementations
24 * @see_also: autopolicy
26 * Any platform-specific policy element should be implemented by subclassing
27 * #GstPolicy. Applications should be using #autopolicy element that finds and
28 * and wraps an appropriate policy element, or just #playbin element which
29 * encapsulates autopolicy element.
31 * #GstPolicy provides an unlimited number of request sink pads. You can obtain
32 * the corresponding source pad by listening to a "pad-added" signal while
33 * requesting the sink pad.
42 #include "gstpolicy.h"
44 GST_DEBUG_CATEGORY_STATIC (gst_policy_debug);
45 #define GST_CAT_DEFAULT gst_policy_debug
58 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
61 GST_STATIC_CAPS ("ANY")
64 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src_%d",
67 GST_STATIC_CAPS ("ANY")
70 GST_BOILERPLATE(GstPolicy, gst_policy, GstElement, GST_TYPE_ELEMENT);
72 static void gst_policy_set_property (GObject * object, guint prop_id,
73 const GValue * value, GParamSpec * pspec);
74 static void gst_policy_get_property (GObject * object, guint prop_id,
75 GValue * value, GParamSpec * pspec);
76 static void gst_policy_finalize (GObject * object);
78 static GstPad *gst_policy_request_new_pad (GstElement * element,
79 GstPadTemplate * templ, const gchar * name);
80 static void gst_policy_release_pad (GstElement * element, GstPad * pad);
82 static gboolean gst_policy_sink_event (GstPad * pad, GstEvent * event);
83 static gboolean gst_policy_src_event (GstPad * pad, GstEvent * event);
84 static GstFlowReturn gst_policy_chain (GstPad * pad, GstBuffer * buf);
86 static GstIterator *gst_policy_iterate_internal_links (GstPad *
87 pad, GstObject * parent);
90 gst_policy_class_init (GstPolicyClass * klass)
92 GObjectClass *gobject_class;
93 GstElementClass *gstelement_class;
95 gobject_class = (GObjectClass *) klass;
96 gstelement_class = (GstElementClass *) klass;
98 GST_DEBUG_CATEGORY_INIT (gst_policy_debug, "policy", 0, "Policy debugging");
100 gobject_class->set_property = gst_policy_set_property;
101 gobject_class->get_property = gst_policy_get_property;
102 gobject_class->finalize = gst_policy_finalize;
107 * Set the role of the stream. This property can be used by the platform policy subsystem
108 * to make policy decisions that affect the stream (for example routing and enforced
111 g_object_class_install_property (gobject_class, PROP_ROLE,
112 g_param_spec_string ("role", "Stream role",
113 "Stream role for the platform policy sybsystem", NULL,
114 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
116 // element class methods
117 gstelement_class->request_new_pad = gst_policy_request_new_pad;
118 gstelement_class->release_pad = gst_policy_release_pad;
122 gst_policy_init (GstPolicy * policy, GstPolicyClass *klass)
124 GST_DEBUG_CATEGORY_INIT (gst_policy_debug, "policy", 0, "Policy");
130 gst_policy_base_init (gpointer klass)
132 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
134 gst_element_class_add_pad_template (gstelement_class,
135 gst_static_pad_template_get (&src_factory));
136 gst_element_class_add_pad_template (gstelement_class,
137 gst_static_pad_template_get (&sink_factory));
142 gst_policy_finalize (GObject * object)
146 policy = GST_POLICY (object);
148 g_free (policy->role);
151 G_OBJECT_CLASS (parent_class)->finalize (object);
155 gst_policy_set_property (GObject * object, guint prop_id,
156 const GValue * value, GParamSpec * pspec)
158 GstPolicy *policy = GST_POLICY (object);
162 g_free (policy->role);
163 policy->role = g_strdup (g_value_get_string (value));
164 GST_DEBUG_OBJECT (policy, "Setting stream role to %s", policy->role);
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
173 gst_policy_get_property (GObject * object, guint prop_id,
174 GValue * value, GParamSpec * pspec)
176 GstPolicy *policy = GST_POLICY (object);
180 GST_DEBUG_OBJECT (policy, "Getting stream role: %s", policy->role);
181 g_value_set_string (value, policy->role);
184 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
189 gst_policy_release_pad (GstElement * element, GstPad * pad)
191 GstPolicy *self = GST_POLICY (element);
192 GstPad *srcpad = gst_pad_get_element_private (pad);
194 gst_pad_set_element_private (pad, NULL);
195 gst_pad_set_element_private (srcpad, NULL);
197 gst_element_remove_pad (GST_ELEMENT_CAST (self), srcpad);
198 gst_element_remove_pad (GST_ELEMENT_CAST (self), pad);
202 gst_policy_iterate_internal_links (GstPad * pad, GstObject * parent)
204 GstIterator *it = NULL;
207 opad = gst_pad_get_element_private (pad);
209 it = gst_iterator_new_single (GST_TYPE_PAD, (gpointer)opad,
210 (GstCopyFunction)gst_object_ref,
211 (GFreeFunc)gst_object_unref);
218 gst_policy_sink_event (GstPad * pad, GstEvent * event)
222 switch (GST_EVENT_TYPE (event)) {
224 ret = gst_pad_event_default (pad, event);
231 gst_policy_src_event (GstPad * pad, GstEvent * event)
235 switch (GST_EVENT_TYPE (event)) {
237 ret = gst_pad_event_default (pad, event);
244 gst_policy_chain (GstPad * pad, GstBuffer * buf)
246 /* just push out the incoming buffer without touching it */
247 return gst_pad_push (gst_pad_get_element_private (pad), buf);
251 gst_policy_request_new_pad (GstElement * element,
252 GstPadTemplate * templ, const gchar * name)
256 GstPolicy *self = GST_POLICY (element);
258 sinkpad = gst_pad_new_from_template (templ, name);
259 srcpad = gst_pad_new_from_static_template (&src_factory, NULL);
261 gst_pad_set_element_private (sinkpad, srcpad);
262 gst_pad_set_element_private (srcpad, sinkpad);
264 gst_pad_set_chain_function (sinkpad,
265 GST_DEBUG_FUNCPTR (gst_policy_chain));
266 gst_pad_set_iterate_internal_links_function (sinkpad,
267 (GstPadIterIntLinkFunction)gst_policy_iterate_internal_links);
268 gst_pad_set_event_function (sinkpad,
269 GST_DEBUG_FUNCPTR (gst_policy_sink_event));
271 gst_pad_set_iterate_internal_links_function (srcpad,
272 (GstPadIterIntLinkFunction)gst_policy_iterate_internal_links);
273 gst_pad_set_event_function (srcpad,
274 GST_DEBUG_FUNCPTR (gst_policy_src_event));
276 gst_pad_set_active (srcpad, TRUE);
277 gst_pad_set_active (sinkpad, TRUE);
279 gst_element_add_pad (GST_ELEMENT (self), sinkpad);
280 gst_element_add_pad (GST_ELEMENT (self), srcpad);