[vlc-commits] stream_demux: simplify pf_read()

Rémi Denis-Courmont git at videolan.org
Tue Aug 25 20:33:14 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 24 22:25:53 2015 +0300| [bbb022135e4d3b64a261be352a7b4b2912f18d98] | committer: Rémi Denis-Courmont

stream_demux: simplify pf_read()

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

 src/input/stream_demux.c |   59 +++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 30 deletions(-)

diff --git a/src/input/stream_demux.c b/src/input/stream_demux.c
index 3be6690..22ee8ff 100644
--- a/src/input/stream_demux.c
+++ b/src/input/stream_demux.c
@@ -173,46 +173,45 @@ static void DStreamDelete( stream_t *s )
 }
 
 
-static ssize_t DStreamRead( stream_t *s, void *p_read, size_t i_read )
+static ssize_t DStreamRead( stream_t *s, void *buf, size_t len )
 {
-    stream_sys_t *p_sys = s->p_sys;
-    uint8_t *p_out = p_read;
-    size_t i_out = 0;
+    stream_sys_t *sys = s->p_sys;
+
+    if( !atomic_load( &sys->active ) )
+        return -1;
+    if( s->b_error )
+        return -1;
+    if( len == 0 )
+        return 0;
 
     //msg_Dbg( s, "DStreamRead: wanted %d bytes", i_read );
 
-    while( atomic_load( &p_sys->active ) && !s->b_error && i_read )
+    block_t *block = sys->p_block;
+    if( block == NULL )
     {
-        block_t *p_block = p_sys->p_block;
-        size_t i_copy;
-
-        if( !p_block )
+        block = block_FifoGet( sys->p_fifo );
+        if( block == NULL )
         {
-            p_block = block_FifoGet( p_sys->p_fifo );
-            if( !p_block ) s->b_error = 1;
-            p_sys->p_block = p_block;
+            s->b_error = true;
+            return -1;
         }
+        sys->p_block = block;
+    }
 
-        if( p_block && i_read )
-        {
-            i_copy = __MIN( i_read, p_block->i_buffer );
-            if( p_out && i_copy ) memcpy( p_out, p_block->p_buffer, i_copy );
-            i_read -= i_copy;
-            if ( p_out ) p_out += i_copy;
-            i_out += i_copy;
-            p_block->i_buffer -= i_copy;
-            p_block->p_buffer += i_copy;
-
-            if( !p_block->i_buffer )
-            {
-                block_Release( p_block );
-                p_sys->p_block = NULL;
-            }
-        }
+    size_t copy = __MIN( len, block->i_buffer );
+    if( buf != NULL && copy > 0 )
+        memcpy( buf, block->p_buffer, copy );
+
+    block->p_buffer += copy;
+    block->i_buffer -= copy;
+    if( block->i_buffer == 0 )
+    {
+        block_Release( block );
+        sys->p_block = NULL;
     }
 
-    p_sys->i_pos += i_out;
-    return i_out;
+    sys->i_pos += copy;
+    return copy;
 }
 
 static int DStreamControl( stream_t *s, int i_query, va_list args )



More information about the vlc-commits mailing list