mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-17 12:55:53 +00:00
[MOVED FROM GST-P-FARSIGHT] Rebase valve onto gstelement instead of basetransform
This commit is contained in:
parent
e97d7d9b04
commit
907a660cdc
2 changed files with 53 additions and 84 deletions
|
@ -73,14 +73,10 @@ static void gst_valve_set_property (GObject *object,
|
||||||
static void gst_valve_get_property (GObject *object,
|
static void gst_valve_get_property (GObject *object,
|
||||||
guint prop_id, GValue *value, GParamSpec *pspec);
|
guint prop_id, GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
static GstFlowReturn gst_valve_transform_ip (GstBaseTransform *trans,
|
static gboolean gst_valve_event (GstPad *pad, GstEvent *event);
|
||||||
GstBuffer *buf);
|
|
||||||
static gboolean gst_valve_event (GstBaseTransform *trans, GstEvent *event);
|
|
||||||
static GstFlowReturn gst_valve_buffer_alloc (GstPad * pad, guint64 offset,
|
static GstFlowReturn gst_valve_buffer_alloc (GstPad * pad, guint64 offset,
|
||||||
guint size, GstCaps * caps, GstBuffer ** buf);
|
guint size, GstCaps * caps, GstBuffer ** buf);
|
||||||
static GstFlowReturn gst_valve_prepare_output_buffer (GstBaseTransform *trans,
|
static GstFlowReturn gst_valve_chain (GstPad *pad, GstBuffer *buffer);
|
||||||
GstBuffer * in_buf, gint out_size, GstCaps * out_caps,
|
|
||||||
GstBuffer ** out_buf);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_do_init (GType type)
|
_do_init (GType type)
|
||||||
|
@ -89,8 +85,8 @@ _do_init (GType type)
|
||||||
(valve_debug, "valve", 0, "Valve");
|
(valve_debug, "valve", 0, "Valve");
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_BOILERPLATE_FULL (GstValve, gst_valve, GstBaseTransform,
|
GST_BOILERPLATE_FULL (GstValve, gst_valve, GstElement,
|
||||||
GST_TYPE_BASE_TRANSFORM, _do_init);
|
GST_TYPE_ELEMENT, _do_init);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_valve_base_init (gpointer klass)
|
gst_valve_base_init (gpointer klass)
|
||||||
|
@ -109,23 +105,12 @@ static void
|
||||||
gst_valve_class_init (GstValveClass *klass)
|
gst_valve_class_init (GstValveClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GstBaseTransformClass *gstbasetransform_class;
|
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
gstbasetransform_class = (GstBaseTransformClass *) klass;
|
|
||||||
|
|
||||||
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_valve_set_property);
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_valve_set_property);
|
||||||
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_valve_get_property);
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_valve_get_property);
|
||||||
|
|
||||||
gstbasetransform_class->transform_ip =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_transform_ip);
|
|
||||||
gstbasetransform_class->prepare_output_buffer =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_prepare_output_buffer);
|
|
||||||
gstbasetransform_class->event =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_event);
|
|
||||||
gstbasetransform_class->src_event =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_event);
|
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, ARG_DROP,
|
g_object_class_install_property (gobject_class, ARG_DROP,
|
||||||
g_param_spec_boolean ("drop",
|
g_param_spec_boolean ("drop",
|
||||||
"Drops all buffers if TRUE",
|
"Drops all buffers if TRUE",
|
||||||
|
@ -138,22 +123,20 @@ gst_valve_class_init (GstValveClass *klass)
|
||||||
static void
|
static void
|
||||||
gst_valve_init (GstValve *valve, GstValveClass *klass)
|
gst_valve_init (GstValve *valve, GstValveClass *klass)
|
||||||
{
|
{
|
||||||
|
|
||||||
valve->drop = FALSE;
|
valve->drop = FALSE;
|
||||||
valve->discont = FALSE;
|
valve->discont = FALSE;
|
||||||
|
|
||||||
valve->original_allocfunc =
|
valve->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
|
||||||
GST_BASE_TRANSFORM (valve)->sinkpad->bufferallocfunc;
|
gst_element_add_pad (GST_ELEMENT (valve), valve->srcpad);
|
||||||
|
|
||||||
gst_pad_set_bufferalloc_function (
|
valve->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
|
||||||
GST_BASE_TRANSFORM (valve)->sinkpad,
|
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_bufferalloc_function (valve->sinkpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_valve_buffer_alloc));
|
GST_DEBUG_FUNCPTR (gst_valve_buffer_alloc));
|
||||||
|
gst_element_add_pad (GST_ELEMENT (valve), valve->sinkpad);
|
||||||
|
|
||||||
#if GST_VERSION_MINOR >= 10 && GST_VERSION_MICRO >= 13
|
|
||||||
gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (valve), FALSE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -194,60 +177,51 @@ gst_valve_get_property (GObject *object,
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_valve_prepare_output_buffer (GstBaseTransform *trans, GstBuffer * in_buf,
|
gst_valve_chain (GstPad *pad, GstBuffer *buffer)
|
||||||
gint out_size, GstCaps * out_caps,
|
|
||||||
GstBuffer ** out_buf)
|
|
||||||
{
|
{
|
||||||
GstValve *valve = GST_VALVE (trans);
|
GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
|
gboolean drop;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (GST_OBJECT (trans));
|
GST_OBJECT_LOCK (GST_OBJECT (valve));
|
||||||
if (valve->drop)
|
drop = valve->drop;
|
||||||
|
|
||||||
|
if (!drop && valve->discont)
|
||||||
{
|
{
|
||||||
#if GST_VERSION_MINOR >= 10 && GST_VERSION_MICRO >= 13
|
buffer = gst_buffer_make_metadata_writable (buffer);
|
||||||
ret = GST_BASE_TRANSFORM_FLOW_DROPPED;
|
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
|
||||||
#endif
|
|
||||||
*out_buf = NULL;
|
|
||||||
valve->discont = TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (valve->discont)
|
|
||||||
{
|
|
||||||
*out_buf = gst_buffer_make_metadata_writable (in_buf);
|
|
||||||
GST_BUFFER_FLAG_SET (*out_buf, GST_BUFFER_FLAG_DISCONT);
|
|
||||||
valve->discont = FALSE;
|
valve->discont = FALSE;
|
||||||
|
}
|
||||||
|
GST_OBJECT_UNLOCK (GST_OBJECT (valve));
|
||||||
|
|
||||||
}
|
if (drop)
|
||||||
|
gst_buffer_unref (buffer);
|
||||||
else
|
else
|
||||||
{
|
ret = gst_pad_push (valve->srcpad, buffer);
|
||||||
*out_buf = in_buf;
|
|
||||||
}
|
gst_object_unref (valve);
|
||||||
gst_buffer_ref (*out_buf);
|
|
||||||
}
|
|
||||||
GST_OBJECT_UNLOCK (GST_OBJECT (trans));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
|
||||||
gst_valve_transform_ip (GstBaseTransform *trans, GstBuffer *buf)
|
|
||||||
{
|
|
||||||
return GST_FLOW_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_valve_event (GstBaseTransform *trans, GstEvent *event)
|
gst_valve_event (GstPad *pad, GstEvent *event)
|
||||||
{
|
{
|
||||||
GstValve *valve = GST_VALVE (trans);
|
GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
|
gboolean drop;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (GST_OBJECT (trans));
|
GST_OBJECT_LOCK (GST_OBJECT (valve));
|
||||||
if (valve->drop)
|
drop = valve->drop;
|
||||||
ret = FALSE;
|
GST_OBJECT_UNLOCK (GST_OBJECT (valve));
|
||||||
GST_OBJECT_UNLOCK (GST_OBJECT (trans));
|
|
||||||
|
|
||||||
|
if (drop)
|
||||||
|
gst_event_unref (event);
|
||||||
|
else
|
||||||
|
ret = gst_pad_push_event (valve->srcpad, event);
|
||||||
|
|
||||||
|
gst_object_unref (valve);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,21 +231,16 @@ gst_valve_buffer_alloc (GstPad * pad, guint64 offset, guint size,
|
||||||
{
|
{
|
||||||
GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
|
GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
|
gboolean drop;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (GST_OBJECT (valve));
|
GST_OBJECT_LOCK (GST_OBJECT (valve));
|
||||||
if (valve->drop)
|
drop = valve->drop;
|
||||||
{
|
|
||||||
GST_OBJECT_UNLOCK (GST_OBJECT (valve));
|
GST_OBJECT_UNLOCK (GST_OBJECT (valve));
|
||||||
*buf = gst_buffer_new_and_alloc (size);
|
|
||||||
GST_BUFFER_OFFSET (*buf) = offset;
|
if (drop)
|
||||||
gst_buffer_set_caps (*buf, caps);
|
*buf = NULL;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
ret = gst_pad_alloc_buffer (valve->srcpad, offset, size, caps, buf);
|
||||||
GstPadBufferAllocFunction allocfunc = valve->original_allocfunc;
|
|
||||||
GST_OBJECT_UNLOCK (GST_OBJECT (valve));
|
|
||||||
ret = allocfunc (pad, offset, size, caps, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_object_unref (valve);
|
gst_object_unref (valve);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#define __GST_VALVE_H__
|
#define __GST_VALVE_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/base/gstbasetransform.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ typedef struct _GstValvePrivate GstValvePrivate;
|
||||||
|
|
||||||
struct _GstValve
|
struct _GstValve
|
||||||
{
|
{
|
||||||
GstBaseTransform parent;
|
GstElement parent;
|
||||||
|
|
||||||
/* Protected by the object lock */
|
/* Protected by the object lock */
|
||||||
gboolean drop;
|
gboolean drop;
|
||||||
|
@ -58,7 +57,8 @@ struct _GstValve
|
||||||
/* Protected by the stream lock*/
|
/* Protected by the stream lock*/
|
||||||
gboolean discont;
|
gboolean discont;
|
||||||
|
|
||||||
GstPadBufferAllocFunction original_allocfunc;
|
GstPad *srcpad;
|
||||||
|
GstPad *sinkpad;
|
||||||
|
|
||||||
/*< private > */
|
/*< private > */
|
||||||
gpointer _gst_reserved[GST_PADDING];
|
gpointer _gst_reserved[GST_PADDING];
|
||||||
|
@ -66,7 +66,7 @@ struct _GstValve
|
||||||
|
|
||||||
struct _GstValveClass
|
struct _GstValveClass
|
||||||
{
|
{
|
||||||
GstBaseTransformClass parent_class;
|
GstElementClass parent_class;
|
||||||
|
|
||||||
/*< private > */
|
/*< private > */
|
||||||
gpointer _gst_reserved[GST_PADDING];
|
gpointer _gst_reserved[GST_PADDING];
|
||||||
|
|
Loading…
Reference in a new issue