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