| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#include <xosd.h> |
|---|
| 29 |
#ifdef HAVE_CONFIG_H |
|---|
| 30 |
# include "config.h" |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
#include <vlc_common.h> |
|---|
| 34 |
#include <vlc_plugin.h> |
|---|
| 35 |
#include <vlc_playlist.h> |
|---|
| 36 |
#include <vlc_input.h> |
|---|
| 37 |
#include <vlc_interface.h> |
|---|
| 38 |
|
|---|
| 39 |
#ifdef HAVE_UNISTD_H |
|---|
| 40 |
# include <unistd.h> |
|---|
| 41 |
#endif |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
struct intf_sys_t |
|---|
| 47 |
{ |
|---|
| 48 |
xosd * p_osd; |
|---|
| 49 |
bool b_need_update; |
|---|
| 50 |
}; |
|---|
| 51 |
|
|---|
| 52 |
#define MAX_LINE_LENGTH 256 |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
static int Open ( vlc_object_t * ); |
|---|
| 58 |
static void Close ( vlc_object_t * ); |
|---|
| 59 |
|
|---|
| 60 |
static void Run ( intf_thread_t * ); |
|---|
| 61 |
|
|---|
| 62 |
static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, |
|---|
| 63 |
vlc_value_t oval, vlc_value_t nval, void *param ); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
#define POSITION_TEXT N_("Flip vertical position") |
|---|
| 69 |
#define POSITION_LONGTEXT N_("Display XOSD output at the bottom of the " \ |
|---|
| 70 |
"screen instead of the top.") |
|---|
| 71 |
|
|---|
| 72 |
#define TXT_OFS_TEXT N_("Vertical offset") |
|---|
| 73 |
#define TXT_OFS_LONGTEXT N_("Vertical offset between the border of the screen "\ |
|---|
| 74 |
"and the displayed text (in pixels, defaults to "\ |
|---|
| 75 |
"30 pixels)." ) |
|---|
| 76 |
|
|---|
| 77 |
#define SHD_OFS_TEXT N_("Shadow offset") |
|---|
| 78 |
#define SHD_OFS_LONGTEXT N_("Offset between the text and the shadow (in " \ |
|---|
| 79 |
"pixels, defaults to 2 pixels)." ) |
|---|
| 80 |
|
|---|
| 81 |
#define FONT_TEXT N_("Font") |
|---|
| 82 |
#define FONT_LONGTEXT N_("Font used to display text in the XOSD output.") |
|---|
| 83 |
#define COLOUR_TEXT N_("Color") |
|---|
| 84 |
#define COLOUR_LONGTEXT N_("Color used to display text in the XOSD output.") |
|---|
| 85 |
|
|---|
| 86 |
vlc_module_begin(); |
|---|
| 87 |
set_category( CAT_INTERFACE ); |
|---|
| 88 |
set_subcategory( SUBCAT_INTERFACE_CONTROL ); |
|---|
| 89 |
set_description( N_("XOSD interface") ); |
|---|
| 90 |
set_shortname( "XOSD" ); |
|---|
| 91 |
add_bool( "xosd-position", 1, NULL, POSITION_TEXT, POSITION_LONGTEXT, true ); |
|---|
| 92 |
add_integer( "xosd-text-offset", 30, NULL, TXT_OFS_TEXT, TXT_OFS_LONGTEXT, true ); |
|---|
| 93 |
add_integer( "xosd-shadow-offset", 2, NULL, |
|---|
| 94 |
SHD_OFS_TEXT, SHD_OFS_LONGTEXT, true ); |
|---|
| 95 |
add_string( "xosd-font", |
|---|
| 96 |
"-adobe-helvetica-bold-r-normal-*-*-160-*-*-p-*-iso8859-1", |
|---|
| 97 |
NULL, FONT_TEXT, FONT_LONGTEXT, true ); |
|---|
| 98 |
add_string( "xosd-colour", "LawnGreen", |
|---|
| 99 |
NULL, COLOUR_TEXT, COLOUR_LONGTEXT, true ); |
|---|
| 100 |
set_capability( "interface", 10 ); |
|---|
| 101 |
set_callbacks( Open, Close ); |
|---|
| 102 |
vlc_module_end(); |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
static int Open( vlc_object_t *p_this ) |
|---|
| 108 |
{ |
|---|
| 109 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 110 |
xosd *p_osd; |
|---|
| 111 |
char *psz_font, *psz_colour; |
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) ); |
|---|
| 115 |
if( p_intf->p_sys == NULL ) |
|---|
| 116 |
{ |
|---|
| 117 |
msg_Err( p_intf, "out of memory" ); |
|---|
| 118 |
return VLC_ENOMEM; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
if( getenv( "DISPLAY" ) == NULL ) |
|---|
| 122 |
{ |
|---|
| 123 |
msg_Err( p_intf, "no display, please set the DISPLAY variable" ); |
|---|
| 124 |
return VLC_EGENERIC; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
#if defined(HAVE_XOSD_VERSION_0) || defined(HAVE_XOSD_VERSION_1) |
|---|
| 129 |
psz_font = config_GetPsz( p_intf, "xosd-font" ); |
|---|
| 130 |
psz_colour = config_GetPsz( p_intf,"xosd-colour" ); |
|---|
| 131 |
p_osd = p_intf->p_sys->p_osd = xosd_init( psz_font, psz_colour, 3, |
|---|
| 132 |
XOSD_top, 0, 1 ); |
|---|
| 133 |
free( psz_font ); |
|---|
| 134 |
free( psz_colour ); |
|---|
| 135 |
|
|---|
| 136 |
if( p_intf->p_sys->p_osd == NULL ) |
|---|
| 137 |
{ |
|---|
| 138 |
msg_Err( p_intf, "couldn't initialize libxosd" ); |
|---|
| 139 |
return VLC_EGENERIC; |
|---|
| 140 |
} |
|---|
| 141 |
#else |
|---|
| 142 |
p_osd = p_intf->p_sys->p_osd = xosd_create( 1 ); |
|---|
| 143 |
if( p_osd == NULL ) |
|---|
| 144 |
{ |
|---|
| 145 |
msg_Err( p_intf, "couldn't initialize libxosd" ); |
|---|
| 146 |
return VLC_EGENERIC; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
psz_colour = config_GetPsz( p_intf,"xosd-colour" ); |
|---|
| 150 |
xosd_set_colour( p_osd, psz_colour ); |
|---|
| 151 |
xosd_set_timeout( p_osd, 3 ); |
|---|
| 152 |
free( psz_colour ); |
|---|
| 153 |
#endif |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
playlist_t *p_playlist = pl_Hold( p_intf ); |
|---|
| 157 |
var_AddCallback( p_playlist, "playlist-current", PlaylistNext, p_this ); |
|---|
| 158 |
var_AddCallback( p_playlist, "item-change", PlaylistNext, p_this ); |
|---|
| 159 |
pl_Release( p_intf ); |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
psz_font = config_GetPsz( p_intf, "xosd-font" ); |
|---|
| 163 |
xosd_set_font( p_intf->p_sys->p_osd, psz_font ); |
|---|
| 164 |
free( psz_font ); |
|---|
| 165 |
xosd_set_outline_colour( p_intf->p_sys->p_osd,"black" ); |
|---|
| 166 |
#ifdef HAVE_XOSD_VERSION_2 |
|---|
| 167 |
xosd_set_horizontal_offset( p_intf->p_sys->p_osd, |
|---|
| 168 |
config_GetInt( p_intf, "xosd-text-offset" ) ); |
|---|
| 169 |
xosd_set_vertical_offset( p_intf->p_sys->p_osd, |
|---|
| 170 |
config_GetInt( p_intf, "xosd-text-offset" ) ); |
|---|
| 171 |
#else |
|---|
| 172 |
xosd_set_offset( p_intf->p_sys->p_osd, |
|---|
| 173 |
config_GetInt( p_intf, "xosd-text-offset" ) ); |
|---|
| 174 |
#endif |
|---|
| 175 |
xosd_set_shadow_offset( p_intf->p_sys->p_osd, |
|---|
| 176 |
config_GetInt( p_intf, "xosd-shadow-offset" )); |
|---|
| 177 |
xosd_set_pos( p_intf->p_sys->p_osd, |
|---|
| 178 |
config_GetInt( p_intf, "xosd-position" ) ? |
|---|
| 179 |
XOSD_bottom: XOSD_top ); |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
xosd_display( p_osd, 0, XOSD_string, "XOSD interface initialized" ); |
|---|
| 183 |
|
|---|
| 184 |
p_intf->pf_run = Run; |
|---|
| 185 |
|
|---|
| 186 |
p_intf->p_sys->b_need_update = true; |
|---|
| 187 |
|
|---|
| 188 |
return VLC_SUCCESS; |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
static void Close( vlc_object_t *p_this ) |
|---|
| 195 |
{ |
|---|
| 196 |
intf_thread_t *p_intf = (intf_thread_t *)p_this; |
|---|
| 197 |
playlist_t *p_playlist = pl_Hold( p_intf ); |
|---|
| 198 |
var_DelCallback( p_playlist, "playlist-current", PlaylistNext, p_this ); |
|---|
| 199 |
var_DelCallback( p_playlist, "item-change", PlaylistNext, p_this ); |
|---|
| 200 |
pl_Release( p_intf ); |
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
xosd_destroy( p_intf->p_sys->p_osd ); |
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
free( p_intf->p_sys ); |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
static void Run( intf_thread_t *p_intf ) |
|---|
| 215 |
{ |
|---|
| 216 |
playlist_t *p_playlist; |
|---|
| 217 |
playlist_item_t *p_item = NULL; |
|---|
| 218 |
input_item_t *p_input; |
|---|
| 219 |
char psz_duration[MSTRTIME_MAX_SIZE+2]; |
|---|
| 220 |
char *psz_display = NULL; |
|---|
| 221 |
|
|---|
| 222 |
for( ;; ) |
|---|
| 223 |
{ |
|---|
| 224 |
int canc = vlc_savecancel(); |
|---|
| 225 |
if( p_intf->p_sys->b_need_update == true ) |
|---|
| 226 |
{ |
|---|
| 227 |
p_intf->p_sys->b_need_update = false; |
|---|
| 228 |
p_playlist = pl_Hold( p_intf ); |
|---|
| 229 |
|
|---|
| 230 |
if( playlist_IsEmpty( p_playlist ) ) |
|---|
| 231 |
{ |
|---|
| 232 |
pl_Release( p_intf ); |
|---|
| 233 |
continue; |
|---|
| 234 |
} |
|---|
| 235 |
free( psz_display ); |
|---|
| 236 |
psz_display = NULL; |
|---|
| 237 |
int i_status = playlist_Status( p_playlist ); |
|---|
| 238 |
if( i_status == PLAYLIST_STOPPED ) |
|---|
| 239 |
{ |
|---|
| 240 |
psz_display = strdup(_("Stop")); |
|---|
| 241 |
pl_Release( p_intf ); |
|---|
| 242 |
} |
|---|
| 243 |
else if( i_status == PLAYLIST_PAUSED ) |
|---|
| 244 |
{ |
|---|
| 245 |
psz_display = strdup(_("Pause")); |
|---|
| 246 |
pl_Release( p_intf ); |
|---|
| 247 |
} |
|---|
| 248 |
else |
|---|
| 249 |
{ |
|---|
| 250 |
p_item = playlist_CurrentPlayingItem( p_playlist ); |
|---|
| 251 |
p_input = p_item->p_input; |
|---|
| 252 |
|
|---|
| 253 |
pl_Release( p_intf ); |
|---|
| 254 |
if( !p_item ) |
|---|
| 255 |
continue; |
|---|
| 256 |
|
|---|
| 257 |
mtime_t i_duration = input_item_GetDuration( p_input ); |
|---|
| 258 |
if( i_duration != -1 ) |
|---|
| 259 |
{ |
|---|
| 260 |
char psz_durationstr[MSTRTIME_MAX_SIZE]; |
|---|
| 261 |
secstotimestr( psz_durationstr, i_duration / 1000000 ); |
|---|
| 262 |
sprintf( psz_duration, "(%s)", psz_durationstr ); |
|---|
| 263 |
} |
|---|
| 264 |
else |
|---|
| 265 |
{ |
|---|
| 266 |
sprintf( psz_duration," " ); |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
psz_display = (char *)malloc( sizeof(char )* |
|---|
| 270 |
(strlen( p_input->psz_name ) + |
|---|
| 271 |
MSTRTIME_MAX_SIZE + 2+6 + 10 +10 )); |
|---|
| 272 |
sprintf( psz_display,"%s %s", |
|---|
| 273 |
p_input->psz_name, psz_duration); |
|---|
| 274 |
} |
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
xosd_display( p_intf->p_sys->p_osd, |
|---|
| 278 |
0, |
|---|
| 279 |
XOSD_string, |
|---|
| 280 |
psz_display ); |
|---|
| 281 |
} |
|---|
| 282 |
|
|---|
| 283 |
vlc_restorecancel( canc ); |
|---|
| 284 |
msleep( INTF_IDLE_SLEEP ); |
|---|
| 285 |
} |
|---|
| 286 |
} |
|---|
| 287 |
|
|---|
| 288 |
static int PlaylistNext( vlc_object_t *p_this, const char *psz_variable, |
|---|
| 289 |
vlc_value_t oval, vlc_value_t nval, void *param ) |
|---|
| 290 |
{ |
|---|
| 291 |
intf_thread_t *p_intf = (intf_thread_t *)param; |
|---|
| 292 |
|
|---|
| 293 |
p_intf->p_sys->b_need_update = true; |
|---|
| 294 |
return VLC_SUCCESS; |
|---|
| 295 |
} |
|---|
| 296 |
|
|---|