[vlc-commits] HTTP interface: give access to equalizer preamp

Akash Mehrotra git at videolan.org
Wed Jun 15 02:01:58 CEST 2011


vlc | branch: master | Akash Mehrotra <mehrotra.akash at gmail.com> | Wed Jun 15 01:37:59 2011 +0530| [187293b678d2c96ff2287d0a6844e35935cb2842] | committer: Jean-Baptiste Kempf

HTTP interface: give access to equalizer preamp

This is the first part of the equalizer control

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=187293b678d2c96ff2287d0a6844e35935cb2842
---

 modules/lua/Modules.am                |    1 +
 modules/lua/intf.c                    |    1 +
 modules/lua/libs.h                    |    1 +
 modules/lua/libs/equalizer.c          |   86 +++++++++++++++++++++++++++++++++
 share/lua/http/requests/README.txt    |    5 ++
 share/lua/http/requests/equalizer.xml |   38 ++++++++++++++
 6 files changed, 132 insertions(+), 0 deletions(-)

diff --git a/modules/lua/Modules.am b/modules/lua/Modules.am
index d715ef9..a806804 100644
--- a/modules/lua/Modules.am
+++ b/modules/lua/Modules.am
@@ -11,6 +11,7 @@ SOURCES_lua = \
 	libs.h \
 	libs/acl.c \
 	libs/configuration.c \
+	libs/equalizer.c \
 	libs/gettext.c \
 	libs/dialog.c \
 	libs/httpd.c \
diff --git a/modules/lua/intf.c b/modules/lua/intf.c
index c2c203f..bcc1df9 100644
--- a/modules/lua/intf.c
+++ b/modules/lua/intf.c
@@ -255,6 +255,7 @@ int Open_LuaIntf( vlc_object_t *p_this )
     luaopen_gettext( L );
     luaopen_xml( L );
     luaopen_md5( L );
+    luaopen_equalizer( L );
 
     /* clean up */
     lua_pop( L, 1 );
diff --git a/modules/lua/libs.h b/modules/lua/libs.h
index 8bca89c..9afaac0 100644
--- a/modules/lua/libs.h
+++ b/modules/lua/libs.h
@@ -46,5 +46,6 @@ void luaopen_gettext( lua_State * );
 void luaopen_input_item( lua_State *L, input_item_t *item );
 void luaopen_xml( lua_State *L );
 void luaopen_md5( lua_State *L );
+void luaopen_equalizer( lua_State *L );
 
 #endif
diff --git a/modules/lua/libs/equalizer.c b/modules/lua/libs/equalizer.c
new file mode 100644
index 0000000..c4d8d38
--- /dev/null
+++ b/modules/lua/libs/equalizer.c
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * equalizer.c
+ *****************************************************************************
+ * 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.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#ifndef  _GNU_SOURCE
+#   define  _GNU_SOURCE
+#endif
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_aout.h>
+#include <vlc_input.h>
+#include <lua.h>        /* Low level lua C API */
+#include <lauxlib.h>    /* Higher level C API */
+#include <lualib.h>     /* Lua libs */
+#include "input.h"
+/*****************************************************************************
+* Get the preamp level
+*****************************************************************************/
+static int vlclua_preamp_get( lua_State *L )
+{
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( p_input )
+    {
+        aout_instance_t *p_aout = input_GetAout( p_input );
+        float preamp = var_GetFloat( p_aout, "equalizer-preamp");
+        lua_pushnumber( L, preamp );
+        return 1;
+    }
+    return 0;
+}
+
+/*****************************************************************************
+* Set the preamp level
+*****************************************************************************/
+static int vlclua_preamp_set( lua_State *L )
+{
+    input_thread_t *p_input = vlclua_get_input_internal( L );
+    if( p_input )
+    {
+        aout_instance_t *p_aout = input_GetAout( p_input );
+        float preamp = luaL_checknumber( L, 1 );
+        var_SetFloat( p_aout, "equalizer-preamp",preamp);
+        lua_pushnumber( L, preamp );
+        return 1;
+    }
+    return 0;
+}
+
+static const luaL_Reg vlclua_equalizer_reg[] = {
+    { "preampget", vlclua_preamp_get },
+    { "preampset", vlclua_preamp_set },
+    { NULL, NULL }
+};
+
+void luaopen_equalizer( lua_State *L )
+{
+    lua_newtable( L );
+    luaL_register( L, NULL, vlclua_equalizer_reg );
+    lua_setfield( L, -2, "equalizer" );
+}
diff --git a/share/lua/http/requests/README.txt b/share/lua/http/requests/README.txt
index 0b19bb6..a327ff2 100644
--- a/share/lua/http/requests/README.txt
+++ b/share/lua/http/requests/README.txt
@@ -124,3 +124,8 @@ vlm_cmd.xml:
 < execute VLM command <cmd>
   ?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
diff --git a/share/lua/http/requests/equalizer.xml b/share/lua/http/requests/equalizer.xml
new file mode 100644
index 0000000..7476487
--- /dev/null
+++ b/share/lua/http/requests/equalizer.xml
@@ -0,0 +1,38 @@
+<?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']
+function round(what, precision)
+   return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision)
+end
+if command == "preamp" then vlc.equalizer.preampset(val) end
+?>
+<root>
+  <preamp><?vlc print(round(vlc.equalizer.preampget(),2)) ?></preamp>
+</root>



More information about the vlc-commits mailing list