]> git.sesse.net Git - vlc/blob - modules/lua/libs/equalizer.c
lua: fix object leaks.
[vlc] / modules / lua / libs / equalizer.c
1 /*****************************************************************************
2  * equalizer.c
3  *****************************************************************************
4  * Copyright (C) 2011 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Akash Mehrotra < mehrotra <dot> akash <at> gmail <dot> com >
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifndef  _GNU_SOURCE
28 #   define  _GNU_SOURCE
29 #endif
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <vlc_common.h>
36 #include <vlc_aout.h>
37 #include <vlc_input.h>
38 #include <lua.h>        /* Low level lua C API */
39 #include <lauxlib.h>    /* Higher level C API */
40 #include <lualib.h>     /* Lua libs */
41 #include "input.h"
42 /*****************************************************************************
43 * Get the preamp level
44 *****************************************************************************/
45 static int vlclua_preamp_get( lua_State *L )
46 {
47     input_thread_t *p_input = vlclua_get_input_internal( L );
48     if( p_input )
49     {
50         aout_instance_t *p_aout = input_GetAout( p_input );
51         float preamp = var_GetFloat( p_aout, "equalizer-preamp");
52         lua_pushnumber( L, preamp );
53
54         vlc_object_release( p_aout );
55         vlc_object_release( p_input );
56         return 1;
57     }
58     return 0;
59 }
60
61 /*****************************************************************************
62 * Set the preamp level
63 *****************************************************************************/
64 static int vlclua_preamp_set( lua_State *L )
65 {
66     input_thread_t *p_input = vlclua_get_input_internal( L );
67     if( p_input )
68     {
69         aout_instance_t *p_aout = input_GetAout( p_input );
70         float preamp = luaL_checknumber( L, 1 );
71         var_SetFloat( p_aout, "equalizer-preamp",preamp);
72         lua_pushnumber( L, preamp );
73
74         vlc_object_release( p_aout );
75         vlc_object_release( p_input );
76         return 1;
77     }
78     return 0;
79 }
80
81 static const luaL_Reg vlclua_equalizer_reg[] = {
82     { "preampget", vlclua_preamp_get },
83     { "preampset", vlclua_preamp_set },
84     { NULL, NULL }
85 };
86
87 void luaopen_equalizer( lua_State *L )
88 {
89     lua_newtable( L );
90     luaL_register( L, NULL, vlclua_equalizer_reg );
91     lua_setfield( L, -2, "equalizer" );
92 }