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 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
33 #include <errno.h> /* ENOMEM */
41 #include <vlc_video.h>
43 #include <vlc_update.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
52 #include <sys/types.h>
54 #include "vlc_error.h"
60 #if defined(AF_UNIX) && !defined(AF_LOCAL)
61 # define AF_LOCAL AF_UNIX
64 #if defined(AF_LOCAL) && ! defined(WIN32)
68 #define MAX_LINE_LENGTH 256
69 #define STATUS_CHANGE "status change: "
71 /*****************************************************************************
73 *****************************************************************************/
74 static int Activate ( vlc_object_t * );
75 static void Deactivate ( vlc_object_t * );
76 static void Run ( intf_thread_t * );
78 static void Help ( intf_thread_t *, vlc_bool_t );
79 static void RegisterCallbacks( intf_thread_t * );
81 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
83 static input_item_t *parse_MRL( intf_thread_t *, char * );
85 static int Input ( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
87 static int Playlist ( vlc_object_t *, char const *,
88 vlc_value_t, vlc_value_t, void * );
89 static int Other ( vlc_object_t *, char const *,
90 vlc_value_t, vlc_value_t, void * );
91 static int Quit ( vlc_object_t *, char const *,
92 vlc_value_t, vlc_value_t, void * );
93 static int Intf ( vlc_object_t *, char const *,
94 vlc_value_t, vlc_value_t, void * );
95 static int Volume ( vlc_object_t *, char const *,
96 vlc_value_t, vlc_value_t, void * );
97 static int VolumeMove ( vlc_object_t *, char const *,
98 vlc_value_t, vlc_value_t, void * );
99 static int VideoConfig ( vlc_object_t *, char const *,
100 vlc_value_t, vlc_value_t, void * );
101 static int AudioConfig ( vlc_object_t *, char const *,
102 vlc_value_t, vlc_value_t, void * );
103 static int Menu ( vlc_object_t *, char const *,
104 vlc_value_t, vlc_value_t, void * );
105 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg );
107 /* Status Callbacks */
108 static int TimeOffsetChanged( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t , void * );
110 static int VolumeChanged ( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t, void * );
112 static int StateChanged ( vlc_object_t *, char const *,
113 vlc_value_t, vlc_value_t, void * );
114 static int RateChanged ( vlc_object_t *, char const *,
115 vlc_value_t, vlc_value_t, void * );
119 int *pi_socket_listen;
124 vlc_mutex_t status_lock;
125 playlist_status_t i_last_state;
133 #ifdef HAVE_VARIADIC_MACROS
134 # define msg_rc( psz_format, args... ) \
135 __msg_rc( p_intf, psz_format, ## args )
138 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
141 va_start( args, psz_fmt );
143 if( p_intf->p_sys->i_socket == -1 )
145 utf8_vfprintf( stdout, psz_fmt, args );
150 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
151 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
156 /*****************************************************************************
158 *****************************************************************************/
159 #define POS_TEXT N_("Show stream position")
160 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
161 "stream from time to time." )
163 #define TTY_TEXT N_("Fake TTY")
164 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
166 #define UNIX_TEXT N_("UNIX socket command input")
167 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
170 #define HOST_TEXT N_("TCP command input")
171 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
172 "You can set the address and port the interface will bind to." )
175 #define QUIET_TEXT N_("Do not open a DOS command box interface")
176 #define QUIET_LONGTEXT N_( \
177 "By default the rc interface plugin will start a DOS command box. " \
178 "Enabling the quiet mode will not bring this command box but can also " \
179 "be pretty annoying when you want to stop VLC and no video window is " \
184 set_shortname( _("RC"));
185 set_category( CAT_INTERFACE );
186 set_subcategory( SUBCAT_INTERFACE_MAIN );
187 set_description( _("Remote control interface") );
188 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
190 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
192 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
193 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
196 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
199 set_capability( "interface", 20 );
200 set_callbacks( Activate, Deactivate );
203 /*****************************************************************************
204 * Activate: initialize and create stuff
205 *****************************************************************************/
206 static int Activate( vlc_object_t *p_this )
208 intf_thread_t *p_intf = (intf_thread_t*)p_this;
209 char *psz_host, *psz_unix_path;
210 int *pi_socket = NULL;
212 #if defined(HAVE_ISATTY) && !defined(WIN32)
213 /* Check that stdin is a TTY */
214 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
216 msg_Warn( p_intf, "fd 0 is not a TTY" );
221 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
224 int i_socket, i_overwrite;
226 i_overwrite = config_GetInt( p_intf, "rc-overwrite" );
229 #if !defined(AF_LOCAL) || defined(WIN32)
230 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
231 free( psz_unix_path );
234 struct sockaddr_un addr;
236 memset( &addr, 0, sizeof(struct sockaddr_un) );
238 msg_Dbg( p_intf, "trying UNIX socket" );
240 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
242 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
243 free( psz_unix_path );
247 addr.sun_family = AF_LOCAL;
248 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
249 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
251 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
252 && (errno == EADDRINUSE)
253 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
254 && (errno == ECONNREFUSED))
256 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
257 unlink (psz_unix_path);
259 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
261 msg_Err (p_intf, "cannot bind UNIX socket at %s: %s",
262 psz_unix_path, strerror (errno));
263 free (psz_unix_path);
264 net_Close (i_socket);
269 if( listen( i_socket, 1 ) )
271 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
272 free( psz_unix_path );
273 net_Close( i_socket );
277 /* FIXME: we need a core function to merge listening sockets sets */
278 pi_socket = calloc( 2, sizeof( int ) );
279 if( pi_socket == NULL )
281 free( psz_unix_path );
282 net_Close( i_socket );
285 pi_socket[0] = i_socket;
290 if( ( pi_socket == NULL ) &&
291 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
295 vlc_UrlParse( &url, psz_host, 0 );
297 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
299 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
300 if( pi_socket == NULL )
302 msg_Warn( p_intf, "can't listen to %s port %i",
303 url.psz_host, url.i_port );
304 vlc_UrlClean( &url );
309 vlc_UrlClean( &url );
313 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
316 msg_Err( p_intf, "no memory" );
320 p_intf->p_sys->pi_socket_listen = pi_socket;
321 p_intf->p_sys->i_socket = -1;
322 p_intf->p_sys->psz_unix_path = psz_unix_path;
323 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
324 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
326 /* Non-buffered stdout */
327 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
329 p_intf->pf_run = Run;
332 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
333 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
338 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
342 /*****************************************************************************
343 * Deactivate: uninitialize and cleanup
344 *****************************************************************************/
345 static void Deactivate( vlc_object_t *p_this )
347 intf_thread_t *p_intf = (intf_thread_t*)p_this;
349 net_ListenClose( p_intf->p_sys->pi_socket_listen );
350 if( p_intf->p_sys->i_socket != -1 )
351 net_Close( p_intf->p_sys->i_socket );
352 if( p_intf->p_sys->psz_unix_path != NULL )
354 #if defined(AF_LOCAL) && !defined(WIN32)
355 unlink( p_intf->p_sys->psz_unix_path );
357 free( p_intf->p_sys->psz_unix_path );
359 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
360 free( p_intf->p_sys );
363 /*****************************************************************************
364 * RegisterCallbacks: Register callbacks to dynamic variables
365 *****************************************************************************/
366 static void RegisterCallbacks( intf_thread_t *p_intf )
368 /* Register commands that will be cleaned up upon object destruction */
369 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
370 var_AddCallback( p_intf, "quit", Quit, NULL );
371 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
372 var_AddCallback( p_intf, "intf", Intf, NULL );
374 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
375 var_AddCallback( p_intf, "add", Playlist, NULL );
376 var_Create( p_intf, "repeat", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
377 var_AddCallback( p_intf, "repeat", Playlist, NULL );
378 var_Create( p_intf, "loop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
379 var_AddCallback( p_intf, "loop", Playlist, NULL );
380 var_Create( p_intf, "enqueue", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
381 var_AddCallback( p_intf, "enqueue", Playlist, NULL );
382 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
383 var_AddCallback( p_intf, "playlist", Playlist, NULL );
384 var_Create( p_intf, "sort", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
385 var_AddCallback( p_intf, "sort", Playlist, NULL );
386 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
387 var_AddCallback( p_intf, "play", Playlist, NULL );
388 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
389 var_AddCallback( p_intf, "stop", Playlist, NULL );
390 var_Create( p_intf, "clear", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
391 var_AddCallback( p_intf, "clear", Playlist, NULL );
392 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
393 var_AddCallback( p_intf, "prev", Playlist, NULL );
394 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
395 var_AddCallback( p_intf, "next", Playlist, NULL );
396 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
397 var_AddCallback( p_intf, "goto", Playlist, NULL );
398 var_Create( p_intf, "status", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
399 var_AddCallback( p_intf, "status", Playlist, NULL );
401 /* marquee on the fly items */
402 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
403 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
404 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
405 var_AddCallback( p_intf, "marq-x", Other, NULL );
406 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
407 var_AddCallback( p_intf, "marq-y", Other, NULL );
408 var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
409 var_AddCallback( p_intf, "marq-position", Other, NULL );
410 var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
411 var_AddCallback( p_intf, "marq-color", Other, NULL );
412 var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
413 var_AddCallback( p_intf, "marq-opacity", Other, NULL );
414 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
415 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
416 var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
417 var_AddCallback( p_intf, "marq-size", Other, NULL );
419 var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
420 var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
421 var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
422 var_AddCallback( p_intf, "mosaic-height", Other, NULL );
423 var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
424 var_AddCallback( p_intf, "mosaic-width", Other, NULL );
425 var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
426 var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
427 var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
428 var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
429 var_Create( p_intf, "mosaic-offsets", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
430 var_AddCallback( p_intf, "mosaic-offsets", Other, NULL );
431 var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
432 var_AddCallback( p_intf, "mosaic-align", Other, NULL );
433 var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
434 var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
435 var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
436 var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
437 var_Create( p_intf, "mosaic-position",
438 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
439 var_AddCallback( p_intf, "mosaic-position", Other, NULL );
440 var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
441 var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
442 var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
443 var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
444 var_Create( p_intf, "mosaic-order", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
445 var_AddCallback( p_intf, "mosaic-order", Other, NULL );
446 var_Create( p_intf, "mosaic-keep-aspect-ratio",
447 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
448 var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", 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 );
495 var_Create( p_intf, "atrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
496 var_AddCallback( p_intf, "atrack", Input, NULL );
497 var_Create( p_intf, "vtrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
498 var_AddCallback( p_intf, "vtrack", Input, NULL );
499 var_Create( p_intf, "strack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
500 var_AddCallback( p_intf, "strack", Input, NULL );
503 var_Create( p_intf, "vratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
504 var_AddCallback( p_intf, "vratio", VideoConfig, NULL );
505 var_Create( p_intf, "vcrop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
506 var_AddCallback( p_intf, "vcrop", VideoConfig, NULL );
507 var_Create( p_intf, "vzoom", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
508 var_AddCallback( p_intf, "vzoom", VideoConfig, NULL );
511 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
512 var_AddCallback( p_intf, "volume", Volume, NULL );
513 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
514 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
515 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
516 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
517 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
518 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
519 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
520 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
523 /*****************************************************************************
525 *****************************************************************************
526 * This part of the interface is in a separate thread so that we can call
527 * exec() from within it without annoying the rest of the program.
528 *****************************************************************************/
529 static void Run( intf_thread_t *p_intf )
531 input_thread_t * p_input;
532 playlist_t * p_playlist;
534 char p_buffer[ MAX_LINE_LENGTH + 1 ];
535 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
536 vlc_bool_t b_longhelp = VLC_FALSE;
546 /* Register commands that will be cleaned up upon object destruction */
547 RegisterCallbacks( p_intf );
549 /* status callbacks */
550 /* Listen to audio volume updates */
551 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
554 /* Get the file descriptor of the console input */
555 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
556 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
558 msg_Err( p_intf, "couldn't find user input handle" );
559 p_intf->b_die = VLC_TRUE;
563 while( !intf_ShouldDie( p_intf ) )
565 char *psz_cmd, *psz_arg;
566 vlc_bool_t b_complete;
568 if( p_intf->p_sys->pi_socket_listen != NULL &&
569 p_intf->p_sys->i_socket == -1 )
571 p_intf->p_sys->i_socket =
572 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
575 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
577 /* Manage the input part */
578 if( p_input == NULL )
582 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
587 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
591 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
595 /* New input has been registered */
598 if( !p_input->b_dead || !p_input->b_die )
600 msg_rc( STATUS_CHANGE "( new input: %s )", p_input->input.p_item->psz_uri );
601 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
603 var_AddCallback( p_input, "state", StateChanged, p_intf );
604 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
605 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
606 var_AddCallback( p_input, "rate", RateChanged, p_intf );
607 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
610 else if( p_input->b_dead )
612 var_DelCallback( p_input, "state", StateChanged, p_intf );
613 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
614 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
615 var_DelCallback( p_input, "rate", RateChanged, p_intf );
616 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
617 vlc_object_release( p_input );
622 vlc_mutex_lock( &p_playlist->object_lock );
623 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
624 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
625 vlc_mutex_unlock( &p_playlist->object_lock );
629 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
630 (p_playlist != NULL) )
632 vlc_mutex_lock( &p_playlist->object_lock );
633 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
634 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
636 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
637 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
639 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
640 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
642 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
643 msg_rc( STATUS_CHANGE "( play state: 1 )" );
645 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
646 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
648 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
649 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
651 vlc_mutex_unlock( &p_playlist->object_lock );
654 if( p_input && b_showpos )
656 i_newpos = 100 * var_GetFloat( p_input, "position" );
657 if( i_oldpos != i_newpos )
660 msg_rc( "pos: %d%%", i_newpos );
664 /* Is there something to do? */
665 if( !b_complete ) continue;
668 /* Skip heading spaces */
670 while( *psz_cmd == ' ' )
675 /* Split psz_cmd at the first space and make sure that
676 * psz_arg is valid */
677 psz_arg = strchr( psz_cmd, ' ' );
681 while( *psz_arg == ' ' )
691 /* If the user typed a registered local command, try it */
692 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
697 val.psz_string = psz_arg;
698 i_ret = var_Set( p_intf, psz_cmd, val );
699 msg_rc( "%s: returned %i (%s)",
700 psz_cmd, i_ret, vlc_error( i_ret ) );
702 /* Or maybe it's a global command */
703 else if( var_Type( p_intf->p_libvlc_global, psz_cmd ) & VLC_VAR_ISCOMMAND )
708 val.psz_string = psz_arg;
709 /* FIXME: it's a global command, but we should pass the
710 * local object as an argument, not p_intf->p_libvlc_global. */
711 i_ret = var_Set( p_intf->p_libvlc_global, psz_cmd, val );
714 msg_rc( "%s: returned %i (%s)",
715 psz_cmd, i_ret, vlc_error( i_ret ) );
718 else if( !strcmp( psz_cmd, "logout" ) )
720 /* Close connection */
721 if( p_intf->p_sys->i_socket != -1 )
723 net_Close( p_intf->p_sys->i_socket );
725 p_intf->p_sys->i_socket = -1;
727 else if( !strcmp( psz_cmd, "info" ) )
732 vlc_mutex_lock( &p_input->input.p_item->lock );
733 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
735 info_category_t *p_category =
736 p_input->input.p_item->pp_categories[i];
738 msg_rc( "+----[ %s ]", p_category->psz_name );
740 for ( j = 0; j < p_category->i_infos; j++ )
742 info_t *p_info = p_category->pp_infos[j];
743 msg_rc( "| %s: %s", p_info->psz_name,
748 msg_rc( "+----[ end of stream info ]" );
749 vlc_mutex_unlock( &p_input->input.p_item->lock );
753 msg_rc( "no input" );
756 else if( !strcmp( psz_cmd, "is_playing" ) )
767 else if( !strcmp( psz_cmd, "get_time" ) )
776 var_Get( p_input, "time", &time );
777 msg_rc( "%i", time.i_time / 1000000);
780 else if( !strcmp( psz_cmd, "get_length" ) )
789 var_Get( p_input, "length", &time );
790 msg_rc( "%i", time.i_time / 1000000);
793 else if( !strcmp( psz_cmd, "get_title" ) )
801 msg_rc( "%s", p_input->input.p_item->psz_name );
804 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
805 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
807 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
808 b_longhelp = VLC_TRUE;
809 else b_longhelp = VLC_FALSE;
811 Help( p_intf, b_longhelp );
813 else if( !strcmp( psz_cmd, "check-updates" ) )
815 checkUpdates( p_intf, psz_arg );
817 else switch( psz_cmd[0] )
823 vout_thread_t *p_vout;
824 p_vout = vlc_object_find( p_input,
825 VLC_OBJECT_VOUT, FIND_CHILD );
830 vlc_bool_t b_update = VLC_FALSE;
831 var_Get( p_vout, "fullscreen", &val );
832 val.b_bool = !val.b_bool;
833 if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
836 val.b_bool = VLC_TRUE;
838 else if( !strncmp(psz_arg, "off", 3) && (val.b_bool == VLC_FALSE) )
841 val.b_bool = VLC_FALSE;
843 else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
845 if( b_update ) var_Set( p_vout, "fullscreen", val );
846 vlc_object_release( p_vout );
857 /* Ignore empty lines */
861 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
865 /* Command processed */
866 i_size = 0; p_buffer[0] = 0;
869 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
870 msg_rc( STATUS_CHANGE "( quit )" );
874 var_DelCallback( p_input, "state", StateChanged, p_intf );
875 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
876 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
877 var_DelCallback( p_input, "rate", RateChanged, p_intf );
878 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
879 vlc_object_release( p_input );
885 vlc_object_release( p_playlist );
889 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
892 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
894 msg_rc(_("+----[ Remote control commands ]"));
896 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist"));
897 msg_rc(_("| enqueue XYZ . . . . . . . queue XYZ to playlist"));
898 msg_rc(_("| playlist . . . show items currently in playlist"));
899 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
900 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
901 msg_rc(_("| next . . . . . . . . . . . . next playlist item"));
902 msg_rc(_("| prev . . . . . . . . . . previous playlist item"));
903 msg_rc(_("| goto . . . . . . . . . . . . goto item at index"));
904 msg_rc(_("| repeat [on|off] . . toggle playlist item repeat"));
905 msg_rc(_("| loop [on|off] . . . . toggle playlist item loop"));
906 msg_rc(_("| clear . . . . . . . . . . . clear the playlist"));
907 msg_rc(_("| status . . . . . . . . . current playlist status"));
908 msg_rc(_("| title [X] . . . . set/get title in current item"));
909 msg_rc(_("| title_n . . . . . . next title in current item"));
910 msg_rc(_("| title_p . . . . previous title in current item"));
911 msg_rc(_("| chapter [X] . . set/get chapter in current item"));
912 msg_rc(_("| chapter_n . . . . next chapter in current item"));
913 msg_rc(_("| chapter_p . . previous chapter in current item"));
915 msg_rc(_("| seek X . seek in seconds, for instance `seek 12'"));
916 msg_rc(_("| pause . . . . . . . . . . . . . . toggle pause"));
917 msg_rc(_("| fastforward . . . . . . . set to maximum rate"));
918 msg_rc(_("| rewind . . . . . . . . . . set to minimum rate"));
919 msg_rc(_("| faster . . . . . . . . faster playing of stream"));
920 msg_rc(_("| slower . . . . . . . . slower playing of stream"));
921 msg_rc(_("| normal . . . . . . . . normal playing of stream"));
922 msg_rc(_("| f [on|off] . . . . . . . . . . toggle fullscreen"));
923 msg_rc(_("| info . . . information about the current stream"));
924 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
925 msg_rc(_("| is_playing . . 1 if a stream plays, 0 otherwise"));
926 msg_rc(_("| get_title . . . the title of the current stream"));
927 msg_rc(_("| get_length . . the length of the current stream"));
929 msg_rc(_("| volume [X] . . . . . . . . set/get audio volume"));
930 msg_rc(_("| volup [X] . . . . . raise audio volume X steps"));
931 msg_rc(_("| voldown [X] . . . . lower audio volume X steps"));
932 msg_rc(_("| adev [X] . . . . . . . . . set/get audio device"));
933 msg_rc(_("| achan [X]. . . . . . . . set/get audio channels"));
934 msg_rc(_("| atrack [X] . . . . . . . . . set/get audio track"));
935 msg_rc(_("| vtrack [X] . . . . . . . . . set/get video track"));
936 msg_rc(_("| vratio [X] . . . . . set/get video aspect ratio"));
937 msg_rc(_("| vcrop [X] . . . . . . . . . set/get video crop"));
938 msg_rc(_("| vzoom [X] . . . . . . . . . set/get video zoom"));
939 msg_rc(_("| strack [X] . . . . . . . set/get subtitles track"));
940 msg_rc(_("| menu [on|off|up|down|left|right|select] use menu"));
945 msg_rc(_("| marq-marquee STRING . . overlay STRING in video"));
946 msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left"));
947 msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top"));
948 msg_rc(_("| marq-position #. . . .relative position control"));
949 msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB"));
950 msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity"));
951 msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms"));
952 msg_rc(_("| marq-size # . . . . . . . . font size, in pixels"));
954 msg_rc(_("| logo-file STRING . . .the overlay file path/name"));
955 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
956 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
957 msg_rc(_("| logo-position #. . . . . . . . relative position"));
958 msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
960 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
961 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
962 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
963 msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
964 msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
965 msg_rc(_("| mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
966 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
967 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
968 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
969 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
970 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
971 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
972 msg_rc(_("| mosaic-order id(,id)* . . . . order of pictures "));
973 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
975 msg_rc(_("| check-updates [newer] [equal] [older]\n"
976 "| [undef] [info] [source] [binary] [plugin]"));
979 msg_rc(_("| help . . . . . . . . . . . . . this help message"));
980 msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
981 msg_rc(_("| logout . . . . . exit (if in socket connection)"));
982 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc"));
984 msg_rc(_("+----[ end of help ]"));
987 /********************************************************************
988 * Status callback routines
989 ********************************************************************/
990 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
991 vlc_value_t oldval, vlc_value_t newval, void *p_data )
993 intf_thread_t *p_intf = (intf_thread_t*)p_data;
994 input_thread_t *p_input = NULL;
996 vlc_mutex_lock( &p_intf->p_sys->status_lock );
997 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1000 msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
1001 vlc_object_release( p_input );
1003 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1007 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
1008 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1010 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1012 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1013 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
1014 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1018 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
1019 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1021 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1022 playlist_t *p_playlist = NULL;
1023 input_thread_t *p_input = NULL;
1025 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1026 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1029 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
1033 switch( p_playlist->status.i_status )
1035 case PLAYLIST_STOPPED:
1036 strncpy( &cmd[0], "stop", 4);
1039 case PLAYLIST_RUNNING:
1040 strncpy( &cmd[0], "play", 4);
1043 case PLAYLIST_PAUSED:
1044 strncpy( &cmd[0], "pause", 5);
1047 } /* var_GetInteger( p_input, "state" ) */
1048 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1049 vlc_object_release( p_playlist );
1051 vlc_object_release( p_input );
1053 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1057 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1058 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1060 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1061 input_thread_t *p_input = NULL;
1063 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1064 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1067 msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
1068 vlc_object_release( p_input );
1070 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1074 /********************************************************************
1076 ********************************************************************/
1077 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1078 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1080 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1081 input_thread_t *p_input;
1084 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1085 if( !p_input ) return VLC_ENOOBJ;
1087 var_Get( p_input, "state", &val );
1088 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1089 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1091 msg_rc( _("Press menu select or pause to continue.") );
1092 vlc_object_release( p_input );
1093 return VLC_EGENERIC;
1096 /* Parse commands that only require an input */
1097 if( !strcmp( psz_cmd, "pause" ) )
1099 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1100 var_Set( p_intf->p_libvlc, "key-pressed", val );
1101 vlc_object_release( p_input );
1104 else if( !strcmp( psz_cmd, "seek" ) )
1106 if( strlen( newval.psz_string ) > 0 &&
1107 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1109 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1110 var_Set( p_input, "position", val );
1114 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1115 var_Set( p_input, "time", val );
1117 vlc_object_release( p_input );
1120 else if ( !strcmp( psz_cmd, "fastforward" ) )
1122 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1123 var_Set( p_intf->p_libvlc, "key-pressed", val );
1124 vlc_object_release( p_input );
1127 else if ( !strcmp( psz_cmd, "rewind" ) )
1129 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1130 var_Set( p_intf->p_libvlc, "key-pressed", val );
1131 vlc_object_release( p_input );
1134 else if ( !strcmp( psz_cmd, "faster" ) )
1136 val.b_bool = VLC_TRUE;
1137 var_Set( p_input, "rate-faster", val );
1138 vlc_object_release( p_input );
1141 else if ( !strcmp( psz_cmd, "slower" ) )
1143 val.b_bool = VLC_TRUE;
1144 var_Set( p_input, "rate-slower", val );
1145 vlc_object_release( p_input );
1148 else if ( !strcmp( psz_cmd, "normal" ) )
1150 val.i_int = INPUT_RATE_DEFAULT;
1151 var_Set( p_input, "rate", val );
1152 vlc_object_release( p_input );
1155 else if( !strcmp( psz_cmd, "chapter" ) ||
1156 !strcmp( psz_cmd, "chapter_n" ) ||
1157 !strcmp( psz_cmd, "chapter_p" ) )
1159 if( !strcmp( psz_cmd, "chapter" ) )
1161 if ( *newval.psz_string )
1164 val.i_int = atoi( newval.psz_string );
1165 var_Set( p_input, "chapter", val );
1169 vlc_value_t val_list;
1172 var_Get( p_input, "chapter", &val );
1173 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1175 msg_rc( "Currently playing chapter %d/%d.",
1176 val.i_int, val_list.p_list->i_count );
1177 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1181 else if( !strcmp( psz_cmd, "chapter_n" ) )
1183 val.b_bool = VLC_TRUE;
1184 var_Set( p_input, "next-chapter", val );
1186 else if( !strcmp( psz_cmd, "chapter_p" ) )
1188 val.b_bool = VLC_TRUE;
1189 var_Set( p_input, "prev-chapter", val );
1191 vlc_object_release( p_input );
1194 else if( !strcmp( psz_cmd, "title" ) ||
1195 !strcmp( psz_cmd, "title_n" ) ||
1196 !strcmp( psz_cmd, "title_p" ) )
1198 if( !strcmp( psz_cmd, "title" ) )
1200 if ( *newval.psz_string )
1203 val.i_int = atoi( newval.psz_string );
1204 var_Set( p_input, "title", val );
1208 vlc_value_t val_list;
1211 var_Get( p_input, "title", &val );
1212 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1214 msg_rc( "Currently playing title %d/%d.",
1215 val.i_int, val_list.p_list->i_count );
1216 var_Change( p_this, "title", VLC_VAR_FREELIST,
1220 else if( !strcmp( psz_cmd, "title_n" ) )
1222 val.b_bool = VLC_TRUE;
1223 var_Set( p_input, "next-title", val );
1225 else if( !strcmp( psz_cmd, "title_p" ) )
1227 val.b_bool = VLC_TRUE;
1228 var_Set( p_input, "prev-title", val );
1231 vlc_object_release( p_input );
1234 else if( !strcmp( psz_cmd, "atrack" )
1235 || !strcmp( psz_cmd, "vtrack" )
1236 || !strcmp( psz_cmd, "strack" ) )
1239 vlc_value_t val_name;
1242 if( !strcmp( psz_cmd, "atrack" ) )
1244 psz_variable = "audio-es";
1246 else if( !strcmp( psz_cmd, "vtrack" ) )
1248 psz_variable = "video-es";
1252 psz_variable = "spu-es";
1255 /* Get the descriptive name of the variable */
1256 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1258 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1260 if( newval.psz_string && *newval.psz_string )
1264 val.i_int = atoi( newval.psz_string );
1266 i_error = var_Set( p_input, psz_variable, val );
1271 vlc_value_t val, text;
1274 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1276 vlc_object_release( p_input );
1277 return VLC_EGENERIC;
1279 i_value = val.i_int;
1281 if ( var_Change( p_input, psz_variable,
1282 VLC_VAR_GETLIST, &val, &text ) < 0 )
1284 vlc_object_release( p_input );
1285 return VLC_EGENERIC;
1288 msg_rc( "+----[ %s ]", val_name.psz_string );
1289 for ( i = 0; i < val.p_list->i_count; i++ )
1291 if ( i_value == val.p_list->p_values[i].i_int )
1292 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1293 text.p_list->p_values[i].psz_string );
1295 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1296 text.p_list->p_values[i].psz_string );
1298 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1300 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1302 if( val_name.psz_string ) free( val_name.psz_string );
1304 i_error = VLC_SUCCESS;
1306 vlc_object_release( p_input );
1310 /* Never reached. */
1311 vlc_object_release( p_input );
1312 return VLC_EGENERIC;
1315 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1316 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1320 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1321 playlist_t *p_playlist = pl_Yield( p_this );
1324 if( p_playlist->p_input )
1326 var_Get( p_playlist->p_input, "state", &val );
1327 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1329 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1330 vlc_object_release( p_playlist );
1332 return VLC_EGENERIC;
1337 /* Parse commands that require a playlist */
1338 if( !strcmp( psz_cmd, "prev" ) )
1340 playlist_Prev( p_playlist );
1342 else if( !strcmp( psz_cmd, "next" ) )
1344 playlist_Next( p_playlist );
1346 else if( !strcmp( psz_cmd, "play" ) )
1348 msg_Warn( p_playlist, "play" );
1349 playlist_Play( p_playlist );
1351 else if( !strcmp( psz_cmd, "repeat" ) )
1353 vlc_bool_t b_update = VLC_TRUE;
1355 var_Get( p_playlist, "repeat", &val );
1357 if( strlen( newval.psz_string ) > 0 )
1359 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1360 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1362 b_update = VLC_FALSE;
1368 val.b_bool = !val.b_bool;
1369 var_Set( p_playlist, "repeat", val );
1371 msg_rc( "Setting repeat to %d", val.b_bool );
1373 else if( !strcmp( psz_cmd, "loop" ) )
1375 vlc_bool_t b_update = VLC_TRUE;
1377 var_Get( p_playlist, "loop", &val );
1379 if( strlen( newval.psz_string ) > 0 )
1381 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1382 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1384 b_update = VLC_FALSE;
1390 val.b_bool = !val.b_bool;
1391 var_Set( p_playlist, "loop", val );
1393 msg_rc( "Setting loop to %d", val.b_bool );
1395 else if (!strcmp( psz_cmd, "goto" ) )
1397 msg_rc( _("goto is deprecated" ) );
1398 msg_Err( p_playlist, "goto is deprecated" );
1400 else if( !strcmp( psz_cmd, "stop" ) )
1402 playlist_Stop( p_playlist );
1404 else if( !strcmp( psz_cmd, "clear" ) )
1406 playlist_Stop( p_playlist );
1407 vlc_mutex_lock( &p_playlist->object_lock );
1408 playlist_Clear( p_playlist );
1409 vlc_mutex_unlock( &p_playlist->object_lock );
1411 else if( !strcmp( psz_cmd, "add" ) &&
1412 newval.psz_string && *newval.psz_string )
1414 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1418 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1419 playlist_PlaylistAddInput( p_playlist, p_item,
1420 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
1423 else if( !strcmp( psz_cmd, "enqueue" ) &&
1424 newval.psz_string && *newval.psz_string )
1426 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1430 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1431 playlist_PlaylistAddInput( p_playlist, p_item,
1432 PLAYLIST_APPEND, PLAYLIST_END );
1435 else if( !strcmp( psz_cmd, "playlist" ) )
1437 msg_Dbg( p_playlist, "Dumping category" );
1438 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1439 msg_Dbg( p_playlist, "Dumping Onelevel" );
1440 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1442 else if( !strcmp( psz_cmd, "sort" ))
1444 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1445 SORT_ARTIST, ORDER_NORMAL );
1447 else if( !strcmp( psz_cmd, "status" ) )
1449 if( p_playlist->p_input )
1451 /* Replay the current state of the system. */
1452 msg_rc( STATUS_CHANGE "( new input: %s )", p_playlist->p_input->input.p_item->psz_uri );
1453 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
1455 vlc_mutex_lock( &p_playlist->object_lock );
1456 switch( p_playlist->status.i_status )
1458 case PLAYLIST_STOPPED:
1459 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1461 case PLAYLIST_RUNNING:
1462 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1464 case PLAYLIST_PAUSED:
1465 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1468 msg_rc( STATUS_CHANGE "( state unknown )" );
1471 vlc_mutex_unlock( &p_playlist->object_lock );
1480 msg_rc( "unknown command!" );
1483 vlc_object_release( p_playlist );
1487 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1488 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1490 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1491 vlc_object_t *p_playlist;
1493 vlc_object_t *p_input;
1495 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1501 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1504 vlc_object_release( p_playlist );
1510 var_Get( p_input, "state", &val );
1511 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1513 msg_rc( _("Type 'pause' to continue.") );
1514 vlc_object_release( p_playlist );
1515 vlc_object_release( p_input );
1516 return VLC_EGENERIC;
1520 /* Parse miscellaneous commands */
1521 if( !strcmp( psz_cmd, "marq-marquee" ) )
1523 var_SetString( p_input->p_libvlc_global, "marq-marquee", newval.psz_string );
1526 if( strlen( newval.psz_string ) == 0)
1528 /* All the variable above expects strlen > 0 */
1532 static const char vars[] =
1533 "marq-x\0" "marq-y\0" "marq-position\0" "marq-color\0"
1534 "marq-opacity\0" "marq-size\0" "marq-timeout\0"
1535 "mosaic-alpha\0" "mosaic-height\0" "mosaic-width\0"
1536 "mosaic-xoffset\0" "mosaic-yoffset\0" "mosaic-align\0"
1537 "mosaic-vborder\0" "mosaic-hborder\0" "mosaic-position\0"
1538 "mosaic-rows\0" "mosaic-cols\0" "mosaic-order\0"
1539 "mosaic-offsets\0" "mosaic-keep-aspect-ratio\0"
1540 "logo-file\0" "logo-x\0" "logo-y\0" "logo-position\0"
1541 "logo-transparency\0";
1544 for (name = vars; *name; name += strlen (name) + 1)
1546 if (strcmp (name, psz_cmd) == 0)
1548 val.i_int = atoi (newval.psz_string);
1549 var_Set (p_input->p_libvlc_global, name, val);
1555 msg_rc( "Unknown command!" );
1558 vlc_object_release( p_playlist );
1559 vlc_object_release( p_input );
1563 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1564 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1566 playlist_t *p_playlist;
1568 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1571 playlist_Stop( p_playlist );
1572 vlc_object_release( p_playlist );
1574 p_this->p_libvlc->b_die = VLC_TRUE;
1578 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1579 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1581 intf_thread_t *p_newintf = NULL;
1583 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1586 p_newintf->b_block = VLC_FALSE;
1587 if( intf_RunThread( p_newintf ) )
1589 vlc_object_detach( p_newintf );
1590 intf_Destroy( p_newintf );
1597 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1598 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1600 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1601 input_thread_t *p_input = NULL;
1602 int i_error = VLC_EGENERIC;
1604 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1612 var_Get( p_input, "state", &val );
1613 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1615 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1616 vlc_object_release( p_input );
1617 return VLC_EGENERIC;
1619 vlc_object_release( p_input );
1622 if ( *newval.psz_string )
1625 audio_volume_t i_volume = atoi( newval.psz_string );
1626 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1628 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1630 i_error = VLC_EBADVAR;
1634 if( i_volume == AOUT_VOLUME_MIN )
1638 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1639 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1641 i_error = aout_VolumeSet( p_this, i_volume );
1642 osd_Volume( p_this );
1643 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1649 audio_volume_t i_volume;
1650 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1652 i_error = VLC_EGENERIC;
1656 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1657 i_error = VLC_SUCCESS;
1664 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1665 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1667 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1668 audio_volume_t i_volume;
1669 input_thread_t *p_input = NULL;
1670 int i_nb_steps = atoi(newval.psz_string);
1671 int i_error = VLC_SUCCESS;
1672 int i_volume_step = 0;
1674 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1682 var_Get( p_input, "state", &val );
1683 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1685 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1686 vlc_object_release( p_input );
1687 return VLC_EGENERIC;
1689 vlc_object_release( p_input );
1692 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1693 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1698 if ( !strcmp(psz_cmd, "volup") )
1700 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1701 i_error = VLC_EGENERIC;
1705 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1706 i_error = VLC_EGENERIC;
1708 osd_Volume( p_this );
1710 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1715 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1716 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1718 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1719 input_thread_t *p_input = NULL;
1720 vout_thread_t * p_vout;
1721 const char * psz_variable;
1722 vlc_value_t val_name;
1725 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1729 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1730 vlc_object_release( p_input );
1734 if( !strcmp( psz_cmd, "vcrop" ) )
1736 psz_variable = "crop";
1738 else if( !strcmp( psz_cmd, "vratio" ) )
1740 psz_variable = "aspect-ratio";
1742 else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1744 psz_variable = "zoom";
1748 /* Get the descriptive name of the variable */
1749 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1751 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1753 if( newval.psz_string && *newval.psz_string )
1756 if( !strcmp( psz_variable, "zoom" ) )
1759 val.f_float = atof( newval.psz_string );
1760 i_error = var_Set( p_vout, psz_variable, val );
1764 i_error = var_Set( p_vout, psz_variable, newval );
1770 vlc_value_t val, text;
1773 char *psz_value = NULL;
1775 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1777 vlc_object_release( p_vout );
1778 return VLC_EGENERIC;
1780 if( !strcmp( psz_variable, "zoom" ) )
1782 f_value = val.f_float;
1786 psz_value = strdup( val.psz_string );
1789 if ( var_Change( p_vout, psz_variable,
1790 VLC_VAR_GETLIST, &val, &text ) < 0 )
1792 vlc_object_release( p_vout );
1793 return VLC_EGENERIC;
1796 msg_rc( "+----[ %s ]", val_name.psz_string );
1797 if( !strcmp( psz_variable, "zoom" ) )
1799 for ( i = 0; i < val.p_list->i_count; i++ )
1801 if ( f_value == val.p_list->p_values[i].f_float )
1802 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1803 text.p_list->p_values[i].psz_string );
1805 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1806 text.p_list->p_values[i].psz_string );
1811 for ( i = 0; i < val.p_list->i_count; i++ )
1813 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1814 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1815 text.p_list->p_values[i].psz_string );
1817 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1818 text.p_list->p_values[i].psz_string );
1822 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1824 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1826 if( val_name.psz_string ) free( val_name.psz_string );
1828 i_error = VLC_SUCCESS;
1830 vlc_object_release( p_vout );
1834 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1835 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1837 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1838 input_thread_t *p_input = NULL;
1839 aout_instance_t * p_aout;
1840 const char * psz_variable;
1841 vlc_value_t val_name;
1844 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1852 var_Get( p_input, "state", &val );
1853 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1854 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1855 vlc_object_release( p_input );
1856 return VLC_EGENERIC;
1858 vlc_object_release( p_input );
1861 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1862 if ( p_aout == NULL ) return VLC_ENOOBJ;
1864 if ( !strcmp( psz_cmd, "adev" ) )
1866 psz_variable = "audio-device";
1870 psz_variable = "audio-channels";
1873 /* Get the descriptive name of the variable */
1874 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1876 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1878 if ( !*newval.psz_string )
1880 /* Retrieve all registered ***. */
1881 vlc_value_t val, text;
1884 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1886 vlc_object_release( (vlc_object_t *)p_aout );
1887 return VLC_EGENERIC;
1889 i_value = val.i_int;
1891 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1892 VLC_VAR_GETLIST, &val, &text ) < 0 )
1894 vlc_object_release( (vlc_object_t *)p_aout );
1895 return VLC_EGENERIC;
1898 msg_rc( "+----[ %s ]", val_name.psz_string );
1899 for ( i = 0; i < val.p_list->i_count; i++ )
1901 if ( i_value == val.p_list->p_values[i].i_int )
1902 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1903 text.p_list->p_values[i].psz_string );
1905 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1906 text.p_list->p_values[i].psz_string );
1908 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1910 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1912 if( val_name.psz_string ) free( val_name.psz_string );
1913 i_error = VLC_SUCCESS;
1918 val.i_int = atoi( newval.psz_string );
1920 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1922 vlc_object_release( (vlc_object_t *)p_aout );
1927 /* OSD menu commands */
1928 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1929 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1931 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1932 playlist_t *p_playlist = NULL;
1934 int i_error = VLC_EGENERIC;
1936 if ( !*newval.psz_string )
1938 msg_rc( _("Please provide one of the following parameters:") );
1939 msg_rc( "[on|off|up|down|left|right|select]" );
1943 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1947 if( p_playlist->p_input )
1949 var_Get( p_playlist->p_input, "state", &val );
1950 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1951 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1953 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1954 vlc_object_release( p_playlist );
1955 return VLC_EGENERIC;
1958 vlc_object_release( p_playlist );
1960 val.psz_string = strdup( newval.psz_string );
1961 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1962 osd_MenuShow( p_this );
1963 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1964 osd_MenuHide( p_this );
1965 else if( !strcmp( val.psz_string, "up" ) )
1966 osd_MenuUp( p_this );
1967 else if( !strcmp( val.psz_string, "down" ) )
1968 osd_MenuDown( p_this );
1969 else if( !strcmp( val.psz_string, "left" ) )
1970 osd_MenuPrev( p_this );
1971 else if( !strcmp( val.psz_string, "right" ) )
1972 osd_MenuNext( p_this );
1973 else if( !strcmp( val.psz_string, "select" ) )
1974 osd_MenuActivate( p_this );
1977 msg_rc( _("Please provide one of the following parameters:") );
1978 msg_rc( "[on|off|up|down|left|right|select]" );
1979 if( val.psz_string ) free( val.psz_string );
1983 i_error = VLC_SUCCESS;
1984 if( val.psz_string ) free( val.psz_string );
1989 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1991 INPUT_RECORD input_record;
1994 /* On Win32, select() only works on socket descriptors */
1995 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1996 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1998 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1999 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2002 if( input_record.EventType != KEY_EVENT ||
2003 !input_record.Event.KeyEvent.bKeyDown ||
2004 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2005 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2006 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2007 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2009 /* nothing interesting */
2013 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2015 /* Echo out the command */
2016 putc( p_buffer[ *pi_size ], stdout );
2018 /* Handle special keys */
2019 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2021 putc( '\n', stdout );
2024 switch( p_buffer[ *pi_size ] )
2030 putc( ' ', stdout );
2031 putc( '\b', stdout );
2042 if( *pi_size == MAX_LINE_LENGTH ||
2043 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2045 p_buffer[ *pi_size ] = 0;
2054 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2059 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2060 return ReadWin32( p_intf, p_buffer, pi_size );
2061 else if( p_intf->p_sys->i_socket == -1 )
2063 msleep( INTF_IDLE_SLEEP );
2068 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2069 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
2070 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2071 (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
2073 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2079 /* Connection closed */
2082 p_intf->p_sys->i_socket = -1;
2083 p_buffer[ *pi_size ] = 0;
2087 if( *pi_size == MAX_LINE_LENGTH ||
2088 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2090 p_buffer[ *pi_size ] = 0;
2097 /*****************************************************************************
2098 * parse_MRL: build a input item from a full mrl
2099 *****************************************************************************
2100 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2101 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2102 * space is a new option. Should be good enough for our purpose.
2103 *****************************************************************************/
2104 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2106 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2107 #define SKIPTRAILINGSPACE( p, d ) \
2108 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2110 input_item_t *p_item = NULL;
2111 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2112 char **ppsz_options = NULL;
2113 int i, i_options = 0;
2115 if( !psz_mrl ) return 0;
2117 psz_mrl = psz_orig = strdup( psz_mrl );
2120 SKIPSPACE( psz_mrl );
2123 for( ; *psz_mrl; psz_mrl++ )
2125 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2127 /* We have a complete item */
2130 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2131 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2133 /* We have a complete item */
2138 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2139 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2141 /* Remove '"' and '\'' if necessary */
2142 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2143 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2144 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2145 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2147 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2148 else if( *psz_item )
2151 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2152 ppsz_options[i_options - 1] = &psz_item[1];
2155 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2158 /* Now create a playlist item */
2161 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2162 for( i = 0; i < i_options; i++ )
2164 input_ItemAddOption( p_item, ppsz_options[i] );
2168 if( i_options ) free( ppsz_options );
2174 /*****************************************************************************
2175 * checkUpdates : check for updates
2176 ****************************************************************************/
2177 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2179 update_iterator_t *p_uit;
2180 update_t *p_u = update_New( p_intf );
2181 if( p_u == NULL ) return;
2182 p_uit = update_iterator_New( p_u );
2187 if( strstr( psz_arg, "newer" ) )
2188 s |= UPDATE_RELEASE_STATUS_NEWER;
2189 if( strstr( psz_arg, "equal" ) )
2190 s |= UPDATE_RELEASE_STATUS_EQUAL;
2191 if( strstr( psz_arg, "older" ) )
2192 s |= UPDATE_RELEASE_STATUS_OLDER;
2193 if( s ) p_uit->i_rs = s;
2194 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2196 if( strstr( psz_arg, "undef" ) )
2197 t |= UPDATE_FILE_TYPE_UNDEF;
2198 if( strstr( psz_arg, "info" ) )
2199 t |= UPDATE_FILE_TYPE_INFO;
2200 if( strstr( psz_arg, "source" ) )
2201 t |= UPDATE_FILE_TYPE_SOURCE;
2202 if( strstr( psz_arg, "binary" ) )
2203 t |= UPDATE_FILE_TYPE_BINARY;
2204 if( strstr( psz_arg, "plugin" ) )
2205 t |= UPDATE_FILE_TYPE_PLUGIN;
2206 if( t ) p_uit->i_t = t;
2208 update_Check( p_u, VLC_FALSE );
2209 update_iterator_Action( p_uit, UPDATE_MIRROR );
2210 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2211 p_uit->mirror.psz_name,
2212 p_uit->mirror.psz_location,
2213 p_uit->mirror.psz_type );
2214 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2217 if( s & UPDATE_RELEASE )
2219 switch( p_uit->release.i_status )
2221 case UPDATE_RELEASE_STATUS_OLDER:
2222 psz_tmp = strdup( "older" );
2224 case UPDATE_RELEASE_STATUS_EQUAL:
2225 psz_tmp = strdup( "equal" );
2227 case UPDATE_RELEASE_STATUS_NEWER:
2228 psz_tmp = strdup( "newer" );
2231 psz_tmp = strdup( "?!?" );
2234 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2235 p_uit->release.psz_version,
2236 p_uit->release.psz_svn_revision,
2240 switch( p_uit->file.i_type )
2242 case UPDATE_FILE_TYPE_UNDEF:
2243 psz_tmp = strdup( "undef" );
2245 case UPDATE_FILE_TYPE_INFO:
2246 psz_tmp = strdup( "info" );
2248 case UPDATE_FILE_TYPE_SOURCE:
2249 psz_tmp = strdup( "source" );
2251 case UPDATE_FILE_TYPE_BINARY:
2252 psz_tmp = strdup( "binary" );
2254 case UPDATE_FILE_TYPE_PLUGIN:
2255 psz_tmp = strdup( "plugin" );
2258 psz_tmp = strdup( "?!?" );
2261 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2263 if( p_uit->file.l_size )
2265 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2266 asprintf( &psz_tmp, "(%ld GB)",
2267 p_uit->file.l_size / (1024*1024*1024) );
2268 if( p_uit->file.l_size > 1024 * 1024 )
2269 asprintf( &psz_tmp, "(%ld MB)",
2270 p_uit->file.l_size / (1024*1024) );
2271 else if( p_uit->file.l_size > 1024 )
2272 asprintf( &psz_tmp, "(%ld kB)",
2273 p_uit->file.l_size / 1024 );
2275 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2279 psz_tmp = strdup( "" );
2281 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2286 update_iterator_Delete( p_uit );
2288 update_Delete( p_u );