[vlc-devel] [PATCH] UDP: use static 65k buffer for receive

Ilkka Ollakka ileoo at videolan.org
Sun Jan 31 12:51:11 CET 2016


Duplicate packets from that, so fifo and stream_cache memory usage
have smaller overhead compared i_size and i_buffer.

Re #16315
---
 modules/access/udp.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/modules/access/udp.c b/modules/access/udp.c
index 9e08b55..f620427 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -267,32 +267,28 @@ static void* ThreadRead( void *data )
 {
     access_t *access = data;
     access_sys_t *sys = access->p_sys;
+    block_t *pkt_buffer = block_Alloc(MTU);
 
     for(;;)
     {
-        block_t *pkt = block_Alloc(MTU);
-        if (unlikely(pkt == NULL))
-        {   /* OOM - dequeue and discard one packet */
-            char dummy;
-            recv(sys->fd, &dummy, 1, 0);
-            continue;
-        }
-
         ssize_t len;
+        block_t *pkt;
 
-        block_cleanup_push(pkt);
+        block_cleanup_push(pkt_buffer);
         do
         {
 #ifndef LIBVLC_USE_PTHREAD
             struct pollfd ufd = { .fd = sys->fd, .events = POLLIN };
             while (poll(&ufd, 1, -1) <= 0); /* cancellation point */
 #endif
-            len = recv(sys->fd, pkt->p_buffer, MTU, 0);
+            len = recv(sys->fd, pkt_buffer->p_buffer, MTU, 0);
         }
         while (len == -1);
         vlc_cleanup_pop();
 
-        pkt->i_buffer = len;
+        pkt_buffer->i_buffer = len;
+
+        pkt = block_Duplicate( pkt_buffer );
 
         vlc_fifo_Lock(sys->fifo);
         /* Discard old buffers on overflow */
@@ -307,6 +303,7 @@ static void* ThreadRead( void *data )
         vlc_fifo_Unlock(sys->fifo);
         vlc_sem_post(&sys->semaphore);
     }
+    block_Release( pkt_buffer );
 
     return NULL;
 }
-- 
2.7.0



More information about the vlc-devel mailing list