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 *****************************************************************************/
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_callbacks( Activate, Deactivate );
198 /*****************************************************************************
199 * Activate: initialize and create stuff
200 *****************************************************************************/
201 static int Activate( vlc_object_t *p_this )
203 intf_thread_t *p_intf = (intf_thread_t*)p_this;
204 char *psz_host, *psz_unix_path;
205 int *pi_socket = NULL;
208 #if defined(HAVE_ISATTY)
209 /* Check that stdin is a TTY */
210 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
212 msg_Warn( p_intf, "fd 0 is not a TTY" );
217 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
223 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
224 free( psz_unix_path );
227 struct sockaddr_un addr;
229 memset( &addr, 0, sizeof(struct sockaddr_un) );
231 msg_Dbg( p_intf, "trying UNIX socket" );
233 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
235 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
236 free( psz_unix_path );
240 addr.sun_family = AF_LOCAL;
241 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
242 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
244 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
245 && (errno == EADDRINUSE)
246 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
247 && (errno == ECONNREFUSED))
249 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
250 unlink (psz_unix_path);
252 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
254 msg_Err (p_intf, "cannot bind UNIX socket at %s: %s",
255 psz_unix_path, strerror (errno));
256 free (psz_unix_path);
257 net_Close (i_socket);
262 if( listen( i_socket, 1 ) )
264 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
265 free( psz_unix_path );
266 net_Close( i_socket );
270 /* FIXME: we need a core function to merge listening sockets sets */
271 pi_socket = calloc( 2, sizeof( int ) );
272 if( pi_socket == NULL )
274 free( psz_unix_path );
275 net_Close( i_socket );
278 pi_socket[0] = i_socket;
280 #endif /* AF_LOCAL */
284 if( ( pi_socket == NULL ) &&
285 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
289 vlc_UrlParse( &url, psz_host, 0 );
291 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
293 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
294 if( pi_socket == NULL )
296 msg_Warn( p_intf, "can't listen to %s port %i",
297 url.psz_host, url.i_port );
298 vlc_UrlClean( &url );
303 vlc_UrlClean( &url );
307 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
310 msg_Err( p_intf, "no memory" );
314 p_intf->p_sys->pi_socket_listen = pi_socket;
315 p_intf->p_sys->i_socket = -1;
316 p_intf->p_sys->psz_unix_path = psz_unix_path;
317 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
318 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
320 /* Non-buffered stdout */
321 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
323 p_intf->pf_run = Run;
326 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
327 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
332 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
336 /*****************************************************************************
337 * Deactivate: uninitialize and cleanup
338 *****************************************************************************/
339 static void Deactivate( vlc_object_t *p_this )
341 intf_thread_t *p_intf = (intf_thread_t*)p_this;
343 net_ListenClose( p_intf->p_sys->pi_socket_listen );
344 if( p_intf->p_sys->i_socket != -1 )
345 net_Close( p_intf->p_sys->i_socket );
346 if( p_intf->p_sys->psz_unix_path != NULL )
348 #if defined(AF_LOCAL) && !defined(WIN32)
349 unlink( p_intf->p_sys->psz_unix_path );
351 free( p_intf->p_sys->psz_unix_path );
353 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
354 free( p_intf->p_sys );
357 /*****************************************************************************
358 * RegisterCallbacks: Register callbacks to dynamic variables
359 *****************************************************************************/
360 static void RegisterCallbacks( intf_thread_t *p_intf )
362 /* Register commands that will be cleaned up upon object destruction */
363 #define ADD( name, type, target ) \
364 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
365 var_AddCallback( p_intf, name, target, NULL );
366 ADD( "quit", VOID, Quit )
367 ADD( "intf", STRING, Intf )
369 ADD( "add", STRING, Playlist )
370 ADD( "repeat", STRING, Playlist )
371 ADD( "loop", STRING, Playlist )
372 ADD( "enqueue", STRING, Playlist )
373 ADD( "playlist", VOID, Playlist )
374 ADD( "sort", VOID, Playlist )
375 ADD( "play", VOID, Playlist )
376 ADD( "stop", VOID, Playlist )
377 ADD( "clear", VOID, Playlist )
378 ADD( "prev", VOID, Playlist )
379 ADD( "next", VOID, Playlist )
380 ADD( "goto", INTEGER, Playlist )
381 ADD( "status", INTEGER, Playlist )
383 /* OSD menu commands */
384 ADD( "menu", STRING, Menu )
387 ADD( "pause", VOID, Input )
388 ADD( "seek", INTEGER, Input )
389 ADD( "title", STRING, Input )
390 ADD( "title_n", VOID, Input )
391 ADD( "title_p", VOID, Input )
392 ADD( "chapter", STRING, Input )
393 ADD( "chapter_n", VOID, Input )
394 ADD( "chapter_p", VOID, Input )
396 ADD( "fastforward", VOID, Input )
397 ADD( "rewind", VOID, Input )
398 ADD( "faster", VOID, Input )
399 ADD( "slower", VOID, Input )
400 ADD( "normal", VOID, Input )
402 ADD( "atrack", STRING, Input )
403 ADD( "vtrack", STRING, Input )
404 ADD( "strack", STRING, Input )
407 ADD( "vratio", STRING, VideoConfig )
408 ADD( "vcrop", STRING, VideoConfig )
409 ADD( "vzoom", STRING, VideoConfig )
412 ADD( "volume", STRING, Volume )
413 ADD( "volup", STRING, VolumeMove )
414 ADD( "voldown", STRING, VolumeMove )
415 ADD( "adev", STRING, AudioConfig )
416 ADD( "achan", STRING, AudioConfig )
421 /*****************************************************************************
423 *****************************************************************************
424 * This part of the interface is in a separate thread so that we can call
425 * exec() from within it without annoying the rest of the program.
426 *****************************************************************************/
427 static void Run( intf_thread_t *p_intf )
429 input_thread_t * p_input;
430 playlist_t * p_playlist;
432 char p_buffer[ MAX_LINE_LENGTH + 1 ];
433 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
434 vlc_bool_t b_longhelp = VLC_FALSE;
444 /* Register commands that will be cleaned up upon object destruction */
445 RegisterCallbacks( p_intf );
447 /* status callbacks */
448 /* Listen to audio volume updates */
449 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
452 /* Get the file descriptor of the console input */
453 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
454 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
456 msg_Err( p_intf, "couldn't find user input handle" );
457 vlc_object_kill( p_intf );
461 while( !intf_ShouldDie( p_intf ) )
463 char *psz_cmd, *psz_arg;
464 vlc_bool_t b_complete;
466 if( p_intf->p_sys->pi_socket_listen != NULL &&
467 p_intf->p_sys->i_socket == -1 )
469 p_intf->p_sys->i_socket =
470 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
472 if( p_intf->p_sys->i_socket == -1 ) continue;
475 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
477 /* Manage the input part */
478 if( p_input == NULL )
482 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
487 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
491 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
495 /* New input has been registered */
498 if( !p_input->b_dead || !p_input->b_die )
501 input_item_GetURI( input_GetItem( p_input ) );
502 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
504 msg_rc( STATUS_CHANGE "( audio volume: %d )",
505 config_GetInt( p_intf, "volume" ));
507 var_AddCallback( p_input, "state", StateChanged, p_intf );
508 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
509 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
510 var_AddCallback( p_input, "rate", RateChanged, p_intf );
511 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
515 else if( p_input->b_dead )
517 var_DelCallback( p_input, "state", StateChanged, p_intf );
518 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
519 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
520 var_DelCallback( p_input, "rate", RateChanged, p_intf );
521 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
523 vlc_object_release( p_input );
528 vlc_mutex_lock( &p_playlist->object_lock );
529 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
530 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
531 vlc_mutex_unlock( &p_playlist->object_lock );
535 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
536 (p_playlist != NULL) )
538 vlc_mutex_lock( &p_playlist->object_lock );
539 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
540 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
542 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
543 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
546 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
547 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
549 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
550 msg_rc( STATUS_CHANGE "( play state: 1 )" );
553 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
554 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
556 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
557 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
559 vlc_mutex_unlock( &p_playlist->object_lock );
562 if( p_input && b_showpos )
564 i_newpos = 100 * var_GetFloat( p_input, "position" );
565 if( i_oldpos != i_newpos )
568 msg_rc( "pos: %d%%", i_newpos );
572 /* Is there something to do? */
573 if( !b_complete ) continue;
576 /* Skip heading spaces */
578 while( *psz_cmd == ' ' )
583 /* Split psz_cmd at the first space and make sure that
584 * psz_arg is valid */
585 psz_arg = strchr( psz_cmd, ' ' );
589 while( *psz_arg == ' ' )
599 /* module specfic commands: @<module name> <command> <args...> */
600 if( *psz_cmd == '@' && *psz_arg )
602 /* Parse miscellaneous commands */
603 char *psz_alias = psz_cmd + 1;
604 char *psz_mycmd = strdup( psz_arg );
605 char *psz_myarg = strchr( psz_mycmd, ' ' );
610 msg_rc( "Not enough parameters." );
617 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
628 /* If the user typed a registered local command, try it */
629 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
634 val.psz_string = psz_arg;
635 i_ret = var_Set( p_intf, psz_cmd, val );
636 msg_rc( "%s: returned %i (%s)",
637 psz_cmd, i_ret, vlc_error( i_ret ) );
639 /* Or maybe it's a global command */
640 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
645 val.psz_string = psz_arg;
646 /* FIXME: it's a global command, but we should pass the
647 * local object as an argument, not p_intf->p_libvlc. */
648 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
651 msg_rc( "%s: returned %i (%s)",
652 psz_cmd, i_ret, vlc_error( i_ret ) );
655 else if( !strcmp( psz_cmd, "logout" ) )
657 /* Close connection */
658 if( p_intf->p_sys->i_socket != -1 )
660 net_Close( p_intf->p_sys->i_socket );
662 p_intf->p_sys->i_socket = -1;
664 else if( !strcmp( psz_cmd, "info" ) )
669 vlc_mutex_lock( &input_GetItem(p_input)->lock );
670 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
672 info_category_t *p_category = input_GetItem(p_input)
675 msg_rc( "+----[ %s ]", p_category->psz_name );
677 for ( j = 0; j < p_category->i_infos; j++ )
679 info_t *p_info = p_category->pp_infos[j];
680 msg_rc( "| %s: %s", p_info->psz_name,
685 msg_rc( "+----[ end of stream info ]" );
686 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
690 msg_rc( "no input" );
693 else if( !strcmp( psz_cmd, "is_playing" ) )
704 else if( !strcmp( psz_cmd, "get_time" ) )
713 var_Get( p_input, "time", &time );
714 msg_rc( "%i", time.i_time / 1000000);
717 else if( !strcmp( psz_cmd, "get_length" ) )
726 var_Get( p_input, "length", &time );
727 msg_rc( "%i", time.i_time / 1000000);
730 else if( !strcmp( psz_cmd, "get_title" ) )
738 msg_rc( "%s", input_GetItem(p_input)->psz_name );
741 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
742 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
744 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
745 b_longhelp = VLC_TRUE;
746 else b_longhelp = VLC_FALSE;
748 Help( p_intf, b_longhelp );
751 else if( !strcmp( psz_cmd, "check-updates" ) )
753 checkUpdates( p_intf, psz_arg );
756 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
758 var_SetInteger( p_intf->p_libvlc, "key-pressed",
759 config_GetInt( p_intf, psz_arg ) );
761 else switch( psz_cmd[0] )
767 vout_thread_t *p_vout;
768 p_vout = vlc_object_find( p_input,
769 VLC_OBJECT_VOUT, FIND_CHILD );
774 vlc_bool_t b_update = VLC_FALSE;
775 var_Get( p_vout, "fullscreen", &val );
776 val.b_bool = !val.b_bool;
777 if( !strncmp( psz_arg, "on", 2 )
778 && ( val.b_bool == VLC_TRUE ) )
781 val.b_bool = VLC_TRUE;
783 else if( !strncmp( psz_arg, "off", 3 )
784 && ( val.b_bool == VLC_FALSE ) )
787 val.b_bool = VLC_FALSE;
789 else if( strncmp( psz_arg, "off", 3 )
790 && strncmp( psz_arg, "on", 2 ) )
792 if( b_update ) var_Set( p_vout, "fullscreen", val );
793 vlc_object_release( p_vout );
804 /* Ignore empty lines */
808 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
812 /* Command processed */
813 i_size = 0; p_buffer[0] = 0;
816 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
817 msg_rc( STATUS_CHANGE "( quit )" );
821 var_DelCallback( p_input, "state", StateChanged, p_intf );
822 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
823 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
824 var_DelCallback( p_input, "rate", RateChanged, p_intf );
825 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
826 vlc_object_release( p_input );
832 vlc_object_release( p_playlist );
836 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
839 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
841 msg_rc(_("+----[ Remote control commands ]"));
843 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
844 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
845 msg_rc(_("| playlist . . . . . show items currently in playlist"));
846 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
847 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
848 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
849 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
850 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
851 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
852 msg_rc(_("| loop [on|off] . . . . . . toggle playlist item loop"));
853 msg_rc(_("| clear . . . . . . . . . . . . . clear the playlist"));
854 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
855 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
856 msg_rc(_("| title_n . . . . . . . . next title in current item"));
857 msg_rc(_("| title_p . . . . . . previous title in current item"));
858 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
859 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
860 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
862 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
863 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
864 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
865 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
866 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
867 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
868 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
869 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
870 msg_rc(_("| info . . . . . information about the current stream"));
871 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
872 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
873 msg_rc(_("| get_title . . . . . the title of the current stream"));
874 msg_rc(_("| get_length . . . . the length of the current stream"));
876 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
877 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
878 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
879 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
880 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
881 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
882 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
883 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
884 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
885 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
886 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
887 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
888 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
893 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
894 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
895 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
896 msg_rc(_("| @name marq-position #. . . .relative position control"));
897 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
898 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
899 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
900 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
902 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
903 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
904 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
905 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
906 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
908 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
909 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
910 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
911 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
912 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
913 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
914 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
915 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
916 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
917 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
918 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
919 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
920 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
921 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
923 msg_rc(_("| check-updates [newer] [equal] [older]\n"
924 "| [undef] [info] [source] [binary] [plugin]"));
927 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
928 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
929 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
930 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
932 msg_rc(_("+----[ end of help ]"));
935 /********************************************************************
936 * Status callback routines
937 ********************************************************************/
938 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
939 vlc_value_t oldval, vlc_value_t newval, void *p_data )
941 intf_thread_t *p_intf = (intf_thread_t*)p_data;
942 input_thread_t *p_input = NULL;
944 vlc_mutex_lock( &p_intf->p_sys->status_lock );
945 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
948 msg_rc( STATUS_CHANGE "( time-offset: %d )",
949 var_GetInteger( p_input, "time-offset" ) );
950 vlc_object_release( p_input );
952 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
956 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
957 vlc_value_t oldval, vlc_value_t newval, void *p_data )
959 intf_thread_t *p_intf = (intf_thread_t*)p_data;
961 vlc_mutex_lock( &p_intf->p_sys->status_lock );
962 msg_rc( STATUS_CHANGE "( audio volume: %d )",
963 config_GetInt( p_this, "volume") );
964 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
968 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
969 vlc_value_t oldval, vlc_value_t newval, void *p_data )
971 intf_thread_t *p_intf = (intf_thread_t*)p_data;
972 playlist_t *p_playlist = NULL;
973 input_thread_t *p_input = NULL;
975 vlc_mutex_lock( &p_intf->p_sys->status_lock );
976 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
979 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
983 switch( p_playlist->status.i_status )
985 case PLAYLIST_STOPPED:
986 strncpy( &cmd[0], "stop", 4);
989 case PLAYLIST_RUNNING:
990 strncpy( &cmd[0], "play", 4);
993 case PLAYLIST_PAUSED:
994 strncpy( &cmd[0], "pause", 5);
997 } /* var_GetInteger( p_input, "state" ) */
998 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
999 vlc_object_release( p_playlist );
1001 vlc_object_release( p_input );
1003 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1007 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1008 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1010 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1011 input_thread_t *p_input = NULL;
1013 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1014 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1017 msg_rc( STATUS_CHANGE "( new rate: %d )",
1018 var_GetInteger( p_input, "rate" ) );
1019 vlc_object_release( p_input );
1021 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1025 /********************************************************************
1027 ********************************************************************/
1028 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1029 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1031 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1032 input_thread_t *p_input;
1035 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1036 if( !p_input ) return VLC_ENOOBJ;
1038 var_Get( p_input, "state", &val );
1039 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1040 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1042 msg_rc( _("Press menu select or pause to continue.") );
1043 vlc_object_release( p_input );
1044 return VLC_EGENERIC;
1047 /* Parse commands that only require an input */
1048 if( !strcmp( psz_cmd, "pause" ) )
1050 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1051 var_Set( p_intf->p_libvlc, "key-pressed", val );
1052 vlc_object_release( p_input );
1055 else if( !strcmp( psz_cmd, "seek" ) )
1057 if( strlen( newval.psz_string ) > 0 &&
1058 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1060 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1061 var_Set( p_input, "position", val );
1065 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1066 var_Set( p_input, "time", val );
1068 vlc_object_release( p_input );
1071 else if ( !strcmp( psz_cmd, "fastforward" ) )
1073 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1074 var_Set( p_intf->p_libvlc, "key-pressed", val );
1075 vlc_object_release( p_input );
1078 else if ( !strcmp( psz_cmd, "rewind" ) )
1080 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1081 var_Set( p_intf->p_libvlc, "key-pressed", val );
1082 vlc_object_release( p_input );
1085 else if ( !strcmp( psz_cmd, "faster" ) )
1087 val.b_bool = VLC_TRUE;
1088 var_Set( p_input, "rate-faster", val );
1089 vlc_object_release( p_input );
1092 else if ( !strcmp( psz_cmd, "slower" ) )
1094 val.b_bool = VLC_TRUE;
1095 var_Set( p_input, "rate-slower", val );
1096 vlc_object_release( p_input );
1099 else if ( !strcmp( psz_cmd, "normal" ) )
1101 val.i_int = INPUT_RATE_DEFAULT;
1102 var_Set( p_input, "rate", val );
1103 vlc_object_release( p_input );
1106 else if( !strcmp( psz_cmd, "chapter" ) ||
1107 !strcmp( psz_cmd, "chapter_n" ) ||
1108 !strcmp( psz_cmd, "chapter_p" ) )
1110 if( !strcmp( psz_cmd, "chapter" ) )
1112 if ( *newval.psz_string )
1115 val.i_int = atoi( newval.psz_string );
1116 var_Set( p_input, "chapter", val );
1120 vlc_value_t val_list;
1123 var_Get( p_input, "chapter", &val );
1124 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1126 msg_rc( "Currently playing chapter %d/%d.",
1127 val.i_int, val_list.p_list->i_count );
1128 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1132 else if( !strcmp( psz_cmd, "chapter_n" ) )
1134 val.b_bool = VLC_TRUE;
1135 var_Set( p_input, "next-chapter", val );
1137 else if( !strcmp( psz_cmd, "chapter_p" ) )
1139 val.b_bool = VLC_TRUE;
1140 var_Set( p_input, "prev-chapter", val );
1142 vlc_object_release( p_input );
1145 else if( !strcmp( psz_cmd, "title" ) ||
1146 !strcmp( psz_cmd, "title_n" ) ||
1147 !strcmp( psz_cmd, "title_p" ) )
1149 if( !strcmp( psz_cmd, "title" ) )
1151 if ( *newval.psz_string )
1154 val.i_int = atoi( newval.psz_string );
1155 var_Set( p_input, "title", val );
1159 vlc_value_t val_list;
1162 var_Get( p_input, "title", &val );
1163 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1165 msg_rc( "Currently playing title %d/%d.",
1166 val.i_int, val_list.p_list->i_count );
1167 var_Change( p_this, "title", VLC_VAR_FREELIST,
1171 else if( !strcmp( psz_cmd, "title_n" ) )
1173 val.b_bool = VLC_TRUE;
1174 var_Set( p_input, "next-title", val );
1176 else if( !strcmp( psz_cmd, "title_p" ) )
1178 val.b_bool = VLC_TRUE;
1179 var_Set( p_input, "prev-title", val );
1182 vlc_object_release( p_input );
1185 else if( !strcmp( psz_cmd, "atrack" )
1186 || !strcmp( psz_cmd, "vtrack" )
1187 || !strcmp( psz_cmd, "strack" ) )
1189 const char *psz_variable;
1190 vlc_value_t val_name;
1193 if( !strcmp( psz_cmd, "atrack" ) )
1195 psz_variable = "audio-es";
1197 else if( !strcmp( psz_cmd, "vtrack" ) )
1199 psz_variable = "video-es";
1203 psz_variable = "spu-es";
1206 /* Get the descriptive name of the variable */
1207 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1209 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1211 if( newval.psz_string && *newval.psz_string )
1215 val.i_int = atoi( newval.psz_string );
1217 i_error = var_Set( p_input, psz_variable, val );
1222 vlc_value_t val, text;
1225 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1227 vlc_object_release( p_input );
1228 return VLC_EGENERIC;
1230 i_value = val.i_int;
1232 if ( var_Change( p_input, psz_variable,
1233 VLC_VAR_GETLIST, &val, &text ) < 0 )
1235 vlc_object_release( p_input );
1236 return VLC_EGENERIC;
1239 msg_rc( "+----[ %s ]", val_name.psz_string );
1240 for ( i = 0; i < val.p_list->i_count; i++ )
1242 if ( i_value == val.p_list->p_values[i].i_int )
1243 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1244 text.p_list->p_values[i].psz_string );
1246 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1247 text.p_list->p_values[i].psz_string );
1249 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1251 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1253 if( val_name.psz_string ) free( val_name.psz_string );
1255 i_error = VLC_SUCCESS;
1257 vlc_object_release( p_input );
1261 /* Never reached. */
1262 vlc_object_release( p_input );
1263 return VLC_EGENERIC;
1266 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1267 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1271 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1272 playlist_t *p_playlist = pl_Yield( p_this );
1275 if( p_playlist->p_input )
1277 var_Get( p_playlist->p_input, "state", &val );
1278 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1280 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1281 vlc_object_release( p_playlist );
1283 return VLC_EGENERIC;
1288 /* Parse commands that require a playlist */
1289 if( !strcmp( psz_cmd, "prev" ) )
1291 playlist_Prev( p_playlist );
1293 else if( !strcmp( psz_cmd, "next" ) )
1295 playlist_Next( p_playlist );
1297 else if( !strcmp( psz_cmd, "play" ) )
1299 msg_Warn( p_playlist, "play" );
1300 playlist_Play( p_playlist );
1302 else if( !strcmp( psz_cmd, "repeat" ) )
1304 vlc_bool_t b_update = VLC_TRUE;
1306 var_Get( p_playlist, "repeat", &val );
1308 if( strlen( newval.psz_string ) > 0 )
1310 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1311 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1313 b_update = VLC_FALSE;
1319 val.b_bool = !val.b_bool;
1320 var_Set( p_playlist, "repeat", val );
1322 msg_rc( "Setting repeat to %d", val.b_bool );
1324 else if( !strcmp( psz_cmd, "loop" ) )
1326 vlc_bool_t b_update = VLC_TRUE;
1328 var_Get( p_playlist, "loop", &val );
1330 if( strlen( newval.psz_string ) > 0 )
1332 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1333 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1335 b_update = VLC_FALSE;
1341 val.b_bool = !val.b_bool;
1342 var_Set( p_playlist, "loop", val );
1344 msg_rc( "Setting loop to %d", val.b_bool );
1346 else if (!strcmp( psz_cmd, "goto" ) )
1348 msg_rc( _("goto is deprecated" ) );
1349 msg_Err( p_playlist, "goto is deprecated" );
1351 else if( !strcmp( psz_cmd, "stop" ) )
1353 playlist_Stop( p_playlist );
1355 else if( !strcmp( psz_cmd, "clear" ) )
1357 playlist_Stop( p_playlist );
1358 playlist_Clear( p_playlist, VLC_FALSE );
1360 else if( !strcmp( psz_cmd, "add" ) &&
1361 newval.psz_string && *newval.psz_string )
1363 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1367 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1368 playlist_AddInput( p_playlist, p_item,
1369 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1373 else if( !strcmp( psz_cmd, "enqueue" ) &&
1374 newval.psz_string && *newval.psz_string )
1376 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1380 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1381 playlist_AddInput( p_playlist, p_item,
1382 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1386 else if( !strcmp( psz_cmd, "playlist" ) )
1388 msg_Dbg( p_playlist, "Dumping category" );
1389 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1390 msg_Dbg( p_playlist, "Dumping Onelevel" );
1391 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1393 else if( !strcmp( psz_cmd, "sort" ))
1395 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1396 SORT_ARTIST, ORDER_NORMAL );
1398 else if( !strcmp( psz_cmd, "status" ) )
1400 if( p_playlist->p_input )
1402 /* Replay the current state of the system. */
1404 input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1405 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1407 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1408 config_GetInt( p_intf, "volume" ));
1410 vlc_mutex_lock( &p_playlist->object_lock );
1411 switch( p_playlist->status.i_status )
1413 case PLAYLIST_STOPPED:
1414 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1416 case PLAYLIST_RUNNING:
1417 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1419 case PLAYLIST_PAUSED:
1420 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1423 msg_rc( STATUS_CHANGE "( state unknown )" );
1426 vlc_mutex_unlock( &p_playlist->object_lock );
1435 msg_rc( "unknown command!" );
1438 vlc_object_release( p_playlist );
1442 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1443 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1445 playlist_t *p_playlist;
1447 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1450 playlist_Stop( p_playlist );
1451 vlc_object_release( p_playlist );
1453 vlc_object_kill( p_this->p_libvlc );
1457 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1458 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1460 intf_thread_t *p_newintf = NULL;
1462 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1465 if( intf_RunThread( p_newintf ) )
1467 vlc_object_detach( p_newintf );
1468 intf_Destroy( p_newintf );
1475 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1476 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1478 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1479 input_thread_t *p_input = NULL;
1480 int i_error = VLC_EGENERIC;
1482 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1490 var_Get( p_input, "state", &val );
1491 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1493 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1494 vlc_object_release( p_input );
1495 return VLC_EGENERIC;
1497 vlc_object_release( p_input );
1500 if ( *newval.psz_string )
1503 audio_volume_t i_volume = atoi( newval.psz_string );
1504 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1506 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1508 i_error = VLC_EBADVAR;
1512 if( i_volume == AOUT_VOLUME_MIN )
1516 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1517 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1519 i_error = aout_VolumeSet( p_this, i_volume );
1520 osd_Volume( p_this );
1521 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1527 audio_volume_t i_volume;
1528 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1530 i_error = VLC_EGENERIC;
1534 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1535 i_error = VLC_SUCCESS;
1542 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1543 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1545 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1546 audio_volume_t i_volume;
1547 input_thread_t *p_input = NULL;
1548 int i_nb_steps = atoi(newval.psz_string);
1549 int i_error = VLC_SUCCESS;
1550 int i_volume_step = 0;
1552 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1560 var_Get( p_input, "state", &val );
1561 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1563 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1564 vlc_object_release( p_input );
1565 return VLC_EGENERIC;
1567 vlc_object_release( p_input );
1570 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1571 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1576 if ( !strcmp(psz_cmd, "volup") )
1578 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1579 i_error = VLC_EGENERIC;
1583 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1584 i_error = VLC_EGENERIC;
1586 osd_Volume( p_this );
1588 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1593 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1594 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1596 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1597 input_thread_t *p_input = NULL;
1598 vout_thread_t * p_vout;
1599 const char * psz_variable;
1600 vlc_value_t val_name;
1603 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1607 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1608 vlc_object_release( p_input );
1612 if( !strcmp( psz_cmd, "vcrop" ) )
1614 psz_variable = "crop";
1616 else if( !strcmp( psz_cmd, "vratio" ) )
1618 psz_variable = "aspect-ratio";
1620 else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1622 psz_variable = "zoom";
1626 /* Get the descriptive name of the variable */
1627 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1629 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1631 if( newval.psz_string && *newval.psz_string )
1634 if( !strcmp( psz_variable, "zoom" ) )
1637 val.f_float = atof( newval.psz_string );
1638 i_error = var_Set( p_vout, psz_variable, val );
1642 i_error = var_Set( p_vout, psz_variable, newval );
1648 vlc_value_t val, text;
1651 char *psz_value = NULL;
1653 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1655 vlc_object_release( p_vout );
1656 return VLC_EGENERIC;
1658 if( !strcmp( psz_variable, "zoom" ) )
1660 f_value = val.f_float;
1664 psz_value = strdup( val.psz_string );
1667 if ( var_Change( p_vout, psz_variable,
1668 VLC_VAR_GETLIST, &val, &text ) < 0 )
1670 vlc_object_release( p_vout );
1671 return VLC_EGENERIC;
1674 msg_rc( "+----[ %s ]", val_name.psz_string );
1675 if( !strcmp( psz_variable, "zoom" ) )
1677 for ( i = 0; i < val.p_list->i_count; i++ )
1679 if ( f_value == val.p_list->p_values[i].f_float )
1680 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1681 text.p_list->p_values[i].psz_string );
1683 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1684 text.p_list->p_values[i].psz_string );
1689 for ( i = 0; i < val.p_list->i_count; i++ )
1691 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1692 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1693 text.p_list->p_values[i].psz_string );
1695 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1696 text.p_list->p_values[i].psz_string );
1700 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1702 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1704 if( val_name.psz_string ) free( val_name.psz_string );
1706 i_error = VLC_SUCCESS;
1708 vlc_object_release( p_vout );
1712 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1713 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1715 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1716 input_thread_t *p_input = NULL;
1717 aout_instance_t * p_aout;
1718 const char * psz_variable;
1719 vlc_value_t val_name;
1722 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1730 var_Get( p_input, "state", &val );
1731 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1732 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1733 vlc_object_release( p_input );
1734 return VLC_EGENERIC;
1736 vlc_object_release( p_input );
1739 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1740 if ( p_aout == NULL ) return VLC_ENOOBJ;
1742 if ( !strcmp( psz_cmd, "adev" ) )
1744 psz_variable = "audio-device";
1748 psz_variable = "audio-channels";
1751 /* Get the descriptive name of the variable */
1752 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1754 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1756 if ( !*newval.psz_string )
1758 /* Retrieve all registered ***. */
1759 vlc_value_t val, text;
1762 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1764 vlc_object_release( (vlc_object_t *)p_aout );
1765 return VLC_EGENERIC;
1767 i_value = val.i_int;
1769 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1770 VLC_VAR_GETLIST, &val, &text ) < 0 )
1772 vlc_object_release( (vlc_object_t *)p_aout );
1773 return VLC_EGENERIC;
1776 msg_rc( "+----[ %s ]", val_name.psz_string );
1777 for ( i = 0; i < val.p_list->i_count; i++ )
1779 if ( i_value == val.p_list->p_values[i].i_int )
1780 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1781 text.p_list->p_values[i].psz_string );
1783 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1784 text.p_list->p_values[i].psz_string );
1786 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1788 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1790 if( val_name.psz_string ) free( val_name.psz_string );
1791 i_error = VLC_SUCCESS;
1796 val.i_int = atoi( newval.psz_string );
1798 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1800 vlc_object_release( (vlc_object_t *)p_aout );
1805 /* OSD menu commands */
1806 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1807 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1809 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1810 playlist_t *p_playlist = NULL;
1812 int i_error = VLC_EGENERIC;
1814 if ( !*newval.psz_string )
1816 msg_rc( _("Please provide one of the following parameters:") );
1817 msg_rc( "[on|off|up|down|left|right|select]" );
1821 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1825 if( p_playlist->p_input )
1827 var_Get( p_playlist->p_input, "state", &val );
1828 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1829 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1831 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1832 vlc_object_release( p_playlist );
1833 return VLC_EGENERIC;
1836 vlc_object_release( p_playlist );
1838 val.psz_string = strdup( newval.psz_string );
1839 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1840 osd_MenuShow( p_this );
1841 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1842 osd_MenuHide( p_this );
1843 else if( !strcmp( val.psz_string, "up" ) )
1844 osd_MenuUp( p_this );
1845 else if( !strcmp( val.psz_string, "down" ) )
1846 osd_MenuDown( p_this );
1847 else if( !strcmp( val.psz_string, "left" ) )
1848 osd_MenuPrev( p_this );
1849 else if( !strcmp( val.psz_string, "right" ) )
1850 osd_MenuNext( p_this );
1851 else if( !strcmp( val.psz_string, "select" ) )
1852 osd_MenuActivate( p_this );
1855 msg_rc( _("Please provide one of the following parameters:") );
1856 msg_rc( "[on|off|up|down|left|right|select]" );
1857 if( val.psz_string ) free( val.psz_string );
1861 i_error = VLC_SUCCESS;
1862 if( val.psz_string ) free( val.psz_string );
1867 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1869 INPUT_RECORD input_record;
1872 /* On Win32, select() only works on socket descriptors */
1873 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1874 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1876 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1877 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1880 if( input_record.EventType != KEY_EVENT ||
1881 !input_record.Event.KeyEvent.bKeyDown ||
1882 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1883 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1884 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1885 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1887 /* nothing interesting */
1891 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1893 /* Echo out the command */
1894 putc( p_buffer[ *pi_size ], stdout );
1896 /* Handle special keys */
1897 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1899 putc( '\n', stdout );
1902 switch( p_buffer[ *pi_size ] )
1908 putc( ' ', stdout );
1909 putc( '\b', stdout );
1920 if( *pi_size == MAX_LINE_LENGTH ||
1921 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1923 p_buffer[ *pi_size ] = 0;
1932 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1937 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1938 return ReadWin32( p_intf, p_buffer, pi_size );
1939 else if( p_intf->p_sys->i_socket == -1 )
1941 msleep( INTF_IDLE_SLEEP );
1946 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1947 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
1948 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1949 (uint8_t *)p_buffer + *pi_size, 1, VLC_FALSE ) ) > 0 )
1951 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1957 /* Connection closed */
1960 if( p_intf->p_sys->i_socket != -1 )
1962 net_Close( p_intf->p_sys->i_socket );
1963 p_intf->p_sys->i_socket = -1;
1966 /* Standard input closed: exit */
1967 vlc_object_kill( p_intf );
1969 p_buffer[ *pi_size ] = 0;
1973 if( *pi_size == MAX_LINE_LENGTH ||
1974 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1976 p_buffer[ *pi_size ] = 0;
1983 /*****************************************************************************
1984 * parse_MRL: build a input item from a full mrl
1985 *****************************************************************************
1986 * MRL format: "simplified-mrl [:option-name[=option-value]]"
1987 * We don't check for '"' or '\'', we just assume that a ':' that follows a
1988 * space is a new option. Should be good enough for our purpose.
1989 *****************************************************************************/
1990 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
1992 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
1993 #define SKIPTRAILINGSPACE( p, d ) \
1994 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
1996 input_item_t *p_item = NULL;
1997 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
1998 char **ppsz_options = NULL;
1999 int i, i_options = 0;
2001 if( !psz_mrl ) return 0;
2003 psz_mrl = psz_orig = strdup( psz_mrl );
2006 SKIPSPACE( psz_mrl );
2009 for( ; *psz_mrl; psz_mrl++ )
2011 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2013 /* We have a complete item */
2016 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2017 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2019 /* We have a complete item */
2024 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2025 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2027 /* Remove '"' and '\'' if necessary */
2028 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2029 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2030 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2031 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2033 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2034 else if( *psz_item )
2037 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2038 ppsz_options[i_options - 1] = &psz_item[1];
2041 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2044 /* Now create a playlist item */
2047 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2048 for( i = 0; i < i_options; i++ )
2050 input_ItemAddOption( p_item, ppsz_options[i] );
2054 if( i_options ) free( ppsz_options );
2061 /*****************************************************************************
2062 * checkUpdates : check for updates
2063 ****************************************************************************/
2064 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2066 update_iterator_t *p_uit;
2067 update_t *p_u = update_New( p_intf );
2068 if( p_u == NULL ) return;
2069 p_uit = update_iterator_New( p_u );
2074 if( strstr( psz_arg, "newer" ) )
2075 s |= UPDATE_RELEASE_STATUS_NEWER;
2076 if( strstr( psz_arg, "equal" ) )
2077 s |= UPDATE_RELEASE_STATUS_EQUAL;
2078 if( strstr( psz_arg, "older" ) )
2079 s |= UPDATE_RELEASE_STATUS_OLDER;
2080 if( s ) p_uit->i_rs = s;
2081 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2083 if( strstr( psz_arg, "undef" ) )
2084 t |= UPDATE_FILE_TYPE_UNDEF;
2085 if( strstr( psz_arg, "info" ) )
2086 t |= UPDATE_FILE_TYPE_INFO;
2087 if( strstr( psz_arg, "source" ) )
2088 t |= UPDATE_FILE_TYPE_SOURCE;
2089 if( strstr( psz_arg, "binary" ) )
2090 t |= UPDATE_FILE_TYPE_BINARY;
2091 if( strstr( psz_arg, "plugin" ) )
2092 t |= UPDATE_FILE_TYPE_PLUGIN;
2093 if( t ) p_uit->i_t = t;
2095 update_Check( p_u, VLC_FALSE );
2096 update_iterator_Action( p_uit, UPDATE_MIRROR );
2097 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2098 p_uit->mirror.psz_name,
2099 p_uit->mirror.psz_location,
2100 p_uit->mirror.psz_type );
2101 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2104 if( s & UPDATE_RELEASE )
2106 switch( p_uit->release.i_status )
2108 case UPDATE_RELEASE_STATUS_OLDER:
2109 psz_tmp = strdup( "older" );
2111 case UPDATE_RELEASE_STATUS_EQUAL:
2112 psz_tmp = strdup( "equal" );
2114 case UPDATE_RELEASE_STATUS_NEWER:
2115 psz_tmp = strdup( "newer" );
2118 psz_tmp = strdup( "?!?" );
2121 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2122 p_uit->release.psz_version,
2123 p_uit->release.psz_svn_revision,
2127 switch( p_uit->file.i_type )
2129 case UPDATE_FILE_TYPE_UNDEF:
2130 psz_tmp = strdup( "undef" );
2132 case UPDATE_FILE_TYPE_INFO:
2133 psz_tmp = strdup( "info" );
2135 case UPDATE_FILE_TYPE_SOURCE:
2136 psz_tmp = strdup( "source" );
2138 case UPDATE_FILE_TYPE_BINARY:
2139 psz_tmp = strdup( "binary" );
2141 case UPDATE_FILE_TYPE_PLUGIN:
2142 psz_tmp = strdup( "plugin" );
2145 psz_tmp = strdup( "?!?" );
2148 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2150 if( p_uit->file.l_size )
2152 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2153 asprintf( &psz_tmp, "(%ld GB)",
2154 p_uit->file.l_size / (1024*1024*1024) );
2155 if( p_uit->file.l_size > 1024 * 1024 )
2156 asprintf( &psz_tmp, "(%ld MB)",
2157 p_uit->file.l_size / (1024*1024) );
2158 else if( p_uit->file.l_size > 1024 )
2159 asprintf( &psz_tmp, "(%ld kB)",
2160 p_uit->file.l_size / 1024 );
2162 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2166 psz_tmp = strdup( "" );
2168 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2173 update_iterator_Delete( p_uit );
2175 update_Delete( p_u );