Commit 80d51438 authored by Akash Mehrotra's avatar Akash Mehrotra Committed by Jean-Baptiste Kempf

LUA: Enable/Disable EQ, fix EQ input validation, and presets getter

move equalizer.xml to httprequests.lua
Use a table to return equalizer band values
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 8568f791
......@@ -34,6 +34,7 @@
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_aout_intf.h>
#include <vlc_input.h>
#include <vlc_charset.h>
......@@ -42,6 +43,9 @@
#include "input.h"
#include "../libs.h"
#include "../vlc.h"
#include "playlist.h"
#include "../../audio_filter/equalizer_presets.h"
#if !defined WIN32
# include <locale.h>
......@@ -128,14 +132,14 @@ Band 8: 14 kHz
Band 9: 16 kHz
*****************************************************************************/
/*****************************************************************************
* Get the equalizer level for the specified band
* Return EQ level for all bands as a Table
*****************************************************************************/
static int vlclua_equalizer_get( lua_State *L )
{
int bands = 9;
input_thread_t *p_input = vlclua_get_input_internal( L );
if( !p_input )
return 0;
audio_output_t *p_aout = input_GetAout( p_input );
vlc_object_release( p_input );
if( !p_aout )
......@@ -151,15 +155,28 @@ static int vlclua_equalizer_get( lua_State *L )
}
free( psz_af );
int bandid = luaL_checknumber( L, 1 );
char *psz_bands_origin, *psz_bands;
psz_bands_origin = psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
if( !psz_bands )
{
vlc_object_release( p_aout );
return 0;
}
locale_t loc = newlocale (LC_NUMERIC_MASK, "C", NULL);
locale_t oldloc = uselocale (loc);
while( bandid >= 0 )
int i = 0;
char *str;
lua_newtable( L );
while( bands >= 0 )
{
level = strtof( psz_bands, &psz_bands);
bandid--;
bands--;
asprintf( &str , "%f" , level );
lua_pushstring( L, str );
free(str);
asprintf( &str , "band_%d", i++ );
lua_setfield( L , -2 , str );
free(str);
}
free( psz_bands_origin );
if (loc != (locale_t)0)
......@@ -167,15 +184,8 @@ static int vlclua_equalizer_get( lua_State *L )
uselocale (oldloc);
freelocale (loc);
}
vlc_object_release( p_aout );
if( bandid == -1 )
{
lua_pushnumber( L, level );
return 1;
}
else
return 0;
return 1;
}
......@@ -184,6 +194,9 @@ static int vlclua_equalizer_get( lua_State *L )
*****************************************************************************/
static int vlclua_equalizer_set( lua_State *L )
{
int bandid = luaL_checknumber( L, 1 );
if ( bandid < 0 || bandid > 9)
return 0;
input_thread_t *p_input = vlclua_get_input_internal( L );
if( !p_input )
return 0;
......@@ -203,7 +216,6 @@ static int vlclua_equalizer_set( lua_State *L )
}
free( psz_af );
int bandid = luaL_checknumber( L, 1 );
float level = luaL_checknumber( L, 2 );
char *bands = var_GetString( p_aout, "equalizer-bands" );
char newstr[7];
......@@ -227,12 +239,39 @@ static int vlclua_equalizer_set( lua_State *L )
return 1;
}
/****************************************************************************
* Enable/disable Equalizer
*****************************************************************************/
static int vlclua_equalizer_enable ( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
bool state = luaL_checkboolean ( L , 1 );
aout_EnableFilter( p_playlist, "equalizer", state );
return 0;
}
/*****************************************************************************
* Get preset names
*****************************************************************************/
static int vlclua_equalizer_get_presets( lua_State *L )
{
lua_newtable( L );
char *str;
for( int i = 0 ; i < NB_PRESETS ; i++ )
{
lua_pushstring( L, preset_list_text[i] );
asprintf( &str , "id_%d",i );
lua_setfield( L , -2 , str );
free(str);
}
return 1;
}
static const luaL_Reg vlclua_equalizer_reg[] = {
{ "preampget", vlclua_preamp_get },
{ "preampset", vlclua_preamp_set },
{ "equalizerget", vlclua_equalizer_get },
{ "equalizerset", vlclua_equalizer_set },
{ "enable", vlclua_equalizer_enable },
{"presets",vlclua_equalizer_get_presets },
{ NULL, NULL }
};
......
......@@ -333,7 +333,6 @@ DIST_http_lua = \
lua/http/requests/playlist.xml \
lua/http/requests/README.txt \
lua/http/requests/playlist_jstree.xml \
lua/http/requests/equalizer.xml \
lua/http/requests/browse.xml \
lua/http/requests/vlm_cmd.xml \
lua/http/requests/status.xml \
......
......@@ -63,7 +63,7 @@ status.xml or status.json
> set aspect ratio. Must be one of the following values. Any other value will reset aspect ratio to default
?command=aspectratio&val=<newratio>
Valid aspect ratio values: 1:1 , 4:3 , 5:4 , 16:9 , 16:10 , 221:100 , 235:100 , 239:100
Valid aspect ratio values: 1:1 , 4:3 , 5:4 , 16:9 , 16:10 , 221:100 , 235:100 , 239:100
> sort playlist using sort mode <val> and order <id>:
?command=pl_sort&id=<id>&val=<val>
......@@ -112,6 +112,23 @@ status.xml or status.json
+1H:2M -> seek 1 hour and 2 minutes forward
-10% -> seek 10% back
>command=preamp&val=<val in dB>
sets the preamp value, must be >=-20 and <=20
>command=equalizer&band=<band>&val=<gain in dB, must be >=-20 and <=20)
set the gain for a specific band
>command=enableeq&val=<0 or 1>
0 -- disables the equalizer
1 -- enables the equalizer
<Displays the equalizer band gains.
Band 0: 60 Hz, 1: 170 Hz, 2: 310 Hz, 3: 600 Hz, 4: 1 kHz,
5: 3 kHz, 6: 6 kHz, 7: 12 kHz , 8: 14 kHz , 9: 16 kHz
<Display the list of presets available for the equalizer
=======
playlist.xml:
=============
< get the full playlist tree
......@@ -131,13 +148,3 @@ vlm_cmd.xml:
?command=<cmd>
> get the error message from <cmd>
equalizer.xml:
=============
>command=preamp&val=<val in dB>
sets the preamp value, must be >=-20 and <=20
>command=equalizer&band=<band>&val=<gain in dB, must be >=-20 and <=20)
<Displays the equalizer band gains.
Band 0: 60 Hz, 1: 170 Hz, 2: 310 Hz, 3: 600 Hz, 4: 1 kHz,
5: 3 kHz, 6: 6 kHz, 7: 12 kHz , 8: 14 kHz , 9: 16 kHz
<?xml version="1.0" encoding="utf-8" standalone="yes" ?<?vlcprint'>'?>
<?vlc --[[
vim:syntax=lua
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
< equalizer.xml: VLC media player web interface
< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >
< Copyright (C) 2011 the VideoLAN team
< $Id$
<
< Authors: Akash Mehrotra < mehrotra <dot> akash <at> gmail <dot> com >
<
< 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
local command = _GET['command']
local val = _GET['val']
local band = _GET['band']
function round(what, precision)
if what then return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision) else return "" end
end
if command == "preamp" then vlc.equalizer.preampset(val)
elseif command == "equalizer" then vlc.equalizer.equalizerset(band,val)
end
freq = { 60 , 170 , 310 , 600 , 1000 , 3000 , 6000 , 12000 , 14000 , 16000 }
?>
<root>
<preamp><?vlc print(round(vlc.equalizer.preampget(),2)) ?></preamp>
<equalizer>
<?vlc for i = 0,9
do print("<band id='"..i.."' freqency = '"..freq[i+1].."'>"..round(vlc.equalizer.equalizerget(i),1).."</band>") end ?>
</equalizer>
</root>
......@@ -59,20 +59,24 @@ function strsplit(text, delimiter)
return list
end
function round(what, precision)
if what then return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision) else return "" end
end
--main function to process commands sent with the request
processcommands = function ()
local input = _GET['input']
local command = _GET['command']
local id = tonumber(_GET['id'] or -1)
local val = _GET['val']
local options = _GET['option']
local band = _GET['band']
if type(options) ~= "table" then -- Deal with the 0 or 1 option case
options = { options }
end
if command == "in_play" then
--[[
vlc.msg.err( "<options>" )
......@@ -158,8 +162,14 @@ processcommands = function ()
if vlc.object.vout() then
vlc.var.set(vlc.object.vout(),"aspect-ratio",val)
end
elseif command == "preamp" then
vlc.equalizer.preampset(val)
elseif command == "equalizer" then
vlc.equalizer.equalizerset(band,val)
elseif command == "enableeq" then
if val == '0' then vlc.equalizer.enable(false) else vlc.equalizer.enable(true) end
end
local input = nil
local command = nil
local id = nil
......@@ -183,18 +193,18 @@ local printJsonKeyValue = function (k,v,indent)
if (k) then
print("\""..k.."\":")
end
if (type(v)=="number") then
print(xmlString(v))
elseif (type(v)=="table") then
if (v._array==NULL) then
elseif (type(v)=="table") then
if (v._array==NULL) then
print("{\n")
printTableAsJson(v,indent+2)
print("\n}")
else
print("\n}")
else
print("[")
printArrayAsJson(v._array,indent+2)
print("\n]")
print("\n]")
end
else
print("\""..xmlString(v).."\"")
......@@ -206,7 +216,7 @@ printArrayAsJson = function(array,indent)
first=true
for i,v in ipairs(array) do
if not first then print(",") end
printJsonKeyValue(NULL,v,indent)
printJsonKeyValue(NULL,v,indent)
first=false
end
end
......@@ -226,13 +236,13 @@ local printXmlKeyValue = function (k,v,indent)
if (k) then
print("<"..k..">")
end
if (type(v)=="table") then
printTableAsXml(v,indent+2)
else
print(xmlString(v))
end
if (k) then
print("</"..k..">")
end
......@@ -260,7 +270,7 @@ end
getplaylist = function ()
local p
if _GET["search"] then
if _GET["search"] ~= "" then
_G.search_key = _GET["search"]
......@@ -272,54 +282,54 @@ getplaylist = function ()
else
p = vlc.playlist.get()
end
--logTable(p) --Uncomment to debug
return p
end
parseplaylist = function (item)
if item.flags.disabled then return end
if (item.children) then
local result={}
local name = vlc.strings.convert_xml_special_chars(item.name or "")
result["type"]="node"
result.id=tostring(item.id)
result.name=tostring(name)
result.ro=item.flags.ro and "ro" or "rw"
--store children in an array
--we use _array as a proxy for arrays
result.children={}
result.children._array={}
for _, child in ipairs(item.children) do
local nextChild=parseplaylist(child)
table.insert(result.children._array,nextChild)
end
end
return result
else
local result={}
local name, path = vlc.strings.convert_xml_special_chars(item.name or "", item.path or "")
local current_item = vlc.input.item()
-- Is the item the one currently played
if(current_item ~= nil) then
if(vlc.input.item().uri(current_item) == path) then
result.current = "current"
end
end
result["type"]="leaf"
result.id=tostring(item.id)
result.uri=tostring(path)
result.name=name
result.ro=item.flags.ro and "ro" or "rw"
result.duration=math.floor(item.duration)
return result
end
......@@ -328,7 +338,7 @@ end
playlisttable = function ()
local basePlaylist=getplaylist()
return parseplaylist(basePlaylist)
end
......@@ -343,20 +353,20 @@ local vout = vlc.object.vout()
local aout = vlc.object.aout()
local s ={}
--update api version when new data/commands added
s.apiversion=1
s.version=vlc.misc.version()
s.volume=vlc.volume.get()
if input then
if input then
s.length=math.floor(vlc.var.get(input,"length"))
s.time=math.floor(vlc.var.get(input,"time"))
s.position=vlc.var.get(input,"position")
s.audiodelay=vlc.var.get(input,"audio-delay")
s.rate=vlc.var.get(input,"rate")
s.subtitledelay=vlc.var.get(input,"spu-delay")
else
else
s.length=0
s.time=0
s.position=0
......@@ -391,12 +401,19 @@ local aout = vlc.object.aout()
s.random=vlc.var.get(playlist,"random")
s.loop=vlc.var.get(playlist,"loop")
s["repeat"]=vlc.var.get(playlist,"repeat")
s.equalizer={}
s.equalizer.preamp=round(vlc.equalizer.preampget(),2)
s.equalizer.bands=vlc.equalizer.equalizerget()
if s.equalizer.bands ~= null then
for k,i in pairs(s.equalizer.bands) do s.equalizer.bands[k]=round(i,2) end
s.equalizer.presets=vlc.equalizer.presets()
end
if (includecategories and item) then
s.information={}
s.information.category={}
s.information.category.meta=item:metas()
local info = item:info()
for k, v in pairs(info) do
local streamTable={}
......@@ -404,20 +421,21 @@ local aout = vlc.object.aout()
local tag = string.gsub(k2," ","_")
streamTable[xmlString(tag)]=xmlString(v2)
end
s.information.category[xmlString(k)]=streamTable
end
s.stats={}
local statsdata = item:stats()
for k,v in pairs(statsdata) do
local tag = string.gsub(k,"_","")
s.stats[tag]=xmlString(v)
end
end
return s
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment