1 /*****************************************************************************
2 * intf.c: Generic lua interface functions
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan tod org>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
38 #include <lua.h> /* Low level lua C API */
39 #include <lauxlib.h> /* Higher level C API */
45 /*****************************************************************************
47 *****************************************************************************/
48 static int vlc_osd_icon_from_string( const char *psz_name )
55 { { OSD_PAUSE_ICON, "pause" },
56 { OSD_PLAY_ICON, "play" },
57 { OSD_SPEAKER_ICON, "speaker" },
58 { OSD_MUTE_ICON, "mute" },
61 for( i = 0; pp_icons[i].psz_name; i++ )
63 if( !strcmp( psz_name, pp_icons[i].psz_name ) )
64 return pp_icons[i].i_icon;
69 static int vlclua_osd_icon( lua_State *L )
71 const char *psz_icon = luaL_checkstring( L, 1 );
72 int i_icon = vlc_osd_icon_from_string( psz_icon );
73 int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
75 return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
77 input_thread_t *p_input = vlclua_get_input_internal( L );
80 vout_thread_t *p_vout = input_GetVout( p_input );
83 vout_OSDIcon( p_vout, i_chan, i_icon );
84 vlc_object_release( p_vout );
86 vlc_object_release( p_input );
91 static int vlc_osd_position_from_string( const char *psz_name )
98 { { SUBPICTURE_ALIGN_MASK, "center" },
99 { SUBPICTURE_ALIGN_LEFT, "left" },
100 { SUBPICTURE_ALIGN_RIGHT, "rigth" },
101 { SUBPICTURE_ALIGN_TOP, "top" },
102 { SUBPICTURE_ALIGN_BOTTOM, "bottom" },
103 { SUBPICTURE_ALIGN_TOP |SUBPICTURE_ALIGN_LEFT, "top-left" },
104 { SUBPICTURE_ALIGN_TOP |SUBPICTURE_ALIGN_RIGHT, "top-right" },
105 { SUBPICTURE_ALIGN_BOTTOM|SUBPICTURE_ALIGN_LEFT, "bottom-left" },
106 { SUBPICTURE_ALIGN_BOTTOM|SUBPICTURE_ALIGN_RIGHT, "bottom-right" },
109 for( i = 0; pp_icons[i].psz_name; i++ )
111 if( !strcmp( psz_name, pp_icons[i].psz_name ) )
112 return pp_icons[i].i_position;
117 static int vlclua_osd_message( lua_State *L )
119 const char *psz_message = luaL_checkstring( L, 1 );
120 int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
121 const char *psz_position = luaL_optstring( L, 3, "top-right" );
122 mtime_t duration = luaL_optint( L, 4, 1000000 );
124 input_thread_t *p_input = vlclua_get_input_internal( L );
127 vout_thread_t *p_vout = input_GetVout( p_input );
130 vout_OSDText( p_vout, i_chan, vlc_osd_position_from_string( psz_position ),
131 duration, psz_message );
132 vlc_object_release( p_vout );
134 vlc_object_release( p_input );
139 static int vlc_osd_slider_type_from_string( const char *psz_name )
144 const char *psz_name;
146 { { OSD_HOR_SLIDER, "horizontal" },
147 { OSD_VERT_SLIDER, "vertical" },
150 for( i = 0; pp_types[i].psz_name; i++ )
152 if( !strcmp( psz_name, pp_types[i].psz_name ) )
153 return pp_types[i].i_type;
158 static int vlclua_osd_slider( lua_State *L )
160 int i_position = luaL_checkint( L, 1 );
161 const char *psz_type = luaL_checkstring( L, 2 );
162 int i_type = vlc_osd_slider_type_from_string( psz_type );
163 int i_chan = luaL_optint( L, 3, SPU_DEFAULT_CHANNEL );
165 return luaL_error( L, "\"%s\" is not a valid slider type.",
168 input_thread_t *p_input = vlclua_get_input_internal( L );
171 vout_thread_t *p_vout = input_GetVout( p_input );
174 vout_OSDSlider( p_vout, i_chan, i_position, i_type );
175 vlc_object_release( p_vout );
177 vlc_object_release( p_input );
182 static int vlclua_spu_channel_register( lua_State *L )
184 input_thread_t *p_input = vlclua_get_input_internal( L );
186 return luaL_error( L, "Unable to find input." );
188 vout_thread_t *p_vout = input_GetVout( p_input );
191 vlc_object_release( p_input );
192 return luaL_error( L, "Unable to find vout." );
195 int i_chan = vout_RegisterSubpictureChannel( p_vout );
196 vlc_object_release( p_vout );
197 vlc_object_release( p_input );
198 lua_pushinteger( L, i_chan );
202 static int vlclua_spu_channel_clear( lua_State *L )
204 int i_chan = luaL_checkint( L, 1 );
205 input_thread_t *p_input = vlclua_get_input_internal( L );
207 return luaL_error( L, "Unable to find input." );
208 vout_thread_t *p_vout = input_GetVout( p_input );
211 vlc_object_release( p_input );
212 return luaL_error( L, "Unable to find vout." );
215 vout_FlushSubpictureChannel( p_vout, i_chan );
216 vlc_object_release( p_vout );
217 vlc_object_release( p_input );
221 static int vlclua_menu_show( lua_State *L )
223 vlc_object_t *p_this = vlclua_get_this( L );
224 osd_MenuShow( p_this );
228 static int vlclua_menu_hide( lua_State *L )
230 vlc_object_t *p_this = vlclua_get_this( L );
231 osd_MenuHide( p_this );
235 static int vlclua_menu_prev( lua_State *L )
237 vlc_object_t *p_this = vlclua_get_this( L );
238 osd_MenuPrev( p_this );
242 static int vlclua_menu_next( lua_State *L )
244 vlc_object_t *p_this = vlclua_get_this( L );
245 osd_MenuNext( p_this );
249 static int vlclua_menu_up( lua_State *L )
251 vlc_object_t *p_this = vlclua_get_this( L );
252 osd_MenuUp( p_this );
256 static int vlclua_menu_down( lua_State *L )
258 vlc_object_t *p_this = vlclua_get_this( L );
259 osd_MenuDown( p_this );
263 static int vlclua_menu_activate( lua_State *L )
265 vlc_object_t *p_this = vlclua_get_this( L );
266 osd_MenuActivate( p_this );
270 /*****************************************************************************
272 *****************************************************************************/
273 static const luaL_Reg vlclua_osd_reg[] = {
274 { "icon", vlclua_osd_icon },
275 { "message", vlclua_osd_message },
276 { "slider", vlclua_osd_slider },
277 { "channel_register", vlclua_spu_channel_register },
278 { "channel_clear", vlclua_spu_channel_clear },
282 static const luaL_Reg vlclua_menu_reg[] = {
283 { "show", vlclua_menu_show },
284 { "hide", vlclua_menu_hide },
285 { "prev", vlclua_menu_prev },
286 { "next", vlclua_menu_next },
287 { "up", vlclua_menu_up },
288 { "down", vlclua_menu_down },
289 { "activate", vlclua_menu_activate },
293 void luaopen_osd( lua_State *L )
296 luaL_register( L, NULL, vlclua_osd_reg );
298 luaL_register( L, NULL, vlclua_menu_reg );
299 lua_setfield( L, -2, "menu" );
300 lua_setfield( L, -2, "osd" );