1 /*****************************************************************************
2 * xosd.c : X On Screen Display interface
3 *****************************************************************************
4 * Copyright (C) 2001 the VideoLAN team
7 * Authors: Loïc Minier <lool@videolan.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 *****************************************************************************/
34 #include <vlc_playlist.h>
35 #include <vlc_input.h>
36 #include <vlc_interface.h>
42 /*****************************************************************************
43 * intf_sys_t: description and status of rc interface
44 *****************************************************************************/
47 xosd * p_osd; /* libxosd handle */
48 vlc_bool_t b_need_update; /* Update display ? */
51 #define MAX_LINE_LENGTH 256
53 /*****************************************************************************
55 *****************************************************************************/
56 static int Open ( vlc_object_t * );
57 static void Close ( vlc_object_t * );
59 static void Run ( intf_thread_t * );
61 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
62 vlc_value_t oval, vlc_value_t nval, void *param );
64 /*****************************************************************************
66 *****************************************************************************/
67 #define POSITION_TEXT N_("Flip vertical position")
68 #define POSITION_LONGTEXT N_("Display XOSD output at the bottom of the " \
69 "screen instead of the top.")
71 #define TXT_OFS_TEXT N_("Vertical offset")
72 #define TXT_OFS_LONGTEXT N_("Vertical offset between the border of the screen "\
73 "and the displayed text (in pixels, defaults to "\
76 #define SHD_OFS_TEXT N_("Shadow offset")
77 #define SHD_OFS_LONGTEXT N_("Offset between the text and the shadow (in " \
78 "pixels, defaults to 2 pixels)." )
80 #define FONT_TEXT N_("Font")
81 #define FONT_LONGTEXT N_("Font used to display text in the XOSD output.")
82 #define COLOUR_TEXT N_("Color")
83 #define COLOUR_LONGTEXT N_("Color used to display text in the XOSD output.")
86 set_category( CAT_INTERFACE );
87 set_subcategory( SUBCAT_INTERFACE_CONTROL );
88 set_description( _("XOSD interface") );
89 set_shortname( "XOSD" );
90 add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, VLC_TRUE );
91 add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, VLC_TRUE );
92 add_integer( "xosd-shadow-offset", 2, NULL,
93 SHD_OFS_TEXT, SHD_OFS_LONGTEXT, VLC_TRUE );
94 add_string( "xosd-font",
95 "-adobe-helvetica-bold-r-normal-*-*-160-*-*-p-*-iso8859-1",
96 NULL, FONT_TEXT, FONT_LONGTEXT, VLC_TRUE );
97 add_string( "xosd-colour", "LawnGreen",
98 NULL, COLOUR_TEXT, COLOUR_LONGTEXT, VLC_TRUE );
99 set_capability( "interface", 10 );
100 set_callbacks( Open, Close );
103 /*****************************************************************************
104 * Open: initialize and create stuff
105 *****************************************************************************/
106 static int Open( vlc_object_t *p_this )
108 intf_thread_t *p_intf = (intf_thread_t *)p_this;
111 /* Allocate instance and initialize some members */
112 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
113 if( p_intf->p_sys == NULL )
115 msg_Err( p_intf, "out of memory" );
119 if( getenv( "DISPLAY" ) == NULL )
121 msg_Err( p_intf, "no display, please set the DISPLAY variable" );
125 /* Initialize library */
126 #if defined(HAVE_XOSD_VERSION_0) || defined(HAVE_XOSD_VERSION_1)
127 p_osd = p_intf->p_sys->p_osd =
128 xosd_init( config_GetPsz( p_intf, "xosd-font" ),
129 config_GetPsz( p_intf,"xosd-colour" ), 3,
131 if( p_intf->p_sys->p_osd == NULL )
133 msg_Err( p_intf, "couldn't initialize libxosd" );
137 p_osd = p_intf->p_sys->p_osd = xosd_create( 1 );
140 msg_Err( p_intf, "couldn't initialize libxosd" );
143 xosd_set_colour( p_osd, config_GetPsz( p_intf,"xosd-colour" ) );
144 xosd_set_timeout( p_osd, 3 );
148 playlist_t *p_playlist = pl_Yield( p_intf );
149 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, p_this );
150 var_AddCallback( p_playlist, "item-change", PlaylistNext, p_this );
151 pl_Release( p_intf );
153 /* Set user preferences */
154 xosd_set_font( p_intf->p_sys->p_osd,
155 config_GetPsz( p_intf, "xosd-font" ) );
156 xosd_set_outline_colour( p_intf->p_sys->p_osd,"black" );
157 #ifdef HAVE_XOSD_VERSION_2
158 xosd_set_horizontal_offset( p_intf->p_sys->p_osd,
159 config_GetInt( p_intf, "xosd-text-offset" ) );
160 xosd_set_vertical_offset( p_intf->p_sys->p_osd,
161 config_GetInt( p_intf, "xosd-text-offset" ) );
163 xosd_set_offset( p_intf->p_sys->p_osd,
164 config_GetInt( p_intf, "xosd-text-offset" ) );
166 xosd_set_shadow_offset( p_intf->p_sys->p_osd,
167 config_GetInt( p_intf, "xosd-shadow-offset" ));
168 xosd_set_pos( p_intf->p_sys->p_osd,
169 config_GetInt( p_intf, "xosd-position" ) ?
170 XOSD_bottom: XOSD_top );
172 /* Initialize to NULL */
173 xosd_display( p_osd, 0, XOSD_string, "XOSD interface initialized" );
175 p_intf->pf_run = Run;
177 p_intf->p_sys->b_need_update = VLC_TRUE;
182 /*****************************************************************************
183 * Close: destroy interface stuff
184 *****************************************************************************/
185 static void Close( vlc_object_t *p_this )
187 intf_thread_t *p_intf = (intf_thread_t *)p_this;
188 playlist_t *p_playlist = pl_Yield( p_intf );
189 var_DelCallback( p_playlist, "playlist-current", PlaylistNext, p_this );
190 var_DelCallback( p_playlist, "item-change", PlaylistNext, p_this );
191 pl_Release( p_intf );
193 /* Uninitialize library */
194 xosd_destroy( p_intf->p_sys->p_osd );
196 /* Destroy structure */
197 free( p_intf->p_sys );
200 /*****************************************************************************
202 *****************************************************************************
203 * This part of the interface runs in a separate thread
204 *****************************************************************************/
205 static void Run( intf_thread_t *p_intf )
207 playlist_t *p_playlist;
208 playlist_item_t *p_item = NULL;
209 input_item_t *p_input;
210 char psz_duration[MSTRTIME_MAX_SIZE+2];
211 char *psz_display = NULL;
213 while( !p_intf->b_die )
215 if( p_intf->p_sys->b_need_update == VLC_TRUE )
217 p_intf->p_sys->b_need_update = VLC_FALSE;
218 p_playlist = pl_Yield( p_intf );
220 if( playlist_IsEmpty( p_playlist ) )
222 vlc_object_release( p_playlist );
230 if( p_playlist->status.i_status == PLAYLIST_STOPPED )
232 psz_display = strdup(_("Stop"));
233 vlc_object_release( p_playlist );
235 else if( p_playlist->status.i_status == PLAYLIST_PAUSED )
237 psz_display = strdup(_("Pause"));
238 vlc_object_release( p_playlist );
242 p_item = p_playlist->status.p_item;
243 p_input = p_item->p_input;
246 vlc_object_release( p_playlist );
250 vlc_object_release( p_playlist );
252 mtime_t i_duration = input_item_GetDuration( p_input );
253 if( i_duration != -1 )
255 char psz_durationstr[MSTRTIME_MAX_SIZE];
256 secstotimestr( psz_durationstr, i_duration / 1000000 );
257 sprintf( psz_duration, "(%s)", psz_durationstr );
261 sprintf( psz_duration," " );
264 psz_display = (char *)malloc( sizeof(char )*
265 (strlen( p_input->psz_name ) +
266 MSTRTIME_MAX_SIZE + 2+6 + 10 +10 ));
267 sprintf( psz_display,"%s %s",
268 p_input->psz_name, psz_duration);
272 xosd_display( p_intf->p_sys->p_osd,
278 msleep( INTF_IDLE_SLEEP );
282 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
283 vlc_value_t oval, vlc_value_t nval, void *param )
285 intf_thread_t *p_intf = (intf_thread_t *)param;
287 p_intf->p_sys->b_need_update = VLC_TRUE;