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 OVERWRITE_TEXT N_("Over-write UNIX socket")
171 #define OVERWRITE_LONGTEXT N_("If unable to bind RC interface to the specified " \
172 " UNIX socket will attempt to unlink it then retry." )
174 #define HOST_TEXT N_("TCP command input")
175 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
176 "You can set the address and port the interface will bind to." )
179 #define QUIET_TEXT N_("Do not open a DOS command box interface")
180 #define QUIET_LONGTEXT N_( \
181 "By default the rc interface plugin will start a DOS command box. " \
182 "Enabling the quiet mode will not bring this command box but can also " \
183 "be pretty annoying when you want to stop VLC and no video window is " \
188 set_shortname( _("RC"));
189 set_category( CAT_INTERFACE );
190 set_subcategory( SUBCAT_INTERFACE_MAIN );
191 set_description( _("Remote control interface") );
192 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
194 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
196 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
197 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
198 add_bool( "rc-overwrite", 0, NULL, OVERWRITE_TEXT, OVERWRITE_LONGTEXT, VLC_TRUE );
201 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
204 set_capability( "interface", 20 );
205 set_callbacks( Activate, Deactivate );
208 /*****************************************************************************
209 * Activate: initialize and create stuff
210 *****************************************************************************/
211 static int Activate( vlc_object_t *p_this )
213 intf_thread_t *p_intf = (intf_thread_t*)p_this;
214 char *psz_host, *psz_unix_path;
215 int *pi_socket = NULL;
217 #if defined(HAVE_ISATTY) && !defined(WIN32)
218 /* Check that stdin is a TTY */
219 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
221 msg_Warn( p_intf, "fd 0 is not a TTY" );
226 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
229 int i_socket, i_overwrite;
231 i_overwrite = config_GetInt( p_intf, "rc-overwrite" );
234 #if !defined(AF_LOCAL) || defined(WIN32)
235 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
236 free( psz_unix_path );
239 struct sockaddr_un addr;
242 memset( &addr, 0, sizeof(struct sockaddr_un) );
244 msg_Dbg( p_intf, "trying UNIX socket" );
246 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
248 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
249 free( psz_unix_path );
253 addr.sun_family = AF_LOCAL;
254 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
255 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
257 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
258 sizeof(struct sockaddr_un) ) ) < 0 )
262 msg_Warn( p_intf, "Found old UNIX socket: %s, deleting and re-trying", psz_unix_path );
263 unlink( psz_unix_path );
266 if( !i_overwrite || bind( i_socket, (struct sockaddr*)&addr,
267 sizeof(struct sockaddr_un) ) < 0 )
270 msg_Warn( p_intf, "couldn't bind socket to address: %s",
272 free( psz_unix_path );
273 net_Close( i_socket );
278 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
280 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
281 free( psz_unix_path );
282 net_Close( i_socket );
286 /* FIXME: we need a core function to merge listening sockets sets */
287 pi_socket = calloc( 2, sizeof( int ) );
288 if( pi_socket == NULL )
290 free( psz_unix_path );
291 net_Close( i_socket );
294 pi_socket[0] = i_socket;
299 if( ( pi_socket == NULL ) &&
300 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
304 vlc_UrlParse( &url, psz_host, 0 );
306 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
308 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
309 if( pi_socket == NULL )
311 msg_Warn( p_intf, "can't listen to %s port %i",
312 url.psz_host, url.i_port );
313 vlc_UrlClean( &url );
318 vlc_UrlClean( &url );
322 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
325 msg_Err( p_intf, "no memory" );
329 p_intf->p_sys->pi_socket_listen = pi_socket;
330 p_intf->p_sys->i_socket = -1;
331 p_intf->p_sys->psz_unix_path = psz_unix_path;
332 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
333 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
335 /* Non-buffered stdout */
336 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
338 p_intf->pf_run = Run;
341 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
342 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
347 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
351 /*****************************************************************************
352 * Deactivate: uninitialize and cleanup
353 *****************************************************************************/
354 static void Deactivate( vlc_object_t *p_this )
356 intf_thread_t *p_intf = (intf_thread_t*)p_this;
358 net_ListenClose( p_intf->p_sys->pi_socket_listen );
359 if( p_intf->p_sys->i_socket != -1 )
360 net_Close( p_intf->p_sys->i_socket );
361 if( p_intf->p_sys->psz_unix_path != NULL )
363 #if defined(AF_LOCAL) && !defined(WIN32)
364 unlink( p_intf->p_sys->psz_unix_path );
366 free( p_intf->p_sys->psz_unix_path );
368 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
369 free( p_intf->p_sys );
372 /*****************************************************************************
373 * RegisterCallbacks: Register callbacks to dynamic variables
374 *****************************************************************************/
375 static void RegisterCallbacks( intf_thread_t *p_intf )
377 /* Register commands that will be cleaned up upon object destruction */
378 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
379 var_AddCallback( p_intf, "quit", Quit, NULL );
380 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
381 var_AddCallback( p_intf, "intf", Intf, NULL );
383 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
384 var_AddCallback( p_intf, "add", Playlist, NULL );
385 var_Create( p_intf, "repeat", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
386 var_AddCallback( p_intf, "repeat", Playlist, NULL );
387 var_Create( p_intf, "loop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
388 var_AddCallback( p_intf, "loop", Playlist, NULL );
389 var_Create( p_intf, "enqueue", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
390 var_AddCallback( p_intf, "enqueue", Playlist, NULL );
391 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
392 var_AddCallback( p_intf, "playlist", Playlist, NULL );
393 var_Create( p_intf, "sort", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
394 var_AddCallback( p_intf, "sort", Playlist, NULL );
395 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
396 var_AddCallback( p_intf, "play", Playlist, NULL );
397 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
398 var_AddCallback( p_intf, "stop", Playlist, NULL );
399 var_Create( p_intf, "clear", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
400 var_AddCallback( p_intf, "clear", Playlist, NULL );
401 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
402 var_AddCallback( p_intf, "prev", Playlist, NULL );
403 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
404 var_AddCallback( p_intf, "next", Playlist, NULL );
405 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
406 var_AddCallback( p_intf, "goto", Playlist, NULL );
407 var_Create( p_intf, "status", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
408 var_AddCallback( p_intf, "status", Playlist, NULL );
410 /* marquee on the fly items */
411 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
412 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
413 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
414 var_AddCallback( p_intf, "marq-x", Other, NULL );
415 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
416 var_AddCallback( p_intf, "marq-y", Other, NULL );
417 var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
418 var_AddCallback( p_intf, "marq-position", Other, NULL );
419 var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
420 var_AddCallback( p_intf, "marq-color", Other, NULL );
421 var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
422 var_AddCallback( p_intf, "marq-opacity", Other, NULL );
423 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
424 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
425 var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
426 var_AddCallback( p_intf, "marq-size", Other, NULL );
428 var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
429 var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
430 var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
431 var_AddCallback( p_intf, "mosaic-height", Other, NULL );
432 var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
433 var_AddCallback( p_intf, "mosaic-width", Other, NULL );
434 var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
435 var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
436 var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
437 var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
438 var_Create( p_intf, "mosaic-offsets", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
439 var_AddCallback( p_intf, "mosaic-offsets", Other, NULL );
440 var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
441 var_AddCallback( p_intf, "mosaic-align", Other, NULL );
442 var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
443 var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
444 var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
445 var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
446 var_Create( p_intf, "mosaic-position",
447 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
448 var_AddCallback( p_intf, "mosaic-position", Other, NULL );
449 var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
450 var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
451 var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
452 var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
453 var_Create( p_intf, "mosaic-order", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
454 var_AddCallback( p_intf, "mosaic-order", Other, NULL );
455 var_Create( p_intf, "mosaic-keep-aspect-ratio",
456 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
457 var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
459 /* logo on the fly items */
460 var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
461 var_AddCallback( p_intf, "logo-file", Other, NULL );
462 var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
463 var_AddCallback( p_intf, "logo-x", Other, NULL );
464 var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
465 var_AddCallback( p_intf, "logo-y", Other, NULL );
466 var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
467 var_AddCallback( p_intf, "logo-position", Other, NULL );
468 var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
469 var_AddCallback( p_intf, "logo-transparency", Other, NULL );
471 /* OSD menu commands */
472 var_Create( p_intf, "menu", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
473 var_AddCallback( p_intf, "menu", Menu, NULL );
476 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
477 var_AddCallback( p_intf, "pause", Input, NULL );
478 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
479 var_AddCallback( p_intf, "seek", Input, NULL );
480 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
481 var_AddCallback( p_intf, "title", Input, NULL );
482 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
483 var_AddCallback( p_intf, "title_n", Input, NULL );
484 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
485 var_AddCallback( p_intf, "title_p", Input, NULL );
486 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
487 var_AddCallback( p_intf, "chapter", Input, NULL );
488 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
489 var_AddCallback( p_intf, "chapter_n", Input, NULL );
490 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
491 var_AddCallback( p_intf, "chapter_p", Input, NULL );
493 var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
494 var_AddCallback( p_intf, "fastforward", Input, NULL );
495 var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
496 var_AddCallback( p_intf, "rewind", Input, NULL );
497 var_Create( p_intf, "faster", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
498 var_AddCallback( p_intf, "faster", Input, NULL );
499 var_Create( p_intf, "slower", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
500 var_AddCallback( p_intf, "slower", Input, NULL );
501 var_Create( p_intf, "normal", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
502 var_AddCallback( p_intf, "normal", Input, NULL );
504 var_Create( p_intf, "atrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
505 var_AddCallback( p_intf, "atrack", Input, NULL );
506 var_Create( p_intf, "vtrack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
507 var_AddCallback( p_intf, "vtrack", Input, NULL );
508 var_Create( p_intf, "strack", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
509 var_AddCallback( p_intf, "strack", Input, NULL );
512 var_Create( p_intf, "vratio", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
513 var_AddCallback( p_intf, "vratio", VideoConfig, NULL );
514 var_Create( p_intf, "vcrop", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
515 var_AddCallback( p_intf, "vcrop", VideoConfig, NULL );
516 var_Create( p_intf, "vzoom", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
517 var_AddCallback( p_intf, "vzoom", VideoConfig, NULL );
520 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
521 var_AddCallback( p_intf, "volume", Volume, NULL );
522 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
523 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
524 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
525 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
526 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
527 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
528 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
529 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
532 /*****************************************************************************
534 *****************************************************************************
535 * This part of the interface is in a separate thread so that we can call
536 * exec() from within it without annoying the rest of the program.
537 *****************************************************************************/
538 static void Run( intf_thread_t *p_intf )
540 input_thread_t * p_input;
541 playlist_t * p_playlist;
543 char p_buffer[ MAX_LINE_LENGTH + 1 ];
544 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
545 vlc_bool_t b_longhelp = VLC_FALSE;
555 /* Register commands that will be cleaned up upon object destruction */
556 RegisterCallbacks( p_intf );
558 /* status callbacks */
559 /* Listen to audio volume updates */
560 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
563 /* Get the file descriptor of the console input */
564 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
565 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
567 msg_Err( p_intf, "couldn't find user input handle" );
568 p_intf->b_die = VLC_TRUE;
572 while( !intf_ShouldDie( p_intf ) )
574 char *psz_cmd, *psz_arg;
575 vlc_bool_t b_complete;
577 if( p_intf->p_sys->pi_socket_listen != NULL &&
578 p_intf->p_sys->i_socket == -1 )
580 p_intf->p_sys->i_socket =
581 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
584 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
586 /* Manage the input part */
587 if( p_input == NULL )
591 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
596 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
600 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
604 /* New input has been registered */
607 if( !p_input->b_dead || !p_input->b_die )
609 msg_rc( STATUS_CHANGE "( new input: %s )", p_input->input.p_item->psz_uri );
610 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
612 var_AddCallback( p_input, "state", StateChanged, p_intf );
613 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
614 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
615 var_AddCallback( p_input, "rate", RateChanged, p_intf );
616 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
619 else if( p_input->b_dead )
621 var_DelCallback( p_input, "state", StateChanged, p_intf );
622 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
623 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
624 var_DelCallback( p_input, "rate", RateChanged, p_intf );
625 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
626 vlc_object_release( p_input );
631 vlc_mutex_lock( &p_playlist->object_lock );
632 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
633 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
634 vlc_mutex_unlock( &p_playlist->object_lock );
638 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
639 (p_playlist != NULL) )
641 vlc_mutex_lock( &p_playlist->object_lock );
642 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
643 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
645 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
646 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
648 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
649 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
651 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
652 msg_rc( STATUS_CHANGE "( play state: 1 )" );
654 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
655 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
657 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
658 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
660 vlc_mutex_unlock( &p_playlist->object_lock );
663 if( p_input && b_showpos )
665 i_newpos = 100 * var_GetFloat( p_input, "position" );
666 if( i_oldpos != i_newpos )
669 msg_rc( "pos: %d%%", i_newpos );
673 /* Is there something to do? */
674 if( !b_complete ) continue;
677 /* Skip heading spaces */
679 while( *psz_cmd == ' ' )
684 /* Split psz_cmd at the first space and make sure that
685 * psz_arg is valid */
686 psz_arg = strchr( psz_cmd, ' ' );
690 while( *psz_arg == ' ' )
700 /* If the user typed a registered local command, try it */
701 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
706 val.psz_string = psz_arg;
707 i_ret = var_Set( p_intf, psz_cmd, val );
708 msg_rc( "%s: returned %i (%s)",
709 psz_cmd, i_ret, vlc_error( i_ret ) );
711 /* Or maybe it's a global command */
712 else if( var_Type( p_intf->p_libvlc_global, psz_cmd ) & VLC_VAR_ISCOMMAND )
717 val.psz_string = psz_arg;
718 /* FIXME: it's a global command, but we should pass the
719 * local object as an argument, not p_intf->p_libvlc_global. */
720 i_ret = var_Set( p_intf->p_libvlc_global, psz_cmd, val );
723 msg_rc( "%s: returned %i (%s)",
724 psz_cmd, i_ret, vlc_error( i_ret ) );
727 else if( !strcmp( psz_cmd, "logout" ) )
729 /* Close connection */
730 if( p_intf->p_sys->i_socket != -1 )
732 net_Close( p_intf->p_sys->i_socket );
734 p_intf->p_sys->i_socket = -1;
736 else if( !strcmp( psz_cmd, "info" ) )
741 vlc_mutex_lock( &p_input->input.p_item->lock );
742 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
744 info_category_t *p_category =
745 p_input->input.p_item->pp_categories[i];
747 msg_rc( "+----[ %s ]", p_category->psz_name );
749 for ( j = 0; j < p_category->i_infos; j++ )
751 info_t *p_info = p_category->pp_infos[j];
752 msg_rc( "| %s: %s", p_info->psz_name,
757 msg_rc( "+----[ end of stream info ]" );
758 vlc_mutex_unlock( &p_input->input.p_item->lock );
762 msg_rc( "no input" );
765 else if( !strcmp( psz_cmd, "is_playing" ) )
776 else if( !strcmp( psz_cmd, "get_time" ) )
785 var_Get( p_input, "time", &time );
786 msg_rc( "%i", time.i_time / 1000000);
789 else if( !strcmp( psz_cmd, "get_length" ) )
798 var_Get( p_input, "length", &time );
799 msg_rc( "%i", time.i_time / 1000000);
802 else if( !strcmp( psz_cmd, "get_title" ) )
810 msg_rc( "%s", p_input->input.p_item->psz_name );
813 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
814 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
816 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
817 b_longhelp = VLC_TRUE;
818 else b_longhelp = VLC_FALSE;
820 Help( p_intf, b_longhelp );
822 else if( !strcmp( psz_cmd, "check-updates" ) )
824 checkUpdates( p_intf, psz_arg );
826 else switch( psz_cmd[0] )
832 vout_thread_t *p_vout;
833 p_vout = vlc_object_find( p_input,
834 VLC_OBJECT_VOUT, FIND_CHILD );
839 vlc_bool_t b_update = VLC_FALSE;
840 var_Get( p_vout, "fullscreen", &val );
841 val.b_bool = !val.b_bool;
842 if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
845 val.b_bool = VLC_TRUE;
847 else if( !strncmp(psz_arg, "off", 3) && (val.b_bool == VLC_FALSE) )
850 val.b_bool = VLC_FALSE;
852 else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
854 if( b_update ) var_Set( p_vout, "fullscreen", val );
855 vlc_object_release( p_vout );
866 /* Ignore empty lines */
870 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
874 /* Command processed */
875 i_size = 0; p_buffer[0] = 0;
878 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
879 msg_rc( STATUS_CHANGE "( quit )" );
883 var_DelCallback( p_input, "state", StateChanged, p_intf );
884 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
885 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
886 var_DelCallback( p_input, "rate", RateChanged, p_intf );
887 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
888 vlc_object_release( p_input );
894 vlc_object_release( p_playlist );
898 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
901 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
903 msg_rc(_("+----[ Remote control commands ]"));
905 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist"));
906 msg_rc(_("| enqueue XYZ . . . . . . . queue XYZ to playlist"));
907 msg_rc(_("| playlist . . . show items currently in playlist"));
908 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
909 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
910 msg_rc(_("| next . . . . . . . . . . . . next playlist item"));
911 msg_rc(_("| prev . . . . . . . . . . previous playlist item"));
912 msg_rc(_("| goto . . . . . . . . . . . . goto item at index"));
913 msg_rc(_("| repeat [on|off] . . toggle playlist item repeat"));
914 msg_rc(_("| loop [on|off] . . . . toggle playlist item loop"));
915 msg_rc(_("| clear . . . . . . . . . . . clear the playlist"));
916 msg_rc(_("| status . . . . . . . . . current playlist status"));
917 msg_rc(_("| title [X] . . . . set/get title in current item"));
918 msg_rc(_("| title_n . . . . . . next title in current item"));
919 msg_rc(_("| title_p . . . . previous title in current item"));
920 msg_rc(_("| chapter [X] . . set/get chapter in current item"));
921 msg_rc(_("| chapter_n . . . . next chapter in current item"));
922 msg_rc(_("| chapter_p . . previous chapter in current item"));
924 msg_rc(_("| seek X . seek in seconds, for instance `seek 12'"));
925 msg_rc(_("| pause . . . . . . . . . . . . . . toggle pause"));
926 msg_rc(_("| fastforward . . . . . . . set to maximum rate"));
927 msg_rc(_("| rewind . . . . . . . . . . set to minimum rate"));
928 msg_rc(_("| faster . . . . . . . . faster playing of stream"));
929 msg_rc(_("| slower . . . . . . . . slower playing of stream"));
930 msg_rc(_("| normal . . . . . . . . normal playing of stream"));
931 msg_rc(_("| f [on|off] . . . . . . . . . . toggle fullscreen"));
932 msg_rc(_("| info . . . information about the current stream"));
933 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
934 msg_rc(_("| is_playing . . 1 if a stream plays, 0 otherwise"));
935 msg_rc(_("| get_title . . . the title of the current stream"));
936 msg_rc(_("| get_length . . the length of the current stream"));
938 msg_rc(_("| volume [X] . . . . . . . . set/get audio volume"));
939 msg_rc(_("| volup [X] . . . . . raise audio volume X steps"));
940 msg_rc(_("| voldown [X] . . . . lower audio volume X steps"));
941 msg_rc(_("| adev [X] . . . . . . . . . set/get audio device"));
942 msg_rc(_("| achan [X]. . . . . . . . set/get audio channels"));
943 msg_rc(_("| atrack [X] . . . . . . . . . set/get audio track"));
944 msg_rc(_("| vtrack [X] . . . . . . . . . set/get video track"));
945 msg_rc(_("| vratio [X] . . . . . set/get video aspect ratio"));
946 msg_rc(_("| vcrop [X] . . . . . . . . . set/get video crop"));
947 msg_rc(_("| vzoom [X] . . . . . . . . . set/get video zoom"));
948 msg_rc(_("| strack [X] . . . . . . . set/get subtitles track"));
949 msg_rc(_("| menu [on|off|up|down|left|right|select] use menu"));
954 msg_rc(_("| marq-marquee STRING . . overlay STRING in video"));
955 msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left"));
956 msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top"));
957 msg_rc(_("| marq-position #. . . .relative position control"));
958 msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB"));
959 msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity"));
960 msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms"));
961 msg_rc(_("| marq-size # . . . . . . . . font size, in pixels"));
963 msg_rc(_("| logo-file STRING . . .the overlay file path/name"));
964 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
965 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
966 msg_rc(_("| logo-position #. . . . . . . . relative position"));
967 msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
969 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
970 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
971 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
972 msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
973 msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
974 msg_rc(_("| mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
975 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
976 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
977 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
978 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
979 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
980 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
981 msg_rc(_("| mosaic-order id(,id)* . . . . order of pictures "));
982 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
984 msg_rc(_("| check-updates [newer] [equal] [older]\n"
985 "| [undef] [info] [source] [binary] [plugin]"));
988 msg_rc(_("| help . . . . . . . . . . . . . this help message"));
989 msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
990 msg_rc(_("| logout . . . . . exit (if in socket connection)"));
991 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc"));
993 msg_rc(_("+----[ end of help ]"));
996 /********************************************************************
997 * Status callback routines
998 ********************************************************************/
999 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
1000 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1002 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1003 input_thread_t *p_input = NULL;
1005 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1006 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1009 msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
1010 vlc_object_release( p_input );
1012 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1016 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
1017 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1019 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1021 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1022 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
1023 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1027 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
1028 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1030 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1031 playlist_t *p_playlist = NULL;
1032 input_thread_t *p_input = NULL;
1034 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1035 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1038 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
1042 switch( p_playlist->status.i_status )
1044 case PLAYLIST_STOPPED:
1045 strncpy( &cmd[0], "stop", 4);
1048 case PLAYLIST_RUNNING:
1049 strncpy( &cmd[0], "play", 4);
1052 case PLAYLIST_PAUSED:
1053 strncpy( &cmd[0], "pause", 5);
1056 } /* var_GetInteger( p_input, "state" ) */
1057 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1058 vlc_object_release( p_playlist );
1060 vlc_object_release( p_input );
1062 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1066 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1067 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1069 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1070 input_thread_t *p_input = NULL;
1072 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1073 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1076 msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
1077 vlc_object_release( p_input );
1079 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1083 /********************************************************************
1085 ********************************************************************/
1086 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1087 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1089 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1090 input_thread_t *p_input;
1093 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1094 if( !p_input ) return VLC_ENOOBJ;
1096 var_Get( p_input, "state", &val );
1097 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1098 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1100 msg_rc( _("Press menu select or pause to continue.") );
1101 vlc_object_release( p_input );
1102 return VLC_EGENERIC;
1105 /* Parse commands that only require an input */
1106 if( !strcmp( psz_cmd, "pause" ) )
1108 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1109 var_Set( p_intf->p_libvlc, "key-pressed", val );
1110 vlc_object_release( p_input );
1113 else if( !strcmp( psz_cmd, "seek" ) )
1115 if( strlen( newval.psz_string ) > 0 &&
1116 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1118 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
1119 var_Set( p_input, "position", val );
1123 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1124 var_Set( p_input, "time", val );
1126 vlc_object_release( p_input );
1129 else if ( !strcmp( psz_cmd, "fastforward" ) )
1131 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1132 var_Set( p_intf->p_libvlc, "key-pressed", val );
1133 vlc_object_release( p_input );
1136 else if ( !strcmp( psz_cmd, "rewind" ) )
1138 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1139 var_Set( p_intf->p_libvlc, "key-pressed", val );
1140 vlc_object_release( p_input );
1143 else if ( !strcmp( psz_cmd, "faster" ) )
1145 val.b_bool = VLC_TRUE;
1146 var_Set( p_input, "rate-faster", val );
1147 vlc_object_release( p_input );
1150 else if ( !strcmp( psz_cmd, "slower" ) )
1152 val.b_bool = VLC_TRUE;
1153 var_Set( p_input, "rate-slower", val );
1154 vlc_object_release( p_input );
1157 else if ( !strcmp( psz_cmd, "normal" ) )
1159 val.i_int = INPUT_RATE_DEFAULT;
1160 var_Set( p_input, "rate", val );
1161 vlc_object_release( p_input );
1164 else if( !strcmp( psz_cmd, "chapter" ) ||
1165 !strcmp( psz_cmd, "chapter_n" ) ||
1166 !strcmp( psz_cmd, "chapter_p" ) )
1168 if( !strcmp( psz_cmd, "chapter" ) )
1170 if ( *newval.psz_string )
1173 val.i_int = atoi( newval.psz_string );
1174 var_Set( p_input, "chapter", val );
1178 vlc_value_t val_list;
1181 var_Get( p_input, "chapter", &val );
1182 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1184 msg_rc( "Currently playing chapter %d/%d.",
1185 val.i_int, val_list.p_list->i_count );
1186 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1190 else if( !strcmp( psz_cmd, "chapter_n" ) )
1192 val.b_bool = VLC_TRUE;
1193 var_Set( p_input, "next-chapter", val );
1195 else if( !strcmp( psz_cmd, "chapter_p" ) )
1197 val.b_bool = VLC_TRUE;
1198 var_Set( p_input, "prev-chapter", val );
1200 vlc_object_release( p_input );
1203 else if( !strcmp( psz_cmd, "title" ) ||
1204 !strcmp( psz_cmd, "title_n" ) ||
1205 !strcmp( psz_cmd, "title_p" ) )
1207 if( !strcmp( psz_cmd, "title" ) )
1209 if ( *newval.psz_string )
1212 val.i_int = atoi( newval.psz_string );
1213 var_Set( p_input, "title", val );
1217 vlc_value_t val_list;
1220 var_Get( p_input, "title", &val );
1221 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1223 msg_rc( "Currently playing title %d/%d.",
1224 val.i_int, val_list.p_list->i_count );
1225 var_Change( p_this, "title", VLC_VAR_FREELIST,
1229 else if( !strcmp( psz_cmd, "title_n" ) )
1231 val.b_bool = VLC_TRUE;
1232 var_Set( p_input, "next-title", val );
1234 else if( !strcmp( psz_cmd, "title_p" ) )
1236 val.b_bool = VLC_TRUE;
1237 var_Set( p_input, "prev-title", val );
1240 vlc_object_release( p_input );
1243 else if( !strcmp( psz_cmd, "atrack" )
1244 || !strcmp( psz_cmd, "vtrack" )
1245 || !strcmp( psz_cmd, "strack" ) )
1248 vlc_value_t val_name;
1251 if( !strcmp( psz_cmd, "atrack" ) )
1253 psz_variable = "audio-es";
1255 else if( !strcmp( psz_cmd, "vtrack" ) )
1257 psz_variable = "video-es";
1261 psz_variable = "spu-es";
1264 /* Get the descriptive name of the variable */
1265 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1267 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1269 if( newval.psz_string && *newval.psz_string )
1273 val.i_int = atoi( newval.psz_string );
1275 i_error = var_Set( p_input, psz_variable, val );
1280 vlc_value_t val, text;
1283 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1285 vlc_object_release( p_input );
1286 return VLC_EGENERIC;
1288 i_value = val.i_int;
1290 if ( var_Change( p_input, psz_variable,
1291 VLC_VAR_GETLIST, &val, &text ) < 0 )
1293 vlc_object_release( p_input );
1294 return VLC_EGENERIC;
1297 msg_rc( "+----[ %s ]", val_name.psz_string );
1298 for ( i = 0; i < val.p_list->i_count; i++ )
1300 if ( i_value == val.p_list->p_values[i].i_int )
1301 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1302 text.p_list->p_values[i].psz_string );
1304 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1305 text.p_list->p_values[i].psz_string );
1307 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1309 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1311 if( val_name.psz_string ) free( val_name.psz_string );
1313 i_error = VLC_SUCCESS;
1315 vlc_object_release( p_input );
1319 /* Never reached. */
1320 vlc_object_release( p_input );
1321 return VLC_EGENERIC;
1324 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1325 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1329 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1330 playlist_t *p_playlist = pl_Yield( p_this );
1333 if( p_playlist->p_input )
1335 var_Get( p_playlist->p_input, "state", &val );
1336 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1338 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1339 vlc_object_release( p_playlist );
1341 return VLC_EGENERIC;
1346 /* Parse commands that require a playlist */
1347 if( !strcmp( psz_cmd, "prev" ) )
1349 playlist_Prev( p_playlist );
1351 else if( !strcmp( psz_cmd, "next" ) )
1353 playlist_Next( p_playlist );
1355 else if( !strcmp( psz_cmd, "play" ) )
1357 msg_Warn( p_playlist, "play" );
1358 playlist_Play( p_playlist );
1360 else if( !strcmp( psz_cmd, "repeat" ) )
1362 vlc_bool_t b_update = VLC_TRUE;
1364 var_Get( p_playlist, "repeat", &val );
1366 if( strlen( newval.psz_string ) > 0 )
1368 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1369 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1371 b_update = VLC_FALSE;
1377 val.b_bool = !val.b_bool;
1378 var_Set( p_playlist, "repeat", val );
1380 msg_rc( "Setting repeat to %d", val.b_bool );
1382 else if( !strcmp( psz_cmd, "loop" ) )
1384 vlc_bool_t b_update = VLC_TRUE;
1386 var_Get( p_playlist, "loop", &val );
1388 if( strlen( newval.psz_string ) > 0 )
1390 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1391 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1393 b_update = VLC_FALSE;
1399 val.b_bool = !val.b_bool;
1400 var_Set( p_playlist, "loop", val );
1402 msg_rc( "Setting loop to %d", val.b_bool );
1404 else if (!strcmp( psz_cmd, "goto" ) )
1406 msg_rc( _("goto is deprecated" ) );
1407 msg_Err( p_playlist, "goto is deprecated" );
1409 else if( !strcmp( psz_cmd, "stop" ) )
1411 playlist_Stop( p_playlist );
1413 else if( !strcmp( psz_cmd, "clear" ) )
1415 playlist_Stop( p_playlist );
1416 vlc_mutex_lock( &p_playlist->object_lock );
1417 playlist_Clear( p_playlist );
1418 vlc_mutex_unlock( &p_playlist->object_lock );
1420 else if( !strcmp( psz_cmd, "add" ) &&
1421 newval.psz_string && *newval.psz_string )
1423 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1427 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1428 playlist_PlaylistAddInput( p_playlist, p_item,
1429 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
1432 else if( !strcmp( psz_cmd, "enqueue" ) &&
1433 newval.psz_string && *newval.psz_string )
1435 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1439 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1440 playlist_PlaylistAddInput( p_playlist, p_item,
1441 PLAYLIST_APPEND, PLAYLIST_END );
1444 else if( !strcmp( psz_cmd, "playlist" ) )
1446 msg_Dbg( p_playlist, "Dumping category" );
1447 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1448 msg_Dbg( p_playlist, "Dumping Onelevel" );
1449 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1451 else if( !strcmp( psz_cmd, "sort" ))
1453 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1454 SORT_ARTIST, ORDER_NORMAL );
1456 else if( !strcmp( psz_cmd, "status" ) )
1458 if( p_playlist->p_input )
1460 /* Replay the current state of the system. */
1461 msg_rc( STATUS_CHANGE "( new input: %s )", p_playlist->p_input->input.p_item->psz_uri );
1462 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
1464 vlc_mutex_lock( &p_playlist->object_lock );
1465 switch( p_playlist->status.i_status )
1467 case PLAYLIST_STOPPED:
1468 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1470 case PLAYLIST_RUNNING:
1471 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1473 case PLAYLIST_PAUSED:
1474 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1477 msg_rc( STATUS_CHANGE "( state unknown )" );
1480 vlc_mutex_unlock( &p_playlist->object_lock );
1489 msg_rc( "unknown command!" );
1492 vlc_object_release( p_playlist );
1496 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1497 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1499 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1500 vlc_object_t *p_playlist;
1502 vlc_object_t *p_input;
1504 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1510 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1513 vlc_object_release( p_playlist );
1519 var_Get( p_input, "state", &val );
1520 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1522 msg_rc( _("Type 'pause' to continue.") );
1523 vlc_object_release( p_playlist );
1524 vlc_object_release( p_input );
1525 return VLC_EGENERIC;
1529 /* Parse miscellaneous commands */
1530 if( !strcmp( psz_cmd, "marq-marquee" ) )
1532 if( strlen( newval.psz_string ) > 0 )
1534 val.psz_string = newval.psz_string;
1535 var_Set( p_input->p_libvlc_global, "marq-marquee", val );
1539 val.psz_string = "";
1540 var_Set( p_input->p_libvlc_global, "marq-marquee", val);
1543 else if( !strcmp( psz_cmd, "marq-x" ) )
1545 if( strlen( newval.psz_string ) > 0)
1547 val.i_int = atoi( newval.psz_string );
1548 var_Set( p_input->p_libvlc_global, "marq-x", val );
1551 else if( !strcmp( psz_cmd, "marq-y" ) )
1553 if( strlen( newval.psz_string ) > 0)
1555 val.i_int = atoi( newval.psz_string );
1556 var_Set( p_input->p_libvlc_global, "marq-y", val );
1559 else if( !strcmp( psz_cmd, "marq-position" ) )
1561 if( strlen( newval.psz_string ) > 0)
1563 val.i_int = atoi( newval.psz_string );
1564 var_Set( p_input->p_libvlc_global, "marq-position", val );
1567 else if( !strcmp( psz_cmd, "marq-color" ) )
1569 if( strlen( newval.psz_string ) > 0)
1571 val.i_int = strtol( newval.psz_string, NULL, 0 );
1572 var_Set( p_input->p_libvlc_global, "marq-color", val );
1575 else if( !strcmp( psz_cmd, "marq-opacity" ) )
1577 if( strlen( newval.psz_string ) > 0)
1579 val.i_int = strtol( newval.psz_string, NULL, 0 );
1580 var_Set( p_input->p_libvlc_global, "marq-opacity", val );
1583 else if( !strcmp( psz_cmd, "marq-size" ) )
1585 if( strlen( newval.psz_string ) > 0)
1587 val.i_int = atoi( newval.psz_string );
1588 var_Set( p_input->p_libvlc_global, "marq-size", val );
1591 else if( !strcmp( psz_cmd, "marq-timeout" ) )
1593 if( strlen( newval.psz_string ) > 0)
1595 val.i_int = atoi( newval.psz_string );
1596 var_Set( p_input, "marq-timeout", val );
1599 else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1601 if( strlen( newval.psz_string ) > 0)
1603 val.i_int = atoi( newval.psz_string );
1604 var_Set( p_input->p_libvlc_global, "mosaic-alpha", val );
1607 else if( !strcmp( psz_cmd, "mosaic-height" ) )
1609 if( strlen( newval.psz_string ) > 0)
1611 val.i_int = atoi( newval.psz_string );
1612 var_Set( p_input->p_libvlc_global, "mosaic-height", val );
1615 else if( !strcmp( psz_cmd, "mosaic-width" ) )
1617 if( strlen( newval.psz_string ) > 0)
1619 val.i_int = atoi( newval.psz_string );
1620 var_Set( p_input->p_libvlc_global, "mosaic-width", val );
1623 else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1625 if( strlen( newval.psz_string ) > 0)
1627 val.i_int = atoi( newval.psz_string );
1628 var_Set( p_input->p_libvlc_global, "mosaic-xoffset", val );
1631 else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1633 if( strlen( newval.psz_string ) > 0)
1635 val.i_int = atoi( newval.psz_string );
1636 var_Set( p_input->p_libvlc_global, "mosaic-yoffset", val );
1639 else if( !strcmp( psz_cmd, "mosaic-align" ) )
1641 if( strlen( newval.psz_string ) > 0 )
1643 val.i_int = atoi( newval.psz_string );
1644 var_Set( p_input->p_libvlc_global, "mosaic-align", val );
1647 else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1649 if( strlen( newval.psz_string ) > 0)
1651 val.i_int = atoi( newval.psz_string );
1652 var_Set( p_input->p_libvlc_global, "mosaic-vborder", val );
1655 else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1657 if( strlen( newval.psz_string ) > 0)
1659 val.i_int = atoi( newval.psz_string );
1660 var_Set( p_input->p_libvlc_global, "mosaic-hborder", val );
1663 else if( !strcmp( psz_cmd, "mosaic-position" ) )
1665 if( strlen( newval.psz_string ) > 0)
1667 val.i_int = atoi( newval.psz_string );
1668 var_Set( p_input->p_libvlc_global, "mosaic-position", val );
1671 else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1673 if( strlen( newval.psz_string ) > 0)
1675 val.i_int = atoi( newval.psz_string );
1676 var_Set( p_input->p_libvlc_global, "mosaic-rows", val );
1679 else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1681 if( strlen( newval.psz_string ) > 0)
1683 val.i_int = atoi( newval.psz_string );
1684 var_Set( p_input->p_libvlc_global, "mosaic-cols", val );
1687 else if( !strcmp( psz_cmd, "mosaic-order" ) )
1689 if( strlen( newval.psz_string ) > 0)
1691 val.psz_string = newval.psz_string;
1692 var_Set( p_input->p_libvlc_global, "mosaic-order", val );
1695 else if( !strcmp( psz_cmd, "mosaic-offsets" ) )
1697 if( strlen( newval.psz_string ) > 0)
1699 val.psz_string = newval.psz_string;
1700 var_Set( p_input->p_libvlc_global, "mosaic-offsets", val );
1703 else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1705 if( strlen( newval.psz_string ) > 0)
1707 val.i_int = atoi( newval.psz_string );
1708 var_Set( p_input->p_libvlc_global, "mosaic-keep-aspect-ratio", val );
1711 else if( !strcmp( psz_cmd, "logo-file" ) )
1713 if( strlen( newval.psz_string ) > 0 )
1715 val.psz_string = newval.psz_string;
1716 var_Set( p_input->p_libvlc_global, "logo-file", val );
1719 else if( !strcmp( psz_cmd, "logo-x" ) )
1721 if( strlen( newval.psz_string ) > 0)
1723 val.i_int = atoi( newval.psz_string );
1724 var_Set( p_input->p_libvlc_global, "logo-x", val );
1727 else if( !strcmp( psz_cmd, "logo-y" ) )
1729 if( strlen( newval.psz_string ) > 0)
1731 val.i_int = atoi( newval.psz_string );
1732 var_Set( p_input->p_libvlc_global, "logo-y", val );
1735 else if( !strcmp( psz_cmd, "logo-position" ) )
1737 if( strlen( newval.psz_string ) > 0)
1739 val.i_int = atoi( newval.psz_string );
1740 var_Set( p_input->p_libvlc_global, "logo-position", val );
1743 else if( !strcmp( psz_cmd, "logo-transparency" ) )
1745 if( strlen( newval.psz_string ) > 0)
1747 val.i_int = strtol( newval.psz_string, NULL, 0 );
1748 var_Set( p_input->p_libvlc_global, "logo-transparency", val );
1757 msg_rc( "Unknown command!" );
1760 vlc_object_release( p_playlist );
1761 vlc_object_release( p_input );
1765 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1766 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1768 playlist_t *p_playlist;
1770 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1773 playlist_Stop( p_playlist );
1774 vlc_object_release( p_playlist );
1776 p_this->p_libvlc->b_die = VLC_TRUE;
1780 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1781 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1783 intf_thread_t *p_newintf = NULL;
1785 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1788 p_newintf->b_block = VLC_FALSE;
1789 if( intf_RunThread( p_newintf ) )
1791 vlc_object_detach( p_newintf );
1792 intf_Destroy( p_newintf );
1799 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1800 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1802 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1803 input_thread_t *p_input = NULL;
1804 int i_error = VLC_EGENERIC;
1806 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1814 var_Get( p_input, "state", &val );
1815 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1817 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1818 vlc_object_release( p_input );
1819 return VLC_EGENERIC;
1821 vlc_object_release( p_input );
1824 if ( *newval.psz_string )
1827 audio_volume_t i_volume = atoi( newval.psz_string );
1828 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1830 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1832 i_error = VLC_EBADVAR;
1836 if( i_volume == AOUT_VOLUME_MIN )
1840 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1841 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1843 i_error = aout_VolumeSet( p_this, i_volume );
1844 osd_Volume( p_this );
1845 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1851 audio_volume_t i_volume;
1852 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1854 i_error = VLC_EGENERIC;
1858 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1859 i_error = VLC_SUCCESS;
1866 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1867 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1869 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1870 audio_volume_t i_volume;
1871 input_thread_t *p_input = NULL;
1872 int i_nb_steps = atoi(newval.psz_string);
1873 int i_error = VLC_SUCCESS;
1874 int i_volume_step = 0;
1876 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1884 var_Get( p_input, "state", &val );
1885 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1887 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1888 vlc_object_release( p_input );
1889 return VLC_EGENERIC;
1891 vlc_object_release( p_input );
1894 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1895 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1900 if ( !strcmp(psz_cmd, "volup") )
1902 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1903 i_error = VLC_EGENERIC;
1907 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1908 i_error = VLC_EGENERIC;
1910 osd_Volume( p_this );
1912 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1917 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1918 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1920 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1921 input_thread_t *p_input = NULL;
1922 vout_thread_t * p_vout;
1923 const char * psz_variable;
1924 vlc_value_t val_name;
1927 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1931 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1932 vlc_object_release( p_input );
1936 if( !strcmp( psz_cmd, "vcrop" ) )
1938 psz_variable = "crop";
1940 else if( !strcmp( psz_cmd, "vratio" ) )
1942 psz_variable = "aspect-ratio";
1944 else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1946 psz_variable = "zoom";
1950 /* Get the descriptive name of the variable */
1951 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1953 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1955 if( newval.psz_string && *newval.psz_string )
1958 if( !strcmp( psz_variable, "zoom" ) )
1961 val.f_float = atof( newval.psz_string );
1962 i_error = var_Set( p_vout, psz_variable, val );
1966 i_error = var_Set( p_vout, psz_variable, newval );
1972 vlc_value_t val, text;
1975 char *psz_value = NULL;
1977 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1979 vlc_object_release( p_vout );
1980 return VLC_EGENERIC;
1982 if( !strcmp( psz_variable, "zoom" ) )
1984 f_value = val.f_float;
1988 psz_value = strdup( val.psz_string );
1991 if ( var_Change( p_vout, psz_variable,
1992 VLC_VAR_GETLIST, &val, &text ) < 0 )
1994 vlc_object_release( p_vout );
1995 return VLC_EGENERIC;
1998 msg_rc( "+----[ %s ]", val_name.psz_string );
1999 if( !strcmp( psz_variable, "zoom" ) )
2001 for ( i = 0; i < val.p_list->i_count; i++ )
2003 if ( f_value == val.p_list->p_values[i].f_float )
2004 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
2005 text.p_list->p_values[i].psz_string );
2007 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
2008 text.p_list->p_values[i].psz_string );
2013 for ( i = 0; i < val.p_list->i_count; i++ )
2015 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
2016 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
2017 text.p_list->p_values[i].psz_string );
2019 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
2020 text.p_list->p_values[i].psz_string );
2024 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
2026 msg_rc( "+----[ end of %s ]", val_name.psz_string );
2028 if( val_name.psz_string ) free( val_name.psz_string );
2030 i_error = VLC_SUCCESS;
2032 vlc_object_release( p_vout );
2036 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
2037 vlc_value_t oldval, vlc_value_t newval, void *p_data )
2039 intf_thread_t *p_intf = (intf_thread_t*)p_this;
2040 input_thread_t *p_input = NULL;
2041 aout_instance_t * p_aout;
2042 const char * psz_variable;
2043 vlc_value_t val_name;
2046 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
2054 var_Get( p_input, "state", &val );
2055 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
2056 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
2057 vlc_object_release( p_input );
2058 return VLC_EGENERIC;
2060 vlc_object_release( p_input );
2063 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
2064 if ( p_aout == NULL ) return VLC_ENOOBJ;
2066 if ( !strcmp( psz_cmd, "adev" ) )
2068 psz_variable = "audio-device";
2072 psz_variable = "audio-channels";
2075 /* Get the descriptive name of the variable */
2076 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
2078 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
2080 if ( !*newval.psz_string )
2082 /* Retrieve all registered ***. */
2083 vlc_value_t val, text;
2086 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
2088 vlc_object_release( (vlc_object_t *)p_aout );
2089 return VLC_EGENERIC;
2091 i_value = val.i_int;
2093 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
2094 VLC_VAR_GETLIST, &val, &text ) < 0 )
2096 vlc_object_release( (vlc_object_t *)p_aout );
2097 return VLC_EGENERIC;
2100 msg_rc( "+----[ %s ]", val_name.psz_string );
2101 for ( i = 0; i < val.p_list->i_count; i++ )
2103 if ( i_value == val.p_list->p_values[i].i_int )
2104 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
2105 text.p_list->p_values[i].psz_string );
2107 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
2108 text.p_list->p_values[i].psz_string );
2110 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
2112 msg_rc( "+----[ end of %s ]", val_name.psz_string );
2114 if( val_name.psz_string ) free( val_name.psz_string );
2115 i_error = VLC_SUCCESS;
2120 val.i_int = atoi( newval.psz_string );
2122 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
2124 vlc_object_release( (vlc_object_t *)p_aout );
2129 /* OSD menu commands */
2130 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
2131 vlc_value_t oldval, vlc_value_t newval, void *p_data )
2133 intf_thread_t *p_intf = (intf_thread_t*)p_this;
2134 playlist_t *p_playlist = NULL;
2136 int i_error = VLC_EGENERIC;
2138 if ( !*newval.psz_string )
2140 msg_rc( _("Please provide one of the following parameters:") );
2141 msg_rc( "[on|off|up|down|left|right|select]" );
2145 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
2149 if( p_playlist->p_input )
2151 var_Get( p_playlist->p_input, "state", &val );
2152 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
2153 ( strcmp( newval.psz_string, "select" ) != 0 ) )
2155 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
2156 vlc_object_release( p_playlist );
2157 return VLC_EGENERIC;
2160 vlc_object_release( p_playlist );
2162 val.psz_string = strdup( newval.psz_string );
2163 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
2164 osd_MenuShow( p_this );
2165 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
2166 osd_MenuHide( p_this );
2167 else if( !strcmp( val.psz_string, "up" ) )
2168 osd_MenuUp( p_this );
2169 else if( !strcmp( val.psz_string, "down" ) )
2170 osd_MenuDown( p_this );
2171 else if( !strcmp( val.psz_string, "left" ) )
2172 osd_MenuPrev( p_this );
2173 else if( !strcmp( val.psz_string, "right" ) )
2174 osd_MenuNext( p_this );
2175 else if( !strcmp( val.psz_string, "select" ) )
2176 osd_MenuActivate( p_this );
2179 msg_rc( _("Please provide one of the following parameters:") );
2180 msg_rc( "[on|off|up|down|left|right|select]" );
2181 if( val.psz_string ) free( val.psz_string );
2185 i_error = VLC_SUCCESS;
2186 if( val.psz_string ) free( val.psz_string );
2191 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2193 INPUT_RECORD input_record;
2196 /* On Win32, select() only works on socket descriptors */
2197 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2198 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2200 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2201 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2204 if( input_record.EventType != KEY_EVENT ||
2205 !input_record.Event.KeyEvent.bKeyDown ||
2206 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2207 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2208 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2209 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2211 /* nothing interesting */
2215 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2217 /* Echo out the command */
2218 putc( p_buffer[ *pi_size ], stdout );
2220 /* Handle special keys */
2221 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2223 putc( '\n', stdout );
2226 switch( p_buffer[ *pi_size ] )
2232 putc( ' ', stdout );
2233 putc( '\b', stdout );
2244 if( *pi_size == MAX_LINE_LENGTH ||
2245 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2247 p_buffer[ *pi_size ] = 0;
2256 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2261 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2262 return ReadWin32( p_intf, p_buffer, pi_size );
2263 else if( p_intf->p_sys->i_socket == -1 )
2265 msleep( INTF_IDLE_SLEEP );
2270 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2271 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
2272 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2273 (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
2275 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2281 /* Connection closed */
2284 p_intf->p_sys->i_socket = -1;
2285 p_buffer[ *pi_size ] = 0;
2289 if( *pi_size == MAX_LINE_LENGTH ||
2290 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2292 p_buffer[ *pi_size ] = 0;
2299 /*****************************************************************************
2300 * parse_MRL: build a input item from a full mrl
2301 *****************************************************************************
2302 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2303 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2304 * space is a new option. Should be good enough for our purpose.
2305 *****************************************************************************/
2306 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2308 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2309 #define SKIPTRAILINGSPACE( p, d ) \
2310 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2312 input_item_t *p_item = NULL;
2313 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2314 char **ppsz_options = NULL;
2315 int i, i_options = 0;
2317 if( !psz_mrl ) return 0;
2319 psz_mrl = psz_orig = strdup( psz_mrl );
2322 SKIPSPACE( psz_mrl );
2325 for( ; *psz_mrl; psz_mrl++ )
2327 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2329 /* We have a complete item */
2332 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2333 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2335 /* We have a complete item */
2340 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2341 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2343 /* Remove '"' and '\'' if necessary */
2344 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2345 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2346 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2347 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2349 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2350 else if( *psz_item )
2353 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2354 ppsz_options[i_options - 1] = &psz_item[1];
2357 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2360 /* Now create a playlist item */
2363 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2364 for( i = 0; i < i_options; i++ )
2366 input_ItemAddOption( p_item, ppsz_options[i] );
2370 if( i_options ) free( ppsz_options );
2376 /*****************************************************************************
2377 * checkUpdates : check for updates
2378 ****************************************************************************/
2379 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2381 update_iterator_t *p_uit;
2382 update_t *p_u = update_New( p_intf );
2383 if( p_u == NULL ) return;
2384 p_uit = update_iterator_New( p_u );
2389 if( strstr( psz_arg, "newer" ) )
2390 s |= UPDATE_RELEASE_STATUS_NEWER;
2391 if( strstr( psz_arg, "equal" ) )
2392 s |= UPDATE_RELEASE_STATUS_EQUAL;
2393 if( strstr( psz_arg, "older" ) )
2394 s |= UPDATE_RELEASE_STATUS_OLDER;
2395 if( s ) p_uit->i_rs = s;
2396 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2398 if( strstr( psz_arg, "undef" ) )
2399 t |= UPDATE_FILE_TYPE_UNDEF;
2400 if( strstr( psz_arg, "info" ) )
2401 t |= UPDATE_FILE_TYPE_INFO;
2402 if( strstr( psz_arg, "source" ) )
2403 t |= UPDATE_FILE_TYPE_SOURCE;
2404 if( strstr( psz_arg, "binary" ) )
2405 t |= UPDATE_FILE_TYPE_BINARY;
2406 if( strstr( psz_arg, "plugin" ) )
2407 t |= UPDATE_FILE_TYPE_PLUGIN;
2408 if( t ) p_uit->i_t = t;
2410 update_Check( p_u, VLC_FALSE );
2411 update_iterator_Action( p_uit, UPDATE_MIRROR );
2412 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2413 p_uit->mirror.psz_name,
2414 p_uit->mirror.psz_location,
2415 p_uit->mirror.psz_type );
2416 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2419 if( s & UPDATE_RELEASE )
2421 switch( p_uit->release.i_status )
2423 case UPDATE_RELEASE_STATUS_OLDER:
2424 psz_tmp = strdup( "older" );
2426 case UPDATE_RELEASE_STATUS_EQUAL:
2427 psz_tmp = strdup( "equal" );
2429 case UPDATE_RELEASE_STATUS_NEWER:
2430 psz_tmp = strdup( "newer" );
2433 psz_tmp = strdup( "?!?" );
2436 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2437 p_uit->release.psz_version,
2438 p_uit->release.psz_svn_revision,
2442 switch( p_uit->file.i_type )
2444 case UPDATE_FILE_TYPE_UNDEF:
2445 psz_tmp = strdup( "undef" );
2447 case UPDATE_FILE_TYPE_INFO:
2448 psz_tmp = strdup( "info" );
2450 case UPDATE_FILE_TYPE_SOURCE:
2451 psz_tmp = strdup( "source" );
2453 case UPDATE_FILE_TYPE_BINARY:
2454 psz_tmp = strdup( "binary" );
2456 case UPDATE_FILE_TYPE_PLUGIN:
2457 psz_tmp = strdup( "plugin" );
2460 psz_tmp = strdup( "?!?" );
2463 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2465 if( p_uit->file.l_size )
2467 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2468 asprintf( &psz_tmp, "(%ld GB)",
2469 p_uit->file.l_size / (1024*1024*1024) );
2470 if( p_uit->file.l_size > 1024 * 1024 )
2471 asprintf( &psz_tmp, "(%ld MB)",
2472 p_uit->file.l_size / (1024*1024) );
2473 else if( p_uit->file.l_size > 1024 )
2474 asprintf( &psz_tmp, "(%ld kB)",
2475 p_uit->file.l_size / 1024 );
2477 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2481 psz_tmp = strdup( "" );
2483 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2488 update_iterator_Delete( p_uit );
2490 update_Delete( p_u );