[vlc-devel] [PATCH] network: export SO_RCVBUF & SR_SNDBUF as config options

Tzu-Jung Lee roylee17 at gmail.com
Mon Aug 12 19:31:00 CEST 2013


These buffer sizes have large impact on packet loss.

For high bitrate (e.g. 50Mbps) streaming, we have tunes the system-wise
default sizes on our embedded system (Linux) to:

  net.core.rmem_max = 8388608
  net.core.wmem_max = 8388608
  net.core.rmem_default = 8388608
  net.core.wmem_default = 8388608

But VLC overwrite them with a default value 512 KB.

Also, when we tried to playback high bitrate streaming on a windows
desktop, it also drops packet badly.

This patch allows user to overrite default values set by VLC on our
Linux system, though I haven't managed to build a Windows version
and give it a try.

Signed-off-by: Tzu-Jung Lee <tjlee at ambarella.com>
---
 src/libvlc-module.c | 14 ++++++++++++++
 src/network/udp.c   | 22 ++++++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index a29df0c..7208450 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -535,6 +535,14 @@ static const char *const ppsz_pos_descriptions[] =
         "synchronise clocks for server and client. The detailed settings " \
         "are available in Advanced / Network Sync." )
 
+#define NETWORK_RCVBUF_TEXT N_("Sets the maximum per-socket receive buffer" )
+#define NETWORK_RCVBUF_LONGTEXT N_( "Sets the maximum per-socket receive " \
+        "buffer in bytes" )
+
+#define NETWORK_SNDBUF_TEXT N_("Sets the maximum per-socket send buffer" )
+#define NETWORK_SNDBUF_LONGTEXT N_( "Sets the maximum per-socket send " \
+        "buffer in bytes" )
+
 static const int pi_clock_values[] = { -1, 0, 1 };
 static const char *const ppsz_clock_descriptions[] =
 { N_("Default"), N_("Disable"), N_("Enable") };
@@ -1869,6 +1877,12 @@ vlc_module_begin ()
     add_bool( "network-synchronisation", false, NETSYNC_TEXT,
               NETSYNC_LONGTEXT, true )
 
+    add_integer( "network-rcvbuf", 0x80000, NETWORK_RCVBUF_TEXT,
+                 NETWORK_RCVBUF_LONGTEXT, true )
+
+    add_integer( "network-sndbuf", 0x80000, NETWORK_SNDBUF_TEXT,
+                 NETWORK_SNDBUF_LONGTEXT, true )
+
     add_string( "input-record-path", NULL, INPUT_RECORD_PATH_TEXT,
                 INPUT_RECORD_PATH_LONGTEXT, true )
     add_bool( "input-record-native", true, INPUT_RECORD_NATIVE_TEXT,
diff --git a/src/network/udp.c b/src/network/udp.c
index d3ccf7f..130f013 100644
--- a/src/network/udp.c
+++ b/src/network/udp.c
@@ -96,12 +96,16 @@ static int net_SetupDgramSocket (vlc_object_t *p_obj, int fd,
 #endif
 
 #ifdef SO_RCVBUF
+    int rcvbuf;
+    int sndbuf;
     /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
      * to avoid packet loss caused in case of scheduling hiccups */
-    setsockopt (fd, SOL_SOCKET, SO_RCVBUF,
-                (void *)&(int){ 0x80000 }, sizeof (int));
-    setsockopt (fd, SOL_SOCKET, SO_SNDBUF,
-                (void *)&(int){ 0x80000 }, sizeof (int));
+    rcvbuf = var_InheritInteger( p_obj, "network-rcvbuf" );
+    sndbuf = var_InheritInteger( p_obj, "network-sndbuf" );
+    msg_Dbg( p_obj, "socket rcvbuf: 0x%x", rcvbuf );
+    msg_Dbg( p_obj, "socket sndbuf: 0x%x", sndbuf );
+    setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof (int));
+    setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof (int));
 #endif
 
 #if defined (_WIN32)
@@ -521,6 +525,8 @@ int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
     for (struct addrinfo *ptr = res; ptr != NULL; ptr = ptr->ai_next)
     {
         char *str;
+        int rcvbuf;
+        int sndbuf;
         int fd = net_Socket (p_this, ptr->ai_family, ptr->ai_socktype,
                              ptr->ai_protocol);
         if (fd == -1)
@@ -528,8 +534,12 @@ int net_ConnectDgram( vlc_object_t *p_this, const char *psz_host, int i_port,
 
         /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s)
         * to avoid packet loss caused by scheduling problems */
-        setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &(int){ 0x80000 }, sizeof (int));
-        setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &(int){ 0x80000 }, sizeof (int));
+        rcvbuf = var_InheritInteger( p_this, "network-rcvbuf" );
+        sndbuf = var_InheritInteger( p_this, "network-sndbuf" );
+        msg_Dbg( p_this, "socket rcvbuf: 0x%x", rcvbuf );
+        msg_Dbg( p_this, "socket sndbuf: 0x%x", sndbuf );
+        setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof (int));
+        setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof (int));
 
         /* Allow broadcast sending */
         setsockopt (fd, SOL_SOCKET, SO_BROADCAST, &(int){ 1 }, sizeof (int));
-- 
1.8.3.2




More information about the vlc-devel mailing list