commit 6df2365c61379469008a55f003e5b01ca86a541c
Author: Duncan Palmer <dpalmer@digisoft.tv>
Date:   Mon Feb 9 15:37:23 2015 +1000

    DDTWO-1272 souphttpsrc Set socket recv buffer size.
    
    This is a hack to prevent socket read buffering from effecting hlsdemux
    bitrate calculations. We set the recv buffer size to 2K. So there's very
    little buffering in effect, and the time taken to read data is
    indicative of the network speed.

diff --git a/ext/soup/gstsouphttpsrc.c b/ext/soup/gstsouphttpsrc.c
index 11842f1..c17b3b1 100644
--- a/ext/soup/gstsouphttpsrc.c
+++ b/ext/soup/gstsouphttpsrc.c
@@ -78,6 +78,7 @@
 #include <gst/gstelement.h>
 #include <gst/gst-i18n-plugin.h>
 #include <libsoup/soup.h>
+#include <gio/gio.h>
 #include "gstsouphttpsrc.h"
 #include "gstsouputils.h"
 
@@ -179,6 +180,8 @@ static void gst_soup_http_src_parse_status (SoupMessage * msg,
 static void gst_soup_http_src_chunk_free (gpointer gstbuf);
 static SoupBuffer *gst_soup_http_src_chunk_allocator (SoupMessage * msg,
     gsize max_len, gpointer user_data);
+static void gst_soup_http_src_network_event_cb (SoupMessage * msg,
+    GSocketClientEvent event, GIOStream * connection, GstSoupHTTPSrc * src);
 static void gst_soup_http_src_got_chunk_cb (SoupMessage * msg,
     SoupBuffer * chunk, GstSoupHTTPSrc * src);
 static void gst_soup_http_src_response_cb (SoupSession * session,
@@ -1360,6 +1363,39 @@ gst_soup_http_src_chunk_allocator (SoupMessage * msg, gsize max_len,
   return soupbuf;
 }
 
+#include <sys/types.h>
+#include <sys/socket.h>
+static void
+gst_soup_http_src_network_event_cb (SoupMessage * msg,
+    GSocketClientEvent event, GIOStream * connection, GstSoupHTTPSrc * src)
+{
+  GSocket *s;
+  int sfd;
+  int rcv_buflen = 2048;
+
+  if (G_UNLIKELY (msg != src->msg)) {
+    GST_DEBUG_OBJECT (src, "got network event, but not for current message");
+    return;
+  }
+
+  if (event != G_SOCKET_CLIENT_CONNECTED)
+    return;
+
+  GST_DEBUG_OBJECT (src, "Got new connection");
+
+  s = g_socket_connection_get_socket ((GSocketConnection *) connection);
+  if (!s) {
+    GST_ERROR_OBJECT (src, "failed to get socket");
+    return;
+  }
+
+  sfd = g_socket_get_fd (s);
+  if (setsockopt (sfd, SOL_SOCKET, SO_RCVBUF, &rcv_buflen,
+          sizeof (rcv_buflen)) != 0)
+    GST_ERROR_OBJECT (src, "failed to set reveive buffer length");
+
+}
+
 static void
 gst_soup_http_src_got_chunk_cb (SoupMessage * msg, SoupBuffer * chunk,
     GstSoupHTTPSrc * src)
@@ -1591,6 +1627,8 @@ gst_soup_http_src_build_message (GstSoupHTTPSrc * src, const gchar * method)
       G_CALLBACK (gst_soup_http_src_finished_cb), src);
   g_signal_connect (src->msg, "got_chunk",
       G_CALLBACK (gst_soup_http_src_got_chunk_cb), src);
+  g_signal_connect (src->msg, "network-event",
+      G_CALLBACK (gst_soup_http_src_network_event_cb), src);
   soup_message_set_flags (src->msg, SOUP_MESSAGE_OVERWRITE_CHUNKS |
       (src->automatic_redirect ? 0 : SOUP_MESSAGE_NO_REDIRECT));
   soup_message_set_chunk_allocator (src->msg,
