X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=plugins%2Felements%2Fgstvalve.c;h=9dbc7a6f68f45b5fc446094c7311d447ac246ec6;hb=b17d03cb0ae25a30a2f4640181d13cbb3081e9f5;hp=877d51e20b732c95c43448186fcf4705873f3467;hpb=d110c4db31a628aef84efdb374422b28f9976089;p=platform%2Fupstream%2Fgstreamer.git diff --git a/plugins/elements/gstvalve.c b/plugins/elements/gstvalve.c index 877d51e..9dbc7a6 100644 --- a/plugins/elements/gstvalve.c +++ b/plugins/elements/gstvalve.c @@ -15,27 +15,21 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. * */ /** * SECTION:element-valve + * @title: valve * * The valve is a simple element that drops buffers when the #GstValve:drop * property is set to %TRUE and lets then through otherwise. * - * Any downstream error received while the #GstValve:drop property is %FALSE + * Any downstream error received while the #GstValve:drop property is %TRUE * is ignored. So downstream element can be set to %GST_STATE_NULL and removed, * without using pad blocking. - * - * This element was previously part of gst-plugins-farsight, and then - * gst-plugins-bad. - * - * Documentation last reviewed on 2010-12-30 (0.10.31) - * - * Since: 0.10.32 */ #ifdef HAVE_CONFIG_H @@ -72,9 +66,12 @@ static void gst_valve_set_property (GObject * object, static void gst_valve_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static gboolean gst_valve_event (GstPad * pad, GstEvent * event); -static GstFlowReturn gst_valve_chain (GstPad * pad, GstBuffer * buffer); -static GstCaps *gst_valve_getcaps (GstPad * pad, GstCaps * filter); +static GstFlowReturn gst_valve_chain (GstPad * pad, GstObject * parent, + GstBuffer * buffer); +static gboolean gst_valve_sink_event (GstPad * pad, GstObject * parent, + GstEvent * event); +static gboolean gst_valve_query (GstPad * pad, GstObject * parent, + GstQuery * query); #define _do_init \ GST_DEBUG_CATEGORY_INIT (valve_debug, "valve", 0, "Valve"); @@ -96,14 +93,13 @@ gst_valve_class_init (GstValveClass * klass) g_object_class_install_property (gobject_class, PROP_DROP, g_param_spec_boolean ("drop", "Drop buffers and events", "Whether to drop buffers and events or let them through", - DEFAULT_DROP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + DEFAULT_DROP, G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | + G_PARAM_STATIC_STRINGS)); - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&srctemplate)); - gst_element_class_add_pad_template (gstelement_class, - gst_static_pad_template_get (&sinktemplate)); + gst_element_class_add_static_pad_template (gstelement_class, &srctemplate); + gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate); - gst_element_class_set_details_simple (gstelement_class, "Valve element", + gst_element_class_set_static_metadata (gstelement_class, "Valve element", "Filter", "Drops buffers and events or lets them through", "Olivier Crete "); } @@ -115,17 +111,20 @@ gst_valve_init (GstValve * valve) valve->discont = FALSE; valve->srcpad = gst_pad_new_from_static_template (&srctemplate, "src"); - gst_pad_set_getcaps_function (valve->srcpad, - GST_DEBUG_FUNCPTR (gst_valve_getcaps)); + gst_pad_set_query_function (valve->srcpad, + GST_DEBUG_FUNCPTR (gst_valve_query)); + GST_PAD_SET_PROXY_CAPS (valve->srcpad); gst_element_add_pad (GST_ELEMENT (valve), valve->srcpad); valve->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink"); gst_pad_set_chain_function (valve->sinkpad, GST_DEBUG_FUNCPTR (gst_valve_chain)); gst_pad_set_event_function (valve->sinkpad, - GST_DEBUG_FUNCPTR (gst_valve_event)); - gst_pad_set_getcaps_function (valve->sinkpad, - GST_DEBUG_FUNCPTR (gst_valve_getcaps)); + GST_DEBUG_FUNCPTR (gst_valve_sink_event)); + gst_pad_set_query_function (valve->sinkpad, + GST_DEBUG_FUNCPTR (gst_valve_query)); + GST_PAD_SET_PROXY_CAPS (valve->sinkpad); + GST_PAD_SET_PROXY_ALLOCATION (valve->sinkpad); gst_element_add_pad (GST_ELEMENT (valve), valve->sinkpad); } @@ -139,6 +138,7 @@ gst_valve_set_property (GObject * object, switch (prop_id) { case PROP_DROP: g_atomic_int_set (&valve->drop, g_value_get_boolean (value)); + gst_pad_push_event (valve->sinkpad, gst_event_new_reconfigure ()); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -162,10 +162,29 @@ gst_valve_get_property (GObject * object, } } + +static gboolean +forward_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data) +{ + GstValve *valve = user_data; + + if (!gst_pad_push_event (valve->srcpad, gst_event_ref (*event))) + valve->need_repush_sticky = TRUE; + + return TRUE; +} + +static void +gst_valve_repush_sticky (GstValve * valve) +{ + valve->need_repush_sticky = FALSE; + gst_pad_sticky_events_foreach (valve->sinkpad, forward_sticky_events, valve); +} + static GstFlowReturn -gst_valve_chain (GstPad * pad, GstBuffer * buffer) +gst_valve_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) { - GstValve *valve = GST_VALVE (GST_OBJECT_PARENT (pad)); + GstValve *valve = GST_VALVE (parent); GstFlowReturn ret = GST_FLOW_OK; if (g_atomic_int_get (&valve->drop)) { @@ -178,6 +197,9 @@ gst_valve_chain (GstPad * pad, GstBuffer * buffer) valve->discont = FALSE; } + if (valve->need_repush_sticky) + gst_valve_repush_sticky (valve); + ret = gst_pad_push (valve->srcpad, buffer); } @@ -193,41 +215,43 @@ gst_valve_chain (GstPad * pad, GstBuffer * buffer) static gboolean -gst_valve_event (GstPad * pad, GstEvent * event) +gst_valve_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) { - GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad)); + GstValve *valve; + gboolean is_sticky = GST_EVENT_IS_STICKY (event); gboolean ret = TRUE; - if (g_atomic_int_get (&valve->drop)) + valve = GST_VALVE (parent); + + if (g_atomic_int_get (&valve->drop)) { + valve->need_repush_sticky |= is_sticky; gst_event_unref (event); - else - ret = gst_pad_push_event (valve->srcpad, event); + } else { + if (valve->need_repush_sticky) + gst_valve_repush_sticky (valve); + ret = gst_pad_event_default (pad, parent, event); + } /* Ignore errors if "drop" was changed while the thread was blocked * downwards. */ - if (g_atomic_int_get (&valve->drop)) + if (g_atomic_int_get (&valve->drop)) { + valve->need_repush_sticky |= is_sticky; ret = TRUE; + } - gst_object_unref (valve); return ret; } -static GstCaps * -gst_valve_getcaps (GstPad * pad, GstCaps * filter) -{ - GstValve *valve = GST_VALVE (gst_pad_get_parent (pad)); - GstCaps *caps; - if (pad == valve->sinkpad) - caps = gst_pad_peer_get_caps (valve->srcpad, filter); - else - caps = gst_pad_peer_get_caps (valve->sinkpad, filter); - if (caps == NULL) - caps = (filter ? gst_caps_ref (filter) : gst_caps_new_any ()); +static gboolean +gst_valve_query (GstPad * pad, GstObject * parent, GstQuery * query) +{ + GstValve *valve = GST_VALVE (parent); - gst_object_unref (valve); + if (GST_QUERY_IS_SERIALIZED (query) && g_atomic_int_get (&valve->drop)) + return FALSE; - return caps; + return gst_pad_query_default (pad, parent, query); }