1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2007 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 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
35 #include <vlc_interface.h>
39 #include <vlc_playlist.h>
40 #include <vlc_update.h>
46 #ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
49 #include <sys/types.h>
51 #include <vlc_network.h>
54 #include <vlc_charset.h>
56 #if defined(AF_UNIX) && !defined(AF_LOCAL)
57 # define AF_LOCAL AF_UNIX
60 #if defined(AF_LOCAL) && ! defined(WIN32)
64 #define MAX_LINE_LENGTH 256
65 #define STATUS_CHANGE "status change: "
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Activate ( vlc_object_t * );
71 static void Deactivate ( vlc_object_t * );
72 static void Run ( intf_thread_t * );
74 static void Help ( intf_thread_t *, vlc_bool_t );
75 static void RegisterCallbacks( intf_thread_t * );
77 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
79 static input_item_t *parse_MRL( intf_thread_t *, char * );
81 static int Input ( vlc_object_t *, char const *,
82 vlc_value_t, vlc_value_t, void * );
83 static int Playlist ( vlc_object_t *, char const *,
84 vlc_value_t, vlc_value_t, void * );
85 static int Quit ( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
87 static int Intf ( vlc_object_t *, char const *,
88 vlc_value_t, vlc_value_t, void * );
89 static int Volume ( vlc_object_t *, char const *,
90 vlc_value_t, vlc_value_t, void * );
91 static int VolumeMove ( vlc_object_t *, char const *,
92 vlc_value_t, vlc_value_t, void * );
93 static int VideoConfig ( vlc_object_t *, char const *,
94 vlc_value_t, vlc_value_t, void * );
95 static int AudioConfig ( vlc_object_t *, char const *,
96 vlc_value_t, vlc_value_t, void * );
97 static int Menu ( vlc_object_t *, char const *,
98 vlc_value_t, vlc_value_t, void * );
99 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg );
101 /* Status Callbacks */
102 static int TimeOffsetChanged( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t , void * );
104 static int VolumeChanged ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int StateChanged ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int RateChanged ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
113 int *pi_socket_listen;
118 vlc_mutex_t status_lock;
119 playlist_status_t i_last_state;
127 #ifdef HAVE_VARIADIC_MACROS
128 # define msg_rc( psz_format, args... ) \
129 __msg_rc( p_intf, psz_format, ## args )
132 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
135 va_start( args, psz_fmt );
137 if( p_intf->p_sys->i_socket == -1 )
139 utf8_vfprintf( stdout, psz_fmt, args );
144 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
145 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
150 /*****************************************************************************
152 *****************************************************************************/
153 #define POS_TEXT N_("Show stream position")
154 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
155 "stream from time to time." )
157 #define TTY_TEXT N_("Fake TTY")
158 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
160 #define UNIX_TEXT N_("UNIX socket command input")
161 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
164 #define HOST_TEXT N_("TCP command input")
165 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
166 "You can set the address and port the interface will bind to." )
169 #define QUIET_TEXT N_("Do not open a DOS command box interface")
170 #define QUIET_LONGTEXT N_( \
171 "By default the rc interface plugin will start a DOS command box. " \
172 "Enabling the quiet mode will not bring this command box but can also " \
173 "be pretty annoying when you want to stop VLC and no video window is " \
178 set_shortname( _("RC"));
179 set_category( CAT_INTERFACE );
180 set_subcategory( SUBCAT_INTERFACE_MAIN );
181 set_description( _("Remote control interface") );
182 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
185 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
187 #if defined (HAVE_ISATTY)
188 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
190 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 );
194 set_capability( "interface", 20 );
195 set_program( "rvlc" );
197 set_callbacks( Activate, Deactivate );
200 /*****************************************************************************
201 * Activate: initialize and create stuff
202 *****************************************************************************/
203 static int Activate( vlc_object_t *p_this )
205 intf_thread_t *p_intf = (intf_thread_t*)p_this;
206 char *psz_host, *psz_unix_path;
207 int *pi_socket = NULL;
210 #if defined(HAVE_ISATTY)
211 /* Check that stdin is a TTY */
212 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
214 msg_Warn( p_intf, "fd 0 is not a TTY" );
219 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
225 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
226 free( psz_unix_path );
229 struct sockaddr_un addr;
231 memset( &addr, 0, sizeof(struct sockaddr_un) );
233 msg_Dbg( p_intf, "trying UNIX socket" );
235 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
237 msg_Warn( p_intf, "can't open socket: %m" );
238 free( psz_unix_path );
242 addr.sun_family = AF_LOCAL;
243 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
244 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
246 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
247 && (errno == EADDRINUSE)
248 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
249 && (errno == ECONNREFUSED))
251 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
252 unlink (psz_unix_path);
254 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
256 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
258 free (psz_unix_path);
259 net_Close (i_socket);
264 if( listen( i_socket, 1 ) )
266 msg_Warn( p_intf, "can't listen on socket: %m");
267 free( psz_unix_path );
268 net_Close( i_socket );
272 /* FIXME: we need a core function to merge listening sockets sets */
273 pi_socket = calloc( 2, sizeof( int ) );
274 if( pi_socket == NULL )
276 free( psz_unix_path );
277 net_Close( i_socket );
280 pi_socket[0] = i_socket;
282 #endif /* AF_LOCAL */
286 if( ( pi_socket == NULL ) &&
287 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
291 vlc_UrlParse( &url, psz_host, 0 );
293 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
295 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
296 if( pi_socket == NULL )
298 msg_Warn( p_intf, "can't listen to %s port %i",
299 url.psz_host, url.i_port );
300 vlc_UrlClean( &url );
305 vlc_UrlClean( &url );
309 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
312 msg_Err( p_intf, "no memory" );
316 p_intf->p_sys->pi_socket_listen = pi_socket;
317 p_intf->p_sys->i_socket = -1;
318 p_intf->p_sys->psz_unix_path = psz_unix_path;
319 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
320 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
322 /* Non-buffered stdout */
323 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
325 p_intf->pf_run = Run;
328 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
329 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
334 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
338 /*****************************************************************************
339 * Deactivate: uninitialize and cleanup
340 *****************************************************************************/
341 static void Deactivate( vlc_object_t *p_this )
343 intf_thread_t *p_intf = (intf_thread_t*)p_this;
345 net_ListenClose( p_intf->p_sys->pi_socket_listen );
346 if( p_intf->p_sys->i_socket != -1 )
347 net_Close( p_intf->p_sys->i_socket );
348 if( p_intf->p_sys->psz_unix_path != NULL )
350 #if defined(AF_LOCAL) && !defined(WIN32)
351 unlink( p_intf->p_sys->psz_unix_path );
353 free( p_intf->p_sys->psz_unix_path );
355 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
356 free( p_intf->p_sys );
359 /*****************************************************************************
360 * RegisterCallbacks: Register callbacks to dynamic variables
361 *****************************************************************************/
362 static void RegisterCallbacks( intf_thread_t *p_intf )
364 /* Register commands that will be cleaned up upon object destruction */
365 #define ADD( name, type, target ) \
366 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
367 var_AddCallback( p_intf, name, target, NULL );
368 ADD( "quit", VOID, Quit )
369 ADD( "intf", STRING, Intf )
371 ADD( "add", STRING, Playlist )
372 ADD( "repeat", STRING, Playlist )
373 ADD( "loop", STRING, Playlist )
374 ADD( "random", STRING, Playlist )
375 ADD( "enqueue", STRING, Playlist )
376 ADD( "playlist", VOID, Playlist )
377 ADD( "sort", VOID, Playlist )
378 ADD( "play", VOID, Playlist )
379 ADD( "stop", VOID, Playlist )
380 ADD( "clear", VOID, Playlist )
381 ADD( "prev", VOID, Playlist )
382 ADD( "next", VOID, Playlist )
383 ADD( "goto", INTEGER, Playlist )
384 ADD( "status", INTEGER, Playlist )
386 /* OSD menu commands */
387 ADD( "menu", STRING, Menu )
390 ADD( "pause", VOID, Input )
391 ADD( "seek", INTEGER, Input )
392 ADD( "title", STRING, Input )
393 ADD( "title_n", VOID, Input )
394 ADD( "title_p", VOID, Input )
395 ADD( "chapter", STRING, Input )
396 ADD( "chapter_n", VOID, Input )
397 ADD( "chapter_p", VOID, Input )
399 ADD( "fastforward", VOID, Input )
400 ADD( "rewind", VOID, Input )
401 ADD( "faster", VOID, Input )
402 ADD( "slower", VOID, Input )
403 ADD( "normal", VOID, Input )
405 ADD( "atrack", STRING, Input )
406 ADD( "vtrack", STRING, Input )
407 ADD( "strack", STRING, Input )
410 ADD( "vratio", STRING, VideoConfig )
411 ADD( "vcrop", STRING, VideoConfig )
412 ADD( "vzoom", STRING, VideoConfig )
413 ADD( "snapshot", VOID, VideoConfig )
416 ADD( "volume", STRING, Volume )
417 ADD( "volup", STRING, VolumeMove )
418 ADD( "voldown", STRING, VolumeMove )
419 ADD( "adev", STRING, AudioConfig )
420 ADD( "achan", STRING, AudioConfig )
425 /*****************************************************************************
427 *****************************************************************************
428 * This part of the interface is in a separate thread so that we can call
429 * exec() from within it without annoying the rest of the program.
430 *****************************************************************************/
431 static void Run( intf_thread_t *p_intf )
433 input_thread_t * p_input;
434 playlist_t * p_playlist;
436 char p_buffer[ MAX_LINE_LENGTH + 1 ];
437 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
438 vlc_bool_t b_longhelp = VLC_FALSE;
448 /* Register commands that will be cleaned up upon object destruction */
449 RegisterCallbacks( p_intf );
451 /* status callbacks */
452 /* Listen to audio volume updates */
453 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
456 /* Get the file descriptor of the console input */
457 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
458 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
460 msg_Err( p_intf, "couldn't find user input handle" );
461 vlc_object_kill( p_intf );
465 while( !intf_ShouldDie( p_intf ) )
467 char *psz_cmd, *psz_arg;
468 vlc_bool_t b_complete;
470 if( p_intf->p_sys->pi_socket_listen != NULL &&
471 p_intf->p_sys->i_socket == -1 )
473 p_intf->p_sys->i_socket =
474 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
476 if( p_intf->p_sys->i_socket == -1 ) continue;
479 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
481 /* Manage the input part */
482 if( p_input == NULL )
486 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
491 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
495 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
499 /* New input has been registered */
502 if( !p_input->b_dead || !p_input->b_die )
505 input_item_GetURI( input_GetItem( p_input ) );
506 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
508 msg_rc( STATUS_CHANGE "( audio volume: %d )",
509 config_GetInt( p_intf, "volume" ));
511 var_AddCallback( p_input, "state", StateChanged, p_intf );
512 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
513 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
514 var_AddCallback( p_input, "rate", RateChanged, p_intf );
515 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
519 else if( p_input->b_dead )
521 var_DelCallback( p_input, "state", StateChanged, p_intf );
522 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
523 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
524 var_DelCallback( p_input, "rate", RateChanged, p_intf );
525 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
527 vlc_object_release( p_input );
532 vlc_mutex_lock( &p_playlist->object_lock );
533 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
534 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
535 vlc_mutex_unlock( &p_playlist->object_lock );
539 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
540 (p_playlist != NULL) )
542 vlc_mutex_lock( &p_playlist->object_lock );
543 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
544 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
546 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
547 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
550 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
551 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
553 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
554 msg_rc( STATUS_CHANGE "( play state: 1 )" );
557 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
558 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
560 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
561 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
563 vlc_mutex_unlock( &p_playlist->object_lock );
566 if( p_input && b_showpos )
568 i_newpos = 100 * var_GetFloat( p_input, "position" );
569 if( i_oldpos != i_newpos )
572 msg_rc( "pos: %d%%", i_newpos );
576 /* Is there something to do? */
577 if( !b_complete ) continue;
580 /* Skip heading spaces */
582 while( *psz_cmd == ' ' )
587 /* Split psz_cmd at the first space and make sure that
588 * psz_arg is valid */
589 psz_arg = strchr( psz_cmd, ' ' );
593 while( *psz_arg == ' ' )
603 /* module specfic commands: @<module name> <command> <args...> */
604 if( *psz_cmd == '@' && *psz_arg )
606 /* Parse miscellaneous commands */
607 char *psz_alias = psz_cmd + 1;
608 char *psz_mycmd = strdup( psz_arg );
609 char *psz_myarg = strchr( psz_mycmd, ' ' );
614 msg_rc( "Not enough parameters." );
621 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
632 /* If the user typed a registered local command, try it */
633 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
638 val.psz_string = psz_arg;
639 i_ret = var_Set( p_intf, psz_cmd, val );
640 msg_rc( "%s: returned %i (%s)",
641 psz_cmd, i_ret, vlc_error( i_ret ) );
643 /* Or maybe it's a global command */
644 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
649 val.psz_string = psz_arg;
650 /* FIXME: it's a global command, but we should pass the
651 * local object as an argument, not p_intf->p_libvlc. */
652 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
655 msg_rc( "%s: returned %i (%s)",
656 psz_cmd, i_ret, vlc_error( i_ret ) );
659 else if( !strcmp( psz_cmd, "logout" ) )
661 /* Close connection */
662 if( p_intf->p_sys->i_socket != -1 )
664 net_Close( p_intf->p_sys->i_socket );
666 p_intf->p_sys->i_socket = -1;
668 else if( !strcmp( psz_cmd, "info" ) )
673 vlc_mutex_lock( &input_GetItem(p_input)->lock );
674 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
676 info_category_t *p_category = input_GetItem(p_input)
679 msg_rc( "+----[ %s ]", p_category->psz_name );
681 for ( j = 0; j < p_category->i_infos; j++ )
683 info_t *p_info = p_category->pp_infos[j];
684 msg_rc( "| %s: %s", p_info->psz_name,
689 msg_rc( "+----[ end of stream info ]" );
690 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
694 msg_rc( "no input" );
697 else if( !strcmp( psz_cmd, "is_playing" ) )
708 else if( !strcmp( psz_cmd, "get_time" ) )
717 var_Get( p_input, "time", &time );
718 msg_rc( "%i", time.i_time / 1000000);
721 else if( !strcmp( psz_cmd, "get_length" ) )
730 var_Get( p_input, "length", &time );
731 msg_rc( "%i", time.i_time / 1000000);
734 else if( !strcmp( psz_cmd, "get_title" ) )
742 msg_rc( "%s", input_GetItem(p_input)->psz_name );
745 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
746 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
748 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
749 b_longhelp = VLC_TRUE;
750 else b_longhelp = VLC_FALSE;
752 Help( p_intf, b_longhelp );
754 else if( !strcmp( psz_cmd, "check-updates" ) )
756 checkUpdates( p_intf, psz_arg );
758 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
760 var_SetInteger( p_intf->p_libvlc, "key-pressed",
761 config_GetInt( p_intf, psz_arg ) );
763 else switch( psz_cmd[0] )
769 vout_thread_t *p_vout;
770 p_vout = vlc_object_find( p_input,
771 VLC_OBJECT_VOUT, FIND_CHILD );
776 vlc_bool_t b_update = VLC_FALSE;
777 var_Get( p_vout, "fullscreen", &val );
778 val.b_bool = !val.b_bool;
779 if( !strncmp( psz_arg, "on", 2 )
780 && ( val.b_bool == VLC_TRUE ) )
783 val.b_bool = VLC_TRUE;
785 else if( !strncmp( psz_arg, "off", 3 )
786 && ( val.b_bool == VLC_FALSE ) )
789 val.b_bool = VLC_FALSE;
791 else if( strncmp( psz_arg, "off", 3 )
792 && strncmp( psz_arg, "on", 2 ) )
794 if( b_update ) var_Set( p_vout, "fullscreen", val );
795 vlc_object_release( p_vout );
806 /* Ignore empty lines */
810 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
814 /* Command processed */
815 i_size = 0; p_buffer[0] = 0;
818 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
819 msg_rc( STATUS_CHANGE "( quit )" );
823 var_DelCallback( p_input, "state", StateChanged, p_intf );
824 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
825 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
826 var_DelCallback( p_input, "rate", RateChanged, p_intf );
827 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
828 vlc_object_release( p_input );
834 vlc_object_release( p_playlist );
838 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
841 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
843 msg_rc(_("+----[ Remote control commands ]"));
845 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
846 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
847 msg_rc(_("| playlist . . . . . show items currently in playlist"));
848 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
849 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
850 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
851 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
852 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
853 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
854 msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
855 msg_rc(_("| random [on|off] . . . . . . . toggle random jumping"));
856 msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
857 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
858 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
859 msg_rc(_("| title_n . . . . . . . . next title in current item"));
860 msg_rc(_("| title_p . . . . . . previous title in current item"));
861 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
862 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
863 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
865 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
866 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
867 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
868 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
869 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
870 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
871 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
872 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
873 msg_rc(_("| info . . . . . information about the current stream"));
874 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
875 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
876 msg_rc(_("| get_title . . . . . the title of the current stream"));
877 msg_rc(_("| get_length . . . . the length of the current stream"));
879 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
880 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
881 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
882 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
883 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
884 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
885 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
886 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
887 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
888 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
889 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
890 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
891 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
892 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
897 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
898 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
899 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
900 msg_rc(_("| @name marq-position #. . . .relative position control"));
901 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
902 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
903 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
904 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
906 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
907 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
908 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
909 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
910 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
912 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
913 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
914 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
915 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
916 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
917 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
918 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
919 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
920 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
921 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
922 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
923 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
924 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
925 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
927 msg_rc(_("| check-updates [newer] [equal] [older]\n"
928 "| [undef] [info] [source] [binary] [plugin]"));
931 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
932 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
933 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
934 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
936 msg_rc(_("+----[ end of help ]"));
939 /********************************************************************
940 * Status callback routines
941 ********************************************************************/
942 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
943 vlc_value_t oldval, vlc_value_t newval, void *p_data )
945 intf_thread_t *p_intf = (intf_thread_t*)p_data;
946 input_thread_t *p_input = NULL;
948 vlc_mutex_lock( &p_intf->p_sys->status_lock );
949 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
952 msg_rc( STATUS_CHANGE "( time-offset: %d )",
953 var_GetInteger( p_input, "time-offset" ) );
954 vlc_object_release( p_input );
956 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
960 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
961 vlc_value_t oldval, vlc_value_t newval, void *p_data )
963 intf_thread_t *p_intf = (intf_thread_t*)p_data;
965 vlc_mutex_lock( &p_intf->p_sys->status_lock );
966 msg_rc( STATUS_CHANGE "( audio volume: %d )",
967 config_GetInt( p_this, "volume") );
968 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
972 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
973 vlc_value_t oldval, vlc_value_t newval, void *p_data )
975 intf_thread_t *p_intf = (intf_thread_t*)p_data;
976 playlist_t *p_playlist = NULL;
977 input_thread_t *p_input = NULL;
979 vlc_mutex_lock( &p_intf->p_sys->status_lock );
980 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
983 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
987 switch( p_playlist->status.i_status )
989 case PLAYLIST_STOPPED:
990 strncpy( &cmd[0], "stop", 4);
993 case PLAYLIST_RUNNING:
994 strncpy( &cmd[0], "play", 4);
997 case PLAYLIST_PAUSED:
998 strncpy( &cmd[0], "pause", 5);
1001 } /* var_GetInteger( p_input, "state" ) */
1002 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1003 vlc_object_release( p_playlist );
1005 vlc_object_release( p_input );
1007 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1011 static int RateChanged( 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_data;
1015 input_thread_t *p_input = NULL;
1017 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1018 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1021 msg_rc( STATUS_CHANGE "( new rate: %d )",
1022 var_GetInteger( p_input, "rate" ) );
1023 vlc_object_release( p_input );
1025 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1029 /********************************************************************
1031 ********************************************************************/
1032 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1033 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1035 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1036 input_thread_t *p_input;
1039 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1040 if( !p_input ) return VLC_ENOOBJ;
1042 var_Get( p_input, "state", &val );
1043 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1044 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1046 msg_rc( _("Press menu select or pause to continue.") );
1047 vlc_object_release( p_input );
1048 return VLC_EGENERIC;
1051 /* Parse commands that only require an input */
1052 if( !strcmp( psz_cmd, "pause" ) )
1054 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1055 var_Set( p_intf->p_libvlc, "key-pressed", val );
1056 vlc_object_release( p_input );
1059 else if( !strcmp( psz_cmd, "seek" ) )
1061 if( strlen( newval.psz_string ) > 0 &&
1062 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1064 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1065 var_Set( p_input, "position", val );
1069 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1070 var_Set( p_input, "time", val );
1072 vlc_object_release( p_input );
1075 else if ( !strcmp( psz_cmd, "fastforward" ) )
1077 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1078 var_Set( p_intf->p_libvlc, "key-pressed", val );
1079 vlc_object_release( p_input );
1082 else if ( !strcmp( psz_cmd, "rewind" ) )
1084 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1085 var_Set( p_intf->p_libvlc, "key-pressed", val );
1086 vlc_object_release( p_input );
1089 else if ( !strcmp( psz_cmd, "faster" ) )
1091 var_Set( p_input, "rate-faster", val );
1092 vlc_object_release( p_input );
1095 else if ( !strcmp( psz_cmd, "slower" ) )
1097 var_Set( p_input, "rate-slower", val );
1098 vlc_object_release( p_input );
1101 else if ( !strcmp( psz_cmd, "normal" ) )
1103 val.i_int = INPUT_RATE_DEFAULT;
1104 var_Set( p_input, "rate", val );
1105 vlc_object_release( p_input );
1108 else if( !strcmp( psz_cmd, "chapter" ) ||
1109 !strcmp( psz_cmd, "chapter_n" ) ||
1110 !strcmp( psz_cmd, "chapter_p" ) )
1112 if( !strcmp( psz_cmd, "chapter" ) )
1114 if ( *newval.psz_string )
1117 val.i_int = atoi( newval.psz_string );
1118 var_Set( p_input, "chapter", val );
1122 vlc_value_t val_list;
1125 var_Get( p_input, "chapter", &val );
1126 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1128 msg_rc( "Currently playing chapter %d/%d.",
1129 val.i_int, val_list.p_list->i_count );
1130 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1134 else if( !strcmp( psz_cmd, "chapter_n" ) )
1136 val.b_bool = VLC_TRUE;
1137 var_Set( p_input, "next-chapter", val );
1139 else if( !strcmp( psz_cmd, "chapter_p" ) )
1141 val.b_bool = VLC_TRUE;
1142 var_Set( p_input, "prev-chapter", val );
1144 vlc_object_release( p_input );
1147 else if( !strcmp( psz_cmd, "title" ) ||
1148 !strcmp( psz_cmd, "title_n" ) ||
1149 !strcmp( psz_cmd, "title_p" ) )
1151 if( !strcmp( psz_cmd, "title" ) )
1153 if ( *newval.psz_string )
1156 val.i_int = atoi( newval.psz_string );
1157 var_Set( p_input, "title", val );
1161 vlc_value_t val_list;
1164 var_Get( p_input, "title", &val );
1165 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1167 msg_rc( "Currently playing title %d/%d.",
1168 val.i_int, val_list.p_list->i_count );
1169 var_Change( p_this, "title", VLC_VAR_FREELIST,
1173 else if( !strcmp( psz_cmd, "title_n" ) )
1175 val.b_bool = VLC_TRUE;
1176 var_Set( p_input, "next-title", val );
1178 else if( !strcmp( psz_cmd, "title_p" ) )
1180 val.b_bool = VLC_TRUE;
1181 var_Set( p_input, "prev-title", val );
1184 vlc_object_release( p_input );
1187 else if( !strcmp( psz_cmd, "atrack" )
1188 || !strcmp( psz_cmd, "vtrack" )
1189 || !strcmp( psz_cmd, "strack" ) )
1191 const char *psz_variable;
1192 vlc_value_t val_name;
1195 if( !strcmp( psz_cmd, "atrack" ) )
1197 psz_variable = "audio-es";
1199 else if( !strcmp( psz_cmd, "vtrack" ) )
1201 psz_variable = "video-es";
1205 psz_variable = "spu-es";
1208 /* Get the descriptive name of the variable */
1209 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1211 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1213 if( newval.psz_string && *newval.psz_string )
1217 val.i_int = atoi( newval.psz_string );
1219 i_error = var_Set( p_input, psz_variable, val );
1224 vlc_value_t val, text;
1227 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1229 vlc_object_release( p_input );
1230 return VLC_EGENERIC;
1232 i_value = val.i_int;
1234 if ( var_Change( p_input, psz_variable,
1235 VLC_VAR_GETLIST, &val, &text ) < 0 )
1237 vlc_object_release( p_input );
1238 return VLC_EGENERIC;
1241 msg_rc( "+----[ %s ]", val_name.psz_string );
1242 for ( i = 0; i < val.p_list->i_count; i++ )
1244 if ( i_value == val.p_list->p_values[i].i_int )
1245 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1246 text.p_list->p_values[i].psz_string );
1248 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1249 text.p_list->p_values[i].psz_string );
1251 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1253 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1255 if( val_name.psz_string ) free( val_name.psz_string );
1257 i_error = VLC_SUCCESS;
1259 vlc_object_release( p_input );
1263 /* Never reached. */
1264 vlc_object_release( p_input );
1265 return VLC_EGENERIC;
1268 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1269 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1273 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1274 playlist_t *p_playlist = pl_Yield( p_this );
1277 if( p_playlist->p_input )
1279 var_Get( p_playlist->p_input, "state", &val );
1280 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1282 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1283 vlc_object_release( p_playlist );
1285 return VLC_EGENERIC;
1290 /* Parse commands that require a playlist */
1291 if( !strcmp( psz_cmd, "prev" ) )
1293 playlist_Prev( p_playlist );
1295 else if( !strcmp( psz_cmd, "next" ) )
1297 playlist_Next( p_playlist );
1299 else if( !strcmp( psz_cmd, "play" ) )
1301 msg_Warn( p_playlist, "play" );
1302 playlist_Play( p_playlist );
1304 else if( !strcmp( psz_cmd, "repeat" ) )
1306 vlc_bool_t b_update = VLC_TRUE;
1308 var_Get( p_playlist, "repeat", &val );
1310 if( strlen( newval.psz_string ) > 0 )
1312 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1313 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1315 b_update = VLC_FALSE;
1321 val.b_bool = !val.b_bool;
1322 var_Set( p_playlist, "repeat", val );
1324 msg_rc( "Setting repeat to %d", val.b_bool );
1326 else if( !strcmp( psz_cmd, "loop" ) )
1328 vlc_bool_t b_update = VLC_TRUE;
1330 var_Get( p_playlist, "loop", &val );
1332 if( strlen( newval.psz_string ) > 0 )
1334 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1335 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1337 b_update = VLC_FALSE;
1343 val.b_bool = !val.b_bool;
1344 var_Set( p_playlist, "loop", val );
1346 msg_rc( "Setting loop to %d", val.b_bool );
1348 else if( !strcmp( psz_cmd, "random" ) )
1350 vlc_bool_t b_update = VLC_TRUE;
1352 var_Get( p_playlist, "random", &val );
1354 if( strlen( newval.psz_string ) > 0 )
1356 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1357 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1359 b_update = VLC_FALSE;
1365 val.b_bool = !val.b_bool;
1366 var_Set( p_playlist, "random", val );
1368 msg_rc( "Setting random to %d", val.b_bool );
1370 else if (!strcmp( psz_cmd, "goto" ) )
1372 int i_pos = atoi( newval.psz_string );
1373 /* The playlist stores 2 times the same item: onelevel & category */
1374 int i_size = p_playlist->items.i_size / 2;
1377 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1378 else if( i_pos <= i_size )
1380 playlist_item_t *p_item, *p_parent;
1381 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1382 while( p_parent->p_parent )
1383 p_parent = p_parent->p_parent;
1384 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE,
1388 msg_rc( _("Playlist has only %d elements"), i_size );
1390 else if( !strcmp( psz_cmd, "stop" ) )
1392 playlist_Stop( p_playlist );
1394 else if( !strcmp( psz_cmd, "clear" ) )
1396 playlist_Stop( p_playlist );
1397 playlist_Clear( p_playlist, VLC_FALSE );
1399 else if( !strcmp( psz_cmd, "add" ) &&
1400 newval.psz_string && *newval.psz_string )
1402 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1406 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1407 playlist_AddInput( p_playlist, p_item,
1408 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1412 else if( !strcmp( psz_cmd, "enqueue" ) &&
1413 newval.psz_string && *newval.psz_string )
1415 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1419 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1420 playlist_AddInput( p_playlist, p_item,
1421 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1425 else if( !strcmp( psz_cmd, "playlist" ) )
1427 msg_Dbg( p_playlist, "Dumping category" );
1428 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1429 msg_Dbg( p_playlist, "Dumping Onelevel" );
1430 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1432 else if( !strcmp( psz_cmd, "sort" ))
1434 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1435 SORT_ARTIST, ORDER_NORMAL );
1437 else if( !strcmp( psz_cmd, "status" ) )
1439 if( p_playlist->p_input )
1441 /* Replay the current state of the system. */
1443 input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1444 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1446 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1447 config_GetInt( p_intf, "volume" ));
1449 vlc_mutex_lock( &p_playlist->object_lock );
1450 switch( p_playlist->status.i_status )
1452 case PLAYLIST_STOPPED:
1453 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1455 case PLAYLIST_RUNNING:
1456 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1458 case PLAYLIST_PAUSED:
1459 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1462 msg_rc( STATUS_CHANGE "( state unknown )" );
1465 vlc_mutex_unlock( &p_playlist->object_lock );
1474 msg_rc( "unknown command!" );
1477 vlc_object_release( p_playlist );
1481 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1482 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1484 playlist_t *p_playlist;
1486 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1489 playlist_Stop( p_playlist );
1490 vlc_object_release( p_playlist );
1492 vlc_object_kill( p_this->p_libvlc );
1496 static int Intf( 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_newintf = NULL;
1501 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1504 if( intf_RunThread( p_newintf ) )
1506 vlc_object_detach( p_newintf );
1507 intf_Destroy( p_newintf );
1514 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1515 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1517 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1518 input_thread_t *p_input = NULL;
1519 int i_error = VLC_EGENERIC;
1521 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1529 var_Get( p_input, "state", &val );
1530 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1532 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1533 vlc_object_release( p_input );
1534 return VLC_EGENERIC;
1536 vlc_object_release( p_input );
1539 if ( *newval.psz_string )
1542 audio_volume_t i_volume = atoi( newval.psz_string );
1543 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1545 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1547 i_error = VLC_EBADVAR;
1551 if( i_volume == AOUT_VOLUME_MIN )
1555 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1556 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1558 i_error = aout_VolumeSet( p_this, i_volume );
1559 osd_Volume( p_this );
1560 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1566 audio_volume_t i_volume;
1567 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1569 i_error = VLC_EGENERIC;
1573 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1574 i_error = VLC_SUCCESS;
1581 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1582 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1584 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1585 audio_volume_t i_volume;
1586 input_thread_t *p_input = NULL;
1587 int i_nb_steps = atoi(newval.psz_string);
1588 int i_error = VLC_SUCCESS;
1589 int i_volume_step = 0;
1591 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1599 var_Get( p_input, "state", &val );
1600 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1602 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1603 vlc_object_release( p_input );
1604 return VLC_EGENERIC;
1606 vlc_object_release( p_input );
1609 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1610 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1615 if ( !strcmp(psz_cmd, "volup") )
1617 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1618 i_error = VLC_EGENERIC;
1622 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1623 i_error = VLC_EGENERIC;
1625 osd_Volume( p_this );
1627 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1632 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1633 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1635 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1636 input_thread_t *p_input = NULL;
1637 vout_thread_t * p_vout;
1638 const char * psz_variable;
1641 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1645 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1646 vlc_object_release( p_input );
1650 if( !strcmp( psz_cmd, "vcrop" ) )
1652 psz_variable = "crop";
1654 else if( !strcmp( psz_cmd, "vratio" ) )
1656 psz_variable = "aspect-ratio";
1658 else if( !strcmp( psz_cmd, "vzoom" ) )
1660 psz_variable = "zoom";
1662 else if( !strcmp( psz_cmd, "snapshot" ) )
1664 psz_variable = "video-snapshot";
1667 if( newval.psz_string && *newval.psz_string )
1670 if( !strcmp( psz_variable, "zoom" ) )
1673 val.f_float = atof( newval.psz_string );
1674 i_error = var_Set( p_vout, psz_variable, val );
1678 i_error = var_Set( p_vout, psz_variable, newval );
1681 else if( !strcmp( psz_cmd, "snapshot" ) )
1683 i_error = var_Set( p_vout, psz_variable, newval );
1688 vlc_value_t val_name;
1689 vlc_value_t val, text;
1692 char *psz_value = NULL;
1694 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1696 vlc_object_release( p_vout );
1697 return VLC_EGENERIC;
1699 if( !strcmp( psz_variable, "zoom" ) )
1701 f_value = val.f_float;
1705 psz_value = strdup( val.psz_string );
1708 if ( var_Change( p_vout, psz_variable,
1709 VLC_VAR_GETLIST, &val, &text ) < 0 )
1711 vlc_object_release( p_vout );
1712 return VLC_EGENERIC;
1715 /* Get the descriptive name of the variable */
1716 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1718 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1720 msg_rc( "+----[ %s ]", val_name.psz_string );
1721 if( !strcmp( psz_variable, "zoom" ) )
1723 for ( i = 0; i < val.p_list->i_count; i++ )
1725 if ( f_value == val.p_list->p_values[i].f_float )
1726 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1727 text.p_list->p_values[i].psz_string );
1729 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1730 text.p_list->p_values[i].psz_string );
1735 for ( i = 0; i < val.p_list->i_count; i++ )
1737 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1738 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1739 text.p_list->p_values[i].psz_string );
1741 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1742 text.p_list->p_values[i].psz_string );
1746 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1748 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1750 if( val_name.psz_string ) free( val_name.psz_string );
1752 i_error = VLC_SUCCESS;
1754 vlc_object_release( p_vout );
1758 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1759 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1761 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1762 input_thread_t *p_input = NULL;
1763 aout_instance_t * p_aout;
1764 const char * psz_variable;
1765 vlc_value_t val_name;
1768 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1776 var_Get( p_input, "state", &val );
1777 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1778 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1779 vlc_object_release( p_input );
1780 return VLC_EGENERIC;
1782 vlc_object_release( p_input );
1785 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1786 if ( p_aout == NULL ) return VLC_ENOOBJ;
1788 if ( !strcmp( psz_cmd, "adev" ) )
1790 psz_variable = "audio-device";
1794 psz_variable = "audio-channels";
1797 /* Get the descriptive name of the variable */
1798 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1800 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1802 if ( !*newval.psz_string )
1804 /* Retrieve all registered ***. */
1805 vlc_value_t val, text;
1808 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1810 vlc_object_release( (vlc_object_t *)p_aout );
1811 return VLC_EGENERIC;
1813 i_value = val.i_int;
1815 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1816 VLC_VAR_GETLIST, &val, &text ) < 0 )
1818 vlc_object_release( (vlc_object_t *)p_aout );
1819 return VLC_EGENERIC;
1822 msg_rc( "+----[ %s ]", val_name.psz_string );
1823 for ( i = 0; i < val.p_list->i_count; i++ )
1825 if ( i_value == val.p_list->p_values[i].i_int )
1826 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1827 text.p_list->p_values[i].psz_string );
1829 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1830 text.p_list->p_values[i].psz_string );
1832 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1834 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1836 if( val_name.psz_string ) free( val_name.psz_string );
1837 i_error = VLC_SUCCESS;
1842 val.i_int = atoi( newval.psz_string );
1844 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1846 vlc_object_release( (vlc_object_t *)p_aout );
1851 /* OSD menu commands */
1852 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1853 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1855 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1856 playlist_t *p_playlist = NULL;
1858 int i_error = VLC_EGENERIC;
1860 if ( !*newval.psz_string )
1862 msg_rc( _("Please provide one of the following parameters:") );
1863 msg_rc( "[on|off|up|down|left|right|select]" );
1867 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1871 if( p_playlist->p_input )
1873 var_Get( p_playlist->p_input, "state", &val );
1874 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1875 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1877 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1878 vlc_object_release( p_playlist );
1879 return VLC_EGENERIC;
1882 vlc_object_release( p_playlist );
1884 val.psz_string = strdup( newval.psz_string );
1885 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1886 osd_MenuShow( p_this );
1887 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1888 osd_MenuHide( p_this );
1889 else if( !strcmp( val.psz_string, "up" ) )
1890 osd_MenuUp( p_this );
1891 else if( !strcmp( val.psz_string, "down" ) )
1892 osd_MenuDown( p_this );
1893 else if( !strcmp( val.psz_string, "left" ) )
1894 osd_MenuPrev( p_this );
1895 else if( !strcmp( val.psz_string, "right" ) )
1896 osd_MenuNext( p_this );
1897 else if( !strcmp( val.psz_string, "select" ) )
1898 osd_MenuActivate( p_this );
1901 msg_rc( _("Please provide one of the following parameters:") );
1902 msg_rc( "[on|off|up|down|left|right|select]" );
1903 if( val.psz_string ) free( val.psz_string );
1907 i_error = VLC_SUCCESS;
1908 if( val.psz_string ) free( val.psz_string );
1913 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1915 INPUT_RECORD input_record;
1918 /* On Win32, select() only works on socket descriptors */
1919 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1920 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1922 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1923 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1926 if( input_record.EventType != KEY_EVENT ||
1927 !input_record.Event.KeyEvent.bKeyDown ||
1928 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1929 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1930 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1931 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1933 /* nothing interesting */
1937 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1939 /* Echo out the command */
1940 putc( p_buffer[ *pi_size ], stdout );
1942 /* Handle special keys */
1943 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1945 putc( '\n', stdout );
1948 switch( p_buffer[ *pi_size ] )
1954 putc( ' ', stdout );
1955 putc( '\b', stdout );
1966 if( *pi_size == MAX_LINE_LENGTH ||
1967 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1969 p_buffer[ *pi_size ] = 0;
1978 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1983 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1984 return ReadWin32( p_intf, p_buffer, pi_size );
1985 else if( p_intf->p_sys->i_socket == -1 )
1987 msleep( INTF_IDLE_SLEEP );
1992 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1993 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
1994 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1995 (uint8_t *)p_buffer + *pi_size, 1, VLC_FALSE ) ) > 0 )
1997 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2003 /* Connection closed */
2006 if( p_intf->p_sys->i_socket != -1 )
2008 net_Close( p_intf->p_sys->i_socket );
2009 p_intf->p_sys->i_socket = -1;
2012 /* Standard input closed: exit */
2013 vlc_object_kill( p_intf );
2015 p_buffer[ *pi_size ] = 0;
2019 if( *pi_size == MAX_LINE_LENGTH ||
2020 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2022 p_buffer[ *pi_size ] = 0;
2029 /*****************************************************************************
2030 * parse_MRL: build a input item from a full mrl
2031 *****************************************************************************
2032 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2033 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2034 * space is a new option. Should be good enough for our purpose.
2035 *****************************************************************************/
2036 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2038 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2039 #define SKIPTRAILINGSPACE( p, d ) \
2040 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2042 input_item_t *p_item = NULL;
2043 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2044 char **ppsz_options = NULL;
2045 int i, i_options = 0;
2047 if( !psz_mrl ) return 0;
2049 psz_mrl = psz_orig = strdup( psz_mrl );
2052 SKIPSPACE( psz_mrl );
2055 for( ; *psz_mrl; psz_mrl++ )
2057 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2059 /* We have a complete item */
2062 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2063 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2065 /* We have a complete item */
2070 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2071 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2073 /* Remove '"' and '\'' if necessary */
2074 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2075 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2076 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2077 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2079 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2080 else if( *psz_item )
2083 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2084 ppsz_options[i_options - 1] = &psz_item[1];
2087 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2090 /* Now create a playlist item */
2093 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2094 for( i = 0; i < i_options; i++ )
2096 input_ItemAddOption( p_item, ppsz_options[i] );
2100 if( i_options ) free( ppsz_options );
2106 /*****************************************************************************
2107 * checkUpdates : check for updates
2108 ****************************************************************************/
2109 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2111 update_iterator_t *p_uit;
2112 update_t *p_u = update_New( p_intf );
2113 if( p_u == NULL ) return;
2114 p_uit = update_iterator_New( p_u );
2119 if( strstr( psz_arg, "newer" ) )
2120 s |= UPDATE_RELEASE_STATUS_NEWER;
2121 if( strstr( psz_arg, "equal" ) )
2122 s |= UPDATE_RELEASE_STATUS_EQUAL;
2123 if( strstr( psz_arg, "older" ) )
2124 s |= UPDATE_RELEASE_STATUS_OLDER;
2125 if( s ) p_uit->i_rs = s;
2126 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2128 if( strstr( psz_arg, "undef" ) )
2129 t |= UPDATE_FILE_TYPE_UNDEF;
2130 if( strstr( psz_arg, "info" ) )
2131 t |= UPDATE_FILE_TYPE_INFO;
2132 if( strstr( psz_arg, "source" ) )
2133 t |= UPDATE_FILE_TYPE_SOURCE;
2134 if( strstr( psz_arg, "binary" ) )
2135 t |= UPDATE_FILE_TYPE_BINARY;
2136 if( strstr( psz_arg, "plugin" ) )
2137 t |= UPDATE_FILE_TYPE_PLUGIN;
2138 if( t ) p_uit->i_t = t;
2140 update_Check( p_u, VLC_FALSE );
2141 update_iterator_Action( p_uit, UPDATE_MIRROR );
2142 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2143 p_uit->mirror.psz_name,
2144 p_uit->mirror.psz_location,
2145 p_uit->mirror.psz_type );
2146 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2149 if( s & UPDATE_RELEASE )
2151 switch( p_uit->release.i_status )
2153 case UPDATE_RELEASE_STATUS_OLDER:
2154 psz_tmp = strdup( "older" );
2156 case UPDATE_RELEASE_STATUS_EQUAL:
2157 psz_tmp = strdup( "equal" );
2159 case UPDATE_RELEASE_STATUS_NEWER:
2160 psz_tmp = strdup( "newer" );
2163 psz_tmp = strdup( "?!?" );
2166 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2167 p_uit->release.psz_version,
2168 p_uit->release.psz_svn_revision,
2172 switch( p_uit->file.i_type )
2174 case UPDATE_FILE_TYPE_UNDEF:
2175 psz_tmp = strdup( "undef" );
2177 case UPDATE_FILE_TYPE_INFO:
2178 psz_tmp = strdup( "info" );
2180 case UPDATE_FILE_TYPE_SOURCE:
2181 psz_tmp = strdup( "source" );
2183 case UPDATE_FILE_TYPE_BINARY:
2184 psz_tmp = strdup( "binary" );
2186 case UPDATE_FILE_TYPE_PLUGIN:
2187 psz_tmp = strdup( "plugin" );
2190 psz_tmp = strdup( "?!?" );
2193 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2195 if( p_uit->file.l_size )
2197 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2198 asprintf( &psz_tmp, "(%ld GB)",
2199 p_uit->file.l_size / (1024*1024*1024) );
2200 if( p_uit->file.l_size > 1024 * 1024 )
2201 asprintf( &psz_tmp, "(%ld MB)",
2202 p_uit->file.l_size / (1024*1024) );
2203 else if( p_uit->file.l_size > 1024 )
2204 asprintf( &psz_tmp, "(%ld kB)",
2205 p_uit->file.l_size / 1024 );
2207 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2211 psz_tmp = strdup( "" );
2213 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2218 update_iterator_Delete( p_uit );
2220 update_Delete( p_u );