|
Packit Service |
963350 |
/* GStreamer valve element
|
|
Packit Service |
963350 |
* Copyright 2007-2009 Collabora Ltd
|
|
Packit Service |
963350 |
* @author: Olivier Crete <olivier.crete@collabora.co.uk>
|
|
Packit Service |
963350 |
* Copyright 2007-2009 Nokia Corporation
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
963350 |
* modify it under the terms of the GNU Library General Public
|
|
Packit Service |
963350 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
963350 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
963350 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
963350 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
963350 |
* Library General Public License for more details.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* You should have received a copy of the GNU Library General Public
|
|
Packit Service |
963350 |
* License along with this library; if not, write to the
|
|
Packit Service |
963350 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit Service |
963350 |
* Boston, MA 02110-1301, USA.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* SECTION:element-valve
|
|
Packit Service |
963350 |
* @title: valve
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* The valve is a simple element that drops buffers when the #GstValve:drop
|
|
Packit Service |
963350 |
* property is set to %TRUE and lets then through otherwise.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Any downstream error received while the #GstValve:drop property is %TRUE
|
|
Packit Service |
963350 |
* is ignored. So downstream element can be set to %GST_STATE_NULL and removed,
|
|
Packit Service |
963350 |
* without using pad blocking.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
963350 |
#include "config.h"
|
|
Packit Service |
963350 |
#endif
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include "gstvalve.h"
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include <string.h>
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_DEBUG_CATEGORY_STATIC (valve_debug);
|
|
Packit Service |
963350 |
#define GST_CAT_DEFAULT (valve_debug)
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
Packit Service |
963350 |
GST_PAD_SINK,
|
|
Packit Service |
963350 |
GST_PAD_ALWAYS,
|
|
Packit Service |
963350 |
GST_STATIC_CAPS_ANY);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
Packit Service |
963350 |
GST_PAD_SRC,
|
|
Packit Service |
963350 |
GST_PAD_ALWAYS,
|
|
Packit Service |
963350 |
GST_STATIC_CAPS_ANY);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
enum
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
PROP_0,
|
|
Packit Service |
963350 |
PROP_DROP
|
|
Packit Service |
963350 |
};
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#define DEFAULT_DROP FALSE
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void gst_valve_set_property (GObject * object,
|
|
Packit Service |
963350 |
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
Packit Service |
963350 |
static void gst_valve_get_property (GObject * object,
|
|
Packit Service |
963350 |
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static GstFlowReturn gst_valve_chain (GstPad * pad, GstObject * parent,
|
|
Packit Service |
963350 |
GstBuffer * buffer);
|
|
Packit Service |
963350 |
static gboolean gst_valve_sink_event (GstPad * pad, GstObject * parent,
|
|
Packit Service |
963350 |
GstEvent * event);
|
|
Packit Service |
963350 |
static gboolean gst_valve_query (GstPad * pad, GstObject * parent,
|
|
Packit Service |
963350 |
GstQuery * query);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#define _do_init \
|
|
Packit Service |
963350 |
GST_DEBUG_CATEGORY_INIT (valve_debug, "valve", 0, "Valve");
|
|
Packit Service |
963350 |
#define gst_valve_parent_class parent_class
|
|
Packit Service |
963350 |
G_DEFINE_TYPE_WITH_CODE (GstValve, gst_valve, GST_TYPE_ELEMENT, _do_init);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_valve_class_init (GstValveClass * klass)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GObjectClass *gobject_class;
|
|
Packit Service |
963350 |
GstElementClass *gstelement_class;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gobject_class = (GObjectClass *) klass;
|
|
Packit Service |
963350 |
gstelement_class = (GstElementClass *) (klass);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gobject_class->set_property = gst_valve_set_property;
|
|
Packit Service |
963350 |
gobject_class->get_property = gst_valve_get_property;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
g_object_class_install_property (gobject_class, PROP_DROP,
|
|
Packit Service |
963350 |
g_param_spec_boolean ("drop", "Drop buffers and events",
|
|
Packit Service |
963350 |
"Whether to drop buffers and events or let them through",
|
|
Packit Service |
963350 |
DEFAULT_DROP, G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING |
|
|
Packit Service |
963350 |
G_PARAM_STATIC_STRINGS));
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
|
|
Packit Service |
963350 |
gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gst_element_class_set_static_metadata (gstelement_class, "Valve element",
|
|
Packit Service |
963350 |
"Filter", "Drops buffers and events or lets them through",
|
|
Packit Service |
963350 |
"Olivier Crete <olivier.crete@collabora.co.uk>");
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_valve_init (GstValve * valve)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
valve->drop = FALSE;
|
|
Packit Service |
963350 |
valve->discont = FALSE;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
valve->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
|
|
Packit Service |
963350 |
gst_pad_set_query_function (valve->srcpad,
|
|
Packit Service |
963350 |
GST_DEBUG_FUNCPTR (gst_valve_query));
|
|
Packit Service |
963350 |
GST_PAD_SET_PROXY_CAPS (valve->srcpad);
|
|
Packit Service |
963350 |
gst_element_add_pad (GST_ELEMENT (valve), valve->srcpad);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
valve->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
|
|
Packit Service |
963350 |
gst_pad_set_chain_function (valve->sinkpad,
|
|
Packit Service |
963350 |
GST_DEBUG_FUNCPTR (gst_valve_chain));
|
|
Packit Service |
963350 |
gst_pad_set_event_function (valve->sinkpad,
|
|
Packit Service |
963350 |
GST_DEBUG_FUNCPTR (gst_valve_sink_event));
|
|
Packit Service |
963350 |
gst_pad_set_query_function (valve->sinkpad,
|
|
Packit Service |
963350 |
GST_DEBUG_FUNCPTR (gst_valve_query));
|
|
Packit Service |
963350 |
GST_PAD_SET_PROXY_CAPS (valve->sinkpad);
|
|
Packit Service |
963350 |
GST_PAD_SET_PROXY_ALLOCATION (valve->sinkpad);
|
|
Packit Service |
963350 |
gst_element_add_pad (GST_ELEMENT (valve), valve->sinkpad);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_valve_set_property (GObject * object,
|
|
Packit Service |
963350 |
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstValve *valve = GST_VALVE (object);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
switch (prop_id) {
|
|
Packit Service |
963350 |
case PROP_DROP:
|
|
Packit Service |
963350 |
g_atomic_int_set (&valve->drop, g_value_get_boolean (value));
|
|
Packit Service |
963350 |
gst_pad_push_event (valve->sinkpad, gst_event_new_reconfigure ());
|
|
Packit Service |
963350 |
break;
|
|
Packit Service |
963350 |
default:
|
|
Packit Service |
963350 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit Service |
963350 |
break;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_valve_get_property (GObject * object,
|
|
Packit Service |
963350 |
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstValve *valve = GST_VALVE (object);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
switch (prop_id) {
|
|
Packit Service |
963350 |
case PROP_DROP:
|
|
Packit Service |
963350 |
g_value_set_boolean (value, g_atomic_int_get (&valve->drop));
|
|
Packit Service |
963350 |
break;
|
|
Packit Service |
963350 |
default:
|
|
Packit Service |
963350 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit Service |
963350 |
break;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static gboolean
|
|
Packit Service |
963350 |
forward_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstValve *valve = user_data;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (!gst_pad_push_event (valve->srcpad, gst_event_ref (*event)))
|
|
Packit Service |
963350 |
valve->need_repush_sticky = TRUE;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return TRUE;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_valve_repush_sticky (GstValve * valve)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
valve->need_repush_sticky = FALSE;
|
|
Packit Service |
963350 |
gst_pad_sticky_events_foreach (valve->sinkpad, forward_sticky_events, valve);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static GstFlowReturn
|
|
Packit Service |
963350 |
gst_valve_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstValve *valve = GST_VALVE (parent);
|
|
Packit Service |
963350 |
GstFlowReturn ret = GST_FLOW_OK;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (g_atomic_int_get (&valve->drop)) {
|
|
Packit Service |
963350 |
gst_buffer_unref (buffer);
|
|
Packit Service |
963350 |
valve->discont = TRUE;
|
|
Packit Service |
963350 |
} else {
|
|
Packit Service |
963350 |
if (valve->discont) {
|
|
Packit Service |
963350 |
buffer = gst_buffer_make_writable (buffer);
|
|
Packit Service |
963350 |
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
|
Packit Service |
963350 |
valve->discont = FALSE;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (valve->need_repush_sticky)
|
|
Packit Service |
963350 |
gst_valve_repush_sticky (valve);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
ret = gst_pad_push (valve->srcpad, buffer);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* Ignore errors if "drop" was changed while the thread was blocked
|
|
Packit Service |
963350 |
* downwards
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
if (g_atomic_int_get (&valve->drop))
|
|
Packit Service |
963350 |
ret = GST_FLOW_OK;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return ret;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static gboolean
|
|
Packit Service |
963350 |
gst_valve_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstValve *valve;
|
|
Packit Service |
963350 |
gboolean is_sticky = GST_EVENT_IS_STICKY (event);
|
|
Packit Service |
963350 |
gboolean ret = TRUE;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
valve = GST_VALVE (parent);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (g_atomic_int_get (&valve->drop)) {
|
|
Packit Service |
963350 |
valve->need_repush_sticky |= is_sticky;
|
|
Packit Service |
963350 |
gst_event_unref (event);
|
|
Packit Service |
963350 |
} else {
|
|
Packit Service |
963350 |
if (valve->need_repush_sticky)
|
|
Packit Service |
963350 |
gst_valve_repush_sticky (valve);
|
|
Packit Service |
963350 |
ret = gst_pad_event_default (pad, parent, event);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* Ignore errors if "drop" was changed while the thread was blocked
|
|
Packit Service |
963350 |
* downwards.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
if (g_atomic_int_get (&valve->drop)) {
|
|
Packit Service |
963350 |
valve->need_repush_sticky |= is_sticky;
|
|
Packit Service |
963350 |
ret = TRUE;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return ret;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static gboolean
|
|
Packit Service |
963350 |
gst_valve_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstValve *valve = GST_VALVE (parent);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (GST_QUERY_IS_SERIALIZED (query) && g_atomic_int_get (&valve->drop))
|
|
Packit Service |
963350 |
return FALSE;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return gst_pad_query_default (pad, parent, query);
|
|
Packit Service |
963350 |
}
|