[vlc-commits] stream: add stream_Eof()

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 19 20:28:49 2016 +0300| [642a329a75f70ef97860e4530b1efbe00947dc36] | committer: Rémi Denis-Courmont

stream: add stream_Eof()

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

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

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 8f66d5f..1fadf84 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -145,6 +145,28 @@ VLC_API ssize_t stream_Peek(stream_t *, const uint8_t **, size_t) VLC_USED;
 VLC_API uint64_t stream_Tell(const stream_t *) VLC_USED;
 
 /**
+ * Checks for end of stream.
+ *
+ * Checks if the last attempt to reads data from the stream encountered the
+ * end of stream before the attempt could be fully satisfied.
+ * The value is initially false, and is reset to false by stream_Seek().
+ *
+ * \note The function can return false even though the current stream position
+ * is equal to the stream size. It will return true after the following attempt
+ * to read more than zero bytes.
+ *
+ * \note It might be possible to read after the end of the stream.
+ * It implies the size of the stream increased asynchronously in the mean time.
+ * Streams of most types cannot trigger such a case,
+ * but regular local files notably can.
+ *
+ * \note In principles, the stream size should match the stream offset when
+ * the end-of-stream is reached. But that rule is not enforced; it is entirely
+ * dependent on the underlying implementation of the stream.
+ */
+VLC_API bool stream_Eof(const stream_t *) VLC_USED;
+
+/**
  * Sets the current stream position.
  *
  * @param offset byte offset from the beginning of the stream
diff --git a/src/input/stream.c b/src/input/stream.c
index 04390c8..86134c4 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -47,6 +47,7 @@ typedef struct stream_priv_t
     void (*destroy)(stream_t *);
     block_t *peek;
     uint64_t offset;
+    bool eof;
 
     /* UTF-16 and UTF-32 file reading */
     struct {
@@ -87,6 +88,7 @@ stream_t *stream_CommonNew(vlc_object_t *parent, void (*destroy)(stream_t *))
     priv->destroy = destroy;
     priv->peek = NULL;
     priv->offset = 0;
+    priv->eof = false;
 
     /* UTF16 and UTF32 text file conversion */
     priv->text.conv = (vlc_iconv_t)(-1);
@@ -361,13 +363,13 @@ ssize_t stream_Read(stream_t *s, void *buf, size_t len)
     block_t *peek = priv->peek;
     size_t copy = 0;
 
+    if (unlikely(len == 0))
+        return 0;
+
     if (peek != NULL)
     {
         copy = peek->i_buffer < len ? peek->i_buffer : len;
 
-        if (unlikely(len == 0))
-            return 0;
-
         if (buf != NULL)
             memcpy(buf, peek->p_buffer, copy);
 
@@ -393,6 +395,7 @@ ssize_t stream_Read(stream_t *s, void *buf, size_t len)
         return ((copy > 0) ? (ssize_t)copy : ret);
     copy += ret;
     priv->offset += ret;
+    priv->eof = !ret;
     return copy;
 }
 
@@ -457,10 +460,19 @@ uint64_t stream_Tell(const stream_t *s)
     return priv->offset;
 }
 
+bool stream_Eof(const stream_t *s)
+{
+    const stream_priv_t *priv = (const stream_priv_t *)s;
+
+    return priv->eof;
+}
+
 int stream_Seek(stream_t *s, uint64_t offset)
 {
     stream_priv_t *priv = (stream_priv_t *)s;
 
+    priv->eof = false;
+
     block_t *peek = priv->peek;
     if (peek != NULL)
     {
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 1e634dd..1d7511a 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -405,6 +405,7 @@ stream_Block
 stream_Control
 stream_CustomNew
 stream_Delete
+stream_Eof
 stream_FilterNew
 stream_MemoryNew
 stream_Peek



More information about the vlc-commits mailing list