From e63e023e300fd8ab778758dad6a28fa5cea154d2 Mon Sep 17 00:00:00 2001 From: William Manley Date: Thu, 30 Oct 2014 17:53:15 +0000 Subject: [PATCH] multisocketsink: Add support for GstNetControlMessageMeta multisocketsink now understands the new GstNetControlMessageMeta to allow sending control messages (ancillary data) with data when writing to Unix domain sockets. A later commit will introduce a new socketsrc element which will similarly understand `GstNetControlMessageMeta`. This, when used with a `GSocketControlMessage` of type `GUnixFDMessage` will allow GStreamer to send and receive file-descriptions in ancillary data, the first step to using memfds to implement zero-copy video IPC. Thanks to glib's `GSocketControlMessage` abstraction the code introduced in this commit is entirely portable and doesn't introduce and additional dependencies or conditionally compiled code, even if it is unlikely to be of much use on non-UNIX systems. --- configure.ac | 1 + gst/tcp/gstmultisocketsink.c | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index ab79e72..f60dc0a 100644 --- a/configure.ac +++ b/configure.ac @@ -255,6 +255,7 @@ ORC_CHECK([0.4.23]) dnl checks for gstreamer dnl uninstalled is selected preferentially -- see pkg-config(1) AG_GST_CHECK_GST($GST_API_VERSION, [$GST_REQ], yes) +AG_GST_CHECK_GST_NET($GST_API_VERSION, [$GST_REQ], yes) AG_GST_CHECK_GST_BASE($GST_API_VERSION, [$GST_REQ], yes) AG_GST_CHECK_GST_CONTROLLER($GST_API_VERSION, [$GST_REQ], yes) AG_GST_CHECK_GST_CHECK($GST_API_VERSION, [$GST_REQ], no) diff --git a/gst/tcp/gstmultisocketsink.c b/gst/tcp/gstmultisocketsink.c index fa4eee5..22a7e33 100644 --- a/gst/tcp/gstmultisocketsink.c +++ b/gst/tcp/gstmultisocketsink.c @@ -103,6 +103,7 @@ #endif #include +#include #include @@ -672,6 +673,25 @@ unmap_n_memorys (GstMapInfo * mapinfo, int num_mappings) gst_memory_unmap (mapinfo[i].memory, &mapinfo[i]); } +static gsize +gst_buffer_get_cmsg_list (GstBuffer * buf, GSocketControlMessage ** msgs, + gsize msg_space) +{ + gpointer iter_state = NULL; + GstMeta *meta; + gsize msg_count = 0; + + while ((meta = gst_buffer_iterate_meta (buf, &iter_state)) != NULL + && msg_count < msg_space) { + if (meta->info->api == GST_NET_CONTROL_MESSAGE_META_API_TYPE) + msgs[msg_count++] = ((GstNetControlMessageMeta *) meta)->message; + } + + return msg_count; +} + +#define CMSG_MAX 255 + static gssize gst_multi_socket_sink_write (GstMultiSocketSink * sink, GSocket * sock, GstBuffer * buffer, gsize bufoffset, @@ -681,19 +701,20 @@ gst_multi_socket_sink_write (GstMultiSocketSink * sink, GOutputVector vec[8]; guint mems_mapped; gssize wrote; + GSocketControlMessage *cmsgs[CMSG_MAX]; + gsize msg_count; mems_mapped = map_n_memory_output_vector (buffer, bufoffset, vec, maps, 8); + msg_count = gst_buffer_get_cmsg_list (buffer, cmsgs, CMSG_MAX); + wrote = - g_socket_send_message (sock, NULL, vec, mems_mapped, NULL, 0, 0, + g_socket_send_message (sock, NULL, vec, mems_mapped, cmsgs, msg_count, 0, cancellable, err); - unmap_n_memorys (maps, mems_mapped); - return wrote; } - /* Handle a write on a client, * which indicates a read request from a client. * -- 2.7.4