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.
This commit is contained in:
William Manley 2014-10-30 17:53:15 +00:00 committed by Wim Taymans
parent a297b0545f
commit e63e023e30
2 changed files with 26 additions and 4 deletions

View file

@ -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)

View file

@ -103,6 +103,7 @@
#endif
#include <gst/gst-i18n-plugin.h>
#include <gst/net/gstnetcontrolmessagemeta.h>
#include <string.h>
@ -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.
*