[vlc-commits] lua: streams: Expose seek & getsize member functions
Hugo Beauzée-Luyssen
git at videolan.org
Tue Apr 17 14:02:19 CEST 2018
vlc/vlc-3.0 | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Apr 16 17:15:14 2018 +0200| [3c9ce261ce7f7ff87b4e715a022ffc7a6d0f3f64] | committer: Hugo Beauzée-Luyssen
lua: streams: Expose seek & getsize member functions
(cherry picked from commit 502f5c066005576aa5143ffbb8d95e0ab38deeed)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=3c9ce261ce7f7ff87b4e715a022ffc7a6d0f3f64
---
modules/lua/libs/stream.c | 26 ++++++++++++++++++++++++++
share/lua/README.txt | 2 ++
2 files changed, 28 insertions(+)
diff --git a/modules/lua/libs/stream.c b/modules/lua/libs/stream.c
index 2bb3e6ee96..c682759838 100644
--- a/modules/lua/libs/stream.c
+++ b/modules/lua/libs/stream.c
@@ -49,12 +49,16 @@ static int vlclua_stream_readline( lua_State * );
static int vlclua_stream_delete( lua_State * );
static int vlclua_stream_add_filter( lua_State *L );
static int vlclua_stream_readdir( lua_State *L );
+static int vlclua_stream_getsize( lua_State *L );
+static int vlclua_stream_seek( lua_State *L );
static const luaL_Reg vlclua_stream_reg[] = {
{ "read", vlclua_stream_read },
{ "readline", vlclua_stream_readline },
{ "addfilter", vlclua_stream_add_filter },
{ "readdir", vlclua_stream_readdir },
+ { "getsize", vlclua_stream_getsize },
+ { "seek", vlclua_stream_seek },
{ NULL, NULL }
};
@@ -251,6 +255,28 @@ static int vlclua_stream_readdir( lua_State *L )
return 1;
}
+static int vlclua_stream_getsize( lua_State *L )
+{
+ stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+ uint64_t i_size;
+ int i_res = vlc_stream_GetSize( *pp_stream, &i_size );
+ if ( i_res != 0 )
+ return luaL_error( L, "Failed to get stream size" );
+ lua_pushnumber( L, i_size );
+ return 1;
+}
+
+static int vlclua_stream_seek( lua_State *L )
+{
+ stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+ lua_Integer i_offset = luaL_checkinteger( L, 2 );
+ if ( i_offset < 0 )
+ return luaL_error( L, "Invalid negative seek offset" );
+ int i_res = vlc_stream_Seek( *pp_stream, (uint64_t)i_offset );
+ lua_pushboolean( L, i_res == 0 );
+ return 1;
+}
+
static int vlclua_stream_delete( lua_State *L )
{
stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
diff --git a/share/lua/README.txt b/share/lua/README.txt
index 8b92a3179d..cbcd9156e1 100644
--- a/share/lua/README.txt
+++ b/share/lua/README.txt
@@ -392,6 +392,8 @@ s = vlc.stream( "http://www.videolan.org/" )
s:read( 128 ) -- read up to 128 characters. Return 0 if no more data is available (FIXME?).
s:readline() -- read a line. Return nil if EOF was reached.
s:addfilter() -- add a stream filter. If no argument was specified, try to add all automatic stream filters.
+s:getsize() -- returns the size of the stream, or nil if unknown
+s:seek(offset) -- seeks from offset bytes (from the begining of the stream). Returns nil in case of error
Strings
-------
More information about the vlc-commits
mailing list