[vlc-commits] stream: common implementation of stream_Read() loop
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:18:28 2015 +0300| [776959f7daecc66ed308e88af8761aeccd9846aa] | committer: Rémi Denis-Courmont
stream: common implementation of stream_Read() loop
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=776959f7daecc66ed308e88af8761aeccd9846aa
---
src/input/stream.c | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
diff --git a/src/input/stream.c b/src/input/stream.c
index 436c8f4..cbf6346 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -35,6 +35,7 @@
#include <vlc_memory.h>
#include <vlc_access.h>
#include <vlc_charset.h>
+#include <vlc_interrupt.h>
#include <libvlc.h>
#include "stream.h"
@@ -302,6 +303,33 @@ error:
return NULL;
}
+static ssize_t stream_ReadRaw(stream_t *s, void *buf, size_t len)
+{
+ size_t copy = 0;
+ ssize_t ret = 0;
+
+ while (len > 0)
+ {
+ if (vlc_killed())
+ {
+ ret = -1;
+ break;
+ }
+
+ ret = s->pf_read(s, buf, len);
+ if (ret <= 0)
+ break;
+
+ assert((size_t)ret <= len);
+ if (buf != NULL)
+ buf = (unsigned char *)buf + ret;
+ len -= ret;
+ copy += ret;
+ }
+
+ return (copy > 0) ? (ssize_t)copy : ret;
+}
+
/**
* Reads data from a byte stream.
*
@@ -321,14 +349,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;
- assert(copy > 0);
+ if (unlikely(len == 0))
+ return 0;
+
if (buf != NULL)
memcpy(buf, peek->p_buffer, copy);
@@ -347,7 +374,7 @@ ssize_t stream_Read(stream_t *s, void *buf, size_t len)
return copy;
}
- ssize_t ret = s->pf_read(s, buf, len);
+ ssize_t ret = stream_ReadRaw(s, buf, len);
return (ret >= 0) ? (ssize_t)(ret + copy)
: ((copy > 0) ? (ssize_t)copy : ret);
}
@@ -387,7 +414,7 @@ ssize_t stream_Peek(stream_t *s, const uint8_t **restrict bufp, size_t len)
return 0;
}
- ssize_t ret = s->pf_read(s, peek->p_buffer, len);
+ ssize_t ret = stream_ReadRaw(s, peek->p_buffer, len);
if (ret < 0)
{
block_Release(peek);
@@ -412,7 +439,7 @@ ssize_t stream_Peek(stream_t *s, const uint8_t **restrict bufp, size_t len)
}
peek->i_buffer = avail;
- ssize_t ret = s->pf_read(s, peek->p_buffer + avail, len - avail);
+ ssize_t ret = stream_ReadRaw(s, peek->p_buffer + avail, len - avail);
*bufp = peek->p_buffer;
if (ret >= 0)
peek->i_buffer += ret;
More information about the vlc-commits
mailing list