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 */
38 #include <vlc_interface.h>
42 #include <vlc_playlist.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_network.h>
57 #include <vlc_charset.h>
59 #if defined(AF_UNIX) && !defined(AF_LOCAL)
60 # define AF_LOCAL AF_UNIX
63 #if defined(AF_LOCAL) && ! defined(WIN32)
67 #define MAX_LINE_LENGTH 256
68 #define STATUS_CHANGE "status change: "
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Activate ( vlc_object_t * );
74 static void Deactivate ( vlc_object_t * );
75 static void Run ( intf_thread_t * );
77 static void Help ( intf_thread_t *, vlc_bool_t );
78 static void RegisterCallbacks( intf_thread_t * );
80 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
82 static input_item_t *parse_MRL( intf_thread_t *, char * );
84 static int Input ( vlc_object_t *, char const *,
85 vlc_value_t, vlc_value_t, void * );
86 static int Playlist ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
88 static int Other ( vlc_object_t *, char const *,
89 vlc_value_t, vlc_value_t, void * );
90 static int Quit ( vlc_object_t *, char const *,
91 vlc_value_t, vlc_value_t, void * );
92 static int Intf ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int Volume ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
96 static int VolumeMove ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
98 static int VideoConfig ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int AudioConfig ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int Menu ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg );
106 /* Status Callbacks */
107 static int TimeOffsetChanged( vlc_object_t *, char const *,
108 vlc_value_t, vlc_value_t , void * );
109 static int VolumeChanged ( vlc_object_t *, char const *,
110 vlc_value_t, vlc_value_t, void * );
111 static int StateChanged ( vlc_object_t *, char const *,
112 vlc_value_t, vlc_value_t, void * );
113 static int RateChanged ( vlc_object_t *, char const *,
114 vlc_value_t, vlc_value_t, void * );
118 int *pi_socket_listen;
123 vlc_mutex_t status_lock;
124 playlist_status_t i_last_state;
132 #ifdef HAVE_VARIADIC_MACROS
133 # define msg_rc( psz_format, args... ) \
134 __msg_rc( p_intf, psz_format, ## args )
137 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
140 va_start( args, psz_fmt );
142 if( p_intf->p_sys->i_socket == -1 )
144 utf8_vfprintf( stdout, psz_fmt, args );
149 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
150 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
155 /*****************************************************************************
157 *****************************************************************************/
158 #define POS_TEXT N_("Show stream position")
159 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
160 "stream from time to time." )
162 #define TTY_TEXT N_("Fake TTY")
163 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
165 #define UNIX_TEXT N_("UNIX socket command input")
166 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
169 #define HOST_TEXT N_("TCP command input")
170 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
171 "You can set the address and port the interface will bind to." )
174 #define QUIET_TEXT N_("Do not open a DOS command box interface")
175 #define QUIET_LONGTEXT N_( \
176 "By default the rc interface plugin will start a DOS command box. " \
177 "Enabling the quiet mode will not bring this command box but can also " \
178 "be pretty annoying when you want to stop VLC and no video window is " \
183 set_shortname( _("RC"));
184 set_category( CAT_INTERFACE );
185 set_subcategory( SUBCAT_INTERFACE_MAIN );
186 set_description( _("Remote control interface") );
187 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
189 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
191 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
192 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
195 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
198 set_capability( "interface", 20 );
199 set_callbacks( Activate, Deactivate );
202 /*****************************************************************************
203 * Activate: initialize and create stuff
204 *****************************************************************************/
205 static int Activate( vlc_object_t *p_this )
207 intf_thread_t *p_intf = (intf_thread_t*)p_this;
208 char *psz_host, *psz_unix_path;
209 int *pi_socket = NULL;
211 #if defined(HAVE_ISATTY) && !defined(WIN32)
212 /* Check that stdin is a TTY */
213 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
215 msg_Warn( p_intf, "fd 0 is not a TTY" );
220 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
223 int i_socket, i_overwrite;
225 i_overwrite = config_GetInt( p_intf, "rc-overwrite" );
227 #if !defined(AF_LOCAL) || defined(WIN32)
228 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
229 free( psz_unix_path );
232 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 (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
250 && (errno == EADDRINUSE)
251 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
252 && (errno == ECONNREFUSED))
254 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
255 unlink (psz_unix_path);
257 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
259 msg_Err (p_intf, "cannot bind UNIX socket at %s: %s",
260 psz_unix_path, strerror (errno));
261 free (psz_unix_path);
262 net_Close (i_socket);
267 if( listen( i_socket, 1 ) )
269 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
270 free( psz_unix_path );
271 net_Close( i_socket );
275 /* FIXME: we need a core function to merge listening sockets sets */
276 pi_socket = calloc( 2, sizeof( int ) );
277 if( pi_socket == NULL )
279 free( psz_unix_path );
280 net_Close( i_socket );
283 pi_socket[0] = i_socket;
288 if( ( pi_socket == NULL ) &&
289 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
293 vlc_UrlParse( &url, psz_host, 0 );
295 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
297 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
298 if( pi_socket == NULL )
300 msg_Warn( p_intf, "can't listen to %s port %i",
301 url.psz_host, url.i_port );
302 vlc_UrlClean( &url );
307 vlc_UrlClean( &url );
311 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
314 msg_Err( p_intf, "no memory" );
318 p_intf->p_sys->pi_socket_listen = pi_socket;
319 p_intf->p_sys->i_socket = -1;
320 p_intf->p_sys->psz_unix_path = psz_unix_path;
321 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
322 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
324 /* Non-buffered stdout */
325 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
327 p_intf->pf_run = Run;
330 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
331 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
336 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
340 /*****************************************************************************
341 * Deactivate: uninitialize and cleanup
342 *****************************************************************************/
343 static void Deactivate( vlc_object_t *p_this )
345 intf_thread_t *p_intf = (intf_thread_t*)p_this;
347 net_ListenClose( p_intf->p_sys->pi_socket_listen );
348 if( p_intf->p_sys->i_socket != -1 )
349 net_Close( p_intf->p_sys->i_socket );
350 if( p_intf->p_sys->psz_unix_path != NULL )
352 #if defined(AF_LOCAL) && !defined(WIN32)
353 unlink( p_intf->p_sys->psz_unix_path );
355 free( p_intf->p_sys->psz_unix_path );
357 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
358 free( p_intf->p_sys );
361 /*****************************************************************************
362 * RegisterCallbacks: Register callbacks to dynamic variables
363 *****************************************************************************/
364 static void RegisterCallbacks( intf_thread_t *p_intf )
366 /* Register commands that will be cleaned up upon object destruction */
367 #define ADD( name, type, target ) \
368 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
369 var_AddCallback( p_intf, name, target, NULL );
370 ADD( "quit", VOID, Quit )
371 ADD( "intf", STRING, Intf )
373 ADD( "add", STRING, Playlist )
374 ADD( "repeat", STRING, Playlist )
375 ADD( "loop", STRING, Playlist )
376 ADD( "enqueue", STRING, Playlist )
377 ADD( "playlist", VOID, Playlist )
378 ADD( "sort", VOID, Playlist )
379 ADD( "play", VOID, Playlist )
380 ADD( "stop", VOID, Playlist )
381 ADD( "clear", VOID, Playlist )
382 ADD( "prev", VOID, Playlist )
383 ADD( "next", VOID, Playlist )
384 ADD( "goto", INTEGER, Playlist )
385 ADD( "status", INTEGER, Playlist )
387 /* marquee on the fly items */
388 ADD( "marq-marquee", STRING, Other )
389 ADD( "marq-x", INTEGER, Other )
390 ADD( "marq-y", INTEGER, Other )
391 ADD( "marq-position", INTEGER, Other )
392 ADD( "marq-color", INTEGER, Other )
393 ADD( "marq-opacity", INTEGER, Other )
394 ADD( "marq-timeout", INTEGER, Other )
395 ADD( "marq-size", INTEGER, Other )
397 ADD( "mosaic-alpha", INTEGER, Other )
398 ADD( "mosaic-height", INTEGER, Other )
399 ADD( "mosaic-width", INTEGER, Other )
400 ADD( "mosaic-xoffset", INTEGER, Other )
401 ADD( "mosaic-yoffset", INTEGER, Other )
402 ADD( "mosaic-offsets", STRING, Other )
403 ADD( "mosaic-align", INTEGER, Other )
404 ADD( "mosaic-vborder", INTEGER, Other )
405 ADD( "mosaic-hborder", INTEGER, Other )
406 ADD( "mosaic-position", INTEGER, Other )
407 ADD( "mosaic-rows", INTEGER, Other )
408 ADD( "mosaic-cols", INTEGER, Other )
409 ADD( "mosaic-order", STRING, Other )
410 ADD( "mosaic-keep-aspect-ratio", INTEGER, Other )
412 /* logo on the fly items */
413 ADD( "logo-file", STRING, Other )
414 ADD( "logo-x", INTEGER, Other )
415 ADD( "logo-y", INTEGER, Other )
416 ADD( "logo-position", INTEGER, Other )
417 ADD( "logo-transparency", INTEGER, Other )
419 /* OSD menu commands */
420 ADD( "menu", STRING, Menu )
423 ADD( "pause", VOID, Input )
424 ADD( "seek", INTEGER, Input )
425 ADD( "title", STRING, Input )
426 ADD( "title_n", VOID, Input )
427 ADD( "title_p", VOID, Input )
428 ADD( "chapter", STRING, Input )
429 ADD( "chapter_n", VOID, Input )
430 ADD( "chapter_p", VOID, Input )
432 ADD( "fastforward", VOID, Input )
433 ADD( "rewind", VOID, Input )
434 ADD( "faster", VOID, Input )
435 ADD( "slower", VOID, Input )
436 ADD( "normal", VOID, Input )
438 ADD( "atrack", STRING, Input )
439 ADD( "vtrack", STRING, Input )
440 ADD( "strack", STRING, Input )
443 ADD( "vratio", STRING, VideoConfig )
444 ADD( "vcrop", STRING, VideoConfig )
445 ADD( "vzoom", STRING, VideoConfig )
448 ADD( "volume", STRING, Volume )
449 ADD( "volup", STRING, VolumeMove )
450 ADD( "voldown", STRING, VolumeMove )
451 ADD( "adev", STRING, AudioConfig )
452 ADD( "achan", STRING, AudioConfig )
457 /*****************************************************************************
459 *****************************************************************************
460 * This part of the interface is in a separate thread so that we can call
461 * exec() from within it without annoying the rest of the program.
462 *****************************************************************************/
463 static void Run( intf_thread_t *p_intf )
465 input_thread_t * p_input;
466 playlist_t * p_playlist;
468 char p_buffer[ MAX_LINE_LENGTH + 1 ];
469 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
470 vlc_bool_t b_longhelp = VLC_FALSE;
480 /* Register commands that will be cleaned up upon object destruction */
481 RegisterCallbacks( p_intf );
483 /* status callbacks */
484 /* Listen to audio volume updates */
485 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
488 /* Get the file descriptor of the console input */
489 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
490 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
492 msg_Err( p_intf, "couldn't find user input handle" );
493 p_intf->b_die = VLC_TRUE;
497 while( !intf_ShouldDie( p_intf ) )
499 char *psz_cmd, *psz_arg;
500 vlc_bool_t b_complete;
502 if( p_intf->p_sys->pi_socket_listen != NULL &&
503 p_intf->p_sys->i_socket == -1 )
505 p_intf->p_sys->i_socket =
506 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
509 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
511 /* Manage the input part */
512 if( p_input == NULL )
516 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
521 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
525 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
529 /* New input has been registered */
532 if( !p_input->b_dead || !p_input->b_die )
534 msg_rc( STATUS_CHANGE "( new input: %s )", input_GetItem(p_input)->psz_uri );
535 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
537 var_AddCallback( p_input, "state", StateChanged, p_intf );
538 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
539 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
540 var_AddCallback( p_input, "rate", RateChanged, p_intf );
541 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
544 else if( p_input->b_dead )
546 var_DelCallback( p_input, "state", StateChanged, p_intf );
547 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
548 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
549 var_DelCallback( p_input, "rate", RateChanged, p_intf );
550 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
551 vlc_object_release( p_input );
556 vlc_mutex_lock( &p_playlist->object_lock );
557 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
558 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
559 vlc_mutex_unlock( &p_playlist->object_lock );
563 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
564 (p_playlist != NULL) )
566 vlc_mutex_lock( &p_playlist->object_lock );
567 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
568 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
570 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
571 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
573 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
574 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
576 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
577 msg_rc( STATUS_CHANGE "( play state: 1 )" );
579 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
580 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
582 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
583 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
585 vlc_mutex_unlock( &p_playlist->object_lock );
588 if( p_input && b_showpos )
590 i_newpos = 100 * var_GetFloat( p_input, "position" );
591 if( i_oldpos != i_newpos )
594 msg_rc( "pos: %d%%", i_newpos );
598 /* Is there something to do? */
599 if( !b_complete ) continue;
602 /* Skip heading spaces */
604 while( *psz_cmd == ' ' )
609 /* Split psz_cmd at the first space and make sure that
610 * psz_arg is valid */
611 psz_arg = strchr( psz_cmd, ' ' );
615 while( *psz_arg == ' ' )
625 /* If the user typed a registered local command, try it */
626 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
631 val.psz_string = psz_arg;
632 i_ret = var_Set( p_intf, psz_cmd, val );
633 msg_rc( "%s: returned %i (%s)",
634 psz_cmd, i_ret, vlc_error( i_ret ) );
636 /* Or maybe it's a global command */
637 else if( var_Type( p_intf->p_libvlc_global, psz_cmd ) & VLC_VAR_ISCOMMAND )
642 val.psz_string = psz_arg;
643 /* FIXME: it's a global command, but we should pass the
644 * local object as an argument, not p_intf->p_libvlc_global. */
645 i_ret = var_Set( p_intf->p_libvlc_global, psz_cmd, val );
648 msg_rc( "%s: returned %i (%s)",
649 psz_cmd, i_ret, vlc_error( i_ret ) );
652 else if( !strcmp( psz_cmd, "logout" ) )
654 /* Close connection */
655 if( p_intf->p_sys->i_socket != -1 )
657 net_Close( p_intf->p_sys->i_socket );
659 p_intf->p_sys->i_socket = -1;
661 else if( !strcmp( psz_cmd, "info" ) )
666 vlc_mutex_lock( &input_GetItem(p_input)->lock );
667 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
669 info_category_t *p_category = input_GetItem(p_input)
672 msg_rc( "+----[ %s ]", p_category->psz_name );
674 for ( j = 0; j < p_category->i_infos; j++ )
676 info_t *p_info = p_category->pp_infos[j];
677 msg_rc( "| %s: %s", p_info->psz_name,
682 msg_rc( "+----[ end of stream info ]" );
683 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
687 msg_rc( "no input" );
690 else if( !strcmp( psz_cmd, "is_playing" ) )
701 else if( !strcmp( psz_cmd, "get_time" ) )
710 var_Get( p_input, "time", &time );
711 msg_rc( "%i", time.i_time / 1000000);
714 else if( !strcmp( psz_cmd, "get_length" ) )
723 var_Get( p_input, "length", &time );
724 msg_rc( "%i", time.i_time / 1000000);
727 else if( !strcmp( psz_cmd, "get_title" ) )
735 msg_rc( "%s", input_GetItem(p_input)->psz_name );
738 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
739 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
741 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
742 b_longhelp = VLC_TRUE;
743 else b_longhelp = VLC_FALSE;
745 Help( p_intf, b_longhelp );
747 else if( !strcmp( psz_cmd, "check-updates" ) )
749 checkUpdates( p_intf, psz_arg );
751 else switch( psz_cmd[0] )
757 vout_thread_t *p_vout;
758 p_vout = vlc_object_find( p_input,
759 VLC_OBJECT_VOUT, FIND_CHILD );
764 vlc_bool_t b_update = VLC_FALSE;
765 var_Get( p_vout, "fullscreen", &val );
766 val.b_bool = !val.b_bool;
767 if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
770 val.b_bool = VLC_TRUE;
772 else if( !strncmp(psz_arg, "off", 3) && (val.b_bool == VLC_FALSE) )
775 val.b_bool = VLC_FALSE;
777 else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
779 if( b_update ) var_Set( p_vout, "fullscreen", val );
780 vlc_object_release( p_vout );
791 /* Ignore empty lines */
795 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
799 /* Command processed */
800 i_size = 0; p_buffer[0] = 0;
803 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
804 msg_rc( STATUS_CHANGE "( quit )" );
808 var_DelCallback( p_input, "state", StateChanged, p_intf );
809 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
810 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
811 var_DelCallback( p_input, "rate", RateChanged, p_intf );
812 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
813 vlc_object_release( p_input );
819 vlc_object_release( p_playlist );
823 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
826 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
828 msg_rc(_("+----[ Remote control commands ]"));
830 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist"));
831 msg_rc(_("| enqueue XYZ . . . . . . . queue XYZ to playlist"));
832 msg_rc(_("| playlist . . . show items currently in playlist"));
833 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
834 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
835 msg_rc(_("| next . . . . . . . . . . . . next playlist item"));
836 msg_rc(_("| prev . . . . . . . . . . previous playlist item"));
837 msg_rc(_("| goto . . . . . . . . . . . . goto item at index"));
838 msg_rc(_("| repeat [on|off] . . toggle playlist item repeat"));
839 msg_rc(_("| loop [on|off] . . . . toggle playlist item loop"));
840 msg_rc(_("| clear . . . . . . . . . . . clear the playlist"));
841 msg_rc(_("| status . . . . . . . . . current playlist status"));
842 msg_rc(_("| title [X] . . . . set/get title in current item"));
843 msg_rc(_("| title_n . . . . . . next title in current item"));
844 msg_rc(_("| title_p . . . . previous title in current item"));
845 msg_rc(_("| chapter [X] . . set/get chapter in current item"));
846 msg_rc(_("| chapter_n . . . . next chapter in current item"));
847 msg_rc(_("| chapter_p . . previous chapter in current item"));
849 msg_rc(_("| seek X . seek in seconds, for instance `seek 12'"));
850 msg_rc(_("| pause . . . . . . . . . . . . . . toggle pause"));
851 msg_rc(_("| fastforward . . . . . . . set to maximum rate"));
852 msg_rc(_("| rewind . . . . . . . . . . set to minimum rate"));
853 msg_rc(_("| faster . . . . . . . . faster playing of stream"));
854 msg_rc(_("| slower . . . . . . . . slower playing of stream"));
855 msg_rc(_("| normal . . . . . . . . normal playing of stream"));
856 msg_rc(_("| f [on|off] . . . . . . . . . . toggle fullscreen"));
857 msg_rc(_("| info . . . information about the current stream"));
858 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
859 msg_rc(_("| is_playing . . 1 if a stream plays, 0 otherwise"));
860 msg_rc(_("| get_title . . . the title of the current stream"));
861 msg_rc(_("| get_length . . the length of the current stream"));
863 msg_rc(_("| volume [X] . . . . . . . . set/get audio volume"));
864 msg_rc(_("| volup [X] . . . . . raise audio volume X steps"));
865 msg_rc(_("| voldown [X] . . . . lower audio volume X steps"));
866 msg_rc(_("| adev [X] . . . . . . . . . set/get audio device"));
867 msg_rc(_("| achan [X]. . . . . . . . set/get audio channels"));
868 msg_rc(_("| atrack [X] . . . . . . . . . set/get audio track"));
869 msg_rc(_("| vtrack [X] . . . . . . . . . set/get video track"));
870 msg_rc(_("| vratio [X] . . . . . set/get video aspect ratio"));
871 msg_rc(_("| vcrop [X] . . . . . . . . . set/get video crop"));
872 msg_rc(_("| vzoom [X] . . . . . . . . . set/get video zoom"));
873 msg_rc(_("| strack [X] . . . . . . . set/get subtitles track"));
874 msg_rc(_("| menu [on|off|up|down|left|right|select] use menu"));
879 msg_rc(_("| marq-marquee STRING . . overlay STRING in video"));
880 msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left"));
881 msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top"));
882 msg_rc(_("| marq-position #. . . .relative position control"));
883 msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB"));
884 msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity"));
885 msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms"));
886 msg_rc(_("| marq-size # . . . . . . . . font size, in pixels"));
888 msg_rc(_("| logo-file STRING . . .the overlay file path/name"));
889 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
890 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
891 msg_rc(_("| logo-position #. . . . . . . . relative position"));
892 msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
894 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
895 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
896 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
897 msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
898 msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
899 msg_rc(_("| mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
900 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
901 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
902 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
903 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
904 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
905 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
906 msg_rc(_("| mosaic-order id(,id)* . . . . order of pictures "));
907 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
909 msg_rc(_("| check-updates [newer] [equal] [older]\n"
910 "| [undef] [info] [source] [binary] [plugin]"));
913 msg_rc(_("| help . . . . . . . . . . . . . this help message"));
914 msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
915 msg_rc(_("| logout . . . . . exit (if in socket connection)"));
916 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc"));
918 msg_rc(_("+----[ end of help ]"));
921 /********************************************************************
922 * Status callback routines
923 ********************************************************************/
924 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
925 vlc_value_t oldval, vlc_value_t newval, void *p_data )
927 intf_thread_t *p_intf = (intf_thread_t*)p_data;
928 input_thread_t *p_input = NULL;
930 vlc_mutex_lock( &p_intf->p_sys->status_lock );
931 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
934 msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
935 vlc_object_release( p_input );
937 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
941 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
942 vlc_value_t oldval, vlc_value_t newval, void *p_data )
944 intf_thread_t *p_intf = (intf_thread_t*)p_data;
946 vlc_mutex_lock( &p_intf->p_sys->status_lock );
947 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
948 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
952 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
953 vlc_value_t oldval, vlc_value_t newval, void *p_data )
955 intf_thread_t *p_intf = (intf_thread_t*)p_data;
956 playlist_t *p_playlist = NULL;
957 input_thread_t *p_input = NULL;
959 vlc_mutex_lock( &p_intf->p_sys->status_lock );
960 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
963 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
967 switch( p_playlist->status.i_status )
969 case PLAYLIST_STOPPED:
970 strncpy( &cmd[0], "stop", 4);
973 case PLAYLIST_RUNNING:
974 strncpy( &cmd[0], "play", 4);
977 case PLAYLIST_PAUSED:
978 strncpy( &cmd[0], "pause", 5);
981 } /* var_GetInteger( p_input, "state" ) */
982 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
983 vlc_object_release( p_playlist );
985 vlc_object_release( p_input );
987 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
991 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
992 vlc_value_t oldval, vlc_value_t newval, void *p_data )
994 intf_thread_t *p_intf = (intf_thread_t*)p_data;
995 input_thread_t *p_input = NULL;
997 vlc_mutex_lock( &p_intf->p_sys->status_lock );
998 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1001 msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
1002 vlc_object_release( p_input );
1004 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1008 /********************************************************************
1010 ********************************************************************/
1011 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1012 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1014 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1015 input_thread_t *p_input;
1018 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1019 if( !p_input ) return VLC_ENOOBJ;
1021 var_Get( p_input, "state", &val );
1022 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1023 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1025 msg_rc( _("Press menu select or pause to continue.") );
1026 vlc_object_release( p_input );
1027 return VLC_EGENERIC;
1030 /* Parse commands that only require an input */
1031 if( !strcmp( psz_cmd, "pause" ) )
1033 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1034 var_Set( p_intf->p_libvlc, "key-pressed", val );
1035 vlc_object_release( p_input );
1038 else if( !strcmp( psz_cmd, "seek" ) )
1040 if( strlen( newval.psz_string ) > 0 &&
1041 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1043 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1044 var_Set( p_input, "position", val );
1048 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1049 var_Set( p_input, "time", val );
1051 vlc_object_release( p_input );
1054 else if ( !strcmp( psz_cmd, "fastforward" ) )
1056 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1057 var_Set( p_intf->p_libvlc, "key-pressed", val );
1058 vlc_object_release( p_input );
1061 else if ( !strcmp( psz_cmd, "rewind" ) )
1063 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1064 var_Set( p_intf->p_libvlc, "key-pressed", val );
1065 vlc_object_release( p_input );
1068 else if ( !strcmp( psz_cmd, "faster" ) )
1070 val.b_bool = VLC_TRUE;
1071 var_Set( p_input, "rate-faster", val );
1072 vlc_object_release( p_input );
1075 else if ( !strcmp( psz_cmd, "slower" ) )
1077 val.b_bool = VLC_TRUE;
1078 var_Set( p_input, "rate-slower", val );
1079 vlc_object_release( p_input );
1082 else if ( !strcmp( psz_cmd, "normal" ) )
1084 val.i_int = INPUT_RATE_DEFAULT;
1085 var_Set( p_input, "rate", val );
1086 vlc_object_release( p_input );
1089 else if( !strcmp( psz_cmd, "chapter" ) ||
1090 !strcmp( psz_cmd, "chapter_n" ) ||
1091 !strcmp( psz_cmd, "chapter_p" ) )
1093 if( !strcmp( psz_cmd, "chapter" ) )
1095 if ( *newval.psz_string )
1098 val.i_int = atoi( newval.psz_string );
1099 var_Set( p_input, "chapter", val );
1103 vlc_value_t val_list;
1106 var_Get( p_input, "chapter", &val );
1107 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1109 msg_rc( "Currently playing chapter %d/%d.",
1110 val.i_int, val_list.p_list->i_count );
1111 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1115 else if( !strcmp( psz_cmd, "chapter_n" ) )
1117 val.b_bool = VLC_TRUE;
1118 var_Set( p_input, "next-chapter", val );
1120 else if( !strcmp( psz_cmd, "chapter_p" ) )
1122 val.b_bool = VLC_TRUE;
1123 var_Set( p_input, "prev-chapter", val );
1125 vlc_object_release( p_input );
1128 else if( !strcmp( psz_cmd, "title" ) ||
1129 !strcmp( psz_cmd, "title_n" ) ||
1130 !strcmp( psz_cmd, "title_p" ) )
1132 if( !strcmp( psz_cmd, "title" ) )
1134 if ( *newval.psz_string )
1137 val.i_int = atoi( newval.psz_string );
1138 var_Set( p_input, "title", val );
1142 vlc_value_t val_list;
1145 var_Get( p_input, "title", &val );
1146 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1148 msg_rc( "Currently playing title %d/%d.",
1149 val.i_int, val_list.p_list->i_count );
1150 var_Change( p_this, "title", VLC_VAR_FREELIST,
1154 else if( !strcmp( psz_cmd, "title_n" ) )
1156 val.b_bool = VLC_TRUE;
1157 var_Set( p_input, "next-title", val );
1159 else if( !strcmp( psz_cmd, "title_p" ) )
1161 val.b_bool = VLC_TRUE;
1162 var_Set( p_input, "prev-title", val );
1165 vlc_object_release( p_input );
1168 else if( !strcmp( psz_cmd, "atrack" )
1169 || !strcmp( psz_cmd, "vtrack" )
1170 || !strcmp( psz_cmd, "strack" ) )
1173 vlc_value_t val_name;
1176 if( !strcmp( psz_cmd, "atrack" ) )
1178 psz_variable = "audio-es";
1180 else if( !strcmp( psz_cmd, "vtrack" ) )
1182 psz_variable = "video-es";
1186 psz_variable = "spu-es";
1189 /* Get the descriptive name of the variable */
1190 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1192 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1194 if( newval.psz_string && *newval.psz_string )
1198 val.i_int = atoi( newval.psz_string );
1200 i_error = var_Set( p_input, psz_variable, val );
1205 vlc_value_t val, text;
1208 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1210 vlc_object_release( p_input );
1211 return VLC_EGENERIC;
1213 i_value = val.i_int;
1215 if ( var_Change( p_input, psz_variable,
1216 VLC_VAR_GETLIST, &val, &text ) < 0 )
1218 vlc_object_release( p_input );
1219 return VLC_EGENERIC;
1222 msg_rc( "+----[ %s ]", val_name.psz_string );
1223 for ( i = 0; i < val.p_list->i_count; i++ )
1225 if ( i_value == val.p_list->p_values[i].i_int )
1226 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1227 text.p_list->p_values[i].psz_string );
1229 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1230 text.p_list->p_values[i].psz_string );
1232 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1234 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1236 if( val_name.psz_string ) free( val_name.psz_string );
1238 i_error = VLC_SUCCESS;
1240 vlc_object_release( p_input );
1244 /* Never reached. */
1245 vlc_object_release( p_input );
1246 return VLC_EGENERIC;
1249 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1250 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1254 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1255 playlist_t *p_playlist = pl_Yield( p_this );
1258 if( p_playlist->p_input )
1260 var_Get( p_playlist->p_input, "state", &val );
1261 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1263 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1264 vlc_object_release( p_playlist );
1266 return VLC_EGENERIC;
1271 /* Parse commands that require a playlist */
1272 if( !strcmp( psz_cmd, "prev" ) )
1274 playlist_Prev( p_playlist );
1276 else if( !strcmp( psz_cmd, "next" ) )
1278 playlist_Next( p_playlist );
1280 else if( !strcmp( psz_cmd, "play" ) )
1282 msg_Warn( p_playlist, "play" );
1283 playlist_Play( p_playlist );
1285 else if( !strcmp( psz_cmd, "repeat" ) )
1287 vlc_bool_t b_update = VLC_TRUE;
1289 var_Get( p_playlist, "repeat", &val );
1291 if( strlen( newval.psz_string ) > 0 )
1293 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1294 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1296 b_update = VLC_FALSE;
1302 val.b_bool = !val.b_bool;
1303 var_Set( p_playlist, "repeat", val );
1305 msg_rc( "Setting repeat to %d", val.b_bool );
1307 else if( !strcmp( psz_cmd, "loop" ) )
1309 vlc_bool_t b_update = VLC_TRUE;
1311 var_Get( p_playlist, "loop", &val );
1313 if( strlen( newval.psz_string ) > 0 )
1315 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1316 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1318 b_update = VLC_FALSE;
1324 val.b_bool = !val.b_bool;
1325 var_Set( p_playlist, "loop", val );
1327 msg_rc( "Setting loop to %d", val.b_bool );
1329 else if (!strcmp( psz_cmd, "goto" ) )
1331 msg_rc( _("goto is deprecated" ) );
1332 msg_Err( p_playlist, "goto is deprecated" );
1334 else if( !strcmp( psz_cmd, "stop" ) )
1336 playlist_Stop( p_playlist );
1338 else if( !strcmp( psz_cmd, "clear" ) )
1340 playlist_Stop( p_playlist );
1341 playlist_Clear( p_playlist, VLC_FALSE );
1343 else if( !strcmp( psz_cmd, "add" ) &&
1344 newval.psz_string && *newval.psz_string )
1346 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1350 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1351 playlist_AddInput( p_playlist, p_item,
1352 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
1355 else if( !strcmp( psz_cmd, "enqueue" ) &&
1356 newval.psz_string && *newval.psz_string )
1358 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1362 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1363 playlist_AddInput( p_playlist, p_item,
1364 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
1367 else if( !strcmp( psz_cmd, "playlist" ) )
1369 msg_Dbg( p_playlist, "Dumping category" );
1370 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1371 msg_Dbg( p_playlist, "Dumping Onelevel" );
1372 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1374 else if( !strcmp( psz_cmd, "sort" ))
1376 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1377 SORT_ARTIST, ORDER_NORMAL );
1379 else if( !strcmp( psz_cmd, "status" ) )
1381 if( p_playlist->p_input )
1383 /* Replay the current state of the system. */
1384 msg_rc( STATUS_CHANGE "( new input: %s )", input_GetItem(p_playlist->p_input)->psz_uri );
1385 msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
1387 vlc_mutex_lock( &p_playlist->object_lock );
1388 switch( p_playlist->status.i_status )
1390 case PLAYLIST_STOPPED:
1391 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1393 case PLAYLIST_RUNNING:
1394 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1396 case PLAYLIST_PAUSED:
1397 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1400 msg_rc( STATUS_CHANGE "( state unknown )" );
1403 vlc_mutex_unlock( &p_playlist->object_lock );
1412 msg_rc( "unknown command!" );
1415 vlc_object_release( p_playlist );
1419 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1420 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1422 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1423 vlc_object_t *p_playlist;
1425 vlc_object_t *p_input;
1427 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1433 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1436 vlc_object_release( p_playlist );
1442 var_Get( p_input, "state", &val );
1443 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1445 msg_rc( _("Type 'pause' to continue.") );
1446 vlc_object_release( p_playlist );
1447 vlc_object_release( p_input );
1448 return VLC_EGENERIC;
1452 /* Parse miscellaneous commands */
1454 static const char vars[] =
1455 "marq-x\0" "marq-y\0" "marq-position\0" "marq-color\0"
1456 "marq-opacity\0" "marq-size\0" "marq-timeout\0"
1457 "mosaic-alpha\0" "mosaic-height\0" "mosaic-width\0"
1458 "mosaic-xoffset\0" "mosaic-yoffset\0" "mosaic-align\0"
1459 "mosaic-vborder\0" "mosaic-hborder\0" "mosaic-position\0"
1460 "mosaic-rows\0" "mosaic-cols\0" "mosaic-order\0"
1461 "mosaic-offsets\0" "mosaic-keep-aspect-ratio\0"
1462 "logo-file\0" "logo-x\0" "logo-y\0" "logo-position\0"
1463 "logo-transparency\0";
1464 const char *psz_name;
1466 for( psz_name = vars; *psz_name; psz_name += strlen( psz_name ) + 1 )
1468 if( strcmp( psz_name, psz_cmd ) == 0 )
1470 switch( var_Type( p_input->p_libvlc_global, psz_name ) )
1472 case VLC_VAR_INTEGER:
1473 if( !strlen( newval.psz_string ) ) break;
1474 var_SetInteger( p_input->p_libvlc_global, psz_name,
1475 atoi( newval.psz_string ) );
1478 case VLC_VAR_STRING:
1479 if( !strlen( newval.psz_string ) ) break;
1480 var_SetInteger( p_input->p_libvlc_global, psz_name,
1481 newval.psz_string );
1485 msg_Err( p_intf, "unknown variable type" );
1491 if( *psz_name == '\0' )
1492 msg_rc( "Unknown command!" );
1495 vlc_object_release( p_playlist );
1496 vlc_object_release( p_input );
1500 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1501 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1503 playlist_t *p_playlist;
1505 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1508 playlist_Stop( p_playlist );
1509 vlc_object_release( p_playlist );
1511 p_this->p_libvlc->b_die = VLC_TRUE;
1515 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1516 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1518 intf_thread_t *p_newintf = NULL;
1520 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1523 p_newintf->b_block = VLC_FALSE;
1524 if( intf_RunThread( p_newintf ) )
1526 vlc_object_detach( p_newintf );
1527 intf_Destroy( p_newintf );
1534 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1535 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1537 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1538 input_thread_t *p_input = NULL;
1539 int i_error = VLC_EGENERIC;
1541 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1549 var_Get( p_input, "state", &val );
1550 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1552 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1553 vlc_object_release( p_input );
1554 return VLC_EGENERIC;
1556 vlc_object_release( p_input );
1559 if ( *newval.psz_string )
1562 audio_volume_t i_volume = atoi( newval.psz_string );
1563 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1565 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1567 i_error = VLC_EBADVAR;
1571 if( i_volume == AOUT_VOLUME_MIN )
1575 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1576 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1578 i_error = aout_VolumeSet( p_this, i_volume );
1579 osd_Volume( p_this );
1580 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1586 audio_volume_t i_volume;
1587 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1589 i_error = VLC_EGENERIC;
1593 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1594 i_error = VLC_SUCCESS;
1601 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1602 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1604 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1605 audio_volume_t i_volume;
1606 input_thread_t *p_input = NULL;
1607 int i_nb_steps = atoi(newval.psz_string);
1608 int i_error = VLC_SUCCESS;
1609 int i_volume_step = 0;
1611 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1619 var_Get( p_input, "state", &val );
1620 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1622 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1623 vlc_object_release( p_input );
1624 return VLC_EGENERIC;
1626 vlc_object_release( p_input );
1629 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1630 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1635 if ( !strcmp(psz_cmd, "volup") )
1637 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1638 i_error = VLC_EGENERIC;
1642 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1643 i_error = VLC_EGENERIC;
1645 osd_Volume( p_this );
1647 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1652 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1653 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1655 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1656 input_thread_t *p_input = NULL;
1657 vout_thread_t * p_vout;
1658 const char * psz_variable;
1659 vlc_value_t val_name;
1662 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1666 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1667 vlc_object_release( p_input );
1671 if( !strcmp( psz_cmd, "vcrop" ) )
1673 psz_variable = "crop";
1675 else if( !strcmp( psz_cmd, "vratio" ) )
1677 psz_variable = "aspect-ratio";
1679 else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1681 psz_variable = "zoom";
1685 /* Get the descriptive name of the variable */
1686 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1688 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1690 if( newval.psz_string && *newval.psz_string )
1693 if( !strcmp( psz_variable, "zoom" ) )
1696 val.f_float = atof( newval.psz_string );
1697 i_error = var_Set( p_vout, psz_variable, val );
1701 i_error = var_Set( p_vout, psz_variable, newval );
1707 vlc_value_t val, text;
1710 char *psz_value = NULL;
1712 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1714 vlc_object_release( p_vout );
1715 return VLC_EGENERIC;
1717 if( !strcmp( psz_variable, "zoom" ) )
1719 f_value = val.f_float;
1723 psz_value = strdup( val.psz_string );
1726 if ( var_Change( p_vout, psz_variable,
1727 VLC_VAR_GETLIST, &val, &text ) < 0 )
1729 vlc_object_release( p_vout );
1730 return VLC_EGENERIC;
1733 msg_rc( "+----[ %s ]", val_name.psz_string );
1734 if( !strcmp( psz_variable, "zoom" ) )
1736 for ( i = 0; i < val.p_list->i_count; i++ )
1738 if ( f_value == val.p_list->p_values[i].f_float )
1739 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1740 text.p_list->p_values[i].psz_string );
1742 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1743 text.p_list->p_values[i].psz_string );
1748 for ( i = 0; i < val.p_list->i_count; i++ )
1750 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1751 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1752 text.p_list->p_values[i].psz_string );
1754 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1755 text.p_list->p_values[i].psz_string );
1759 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1761 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1763 if( val_name.psz_string ) free( val_name.psz_string );
1765 i_error = VLC_SUCCESS;
1767 vlc_object_release( p_vout );
1771 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1772 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1774 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1775 input_thread_t *p_input = NULL;
1776 aout_instance_t * p_aout;
1777 const char * psz_variable;
1778 vlc_value_t val_name;
1781 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1789 var_Get( p_input, "state", &val );
1790 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1791 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1792 vlc_object_release( p_input );
1793 return VLC_EGENERIC;
1795 vlc_object_release( p_input );
1798 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1799 if ( p_aout == NULL ) return VLC_ENOOBJ;
1801 if ( !strcmp( psz_cmd, "adev" ) )
1803 psz_variable = "audio-device";
1807 psz_variable = "audio-channels";
1810 /* Get the descriptive name of the variable */
1811 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1813 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1815 if ( !*newval.psz_string )
1817 /* Retrieve all registered ***. */
1818 vlc_value_t val, text;
1821 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1823 vlc_object_release( (vlc_object_t *)p_aout );
1824 return VLC_EGENERIC;
1826 i_value = val.i_int;
1828 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1829 VLC_VAR_GETLIST, &val, &text ) < 0 )
1831 vlc_object_release( (vlc_object_t *)p_aout );
1832 return VLC_EGENERIC;
1835 msg_rc( "+----[ %s ]", val_name.psz_string );
1836 for ( i = 0; i < val.p_list->i_count; i++ )
1838 if ( i_value == val.p_list->p_values[i].i_int )
1839 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1840 text.p_list->p_values[i].psz_string );
1842 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1843 text.p_list->p_values[i].psz_string );
1845 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1847 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1849 if( val_name.psz_string ) free( val_name.psz_string );
1850 i_error = VLC_SUCCESS;
1855 val.i_int = atoi( newval.psz_string );
1857 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1859 vlc_object_release( (vlc_object_t *)p_aout );
1864 /* OSD menu commands */
1865 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1866 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1868 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1869 playlist_t *p_playlist = NULL;
1871 int i_error = VLC_EGENERIC;
1873 if ( !*newval.psz_string )
1875 msg_rc( _("Please provide one of the following parameters:") );
1876 msg_rc( "[on|off|up|down|left|right|select]" );
1880 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1884 if( p_playlist->p_input )
1886 var_Get( p_playlist->p_input, "state", &val );
1887 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1888 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1890 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1891 vlc_object_release( p_playlist );
1892 return VLC_EGENERIC;
1895 vlc_object_release( p_playlist );
1897 val.psz_string = strdup( newval.psz_string );
1898 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1899 osd_MenuShow( p_this );
1900 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1901 osd_MenuHide( p_this );
1902 else if( !strcmp( val.psz_string, "up" ) )
1903 osd_MenuUp( p_this );
1904 else if( !strcmp( val.psz_string, "down" ) )
1905 osd_MenuDown( p_this );
1906 else if( !strcmp( val.psz_string, "left" ) )
1907 osd_MenuPrev( p_this );
1908 else if( !strcmp( val.psz_string, "right" ) )
1909 osd_MenuNext( p_this );
1910 else if( !strcmp( val.psz_string, "select" ) )
1911 osd_MenuActivate( p_this );
1914 msg_rc( _("Please provide one of the following parameters:") );
1915 msg_rc( "[on|off|up|down|left|right|select]" );
1916 if( val.psz_string ) free( val.psz_string );
1920 i_error = VLC_SUCCESS;
1921 if( val.psz_string ) free( val.psz_string );
1926 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1928 INPUT_RECORD input_record;
1931 /* On Win32, select() only works on socket descriptors */
1932 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1933 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1935 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1936 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1939 if( input_record.EventType != KEY_EVENT ||
1940 !input_record.Event.KeyEvent.bKeyDown ||
1941 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1942 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1943 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1944 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1946 /* nothing interesting */
1950 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1952 /* Echo out the command */
1953 putc( p_buffer[ *pi_size ], stdout );
1955 /* Handle special keys */
1956 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1958 putc( '\n', stdout );
1961 switch( p_buffer[ *pi_size ] )
1967 putc( ' ', stdout );
1968 putc( '\b', stdout );
1979 if( *pi_size == MAX_LINE_LENGTH ||
1980 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1982 p_buffer[ *pi_size ] = 0;
1991 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1996 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1997 return ReadWin32( p_intf, p_buffer, pi_size );
1998 else if( p_intf->p_sys->i_socket == -1 )
2000 msleep( INTF_IDLE_SLEEP );
2005 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2006 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
2007 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2008 (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
2010 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2016 /* Connection closed */
2019 p_intf->p_sys->i_socket = -1;
2020 p_buffer[ *pi_size ] = 0;
2024 if( *pi_size == MAX_LINE_LENGTH ||
2025 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2027 p_buffer[ *pi_size ] = 0;
2034 /*****************************************************************************
2035 * parse_MRL: build a input item from a full mrl
2036 *****************************************************************************
2037 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2038 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2039 * space is a new option. Should be good enough for our purpose.
2040 *****************************************************************************/
2041 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2043 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2044 #define SKIPTRAILINGSPACE( p, d ) \
2045 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2047 input_item_t *p_item = NULL;
2048 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2049 char **ppsz_options = NULL;
2050 int i, i_options = 0;
2052 if( !psz_mrl ) return 0;
2054 psz_mrl = psz_orig = strdup( psz_mrl );
2057 SKIPSPACE( psz_mrl );
2060 for( ; *psz_mrl; psz_mrl++ )
2062 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2064 /* We have a complete item */
2067 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2068 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2070 /* We have a complete item */
2075 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2076 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2078 /* Remove '"' and '\'' if necessary */
2079 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2080 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2081 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2082 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2084 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2085 else if( *psz_item )
2088 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2089 ppsz_options[i_options - 1] = &psz_item[1];
2092 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2095 /* Now create a playlist item */
2098 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2099 for( i = 0; i < i_options; i++ )
2101 input_ItemAddOption( p_item, ppsz_options[i] );
2105 if( i_options ) free( ppsz_options );
2111 /*****************************************************************************
2112 * checkUpdates : check for updates
2113 ****************************************************************************/
2114 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2116 update_iterator_t *p_uit;
2117 update_t *p_u = update_New( p_intf );
2118 if( p_u == NULL ) return;
2119 p_uit = update_iterator_New( p_u );
2124 if( strstr( psz_arg, "newer" ) )
2125 s |= UPDATE_RELEASE_STATUS_NEWER;
2126 if( strstr( psz_arg, "equal" ) )
2127 s |= UPDATE_RELEASE_STATUS_EQUAL;
2128 if( strstr( psz_arg, "older" ) )
2129 s |= UPDATE_RELEASE_STATUS_OLDER;
2130 if( s ) p_uit->i_rs = s;
2131 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2133 if( strstr( psz_arg, "undef" ) )
2134 t |= UPDATE_FILE_TYPE_UNDEF;
2135 if( strstr( psz_arg, "info" ) )
2136 t |= UPDATE_FILE_TYPE_INFO;
2137 if( strstr( psz_arg, "source" ) )
2138 t |= UPDATE_FILE_TYPE_SOURCE;
2139 if( strstr( psz_arg, "binary" ) )
2140 t |= UPDATE_FILE_TYPE_BINARY;
2141 if( strstr( psz_arg, "plugin" ) )
2142 t |= UPDATE_FILE_TYPE_PLUGIN;
2143 if( t ) p_uit->i_t = t;
2145 update_Check( p_u, VLC_FALSE );
2146 update_iterator_Action( p_uit, UPDATE_MIRROR );
2147 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2148 p_uit->mirror.psz_name,
2149 p_uit->mirror.psz_location,
2150 p_uit->mirror.psz_type );
2151 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2154 if( s & UPDATE_RELEASE )
2156 switch( p_uit->release.i_status )
2158 case UPDATE_RELEASE_STATUS_OLDER:
2159 psz_tmp = strdup( "older" );
2161 case UPDATE_RELEASE_STATUS_EQUAL:
2162 psz_tmp = strdup( "equal" );
2164 case UPDATE_RELEASE_STATUS_NEWER:
2165 psz_tmp = strdup( "newer" );
2168 psz_tmp = strdup( "?!?" );
2171 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2172 p_uit->release.psz_version,
2173 p_uit->release.psz_svn_revision,
2177 switch( p_uit->file.i_type )
2179 case UPDATE_FILE_TYPE_UNDEF:
2180 psz_tmp = strdup( "undef" );
2182 case UPDATE_FILE_TYPE_INFO:
2183 psz_tmp = strdup( "info" );
2185 case UPDATE_FILE_TYPE_SOURCE:
2186 psz_tmp = strdup( "source" );
2188 case UPDATE_FILE_TYPE_BINARY:
2189 psz_tmp = strdup( "binary" );
2191 case UPDATE_FILE_TYPE_PLUGIN:
2192 psz_tmp = strdup( "plugin" );
2195 psz_tmp = strdup( "?!?" );
2198 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2200 if( p_uit->file.l_size )
2202 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2203 asprintf( &psz_tmp, "(%ld GB)",
2204 p_uit->file.l_size / (1024*1024*1024) );
2205 if( p_uit->file.l_size > 1024 * 1024 )
2206 asprintf( &psz_tmp, "(%ld MB)",
2207 p_uit->file.l_size / (1024*1024) );
2208 else if( p_uit->file.l_size > 1024 )
2209 asprintf( &psz_tmp, "(%ld kB)",
2210 p_uit->file.l_size / 1024 );
2212 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2216 psz_tmp = strdup( "" );
2218 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2223 update_iterator_Delete( p_uit );
2225 update_Delete( p_u );