socketsrc: Add support for GstNetControlMessageMeta
authorWilliam Manley <will@williammanley.net>
Fri, 13 Mar 2015 16:19:28 +0000 (16:19 +0000)
committerWim Taymans <wtaymans@redhat.com>
Sat, 14 Mar 2015 12:23:28 +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.

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.

gst/tcp/gstsocketsrc.c

index 219f653..81eef0a 100644 (file)
@@ -49,6 +49,7 @@
 #endif
 
 #include <gst/gst-i18n-plugin.h>
+#include <gst/net/gstnetcontrolmessagemeta.h>
 #include "gstsocketsrc.h"
 #include "gsttcp.h"
 
@@ -167,6 +168,11 @@ gst_socket_src_fill (GstPushSrc * psrc, GstBuffer * outbuf)
   GError *err = NULL;
   GstMapInfo map;
   GSocket *socket = NULL;
+  GSocketControlMessage **messages = NULL;
+  gint num_messages = 0;
+  gint i;
+  GInputVector ivec;
+  gint flags = 0;
 
   src = GST_SOCKET_SRC (psrc);
 
@@ -184,10 +190,20 @@ gst_socket_src_fill (GstPushSrc * psrc, GstBuffer * outbuf)
 
 retry:
   gst_buffer_map (outbuf, &map, GST_MAP_READWRITE);
-  rret = g_socket_receive_with_blocking (socket, (gchar *) map.data,
-      map.size, TRUE, src->cancellable, &err);
+  ivec.buffer = map.data;
+  ivec.size = map.size;
+  rret =
+      g_socket_receive_message (socket, NULL, &ivec, 1, &messages,
+      &num_messages, &flags, src->cancellable, &err);
   gst_buffer_unmap (outbuf, &map);
 
+  for (i = 0; i < num_messages; i++) {
+    gst_buffer_add_net_control_message_meta (outbuf, messages[i]);
+    g_object_unref (messages[i]);
+    messages[i] = NULL;
+  }
+  g_free (messages);
+
   if (rret == 0) {
     GSocket *tmp = NULL;
     GST_DEBUG_OBJECT (src, "Received EOS on socket %p fd %i", socket,