]> git.sesse.net Git - vlc/blobdiff - modules/misc/lua/libs/osd.c
Removed all vlc_object_find in lua osd code.
[vlc] / modules / misc / lua / libs / osd.c
index 05c1aae0cbf9b4fcbc9cb2634e7e11684a1fefe6..86388767a2ddfdf460dcd571115a69cd34638a92 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "../vlc.h"
 #include "../libs.h"
+#include "input.h"
 
 /*****************************************************************************
  * OSD
@@ -69,23 +70,40 @@ static int vlclua_osd_icon( lua_State *L )
 {
     const char *psz_icon = luaL_checkstring( L, 1 );
     int i_icon = vlc_osd_icon_from_string( psz_icon );
-    int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
+    int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
     if( !i_icon )
         return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
-    else
+
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( p_input )
     {
-        vlc_object_t *p_this = vlclua_get_this( L );
-        vout_OSDIcon( p_this, i_chan, i_icon );
-        return 0;
+        vout_thread_t *p_vout = input_GetVout( p_input );
+        if( p_vout )
+        {
+            vout_OSDIcon( p_vout, i_chan, i_icon );
+            vlc_object_release( p_vout );
+        }
+        vlc_object_release( p_input );
     }
+    return 0;
 }
 
 static int vlclua_osd_message( lua_State *L )
 {
     const char *psz_message = luaL_checkstring( L, 1 );
-    int i_chan = luaL_optint( L, 2, DEFAULT_CHAN );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vout_OSDMessage( p_this, i_chan, "%s", psz_message );
+    int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
+
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( p_input )
+    {
+        vout_thread_t *p_vout = input_GetVout( p_input );
+        if( p_vout )
+        {
+            vout_OSDMessage( p_vout, i_chan, "%s", psz_message );
+            vlc_object_release( p_vout );
+        }
+        vlc_object_release( p_input );
+    }
     return 0;
 }
 
@@ -113,29 +131,41 @@ static int vlclua_osd_slider( lua_State *L )
     int i_position = luaL_checkint( L, 1 );
     const char *psz_type = luaL_checkstring( L, 2 );
     int i_type = vlc_osd_slider_type_from_string( psz_type );
-    int i_chan = luaL_optint( L, 3, DEFAULT_CHAN );
+    int i_chan = luaL_optint( L, 3, SPU_DEFAULT_CHANNEL );
     if( !i_type )
         return luaL_error( L, "\"%s\" is not a valid slider type.",
                            psz_type );
-    else
+
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( p_input )
     {
-        vlc_object_t *p_this = vlclua_get_this( L );
-        vout_OSDSlider( p_this, i_chan, i_position, i_type );
-        return 0;
+        vout_thread_t *p_vout = input_GetVout( p_input );
+        if( p_vout )
+        {
+            vout_OSDSlider( p_vout, i_chan, i_position, i_type );
+            vlc_object_release( p_vout );
+        }
+        vlc_object_release( p_input );
     }
+    return 0;
 }
 
 static int vlclua_spu_channel_register( lua_State *L )
 {
-    int i_chan;
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
-                                             FIND_ANYWHERE );
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( !p_input )
+        return luaL_error( L, "Unable to find input." );
+
+    vout_thread_t *p_vout = input_GetVout( p_input );
     if( !p_vout )
+    {
+        vlc_object_release( p_input );
         return luaL_error( L, "Unable to find vout." );
+    }
 
-    spu_Control( p_vout->p_spu, SPU_CHANNEL_REGISTER, &i_chan );
+    int i_chan = vout_RegisterSubpictureChannel( p_vout );
     vlc_object_release( p_vout );
+    vlc_object_release( p_input );
     lua_pushinteger( L, i_chan );
     return 1;
 }
@@ -143,14 +173,68 @@ static int vlclua_spu_channel_register( lua_State *L )
 static int vlclua_spu_channel_clear( lua_State *L )
 {
     int i_chan = luaL_checkint( L, 1 );
-    vlc_object_t *p_this = vlclua_get_this( L );
-    vout_thread_t *p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT,
-                                             FIND_ANYWHERE );
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( !p_input )
+        return luaL_error( L, "Unable to find input." );
+    vout_thread_t *p_vout = input_GetVout( p_input );
     if( !p_vout )
+    {
+        vlc_object_release( p_input );
         return luaL_error( L, "Unable to find vout." );
+    }
 
-    spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, i_chan );
+    vout_FlushSubpictureChannel( p_vout, i_chan );
     vlc_object_release( p_vout );
+    vlc_object_release( p_input );
+    return 0;
+}
+
+static int vlclua_menu_show( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    osd_MenuShow( p_this );
+    return 0;
+}
+
+static int vlclua_menu_hide( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    osd_MenuHide( p_this );
+    return 0;
+}
+
+static int vlclua_menu_prev( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    osd_MenuPrev( p_this );
+    return 0;
+}
+
+static int vlclua_menu_next( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    osd_MenuNext( p_this );
+    return 0;
+}
+
+static int vlclua_menu_up( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    osd_MenuUp( p_this );
+    return 0;
+}
+
+static int vlclua_menu_down( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    osd_MenuDown( p_this );
+    return 0;
+}
+
+static int vlclua_menu_activate( lua_State *L )
+{
+    vlc_object_t *p_this = vlclua_get_this( L );
+    osd_MenuActivate( p_this );
     return 0;
 }
 
@@ -166,9 +250,23 @@ static const luaL_Reg vlclua_osd_reg[] = {
     { NULL, NULL }
 };
 
+static const luaL_Reg vlclua_menu_reg[] = {
+    { "show", vlclua_menu_show },
+    { "hide", vlclua_menu_hide },
+    { "prev", vlclua_menu_prev },
+    { "next", vlclua_menu_next },
+    { "up", vlclua_menu_up },
+    { "down", vlclua_menu_down },
+    { "activate", vlclua_menu_activate },
+    { NULL, NULL }
+};
+
 void luaopen_osd( lua_State *L )
 {
     lua_newtable( L );
     luaL_register( L, NULL, vlclua_osd_reg );
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_menu_reg );
+    lua_setfield( L, -2, "menu" );
     lua_setfield( L, -2, "osd" );
 }