[vlc-commits] rtp: use smaller packets by default (refs #16315)

Rémi Denis-Courmont git at videolan.org
Sun Apr 17 21:27:48 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr 17 22:27:12 2016 +0300| [840b222697f616a479a1ebb789fe5426b558595a] | committer: Rémi Denis-Courmont

rtp: use smaller packets by default (refs #16315)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=840b222697f616a479a1ebb789fe5426b558595a
---

 modules/access/rtp/input.c |   42 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 38 insertions(+), 4 deletions(-)

diff --git a/modules/access/rtp/input.c b/modules/access/rtp/input.c
index 5397649..7e734c4 100644
--- a/modules/access/rtp/input.c
+++ b/modules/access/rtp/input.c
@@ -41,6 +41,8 @@
 # include <srtp.h>
 #endif
 
+#define DEFAULT_MRU (1500u - (20 + 8))
+
 /**
  * Processes a packet received from the RTP socket.
  */
@@ -104,6 +106,15 @@ void *rtp_dgram_thread (void *opaque)
     demux_sys_t *sys = demux->p_sys;
     mtime_t deadline = VLC_TS_INVALID;
     int rtp_fd = sys->fd;
+    struct iovec iov =
+    {
+        .iov_len = DEFAULT_MRU,
+    };
+    struct msghdr msg =
+    {
+        .msg_iov = &iov,
+        .msg_iovlen = 1,
+    };
 
     struct pollfd ufd[1];
     ufd[0].fd = rtp_fd;
@@ -125,14 +136,37 @@ void *rtp_dgram_thread (void *opaque)
             if (unlikely(ufd[0].revents & POLLHUP))
                 break; /* RTP socket dead (DCCP only) */
 
-            block_t *block = block_Alloc (0xffff); /* TODO: p_sys->mru */
+            block_t *block = block_Alloc (iov.iov_len);
             if (unlikely(block == NULL))
-                break; /* we are totallly screwed */
+            {
+                if (iov.iov_len == DEFAULT_MRU)
+                    break; /* we are totallly screwed */
+                iov.iov_len = DEFAULT_MRU;
+                continue; /* retry with shrunk MRU */
+            }
 
-            ssize_t len = recv (rtp_fd, block->p_buffer, block->i_buffer, 0);
+            iov.iov_base = block->p_buffer;
+#ifdef __linux__
+            msg.msg_flags = MSG_TRUNC;
+#else
+            msg.msg_flags = 0;
+#endif
+
+            ssize_t len = recvmsg (rtp_fd, &msg, 0);
             if (len != -1)
             {
-                block->i_buffer = len;
+#ifdef MSG_TRUNC
+                if (msg.msg_flags & MSG_TRUNC)
+                {
+                    msg_Err(demux, "%zd bytes packet truncated (MRU was %zu)",
+                            len, iov.iov_len);
+                    block->i_flags |= BLOCK_FLAG_CORRUPTED;
+                    iov.iov_len = len;
+                }
+                else
+#endif
+                    block->i_buffer = len;
+
                 rtp_process (demux, block);
             }
             else



More information about the vlc-commits mailing list