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 *****************************************************************************/
36 #include <vlc_vout_osd.h>
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 )
96 { SUBPICTURE_ALIGN_LEFT, "left" },
97 { SUBPICTURE_ALIGN_RIGHT, "right" },
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 /*****************************************************************************
220 *****************************************************************************/
221 static const luaL_Reg vlclua_osd_reg[] = {
222 { "icon", vlclua_osd_icon },
223 { "message", vlclua_osd_message },
224 { "slider", vlclua_osd_slider },
225 { "channel_register", vlclua_spu_channel_register },
226 { "channel_clear", vlclua_spu_channel_clear },
230 void luaopen_osd( lua_State *L )
233 luaL_register( L, NULL, vlclua_osd_reg );
234 lua_setfield( L, -2, "osd" );