mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-26 07:00:13 -05:00
Introduce the concept of a Node
Make an object for a processing node. Implement a sink node. Make it possible to implement Sink and Source interfaces to provide input/output from the node. Improve pinosdepay to track fds and handle format changes.
This commit is contained in:
parent
7597e48e02
commit
b885d40390
27 changed files with 3150 additions and 160 deletions
|
|
@ -53,8 +53,13 @@
|
|||
GST_DEBUG_CATEGORY_STATIC (gst_pinos_depay_debug_category);
|
||||
#define GST_CAT_DEFAULT gst_pinos_depay_debug_category
|
||||
|
||||
/* prototypes */
|
||||
static GQuark fdids_quark;
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CAPS,
|
||||
};
|
||||
|
||||
/* pad templates */
|
||||
static GstStaticPadTemplate gst_pinos_depay_src_template =
|
||||
|
|
@ -71,22 +76,97 @@ GST_STATIC_PAD_TEMPLATE ("sink",
|
|||
|
||||
|
||||
/* class initialization */
|
||||
G_DEFINE_TYPE (GstPinosDepay, gst_pinos_depay, GST_TYPE_ELEMENT);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GstPinosDepay, gst_pinos_depay, GST_TYPE_ELEMENT,
|
||||
GST_DEBUG_CATEGORY_INIT (gst_pinos_depay_debug_category, "pinosdepay", 0,
|
||||
"debug category for pinosdepay element"));
|
||||
static gboolean
|
||||
gst_pinos_depay_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
||||
{
|
||||
GstPinosDepay *depay = GST_PINOS_DEPAY (parent);
|
||||
gboolean res = FALSE;
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_SEGMENT:
|
||||
{
|
||||
GstSegment segment;
|
||||
|
||||
gst_segment_init (&segment, GST_FORMAT_TIME);
|
||||
|
||||
res = gst_pad_push_event (depay->srcpad, gst_event_new_segment (&segment));
|
||||
break;
|
||||
}
|
||||
case GST_EVENT_CAPS:
|
||||
{
|
||||
GstCaps *caps;
|
||||
GstStructure *str;
|
||||
|
||||
gst_event_parse_caps (event, &caps);
|
||||
str = gst_caps_get_structure (caps, 0);
|
||||
depay->pinos_input = gst_structure_has_name (str, "application/x-pinos");
|
||||
gst_event_unref (event);
|
||||
|
||||
res = gst_pad_push_event (depay->srcpad, gst_event_new_caps (depay->caps));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
res = gst_pad_event_default (pad, parent, event);
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
release_fds (GstPinosDepay *this, GstBuffer *buffer)
|
||||
{
|
||||
GArray *fdids;
|
||||
guint i;
|
||||
PinosBufferBuilder b;
|
||||
PinosPacketReleaseFDPayload r;
|
||||
PinosBuffer pbuf;
|
||||
gsize size;
|
||||
gpointer data;
|
||||
GstBuffer *outbuf;
|
||||
GstEvent *ev;
|
||||
|
||||
fdids = gst_mini_object_steal_qdata (GST_MINI_OBJECT_CAST (buffer),
|
||||
fdids_quark);
|
||||
if (fdids == NULL)
|
||||
return;
|
||||
|
||||
pinos_buffer_builder_init (&b);
|
||||
|
||||
for (i = 0; i < fdids->len; i++) {
|
||||
r.id = g_array_index (fdids, guint32, i);
|
||||
GST_LOG ("release fd index %d", r.id);
|
||||
pinos_buffer_builder_add_release_fd_payload (&b, &r);
|
||||
}
|
||||
pinos_buffer_builder_end (&b, &pbuf);
|
||||
g_array_unref (fdids);
|
||||
|
||||
data = pinos_buffer_steal (&pbuf, &size, NULL);
|
||||
|
||||
outbuf = gst_buffer_new_wrapped (data, size);
|
||||
ev = gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
|
||||
gst_structure_new ("GstNetworkMessage",
|
||||
"object", G_TYPE_OBJECT, this,
|
||||
"buffer", GST_TYPE_BUFFER, outbuf, NULL));
|
||||
gst_buffer_unref (outbuf);
|
||||
|
||||
gst_pad_push_event (this->sinkpad, ev);
|
||||
g_object_unref (this);
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_pinos_depay_chain (GstPad *pad, GstObject * parent, GstBuffer * buffer)
|
||||
{
|
||||
GstPinosDepay *depay = GST_PINOS_DEPAY (parent);
|
||||
GstBuffer *outbuf;
|
||||
GstBuffer *outbuf = NULL;
|
||||
GstMapInfo info;
|
||||
PinosBuffer pbuf;
|
||||
PinosBufferIter it;
|
||||
GstNetControlMessageMeta * meta;
|
||||
GSocketControlMessage *msg = NULL;
|
||||
GError *err = NULL;
|
||||
GArray *fdids = NULL;
|
||||
|
||||
meta = ((GstNetControlMessageMeta*) gst_buffer_get_meta (
|
||||
buffer, GST_NET_CONTROL_MESSAGE_META_API_TYPE));
|
||||
|
|
@ -96,13 +176,6 @@ gst_pinos_depay_chain (GstPad *pad, GstObject * parent, GstBuffer * buffer)
|
|||
meta = NULL;
|
||||
}
|
||||
|
||||
if (msg == NULL) {
|
||||
gst_buffer_unref (buffer);
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
outbuf = gst_buffer_new ();
|
||||
|
||||
gst_buffer_map (buffer, &info, GST_MAP_READ);
|
||||
pinos_buffer_init_data (&pbuf, info.data, info.size, msg);
|
||||
|
||||
|
|
@ -113,9 +186,21 @@ gst_pinos_depay_chain (GstPad *pad, GstObject * parent, GstBuffer * buffer)
|
|||
{
|
||||
PinosPacketHeader hdr;
|
||||
|
||||
if (!pinos_buffer_iter_parse_header (&it, &hdr))
|
||||
if (!pinos_buffer_iter_parse_header (&it, &hdr))
|
||||
goto error;
|
||||
|
||||
if (outbuf == NULL)
|
||||
outbuf = gst_buffer_new ();
|
||||
|
||||
GST_INFO ("pts %" G_GUINT64_FORMAT ", dts_offset %"G_GUINT64_FORMAT, hdr.pts, hdr.dts_offset);
|
||||
|
||||
#if 0
|
||||
if (GST_CLOCK_TIME_IS_VALID (hdr.pts)) {
|
||||
GST_BUFFER_PTS (outbuf) = hdr.pts;
|
||||
if (GST_BUFFER_PTS (outbuf) + hdr.dts_offset > 0)
|
||||
GST_BUFFER_DTS (outbuf) = GST_BUFFER_PTS (outbuf) + hdr.dts_offset;
|
||||
}
|
||||
#endif
|
||||
GST_BUFFER_OFFSET (outbuf) = hdr.seq;
|
||||
break;
|
||||
}
|
||||
|
|
@ -131,10 +216,35 @@ gst_pinos_depay_chain (GstPad *pad, GstObject * parent, GstBuffer * buffer)
|
|||
if (fd == -1)
|
||||
goto error;
|
||||
|
||||
if (outbuf == NULL)
|
||||
outbuf = gst_buffer_new ();
|
||||
|
||||
fdmem = gst_fd_allocator_alloc (depay->fd_allocator, fd,
|
||||
p.offset + p.size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (fdmem, p.offset, p.size);
|
||||
gst_buffer_append_memory (outbuf, fdmem);
|
||||
|
||||
if (fdids == NULL)
|
||||
fdids = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
|
||||
GST_LOG ("track fd index %d", p.id);
|
||||
g_array_append_val (fdids, p.id);
|
||||
break;
|
||||
}
|
||||
case PINOS_PACKET_TYPE_FORMAT_CHANGE:
|
||||
{
|
||||
PinosPacketFormatChange change;
|
||||
GstCaps *caps;
|
||||
|
||||
if (!pinos_buffer_iter_parse_format_change (&it, &change))
|
||||
goto error;
|
||||
GST_DEBUG ("got format change %d %s", change.id, change.format);
|
||||
|
||||
caps = gst_caps_from_string (change.format);
|
||||
if (caps) {
|
||||
gst_caps_take (&depay->caps, caps);
|
||||
gst_pad_push_event (depay->srcpad, gst_event_new_caps (depay->caps));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -145,7 +255,17 @@ gst_pinos_depay_chain (GstPad *pad, GstObject * parent, GstBuffer * buffer)
|
|||
gst_buffer_unmap (buffer, &info);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
return gst_pad_push (depay->srcpad, outbuf);
|
||||
if (outbuf) {
|
||||
if (fdids != NULL) {
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (outbuf),
|
||||
fdids_quark, fdids, NULL);
|
||||
gst_mini_object_weak_ref (GST_MINI_OBJECT_CAST (outbuf),
|
||||
(GstMiniObjectNotify) release_fds, g_object_ref (depay));
|
||||
}
|
||||
return gst_pad_push (depay->srcpad, outbuf);
|
||||
}
|
||||
else
|
||||
return GST_FLOW_OK;
|
||||
|
||||
error:
|
||||
{
|
||||
|
|
@ -157,6 +277,45 @@ error:
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pinos_depay_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstPinosDepay *depay = GST_PINOS_DEPAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CAPS:
|
||||
{
|
||||
const GstCaps *caps;
|
||||
|
||||
caps = gst_value_get_caps (value);
|
||||
gst_caps_replace (&depay->caps, (GstCaps *)caps);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pinos_depay_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstPinosDepay *depay = GST_PINOS_DEPAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_CAPS:
|
||||
gst_value_set_caps (value, depay->caps);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pinos_depay_finalize (GObject * object)
|
||||
{
|
||||
|
|
@ -164,6 +323,7 @@ gst_pinos_depay_finalize (GObject * object)
|
|||
|
||||
GST_DEBUG_OBJECT (depay, "finalize");
|
||||
|
||||
gst_caps_replace (&depay->caps, NULL);
|
||||
g_object_unref (depay->fd_allocator);
|
||||
|
||||
G_OBJECT_CLASS (gst_pinos_depay_parent_class)->finalize (object);
|
||||
|
|
@ -176,6 +336,15 @@ gst_pinos_depay_class_init (GstPinosDepayClass * klass)
|
|||
GstElementClass *element_class =
|
||||
GST_ELEMENT_CLASS (klass);
|
||||
|
||||
gobject_class->finalize = gst_pinos_depay_finalize;
|
||||
gobject_class->set_property = gst_pinos_depay_set_property;
|
||||
gobject_class->get_property = gst_pinos_depay_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_CAPS,
|
||||
g_param_spec_boxed ("caps", "Caps",
|
||||
"The caps of the source pad", GST_TYPE_CAPS,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/* Setting up pads and setting metadata should be moved to
|
||||
base_class_init if you intend to subclass this class. */
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
|
|
@ -188,7 +357,10 @@ gst_pinos_depay_class_init (GstPinosDepayClass * klass)
|
|||
"Pinos Depayloader for zero-copy IPC via Pinos",
|
||||
"Wim Taymans <wim.taymans@gmail.com>");
|
||||
|
||||
gobject_class->finalize = gst_pinos_depay_finalize;
|
||||
GST_DEBUG_CATEGORY_INIT (gst_pinos_depay_debug_category, "pinosdepay", 0,
|
||||
"debug category for pinosdepay element");
|
||||
|
||||
fdids_quark = g_quark_from_static_string ("GstPinosDepayFDIds");
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -199,6 +371,7 @@ gst_pinos_depay_init (GstPinosDepay * depay)
|
|||
|
||||
depay->sinkpad = gst_pad_new_from_static_template (&gst_pinos_depay_sink_template, "sink");
|
||||
gst_pad_set_chain_function (depay->sinkpad, gst_pinos_depay_chain);
|
||||
gst_pad_set_event_function (depay->sinkpad, gst_pinos_depay_sink_event);
|
||||
gst_element_add_pad (GST_ELEMENT (depay), depay->sinkpad);
|
||||
|
||||
depay->fd_allocator = gst_fd_allocator_new ();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue