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 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" );
226 #if !defined(AF_LOCAL) || defined(WIN32)
227 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
228 free( psz_unix_path );
231 struct sockaddr_un addr;
234 memset( &addr, 0, sizeof(struct sockaddr_un) );
236 msg_Dbg( p_intf, "trying UNIX socket" );
238 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
240 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
241 free( psz_unix_path );
245 addr.sun_family = AF_LOCAL;
246 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
247 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
249 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
250 sizeof(struct sockaddr_un) ) ) < 0 )
252 msg_Warn( p_intf, "couldn't bind socket to address: %s",
254 free( psz_unix_path );
255 net_Close( i_socket );
259 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
261 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
262 free( psz_unix_path );
263 net_Close( i_socket );
267 /* FIXME: we need a core function to merge listening sockets sets */
268 pi_socket = calloc( 2, sizeof( int ) );
269 if( pi_socket == NULL )
271 free( psz_unix_path );
272 net_Close( i_socket );
275 pi_socket[0] = i_socket;
280 if( ( pi_socket == NULL ) &&
281 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
285 vlc_UrlParse( &url, psz_host, 0 );
287 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
289 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
290 if( pi_socket == NULL )
292 msg_Warn( p_intf, "can't listen to %s port %i",
293 url.psz_host, url.i_port );
294 vlc_UrlClean( &url );
299 vlc_UrlClean( &url );
303 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
306 msg_Err( p_intf, "no memory" );
310 p_intf->p_sys->pi_socket_listen = pi_socket;
311 p_intf->p_sys->i_socket = -1;
312 p_intf->p_sys->psz_unix_path = psz_unix_path;
313 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
314 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
316 /* Non-buffered stdout */
317 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
319 p_intf->pf_run = Run;
322 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
323 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
328 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
332 /*****************************************************************************
333 * Deactivate: uninitialize and cleanup
334 *****************************************************************************/
335 static void Deactivate( vlc_object_t *p_this )
337 intf_thread_t *p_intf = (intf_thread_t*)p_this;
339 net_ListenClose( p_intf->p_sys->pi_socket_listen );
340 if( p_intf->p_sys->i_socket != -1 )
341 net_Close( p_intf->p_sys->i_socket );
342 if( p_intf->p_sys->psz_unix_path != NULL )
344 #if defined(AF_LOCAL) && !defined(WIN32)
345 unlink( p_intf->p_sys->psz_unix_path );
347 free( p_intf->p_sys->psz_unix_path );
349 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
350 free( p_intf->p_sys );
353 /*****************************************************************************
354 * RegisterCallbacks: Register callbacks to dynamic variables
355 *****************************************************************************/
356 static void RegisterCallbacks( intf_thread_t *p_intf )
358 /* Register commands that will be cleaned up upon object destruction */
359 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
360 var_AddCallback( p_intf, "quit", Quit, NULL );
361 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
362 var_AddCallback( p_intf, "intf", Intf, NULL );
364 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
365 var_AddCallback( p_intf, "add", Playlist, NULL );
366 var_Create( p_intf, "enqueue", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
367 var_AddCallback( p_intf, "enqueue", Playlist, NULL );
368 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
369 var_AddCallback( p_intf, "playlist", Playlist, NULL );
370 var_Create( p_intf, "sort", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
371 var_AddCallback( p_intf, "sort", Playlist, NULL );
372 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
373 var_AddCallback( p_intf, "play", Playlist, NULL );
374 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
375 var_AddCallback( p_intf, "stop", Playlist, NULL );
376 var_Create( p_intf, "clear", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
377 var_AddCallback( p_intf, "clear", Playlist, NULL );
378 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
379 var_AddCallback( p_intf, "prev", Playlist, NULL );
380 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
381 var_AddCallback( p_intf, "next", Playlist, NULL );
382 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
383 var_AddCallback( p_intf, "goto", Playlist, NULL );
384 var_Create( p_intf, "status", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
385 var_AddCallback( p_intf, "status", Playlist, NULL );
387 /* marquee on the fly items */
388 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
389 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
390 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
391 var_AddCallback( p_intf, "marq-x", Other, NULL );
392 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
393 var_AddCallback( p_intf, "marq-y", Other, NULL );
394 var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
395 var_AddCallback( p_intf, "marq-position", Other, NULL );
396 var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
397 var_AddCallback( p_intf, "marq-color", Other, NULL );
398 var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
399 var_AddCallback( p_intf, "marq-opacity", Other, NULL );
400 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
401 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
402 var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
403 var_AddCallback( p_intf, "marq-size", Other, NULL );
405 var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
406 var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
407 var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
408 var_AddCallback( p_intf, "mosaic-height", Other, NULL );
409 var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
410 var_AddCallback( p_intf, "mosaic-width", Other, NULL );
411 var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
412 var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
413 var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
414 var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
415 var_Create( p_intf, "mosaic-offsets", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
416 var_AddCallback( p_intf, "mosaic-offsets", 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-order", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
431 var_AddCallback( p_intf, "mosaic-order", Other, NULL );
432 var_Create( p_intf, "mosaic-keep-aspect-ratio",
433 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
434 var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
436 /* time on the fly items */
437 var_Create( p_intf, "time-format", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
438 var_AddCallback( p_intf, "time-format", Other, NULL );
439 var_Create( p_intf, "time-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
440 var_AddCallback( p_intf, "time-x", Other, NULL );
441 var_Create( p_intf, "time-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
442 var_AddCallback( p_intf, "time-y", Other, NULL );
443 var_Create( p_intf, "time-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
444 var_AddCallback( p_intf, "time-position", Other, NULL );
445 var_Create( p_intf, "time-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
446 var_AddCallback( p_intf, "time-color", Other, NULL );
447 var_Create( p_intf, "time-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
448 var_AddCallback( p_intf, "time-opacity", Other, NULL );
449 var_Create( p_intf, "time-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
450 var_AddCallback( p_intf, "time-size", Other, NULL );
452 /* logo on the fly items */
453 var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
454 var_AddCallback( p_intf, "logo-file", Other, NULL );
455 var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
456 var_AddCallback( p_intf, "logo-x", Other, NULL );
457 var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
458 var_AddCallback( p_intf, "logo-y", Other, NULL );
459 var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
460 var_AddCallback( p_intf, "logo-position", Other, NULL );
461 var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
462 var_AddCallback( p_intf, "logo-transparency", Other, NULL );
464 /* OSD menu commands */
465 var_Create( p_intf, "menu", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
466 var_AddCallback( p_intf, "menu", Menu, NULL );
469 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
470 var_AddCallback( p_intf, "pause", Input, NULL );
471 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
472 var_AddCallback( p_intf, "seek", Input, NULL );
473 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
474 var_AddCallback( p_intf, "title", Input, NULL );
475 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
476 var_AddCallback( p_intf, "title_n", Input, NULL );
477 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
478 var_AddCallback( p_intf, "title_p", Input, NULL );
479 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
480 var_AddCallback( p_intf, "chapter", Input, NULL );
481 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
482 var_AddCallback( p_intf, "chapter_n", Input, NULL );
483 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
484 var_AddCallback( p_intf, "chapter_p", Input, NULL );
486 var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
487 var_AddCallback( p_intf, "fastforward", Input, NULL );
488 var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
489 var_AddCallback( p_intf, "rewind", Input, NULL );
490 var_Create( p_intf, "faster", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
491 var_AddCallback( p_intf, "faster", Input, NULL );
492 var_Create( p_intf, "slower", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
493 var_AddCallback( p_intf, "slower", Input, NULL );
494 var_Create( p_intf, "normal", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
495 var_AddCallback( p_intf, "normal", Input, NULL );
497 var_Create( p_intf, "atrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
498 var_AddCallback( p_intf, "atrack", Input, NULL );
499 var_Create( p_intf, "vtrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
500 var_AddCallback( p_intf, "vtrack", Input, NULL );
501 var_Create( p_intf, "strack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
502 var_AddCallback( p_intf, "strack", Input, NULL );
505 var_Create( p_intf, "vratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
506 var_AddCallback( p_intf, "vratio", VideoConfig, NULL );
507 var_Create( p_intf, "vcrop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
508 var_AddCallback( p_intf, "vcrop", VideoConfig, NULL );
509 var_Create( p_intf, "vzoom", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
510 var_AddCallback( p_intf, "vzoom", VideoConfig, NULL );
513 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
514 var_AddCallback( p_intf, "volume", Volume, NULL );
515 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
516 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
517 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
518 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
519 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
520 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
521 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
522 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
525 /*****************************************************************************
527 *****************************************************************************
528 * This part of the interface is in a separate thread so that we can call
529 * exec() from within it without annoying the rest of the program.
530 *****************************************************************************/
531 static void Run( intf_thread_t *p_intf )
533 input_thread_t * p_input;
534 playlist_t * p_playlist;
536 char p_buffer[ MAX_LINE_LENGTH + 1 ];
537 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
538 vlc_bool_t b_longhelp = VLC_FALSE;
548 /* Register commands that will be cleaned up upon object destruction */
549 RegisterCallbacks( p_intf );
551 /* status callbacks */
552 /* Listen to audio volume updates */
553 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
556 /* Get the file descriptor of the console input */
557 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
558 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
560 msg_Err( p_intf, "couldn't find user input handle" );
561 p_intf->b_die = VLC_TRUE;
565 while( !intf_ShouldDie( p_intf ) )
567 char *psz_cmd, *psz_arg;
568 vlc_bool_t b_complete;
570 if( p_intf->p_sys->pi_socket_listen != NULL &&
571 p_intf->p_sys->i_socket == -1 )
573 p_intf->p_sys->i_socket =
574 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
577 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
579 /* Manage the input part */
580 if( p_input == NULL )
584 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
589 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
593 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
597 /* New input has been registered */
600 if( !p_input->b_dead || !p_input->b_die )
602 msg_rc( STATUS_CHANGE "( new input: %s )", p_input->input.p_item->psz_uri );
603 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
605 var_AddCallback( p_input, "state", StateChanged, p_intf );
606 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
607 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
608 var_AddCallback( p_input, "rate", RateChanged, p_intf );
609 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
612 else if( p_input->b_dead )
614 var_DelCallback( p_input, "state", StateChanged, p_intf );
615 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
616 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
617 var_DelCallback( p_input, "rate", RateChanged, p_intf );
618 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
619 vlc_object_release( p_input );
624 vlc_mutex_lock( &p_playlist->object_lock );
625 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
626 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
627 vlc_mutex_unlock( &p_playlist->object_lock );
631 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
632 (p_playlist != NULL) )
634 vlc_mutex_lock( &p_playlist->object_lock );
635 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
636 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
638 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
639 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
641 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
642 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
644 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
645 msg_rc( STATUS_CHANGE "( play state: 1 )" );
647 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
648 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
650 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
651 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
653 vlc_mutex_unlock( &p_playlist->object_lock );
656 if( p_input && b_showpos )
658 i_newpos = 100 * var_GetFloat( p_input, "position" );
659 if( i_oldpos != i_newpos )
662 msg_rc( "pos: %d%%", i_newpos );
666 /* Is there something to do? */
667 if( !b_complete ) continue;
670 /* Skip heading spaces */
672 while( *psz_cmd == ' ' )
677 /* Split psz_cmd at the first space and make sure that
678 * psz_arg is valid */
679 psz_arg = strchr( psz_cmd, ' ' );
683 while( *psz_arg == ' ' )
693 /* If the user typed a registered local command, try it */
694 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
699 val.psz_string = psz_arg;
700 i_ret = var_Set( p_intf, psz_cmd, val );
701 msg_rc( "%s: returned %i (%s)",
702 psz_cmd, i_ret, vlc_error( i_ret ) );
704 /* Or maybe it's a global command */
705 else if( var_Type( p_intf->p_libvlc_global, psz_cmd ) & VLC_VAR_ISCOMMAND )
710 val.psz_string = psz_arg;
711 /* FIXME: it's a global command, but we should pass the
712 * local object as an argument, not p_intf->p_libvlc_global. */
713 i_ret = var_Set( p_intf->p_libvlc_global, psz_cmd, val );
716 msg_rc( "%s: returned %i (%s)",
717 psz_cmd, i_ret, vlc_error( i_ret ) );
720 else if( !strcmp( psz_cmd, "logout" ) )
722 /* Close connection */
723 if( p_intf->p_sys->i_socket != -1 )
725 net_Close( p_intf->p_sys->i_socket );
727 p_intf->p_sys->i_socket = -1;
729 else if( !strcmp( psz_cmd, "info" ) )
734 vlc_mutex_lock( &p_input->input.p_item->lock );
735 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
737 info_category_t *p_category =
738 p_input->input.p_item->pp_categories[i];
740 msg_rc( "+----[ %s ]", p_category->psz_name );
742 for ( j = 0; j < p_category->i_infos; j++ )
744 info_t *p_info = p_category->pp_infos[j];
745 msg_rc( "| %s: %s", p_info->psz_name,
750 msg_rc( "+----[ end of stream info ]" );
751 vlc_mutex_unlock( &p_input->input.p_item->lock );
755 msg_rc( "no input" );
758 else if( !strcmp( psz_cmd, "is_playing" ) )
769 else if( !strcmp( psz_cmd, "get_time" ) )
778 var_Get( p_input, "time", &time );
779 msg_rc( "%i", time.i_time / 1000000);
782 else if( !strcmp( psz_cmd, "get_length" ) )
791 var_Get( p_input, "length", &time );
792 msg_rc( "%i", time.i_time / 1000000);
795 else if( !strcmp( psz_cmd, "get_title" ) )
803 msg_rc( "%s", p_input->input.p_item->psz_name );
806 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
807 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
809 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
810 b_longhelp = VLC_TRUE;
811 else b_longhelp = VLC_FALSE;
813 Help( p_intf, b_longhelp );
815 else if( !strcmp( psz_cmd, "check-updates" ) )
817 checkUpdates( p_intf, psz_arg );
819 else switch( psz_cmd[0] )
825 vout_thread_t *p_vout;
826 p_vout = vlc_object_find( p_input,
827 VLC_OBJECT_VOUT, FIND_CHILD );
832 vlc_bool_t b_update = VLC_FALSE;
833 var_Get( p_vout, "fullscreen", &val );
834 val.b_bool = !val.b_bool;
835 if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
838 val.b_bool = VLC_TRUE;
840 else if( !strncmp(psz_arg, "off", 3) && (val.b_bool == VLC_FALSE) )
843 val.b_bool = VLC_FALSE;
845 else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
847 if( b_update ) var_Set( p_vout, "fullscreen", val );
848 vlc_object_release( p_vout );
859 /* Ignore empty lines */
863 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
867 /* Command processed */
868 i_size = 0; p_buffer[0] = 0;
871 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
872 msg_rc( STATUS_CHANGE "( quit )" );
876 var_DelCallback( p_input, "state", StateChanged, p_intf );
877 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
878 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
879 var_DelCallback( p_input, "rate", RateChanged, p_intf );
880 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
881 vlc_object_release( p_input );
887 vlc_object_release( p_playlist );
891 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
894 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
896 msg_rc(_("+----[ Remote control commands ]"));
898 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist"));
899 msg_rc(_("| enqueue XYZ . . . . . . . queue XYZ to playlist"));
900 msg_rc(_("| playlist . . . show items currently in playlist"));
901 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
902 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
903 msg_rc(_("| next . . . . . . . . . . . . next playlist item"));
904 msg_rc(_("| prev . . . . . . . . . . previous playlist item"));
905 msg_rc(_("| goto . . . . . . . . . . . . goto item at index"));
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(_("| time-format STRING . . . overlay STRING in video"));
955 msg_rc(_("| time-x X . . . . . . . . . . . .offset from left"));
956 msg_rc(_("| time-y Y . . . . . . . . . . . . offset from top"));
957 msg_rc(_("| time-position #. . . . . . . . relative position"));
958 msg_rc(_("| time-color # . . . . . . . . . . font color, RGB"));
959 msg_rc(_("| time-opacity # . . . . . . . . . . . . . opacity"));
960 msg_rc(_("| time-size # . . . . . . . . font size, in pixels"));
962 msg_rc(_("| logo-file STRING . . .the overlay file path/name"));
963 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
964 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
965 msg_rc(_("| logo-position #. . . . . . . . relative position"));
966 msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
968 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
969 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
970 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
971 msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
972 msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
973 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
974 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
975 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
976 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
977 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
978 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
979 msg_rc(_("| mosaic-order id(,id)* . . . . order of pictures "));
980 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
982 msg_rc(_("| check-updates [newer] [equal] [older]\n"
983 "| [undef] [info] [source] [binary] [plugin]"));
986 msg_rc(_("| help . . . . . . . . . . . . . this help message"));
987 msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
988 msg_rc(_("| logout . . . . . exit (if in socket connection)"));
989 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc"));
991 msg_rc(_("+----[ end of help ]"));
994 /********************************************************************
995 * Status callback routines
996 ********************************************************************/
997 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
998 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1000 intf_thread_t *p_intf = (intf_thread_t*)p_data;
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 msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
1008 vlc_object_release( p_input );
1010 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1014 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
1015 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1017 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1019 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1020 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
1021 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1025 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
1026 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1028 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1029 playlist_t *p_playlist = NULL;
1030 input_thread_t *p_input = NULL;
1032 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1033 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1036 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
1040 switch( p_playlist->status.i_status )
1042 case PLAYLIST_STOPPED:
1043 strncpy( &cmd[0], "stop", 4);
1046 case PLAYLIST_RUNNING:
1047 strncpy( &cmd[0], "play", 4);
1050 case PLAYLIST_PAUSED:
1051 strncpy( &cmd[0], "pause", 5);
1054 } /* var_GetInteger( p_input, "state" ) */
1055 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1056 vlc_object_release( p_playlist );
1058 vlc_object_release( p_input );
1060 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1064 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1065 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1067 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1068 input_thread_t *p_input = NULL;
1070 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1071 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1074 msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
1075 vlc_object_release( p_input );
1077 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1081 /********************************************************************
1083 ********************************************************************/
1084 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1085 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1087 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1088 input_thread_t *p_input;
1091 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1092 if( !p_input ) return VLC_ENOOBJ;
1094 var_Get( p_input, "state", &val );
1095 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1096 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1098 msg_rc( _("Press menu select or pause to continue.") );
1099 vlc_object_release( p_input );
1100 return VLC_EGENERIC;
1103 /* Parse commands that only require an input */
1104 if( !strcmp( psz_cmd, "pause" ) )
1106 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1107 var_Set( p_intf->p_libvlc, "key-pressed", val );
1108 vlc_object_release( p_input );
1111 else if( !strcmp( psz_cmd, "seek" ) )
1113 if( strlen( newval.psz_string ) > 0 &&
1114 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1116 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
1117 var_Set( p_input, "position", val );
1121 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1122 var_Set( p_input, "time", val );
1124 vlc_object_release( p_input );
1127 else if ( !strcmp( psz_cmd, "fastforward" ) )
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, "rewind" ) )
1136 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1137 var_Set( p_intf->p_libvlc, "key-pressed", val );
1138 vlc_object_release( p_input );
1141 else if ( !strcmp( psz_cmd, "faster" ) )
1143 val.b_bool = VLC_TRUE;
1144 var_Set( p_input, "rate-faster", val );
1145 vlc_object_release( p_input );
1148 else if ( !strcmp( psz_cmd, "slower" ) )
1150 val.b_bool = VLC_TRUE;
1151 var_Set( p_input, "rate-slower", val );
1152 vlc_object_release( p_input );
1155 else if ( !strcmp( psz_cmd, "normal" ) )
1157 val.i_int = INPUT_RATE_DEFAULT;
1158 var_Set( p_input, "rate", val );
1159 vlc_object_release( p_input );
1162 else if( !strcmp( psz_cmd, "chapter" ) ||
1163 !strcmp( psz_cmd, "chapter_n" ) ||
1164 !strcmp( psz_cmd, "chapter_p" ) )
1166 if( !strcmp( psz_cmd, "chapter" ) )
1168 if ( *newval.psz_string )
1171 val.i_int = atoi( newval.psz_string );
1172 var_Set( p_input, "chapter", val );
1176 vlc_value_t val_list;
1179 var_Get( p_input, "chapter", &val );
1180 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1182 msg_rc( "Currently playing chapter %d/%d.",
1183 val.i_int, val_list.p_list->i_count );
1184 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1188 else if( !strcmp( psz_cmd, "chapter_n" ) )
1190 val.b_bool = VLC_TRUE;
1191 var_Set( p_input, "next-chapter", val );
1193 else if( !strcmp( psz_cmd, "chapter_p" ) )
1195 val.b_bool = VLC_TRUE;
1196 var_Set( p_input, "prev-chapter", val );
1198 vlc_object_release( p_input );
1201 else if( !strcmp( psz_cmd, "title" ) ||
1202 !strcmp( psz_cmd, "title_n" ) ||
1203 !strcmp( psz_cmd, "title_p" ) )
1205 if( !strcmp( psz_cmd, "title" ) )
1207 if ( *newval.psz_string )
1210 val.i_int = atoi( newval.psz_string );
1211 var_Set( p_input, "title", val );
1215 vlc_value_t val_list;
1218 var_Get( p_input, "title", &val );
1219 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1221 msg_rc( "Currently playing title %d/%d.",
1222 val.i_int, val_list.p_list->i_count );
1223 var_Change( p_this, "title", VLC_VAR_FREELIST,
1227 else if( !strcmp( psz_cmd, "title_n" ) )
1229 val.b_bool = VLC_TRUE;
1230 var_Set( p_input, "next-title", val );
1232 else if( !strcmp( psz_cmd, "title_p" ) )
1234 val.b_bool = VLC_TRUE;
1235 var_Set( p_input, "prev-title", val );
1238 vlc_object_release( p_input );
1241 else if( !strcmp( psz_cmd, "atrack" )
1242 || !strcmp( psz_cmd, "vtrack" )
1243 || !strcmp( psz_cmd, "strack" ) )
1246 vlc_value_t val_name;
1249 if( !strcmp( psz_cmd, "atrack" ) )
1251 psz_variable = "audio-es";
1253 else if( !strcmp( psz_cmd, "vtrack" ) )
1255 psz_variable = "video-es";
1259 psz_variable = "spu-es";
1262 /* Get the descriptive name of the variable */
1263 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1265 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1267 if( newval.psz_string && *newval.psz_string )
1271 val.i_int = atoi( newval.psz_string );
1273 i_error = var_Set( p_input, psz_variable, val );
1278 vlc_value_t val, text;
1281 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1283 vlc_object_release( p_input );
1284 return VLC_EGENERIC;
1286 i_value = val.i_int;
1288 if ( var_Change( p_input, psz_variable,
1289 VLC_VAR_GETLIST, &val, &text ) < 0 )
1291 vlc_object_release( p_input );
1292 return VLC_EGENERIC;
1295 msg_rc( "+----[ %s ]", val_name.psz_string );
1296 for ( i = 0; i < val.p_list->i_count; i++ )
1298 if ( i_value == val.p_list->p_values[i].i_int )
1299 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1300 text.p_list->p_values[i].psz_string );
1302 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1303 text.p_list->p_values[i].psz_string );
1305 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1307 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1309 if( val_name.psz_string ) free( val_name.psz_string );
1311 i_error = VLC_SUCCESS;
1313 vlc_object_release( p_input );
1317 /* Never reached. */
1318 vlc_object_release( p_input );
1319 return VLC_EGENERIC;
1322 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1323 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1325 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1326 playlist_t *p_playlist = pl_Yield( p_this );
1329 if( p_playlist->p_input )
1332 var_Get( p_playlist->p_input, "state", &val );
1333 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1335 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1336 vlc_object_release( p_playlist );
1338 return VLC_EGENERIC;
1343 /* Parse commands that require a playlist */
1344 if( !strcmp( psz_cmd, "prev" ) )
1346 playlist_Prev( p_playlist );
1348 else if( !strcmp( psz_cmd, "next" ) )
1350 playlist_Next( p_playlist );
1352 else if( !strcmp( psz_cmd, "play" ) )
1354 msg_Warn( p_playlist, "play" );
1355 playlist_Play( p_playlist );
1357 else if (!strcmp( psz_cmd, "goto" ) )
1359 msg_rc( _("goto is deprecated" ) );
1360 msg_Err( p_playlist, "goto is deprecated" );
1362 else if( !strcmp( psz_cmd, "stop" ) )
1364 playlist_Stop( p_playlist );
1366 else if( !strcmp( psz_cmd, "clear" ) )
1368 playlist_Stop( p_playlist );
1369 vlc_mutex_lock( &p_playlist->object_lock );
1370 playlist_Clear( p_playlist );
1371 vlc_mutex_unlock( &p_playlist->object_lock );
1373 else if( !strcmp( psz_cmd, "add" ) &&
1374 newval.psz_string && *newval.psz_string )
1376 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1380 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1381 playlist_PlaylistAddInput( p_playlist, p_item,
1382 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
1385 else if( !strcmp( psz_cmd, "enqueue" ) &&
1386 newval.psz_string && *newval.psz_string )
1388 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1392 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1393 playlist_PlaylistAddInput( p_playlist, p_item,
1394 PLAYLIST_APPEND, PLAYLIST_END );
1397 else if( !strcmp( psz_cmd, "playlist" ) )
1399 msg_Dbg( p_playlist, "Dumping category" );
1400 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1401 msg_Dbg( p_playlist, "Dumping Onelevel" );
1402 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1404 else if( !strcmp( psz_cmd, "sort" ))
1406 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1407 SORT_ARTIST, ORDER_NORMAL );
1409 else if( !strcmp( psz_cmd, "status" ) )
1411 if( p_playlist->p_input )
1413 /* Replay the current state of the system. */
1414 msg_rc( STATUS_CHANGE "( new input: %s )", p_playlist->p_input->input.p_item->psz_uri );
1415 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
1417 vlc_mutex_lock( &p_playlist->object_lock );
1418 switch( p_playlist->status.i_status )
1420 case PLAYLIST_STOPPED:
1421 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1423 case PLAYLIST_RUNNING:
1424 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1426 case PLAYLIST_PAUSED:
1427 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1430 msg_rc( STATUS_CHANGE "( state unknown )" );
1433 vlc_mutex_unlock( &p_playlist->object_lock );
1442 msg_rc( "unknown command!" );
1445 vlc_object_release( p_playlist );
1449 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1450 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1452 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1453 vlc_object_t *p_playlist;
1455 vlc_object_t *p_input;
1457 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1463 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1466 vlc_object_release( p_playlist );
1472 var_Get( p_input, "state", &val );
1473 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1475 msg_rc( _("Type 'pause' to continue.") );
1476 vlc_object_release( p_playlist );
1477 vlc_object_release( p_input );
1478 return VLC_EGENERIC;
1482 /* Parse miscellaneous commands */
1483 if( !strcmp( psz_cmd, "marq-marquee" ) )
1485 if( strlen( newval.psz_string ) > 0 )
1487 val.psz_string = newval.psz_string;
1488 var_Set( p_input->p_libvlc_global, "marq-marquee", val );
1492 val.psz_string = "";
1493 var_Set( p_input->p_libvlc_global, "marq-marquee", val);
1496 else if( !strcmp( psz_cmd, "marq-x" ) )
1498 if( strlen( newval.psz_string ) > 0)
1500 val.i_int = atoi( newval.psz_string );
1501 var_Set( p_input->p_libvlc_global, "marq-x", val );
1504 else if( !strcmp( psz_cmd, "marq-y" ) )
1506 if( strlen( newval.psz_string ) > 0)
1508 val.i_int = atoi( newval.psz_string );
1509 var_Set( p_input->p_libvlc_global, "marq-y", val );
1512 else if( !strcmp( psz_cmd, "marq-position" ) )
1514 if( strlen( newval.psz_string ) > 0)
1516 val.i_int = atoi( newval.psz_string );
1517 var_Set( p_input->p_libvlc_global, "marq-position", val );
1520 else if( !strcmp( psz_cmd, "marq-color" ) )
1522 if( strlen( newval.psz_string ) > 0)
1524 val.i_int = strtol( newval.psz_string, NULL, 0 );
1525 var_Set( p_input->p_libvlc_global, "marq-color", val );
1528 else if( !strcmp( psz_cmd, "marq-opacity" ) )
1530 if( strlen( newval.psz_string ) > 0)
1532 val.i_int = strtol( newval.psz_string, NULL, 0 );
1533 var_Set( p_input->p_libvlc_global, "marq-opacity", val );
1536 else if( !strcmp( psz_cmd, "marq-size" ) )
1538 if( strlen( newval.psz_string ) > 0)
1540 val.i_int = atoi( newval.psz_string );
1541 var_Set( p_input->p_libvlc_global, "marq-size", val );
1544 else if( !strcmp( psz_cmd, "marq-timeout" ) )
1546 if( strlen( newval.psz_string ) > 0)
1548 val.i_int = atoi( newval.psz_string );
1549 var_Set( p_input, "marq-timeout", val );
1552 else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1554 if( strlen( newval.psz_string ) > 0)
1556 val.i_int = atoi( newval.psz_string );
1557 var_Set( p_input->p_libvlc_global, "mosaic-alpha", val );
1560 else if( !strcmp( psz_cmd, "mosaic-height" ) )
1562 if( strlen( newval.psz_string ) > 0)
1564 val.i_int = atoi( newval.psz_string );
1565 var_Set( p_input->p_libvlc_global, "mosaic-height", val );
1568 else if( !strcmp( psz_cmd, "mosaic-width" ) )
1570 if( strlen( newval.psz_string ) > 0)
1572 val.i_int = atoi( newval.psz_string );
1573 var_Set( p_input->p_libvlc_global, "mosaic-width", val );
1576 else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1578 if( strlen( newval.psz_string ) > 0)
1580 val.i_int = atoi( newval.psz_string );
1581 var_Set( p_input->p_libvlc_global, "mosaic-xoffset", val );
1584 else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1586 if( strlen( newval.psz_string ) > 0)
1588 val.i_int = atoi( newval.psz_string );
1589 var_Set( p_input->p_libvlc_global, "mosaic-yoffset", val );
1592 else if( !strcmp( psz_cmd, "mosaic-align" ) )
1594 if( strlen( newval.psz_string ) > 0 )
1596 val.i_int = atoi( newval.psz_string );
1597 var_Set( p_input->p_libvlc_global, "mosaic-align", val );
1600 else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1602 if( strlen( newval.psz_string ) > 0)
1604 val.i_int = atoi( newval.psz_string );
1605 var_Set( p_input->p_libvlc_global, "mosaic-vborder", val );
1608 else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1610 if( strlen( newval.psz_string ) > 0)
1612 val.i_int = atoi( newval.psz_string );
1613 var_Set( p_input->p_libvlc_global, "mosaic-hborder", val );
1616 else if( !strcmp( psz_cmd, "mosaic-position" ) )
1618 if( strlen( newval.psz_string ) > 0)
1620 val.i_int = atoi( newval.psz_string );
1621 var_Set( p_input->p_libvlc_global, "mosaic-position", val );
1624 else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1626 if( strlen( newval.psz_string ) > 0)
1628 val.i_int = atoi( newval.psz_string );
1629 var_Set( p_input->p_libvlc_global, "mosaic-rows", val );
1632 else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1634 if( strlen( newval.psz_string ) > 0)
1636 val.i_int = atoi( newval.psz_string );
1637 var_Set( p_input->p_libvlc_global, "mosaic-cols", val );
1640 else if( !strcmp( psz_cmd, "mosaic-order" ) )
1642 if( strlen( newval.psz_string ) > 0)
1644 val.psz_string = newval.psz_string;
1645 var_Set( p_input->p_libvlc_global, "mosaic-order", val );
1648 else if( !strcmp( psz_cmd, "mosaic-offsets" ) )
1650 if( strlen( newval.psz_string ) > 0)
1652 val.psz_string = newval.psz_string;
1653 var_Set( p_input->p_libvlc, "mosaic-offsets", val );
1656 else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1658 if( strlen( newval.psz_string ) > 0)
1660 val.i_int = atoi( newval.psz_string );
1661 var_Set( p_input->p_libvlc_global, "mosaic-keep-aspect-ratio", val );
1664 else if( !strcmp( psz_cmd, "time-format" ) )
1666 if( strlen( newval.psz_string ) > 0 )
1668 val.psz_string = newval.psz_string;
1669 var_Set( p_input->p_libvlc_global, "time-format", val );
1673 val.psz_string = "";
1674 var_Set( p_input->p_libvlc_global, "time-format", val);
1677 else if( !strcmp( psz_cmd, "time-x" ) )
1679 if( strlen( newval.psz_string ) > 0)
1681 val.i_int = atoi( newval.psz_string );
1682 var_Set( p_input->p_libvlc_global, "time-x", val );
1685 else if( !strcmp( psz_cmd, "time-y" ) )
1687 if( strlen( newval.psz_string ) > 0)
1689 val.i_int = atoi( newval.psz_string );
1690 var_Set( p_input->p_libvlc_global, "time-y", val );
1693 else if( !strcmp( psz_cmd, "time-position" ) )
1695 if( strlen( newval.psz_string ) > 0)
1697 val.i_int = atoi( newval.psz_string );
1698 var_Set( p_input->p_libvlc_global, "time-position", val );
1701 else if( !strcmp( psz_cmd, "time-color" ) )
1703 if( strlen( newval.psz_string ) > 0)
1705 val.i_int = strtol( newval.psz_string, NULL, 0 );
1706 var_Set( p_input->p_libvlc_global, "time-color", val );
1709 else if( !strcmp( psz_cmd, "time-opacity" ) )
1711 if( strlen( newval.psz_string ) > 0)
1713 val.i_int = strtol( newval.psz_string, NULL, 0 );
1714 var_Set( p_input->p_libvlc_global, "time-opacity", val );
1717 else if( !strcmp( psz_cmd, "time-size" ) )
1719 if( strlen( newval.psz_string ) > 0)
1721 val.i_int = atoi( newval.psz_string );
1722 var_Set( p_input->p_libvlc_global, "time-size", val );
1725 else if( !strcmp( psz_cmd, "logo-file" ) )
1727 if( strlen( newval.psz_string ) > 0 )
1729 val.psz_string = newval.psz_string;
1730 var_Set( p_input->p_libvlc_global, "logo-file", val );
1733 else if( !strcmp( psz_cmd, "logo-x" ) )
1735 if( strlen( newval.psz_string ) > 0)
1737 val.i_int = atoi( newval.psz_string );
1738 var_Set( p_input->p_libvlc_global, "logo-x", val );
1741 else if( !strcmp( psz_cmd, "logo-y" ) )
1743 if( strlen( newval.psz_string ) > 0)
1745 val.i_int = atoi( newval.psz_string );
1746 var_Set( p_input->p_libvlc_global, "logo-y", val );
1749 else if( !strcmp( psz_cmd, "logo-position" ) )
1751 if( strlen( newval.psz_string ) > 0)
1753 val.i_int = atoi( newval.psz_string );
1754 var_Set( p_input->p_libvlc_global, "logo-position", val );
1757 else if( !strcmp( psz_cmd, "logo-transparency" ) )
1759 if( strlen( newval.psz_string ) > 0)
1761 val.i_int = strtol( newval.psz_string, NULL, 0 );
1762 var_Set( p_input->p_libvlc_global, "logo-transparency", val );
1771 msg_rc( "Unknown command!" );
1774 vlc_object_release( p_playlist );
1775 vlc_object_release( p_input );
1779 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1780 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1782 playlist_t *p_playlist;
1784 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1787 playlist_Stop( p_playlist );
1788 vlc_object_release( p_playlist );
1790 p_this->p_libvlc->b_die = VLC_TRUE;
1794 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1795 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1797 intf_thread_t *p_newintf = NULL;
1799 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1802 p_newintf->b_block = VLC_FALSE;
1803 if( intf_RunThread( p_newintf ) )
1805 vlc_object_detach( p_newintf );
1806 intf_Destroy( p_newintf );
1813 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1814 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1816 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1817 input_thread_t *p_input = NULL;
1818 int i_error = VLC_EGENERIC;
1820 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1828 var_Get( p_input, "state", &val );
1829 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1831 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1832 vlc_object_release( p_input );
1833 return VLC_EGENERIC;
1835 vlc_object_release( p_input );
1838 if ( *newval.psz_string )
1841 audio_volume_t i_volume = atoi( newval.psz_string );
1842 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1844 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1846 i_error = VLC_EBADVAR;
1850 if( i_volume == AOUT_VOLUME_MIN )
1854 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1855 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1857 i_error = aout_VolumeSet( p_this, i_volume );
1858 osd_Volume( p_this );
1859 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1865 audio_volume_t i_volume;
1866 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1868 i_error = VLC_EGENERIC;
1872 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1873 i_error = VLC_SUCCESS;
1880 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1881 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1883 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1884 audio_volume_t i_volume;
1885 input_thread_t *p_input = NULL;
1886 int i_nb_steps = atoi(newval.psz_string);
1887 int i_error = VLC_SUCCESS;
1888 int i_volume_step = 0;
1890 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1898 var_Get( p_input, "state", &val );
1899 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1901 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1902 vlc_object_release( p_input );
1903 return VLC_EGENERIC;
1905 vlc_object_release( p_input );
1908 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1909 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1914 if ( !strcmp(psz_cmd, "volup") )
1916 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1917 i_error = VLC_EGENERIC;
1921 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1922 i_error = VLC_EGENERIC;
1924 osd_Volume( p_this );
1926 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1931 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1932 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1934 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1935 input_thread_t *p_input = NULL;
1936 vout_thread_t * p_vout;
1937 const char * psz_variable;
1938 vlc_value_t val_name;
1941 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1945 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1946 vlc_object_release( p_input );
1950 if( !strcmp( psz_cmd, "vcrop" ) )
1952 psz_variable = "crop";
1954 else if( !strcmp( psz_cmd, "vratio" ) )
1956 psz_variable = "aspect-ratio";
1958 else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1960 psz_variable = "zoom";
1964 /* Get the descriptive name of the variable */
1965 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1967 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1969 if( newval.psz_string && *newval.psz_string )
1972 if( !strcmp( psz_variable, "zoom" ) )
1975 val.f_float = atof( newval.psz_string );
1976 i_error = var_Set( p_vout, psz_variable, val );
1980 i_error = var_Set( p_vout, psz_variable, newval );
1986 vlc_value_t val, text;
1989 char *psz_value = NULL;
1991 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1993 vlc_object_release( p_vout );
1994 return VLC_EGENERIC;
1996 if( !strcmp( psz_variable, "zoom" ) )
1998 f_value = val.f_float;
2002 psz_value = strdup( val.psz_string );
2005 if ( var_Change( p_vout, psz_variable,
2006 VLC_VAR_GETLIST, &val, &text ) < 0 )
2008 vlc_object_release( p_vout );
2009 return VLC_EGENERIC;
2012 msg_rc( "+----[ %s ]", val_name.psz_string );
2013 if( !strcmp( psz_variable, "zoom" ) )
2015 for ( i = 0; i < val.p_list->i_count; i++ )
2017 if ( f_value == val.p_list->p_values[i].f_float )
2018 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
2019 text.p_list->p_values[i].psz_string );
2021 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
2022 text.p_list->p_values[i].psz_string );
2027 for ( i = 0; i < val.p_list->i_count; i++ )
2029 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
2030 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
2031 text.p_list->p_values[i].psz_string );
2033 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
2034 text.p_list->p_values[i].psz_string );
2038 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
2040 msg_rc( "+----[ end of %s ]", val_name.psz_string );
2042 if( val_name.psz_string ) free( val_name.psz_string );
2044 i_error = VLC_SUCCESS;
2046 vlc_object_release( p_vout );
2050 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
2051 vlc_value_t oldval, vlc_value_t newval, void *p_data )
2053 intf_thread_t *p_intf = (intf_thread_t*)p_this;
2054 input_thread_t *p_input = NULL;
2055 aout_instance_t * p_aout;
2056 const char * psz_variable;
2057 vlc_value_t val_name;
2060 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
2068 var_Get( p_input, "state", &val );
2069 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
2070 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
2071 vlc_object_release( p_input );
2072 return VLC_EGENERIC;
2074 vlc_object_release( p_input );
2077 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
2078 if ( p_aout == NULL ) return VLC_ENOOBJ;
2080 if ( !strcmp( psz_cmd, "adev" ) )
2082 psz_variable = "audio-device";
2086 psz_variable = "audio-channels";
2089 /* Get the descriptive name of the variable */
2090 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
2092 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
2094 if ( !*newval.psz_string )
2096 /* Retrieve all registered ***. */
2097 vlc_value_t val, text;
2100 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
2102 vlc_object_release( (vlc_object_t *)p_aout );
2103 return VLC_EGENERIC;
2105 i_value = val.i_int;
2107 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
2108 VLC_VAR_GETLIST, &val, &text ) < 0 )
2110 vlc_object_release( (vlc_object_t *)p_aout );
2111 return VLC_EGENERIC;
2114 msg_rc( "+----[ %s ]", val_name.psz_string );
2115 for ( i = 0; i < val.p_list->i_count; i++ )
2117 if ( i_value == val.p_list->p_values[i].i_int )
2118 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
2119 text.p_list->p_values[i].psz_string );
2121 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
2122 text.p_list->p_values[i].psz_string );
2124 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
2126 msg_rc( "+----[ end of %s ]", val_name.psz_string );
2128 if( val_name.psz_string ) free( val_name.psz_string );
2129 i_error = VLC_SUCCESS;
2134 val.i_int = atoi( newval.psz_string );
2136 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
2138 vlc_object_release( (vlc_object_t *)p_aout );
2143 /* OSD menu commands */
2144 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
2145 vlc_value_t oldval, vlc_value_t newval, void *p_data )
2147 intf_thread_t *p_intf = (intf_thread_t*)p_this;
2148 playlist_t *p_playlist = NULL;
2150 int i_error = VLC_EGENERIC;
2152 if ( !*newval.psz_string )
2154 msg_rc( _("Please provide one of the following parameters:") );
2155 msg_rc( "[on|off|up|down|left|right|select]" );
2159 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
2163 if( p_playlist->p_input )
2165 var_Get( p_playlist->p_input, "state", &val );
2166 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
2167 ( strcmp( newval.psz_string, "select" ) != 0 ) )
2169 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
2170 vlc_object_release( p_playlist );
2171 return VLC_EGENERIC;
2174 vlc_object_release( p_playlist );
2176 val.psz_string = strdup( newval.psz_string );
2177 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
2178 osd_MenuShow( p_this );
2179 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
2180 osd_MenuHide( p_this );
2181 else if( !strcmp( val.psz_string, "up" ) )
2182 osd_MenuUp( p_this );
2183 else if( !strcmp( val.psz_string, "down" ) )
2184 osd_MenuDown( p_this );
2185 else if( !strcmp( val.psz_string, "left" ) )
2186 osd_MenuPrev( p_this );
2187 else if( !strcmp( val.psz_string, "right" ) )
2188 osd_MenuNext( p_this );
2189 else if( !strcmp( val.psz_string, "select" ) )
2190 osd_MenuActivate( p_this );
2193 msg_rc( _("Please provide one of the following parameters:") );
2194 msg_rc( "[on|off|up|down|left|right|select]" );
2195 if( val.psz_string ) free( val.psz_string );
2199 i_error = VLC_SUCCESS;
2200 if( val.psz_string ) free( val.psz_string );
2205 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2207 INPUT_RECORD input_record;
2210 /* On Win32, select() only works on socket descriptors */
2211 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2212 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2214 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2215 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2218 if( input_record.EventType != KEY_EVENT ||
2219 !input_record.Event.KeyEvent.bKeyDown ||
2220 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2221 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2222 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2223 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2225 /* nothing interesting */
2229 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2231 /* Echo out the command */
2232 putc( p_buffer[ *pi_size ], stdout );
2234 /* Handle special keys */
2235 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2237 putc( '\n', stdout );
2240 switch( p_buffer[ *pi_size ] )
2246 putc( ' ', stdout );
2247 putc( '\b', stdout );
2258 if( *pi_size == MAX_LINE_LENGTH ||
2259 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2261 p_buffer[ *pi_size ] = 0;
2270 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2275 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2276 return ReadWin32( p_intf, p_buffer, pi_size );
2277 else if( p_intf->p_sys->i_socket == -1 )
2279 msleep( INTF_IDLE_SLEEP );
2284 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2285 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
2286 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2287 (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
2289 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2295 /* Connection closed */
2298 p_intf->p_sys->i_socket = -1;
2299 p_buffer[ *pi_size ] = 0;
2303 if( *pi_size == MAX_LINE_LENGTH ||
2304 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2306 p_buffer[ *pi_size ] = 0;
2313 /*****************************************************************************
2314 * parse_MRL: build a input item from a full mrl
2315 *****************************************************************************
2316 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2317 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2318 * space is a new option. Should be good enough for our purpose.
2319 *****************************************************************************/
2320 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2322 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2323 #define SKIPTRAILINGSPACE( p, d ) \
2324 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2326 input_item_t *p_item = NULL;
2327 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2328 char **ppsz_options = NULL;
2329 int i, i_options = 0;
2331 if( !psz_mrl ) return 0;
2333 psz_mrl = psz_orig = strdup( psz_mrl );
2336 SKIPSPACE( psz_mrl );
2339 for( ; *psz_mrl; psz_mrl++ )
2341 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2343 /* We have a complete item */
2346 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2347 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2349 /* We have a complete item */
2354 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2355 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2357 /* Remove '"' and '\'' if necessary */
2358 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2359 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2360 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2361 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2363 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2364 else if( *psz_item )
2367 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2368 ppsz_options[i_options - 1] = &psz_item[1];
2371 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2374 /* Now create a playlist item */
2377 p_item = input_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
2378 for( i = 0; i < i_options; i++ )
2380 input_ItemAddOption( p_item, ppsz_options[i] );
2384 if( i_options ) free( ppsz_options );
2390 /*****************************************************************************
2391 * checkUpdates : check for updates
2392 ****************************************************************************/
2393 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2395 update_iterator_t *p_uit;
2396 update_t *p_u = update_New( p_intf );
2397 if( p_u == NULL ) return;
2398 p_uit = update_iterator_New( p_u );
2403 if( strstr( psz_arg, "newer" ) )
2404 s |= UPDATE_RELEASE_STATUS_NEWER;
2405 if( strstr( psz_arg, "equal" ) )
2406 s |= UPDATE_RELEASE_STATUS_EQUAL;
2407 if( strstr( psz_arg, "older" ) )
2408 s |= UPDATE_RELEASE_STATUS_OLDER;
2409 if( s ) p_uit->i_rs = s;
2410 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2412 if( strstr( psz_arg, "undef" ) )
2413 t |= UPDATE_FILE_TYPE_UNDEF;
2414 if( strstr( psz_arg, "info" ) )
2415 t |= UPDATE_FILE_TYPE_INFO;
2416 if( strstr( psz_arg, "source" ) )
2417 t |= UPDATE_FILE_TYPE_SOURCE;
2418 if( strstr( psz_arg, "binary" ) )
2419 t |= UPDATE_FILE_TYPE_BINARY;
2420 if( strstr( psz_arg, "plugin" ) )
2421 t |= UPDATE_FILE_TYPE_PLUGIN;
2422 if( t ) p_uit->i_t = t;
2424 update_Check( p_u, VLC_FALSE );
2425 update_iterator_Action( p_uit, UPDATE_MIRROR );
2426 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2427 p_uit->mirror.psz_name,
2428 p_uit->mirror.psz_location,
2429 p_uit->mirror.psz_type );
2430 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2433 if( s & UPDATE_RELEASE )
2435 switch( p_uit->release.i_status )
2437 case UPDATE_RELEASE_STATUS_OLDER:
2438 psz_tmp = strdup( "older" );
2440 case UPDATE_RELEASE_STATUS_EQUAL:
2441 psz_tmp = strdup( "equal" );
2443 case UPDATE_RELEASE_STATUS_NEWER:
2444 psz_tmp = strdup( "newer" );
2447 psz_tmp = strdup( "?!?" );
2450 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2451 p_uit->release.psz_version,
2452 p_uit->release.psz_svn_revision,
2456 switch( p_uit->file.i_type )
2458 case UPDATE_FILE_TYPE_UNDEF:
2459 psz_tmp = strdup( "undef" );
2461 case UPDATE_FILE_TYPE_INFO:
2462 psz_tmp = strdup( "info" );
2464 case UPDATE_FILE_TYPE_SOURCE:
2465 psz_tmp = strdup( "source" );
2467 case UPDATE_FILE_TYPE_BINARY:
2468 psz_tmp = strdup( "binary" );
2470 case UPDATE_FILE_TYPE_PLUGIN:
2471 psz_tmp = strdup( "plugin" );
2474 psz_tmp = strdup( "?!?" );
2477 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2479 if( p_uit->file.l_size )
2481 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2482 asprintf( &psz_tmp, "(%ld GB)",
2483 p_uit->file.l_size / (1024*1024*1024) );
2484 if( p_uit->file.l_size > 1024 * 1024 )
2485 asprintf( &psz_tmp, "(%ld MB)",
2486 p_uit->file.l_size / (1024*1024) );
2487 else if( p_uit->file.l_size > 1024 )
2488 asprintf( &psz_tmp, "(%ld kB)",
2489 p_uit->file.l_size / 1024 );
2491 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2495 psz_tmp = strdup( "" );
2497 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2502 update_iterator_Delete( p_uit );
2504 update_Delete( p_u );