Commit 642a329a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

stream: add stream_Eof()

parent b1512bb2
......@@ -144,6 +144,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.
*
......
......@@ -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)
{
......
......@@ -405,6 +405,7 @@ stream_Block
stream_Control
stream_CustomNew
stream_Delete
stream_Eof
stream_FilterNew
stream_MemoryNew
stream_Peek
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment