[vlc-devel] [PATCH] stream: pass block flags if read size and block size match

Thomas Guillem thomas at gllm.fr
Sat Jul 1 15:24:45 CEST 2017


This allow to pass block flags to a demux inside a demux_chained. This works
only if the block size and the read size match. This is the case for ts via rtp
for example.
---
 src/input/stream.c | 42 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/src/input/stream.c b/src/input/stream.c
index affc7b2c0d..5b3ddffc89 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -387,7 +387,8 @@ static ssize_t vlc_stream_CopyBlock(block_t **restrict pp,
     return likely(len > 0) ? (ssize_t)len : -1;
 }
 
-static ssize_t vlc_stream_ReadRaw(stream_t *s, void *buf, size_t len)
+static ssize_t vlc_stream_ReadRaw(stream_t *s, void *buf, size_t len,
+                                  uint32_t *block_flags)
 {
     stream_priv_t *priv = (stream_priv_t *)s;
     ssize_t ret;
@@ -424,14 +425,19 @@ static ssize_t vlc_stream_ReadRaw(stream_t *s, void *buf, size_t len)
         priv->block = s->pf_block(s, &eof);
         ret = vlc_stream_CopyBlock(&priv->block, buf, len);
         if (ret >= 0)
+        {
+            if (block_flags != NULL)
+                *block_flags = priv->block->i_flags;
             return ret;
+        }
         return eof ? 0 : -1;
     }
 
     return 0;
 }
 
-ssize_t vlc_stream_ReadPartial(stream_t *s, void *buf, size_t len)
+static ssize_t vlc_stream_ReadPartialInternal(stream_t *s, void *buf, size_t len,
+                                              uint32_t *block_flags)
 {
     stream_priv_t *priv = (stream_priv_t *)s;
     ssize_t ret;
@@ -444,7 +450,7 @@ ssize_t vlc_stream_ReadPartial(stream_t *s, void *buf, size_t len)
         return ret;
     }
 
-    ret = vlc_stream_ReadRaw(s, buf, len);
+    ret = vlc_stream_ReadRaw(s, buf, len, block_flags);
     if (ret > 0)
         priv->offset += ret;
     if (ret == 0)
@@ -453,6 +459,11 @@ ssize_t vlc_stream_ReadPartial(stream_t *s, void *buf, size_t len)
     return ret;
 }
 
+ssize_t vlc_stream_ReadPartial(stream_t *s, void *buf, size_t len)
+{
+    return vlc_stream_ReadPartialInternal(s, buf, len, NULL);
+}
+
 ssize_t vlc_stream_Read(stream_t *s, void *buf, size_t len)
 {
     size_t copied = 0;
@@ -516,7 +527,7 @@ ssize_t vlc_stream_Peek(stream_t *s, const uint8_t **restrict bufp, size_t len)
         size_t avail = peek->i_buffer;
         ssize_t ret;
 
-        ret = vlc_stream_ReadRaw(s, peek->p_buffer + avail, len - avail);
+        ret = vlc_stream_ReadRaw(s, peek->p_buffer + avail, len - avail, NULL);
         if (ret < 0)
             continue;
 
@@ -706,14 +717,31 @@ block_t *vlc_stream_Block( stream_t *s, size_t size )
     if( unlikely(block == NULL) )
         return NULL;
 
-    ssize_t val = vlc_stream_Read( s, block->p_buffer, size );
-    if( val <= 0 )
+    block->i_buffer = 0;
+    char *buf = (char *)block->p_buffer;
+    while (size > 0)
+    {
+        uint32_t block_flags = 0;
+        ssize_t ret = vlc_stream_ReadPartialInternal( s, buf, size, &block_flags );
+        if (ret < 0)
+            continue;
+        if (ret == 0)
+            break;
+
+        if( size == (size_t) ret && block->i_buffer == 0 )
+            block->i_flags = block_flags;
+
+        buf += ret;
+        size -= ret;
+        block->i_buffer += ret;
+    }
+
+    if( block->i_buffer == 0 )
     {
         block_Release( block );
         return NULL;
     }
 
-    block->i_buffer = val;
     return block;
 }
 
-- 
2.11.0



More information about the vlc-devel mailing list