[vlc-devel] [PATCH 3/9] lua: use new playlist and player

Romain Vimont rom1v at videolabs.io
Mon Mar 4 13:58:12 CET 2019


On Mon, Mar 04, 2019 at 01:30:19PM +0200, Rémi Denis-Courmont wrote:
> Hi,
> 
> There are races here. It's pretty obvious with is_playing, which can change before the Lua code acts on the result.
>
> AFAICT, either the playlist lock is exposed to Lua (with some runtime error checking) or it's taken throughout Lua processing (which may need some revectoring of RC).

Yes, the purpose of this patchset is just to make the lua API "work"
with the new player/playlist with "minimal" changes in the lua
scripts, so that we can then remove the legacy playlist.

This is not a new clean playlist lua API. I tried to keep the current
behavior (sometimes weird) as much as possible.

So there were races before, there are still races in the same places.

> Le 4 mars 2019 12:53:23 GMT+02:00, Romain Vimont <rom1v at videolabs.io> a écrit :
> >Change the lua API implementation (the native part) to use the new
> >player and the new playlist.
> >---
> > modules/lua/extension.c      |   5 +-
> > modules/lua/intf.c           |   3 +-
> > modules/lua/libs.h           |   2 +
> > modules/lua/libs/equalizer.c |  29 +-
> > modules/lua/libs/input.c     | 112 ++++---
> > modules/lua/libs/input.h     |   4 +-
> > modules/lua/libs/objects.c   |  66 ++---
> > modules/lua/libs/osd.c       |  60 +---
> > modules/lua/libs/playlist.c  | 548 +++++++++++++++++++++--------------
> > modules/lua/libs/video.c     |  10 +-
> > modules/lua/libs/volume.c    |  57 ++--
> > modules/lua/vlc.h            |   6 +-
> > 12 files changed, 485 insertions(+), 417 deletions(-)
> >
> >diff --git a/modules/lua/extension.c b/modules/lua/extension.c
> >index 2d3c9813a9..475bd06767 100644
> >--- a/modules/lua/extension.c
> >+++ b/modules/lua/extension.c
> >@@ -818,8 +818,9 @@ static lua_State* GetLuaState( extensions_manager_t
> >*p_mgr,
> >             return NULL;
> >         }
> >         vlclua_set_this( L, p_mgr );
> >-        vlclua_set_playlist_internal( L,
> >-            pl_Get((intf_thread_t *)vlc_object_parent(p_mgr)) );
> >+        intf_thread_t *intf = (intf_thread_t *)
> >vlc_object_parent(p_mgr);
> >+        vlc_playlist_t *playlist = vlc_intf_GetMainPlaylist(intf);
> >+        vlclua_set_playlist_internal(L, playlist);
> >         vlclua_extension_set( L, p_ext );
> > 
> >         luaL_openlibs( L );
> >diff --git a/modules/lua/intf.c b/modules/lua/intf.c
> >index 079afa6531..cd906b4591 100644
> >--- a/modules/lua/intf.c
> >+++ b/modules/lua/intf.c
> >@@ -252,7 +252,8 @@ static int Start_LuaIntf( vlc_object_t *p_this,
> >const char *name )
> >     }
> > 
> >     vlclua_set_this( L, p_intf );
> >-    vlclua_set_playlist_internal( L, pl_Get(p_intf) );
> >+    vlc_playlist_t *playlist = vlc_intf_GetMainPlaylist(p_intf);
> >+    vlclua_set_playlist_internal(L, playlist);
> > 
> >     luaL_openlibs( L );
> > 
> >diff --git a/modules/lua/libs.h b/modules/lua/libs.h
> >index d366ef714f..c94854ded8 100644
> >--- a/modules/lua/libs.h
> >+++ b/modules/lua/libs.h
> >@@ -23,6 +23,8 @@
> > #ifndef VLC_LUA_LIBS_H
> > #define VLC_LUA_LIBS_H
> > 
> >+#include "vlc.h"
> >+
> > void luaopen_config( lua_State * );
> > void luaopen_dialog( lua_State *, void * );
> > void luaopen_httpd( lua_State * );
> >diff --git a/modules/lua/libs/equalizer.c
> >b/modules/lua/libs/equalizer.c
> >index 2d43a0e172..91692e2412 100644
> >--- a/modules/lua/libs/equalizer.c
> >+++ b/modules/lua/libs/equalizer.c
> >@@ -35,6 +35,8 @@
> > #include <vlc_aout.h>
> > #include <vlc_input.h>
> > #include <vlc_charset.h>
> >+#include <vlc_playlist.h>
> >+#include <vlc_player.h>
> > 
> > #include "input.h"
> > #include "../libs.h"
> >@@ -58,8 +60,7 @@
> >*****************************************************************************/
> > static int vlclua_preamp_get( lua_State *L )
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    audio_output_t *p_aout = playlist_GetAout( p_playlist );
> >+    audio_output_t *p_aout = vlclua_get_aout_internal(L);
> >     if( p_aout == NULL )
> >         return 0;
> > 
> >@@ -83,8 +84,7 @@ static int vlclua_preamp_get( lua_State *L )
> >*****************************************************************************/
> > static int vlclua_preamp_set( lua_State *L )
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    audio_output_t *p_aout = playlist_GetAout( p_playlist );
> >+    audio_output_t *p_aout = vlclua_get_aout_internal(L);
> >     if( p_aout == NULL )
> >         return 0;
> > 
> >@@ -123,8 +123,7 @@ static int vlclua_equalizer_get( lua_State *L )
> > {
> >     const unsigned bands = 10;
> > 
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    audio_output_t *p_aout = playlist_GetAout( p_playlist );
> >+    audio_output_t *p_aout = vlclua_get_aout_internal(L);
> >     if( p_aout == NULL )
> >         return 0;
> > 
> >@@ -189,8 +188,7 @@ static int vlclua_equalizer_set( lua_State *L )
> >     if( bandid < 0 || bandid > 9)
> >         return 0;
> > 
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    audio_output_t *p_aout = playlist_GetAout( p_playlist );
> >+    audio_output_t *p_aout = vlclua_get_aout_internal(L);
> >     if( p_aout == NULL )
> >         return 0;
> > 
> >@@ -246,8 +244,7 @@ static int vlclua_equalizer_setpreset( lua_State *L
> >)
> >     if( presetid >= NB_PRESETS || presetid < 0 )
> >         return 0;
> > 
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    audio_output_t *p_aout = playlist_GetAout( p_playlist );
> >+    audio_output_t *p_aout = vlclua_get_aout_internal(L);
> >     if( p_aout == NULL )
> >         return 0;
> > 
> >@@ -266,11 +263,15 @@ static int vlclua_equalizer_setpreset( lua_State
> >*L )
> >/****************************************************************************
> > * Enable/disable Equalizer
> >*****************************************************************************/
> >-static int vlclua_equalizer_enable ( lua_State *L )
> >+static int vlclua_equalizer_enable(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    bool state = luaL_checkboolean ( L , 1 );
> >-    playlist_EnableAudioFilter( p_playlist, "equalizer", state );
> >+    bool state = luaL_checkboolean(L , 1);
> >+    audio_output_t *aout = vlclua_get_aout_internal(L);
> >+    if (aout)
> >+    {
> >+        aout_EnableFilter(aout, "equalizer", state);
> >+        vlc_object_release (aout);
> >+    }
> >     return 0;
> > }
> >/*****************************************************************************
> >diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c
> >index 0a0fed10b4..cae6747ddf 100644
> >--- a/modules/lua/libs/input.c
> >+++ b/modules/lua/libs/input.c
> >@@ -35,6 +35,8 @@
> > #include <vlc_meta.h>
> > #include <vlc_url.h>
> > #include <vlc_playlist_legacy.h>
> >+#include <vlc_playlist.h>
> >+#include <vlc_player.h>
> > 
> > #include <assert.h>
> > 
> >@@ -43,32 +45,25 @@
> > #include "../libs.h"
> > #include "../extension.h"
> > 
> >-static input_item_t* vlclua_input_item_get_internal( lua_State *L );
> >+vlc_player_t *vlclua_get_player_internal(lua_State *L) {
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    return vlc_playlist_GetPlayer(playlist);
> >+}
> > 
> >-input_thread_t * vlclua_get_input_internal( lua_State *L )
> >+vout_thread_t *vlclua_get_vout_internal(lua_State *L)
> > {
> >-    extension_t *p_extension = vlclua_extension_get( L );
> >-    if( p_extension )
> >-    {
> >-        input_thread_t *p_input = p_extension->p_sys->p_input;
> >-        if( p_input )
> >-        {
> >-            vlc_object_hold(p_input);
> >-            return p_input;
> >-        }
> >-    }
> >-
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    if( p_playlist != NULL )
> >-    {
> >-        input_thread_t *p_input = playlist_CurrentInput( p_playlist );
> >-        if( p_input )
> >-            return p_input;
> >-    }
> >+    vlc_player_t *player = vlclua_get_player_internal(L);
> >+    return vlc_player_vout_Hold(player);
> >+}
> > 
> >-    return NULL;
> >+audio_output_t *vlclua_get_aout_internal(lua_State *L)
> >+{
> >+    vlc_player_t *player = vlclua_get_player_internal(L);
> >+    return vlc_player_aout_Hold(player);
> > }
> > 
> >+static input_item_t* vlclua_input_item_get_internal( lua_State *L );
> >+
> > static int vlclua_input_item_info( lua_State *L )
> > {
> >     input_item_t *p_item = vlclua_input_item_get_internal( L );
> >@@ -96,10 +91,12 @@ static int vlclua_input_item_info( lua_State *L )
> > 
> > static int vlclua_input_is_playing( lua_State *L )
> > {
> >-    input_thread_t * p_input = vlclua_get_input_internal( L );
> >-    lua_pushboolean( L, !!p_input );
> >-    if( p_input )
> >-        vlc_object_release( p_input );
> >+    vlc_player_t *player = vlclua_get_player_internal(L);
> >+
> >+    vlc_player_Lock(player);
> >+    bool started = vlc_player_IsStarted(player);
> >+    vlc_player_Unlock(player);
> >+    lua_pushboolean(L, started);
> >     return 1;
> > }
> > 
> >@@ -221,32 +218,27 @@ static int vlclua_input_item_stats( lua_State *L
> >)
> >     return 1;
> > }
> > 
> >-static int vlclua_input_add_subtitle( lua_State *L, bool b_path )
> >+static int vlclua_input_add_subtitle(lua_State *L, bool b_path)
> > {
> >-    input_thread_t *p_input = vlclua_get_input_internal( L );
> >-    bool b_autoselect = false;
> >-    if( !p_input )
> >-        return luaL_error( L, "can't add subtitle: no current input"
> >);
> >-    if( !lua_isstring( L, 1 ) )
> >-    {
> >-        vlc_object_release( p_input );
> >-        return luaL_error( L, "vlc.input.add_subtitle() usage: (path)"
> >);
> >-    }
> >-    if( lua_gettop( L ) >= 2 )
> >-        b_autoselect = lua_toboolean( L, 2 );
> >-    const char *psz_sub = luaL_checkstring( L, 1 );
> >-    if( !b_path )
> >-        input_AddSlave( p_input, SLAVE_TYPE_SPU, psz_sub,
> >b_autoselect, true, false );
> >-    else
> >-    {
> >-        char* psz_mrl = vlc_path2uri( psz_sub, NULL );
> >-        if ( psz_mrl )
> >-        {
> >-            input_AddSlave( p_input, SLAVE_TYPE_SPU, psz_mrl,
> >b_autoselect, true, false );
> >-            free( psz_mrl );
> >-        }
> >-    }
> >-    vlc_object_release( p_input );
> >+    vlc_player_t *player = vlclua_get_player_internal(L);
> >+
> >+    if (!lua_isstring(L, 1))
> >+        return luaL_error( L, "vlc.player.add_subtitle() usage:
> >(path)" );
> >+
> >+    bool autoselect;
> >+    if (lua_gettop(L) >= 2)
> >+        autoselect = lua_toboolean(L, 2);
> >+
> >+    const char *sub = luaL_checkstring(L, 1);
> >+    char *mrl;
> >+    if (b_path)
> >+        mrl = vlc_path2uri(sub, NULL);
> >+
> >+    const char *uri = b_path ? mrl : sub;
> >+    vlc_player_AddAssociatedMedia(player, SPU_ES, uri, autoselect,
> >true, false);
> >+    if (b_path)
> >+        free(mrl);
> >+
> >     return 1;
> > }
> > 
> >@@ -292,18 +284,16 @@ static int vlclua_input_item_delete( lua_State *L
> >)
> > 
> > static int vlclua_input_item_get_current( lua_State *L )
> > {
> >-    input_thread_t *p_input = vlclua_get_input_internal( L );
> >-    input_item_t *p_item = p_input ? input_GetItem( p_input ) : NULL;
> >-    if( !p_item )
> >-    {
> >-        lua_pushnil( L );
> >-        if( p_input ) vlc_object_release( p_input );
> >-        return 1;
> >-    }
> >+    vlc_player_t *player = vlclua_get_player_internal(L);
> > 
> >-    vlclua_input_item_get( L, p_item );
> >+    vlc_player_Lock(player);
> >+    input_item_t *media = vlc_player_GetCurrentMedia(player);
> >+    if (media)
> >+        vlclua_input_item_get(L, media);
> >+    else
> >+        lua_pushnil(L);
> >+    vlc_player_Unlock(player);
> > 
> >-    if( p_input ) vlc_object_release( p_input );
> >     return 1;
> > }
> > 
> >@@ -418,7 +408,7 @@ void luaopen_input( lua_State *L )
> > {
> >     lua_newtable( L );
> >     luaL_register( L, NULL, vlclua_input_reg );
> >-    lua_setfield( L, -2, "input" );
> >+    lua_setfield( L, -2, "player" );
> > }
> > 
> > static const luaL_Reg vlclua_input_item_reg[] = {
> >diff --git a/modules/lua/libs/input.h b/modules/lua/libs/input.h
> >index 432a180769..8de2fc3048 100644
> >--- a/modules/lua/libs/input.h
> >+++ b/modules/lua/libs/input.h
> >@@ -25,6 +25,8 @@
> > 
> > #include "../vlc.h"
> > 
> >-input_thread_t * vlclua_get_input_internal( lua_State * );
> >+vlc_player_t *vlclua_get_player_internal(lua_State *);
> >+vout_thread_t *vlclua_get_vout_internal(lua_State *L);
> >+audio_output_t *vlclua_get_aout_internal(lua_State *L);
> > 
> > #endif
> >diff --git a/modules/lua/libs/objects.c b/modules/lua/libs/objects.c
> >index d385ed9061..831a442e39 100644
> >--- a/modules/lua/libs/objects.c
> >+++ b/modules/lua/libs/objects.c
> >@@ -33,6 +33,8 @@
> > 
> > #include <vlc_common.h>
> > #include <vlc_vout.h>
> >+#include <vlc_playlist.h>
> >+#include <vlc_player.h>
> > 
> > #include "../vlc.h"
> > #include "../libs.h"
> >@@ -66,25 +68,21 @@ static int vlclua_get_libvlc( lua_State *L )
> > 
> > static int vlclua_get_playlist( lua_State *L )
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    if( p_playlist )
> >-    {
> >-        vlc_object_hold( p_playlist );
> >-        vlclua_push_vlc_object( L, p_playlist );
> >-    }
> >-    else lua_pushnil( L );
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    if (playlist)
> >+        lua_pushlightuserdata(L, playlist);
> >+    else
> >+        lua_pushnil(L);
> >     return 1;
> > }
> > 
> >-static int vlclua_get_input( lua_State *L )
> >+static int vlclua_get_player( lua_State *L )
> > {
> >-    input_thread_t *p_input = vlclua_get_input_internal( L );
> >-    if( p_input )
> >-    {
> >-        /* NOTE: p_input is already held by
> >vlclua_get_input_internal() */
> >-        vlclua_push_vlc_object( L, p_input );
> >-    }
> >-    else lua_pushnil( L );
> >+    vlc_player_t *player = vlclua_get_player_internal(L);
> >+    if (player)
> >+        lua_pushlightuserdata(L, player);
> >+    else
> >+        lua_pushnil(L);
> >     return 1;
> > }
> > 
> >@@ -107,43 +105,33 @@ int vlclua_push_vlc_object( lua_State *L,
> >vlc_object_t *p_obj )
> >     lua_setmetatable( L, -2 );
> >     return 1;
> > }
> >+
> > static int vlclua_get_vout( lua_State *L )
> > {
> >-    input_thread_t *p_input = vlclua_get_input_internal( L );
> >-    if( p_input )
> >-    {
> >-        vout_thread_t *p_vout = input_GetVout( p_input );
> >-        vlc_object_release( p_input );
> >-        if(p_vout)
> >-        {
> >-            vlclua_push_vlc_object( L, (vlc_object_t *) p_vout );
> >-            return 1;
> >-        }
> >-    }
> >-    lua_pushnil( L );
> >+    vout_thread_t *vout = vlclua_get_vout_internal(L);
> >+    if (vout)
> >+        vlclua_push_vlc_object(L, (vlc_object_t *) vout);
> >+    else
> >+        lua_pushnil(L);
> >     return 1;
> > }
> >+
> > static int vlclua_get_aout( lua_State *L )
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    if( p_playlist != NULL )
> >-    {
> >-        audio_output_t *p_aout = playlist_GetAout( p_playlist );
> >-        if( p_aout != NULL )
> >-        {
> >-            vlclua_push_vlc_object( L, (vlc_object_t *)p_aout );
> >-            return 1;
> >-        }
> >-    }
> >-    lua_pushnil( L );
> >+    audio_output_t *aout = vlclua_get_aout_internal(L);
> >+    if (aout)
> >+        vlclua_push_vlc_object(L, (vlc_object_t *) aout);
> >+    else
> >+        lua_pushnil(L);
> >     return 1;
> > }
> >+
> >/*****************************************************************************
> >  *
> >*****************************************************************************/
> > static const luaL_Reg vlclua_object_reg[] = {
> >-    { "input", vlclua_get_input },
> >     { "playlist", vlclua_get_playlist },
> >+    { "player", vlclua_get_player },
> >     { "libvlc", vlclua_get_libvlc },
> >     { "find", vlclua_object_find },
> >     { "vout", vlclua_get_vout},
> >diff --git a/modules/lua/libs/osd.c b/modules/lua/libs/osd.c
> >index 72a26fd6e3..84dd50da32 100644
> >--- a/modules/lua/libs/osd.c
> >+++ b/modules/lua/libs/osd.c
> >@@ -70,16 +70,11 @@ static int vlclua_osd_icon( lua_State *L )
> >     if( !i_icon )
> >   return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
> > 
> >-    input_thread_t *p_input = vlclua_get_input_internal( L );
> >-    if( p_input )
> >+    vout_thread_t *p_vout = vlclua_get_vout_internal(L);
> >+    if( p_vout )
> >     {
> >-        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 );
> >+        vout_OSDIcon( p_vout, i_chan, i_icon );
> >+        vlc_object_release( p_vout );
> >     }
> >     return 0;
> > }
> >@@ -117,17 +112,12 @@ static int vlclua_osd_message( lua_State *L )
> >     const char *psz_position = luaL_optstring( L, 3, "top-right" );
> >vlc_tick_t duration = (vlc_tick_t)luaL_optinteger( L, 4,
> >VLC_TICK_FROM_SEC(1));
> > 
> >-    input_thread_t *p_input = vlclua_get_input_internal( L );
> >-    if( p_input )
> >+    vout_thread_t *p_vout = vlclua_get_vout_internal(L);
> >+    if( p_vout )
> >     {
> >-        vout_thread_t *p_vout = input_GetVout( p_input );
> >-        if( p_vout )
> >-        {
> >-            vout_OSDText( p_vout, i_chan,
> >vlc_osd_position_from_string( psz_position ),
> >-                          duration, psz_message );
> >-            vlc_object_release( p_vout );
> >-        }
> >-        vlc_object_release( p_input );
> >+        vout_OSDText( p_vout, i_chan, vlc_osd_position_from_string(
> >psz_position ),
> >+                      duration, psz_message );
> >+        vlc_object_release( p_vout );
> >     }
> >     return 0;
> > }
> >@@ -161,36 +151,23 @@ static int vlclua_osd_slider( lua_State *L )
> >         return luaL_error( L, "\"%s\" is not a valid slider type.",
> >                            psz_type );
> > 
> >-    input_thread_t *p_input = vlclua_get_input_internal( L );
> >-    if( p_input )
> >+    vout_thread_t *p_vout = vlclua_get_vout_internal(L);
> >+    if( p_vout )
> >     {
> >-        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 );
> >+        vout_OSDSlider( p_vout, i_chan, i_position, i_type );
> >+        vlc_object_release( p_vout );
> >     }
> >     return 0;
> > }
> > 
> > static int vlclua_spu_channel_register( lua_State *L )
> > {
> >-    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 );
> >+    vout_thread_t *p_vout = vlclua_get_vout_internal(L);
> >     if( !p_vout )
> >-    {
> >-        vlc_object_release( p_input );
> >         return luaL_error( L, "Unable to find vout." );
> >-    }
> > 
> >     int i_chan = vout_RegisterSubpictureChannel( p_vout );
> >     vlc_object_release( p_vout );
> >-    vlc_object_release( p_input );
> >     lua_pushinteger( L, i_chan );
> >     return 1;
> > }
> >@@ -198,19 +175,12 @@ static int vlclua_spu_channel_register( lua_State
> >*L )
> > static int vlclua_spu_channel_clear( lua_State *L )
> > {
> >     int i_chan = luaL_checkinteger( L, 1 );
> >-    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 );
> >+    vout_thread_t *p_vout = vlclua_get_vout_internal(L);
> >     if( !p_vout )
> >-    {
> >-        vlc_object_release( p_input );
> >         return luaL_error( L, "Unable to find vout." );
> >-    }
> > 
> >     vout_FlushSubpictureChannel( p_vout, i_chan );
> >     vlc_object_release( p_vout );
> >-    vlc_object_release( p_input );
> >     return 0;
> > }
> > 
> >diff --git a/modules/lua/libs/playlist.c b/modules/lua/libs/playlist.c
> >index cbbcde5eac..a15b4ff11e 100644
> >--- a/modules/lua/libs/playlist.c
> >+++ b/modules/lua/libs/playlist.c
> >@@ -34,7 +34,8 @@
> > #include <vlc_common.h>
> > 
> > #include <vlc_interface.h>
> >-#include <vlc_playlist_legacy.h>
> >+#include <vlc_playlist.h>
> >+#include <vlc_player.h>
> > 
> > #include "../vlc.h"
> > #include "../libs.h"
> >@@ -42,139 +43,254 @@
> > #include "variables.h"
> > #include "misc.h"
> > 
> >-void vlclua_set_playlist_internal( lua_State *L, playlist_t *pl )
> >+void vlclua_set_playlist_internal(lua_State *L, vlc_playlist_t
> >*playlist)
> > {
> >-    vlclua_set_object( L, vlclua_set_playlist_internal, pl );
> >+    vlclua_set_object(L, vlclua_set_playlist_internal, playlist);
> > }
> > 
> >-playlist_t *vlclua_get_playlist_internal( lua_State *L )
> >+vlc_playlist_t *vlclua_get_playlist_internal(lua_State *L)
> > {
> >-    return vlclua_get_object( L, vlclua_set_playlist_internal );
> >+    return vlclua_get_object(L, vlclua_set_playlist_internal);
> > }
> > 
> >-static int vlclua_playlist_prev( lua_State * L )
> >+static int vlclua_playlist_prev(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    playlist_Prev( p_playlist );
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    vlc_playlist_Lock(playlist);
> >+    vlc_playlist_Prev(playlist);
> >+    vlc_playlist_Unlock(playlist);
> >     return 0;
> > }
> > 
> >-static int vlclua_playlist_next( lua_State * L )
> >+static int vlclua_playlist_next(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    playlist_Next( p_playlist );
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    vlc_playlist_Lock(playlist);
> >+    vlc_playlist_Next(playlist);
> >+    vlc_playlist_Unlock(playlist);
> >     return 0;
> > }
> > 
> >-static int vlclua_playlist_skip( lua_State * L )
> >+static int vlclua_playlist_skip(lua_State *L)
> > {
> >-    int i_skip = luaL_checkinteger( L, 1 );
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    playlist_Skip( p_playlist, i_skip );
> >+    int n = luaL_checkinteger( L, 1 );
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    if (n < 0) {
> >+        for (int i = 0; i < -n; i++)
> >+            vlc_playlist_Prev(playlist);
> >+    } else {
> >+        for (int i = 0; i < n; ++i)
> >+            vlc_playlist_Next(playlist);
> >+    }
> >     return 0;
> > }
> > 
> >-static int vlclua_playlist_play( lua_State * L )
> >+static int vlclua_playlist_play(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    playlist_Play( p_playlist );
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    vlc_playlist_Lock(playlist);
> >+    if (vlc_playlist_GetCurrentIndex(playlist) == -1 &&
> >+            vlc_playlist_Count(playlist) > 0)
> >+        vlc_playlist_GoTo(playlist, 0);
> >+    vlc_playlist_Start(playlist);
> >+    vlc_playlist_Unlock(playlist);
> >     return 0;
> > }
> > 
> >-static int vlclua_playlist_pause( lua_State * L )
> >+static int vlclua_playlist_pause(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    playlist_TogglePause( p_playlist );
> >+    /* this is in fact a toggle pause */
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
> >+
> >+    vlc_player_Lock(player);
> >+    if (vlc_player_GetState(player) != VLC_PLAYER_STATE_PAUSED)
> >+        vlc_player_Pause(player);
> >+    else
> >+        vlc_player_Resume(player);
> >+    vlc_player_Unlock(player);
> >+
> >     return 0;
> > }
> > 
> >-static int vlclua_playlist_stop( lua_State * L )
> >+static int vlclua_playlist_stop(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    playlist_Stop( p_playlist );
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    vlc_playlist_Lock(playlist);
> >+    vlc_playlist_Stop(playlist);
> >+    vlc_playlist_Unlock(playlist);
> >     return 0;
> > }
> > 
> >-static int vlclua_playlist_clear( lua_State * L )
> >+static int vlclua_playlist_clear( lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    playlist_Stop( p_playlist ); /* Isn't this already implied by
> >Clear? */
> >-    playlist_Clear( p_playlist, pl_Unlocked );
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    vlc_playlist_Lock(playlist);
> >+    vlc_playlist_Clear(playlist);
> >+    vlc_playlist_Unlock(playlist);
> >     return 0;
> > }
> > 
> >-static int vlclua_playlist_repeat( lua_State * L )
> >+static bool take_bool(lua_State *L)
> >+{
> >+    const char *s = luaL_checkstring(L, -1);
> >+    lua_pop( L, 1 );
> >+    return s && !strcmp(s, "on");
> >+}
> >+
> >+static int vlclua_playlist_repeat_(lua_State *L,
> >+                               enum vlc_playlist_playback_repeat
> >enabled_mode)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "repeat" );
> >-    return i_ret;
> >+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
> >+    int top = lua_gettop(L);
> >+    if (top > 1)
> >+        return vlclua_error(L);
> >+
> >+    vlc_playlist_Lock(playlist);
> >+
> >+    bool enable;
> >+    if (top == 0)
> >+    {
> >+        /* no value provided, toggle the current */
> >+        enum vlc_playlist_playback_repeat repeat =
> >+                vlc_playlist_GetPlaybackRepeat(playlist);
> >+        enable = repeat != enabled_mode;
> >+    }
> >+    else
> >+    {
> >+        /* use the provided value */
> >+        enable = take_bool(L);
> >+    }
> >+
> >+    enum vlc_playlist_playback_repeat new_repeat = enable
> >+                                    ? enabled_mode
> >+                                    :
> >VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
> >+
> >+    vlc_playlist_SetPlaybackRepeat(playlist, new_repeat);
> >+
> >+    vlc_playlist_Unlock(playlist);
> >+
> >+    lua_pushboolean(L, enable);
> >+    return 1;
> > }
> > 
> >-static int vlclua_playlist_loop( lua_State * L )
> >+static int vlclua_playlist_repeat(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "loop" );
> >-    return i_ret;
> >+    return vlclua_playlist_repeat_(L,
> >VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT);
> > }
> > 
> >-static int vlclua_playlist_random( lua_State * L )
> >+static int vlclua_playlist_loop(lua_State *L)
> > {
> >-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
> >-    int i_ret = vlclua_var_toggle_or_set( L, p_playlist, "random" );
> >-    return i_ret;
> >+ 
> 
> -- 
> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.

> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel



More information about the vlc-devel mailing list