[vlc-commits] stream: provide a common implementation of stream_Tell()
Rémi Denis-Courmont
git at videolan.org
Mon Aug 31 22:03:27 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Aug 31 22:19:32 2015 +0300| [48786ae56db78f89d971e4cbaa3f98f6dd21f78e] | committer: Rémi Denis-Courmont
stream: provide a common implementation of stream_Tell()
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=48786ae56db78f89d971e4cbaa3f98f6dd21f78e
---
include/vlc_stream.h | 19 +++++++------------
src/input/stream.c | 18 ++++++++++++++++++
src/libvlccore.sym | 1 +
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index a1ab152..6050629 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -142,6 +142,13 @@ 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;
+/**
+ * Tells the current stream position.
+ *
+ * @return the byte offset from the beginning of the stream (cannot fail)
+ */
+VLC_API uint64_t stream_Tell(const stream_t *) VLC_USED;
+
VLC_API int stream_vaControl( stream_t *s, int i_query, va_list args );
VLC_API void stream_Delete( stream_t *s );
VLC_API int stream_Control( stream_t *s, int i_query, ... );
@@ -150,18 +157,6 @@ VLC_API char * stream_ReadLine( stream_t * );
VLC_API input_item_t *stream_ReadDir( stream_t * );
/**
- * Get the current position in a stream
- */
-static inline int64_t stream_Tell( stream_t *s )
-{
- uint64_t i_pos;
- stream_Control( s, STREAM_GET_POSITION, &i_pos );
- if( i_pos >> 62 )
- return (int64_t)1 << 62;
- return i_pos;
-}
-
-/**
* Get the size of the stream.
*/
VLC_USED static inline int stream_GetSize( stream_t *s, uint64_t *size )
diff --git a/src/input/stream.c b/src/input/stream.c
index f215a53..6501bfc 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -45,6 +45,7 @@ typedef struct stream_priv_t
{
stream_t stream;
block_t *peek;
+ uint64_t offset;
/* UTF-16 and UTF-32 file reading */
struct {
@@ -75,6 +76,7 @@ stream_t *stream_CommonNew(vlc_object_t *parent)
s->pf_destroy = NULL;
s->p_input = NULL;
priv->peek = NULL;
+ priv->offset = 0;
/* UTF16 and UTF32 text file conversion */
priv->text.conv = (vlc_iconv_t)(-1);
@@ -313,6 +315,7 @@ error:
static ssize_t stream_ReadRaw(stream_t *s, void *buf, size_t len)
{
+ stream_priv_t *priv = (stream_priv_t *)s;
size_t copy = 0;
ssize_t ret = 0;
@@ -333,6 +336,7 @@ static ssize_t stream_ReadRaw(stream_t *s, void *buf, size_t len)
buf = (unsigned char *)buf + ret;
len -= ret;
copy += ret;
+ priv->offset += ret;
}
return (copy > 0) ? (ssize_t)copy : ret;
@@ -430,6 +434,20 @@ ssize_t stream_Peek(stream_t *s, const uint8_t **restrict bufp, size_t len)
return len;
}
+uint64_t stream_Tell(const stream_t *s)
+{
+ const stream_priv_t *priv = (const stream_priv_t *)s;
+ uint64_t pos = priv->offset;
+
+ if (priv->peek != NULL)
+ {
+ assert(pos >= priv->peek->i_buffer);
+ pos -= priv->peek->i_buffer;
+ }
+
+ return pos;
+}
+
static int stream_ControlInternal(stream_t *s, int cmd, ...)
{
va_list ap;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 0a37042..2e914db 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -403,6 +403,7 @@ stream_MemoryNew
stream_Peek
stream_Read
stream_ReadLine
+stream_Tell
stream_UrlNew
stream_vaControl
stream_ReadDir
More information about the vlc-commits
mailing list