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

Romain Vimont rom1v at videolabs.io
Mon Mar 4 11:53:23 CET 2019


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;
+    return vlclua_playlist_repeat_(L, VLC_PLAYLIST_PLAYBACK_REPEAT_ALL);
 }
 
-static int vlclua_playlist_gotoitem( lua_State * L )
+static int vlclua_playlist_random(lua_State *L)
 {
-    int i_id = luaL_checkinteger( L, 1 );
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    PL_LOCK;
-    playlist_ViewPlay( p_playlist, NULL,
-                       playlist_ItemGetById( p_playlist, i_id ) );
-    PL_UNLOCK;
-    return vlclua_push_ret( L, VLC_SUCCESS );
+    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)
+    {
+        enum vlc_playlist_playback_order order =
+                vlc_playlist_GetPlaybackOrder(playlist);
+        enable = order != VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM;
+    }
+    else
+    {
+        /* use the provided value */
+        enable = take_bool(L);
+    }
+
+    enum vlc_playlist_playback_order new_order = enable
+                                    ? VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM
+                                    : VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
+
+    vlc_playlist_SetPlaybackOrder(playlist, new_order);
+
+    vlc_playlist_Unlock(playlist);
+
+    lua_pushboolean(L, enable);
+    return 1;
 }
 
-static int vlclua_playlist_delete( lua_State * L )
+static int vlclua_playlist_gotoitem(lua_State *L)
 {
-    int i_id = luaL_checkinteger( L, 1 );
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
+    uint64_t id = luaL_checkinteger(L, 1);
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+
+    int ret;
 
-    PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
-    if( p_item != NULL )
-       playlist_NodeDelete( p_playlist, p_item );
-    PL_UNLOCK;
+    vlc_playlist_Lock(playlist);
+    ssize_t index = vlc_playlist_IndexOfId(playlist, id);
+    if (index == -1)
+        ret = VLC_ENOITEM;
+    else
+    {
+        vlc_playlist_GoTo(playlist, index);
+        ret = VLC_SUCCESS;
+    }
+    vlc_playlist_Unlock(playlist);
 
-    return vlclua_push_ret( L, (p_item != NULL) ? 0 : -1 );
+    return vlclua_push_ret(L, ret);
 }
 
-static int vlclua_playlist_move( lua_State * L )
+static int vlclua_playlist_delete(lua_State *L)
 {
-    int i_item = luaL_checkinteger( L, 1 );
-    int i_target = luaL_checkinteger( L, 2 );
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    PL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_item );
-    playlist_item_t *p_target = playlist_ItemGetById( p_playlist, i_target );
-    if( !p_item || !p_target )
+    uint64_t id = luaL_checkinteger(L, 1);
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+
+    int ret;
+
+    vlc_playlist_Lock(playlist);
+    ssize_t index = vlc_playlist_IndexOfId(playlist, id);
+    if (index == -1)
+        ret = -1;
+    else
     {
-       PL_UNLOCK;
-       return vlclua_push_ret( L, -1 );
+        vlc_playlist_RemoveOne(playlist, index);
+        ret = VLC_SUCCESS;
     }
-    int i_ret;
-    if( p_target->i_children != -1 )
-        i_ret = playlist_TreeMove( p_playlist, p_item, p_target, 0 );
+    vlc_playlist_Unlock(playlist);
+
+    return vlclua_push_ret(L, ret);
+}
+
+static int vlclua_playlist_move(lua_State *L)
+{
+    uint64_t item_id = luaL_checkinteger(L, 1);
+    uint64_t target_id = luaL_checkinteger(L, 2);
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+
+    int ret;
+
+    vlc_playlist_Lock(playlist);
+    ssize_t item_index = vlc_playlist_IndexOfId(playlist, item_id);
+    ssize_t target_index = vlc_playlist_IndexOfId(playlist, target_id);
+    if (item_index == -1 || target_index == -1)
+        ret = -1;
     else
-        i_ret = playlist_TreeMove( p_playlist, p_item, p_target->p_parent, p_target->i_id - p_target->p_parent->pp_children[0]->i_id + 1 );
-    PL_UNLOCK;
-    return vlclua_push_ret( L, i_ret );
+    {
+        /* if the current item was before the target, moving it shifts the
+         * target item by one */
+        size_t new_index = item_index <= target_index ? target_index
+                                                      : target_index + 1;
+        vlc_playlist_MoveOne(playlist, item_index, new_index);
+        ret = VLC_SUCCESS;
+    }
+    vlc_playlist_Unlock(playlist);
+
+    return vlclua_push_ret(L, ret);
 }
 
 static int vlclua_playlist_add_common(lua_State *L, bool play)
 {
     vlc_object_t *obj = vlclua_get_this(L);
-    playlist_t *playlist = vlclua_get_playlist_internal(L);
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
     int count = 0;
 
     /* playlist */
@@ -186,209 +302,195 @@ static int vlclua_playlist_add_common(lua_State *L, bool play)
 
     lua_pushnil(L);
 
+    vlc_playlist_Lock(playlist);
+
     /* playlist nil */
     while (lua_next(L, -2))
     {
         input_item_t *item = vlclua_read_input_item(obj, L);
         if (item != NULL)
         {
-            /* Play or Enqueue (preparse) */
-            /* FIXME: playlist_AddInput() can fail */
-            playlist_AddInput(playlist, item, play);
+            int ret = vlc_playlist_AppendOne(playlist, item);
+            if (ret == VLC_SUCCESS)
+            {
+                count++;
+                if (play)
+                {
+                    size_t last = vlc_playlist_Count(playlist) - 1;
+                    vlc_playlist_PlayAt(playlist, last);
+                }
+            }
             input_item_Release(item);
-            count++;
         }
         /* pop the value, keep the key for the next lua_next() call */
         lua_pop(L, 1);
     }
     /* playlist */
 
+    vlc_playlist_Unlock(playlist);
+
     lua_pushinteger(L, count);
     return 1;
 }
 
-static int vlclua_playlist_add( lua_State *L )
+static int vlclua_playlist_add(lua_State *L)
 {
     return vlclua_playlist_add_common(L, true);
 }
 
-static int vlclua_playlist_enqueue( lua_State *L )
+static int vlclua_playlist_enqueue(lua_State *L)
 {
     return vlclua_playlist_add_common(L, false);
 }
 
-static void push_playlist_item( lua_State *L, playlist_item_t *p_item )
+static void push_playlist_item(lua_State *L, vlc_playlist_item_t *item)
 {
-    input_item_t *p_input = p_item->p_input;
-    int i_flags = 0;
-    i_flags = p_item->i_flags;
-    lua_newtable( L );
-    lua_pushinteger( L, p_item->i_id );
-    lua_setfield( L, -2, "id" );
-    lua_newtable( L );
-#define CHECK_AND_SET_FLAG( name, label ) \
-    if( i_flags & PLAYLIST_ ## name ## _FLAG ) \
-    { \
-        lua_pushboolean( L, 1 ); \
-        lua_setfield( L, -2, #label ); \
-    }
-    CHECK_AND_SET_FLAG( DBL, disabled )
-    CHECK_AND_SET_FLAG( RO, ro )
-#undef CHECK_AND_SET_FLAG
-    lua_setfield( L, -2, "flags" );
-    if( p_input )
-    {
-        /* Apart from nb_played, these fields unfortunately duplicate
-           fields already available from the input item */
-        char *psz_name = input_item_GetTitleFbName( p_input );
-        lua_pushstring( L, psz_name );
-        free( psz_name );
-        lua_setfield( L, -2, "name" );
-        lua_pushstring( L, p_input->psz_uri );
-        lua_setfield( L, -2, "path" );
-        if( p_input->i_duration < 0 )
-            lua_pushnumber( L, -1 );
-        else
-            lua_pushnumber( L, secf_from_vlc_tick(p_input->i_duration) );
-        lua_setfield( L, -2, "duration" );
-        lua_pushinteger( L, p_item->i_nb_played );
-        lua_setfield( L, -2, "nb_played" );
-        luaopen_input_item( L, p_input );
-    }
-    if( p_item->i_children >= 0 )
-    {
-        int i;
-        lua_createtable( L, p_item->i_children, 0 );
-        for( i = 0; i < p_item->i_children; i++ )
-        {
-            push_playlist_item( L, p_item->pp_children[i] );
-            lua_rawseti( L, -2, i+1 );
-        }
-        lua_setfield( L, -2, "children" );
-    }
-}
+    lua_newtable(L);
 
-static int vlclua_playlist_get( lua_State *L )
-{
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    PL_LOCK;
-    playlist_item_t *p_item = NULL;
+    lua_pushinteger(L, vlc_playlist_item_GetId(item));
+    lua_setfield(L, -2, "id");
 
-    if( lua_isnumber( L, 1 ) )
-    {
-        int i_id = lua_tointeger( L, 1 );
-        p_item = playlist_ItemGetById( p_playlist, i_id );
-        if( !p_item )
-        {
-            PL_UNLOCK;
-            return 0; /* Should we return an error instead? */
-        }
-    }
-    else if( lua_isstring( L, 1 ) )
-    {
-        const char *psz_what = lua_tostring( L, 1 );
-        if( !strcasecmp( psz_what, "normal" )
-         || !strcasecmp( psz_what, "playlist" ) )
-            p_item = p_playlist->p_playing;
-        else if( !strcasecmp( psz_what, "root" ) )
-            p_item = &p_playlist->root;
-        else
-        {
-            /* currently, psz_what must be SD module's longname! */
-            p_item = playlist_ChildSearchName( &p_playlist->root, psz_what );
+    input_item_t *media = vlc_playlist_item_GetMedia(item);
 
-            if( !p_item )
-            {
-                PL_UNLOCK;
-                return 0; /* Should we return an error instead? */
-            }
-        }
-    }
+    /* Apart from nb_played, these fields unfortunately duplicate
+       fields already available from the input item */
+    char *name = input_item_GetTitleFbName(media);
+    lua_pushstring(L, name);
+    free(name);
+    lua_setfield(L, -2, "name");
+
+    lua_pushstring(L, media->psz_uri);
+    lua_setfield(L, -2, "path");
+
+    if( media->i_duration < 0 )
+        lua_pushnumber(L, -1);
     else
-    {
-        p_item = &p_playlist->root;
-    }
-    push_playlist_item( L, p_item );
-    PL_UNLOCK;
+        lua_pushnumber(L, secf_from_vlc_tick(media->i_duration));
+    lua_setfield(L, -2, "duration");
+
+    luaopen_input_item(L, media);
+}
+
+static int vlclua_playlist_get(lua_State *L)
+{
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+    uint64_t item_id = luaL_checkinteger(L, 1);
+
+    vlc_playlist_Lock(playlist);
+    ssize_t index = vlc_playlist_IndexOfId(playlist, item_id);
+    vlc_playlist_item_t *item = index != -1 ? vlc_playlist_Get(playlist, index)
+                                            : NULL;
+    if (item)
+        push_playlist_item(L, item);
+    else
+        lua_pushnil(L);
+    vlc_playlist_Unlock(playlist);
+
     return 1;
 }
 
-static int vlclua_playlist_current( lua_State *L )
+static int vlclua_playlist_current(lua_State *L)
 {
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    playlist_item_t *item;
-    int id = -1;
-
-    PL_LOCK;
-    item = playlist_CurrentPlayingItem( p_playlist );
-    if( item != NULL )
-        id = item->i_id;
-    PL_UNLOCK;
-    lua_pushinteger( L, id );
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+
+    vlc_playlist_Lock(playlist);
+    ssize_t current = vlc_playlist_GetCurrentIndex(playlist);
+    int id;
+    if (current != -1) {
+        vlc_playlist_item_t *item = vlc_playlist_Get(playlist, current);
+        id = vlc_playlist_item_GetId(item);
+    } else
+        id = -1;
+    vlc_playlist_Unlock(playlist);
+
+    lua_pushinteger(L, id);
     return 1;
 }
 
-static int vlc_sort_key_from_string( const char *psz_name )
+static bool vlc_sort_key_from_string(const char *keyname,
+                                     enum vlc_playlist_sort_key *key)
 {
     static const struct
     {
-        const char *psz_name;
-        int i_key;
-    } pp_keys[] =
-        { { "id", SORT_ID },
-          { "title", SORT_TITLE },
-          { "title nodes first", SORT_TITLE_NODES_FIRST },
-          { "artist", SORT_ARTIST },
-          { "genre", SORT_GENRE },
-          { "random", SORT_RANDOM },
-          { "duration", SORT_DURATION },
-          { "title numeric", SORT_TITLE_NUMERIC },
-          { "album", SORT_ALBUM },
-          { NULL, -1 } };
-    int i;
-    for( i = 0; pp_keys[i].psz_name; i++ )
+        const char *keyname;
+        enum vlc_playlist_sort_key key;
+    } map[] = {
+        { "title",    VLC_PLAYLIST_SORT_KEY_TITLE },
+        { "artist",   VLC_PLAYLIST_SORT_KEY_ARTIST },
+        { "genre",    VLC_PLAYLIST_SORT_KEY_GENRE },
+        { "duration", VLC_PLAYLIST_SORT_KEY_DURATION },
+        { "album",    VLC_PLAYLIST_SORT_KEY_ALBUM },
+    };
+    for (size_t i = 0; i < ARRAY_SIZE(map); ++i)
     {
-        if( !strcmp( psz_name, pp_keys[i].psz_name ) )
-            return pp_keys[i].i_key;
+        if (!strcmp(keyname, map[i].keyname))
+        {
+            *key = map[i].key;
+            return true;
+        }
     }
-    return -1;
+    return false;
 }
 
 static int vlclua_playlist_sort( lua_State *L )
 {
-    /* allow setting the different sort keys */
-    int i_mode = vlc_sort_key_from_string( luaL_checkstring( L, 1 ) );
-    if( i_mode == -1 )
-        return luaL_error( L, "Invalid search key." );
-    int i_type = luaL_optboolean( L, 2, 0 ) ? ORDER_REVERSE : ORDER_NORMAL;
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    PL_LOCK;
-    int i_ret = playlist_RecursiveNodeSort( p_playlist, p_playlist->p_playing,
-                                            i_mode, i_type );
-    PL_UNLOCK;
-    return vlclua_push_ret( L, i_ret );
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+
+    const char *keyname = luaL_checkstring(L, 1);
+
+    int ret;
+    if (!strcmp(keyname, "random"))
+    {
+        /* sort randomly -> shuffle */
+        vlc_playlist_Lock(playlist);
+        vlc_playlist_Shuffle(playlist);
+        vlc_playlist_Unlock(playlist);
+        ret = VLC_SUCCESS;
+    }
+    else
+    {
+        struct vlc_playlist_sort_criterion criterion;
+        if (!vlc_sort_key_from_string(keyname, &criterion.key))
+            return luaL_error(L, "Invalid search key.");
+        criterion.order = luaL_optboolean(L, 2, 0)
+                        ? VLC_PLAYLIST_SORT_ORDER_DESCENDING
+                        : VLC_PLAYLIST_SORT_ORDER_ASCENDING;
+
+        vlc_playlist_Lock(playlist);
+        ret = vlc_playlist_Sort(playlist, &criterion, 1);
+        vlc_playlist_Unlock(playlist);
+    }
+    return vlclua_push_ret(L, ret);
 }
 
-static int vlclua_playlist_status( lua_State *L )
+static int vlclua_playlist_status(lua_State *L)
 {
-    playlist_t *p_playlist = vlclua_get_playlist_internal( L );
-    PL_LOCK;
-    int status = playlist_Status( p_playlist );
-    PL_UNLOCK;
-    switch( status )
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+
+    vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+    vlc_player_Lock(player);
+    enum vlc_player_state state = vlc_player_GetState(player);
+    vlc_player_Unlock(player);
+
+    switch (state)
     {
-        case PLAYLIST_STOPPED:
-            lua_pushliteral( L, "stopped" );
+        case VLC_PLAYER_STATE_STOPPED:
+            lua_pushliteral(L, "stopped");
             break;
-        case PLAYLIST_RUNNING:
-            lua_pushliteral( L, "playing" );
+        case VLC_PLAYER_STATE_STARTED:
+            lua_pushliteral(L, "started");
             break;
-        case PLAYLIST_PAUSED:
-            lua_pushliteral( L, "paused" );
+        case VLC_PLAYER_STATE_PLAYING:
+            lua_pushliteral(L, "playing");
             break;
-        default:
-            lua_pushliteral( L, "unknown" );
+        case VLC_PLAYER_STATE_PAUSED:
+            lua_pushliteral(L, "paused");
+            break;
+        case VLC_PLAYER_STATE_STOPPING:
+            lua_pushliteral(L, "stopping");
             break;
+        default:
+            lua_pushliteral(L, "unknown");
     }
     return 1;
 }
diff --git a/modules/lua/libs/video.c b/modules/lua/libs/video.c
index e3d29cbd20..1ee2fabe8b 100644
--- a/modules/lua/libs/video.c
+++ b/modules/lua/libs/video.c
@@ -43,23 +43,15 @@
  *****************************************************************************/
 static int vlclua_fullscreen( lua_State *L )
 {
-    vout_thread_t *p_vout;
     int i_ret;
 
-    input_thread_t * p_input = vlclua_get_input_internal( L );
-    if( !p_input ) return vlclua_error( L );
-
-    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 vlclua_error( L );
-    }
 
     i_ret = vlclua_var_toggle_or_set( L, p_vout, "fullscreen" );
 
     vlc_object_release( p_vout );
-    vlc_object_release( p_input );
     return i_ret;
 }
 
diff --git a/modules/lua/libs/volume.c b/modules/lua/libs/volume.c
index fe379adb4e..ca0a1a9f70 100644
--- a/modules/lua/libs/volume.c
+++ b/modules/lua/libs/volume.c
@@ -36,7 +36,8 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_meta.h>
-#include <vlc_playlist_legacy.h>
+#include <vlc_playlist.h>
+#include <vlc_player.h>
 #include <vlc_aout.h>
 
 #include "../vlc.h"
@@ -45,41 +46,59 @@
 /*****************************************************************************
  * Volume related
  *****************************************************************************/
-static int vlclua_volume_set( lua_State *L )
+static int vlclua_volume_set(lua_State *L)
 {
-    playlist_t *p_this = vlclua_get_playlist_internal( L );
-    int i_volume = luaL_checkinteger( L, 1 );
-    if( i_volume < 0 )
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+    vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+
+    int i_volume = luaL_checkinteger(L, 1);
+    if (i_volume < 0)
         i_volume = 0;
-    int i_ret = playlist_VolumeSet( p_this, i_volume/(float)AOUT_VOLUME_DEFAULT );
-    return vlclua_push_ret( L, i_ret );
+
+    float volume = i_volume / (float) AOUT_VOLUME_DEFAULT;
+    int ret = vlc_player_aout_SetVolume(player, volume);
+    return vlclua_push_ret(L, ret);
 }
 
-static int vlclua_volume_get( lua_State *L )
+static int vlclua_volume_get(lua_State *L)
 {
-    playlist_t *p_this = vlclua_get_playlist_internal( L );
-    long i_volume = lroundf(playlist_VolumeGet( p_this ) * AOUT_VOLUME_DEFAULT);
-    lua_pushnumber( L, i_volume );
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+    vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+
+    float volume = vlc_player_aout_GetVolume(player);
+
+    long i_volume = lroundf(volume * AOUT_VOLUME_DEFAULT);
+    lua_pushnumber(L, i_volume);
     return 1;
 }
 
-static int vlclua_volume_up( lua_State *L )
+static int vlclua_volume_up(lua_State *L)
 {
-    playlist_t *p_this = vlclua_get_playlist_internal( L );
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+    vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+
     float volume;
+    int steps = luaL_optinteger(L, 1, 1);
+    int res = vlc_player_aout_IncrementVolume(player, steps, &volume);
 
-    playlist_VolumeUp( p_this, (int)luaL_optinteger( L, 1, 1 ), &volume );
-    lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
+    long i_volume = res == VLC_SUCCESS ? lroundf(volume * AOUT_VOLUME_DEFAULT)
+                                       : 0;
+    lua_pushnumber(L, i_volume);
     return 1;
 }
 
-static int vlclua_volume_down( lua_State *L )
+static int vlclua_volume_down(lua_State *L)
 {
-    playlist_t *p_this = vlclua_get_playlist_internal( L );
+    vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);
+    vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+
     float volume;
+    int steps = luaL_optinteger(L, 1, 1);
+    int res = vlc_player_aout_DecrementVolume(player, steps, &volume);
 
-    playlist_VolumeDown( p_this, (int)luaL_optinteger( L, 1, 1 ), &volume );
-    lua_pushnumber( L, lroundf(volume * AOUT_VOLUME_DEFAULT) );
+    long i_volume = res == VLC_SUCCESS ? lroundf(volume * AOUT_VOLUME_DEFAULT)
+                                       : 0;
+    lua_pushnumber(L, i_volume);
     return 1;
 }
 
diff --git a/modules/lua/vlc.h b/modules/lua/vlc.h
index 509900e192..36bcc25aad 100644
--- a/modules/lua/vlc.h
+++ b/modules/lua/vlc.h
@@ -29,7 +29,7 @@
 
 #include <vlc_common.h>
 #include <vlc_input.h>
-#include <vlc_playlist_legacy.h>
+#include <vlc_playlist.h>
 #include <vlc_meta.h>
 #include <vlc_meta_fetcher.h>
 #include <vlc_url.h>
@@ -142,8 +142,8 @@ void vlclua_set_this( lua_State *, vlc_object_t * );
 #define vlclua_set_this(a, b) vlclua_set_this(a, VLC_OBJECT(b))
 vlc_object_t * vlclua_get_this( lua_State * );
 
-void vlclua_set_playlist_internal( lua_State *, playlist_t * );
-playlist_t * vlclua_get_playlist_internal( lua_State * );
+void vlclua_set_playlist_internal( lua_State *, vlc_playlist_t * );
+vlc_playlist_t * vlclua_get_playlist_internal( lua_State * );
 
 /*****************************************************************************
  * Lua function bridge
-- 
2.20.1




More information about the vlc-devel mailing list