[vlc-devel] commit: Lua: vlc.stream has a new function: addfilter ( Jean-Philippe André )

git version control git at videolan.org
Sat Dec 19 19:48:24 CET 2009


vlc | branch: master | Jean-Philippe André <jpeg at videolan.org> | Sat Dec 19 19:07:15 2009 +0100| [9304b7db2b5e7a7bd353dc3ee689ffdb8ee3cabf] | committer: Jean-Philippe André 

Lua: vlc.stream has a new function: addfilter

When used with no argument (or nil), it adds all automatic stream
filters. When used with an argument, tries to insert the specified
filter only.

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

 modules/misc/lua/libs/stream.c |   52 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/modules/misc/lua/libs/stream.c b/modules/misc/lua/libs/stream.c
index 49e48b3..ec37386 100644
--- a/modules/misc/lua/libs/stream.c
+++ b/modules/misc/lua/libs/stream.c
@@ -51,10 +51,12 @@
 static int vlclua_stream_read( lua_State * );
 static int vlclua_stream_readline( lua_State * );
 static int vlclua_stream_delete( lua_State * );
+static int vlclua_stream_add_filter( lua_State *L );
 
 static const luaL_Reg vlclua_stream_reg[] = {
     { "read", vlclua_stream_read },
     { "readline", vlclua_stream_readline },
+    { "addfilter", vlclua_stream_add_filter },
     { NULL, NULL }
 };
 
@@ -111,6 +113,56 @@ static int vlclua_stream_readline( lua_State *L )
     return 1;
 }
 
+static int vlclua_stream_add_filter( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+
+    /* Make sure that we have 1 argument (+ 1 object) */
+    lua_settop( L, 2 );
+
+    stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );
+    if( !*pp_stream ) return vlclua_error( L );
+    const char *psz_filter = NULL;
+
+    if( lua_isstring( L, 2 ) )
+        psz_filter = lua_tostring( L, 2 );
+
+    if( !psz_filter || !*psz_filter )
+    {
+        msg_Dbg( p_this, "adding all automatic stream filters" );
+        while( true )
+        {
+            /* Add next automatic stream */
+            stream_t *p_filtered = stream_FilterNew( *pp_stream, NULL );
+            if( !p_filtered )
+                break;
+            else
+            {
+                msg_Dbg( p_this, "inserted an automatic stream filter" );
+                *pp_stream = p_filtered;
+            }
+        }
+        luaL_getmetatable( L, "stream" );
+        lua_setmetatable( L, 1 );
+    }
+    else
+    {
+        /* Add a named filter */
+        stream_t *p_filter = stream_FilterNew( *pp_stream, psz_filter );
+        if( !p_filter )
+            msg_Dbg( p_this, "Unable to open requested stream filter '%s'",
+                     psz_filter );
+        else
+        {
+            *pp_stream = p_filter;
+            luaL_getmetatable( L, "stream" );
+            lua_setmetatable( L, 1 );
+        }
+    }
+
+    return 1;
+}
+
 static int vlclua_stream_delete( lua_State *L )
 {
     stream_t **pp_stream = (stream_t **)luaL_checkudata( L, 1, "stream" );




More information about the vlc-devel mailing list