1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 - 2005 the VideoLAN team
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8 * Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
31 #include <errno.h> /* ENOMEM */
40 #include <vlc_video.h>
42 #include <vlc_update.h>
48 #ifdef HAVE_SYS_TIME_H
49 # include <sys/time.h>
51 #include <sys/types.h>
53 #include "vlc_error.h"
56 #if defined(AF_UNIX) && !defined(AF_LOCAL)
57 # define AF_LOCAL AF_UNIX
60 #if defined(AF_LOCAL) && ! defined(WIN32)
64 #define MAX_LINE_LENGTH 256
65 #define STATUS_CHANGE "status change: "
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Activate ( vlc_object_t * );
71 static void Deactivate ( vlc_object_t * );
72 static void Run ( intf_thread_t * );
74 static void Help ( intf_thread_t *, vlc_bool_t );
75 static void RegisterCallbacks( intf_thread_t * );
77 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
79 static playlist_item_t *parse_MRL( intf_thread_t *, char * );
81 static int Input ( vlc_object_t *, char const *,
82 vlc_value_t, vlc_value_t, void * );
83 static int Playlist ( vlc_object_t *, char const *,
84 vlc_value_t, vlc_value_t, void * );
85 static int Other ( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
87 static int Quit ( vlc_object_t *, char const *,
88 vlc_value_t, vlc_value_t, void * );
89 static int Intf ( vlc_object_t *, char const *,
90 vlc_value_t, vlc_value_t, void * );
91 static int Volume ( vlc_object_t *, char const *,
92 vlc_value_t, vlc_value_t, void * );
93 static int VolumeMove ( vlc_object_t *, char const *,
94 vlc_value_t, vlc_value_t, void * );
95 static int AudioConfig ( vlc_object_t *, char const *,
96 vlc_value_t, vlc_value_t, void * );
97 static int Menu ( vlc_object_t *, char const *,
98 vlc_value_t, vlc_value_t, void * );
99 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg );
101 /* Status Callbacks */
102 static int TimeOffsetChanged( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t , void * );
104 static int VolumeChanged ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int StateChanged ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int RateChanged ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
113 int *pi_socket_listen;
118 vlc_mutex_t status_lock;
119 playlist_status_t i_last_state;
127 #ifdef HAVE_VARIADIC_MACROS
128 # define msg_rc( psz_format, args... ) \
129 __msg_rc( p_intf, psz_format, ## args )
132 void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
135 va_start( args, psz_fmt );
137 if( p_intf->p_sys->i_socket == -1 )
139 vprintf( psz_fmt, args );
144 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
145 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
150 /*****************************************************************************
152 *****************************************************************************/
153 #define POS_TEXT N_("Show stream position")
154 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
155 "stream from time to time." )
157 #define TTY_TEXT N_("Fake TTY")
158 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
160 #define UNIX_TEXT N_("UNIX socket command input")
161 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
164 #define HOST_TEXT N_("TCP command input")
165 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
166 "You can set the address and port the interface will bind to." )
169 #define QUIET_TEXT N_("Do not open a DOS command box interface")
170 #define QUIET_LONGTEXT N_( \
171 "By default the rc interface plugin will start a DOS command box. " \
172 "Enabling the quiet mode will not bring this command box but can also " \
173 "be pretty annoying when you want to stop VLC and no video window is " \
178 set_shortname( _("RC"));
179 set_category( CAT_INTERFACE );
180 set_subcategory( SUBCAT_INTERFACE_GENERAL );
181 set_description( _("Remote control interface") );
182 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
184 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
186 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
187 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
190 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
193 set_capability( "interface", 20 );
194 set_callbacks( Activate, Deactivate );
197 /*****************************************************************************
198 * Activate: initialize and create stuff
199 *****************************************************************************/
200 static int Activate( vlc_object_t *p_this )
202 intf_thread_t *p_intf = (intf_thread_t*)p_this;
203 playlist_t *p_playlist;
204 char *psz_host, *psz_unix_path;
205 int *pi_socket = NULL;
207 #if defined(HAVE_ISATTY) && !defined(WIN32)
208 /* Check that stdin is a TTY */
209 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
211 msg_Warn( p_intf, "fd 0 is not a TTY" );
216 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
221 #if !defined(AF_LOCAL) || defined(WIN32)
222 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
223 free( psz_unix_path );
226 struct sockaddr_un addr;
229 memset( &addr, 0, sizeof(struct sockaddr_un) );
231 msg_Dbg( p_intf, "trying UNIX socket" );
233 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
235 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
236 free( psz_unix_path );
240 addr.sun_family = AF_LOCAL;
241 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
242 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
244 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
245 sizeof(struct sockaddr_un) ) ) < 0 )
247 msg_Warn( p_intf, "couldn't bind socket to address: %s",
249 free( psz_unix_path );
250 net_Close( i_socket );
254 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
256 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
257 free( psz_unix_path );
258 net_Close( i_socket );
262 /* FIXME: we need a core function to merge listening sockets sets */
263 pi_socket = calloc( 2, sizeof( int ) );
264 if( pi_socket == NULL )
266 free( psz_unix_path );
267 net_Close( i_socket );
270 pi_socket[0] = i_socket;
275 if( ( pi_socket == NULL ) &&
276 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
280 vlc_UrlParse( &url, psz_host, 0 );
282 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
284 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
285 if( pi_socket == NULL )
287 msg_Warn( p_intf, "can't listen to %s port %i",
288 url.psz_host, url.i_port );
289 vlc_UrlClean( &url );
294 vlc_UrlClean( &url );
298 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
301 msg_Err( p_intf, "no memory" );
305 p_intf->p_sys->pi_socket_listen = pi_socket;
306 p_intf->p_sys->i_socket = -1;
307 p_intf->p_sys->psz_unix_path = psz_unix_path;
308 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
309 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
311 /* Non-buffered stdout */
312 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
314 p_intf->pf_run = Run;
317 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
318 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
323 /* Force "no-view" mode */
324 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
328 vlc_mutex_lock( &p_playlist->object_lock );
329 p_playlist->status.i_view = -1;
330 vlc_mutex_unlock( &p_playlist->object_lock );
331 vlc_object_release( p_playlist );
334 msg_rc( _("Remote control interface initialized, `h' for help") );
338 /*****************************************************************************
339 * Deactivate: uninitialize and cleanup
340 *****************************************************************************/
341 static void Deactivate( vlc_object_t *p_this )
343 intf_thread_t *p_intf = (intf_thread_t*)p_this;
345 net_ListenClose( p_intf->p_sys->pi_socket_listen );
346 if( p_intf->p_sys->i_socket != -1 )
347 net_Close( p_intf->p_sys->i_socket );
348 if( p_intf->p_sys->psz_unix_path != NULL )
350 #if defined(AF_LOCAL) && !defined(WIN32)
351 unlink( p_intf->p_sys->psz_unix_path );
353 free( p_intf->p_sys->psz_unix_path );
355 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
356 free( p_intf->p_sys );
359 /*****************************************************************************
360 * RegisterCallbacks: Register callbacks to dynamic variables
361 *****************************************************************************/
362 static void RegisterCallbacks( intf_thread_t *p_intf )
364 /* Register commands that will be cleaned up upon object destruction */
365 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
366 var_AddCallback( p_intf, "quit", Quit, NULL );
367 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
368 var_AddCallback( p_intf, "intf", Intf, NULL );
370 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
371 var_AddCallback( p_intf, "add", Playlist, NULL );
372 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
373 var_AddCallback( p_intf, "playlist", Playlist, NULL );
374 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
375 var_AddCallback( p_intf, "play", Playlist, NULL );
376 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
377 var_AddCallback( p_intf, "stop", Playlist, NULL );
378 var_Create( p_intf, "clear", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
379 var_AddCallback( p_intf, "clear", Playlist, NULL );
380 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
381 var_AddCallback( p_intf, "prev", Playlist, NULL );
382 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
383 var_AddCallback( p_intf, "next", Playlist, NULL );
384 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
385 var_AddCallback( p_intf, "goto", Playlist, NULL );
386 var_Create( p_intf, "status", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
387 var_AddCallback( p_intf, "status", Playlist, NULL );
389 /* marquee on the fly items */
390 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
391 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
392 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
393 var_AddCallback( p_intf, "marq-x", Other, NULL );
394 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
395 var_AddCallback( p_intf, "marq-y", Other, NULL );
396 var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
397 var_AddCallback( p_intf, "marq-position", Other, NULL );
398 var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
399 var_AddCallback( p_intf, "marq-color", Other, NULL );
400 var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
401 var_AddCallback( p_intf, "marq-opacity", Other, NULL );
402 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
403 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
404 var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
405 var_AddCallback( p_intf, "marq-size", Other, NULL );
407 var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
408 var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
409 var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
410 var_AddCallback( p_intf, "mosaic-height", Other, NULL );
411 var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
412 var_AddCallback( p_intf, "mosaic-width", Other, NULL );
413 var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
414 var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
415 var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
416 var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
417 var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
418 var_AddCallback( p_intf, "mosaic-align", Other, NULL );
419 var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
420 var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
421 var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
422 var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
423 var_Create( p_intf, "mosaic-position",
424 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
425 var_AddCallback( p_intf, "mosaic-position", Other, NULL );
426 var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
427 var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
428 var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
429 var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
430 var_Create( p_intf, "mosaic-keep-aspect-ratio",
431 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
432 var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
434 /* time on the fly items */
435 var_Create( p_intf, "time-format", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
436 var_AddCallback( p_intf, "time-format", Other, NULL );
437 var_Create( p_intf, "time-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
438 var_AddCallback( p_intf, "time-x", Other, NULL );
439 var_Create( p_intf, "time-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
440 var_AddCallback( p_intf, "time-y", Other, NULL );
441 var_Create( p_intf, "time-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
442 var_AddCallback( p_intf, "time-position", Other, NULL );
443 var_Create( p_intf, "time-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
444 var_AddCallback( p_intf, "time-color", Other, NULL );
445 var_Create( p_intf, "time-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
446 var_AddCallback( p_intf, "time-opacity", Other, NULL );
447 var_Create( p_intf, "time-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
448 var_AddCallback( p_intf, "time-size", Other, NULL );
450 /* logo on the fly items */
451 var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
452 var_AddCallback( p_intf, "logo-file", Other, NULL );
453 var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
454 var_AddCallback( p_intf, "logo-x", Other, NULL );
455 var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
456 var_AddCallback( p_intf, "logo-y", Other, NULL );
457 var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
458 var_AddCallback( p_intf, "logo-position", Other, NULL );
459 var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
460 var_AddCallback( p_intf, "logo-transparency", Other, NULL );
462 /* OSD menu commands */
463 var_Create( p_intf, "menu", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
464 var_AddCallback( p_intf, "menu", Menu, NULL );
467 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
468 var_AddCallback( p_intf, "pause", Input, NULL );
469 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
470 var_AddCallback( p_intf, "seek", Input, NULL );
471 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
472 var_AddCallback( p_intf, "title", Input, NULL );
473 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
474 var_AddCallback( p_intf, "title_n", Input, NULL );
475 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
476 var_AddCallback( p_intf, "title_p", Input, NULL );
477 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
478 var_AddCallback( p_intf, "chapter", Input, NULL );
479 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
480 var_AddCallback( p_intf, "chapter_n", Input, NULL );
481 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
482 var_AddCallback( p_intf, "chapter_p", Input, NULL );
484 var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
485 var_AddCallback( p_intf, "fastforward", Input, NULL );
486 var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
487 var_AddCallback( p_intf, "rewind", Input, NULL );
488 var_Create( p_intf, "faster", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
489 var_AddCallback( p_intf, "faster", Input, NULL );
490 var_Create( p_intf, "slower", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
491 var_AddCallback( p_intf, "slower", Input, NULL );
492 var_Create( p_intf, "normal", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
493 var_AddCallback( p_intf, "normal", Input, NULL );
496 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
497 var_AddCallback( p_intf, "volume", Volume, NULL );
498 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
499 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
500 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
501 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
502 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
503 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
504 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
505 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
508 /*****************************************************************************
510 *****************************************************************************
511 * This part of the interface is in a separate thread so that we can call
512 * exec() from within it without annoying the rest of the program.
513 *****************************************************************************/
514 static void Run( intf_thread_t *p_intf )
516 input_thread_t * p_input;
517 playlist_t * p_playlist;
519 char p_buffer[ MAX_LINE_LENGTH + 1 ];
520 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
521 vlc_bool_t b_longhelp = VLC_FALSE;
531 /* Register commands that will be cleaned up upon object destruction */
532 RegisterCallbacks( p_intf );
534 /* status callbacks */
535 /* Listen to audio volume updates */
536 var_AddCallback( p_intf->p_vlc, "volume-change", VolumeChanged, p_intf );
539 /* Get the file descriptor of the console input */
540 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
541 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
543 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
544 p_intf->b_die = VLC_TRUE;
548 while( !p_intf->b_die )
550 char *psz_cmd, *psz_arg;
551 vlc_bool_t b_complete;
553 if( p_intf->p_sys->pi_socket_listen != NULL &&
554 p_intf->p_sys->i_socket == -1 )
556 p_intf->p_sys->i_socket =
557 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
560 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
562 /* Manage the input part */
563 if( p_input == NULL )
567 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
572 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
576 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
580 /* New input has been registered */
583 if( !p_input->b_dead || !p_input->b_die )
585 msg_rc( STATUS_CHANGE "( New input: %s )", p_input->input.p_item->psz_uri );
586 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
588 var_AddCallback( p_input, "state", StateChanged, p_intf );
589 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
590 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
591 var_AddCallback( p_input, "rate", RateChanged, p_intf );
592 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
595 else if( p_input->b_dead )
597 var_DelCallback( p_input, "state", StateChanged, p_intf );
598 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
599 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
600 var_DelCallback( p_input, "rate", RateChanged, p_intf );
601 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
602 vlc_object_release( p_input );
607 vlc_mutex_lock( &p_playlist->object_lock );
608 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
609 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
610 vlc_mutex_unlock( &p_playlist->object_lock );
614 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
615 (p_playlist != NULL) )
617 vlc_mutex_lock( &p_playlist->object_lock );
618 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
619 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
621 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
622 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
624 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
625 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
627 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
628 msg_rc( STATUS_CHANGE "( play state: 1 )" );
630 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
631 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
633 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
634 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
636 vlc_mutex_unlock( &p_playlist->object_lock );
639 if( p_input && b_showpos )
641 i_newpos = 100 * var_GetFloat( p_input, "position" );
642 if( i_oldpos != i_newpos )
645 msg_rc( "pos: %d%%", i_newpos );
649 /* Is there something to do? */
650 if( !b_complete ) continue;
653 /* Skip heading spaces */
655 while( *psz_cmd == ' ' )
660 /* Split psz_cmd at the first space and make sure that
661 * psz_arg is valid */
662 psz_arg = strchr( psz_cmd, ' ' );
666 while( *psz_arg == ' ' )
676 /* If the user typed a registered local command, try it */
677 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
682 val.psz_string = psz_arg;
683 i_ret = var_Set( p_intf, psz_cmd, val );
684 msg_rc( "%s: returned %i (%s)",
685 psz_cmd, i_ret, vlc_error( i_ret ) );
687 /* Or maybe it's a global command */
688 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
693 val.psz_string = psz_arg;
694 /* FIXME: it's a global command, but we should pass the
695 * local object as an argument, not p_intf->p_libvlc. */
696 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
699 msg_rc( "%s: returned %i (%s)",
700 psz_cmd, i_ret, vlc_error( i_ret ) );
703 else if( !strcmp( psz_cmd, "logout" ) )
705 /* Close connection */
706 if( p_intf->p_sys->i_socket != -1 )
708 net_Close( p_intf->p_sys->i_socket );
710 p_intf->p_sys->i_socket = -1;
712 else if( !strcmp( psz_cmd, "info" ) )
717 vlc_mutex_lock( &p_input->input.p_item->lock );
718 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
720 info_category_t *p_category =
721 p_input->input.p_item->pp_categories[i];
723 msg_rc( "+----[ %s ]", p_category->psz_name );
725 for ( j = 0; j < p_category->i_infos; j++ )
727 info_t *p_info = p_category->pp_infos[j];
728 msg_rc( "| %s: %s", p_info->psz_name,
733 msg_rc( "+----[ end of stream info ]" );
734 vlc_mutex_unlock( &p_input->input.p_item->lock );
738 msg_rc( "no input" );
741 else if( !strcmp( psz_cmd, "is_playing" ) )
752 else if( !strcmp( psz_cmd, "get_time" ) )
761 var_Get( p_input, "time", &time );
762 msg_rc( "%i", time.i_time / 1000000);
765 else if( !strcmp( psz_cmd, "get_length" ) )
774 var_Get( p_input, "length", &time );
775 msg_rc( "%i", time.i_time / 1000000);
778 else if( !strcmp( psz_cmd, "get_title" ) )
786 msg_rc( "%s", p_input->input.p_item->psz_name );
789 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
790 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
792 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
793 b_longhelp = VLC_TRUE;
794 else b_longhelp = VLC_FALSE;
796 Help( p_intf, b_longhelp );
798 else if( !strcmp( psz_cmd, "check-updates" ) )
800 checkUpdates( p_intf, psz_arg );
802 else switch( psz_cmd[0] )
808 vout_thread_t *p_vout;
809 p_vout = vlc_object_find( p_input,
810 VLC_OBJECT_VOUT, FIND_CHILD );
815 vlc_bool_t b_update = VLC_FALSE;
816 var_Get( p_vout, "fullscreen", &val );
817 val.b_bool = !val.b_bool;
818 if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
821 val.b_bool = VLC_TRUE;
823 else if( !strncmp(psz_arg, "off", 3) && (val.b_bool == VLC_FALSE) )
826 val.b_bool = VLC_FALSE;
828 else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
830 if( b_update ) var_Set( p_vout, "fullscreen", val );
831 vlc_object_release( p_vout );
842 /* Ignore empty lines */
846 msg_rc(_("unknown command `%s', type `help' for help"), psz_cmd);
850 /* Command processed */
851 i_size = 0; p_buffer[0] = 0;
854 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
855 msg_rc( STATUS_CHANGE "( quit )" );
859 var_DelCallback( p_input, "state", StateChanged, p_intf );
860 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
861 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
862 var_DelCallback( p_input, "rate", RateChanged, p_intf );
863 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
864 vlc_object_release( p_input );
870 vlc_object_release( p_playlist );
874 var_DelCallback( p_intf->p_vlc, "volume-change", VolumeChanged, p_intf );
877 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
879 msg_rc(_("+----[ Remote control commands ]"));
881 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist"));
882 msg_rc(_("| playlist . . . show items currently in playlist"));
883 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
884 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
885 msg_rc(_("| next . . . . . . . . . . . . next playlist item"));
886 msg_rc(_("| prev . . . . . . . . . . previous playlist item"));
887 msg_rc(_("| goto . . . . . . . . . . . . goto item at index"));
888 msg_rc(_("| clear . . . . . . . . . . . clear the playlist"));
889 msg_rc(_("| status . . . . . . . . . current playlist status"));
890 msg_rc(_("| title [X] . . . . set/get title in current item"));
891 msg_rc(_("| title_n . . . . . . next title in current item"));
892 msg_rc(_("| title_p . . . . previous title in current item"));
893 msg_rc(_("| chapter [X] . . set/get chapter in current item"));
894 msg_rc(_("| chapter_n . . . . next chapter in current item"));
895 msg_rc(_("| chapter_p . . previous chapter in current item"));
897 msg_rc(_("| seek X . seek in seconds, for instance `seek 12'"));
898 msg_rc(_("| pause . . . . . . . . . . . . . . toggle pause"));
899 msg_rc(_("| fastforward . . . . . . . set to maximum rate"));
900 msg_rc(_("| rewind . . . . . . . . . . set to minimum rate"));
901 msg_rc(_("| faster . . . . . . . . faster playing of stream"));
902 msg_rc(_("| slower . . . . . . . . slower playing of stream"));
903 msg_rc(_("| normal . . . . . . . . normal playing of stream"));
904 msg_rc(_("| f [on|off] . . . . . . . . . . toggle fullscreen"));
905 msg_rc(_("| info . . . information about the current stream"));
907 msg_rc(_("| volume [X] . . . . . . . . set/get audio volume"));
908 msg_rc(_("| volup [X] . . . . . raise audio volume X steps"));
909 msg_rc(_("| voldown [X] . . . . lower audio volume X steps"));
910 msg_rc(_("| adev [X] . . . . . . . . . set/get audio device"));
911 msg_rc(_("| achan [X]. . . . . . . . set/get audio channels"));
912 msg_rc(_("| menu [on|off|up|down|left|right|select] use menu"));
917 msg_rc(_("| marq-marquee STRING . . overlay STRING in video"));
918 msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left"));
919 msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top"));
920 msg_rc(_("| marq-position #. . . .relative position control"));
921 msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB"));
922 msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity"));
923 msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms"));
924 msg_rc(_("| marq-size # . . . . . . . . font size, in pixels"));
926 msg_rc(_("| time-format STRING . . . overlay STRING in video"));
927 msg_rc(_("| time-x X . . . . . . . . . . . .offset from left"));
928 msg_rc(_("| time-y Y . . . . . . . . . . . . offset from top"));
929 msg_rc(_("| time-position #. . . . . . . . relative position"));
930 msg_rc(_("| time-color # . . . . . . . . . . font color, RGB"));
931 msg_rc(_("| time-opacity # . . . . . . . . . . . . . opacity"));
932 msg_rc(_("| time-size # . . . . . . . . font size, in pixels"));
934 msg_rc(_("| logo-file STRING . . . the overlay file path/name"));
935 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
936 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
937 msg_rc(_("| logo-position #. . . . . . . . relative position"));
938 msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
940 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
941 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
942 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
943 msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
944 msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
945 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
946 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
947 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
948 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
949 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
950 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
951 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
953 msg_rc(_("| check-updates [newer] [equal] [older]\n"
954 "| [undef] [info] [source] [binary] [plugin]"));
957 msg_rc(_("| help . . . . . . . . . . . . . this help message"));
958 msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
959 msg_rc(_("| logout . . . . . exit (if in socket connection)"));
960 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc"));
962 msg_rc(_("+----[ end of help ]"));
965 /********************************************************************
966 * Status callback routines
967 ********************************************************************/
968 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
969 vlc_value_t oldval, vlc_value_t newval, void *p_data )
971 intf_thread_t *p_intf = (intf_thread_t*)p_data;
972 input_thread_t *p_input = NULL;
974 vlc_mutex_lock( &p_intf->p_sys->status_lock );
975 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
978 msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
979 vlc_object_release( p_input );
981 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
985 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
986 vlc_value_t oldval, vlc_value_t newval, void *p_data )
988 intf_thread_t *p_intf = (intf_thread_t*)p_data;
990 vlc_mutex_lock( &p_intf->p_sys->status_lock );
991 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
992 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
996 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
997 vlc_value_t oldval, vlc_value_t newval, void *p_data )
999 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1000 playlist_t *p_playlist = NULL;
1001 input_thread_t *p_input = NULL;
1003 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1004 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1007 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
1011 switch( p_playlist->status.i_status )
1013 case PLAYLIST_STOPPED:
1014 strncpy( &cmd[0], "stop", 4);
1017 case PLAYLIST_RUNNING:
1018 strncpy( &cmd[0], "play", 4);
1021 case PLAYLIST_PAUSED:
1022 strncpy( &cmd[0], "pause", 5);
1025 } /* var_GetInteger( p_input, "state" ) */
1026 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1027 vlc_object_release( p_playlist );
1029 vlc_object_release( p_input );
1031 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1035 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1036 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1038 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1039 input_thread_t *p_input = NULL;
1041 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1042 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1045 msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
1046 vlc_object_release( p_input );
1048 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1052 /********************************************************************
1054 ********************************************************************/
1055 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1056 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1058 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1059 input_thread_t *p_input;
1062 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1063 if( !p_input ) return VLC_ENOOBJ;
1065 var_Get( p_input, "state", &val );
1066 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1067 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1069 msg_rc( _("press menu select or pause to continue") );
1070 vlc_object_release( p_input );
1071 return VLC_EGENERIC;
1074 /* Parse commands that only require an input */
1075 if( !strcmp( psz_cmd, "pause" ) )
1077 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1078 var_Set( p_intf->p_vlc, "key-pressed", val );
1079 vlc_object_release( p_input );
1082 else if( !strcmp( psz_cmd, "seek" ) )
1084 if( strlen( newval.psz_string ) > 0 &&
1085 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1087 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
1088 var_Set( p_input, "position", val );
1092 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1093 var_Set( p_input, "time", val );
1095 vlc_object_release( p_input );
1098 else if ( !strcmp( psz_cmd, "fastforward" ) )
1100 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1101 var_Set( p_intf->p_vlc, "key-pressed", val );
1102 vlc_object_release( p_input );
1105 else if ( !strcmp( psz_cmd, "rewind" ) )
1107 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1108 var_Set( p_intf->p_vlc, "key-pressed", val );
1109 vlc_object_release( p_input );
1112 else if ( !strcmp( psz_cmd, "faster" ) )
1114 val.b_bool = VLC_TRUE;
1115 var_Set( p_input, "rate-faster", val );
1116 vlc_object_release( p_input );
1119 else if ( !strcmp( psz_cmd, "slower" ) )
1121 val.b_bool = VLC_TRUE;
1122 var_Set( p_input, "rate-slower", val );
1123 vlc_object_release( p_input );
1126 else if ( !strcmp( psz_cmd, "normal" ) )
1128 val.i_int = INPUT_RATE_DEFAULT;
1129 var_Set( p_input, "rate", val );
1130 vlc_object_release( p_input );
1133 else if( !strcmp( psz_cmd, "chapter" ) ||
1134 !strcmp( psz_cmd, "chapter_n" ) ||
1135 !strcmp( psz_cmd, "chapter_p" ) )
1137 if( !strcmp( psz_cmd, "chapter" ) )
1139 if ( *newval.psz_string )
1142 val.i_int = atoi( newval.psz_string );
1143 var_Set( p_input, "chapter", val );
1147 vlc_value_t val_list;
1150 var_Get( p_input, "chapter", &val );
1151 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1153 msg_rc( "Currently playing chapter %d/%d",
1154 val.i_int, val_list.p_list->i_count );
1155 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1159 else if( !strcmp( psz_cmd, "chapter_n" ) )
1161 val.b_bool = VLC_TRUE;
1162 var_Set( p_input, "next-chapter", val );
1164 else if( !strcmp( psz_cmd, "chapter_p" ) )
1166 val.b_bool = VLC_TRUE;
1167 var_Set( p_input, "prev-chapter", val );
1169 vlc_object_release( p_input );
1172 else if( !strcmp( psz_cmd, "title" ) ||
1173 !strcmp( psz_cmd, "title_n" ) ||
1174 !strcmp( psz_cmd, "title_p" ) )
1176 if( !strcmp( psz_cmd, "title" ) )
1178 if ( *newval.psz_string )
1181 val.i_int = atoi( newval.psz_string );
1182 var_Set( p_input, "title", val );
1186 vlc_value_t val_list;
1189 var_Get( p_input, "title", &val );
1190 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1192 msg_rc( "Currently playing title %d/%d",
1193 val.i_int, val_list.p_list->i_count );
1194 var_Change( p_this, "title", VLC_VAR_FREELIST,
1198 else if( !strcmp( psz_cmd, "title_n" ) )
1200 val.b_bool = VLC_TRUE;
1201 var_Set( p_input, "next-title", val );
1203 else if( !strcmp( psz_cmd, "title_p" ) )
1205 val.b_bool = VLC_TRUE;
1206 var_Set( p_input, "prev-title", val );
1209 vlc_object_release( p_input );
1213 /* Never reached. */
1214 vlc_object_release( p_input );
1215 return VLC_EGENERIC;
1218 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1219 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1222 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1223 playlist_t *p_playlist;
1225 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1232 if( p_playlist->p_input )
1235 var_Get( p_playlist->p_input, "state", &val );
1236 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1237 msg_rc( _("press menu select or pause to continue") );
1238 vlc_object_release( p_playlist );
1239 return VLC_EGENERIC;
1243 /* Parse commands that require a playlist */
1244 if( !strcmp( psz_cmd, "prev" ) )
1246 playlist_Prev( p_playlist );
1248 else if( !strcmp( psz_cmd, "next" ) )
1250 playlist_Next( p_playlist );
1252 else if( !strcmp( psz_cmd, "play" ) )
1254 if( p_playlist->p_input )
1258 var_Get( p_playlist->p_input, "rate", &val );
1259 if( val.i_int != INPUT_RATE_DEFAULT )
1261 val.i_int = INPUT_RATE_DEFAULT;
1262 var_Set( p_playlist->p_input, "rate", val );
1266 playlist_Play( p_playlist );
1270 else if (!strcmp( psz_cmd, "goto" ) )
1272 if( strlen( newval.psz_string ) > 0)
1274 val.i_int = atoi( newval.psz_string );
1275 playlist_Goto( p_playlist, val.i_int);
1278 else if( !strcmp( psz_cmd, "stop" ) )
1280 playlist_Stop( p_playlist );
1282 else if( !strcmp( psz_cmd, "clear" ) )
1284 playlist_Stop( p_playlist );
1285 vlc_mutex_lock( &p_playlist->object_lock );
1286 playlist_Clear( p_playlist );
1287 vlc_mutex_unlock( &p_playlist->object_lock );
1289 else if( !strcmp( psz_cmd, "add" ) &&
1290 newval.psz_string && *newval.psz_string )
1292 playlist_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1296 msg_rc( "trying to add %s to playlist", newval.psz_string );
1297 playlist_AddItem( p_playlist, p_item,
1298 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
1301 else if( !strcmp( psz_cmd, "playlist" ) )
1305 for ( i = 0; i < p_playlist->i_size; i++ )
1307 msg_rc( "|%s%s %s|%s|", i == p_playlist->i_index ? "*" : " ",
1308 p_playlist->pp_items[i]->input.psz_name,
1309 p_playlist->pp_items[i]->input.psz_uri,
1310 p_playlist->pp_items[i]->i_parents > 0 ?
1311 p_playlist->pp_items[i]->pp_parents[0]->p_parent->input.psz_name : "" );
1315 msg_rc( "| no entries" );
1318 else if( !strcmp( psz_cmd, "status" ) )
1320 if( p_playlist->p_input )
1322 /* Replay the current state of the system. */
1323 msg_rc( STATUS_CHANGE "( New input: %s )", p_playlist->p_input->input.p_item->psz_uri );
1324 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
1326 vlc_mutex_lock( &p_playlist->object_lock );
1327 switch( p_playlist->status.i_status )
1329 case PLAYLIST_STOPPED:
1330 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1332 case PLAYLIST_RUNNING:
1333 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1335 case PLAYLIST_PAUSED:
1336 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1339 msg_rc( STATUS_CHANGE "( state unknown )" );
1342 vlc_mutex_unlock( &p_playlist->object_lock );
1351 msg_rc( "unknown command!" );
1354 vlc_object_release( p_playlist );
1358 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1359 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1361 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1362 vlc_object_t *p_playlist;
1364 vlc_object_t *p_input;
1366 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1372 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1375 vlc_object_release( p_playlist );
1381 var_Get( p_input, "state", &val );
1382 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1384 msg_rc( _("press pause to continue") );
1385 vlc_object_release( p_playlist );
1386 vlc_object_release( p_input );
1387 return VLC_EGENERIC;
1391 /* Parse miscellaneous commands */
1392 if( !strcmp( psz_cmd, "marq-marquee" ) )
1394 if( strlen( newval.psz_string ) > 0 )
1396 val.psz_string = newval.psz_string;
1397 var_Set( p_input->p_libvlc, "marq-marquee", val );
1401 val.psz_string = "";
1402 var_Set( p_input->p_libvlc, "marq-marquee", val);
1405 else if( !strcmp( psz_cmd, "marq-x" ) )
1407 if( strlen( newval.psz_string ) > 0)
1409 val.i_int = atoi( newval.psz_string );
1410 var_Set( p_input->p_libvlc, "marq-x", val );
1413 else if( !strcmp( psz_cmd, "marq-y" ) )
1415 if( strlen( newval.psz_string ) > 0)
1417 val.i_int = atoi( newval.psz_string );
1418 var_Set( p_input->p_libvlc, "marq-y", val );
1421 else if( !strcmp( psz_cmd, "marq-position" ) )
1423 if( strlen( newval.psz_string ) > 0)
1425 val.i_int = atoi( newval.psz_string );
1426 var_Set( p_input->p_libvlc, "marq-position", val );
1429 else if( !strcmp( psz_cmd, "marq-color" ) )
1431 if( strlen( newval.psz_string ) > 0)
1433 val.i_int = strtol( newval.psz_string, NULL, 0 );
1434 var_Set( p_input->p_libvlc, "marq-color", val );
1437 else if( !strcmp( psz_cmd, "marq-opacity" ) )
1439 if( strlen( newval.psz_string ) > 0)
1441 val.i_int = strtol( newval.psz_string, NULL, 0 );
1442 var_Set( p_input->p_libvlc, "marq-opacity", val );
1445 else if( !strcmp( psz_cmd, "marq-size" ) )
1447 if( strlen( newval.psz_string ) > 0)
1449 val.i_int = atoi( newval.psz_string );
1450 var_Set( p_input->p_libvlc, "marq-size", val );
1453 else if( !strcmp( psz_cmd, "marq-timeout" ) )
1455 if( strlen( newval.psz_string ) > 0)
1457 val.i_int = atoi( newval.psz_string );
1458 var_Set( p_input, "marq-timeout", val );
1461 else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1463 if( strlen( newval.psz_string ) > 0)
1465 val.i_int = atoi( newval.psz_string );
1466 var_Set( p_input->p_libvlc, "mosaic-alpha", val );
1469 else if( !strcmp( psz_cmd, "mosaic-height" ) )
1471 if( strlen( newval.psz_string ) > 0)
1473 val.i_int = atoi( newval.psz_string );
1474 var_Set( p_input->p_libvlc, "mosaic-height", val );
1477 else if( !strcmp( psz_cmd, "mosaic-width" ) )
1479 if( strlen( newval.psz_string ) > 0)
1481 val.i_int = atoi( newval.psz_string );
1482 var_Set( p_input->p_libvlc, "mosaic-width", val );
1485 else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1487 if( strlen( newval.psz_string ) > 0)
1489 val.i_int = atoi( newval.psz_string );
1490 var_Set( p_input->p_libvlc, "mosaic-xoffset", val );
1493 else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1495 if( strlen( newval.psz_string ) > 0)
1497 val.i_int = atoi( newval.psz_string );
1498 var_Set( p_input->p_libvlc, "mosaic-yoffset", val );
1501 else if( !strcmp( psz_cmd, "mosaic-align" ) )
1503 if( strlen( newval.psz_string ) > 0 )
1505 val.i_int = atoi( newval.psz_string );
1506 var_Set( p_input->p_libvlc, "mosaic-align", val );
1509 else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1511 if( strlen( newval.psz_string ) > 0)
1513 val.i_int = atoi( newval.psz_string );
1514 var_Set( p_input->p_libvlc, "mosaic-vborder", val );
1517 else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1519 if( strlen( newval.psz_string ) > 0)
1521 val.i_int = atoi( newval.psz_string );
1522 var_Set( p_input->p_libvlc, "mosaic-hborder", val );
1525 else if( !strcmp( psz_cmd, "mosaic-position" ) )
1527 if( strlen( newval.psz_string ) > 0)
1529 val.i_int = atoi( newval.psz_string );
1530 var_Set( p_input->p_libvlc, "mosaic-position", val );
1533 else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1535 if( strlen( newval.psz_string ) > 0)
1537 val.i_int = atoi( newval.psz_string );
1538 var_Set( p_input->p_libvlc, "mosaic-rows", val );
1541 else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1543 if( strlen( newval.psz_string ) > 0)
1545 val.i_int = atoi( newval.psz_string );
1546 var_Set( p_input->p_libvlc, "mosaic-cols", val );
1549 else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1551 if( strlen( newval.psz_string ) > 0)
1553 val.i_int = atoi( newval.psz_string );
1554 var_Set( p_input->p_libvlc, "mosaic-keep-aspect-ratio", val );
1557 else if( !strcmp( psz_cmd, "time-format" ) )
1559 if( strlen( newval.psz_string ) > 0 )
1561 val.psz_string = newval.psz_string;
1562 var_Set( p_input->p_libvlc, "time-format", val );
1566 val.psz_string = "";
1567 var_Set( p_input->p_libvlc, "time-format", val);
1570 else if( !strcmp( psz_cmd, "time-x" ) )
1572 if( strlen( newval.psz_string ) > 0)
1574 val.i_int = atoi( newval.psz_string );
1575 var_Set( p_input->p_libvlc, "time-x", val );
1578 else if( !strcmp( psz_cmd, "time-y" ) )
1580 if( strlen( newval.psz_string ) > 0)
1582 val.i_int = atoi( newval.psz_string );
1583 var_Set( p_input->p_libvlc, "time-y", val );
1586 else if( !strcmp( psz_cmd, "time-position" ) )
1588 if( strlen( newval.psz_string ) > 0)
1590 val.i_int = atoi( newval.psz_string );
1591 var_Set( p_input->p_libvlc, "time-position", val );
1594 else if( !strcmp( psz_cmd, "time-color" ) )
1596 if( strlen( newval.psz_string ) > 0)
1598 val.i_int = strtol( newval.psz_string, NULL, 0 );
1599 var_Set( p_input->p_libvlc, "time-color", val );
1602 else if( !strcmp( psz_cmd, "time-opacity" ) )
1604 if( strlen( newval.psz_string ) > 0)
1606 val.i_int = strtol( newval.psz_string, NULL, 0 );
1607 var_Set( p_input->p_libvlc, "time-opacity", val );
1610 else if( !strcmp( psz_cmd, "time-size" ) )
1612 if( strlen( newval.psz_string ) > 0)
1614 val.i_int = atoi( newval.psz_string );
1615 var_Set( p_input->p_libvlc, "time-size", val );
1618 else if( !strcmp( psz_cmd, "logo-file" ) )
1620 if( strlen( newval.psz_string ) > 0 )
1622 val.psz_string = newval.psz_string;
1623 var_Set( p_input->p_libvlc, "logo-file", val );
1626 else if( !strcmp( psz_cmd, "logo-x" ) )
1628 if( strlen( newval.psz_string ) > 0)
1630 val.i_int = atoi( newval.psz_string );
1631 var_Set( p_input->p_libvlc, "logo-x", val );
1634 else if( !strcmp( psz_cmd, "logo-y" ) )
1636 if( strlen( newval.psz_string ) > 0)
1638 val.i_int = atoi( newval.psz_string );
1639 var_Set( p_input->p_libvlc, "logo-y", val );
1642 else if( !strcmp( psz_cmd, "logo-position" ) )
1644 if( strlen( newval.psz_string ) > 0)
1646 val.i_int = atoi( newval.psz_string );
1647 var_Set( p_input->p_libvlc, "logo-position", val );
1650 else if( !strcmp( psz_cmd, "logo-transparency" ) )
1652 if( strlen( newval.psz_string ) > 0)
1654 val.i_int = strtol( newval.psz_string, NULL, 0 );
1655 var_Set( p_input->p_libvlc, "logo-transparency", val );
1664 msg_rc( "unknown command!" );
1667 vlc_object_release( p_playlist );
1668 vlc_object_release( p_input );
1672 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1673 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1675 playlist_t *p_playlist;
1677 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1680 playlist_Stop( p_playlist );
1681 vlc_object_release( p_playlist );
1683 p_this->p_vlc->b_die = VLC_TRUE;
1687 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1688 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1690 intf_thread_t *p_newintf = NULL;
1692 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string, 0, NULL );
1695 p_newintf->b_block = VLC_FALSE;
1696 if( intf_RunThread( p_newintf ) )
1698 vlc_object_detach( p_newintf );
1699 intf_Destroy( p_newintf );
1706 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1707 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1709 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1710 input_thread_t *p_input = NULL;
1711 int i_error = VLC_EGENERIC;
1713 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1721 var_Get( p_input, "state", &val );
1722 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1724 msg_rc( _("press menu select or pause to continue") );
1725 vlc_object_release( p_input );
1726 return VLC_EGENERIC;
1728 vlc_object_release( p_input );
1731 if ( *newval.psz_string )
1734 audio_volume_t i_volume = atoi( newval.psz_string );
1735 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1737 msg_rc( "Volume must be in the range %d-%d", AOUT_VOLUME_MIN,
1739 i_error = VLC_EBADVAR;
1743 if( i_volume == AOUT_VOLUME_MIN )
1747 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1748 var_Set( p_intf->p_vlc, "key-pressed", keyval );
1750 i_error = aout_VolumeSet( p_this, i_volume );
1751 osd_Volume( p_this );
1752 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1758 audio_volume_t i_volume;
1759 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1761 i_error = VLC_EGENERIC;
1765 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1766 i_error = VLC_SUCCESS;
1773 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1774 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1776 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1777 audio_volume_t i_volume;
1778 input_thread_t *p_input = NULL;
1779 int i_nb_steps = atoi(newval.psz_string);
1780 int i_error = VLC_SUCCESS;
1781 int i_volume_step = 0;
1783 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1791 var_Get( p_input, "state", &val );
1792 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1794 msg_rc( _("press menu select or pause to continue") );
1795 vlc_object_release( p_input );
1796 return VLC_EGENERIC;
1798 vlc_object_release( p_input );
1801 i_volume_step = config_GetInt( p_intf->p_vlc, "volume-step" );
1802 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1807 if ( !strcmp(psz_cmd, "volup") )
1809 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1810 i_error = VLC_EGENERIC;
1814 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1815 i_error = VLC_EGENERIC;
1817 osd_Volume( p_this );
1819 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1823 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1824 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1826 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1827 input_thread_t *p_input = NULL;
1828 aout_instance_t * p_aout;
1829 const char * psz_variable;
1830 vlc_value_t val_name;
1833 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1841 var_Get( p_input, "state", &val );
1842 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1843 msg_rc( _("press menu select or pause to continue") );
1844 vlc_object_release( p_input );
1845 return VLC_EGENERIC;
1847 vlc_object_release( p_input );
1850 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1851 if ( p_aout == NULL ) return VLC_ENOOBJ;
1853 if ( !strcmp( psz_cmd, "adev" ) )
1855 psz_variable = "audio-device";
1859 psz_variable = "audio-channels";
1862 /* Get the descriptive name of the variable */
1863 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1865 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1867 if ( !*newval.psz_string )
1869 /* Retrieve all registered ***. */
1870 vlc_value_t val, text;
1873 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1875 vlc_object_release( (vlc_object_t *)p_aout );
1876 return VLC_EGENERIC;
1878 i_value = val.i_int;
1880 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1881 VLC_VAR_GETLIST, &val, &text ) < 0 )
1883 vlc_object_release( (vlc_object_t *)p_aout );
1884 return VLC_EGENERIC;
1887 msg_rc( "+----[ %s ]", val_name.psz_string );
1888 for ( i = 0; i < val.p_list->i_count; i++ )
1890 if ( i_value == val.p_list->p_values[i].i_int )
1891 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1892 text.p_list->p_values[i].psz_string );
1894 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1895 text.p_list->p_values[i].psz_string );
1897 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1899 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1901 if( val_name.psz_string ) free( val_name.psz_string );
1902 i_error = VLC_SUCCESS;
1907 val.i_int = atoi( newval.psz_string );
1909 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1911 vlc_object_release( (vlc_object_t *)p_aout );
1916 /* OSD menu commands */
1917 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1918 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1920 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1921 playlist_t *p_playlist = NULL;
1923 int i_error = VLC_EGENERIC;
1925 if ( !*newval.psz_string )
1927 msg_rc( _("please provide one of the following paramaters") );
1928 msg_rc( "[on|off|up|down|left|right|select]" );
1932 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1936 if( p_playlist->p_input )
1938 var_Get( p_playlist->p_input, "state", &val );
1939 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1940 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1942 msg_rc( _("press menu select or pause to continue") );
1943 vlc_object_release( p_playlist );
1944 return VLC_EGENERIC;
1947 vlc_object_release( p_playlist );
1949 val.psz_string = strdup( newval.psz_string );
1950 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1951 osd_MenuShow( p_this );
1952 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1953 osd_MenuHide( p_this );
1954 else if( !strcmp( val.psz_string, "up" ) )
1955 osd_MenuUp( p_this );
1956 else if( !strcmp( val.psz_string, "down" ) )
1957 osd_MenuDown( p_this );
1958 else if( !strcmp( val.psz_string, "left" ) )
1959 osd_MenuPrev( p_this );
1960 else if( !strcmp( val.psz_string, "right" ) )
1961 osd_MenuNext( p_this );
1962 else if( !strcmp( val.psz_string, "select" ) )
1963 osd_MenuActivate( p_this );
1966 msg_rc( _("please provide one of the following paramaters") );
1967 msg_rc( "[on|off|up|down|left|right|select]" );
1968 if( val.psz_string ) free( val.psz_string );
1972 i_error = VLC_SUCCESS;
1973 if( val.psz_string ) free( val.psz_string );
1978 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1980 INPUT_RECORD input_record;
1983 /* On Win32, select() only works on socket descriptors */
1984 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1985 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1987 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1988 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1991 if( input_record.EventType != KEY_EVENT ||
1992 !input_record.Event.KeyEvent.bKeyDown ||
1993 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1994 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1995 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1996 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1998 /* nothing interesting */
2002 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2004 /* Echo out the command */
2005 putc( p_buffer[ *pi_size ], stdout );
2007 /* Handle special keys */
2008 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2010 putc( '\n', stdout );
2013 switch( p_buffer[ *pi_size ] )
2019 putc( ' ', stdout );
2020 putc( '\b', stdout );
2031 if( *pi_size == MAX_LINE_LENGTH ||
2032 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2034 p_buffer[ *pi_size ] = 0;
2043 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2048 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2049 return ReadWin32( p_intf, p_buffer, pi_size );
2050 else if( p_intf->p_sys->i_socket == -1 )
2052 msleep( INTF_IDLE_SLEEP );
2057 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
2058 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
2059 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2060 (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
2062 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2068 /* Connection closed */
2071 p_intf->p_sys->i_socket = -1;
2072 p_buffer[ *pi_size ] = 0;
2076 if( *pi_size == MAX_LINE_LENGTH ||
2077 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2079 p_buffer[ *pi_size ] = 0;
2086 /*****************************************************************************
2087 * parse_MRL: build a playlist item from a full mrl
2088 *****************************************************************************
2089 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2090 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2091 * space is a new option. Should be good enough for our purpose.
2092 *****************************************************************************/
2093 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2095 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2096 #define SKIPTRAILINGSPACE( p, d ) \
2097 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2099 playlist_item_t *p_item = NULL;
2100 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2101 char **ppsz_options = NULL;
2102 int i, i_options = 0;
2104 if( !psz_mrl ) return 0;
2106 psz_mrl = psz_orig = strdup( psz_mrl );
2109 SKIPSPACE( psz_mrl );
2112 for( ; *psz_mrl; psz_mrl++ )
2114 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2116 /* We have a complete item */
2119 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2120 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2122 /* We have a complete item */
2127 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2128 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2130 /* Remove '"' and '\'' if necessary */
2131 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2132 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2133 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2134 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2136 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2137 else if( *psz_item )
2140 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2141 ppsz_options[i_options - 1] = &psz_item[1];
2144 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2147 /* Now create a playlist item */
2150 p_item = playlist_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
2151 for( i = 0; i < i_options; i++ )
2153 playlist_ItemAddOption( p_item, ppsz_options[i] );
2157 if( i_options ) free( ppsz_options );
2163 /*****************************************************************************
2164 * checkUpdates : check for updates
2165 ****************************************************************************/
2166 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2168 update_iterator_t *p_uit;
2169 update_t *p_u = update_New( p_intf );
2170 if( p_u == NULL ) return;
2171 p_uit = update_iterator_New( p_u );
2176 if( strstr( psz_arg, "newer" ) )
2177 s |= UPDATE_RELEASE_STATUS_NEWER;
2178 if( strstr( psz_arg, "equal" ) )
2179 s |= UPDATE_RELEASE_STATUS_EQUAL;
2180 if( strstr( psz_arg, "older" ) )
2181 s |= UPDATE_RELEASE_STATUS_OLDER;
2182 if( s ) p_uit->i_rs = s;
2183 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2185 if( strstr( psz_arg, "undef" ) )
2186 t |= UPDATE_FILE_TYPE_UNDEF;
2187 if( strstr( psz_arg, "info" ) )
2188 t |= UPDATE_FILE_TYPE_INFO;
2189 if( strstr( psz_arg, "source" ) )
2190 t |= UPDATE_FILE_TYPE_SOURCE;
2191 if( strstr( psz_arg, "binary" ) )
2192 t |= UPDATE_FILE_TYPE_BINARY;
2193 if( strstr( psz_arg, "plugin" ) )
2194 t |= UPDATE_FILE_TYPE_PLUGIN;
2195 if( t ) p_uit->i_t = t;
2197 update_Check( p_u, VLC_FALSE );
2198 update_iterator_Action( p_uit, UPDATE_MIRROR );
2199 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2200 p_uit->mirror.psz_name,
2201 p_uit->mirror.psz_location,
2202 p_uit->mirror.psz_type );
2203 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2206 if( s & UPDATE_RELEASE )
2208 switch( p_uit->release.i_status )
2210 case UPDATE_RELEASE_STATUS_OLDER:
2211 psz_tmp = strdup( "older" );
2213 case UPDATE_RELEASE_STATUS_EQUAL:
2214 psz_tmp = strdup( "equal" );
2216 case UPDATE_RELEASE_STATUS_NEWER:
2217 psz_tmp = strdup( "newer" );
2220 psz_tmp = strdup( "?!?" );
2223 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2224 p_uit->release.psz_version,
2225 p_uit->release.psz_svn_revision,
2229 switch( p_uit->file.i_type )
2231 case UPDATE_FILE_TYPE_UNDEF:
2232 psz_tmp = strdup( "undef" );
2234 case UPDATE_FILE_TYPE_INFO:
2235 psz_tmp = strdup( "info" );
2237 case UPDATE_FILE_TYPE_SOURCE:
2238 psz_tmp = strdup( "source" );
2240 case UPDATE_FILE_TYPE_BINARY:
2241 psz_tmp = strdup( "binary" );
2243 case UPDATE_FILE_TYPE_PLUGIN:
2244 psz_tmp = strdup( "plugin" );
2247 psz_tmp = strdup( "?!?" );
2250 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2252 if( p_uit->file.l_size )
2254 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2255 asprintf( &psz_tmp, "(%ld GB)",
2256 p_uit->file.l_size / (1024*1024*1024) );
2257 if( p_uit->file.l_size > 1024 * 1024 )
2258 asprintf( &psz_tmp, "(%ld MB)",
2259 p_uit->file.l_size / (1024*1024) );
2260 else if( p_uit->file.l_size > 1024 )
2261 asprintf( &psz_tmp, "(%ld kB)",
2262 p_uit->file.l_size / 1024 );
2264 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2268 psz_tmp = strdup( "" );
2270 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2275 update_iterator_Delete( p_uit );
2277 update_Delete( p_u );