1 /*****************************************************************************
2 * osd.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 *****************************************************************************/
42 /*****************************************************************************
44 *****************************************************************************/
45 static int vlc_osd_icon_from_string( const char *psz_name )
52 { { OSD_PAUSE_ICON, "pause" },
53 { OSD_PLAY_ICON, "play" },
54 { OSD_SPEAKER_ICON, "speaker" },
55 { OSD_MUTE_ICON, "mute" },
58 for( i = 0; pp_icons[i].psz_name; i++ )
60 if( !strcmp( psz_name, pp_icons[i].psz_name ) )
61 return pp_icons[i].i_icon;
66 static int vlclua_osd_icon( lua_State *L )
68 const char *psz_icon = luaL_checkstring( L, 1 );
69 int i_icon = vlc_osd_icon_from_string( psz_icon );
70 int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
72 return luaL_error( L, "\"%s\" is not a valid osd icon.", psz_icon );
74 input_thread_t *p_input = vlclua_get_input_internal( L );
77 vout_thread_t *p_vout = input_GetVout( p_input );
80 vout_OSDIcon( p_vout, i_chan, i_icon );
81 vlc_object_release( p_vout );
83 vlc_object_release( p_input );
88 static int vlc_osd_position_from_string( const char *psz_name )
95 { { SUBPICTURE_ALIGN_MASK, "center" },
96 { SUBPICTURE_ALIGN_LEFT, "left" },
97 { SUBPICTURE_ALIGN_RIGHT, "rigth" },
98 { SUBPICTURE_ALIGN_TOP, "top" },
99 { SUBPICTURE_ALIGN_BOTTOM, "bottom" },
100 { SUBPICTURE_ALIGN_TOP |SUBPICTURE_ALIGN_LEFT, "top-left" },
101 { SUBPICTURE_ALIGN_TOP |SUBPICTURE_ALIGN_RIGHT, "top-right" },
102 { SUBPICTURE_ALIGN_BOTTOM|SUBPICTURE_ALIGN_LEFT, "bottom-left" },
103 { SUBPICTURE_ALIGN_BOTTOM|SUBPICTURE_ALIGN_RIGHT, "bottom-right" },
106 for( i = 0; pp_icons[i].psz_name; i++ )
108 if( !strcmp( psz_name, pp_icons[i].psz_name ) )
109 return pp_icons[i].i_position;
114 static int vlclua_osd_message( lua_State *L )
116 const char *psz_message = luaL_checkstring( L, 1 );
117 int i_chan = luaL_optint( L, 2, SPU_DEFAULT_CHANNEL );
118 const char *psz_position = luaL_optstring( L, 3, "top-right" );
119 mtime_t duration = luaL_optint( L, 4, 1000000 );
121 input_thread_t *p_input = vlclua_get_input_internal( L );
124 vout_thread_t *p_vout = input_GetVout( p_input );
127 vout_OSDText( p_vout, i_chan, vlc_osd_position_from_string( psz_position ),
128 duration, psz_message );
129 vlc_object_release( p_vout );
131 vlc_object_release( p_input );
136 static int vlc_osd_slider_type_from_string( const char *psz_name )
141 const char *psz_name;
143 { { OSD_HOR_SLIDER, "horizontal" },
144 { OSD_VERT_SLIDER, "vertical" },
147 for( i = 0; pp_types[i].psz_name; i++ )
149 if( !strcmp( psz_name, pp_types[i].psz_name ) )
150 return pp_types[i].i_type;
155 static int vlclua_osd_slider( lua_State *L )
157 int i_position = luaL_checkint( L, 1 );
158 const char *psz_type = luaL_checkstring( L, 2 );
159 int i_type = vlc_osd_slider_type_from_string( psz_type );
160 int i_chan = luaL_optint( L, 3, SPU_DEFAULT_CHANNEL );
162 return luaL_error( L, "\"%s\" is not a valid slider type.",
165 input_thread_t *p_input = vlclua_get_input_internal( L );
168 vout_thread_t *p_vout = input_GetVout( p_input );
171 vout_OSDSlider( p_vout, i_chan, i_position, i_type );
172 vlc_object_release( p_vout );
174 vlc_object_release( p_input );
179 static int vlclua_spu_channel_register( lua_State *L )
181 input_thread_t *p_input = vlclua_get_input_internal( L );
183 return luaL_error( L, "Unable to find input." );
185 vout_thread_t *p_vout = input_GetVout( p_input );
188 vlc_object_release( p_input );
189 return luaL_error( L, "Unable to find vout." );
192 int i_chan = vout_RegisterSubpictureChannel( p_vout );
193 vlc_object_release( p_vout );
194 vlc_object_release( p_input );
195 lua_pushinteger( L, i_chan );
199 static int vlclua_spu_channel_clear( lua_State *L )
201 int i_chan = luaL_checkint( L, 1 );
202 input_thread_t *p_input = vlclua_get_input_internal( L );
204 return luaL_error( L, "Unable to find input." );
205 vout_thread_t *p_vout = input_GetVout( p_input );
208 vlc_object_release( p_input );
209 return luaL_error( L, "Unable to find vout." );
212 vout_FlushSubpictureChannel( p_vout, i_chan );
213 vlc_object_release( p_vout );
214 vlc_object_release( p_input );
218 static int vlclua_menu_show( lua_State *L )
220 vlc_object_t *p_this = vlclua_get_this( L );
221 osd_MenuShow( p_this );
225 static int vlclua_menu_hide( lua_State *L )
227 vlc_object_t *p_this = vlclua_get_this( L );
228 osd_MenuHide( p_this );
232 static int vlclua_menu_prev( lua_State *L )
234 vlc_object_t *p_this = vlclua_get_this( L );
235 osd_MenuPrev( p_this );
239 static int vlclua_menu_next( lua_State *L )
241 vlc_object_t *p_this = vlclua_get_this( L );
242 osd_MenuNext( p_this );
246 static int vlclua_menu_up( lua_State *L )
248 vlc_object_t *p_this = vlclua_get_this( L );
249 osd_MenuUp( p_this );
253 static int vlclua_menu_down( lua_State *L )
255 vlc_object_t *p_this = vlclua_get_this( L );
256 osd_MenuDown( p_this );
260 static int vlclua_menu_activate( lua_State *L )
262 vlc_object_t *p_this = vlclua_get_this( L );
263 osd_MenuActivate( p_this );
267 /*****************************************************************************
269 *****************************************************************************/
270 static const luaL_Reg vlclua_osd_reg[] = {
271 { "icon", vlclua_osd_icon },
272 { "message", vlclua_osd_message },
273 { "slider", vlclua_osd_slider },
274 { "channel_register", vlclua_spu_channel_register },
275 { "channel_clear", vlclua_spu_channel_clear },
279 static const luaL_Reg vlclua_menu_reg[] = {
280 { "show", vlclua_menu_show },
281 { "hide", vlclua_menu_hide },
282 { "prev", vlclua_menu_prev },
283 { "next", vlclua_menu_next },
284 { "up", vlclua_menu_up },
285 { "down", vlclua_menu_down },
286 { "activate", vlclua_menu_activate },
290 void luaopen_osd( lua_State *L )
293 luaL_register( L, NULL, vlclua_osd_reg );
295 luaL_register( L, NULL, vlclua_menu_reg );
296 lua_setfield( L, -2, "menu" );
297 lua_setfield( L, -2, "osd" );