1 /*****************************************************************************
2 * xosd.c : X On Screen Display interface
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
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 input_thread_t * p_input; /* associated input thread */
44 xosd * p_osd; /* libxosd handle */
45 char * psz_source; /* current file || NULL */
48 #define MAX_LINE_LENGTH 256
50 /*****************************************************************************
52 *****************************************************************************/
53 static int Open ( vlc_object_t * );
54 static void Close ( vlc_object_t * );
56 static void Run ( intf_thread_t * );
58 /*****************************************************************************
60 *****************************************************************************/
61 #define POSITION_TEXT N_("Flip vertical position")
62 #define POSITION_LONGTEXT N_("Display xosd output on the bottom of the " \
63 "screen instead of the top")
65 #define TXT_OFS_TEXT N_("Vertical offset")
66 #define TXT_OFS_LONGTEXT N_("Vertical offset in pixels of the displayed text")
68 #define SHD_OFS_TEXT N_("Shadow offset")
69 #define SHD_OFS_LONGTEXT N_("Offset in pixels of the shadow")
71 #define FONT_TEXT N_("Font")
72 #define FONT_LONGTEXT N_("Font used to display text in the xosd output")
75 set_description( _("XOSD interface") );
76 add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, VLC_TRUE );
77 add_integer( "xosd-text-offset", 0, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, VLC_TRUE );
78 add_integer( "xosd-shadow-offset", 1, NULL,
79 SHD_OFS_TEXT, SHD_OFS_LONGTEXT, VLC_TRUE );
80 add_string( "xosd-font", "-misc-fixed-medium-r-*-*-*-300-*-*-*-*-*-*",
81 NULL, FONT_TEXT, FONT_LONGTEXT, VLC_TRUE );
82 set_capability( "interface", 10 );
83 set_callbacks( Open, Close );
86 /*****************************************************************************
87 * Open: initialize and create stuff
88 *****************************************************************************/
89 static int Open( vlc_object_t *p_this )
91 intf_thread_t *p_intf = (intf_thread_t *)p_this;
93 /* Allocate instance and initialize some members */
94 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
95 if( p_intf->p_sys == NULL )
97 msg_Err( p_intf, "out of memory" );
101 if( getenv( "DISPLAY" ) == NULL )
103 msg_Err( p_intf, "no display, please set the DISPLAY variable" );
107 /* Initialize library */
108 p_intf->p_sys->p_osd =
109 #if defined(HAVE_XOSD_VERSION_0) || defined(HAVE_XOSD_VERSION_1)
110 xosd_init( config_GetPsz( p_intf, "xosd-font" ),
111 "LawnGreen", 3, XOSD_top, 0, 1 );
113 xosd_init( config_GetPsz( p_intf, "xosd-font" ),
114 "LawnGreen", 3, XOSD_top, 0, 0, 1 );
117 if( p_intf->p_sys->p_osd == NULL )
119 msg_Err( p_intf, "couldn't initialize libxosd" );
123 /* Initialize to NULL */
124 p_intf->p_sys->psz_source = NULL;
126 xosd_display( p_intf->p_sys->p_osd,
129 "xosd interface initialized" );
131 p_intf->pf_run = Run;
136 /*****************************************************************************
137 * Close: destroy interface stuff
138 *****************************************************************************/
139 static void Close( vlc_object_t *p_this )
141 intf_thread_t *p_intf = (intf_thread_t *)p_this;
143 if( p_intf->p_sys->psz_source ) free( p_intf->p_sys->psz_source );
145 /* Uninitialize library */
146 xosd_uninit( p_intf->p_sys->p_osd );
148 /* Destroy structure */
149 free( p_intf->p_sys );
152 /*****************************************************************************
154 *****************************************************************************
155 * This part of the interface runs in a separate thread
156 *****************************************************************************/
157 static void Run( intf_thread_t *p_intf )
159 p_intf->p_sys->p_input = NULL;
161 while( !p_intf->b_die )
163 /* Manage the input part */
164 if( p_intf->p_sys->p_input == NULL )
166 p_intf->p_sys->p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
169 else if( p_intf->p_sys->p_input->b_dead )
171 vlc_object_release( p_intf->p_sys->p_input );
172 p_intf->p_sys->p_input = NULL;
174 else /* We have a valid input */
176 /* Did source change? */
177 if ( (p_intf->p_sys->psz_source == NULL)
178 || (strcmp( p_intf->p_sys->psz_source,
179 p_intf->p_sys->p_input->psz_source ) != 0)
182 if( p_intf->p_sys->psz_source )
183 free( p_intf->p_sys->psz_source );
185 p_intf->p_sys->psz_source =
186 strdup( p_intf->p_sys->p_input->psz_source );
188 /* Set user preferences */
189 xosd_set_font( p_intf->p_sys->p_osd,
190 config_GetPsz( p_intf, "xosd-font" ) );
191 #ifdef HAVE_XOSD_VERSION_2
192 xosd_set_horizontal_offset( p_intf->p_sys->p_osd,
193 config_GetInt( p_intf, "xosd-text-offset" ) );
194 xosd_set_vertical_offset( p_intf->p_sys->p_osd,
195 config_GetInt( p_intf, "xosd-text-offset" ) );
197 xosd_set_offset( p_intf->p_sys->p_osd,
198 config_GetInt( p_intf, "xosd-text-offset" ) );
200 xosd_set_shadow_offset( p_intf->p_sys->p_osd,
201 config_GetInt( p_intf, "xosd-shadow-offset" ));
202 xosd_set_pos( p_intf->p_sys->p_osd,
203 config_GetInt( p_intf, "xosd-position" ) ? XOSD_bottom
207 xosd_display( p_intf->p_sys->p_osd,
210 p_intf->p_sys->psz_source );
214 msleep( INTF_IDLE_SLEEP );
217 if( p_intf->p_sys->p_input )
219 vlc_object_release( p_intf->p_sys->p_input );
220 p_intf->p_sys->p_input = NULL;