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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
38 /*****************************************************************************
39 * intf_sys_t: description and status of rc interface
40 *****************************************************************************/
43 xosd * p_osd; /* libxosd handle */
44 vlc_bool_t b_need_update; /* Update display ? */
47 #define MAX_LINE_LENGTH 256
49 /*****************************************************************************
51 *****************************************************************************/
52 static int Open ( vlc_object_t * );
53 static void Close ( vlc_object_t * );
55 static void Run ( intf_thread_t * );
57 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
58 vlc_value_t oval, vlc_value_t nval, void *param );
60 /*****************************************************************************
62 *****************************************************************************/
63 #define POSITION_TEXT N_("Flip vertical position")
64 #define POSITION_LONGTEXT N_("Display xosd output on the bottom of the " \
65 "screen instead of the top")
67 #define TXT_OFS_TEXT N_("Vertical offset")
68 #define TXT_OFS_LONGTEXT N_("Vertical offset in pixels of the displayed text")
70 #define SHD_OFS_TEXT N_("Shadow offset")
71 #define SHD_OFS_LONGTEXT N_("Offset in pixels of the shadow")
73 #define FONT_TEXT N_("Font")
74 #define FONT_LONGTEXT N_("Font used to display text in the xosd output")
75 /* FIXME FIXME FIXME: Gettextize */
76 #define COLOUR_TEXT ("Colour")
77 #define COLOUR_LONGTEXT ("Colour used to display text in the xosd output")
80 set_category( CAT_INTERFACE );
81 set_subcategory( SUBCAT_INTERFACE_CONTROL );
82 set_description( _("XOSD interface") );
83 add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, VLC_TRUE );
84 add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, VLC_TRUE );
85 add_integer( "xosd-shadow-offset", 2, NULL,
86 SHD_OFS_TEXT, SHD_OFS_LONGTEXT, VLC_TRUE );
87 add_string( "xosd-font",
88 "-adobe-helvetica-bold-r-normal-*-*-160-*-*-p-*-iso8859-1",
89 NULL, FONT_TEXT, FONT_LONGTEXT, VLC_TRUE );
90 add_string( "xosd-colour", "LawnGreen",
91 NULL, COLOUR_TEXT, COLOUR_LONGTEXT, VLC_TRUE );
92 set_capability( "interface", 10 );
93 set_callbacks( Open, Close );
96 /*****************************************************************************
97 * Open: initialize and create stuff
98 *****************************************************************************/
99 static int Open( vlc_object_t *p_this )
101 intf_thread_t *p_intf = (intf_thread_t *)p_this;
104 /* Allocate instance and initialize some members */
105 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
106 if( p_intf->p_sys == NULL )
108 msg_Err( p_intf, "out of memory" );
112 if( getenv( "DISPLAY" ) == NULL )
114 msg_Err( p_intf, "no display, please set the DISPLAY variable" );
118 /* Initialize library */
119 #if defined(HAVE_XOSD_VERSION_0) || defined(HAVE_XOSD_VERSION_1)
120 p_osd = p_intf->p_sys->p_osd =
121 xosd_init( config_GetPsz( p_intf, "xosd-font" ),
122 config_GetPsz( p_intf,"xosd-colour" ), 3,
124 if( p_intf->p_sys->p_osd == NULL )
126 msg_Err( p_intf, "couldn't initialize libxosd" );
130 p_osd = p_intf->p_sys->p_osd = xosd_create( 1 );
133 msg_Err( p_intf, "couldn't initialize libxosd" );
136 xosd_set_colour( p_osd, config_GetPsz( p_intf,"xosd-colour" ) );
137 xosd_set_timeout( p_osd, 3 );
141 playlist_t *p_playlist =
142 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
144 if( p_playlist == NULL )
149 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, p_this );
150 var_AddCallback( p_playlist, "item-change", PlaylistNext, p_this );
152 vlc_object_release( p_playlist );
154 /* Set user preferences */
155 xosd_set_font( p_intf->p_sys->p_osd,
156 config_GetPsz( p_intf, "xosd-font" ) );
157 xosd_set_outline_colour( p_intf->p_sys->p_osd,"black" );
158 #ifdef HAVE_XOSD_VERSION_2
159 xosd_set_horizontal_offset( p_intf->p_sys->p_osd,
160 config_GetInt( p_intf, "xosd-text-offset" ) );
161 xosd_set_vertical_offset( p_intf->p_sys->p_osd,
162 config_GetInt( p_intf, "xosd-text-offset" ) );
164 xosd_set_offset( p_intf->p_sys->p_osd,
165 config_GetInt( p_intf, "xosd-text-offset" ) );
167 xosd_set_shadow_offset( p_intf->p_sys->p_osd,
168 config_GetInt( p_intf, "xosd-shadow-offset" ));
169 xosd_set_pos( p_intf->p_sys->p_osd,
170 config_GetInt( p_intf, "xosd-position" ) ?
171 XOSD_bottom: XOSD_top );
173 /* Initialize to NULL */
174 xosd_display( p_osd, 0, XOSD_string, "XOSD interface initialized" );
176 p_intf->pf_run = Run;
178 p_intf->p_sys->b_need_update = VLC_TRUE;
183 /*****************************************************************************
184 * Close: destroy interface stuff
185 *****************************************************************************/
186 static void Close( vlc_object_t *p_this )
188 intf_thread_t *p_intf = (intf_thread_t *)p_this;
190 /* Uninitialize library */
191 xosd_destroy( p_intf->p_sys->p_osd );
193 /* Destroy structure */
194 free( p_intf->p_sys );
197 /*****************************************************************************
199 *****************************************************************************
200 * This part of the interface runs in a separate thread
201 *****************************************************************************/
202 static void Run( intf_thread_t *p_intf )
205 playlist_t *p_playlist;
206 playlist_item_t *p_item = NULL;
208 char psz_duration[MSTRTIME_MAX_SIZE+2];
209 char *psz_display = NULL;
211 while( !p_intf->b_die )
213 if( p_intf->p_sys->b_need_update == VLC_TRUE )
215 p_intf->p_sys->b_need_update = VLC_FALSE;
216 p_playlist = (playlist_t *)vlc_object_find( p_intf,
217 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
223 if( p_playlist->i_size < 0 || p_playlist->i_index < 0 )
225 vlc_object_release( p_playlist );
233 if( p_playlist->status.i_status == PLAYLIST_STOPPED )
235 psz_display = strdup(_("Stop"));
236 vlc_object_release( p_playlist );
238 else if( p_playlist->status.i_status == PLAYLIST_PAUSED )
240 psz_display = strdup(_("Pause"));
241 vlc_object_release( p_playlist );
245 // vlc_mutex_lock(&p_playlist->object_lock );
246 p_item = p_playlist->status.p_item;
247 item = p_item->input;
250 vlc_object_release( p_playlist );
251 // vlc_mutex_unlock(&p_playlist->object_lock );
254 i_size = p_playlist->i_size;
255 i_index = p_playlist->i_index+1;
256 // vlc_mutex_unlock(&p_playlist->object_lock );
258 vlc_object_release( p_playlist );
260 if( item.i_duration != -1 )
262 char psz_durationstr[MSTRTIME_MAX_SIZE];
263 secstotimestr( psz_durationstr, item.i_duration/1000000 );
264 sprintf( psz_duration, "(%s)", psz_durationstr );
268 sprintf( psz_duration," " );
271 psz_display = (char *)malloc( sizeof(char )*
272 (strlen( item.psz_name ) +
273 MSTRTIME_MAX_SIZE + 2+6 + 10 +10 ));
274 sprintf( psz_display," %i/%i - %s %s",
275 i_index,i_size, item.psz_name, psz_duration);
279 xosd_display( p_intf->p_sys->p_osd,
285 msleep( INTF_IDLE_SLEEP );
289 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
290 vlc_value_t oval, vlc_value_t nval, void *param )
292 intf_thread_t *p_intf = (intf_thread_t *)param;
294 p_intf->p_sys->b_need_update = VLC_TRUE;