<html><head></head><body>Hi,<br><br>I'm all for using dedicated functions instead of VLC object variables. But are we keeping Lua going forward? Changing the Lua API makes little sense if we switch to a different scripting language anyway.<br><br>And no thanks for having two scripting languages at the same time.<br><br><div class="gmail_quote">Le 4 mars 2019 12:53:26 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">Many features were handled from LUA via VLC variables.<br><br>Expose functions for the new player and playlist instead.<hr> modules/lua/libs/input.c | 447 ++++++++++++++++++++++++++++++++++++<br> modules/lua/libs/playlist.c | 45 ++++<br> 2 files changed, 492 insertions(+)<br><br>diff --git a/modules/lua/libs/input.c b/modules/lua/libs/input.c<br>index cae6747ddf..ad8813a61d 100644<br>--- a/modules/lua/libs/input.c<br>+++ b/modules/lua/libs/input.c<br>@@ -32,6 +32,7 @@<br> #endif<br> <br> #include <vlc_common.h><br>+#include <vlc_es.h><br> #include <vlc_meta.h><br> #include <vlc_url.h><br> #include <vlc_playlist_legacy.h><br>@@ -100,6 +101,421 @@ static int vlclua_input_is_playing( lua_State *L )<br> return 1;<br> }<br> <br>+static int vlclua_player_get_title_index(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ ssize_t idx = vlc_player_GetSelectedTitleIdx(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ lua_pushinteger(L, idx);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_get_titles_count(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ const struct vlc_player_title_list *titles =<br>+ vlc_player_GetTitleList(player);<br>+ size_t count = titles ? vlc_player_title_list_GetCount(titles) : 0;<br>+ vlc_player_Unlock(player);<br>+<br>+ lua_pushinteger(L, count);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_title_next(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SelectNextTitle(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_title_prev(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SelectPrevTitle(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_title_goto(lua_State *L)<br>+{<br>+ int idx = luaL_checkinteger(L, 1);<br>+<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SelectTitleIdx(player, idx);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_get_chapter_index(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ ssize_t idx = vlc_player_GetSelectedChapterIdx(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ lua_pushinteger(L, idx);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_get_chapters_count(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ const struct vlc_player_title *current_title =<br>+ vlc_player_GetSelectedTitle(player);<br>+<br>+ size_t count = current_title ? current_title->chapter_count : 0;<br>+ vlc_player_Unlock(player);<br>+<br>+ lua_pushinteger(L, count);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_chapter_next(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SelectNextChapter(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_chapter_prev(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SelectPrevChapter(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_chapter_goto(lua_State *L)<br>+{<br>+ int idx = luaL_checkinteger(L, 1);<br>+<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SelectChapterIdx(player, idx);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_get_time(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_tick_t time = vlc_player_GetTime(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ lua_pushinteger(L, US_FROM_VLC_TICK(time));<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_get_position(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ float pos = vlc_player_GetPosition(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ lua_pushnumber(L, pos);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_get_rate(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ float rate = vlc_player_GetRate(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ lua_pushnumber(L, rate);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_set_rate(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ float rate = luaL_checknumber(L, 1);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_ChangeRate(player, rate);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_increment_rate(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_IncrementRate(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_decrement_rate(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_DecrementRate(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_get_tracks_(lua_State *L,<br>+ enum es_format_category_e cat)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+<br>+ size_t count = vlc_player_GetTrackCount(player, cat);<br>+ lua_createtable(L, count, 0);<br>+<br>+ for (size_t i = 0; i < count; ++i)<br>+ {<br>+ const struct vlc_player_track *track =<br>+ vlc_player_GetTrackAt(player, cat, i);<br>+ if (!track) {<br>+ continue;<br>+ }<br>+<br>+ lua_newtable(L);<br>+<br>+ lua_pushinteger(L, vlc_es_id_GetInputId(track->es_id));<br>+ lua_setfield(L, -2, "id");<br>+<br>+ lua_pushstring(L, track->name);<br>+ lua_setfield(L, -2, "name");<br>+<br>+ lua_pushboolean(L, track->selected);<br>+ lua_setfield(L, -2, "selected");<br>+<br>+ lua_rawseti(L, -2, i + 1);<br>+ }<br>+<br>+ vlc_player_Unlock(player);<br>+<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_get_video_tracks(lua_State *L)<br>+{<br>+ return vlclua_player_get_tracks_(L, VIDEO_ES);<br>+}<br>+<br>+static int vlclua_player_get_audio_tracks(lua_State *L)<br>+{<br>+ return vlclua_player_get_tracks_(L, AUDIO_ES);<br>+}<br>+<br>+static int vlclua_player_get_spu_tracks(lua_State *L)<br>+{<br>+ return vlclua_player_get_tracks_(L, SPU_ES);<br>+}<br>+<br>+static const struct vlc_player_track *<br>+FindTrack(vlc_player_t *player, enum es_format_category_e cat, int id)<br>+{<br>+ size_t count = vlc_player_GetTrackCount(player, cat);<br>+ for (size_t i = 0; i < count; ++i)<br>+ {<br>+ const struct vlc_player_track *track =<br>+ vlc_player_GetTrackAt(player, cat, i);<br>+ if (id == vlc_es_id_GetInputId(track->es_id))<br>+ return track;<br>+ }<br>+ return NULL;<br>+}<br>+<br>+static int vlclua_player_toggle_track_(lua_State *L,<br>+ enum es_format_category_e cat,<br>+ int id)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+<br>+ const struct vlc_player_track *track = FindTrack(player, cat, id);<br>+ if (track) {<br>+ if (track->selected)<br>+ vlc_player_UnselectTrack(player, track->es_id);<br>+ else<br>+ vlc_player_SelectTrack(player, track->es_id);<br>+ }<br>+<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_toggle_video_track(lua_State *L)<br>+{<br>+ int id = luaL_checkinteger(L, 1);<br>+ return vlclua_player_toggle_track_(L, VIDEO_ES, id);<br>+}<br>+<br>+static int vlclua_player_toggle_audio_track(lua_State *L)<br>+{<br>+ int id = luaL_checkinteger(L, 1);<br>+ return vlclua_player_toggle_track_(L, AUDIO_ES, id);<br>+}<br>+<br>+static int vlclua_player_toggle_spu_track(lua_State *L)<br>+{<br>+ int id = luaL_checkinteger(L, 1);<br>+ return vlclua_player_toggle_track_(L, SPU_ES, id);<br>+}<br>+<br>+static int vlclua_player_next_video_frame(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_NextVideoFrame(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_seek_by_pos_(lua_State *L,<br>+ enum vlc_player_whence whence)<br>+{<br>+ float position = luaL_checknumber(L, 1);<br>+<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SeekByPos(player, position, VLC_PLAYER_SEEK_PRECISE, whence);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_seek_by_pos_absolute(lua_State *L)<br>+{<br>+ return vlclua_player_seek_by_pos_(L, VLC_PLAYER_WHENCE_ABSOLUTE);<br>+}<br>+<br>+static int vlclua_player_seek_by_pos_relative(lua_State *L)<br>+{<br>+ return vlclua_player_seek_by_pos_(L, VLC_PLAYER_WHENCE_RELATIVE);<br>+}<br>+<br>+static int vlclua_player_seek_by_time_(lua_State *L,<br>+ enum vlc_player_whence whence)<br>+{<br>+ int usec = luaL_checkinteger(L, 1);<br>+ vlc_tick_t time = VLC_TICK_FROM_US(usec);<br>+<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SeekByTime(player, time, VLC_PLAYER_SEEK_PRECISE, whence);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_seek_by_time_absolute(lua_State *L)<br>+{<br>+ return vlclua_player_seek_by_time_(L, VLC_PLAYER_WHENCE_ABSOLUTE);<br>+}<br>+<br>+static int vlclua_player_seek_by_time_relative(lua_State *L)<br>+{<br>+ return vlclua_player_seek_by_time_(L, VLC_PLAYER_WHENCE_RELATIVE);<br>+}<br>+<br>+static int vlclua_player_get_audio_delay(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_tick_t delay = vlc_player_GetAudioDelay(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ double delay_sec = secf_from_vlc_tick(delay);<br>+<br>+ lua_pushnumber(L, delay_sec);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_set_audio_delay(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ double delay_sec = luaL_checknumber(L, 1);<br>+ vlc_tick_t delay = vlc_tick_from_sec(delay_sec);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SetAudioDelay(player, delay, VLC_PLAYER_WHENCE_ABSOLUTE);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br>+static int vlclua_player_get_subtitle_delay(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_tick_t delay = vlc_player_GetSubtitleDelay(player);<br>+ vlc_player_Unlock(player);<br>+<br>+ double delay_sec = secf_from_vlc_tick(delay);<br>+<br>+ lua_pushnumber(L, delay_sec);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_player_set_subtitle_delay(lua_State *L)<br>+{<br>+ vlc_player_t *player = vlclua_get_player_internal(L);<br>+<br>+ double delay_sec = luaL_checknumber(L, 1);<br>+ vlc_tick_t delay = vlc_tick_from_sec(delay_sec);<br>+<br>+ vlc_player_Lock(player);<br>+ vlc_player_SetSubtitleDelay(player, delay, VLC_PLAYER_WHENCE_ABSOLUTE);<br>+ vlc_player_Unlock(player);<br>+<br>+ return 0;<br>+}<br>+<br> static int vlclua_input_metas_internal( lua_State *L, input_item_t *p_item )<br> {<br> if( !p_item )<br>@@ -401,6 +817,37 @@ static const luaL_Reg vlclua_input_reg[] = {<br> { "item", vlclua_input_item_get_current },<br> { "add_subtitle", vlclua_input_add_subtitle_path },<br> { "add_subtitle_mrl", vlclua_input_add_subtitle_mrl },<br>+ { "get_title_index", vlclua_player_get_title_index },<br>+ { "get_titles_count", vlclua_player_get_titles_count },<br>+ { "title_next", vlclua_player_title_next },<br>+ { "title_prev", vlclua_player_title_prev },<br>+ { "title_goto", vlclua_player_title_goto },<br>+ { "get_chapter_index", vlclua_player_get_chapter_index },<br>+ { "get_chapters_count", vlclua_player_get_chapters_count },<br>+ { "chapter_next", vlclua_player_chapter_next },<br>+ { "chapter_prev", vlclua_player_chapter_prev },<br>+ { "chapter_goto", vlclua_player_chapter_goto },<br>+ { "get_time", vlclua_player_get_time },<br>+ { "get_position", vlclua_player_get_position },<br>+ { "get_rate", vlclua_player_get_rate },<br>+ { "set_rate", vlclua_player_set_rate },<br>+ { "increment_rate", vlclua_player_increment_rate },<br>+ { "decrement_rate", vlclua_player_decrement_rate },<br>+ { "get_video_tracks", vlclua_player_get_video_tracks },<br>+ { "get_audio_tracks", vlclua_player_get_audio_tracks },<br>+ { "get_spu_tracks", vlclua_player_get_spu_tracks },<br>+ { "toggle_video_track", vlclua_player_toggle_video_track },<br>+ { "toggle_audio_track", vlclua_player_toggle_audio_track },<br>+ { "toggle_spu_track", vlclua_player_toggle_spu_track },<br>+ { "next_video_frame", vlclua_player_next_video_frame },<br>+ { "seek_by_pos_absolute", vlclua_player_seek_by_pos_absolute },<br>+ { "seek_by_pos_relative", vlclua_player_seek_by_pos_relative },<br>+ { "seek_by_time_absolute", vlclua_player_seek_by_time_absolute },<br>+ { "seek_by_time_relative", vlclua_player_seek_by_time_relative },<br>+ { "get_audio_delay", vlclua_player_get_audio_delay },<br>+ { "set_audio_delay", vlclua_player_set_audio_delay },<br>+ { "get_subtitle_delay", vlclua_player_get_subtitle_delay },<br>+ { "set_subtitle_delay", vlclua_player_set_subtitle_delay },<br> { NULL, NULL }<br> };<br> <br>diff --git a/modules/lua/libs/playlist.c b/modules/lua/libs/playlist.c<br>index 73c334e927..956da0a677 100644<br>--- a/modules/lua/libs/playlist.c<br>+++ b/modules/lua/libs/playlist.c<br>@@ -184,6 +184,34 @@ static int vlclua_playlist_loop(lua_State *L)<br> return vlclua_playlist_repeat_(L, VLC_PLAYLIST_PLAYBACK_REPEAT_ALL);<br> }<br> <br>+static int vlclua_playlist_get_repeat(lua_State *L)<br>+{<br>+ vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);<br>+<br>+ vlc_playlist_Lock(playlist);<br>+ enum vlc_playlist_playback_repeat repeat =<br>+ vlc_playlist_GetPlaybackRepeat(playlist);<br>+ bool result = repeat != VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;<br>+ vlc_playlist_Unlock(playlist);<br>+<br>+ lua_pushboolean(L, result);<br>+ return 1;<br>+}<br>+<br>+static int vlclua_playlist_get_loop(lua_State *L)<br>+{<br>+ vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);<br>+<br>+ vlc_playlist_Lock(playlist);<br>+ enum vlc_playlist_playback_repeat repeat =<br>+ vlc_playlist_GetPlaybackRepeat(playlist);<br>+ bool result = repeat == VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;<br>+ vlc_playlist_Unlock(playlist);<br>+<br>+ lua_pushboolean(L, result);<br>+ return 1;<br>+}<br>+<br> static int vlclua_playlist_random(lua_State *L)<br> {<br> vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);<br>@@ -218,6 +246,20 @@ static int vlclua_playlist_random(lua_State *L)<br> return 1;<br> }<br> <br>+static int vlclua_playlist_get_random(lua_State *L)<br>+{<br>+ vlc_playlist_t *playlist = vlclua_get_playlist_internal(L);<br>+<br>+ vlc_playlist_Lock(playlist);<br>+ enum vlc_playlist_playback_order order =<br>+ vlc_playlist_GetPlaybackOrder(playlist);<br>+ bool result = order == VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM;<br>+ vlc_playlist_Unlock(playlist);<br>+<br>+ lua_pushboolean(L, result);<br>+ return 1;<br>+}<br>+<br> static int vlclua_playlist_gotoitem(lua_State *L)<br> {<br> uint64_t id = luaL_checkinteger(L, 1);<br>@@ -547,6 +589,9 @@ static const luaL_Reg vlclua_playlist_reg[] = {<br> { "repeat_", vlclua_playlist_repeat }, // ... provide repeat_ too.<br> { "loop", vlclua_playlist_loop },<br> { "random", vlclua_playlist_random },<br>+ { "get_repeat", vlclua_playlist_get_repeat },<br>+ { "get_loop", vlclua_playlist_get_loop },<br>+ { "get_random", vlclua_playlist_get_random },<br> #if LUA_VERSION_NUM < 502<br> { "goto", vlclua_playlist_gotoitem },<br> #endif</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>