[vlc-commits] stream: add stream_ReadBlock()

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 19 19:56:58 2016 +0300| [deb5e45b297c7fe24f8150f42c39ad90968dceda] | committer: Rémi Denis-Courmont

stream: add stream_ReadBlock()

This reads a block of unspecified size. The main use case will be
support for block-oriented stream filters.

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

 include/vlc_stream.h |   18 ++++++++++++++++++
 src/input/stream.c   |   38 ++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym   |    1 +
 3 files changed, 57 insertions(+)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 1fadf84..376dee6 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -138,6 +138,24 @@ VLC_API ssize_t stream_Read(stream_t *, void *, size_t) VLC_USED;
 VLC_API ssize_t stream_Peek(stream_t *, const uint8_t **, size_t) VLC_USED;
 
 /**
+ * Reads a data block from a byte stream.
+ *
+ * This function dequeues the next block of data from the byte stream. The
+ * byte stream back-end decides on the size of the block; the caller cannot
+ * make any assumption about it.
+ *
+ * The function might also return NULL spuriously - this does not necessarily
+ * imply that the stream is ended nor that it has encountered a nonrecoverable
+ * error.
+ *
+ * This function should be used instead of stream_Read() or stream_Peek() when
+ * the caller can handle reads of any size.
+ *
+ * \return either a data block or NULL
+ */
+VLC_API block_t *stream_ReadBlock(stream_t *) VLC_USED;
+
+/**
  * Tells the current stream position.
  *
  * @return the byte offset from the beginning of the stream (cannot fail)
diff --git a/src/input/stream.c b/src/input/stream.c
index 86134c4..058c063 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -453,6 +453,44 @@ ssize_t stream_Peek(stream_t *s, const uint8_t **restrict bufp, size_t len)
     return len;
 }
 
+block_t *stream_ReadBlock(stream_t *s)
+{
+    stream_priv_t *priv = (stream_priv_t *)s;
+    block_t *block;
+
+    if (priv->peek != NULL)
+    {
+        block = priv->peek;
+        priv->peek = NULL;
+    }
+    else
+    {
+        if (vlc_killed())
+            return NULL;
+
+        block = block_Alloc(4096);
+        if (unlikely(block == NULL))
+            return NULL;
+
+        ssize_t ret = s->pf_read(s, block->p_buffer, block->i_buffer);
+        if (ret >= 0)
+        {
+            block->i_buffer = ret;
+            priv->eof = !ret;
+        }
+        else
+        {
+            block_Release(block);
+            block = NULL;
+        }
+    }
+
+    if (block != NULL)
+        priv->offset += block->i_buffer;
+
+    return block;
+}
+
 uint64_t stream_Tell(const stream_t *s)
 {
     const stream_priv_t *priv = (const stream_priv_t *)s;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 1d7511a..d877e12 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -410,6 +410,7 @@ stream_FilterNew
 stream_MemoryNew
 stream_Peek
 stream_Read
+stream_ReadBlock
 stream_ReadLine
 stream_Seek
 stream_Tell



More information about the vlc-commits mailing list