00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <string.h>
00029
00030 #include <xosd.h>
00031
00032 #include <vlc/intf.h>
00033
00034 #ifdef HAVE_UNISTD_H
00035 # include <unistd.h>
00036 #endif
00037
00038
00039
00040
00041 struct intf_sys_t
00042 {
00043 xosd * p_osd;
00044 vlc_bool_t b_need_update;
00045 };
00046
00047 #define MAX_LINE_LENGTH 256
00048
00049
00050
00051
00052 static int Open ( vlc_object_t * );
00053 static void Close ( vlc_object_t * );
00054
00055 static void Run ( intf_thread_t * );
00056
00057 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
00058 vlc_value_t oval, vlc_value_t nval, void *param );
00059
00060
00061
00062
00063 #define POSITION_TEXT N_("Flip vertical position")
00064 #define POSITION_LONGTEXT N_("Display xosd output on the bottom of the " \
00065 "screen instead of the top")
00066
00067 #define TXT_OFS_TEXT N_("Vertical offset")
00068 #define TXT_OFS_LONGTEXT N_("Vertical offset in pixels of the displayed text")
00069
00070 #define SHD_OFS_TEXT N_("Shadow offset")
00071 #define SHD_OFS_LONGTEXT N_("Offset in pixels of the shadow")
00072
00073 #define FONT_TEXT N_("Font")
00074 #define FONT_LONGTEXT N_("Font used to display text in the xosd output")
00075
00076 #define COLOUR_TEXT ("Colour")
00077 #define COLOUR_LONGTEXT ("Colour used to display text in the xosd output")
00078
00079 vlc_module_begin();
00080 set_category( CAT_INTERFACE );
00081 set_subcategory( SUBCAT_INTERFACE_CONTROL );
00082 set_description( _("XOSD interface") );
00083 add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, VLC_TRUE );
00084 add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, VLC_TRUE );
00085 add_integer( "xosd-shadow-offset", 2, NULL,
00086 SHD_OFS_TEXT, SHD_OFS_LONGTEXT, VLC_TRUE );
00087 add_string( "xosd-font",
00088 "-adobe-helvetica-bold-r-normal-*-*-160-*-*-p-*-iso8859-1",
00089 NULL, FONT_TEXT, FONT_LONGTEXT, VLC_TRUE );
00090 add_string( "xosd-colour", "LawnGreen",
00091 NULL, COLOUR_TEXT, COLOUR_LONGTEXT, VLC_TRUE );
00092 set_capability( "interface", 10 );
00093 set_callbacks( Open, Close );
00094 vlc_module_end();
00095
00096
00097
00098
00099 static int Open( vlc_object_t *p_this )
00100 {
00101 intf_thread_t *p_intf = (intf_thread_t *)p_this;
00102 xosd *p_osd;
00103
00104
00105 p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
00106 if( p_intf->p_sys == NULL )
00107 {
00108 msg_Err( p_intf, "out of memory" );
00109 return VLC_ENOMEM;
00110 }
00111
00112 if( getenv( "DISPLAY" ) == NULL )
00113 {
00114 msg_Err( p_intf, "no display, please set the DISPLAY variable" );
00115 return VLC_EGENERIC;
00116 }
00117
00118
00119 #if defined(HAVE_XOSD_VERSION_0) || defined(HAVE_XOSD_VERSION_1)
00120 p_osd = p_intf->p_sys->p_osd =
00121 xosd_init( config_GetPsz( p_intf, "xosd-font" ),
00122 config_GetPsz( p_intf,"xosd-colour" ), 3,
00123 XOSD_top, 0, 1 );
00124 if( p_intf->p_sys->p_osd == NULL )
00125 {
00126 msg_Err( p_intf, "couldn't initialize libxosd" );
00127 return VLC_EGENERIC;
00128 }
00129 #else
00130 p_osd = p_intf->p_sys->p_osd = xosd_create( 1 );
00131 if( p_osd == NULL )
00132 {
00133 msg_Err( p_intf, "couldn't initialize libxosd" );
00134 return VLC_EGENERIC;
00135 }
00136 xosd_set_colour( p_osd, config_GetPsz( p_intf,"xosd-colour" ) );
00137 xosd_set_timeout( p_osd, 3 );
00138 #endif
00139
00140
00141 playlist_t *p_playlist =
00142 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00143 FIND_ANYWHERE );
00144 if( p_playlist == NULL )
00145 {
00146 return VLC_EGENERIC;
00147 }
00148
00149 var_AddCallback( p_playlist, "playlist-current", PlaylistNext, p_this );
00150 var_AddCallback( p_playlist, "item-change", PlaylistNext, p_this );
00151
00152 vlc_object_release( p_playlist );
00153
00154
00155 xosd_set_font( p_intf->p_sys->p_osd,
00156 config_GetPsz( p_intf, "xosd-font" ) );
00157 xosd_set_outline_colour( p_intf->p_sys->p_osd,"black" );
00158 #ifdef HAVE_XOSD_VERSION_2
00159 xosd_set_horizontal_offset( p_intf->p_sys->p_osd,
00160 config_GetInt( p_intf, "xosd-text-offset" ) );
00161 xosd_set_vertical_offset( p_intf->p_sys->p_osd,
00162 config_GetInt( p_intf, "xosd-text-offset" ) );
00163 #else
00164 xosd_set_offset( p_intf->p_sys->p_osd,
00165 config_GetInt( p_intf, "xosd-text-offset" ) );
00166 #endif
00167 xosd_set_shadow_offset( p_intf->p_sys->p_osd,
00168 config_GetInt( p_intf, "xosd-shadow-offset" ));
00169 xosd_set_pos( p_intf->p_sys->p_osd,
00170 config_GetInt( p_intf, "xosd-position" ) ?
00171 XOSD_bottom: XOSD_top );
00172
00173
00174 xosd_display( p_osd, 0, XOSD_string, "XOSD interface initialized" );
00175
00176 p_intf->pf_run = Run;
00177
00178 p_intf->p_sys->b_need_update = VLC_TRUE;
00179
00180 return VLC_SUCCESS;
00181 }
00182
00183
00184
00185
00186 static void Close( vlc_object_t *p_this )
00187 {
00188 intf_thread_t *p_intf = (intf_thread_t *)p_this;
00189
00190
00191 xosd_destroy( p_intf->p_sys->p_osd );
00192
00193
00194 free( p_intf->p_sys );
00195 }
00196
00197
00198
00199
00200
00201
00202 static void Run( intf_thread_t *p_intf )
00203 {
00204 int i_size,i_index;
00205 playlist_t *p_playlist;
00206 playlist_item_t *p_item = NULL;
00207 input_item_t item;
00208 char psz_duration[MSTRTIME_MAX_SIZE+2];
00209 char *psz_display = NULL;
00210
00211 while( !p_intf->b_die )
00212 {
00213 if( p_intf->p_sys->b_need_update == VLC_TRUE )
00214 {
00215 p_intf->p_sys->b_need_update = VLC_FALSE;
00216 p_playlist = (playlist_t *)vlc_object_find( p_intf,
00217 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
00218 if( !p_playlist )
00219 {
00220 continue;
00221 }
00222
00223 if( p_playlist->i_size < 0 || p_playlist->i_index < 0 )
00224 {
00225 vlc_object_release( p_playlist );
00226 continue;
00227 }
00228 if( psz_display )
00229 {
00230 free( psz_display );
00231 psz_display = NULL;
00232 }
00233 if( p_playlist->status.i_status == PLAYLIST_STOPPED )
00234 {
00235 psz_display = (char *)malloc( sizeof(char )*strlen(_("Stop")));
00236 sprintf( psz_display,_("Stop") );
00237 vlc_object_release( p_playlist );
00238 }
00239 else if( p_playlist->status.i_status == PLAYLIST_PAUSED )
00240 {
00241 psz_display = (char *)malloc( sizeof(char )*strlen(_("Pause")));
00242 sprintf( psz_display,_("Pause") );
00243 vlc_object_release( p_playlist );
00244 }
00245 else
00246 {
00247
00248 p_item = p_playlist->status.p_item;
00249 item = p_item->input;
00250 if( !p_item )
00251 {
00252 vlc_object_release( p_playlist );
00253
00254 continue;
00255 }
00256 i_size = p_playlist->i_size;
00257 i_index = p_playlist->i_index+1;
00258
00259
00260 vlc_object_release( p_playlist );
00261
00262 if( item.i_duration != -1 )
00263 {
00264 char psz_durationstr[MSTRTIME_MAX_SIZE];
00265 secstotimestr( psz_durationstr, item.i_duration/1000000 );
00266 sprintf( psz_duration, "(%s)", psz_durationstr );
00267 }
00268 else
00269 {
00270 sprintf( psz_duration," " );
00271 }
00272
00273 psz_display = (char *)malloc( sizeof(char )*
00274 (strlen( item.psz_name ) +
00275 MSTRTIME_MAX_SIZE + 2+6 + 10 +10 ));
00276 sprintf( psz_display," %i/%i - %s %s",
00277 i_index,i_size, item.psz_name, psz_duration);
00278 }
00279
00280
00281 xosd_display( p_intf->p_sys->p_osd,
00282 0,
00283 XOSD_string,
00284 psz_display );
00285 }
00286
00287 msleep( INTF_IDLE_SLEEP );
00288 }
00289 }
00290
00291 static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable,
00292 vlc_value_t oval, vlc_value_t nval, void *param )
00293 {
00294 intf_thread_t *p_intf = (intf_thread_t *)param;
00295
00296 p_intf->p_sys->b_need_update = VLC_TRUE;
00297 return VLC_SUCCESS;
00298 }
00299