multisocketsink: Add support for GstNetControlMessageMeta
authorWilliam Manley <will@williammanley.net>
Thu, 30 Oct 2014 17:53:15 +0000 (17:53 +0000)
committerWim Taymans <wtaymans@redhat.com>
Sat, 14 Mar 2015 12:23:20 +0000 (13:23 +0100)
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
gst/tcp/gstmultisocketsink.c

index ab79e72..f60dc0a 100644 (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)
index fa4eee5..22a7e33 100644 (file)
 #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.
  *