[vlc-commits] stream: simplify stream_fifo using pf_block

Rémi Denis-Courmont git at videolan.org
Thu Jul 21 21:30:17 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jul 20 18:43:21 2016 +0300| [376a4990f45279273130428445bd8334567c44e7] | committer: Rémi Denis-Courmont

stream: simplify stream_fifo using pf_block

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

 src/input/stream_fifo.c |   54 ++++++++++++-----------------------------------
 1 file changed, 14 insertions(+), 40 deletions(-)

diff --git a/src/input/stream_fifo.c b/src/input/stream_fifo.c
index f468bd1..180a08b 100644
--- a/src/input/stream_fifo.c
+++ b/src/input/stream_fifo.c
@@ -36,7 +36,6 @@
 struct stream_sys_t
 {
     vlc_fifo_t *fifo;
-    block_t *block;
     bool eof;
 };
 
@@ -47,9 +46,6 @@ static void vlc_stream_fifo_Destroy(stream_t *s)
     block_t *block;
     bool closed;
 
-    if (sys->block != NULL)
-        block_Release(sys->block);
-
     vlc_fifo_Lock(fifo);
     block = vlc_fifo_DequeueAllUnlocked(fifo);
     closed = sys->eof;
@@ -65,47 +61,26 @@ static void vlc_stream_fifo_Destroy(stream_t *s)
     }
 }
 
-static ssize_t vlc_stream_fifo_Read(stream_t *s, void *buf, size_t len)
+static block_t *vlc_stream_fifo_Block(stream_t *s, bool *restrict eof)
 {
     stream_sys_t *sys = s->p_sys;
-    block_t *block = sys->block;
+    vlc_fifo_t *fifo = sys->fifo;
+    block_t *block;
 
-    while (block == NULL)
+    vlc_fifo_Lock(fifo);
+    while (vlc_fifo_IsEmpty(fifo))
     {
-        vlc_fifo_t *fifo = sys->fifo;
-
-        vlc_fifo_Lock(fifo);
-        while (vlc_fifo_IsEmpty(fifo))
+        if (sys->eof)
         {
-            if (sys->eof)
-            {
-                vlc_fifo_Unlock(fifo);
-                return 0;
-            }
-            vlc_fifo_Wait(fifo);
+            *eof = true;
+            break;
         }
-        block = vlc_fifo_DequeueUnlocked(fifo);
-        vlc_fifo_Unlock(fifo);
-        assert(block != NULL);
-    }
-
-    if (len > block->i_buffer)
-        len = block->i_buffer;
-
-    if (likely(len > 0))
-        memcpy(buf, block->p_buffer, len);
-
-    block->p_buffer += len;
-    block->i_buffer -= len;
-
-    if (block->i_buffer == 0)
-    {
-        block_Release(block);
-        block = NULL;
+        vlc_fifo_Wait(fifo);
     }
 
-    sys->block = block;
-    return len;
+    block = vlc_fifo_DequeueUnlocked(fifo);
+    vlc_fifo_Unlock(fifo);
+    return block;
 }
 
 static int vlc_stream_fifo_Control(stream_t *s, int query, va_list ap)
@@ -144,7 +119,6 @@ stream_t *vlc_stream_fifo_New(vlc_object_t *parent)
         return NULL;
     }
 
-    sys->block = NULL;
     sys->eof = false;
 
     stream_t *s = stream_CommonNew(parent, vlc_stream_fifo_Destroy);
@@ -155,9 +129,9 @@ stream_t *vlc_stream_fifo_New(vlc_object_t *parent)
         return NULL;
     }
 
-    s->pf_read = vlc_stream_fifo_Read;
+    s->pf_block = vlc_stream_fifo_Block;
     s->pf_seek = NULL;
-    s->pf_control= vlc_stream_fifo_Control;
+    s->pf_control = vlc_stream_fifo_Control;
     s->p_sys = sys;
     return vlc_object_hold(s);
 }



More information about the vlc-commits mailing list