[vlc-devel] [PATCH 2/2] lua: http: Expose renderers

Hugo Beauzée-Luyssen hugo at beauzee.fr
Wed Aug 19 10:49:45 CEST 2020


---
 share/Makefile.am                       |  2 ++
 share/lua/http/custom.lua               | 10 +++++++
 share/lua/http/requests/rd.json         | 34 +++++++++++++++++++++++
 share/lua/http/requests/rd.xml          | 37 +++++++++++++++++++++++++
 share/lua/intf/modules/httprequests.lua | 17 +++++++++++-
 5 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 share/lua/http/requests/rd.json
 create mode 100644 share/lua/http/requests/rd.xml

diff --git a/share/Makefile.am b/share/Makefile.am
index b326f2e744..2373ffbe91 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -218,6 +218,8 @@ nobase_dist_pkgdata_DATA += \
 	lua/http/requests/vlm_cmd.xml \
 	lua/http/requests/status.xml \
 	lua/http/requests/status.json \
+	lua/http/requests/rd.json \
+	lua/http/requests/rd.xml \
 	lua/http/requests/vlm.xml \
 	lua/http/index.html \
 	lua/http/css/ui-lightness/jquery-ui-1.8.13.custom.css \
diff --git a/share/lua/http/custom.lua b/share/lua/http/custom.lua
index d1551f53dd..e75715d79a 100644
--- a/share/lua/http/custom.lua
+++ b/share/lua/http/custom.lua
@@ -18,3 +18,13 @@ _G.dialogs = function(...)
 end
 
 _G.vlm = vlc.vlm()
+
+local _rd = nil
+
+_G.get_renderer_discovery = function()
+    if not _rd then
+        _rd = vlc.rd.create("mdns_renderer")
+    end
+    return _rd
+end
+
diff --git a/share/lua/http/requests/rd.json b/share/lua/http/requests/rd.json
new file mode 100644
index 0000000000..d01d787ffe
--- /dev/null
+++ b/share/lua/http/requests/rd.json
@@ -0,0 +1,34 @@
+<?vlc --[[
+vim:syntax=lua
+<!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
+<  rd.json: VLC media player web interface
+< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
+<  Copyright (C) 2020 the VideoLAN team
+<
+<  This program is free software; you can redistribute it and/or modify
+<  it under the terms of the GNU General Public License as published by
+<  the Free Software Foundation; either version 2 of the License, or
+<  (at your option) any later version.
+<
+<  This program is distributed in the hope that it will be useful,
+<  but WITHOUT ANY WARRANTY; without even the implied warranty of
+<  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+<  GNU General Public License for more details.
+<
+<  You should have received a copy of the GNU General Public License
+<  along with this program; if not, write to the Free Software
+<  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+]]?>
+<?vlc
+
+--package.loaded.httprequests = nil --uncomment to debug changes
+require "httprequests"
+
+httprequests.processcommands()
+
+local rdTable=httprequests.get_renderers()
+
+httprequests.printTableAsJson(rdTable)
+
+?>
diff --git a/share/lua/http/requests/rd.xml b/share/lua/http/requests/rd.xml
new file mode 100644
index 0000000000..6b8b3d3fb9
--- /dev/null
+++ b/share/lua/http/requests/rd.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
+<?vlc --[[
+vim:syntax=lua
+<!--  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
+<  rd.xml: VLC media player web interface
+< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
+<  Copyright (C) 2020 the VideoLAN team
+<
+<  This program is free software; you can redistribute it and/or modify
+<  it under the terms of the GNU General Public License as published by
+<  the Free Software Foundation; either version 2 of the License, or
+<  (at your option) any later version.
+<
+<  This program is distributed in the hope that it will be useful,
+<  but WITHOUT ANY WARRANTY; without even the implied warranty of
+<  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+<  GNU General Public License for more details.
+<
+<  You should have received a copy of the GNU General Public License
+<  along with this program; if not, write to the Free Software
+<  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+]]?>
+
+<?vlc
+
+require "httprequests"
+
+httprequests.processcommands()
+
+local rdTable=httprequests.get_renderers()
+
+print('<root>\n')
+httprequests.printTableAsXml(rdTable,0)
+
+?>
+</root>
diff --git a/share/lua/intf/modules/httprequests.lua b/share/lua/intf/modules/httprequests.lua
index 1f564c6f44..cdbc5a94b1 100644
--- a/share/lua/intf/modules/httprequests.lua
+++ b/share/lua/intf/modules/httprequests.lua
@@ -187,6 +187,14 @@ processcommands = function ()
         vlc.player.toggle_video_track(val)
     elseif command == "subtitle_track" then
         vlc.player.toggle_spu_track(val)
+    elseif command == "set_renderer" then
+        local rd = get_renderer_discovery()
+        if not rd then
+            return
+        end
+        rd:select(id)
+    elseif command == "unset_renderer" then
+        rd:select(-1)
     end
 
     local input = nil
@@ -426,7 +434,7 @@ getstatus = function (includecategories)
     local s ={}
 
     --update api version when new data/commands added
-    s.apiversion=3
+    s.apiversion=4
     s.version=vlc.misc.version()
     s.volume=vlc.volume.get()
 
@@ -516,3 +524,10 @@ getstatus = function (includecategories)
     return s
 end
 
+get_renderers = function()
+    local rd = get_renderer_discovery()
+    if not rd then
+        return {}
+    end
+    return rd:list()
+end
-- 
2.20.1



More information about the vlc-devel mailing list