1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 - 2005 the VideoLAN team
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8 * Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
30 #include <stdlib.h> /* malloc(), free() */
33 #include <errno.h> /* ENOMEM */
38 #include <vlc_interface.h>
42 #include <vlc_playlist.h>
43 #include <vlc_update.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
52 #include <sys/types.h>
54 #include <vlc_network.h>
57 #include <vlc_charset.h>
59 #if defined(AF_UNIX) && !defined(AF_LOCAL)
60 # define AF_LOCAL AF_UNIX
63 #if defined(AF_LOCAL) && ! defined(WIN32)
67 #define MAX_LINE_LENGTH 256
68 #define STATUS_CHANGE "status change: "
70 /*****************************************************************************
72 *****************************************************************************/
73 static int Activate ( vlc_object_t * );
74 static void Deactivate ( vlc_object_t * );
75 static void Run ( intf_thread_t * );
77 static void Help ( intf_thread_t *, vlc_bool_t );
78 static void RegisterCallbacks( intf_thread_t * );
80 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
82 static input_item_t *parse_MRL( intf_thread_t *, char * );
84 static int Input ( vlc_object_t *, char const *,
85 vlc_value_t, vlc_value_t, void * );
86 static int Playlist ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
88 static int Quit ( vlc_object_t *, char const *,
89 vlc_value_t, vlc_value_t, void * );
90 static int Intf ( vlc_object_t *, char const *,
91 vlc_value_t, vlc_value_t, void * );
92 static int Volume ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int VolumeMove ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
96 static int VideoConfig ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
98 static int AudioConfig ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int Menu ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg );
104 /* Status Callbacks */
105 static int TimeOffsetChanged( vlc_object_t *, char const *,
106 vlc_value_t, vlc_value_t , void * );
107 static int VolumeChanged ( vlc_object_t *, char const *,
108 vlc_value_t, vlc_value_t, void * );
109 static int StateChanged ( vlc_object_t *, char const *,
110 vlc_value_t, vlc_value_t, void * );
111 static int RateChanged ( vlc_object_t *, char const *,
112 vlc_value_t, vlc_value_t, void * );
116 int *pi_socket_listen;
121 vlc_mutex_t status_lock;
122 playlist_status_t i_last_state;
130 #ifdef HAVE_VARIADIC_MACROS
131 # define msg_rc( psz_format, args... ) \
132 __msg_rc( p_intf, psz_format, ## args )
135 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
138 va_start( args, psz_fmt );
140 if( p_intf->p_sys->i_socket == -1 )
142 utf8_vfprintf( stdout, psz_fmt, args );
147 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
148 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
153 /*****************************************************************************
155 *****************************************************************************/
156 #define POS_TEXT N_("Show stream position")
157 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
158 "stream from time to time." )
160 #define TTY_TEXT N_("Fake TTY")
161 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
163 #define UNIX_TEXT N_("UNIX socket command input")
164 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
167 #define HOST_TEXT N_("TCP command input")
168 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
169 "You can set the address and port the interface will bind to." )
172 #define QUIET_TEXT N_("Do not open a DOS command box interface")
173 #define QUIET_LONGTEXT N_( \
174 "By default the rc interface plugin will start a DOS command box. " \
175 "Enabling the quiet mode will not bring this command box but can also " \
176 "be pretty annoying when you want to stop VLC and no video window is " \
181 set_shortname( _("RC"));
182 set_category( CAT_INTERFACE );
183 set_subcategory( SUBCAT_INTERFACE_MAIN );
184 set_description( _("Remote control interface") );
185 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
188 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
190 #if defined (HAVE_ISATTY)
191 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
193 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
195 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
197 set_capability( "interface", 20 );
198 set_callbacks( Activate, Deactivate );
201 /*****************************************************************************
202 * Activate: initialize and create stuff
203 *****************************************************************************/
204 static int Activate( vlc_object_t *p_this )
206 intf_thread_t *p_intf = (intf_thread_t*)p_this;
207 char *psz_host, *psz_unix_path;
208 int *pi_socket = NULL;
211 #if defined(HAVE_ISATTY)
212 /* Check that stdin is a TTY */
213 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
215 msg_Warn( p_intf, "fd 0 is not a TTY" );
220 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
226 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
227 free( psz_unix_path );
230 struct sockaddr_un addr;
232 memset( &addr, 0, sizeof(struct sockaddr_un) );
234 msg_Dbg( p_intf, "trying UNIX socket" );
236 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
238 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
239 free( psz_unix_path );
243 addr.sun_family = AF_LOCAL;
244 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
245 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
247 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
248 && (errno == EADDRINUSE)
249 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
250 && (errno == ECONNREFUSED))
252 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
253 unlink (psz_unix_path);
255 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
257 msg_Err (p_intf, "cannot bind UNIX socket at %s: %s",
258 psz_unix_path, strerror (errno));
259 free (psz_unix_path);
260 net_Close (i_socket);
265 if( listen( i_socket, 1 ) )
267 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
268 free( psz_unix_path );
269 net_Close( i_socket );
273 /* FIXME: we need a core function to merge listening sockets sets */
274 pi_socket = calloc( 2, sizeof( int ) );
275 if( pi_socket == NULL )
277 free( psz_unix_path );
278 net_Close( i_socket );
281 pi_socket[0] = i_socket;
283 #endif /* AF_LOCAL */
287 if( ( pi_socket == NULL ) &&
288 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
292 vlc_UrlParse( &url, psz_host, 0 );
294 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
296 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
297 if( pi_socket == NULL )
299 msg_Warn( p_intf, "can't listen to %s port %i",
300 url.psz_host, url.i_port );
301 vlc_UrlClean( &url );
306 vlc_UrlClean( &url );
310 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
313 msg_Err( p_intf, "no memory" );
317 p_intf->p_sys->pi_socket_listen = pi_socket;
318 p_intf->p_sys->i_socket = -1;
319 p_intf->p_sys->psz_unix_path = psz_unix_path;
320 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
321 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
323 /* Non-buffered stdout */
324 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
326 p_intf->pf_run = Run;
329 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
330 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
335 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
339 /*****************************************************************************
340 * Deactivate: uninitialize and cleanup
341 *****************************************************************************/
342 static void Deactivate( vlc_object_t *p_this )
344 intf_thread_t *p_intf = (intf_thread_t*)p_this;
346 net_ListenClose( p_intf->p_sys->pi_socket_listen );
347 if( p_intf->p_sys->i_socket != -1 )
348 net_Close( p_intf->p_sys->i_socket );
349 if( p_intf->p_sys->psz_unix_path != NULL )
351 #if defined(AF_LOCAL) && !defined(WIN32)
352 unlink( p_intf->p_sys->psz_unix_path );
354 free( p_intf->p_sys->psz_unix_path );
356 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
357 free( p_intf->p_sys );
360 /*****************************************************************************
361 * RegisterCallbacks: Register callbacks to dynamic variables
362 *****************************************************************************/
363 static void RegisterCallbacks( intf_thread_t *p_intf )
365 /* Register commands that will be cleaned up upon object destruction */
366 #define ADD( name, type, target ) \
367 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
368 var_AddCallback( p_intf, name, target, NULL );
369 ADD( "quit", VOID, Quit )
370 ADD( "intf", STRING, Intf )
372 ADD( "add", STRING, Playlist )
373 ADD( "repeat", STRING, Playlist )
374 ADD( "loop", 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 )
415 ADD( "volume", STRING, Volume )
416 ADD( "volup", STRING, VolumeMove )
417 ADD( "voldown", STRING, VolumeMove )
418 ADD( "adev", STRING, AudioConfig )
419 ADD( "achan", STRING, AudioConfig )
424 /*****************************************************************************
426 *****************************************************************************
427 * This part of the interface is in a separate thread so that we can call
428 * exec() from within it without annoying the rest of the program.
429 *****************************************************************************/
430 static void Run( intf_thread_t *p_intf )
432 input_thread_t * p_input;
433 playlist_t * p_playlist;
435 char p_buffer[ MAX_LINE_LENGTH + 1 ];
436 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
437 vlc_bool_t b_longhelp = VLC_FALSE;
447 /* Register commands that will be cleaned up upon object destruction */
448 RegisterCallbacks( p_intf );
450 /* status callbacks */
451 /* Listen to audio volume updates */
452 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
455 /* Get the file descriptor of the console input */
456 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
457 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
459 msg_Err( p_intf, "couldn't find user input handle" );
460 vlc_object_kill( p_intf );
464 while( !intf_ShouldDie( p_intf ) )
466 char *psz_cmd, *psz_arg;
467 vlc_bool_t b_complete;
469 if( p_intf->p_sys->pi_socket_listen != NULL &&
470 p_intf->p_sys->i_socket == -1 )
472 p_intf->p_sys->i_socket =
473 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
475 if( p_intf->p_sys->i_socket == -1 ) continue;
478 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
480 /* Manage the input part */
481 if( p_input == NULL )
485 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
490 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
494 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
498 /* New input has been registered */
501 if( !p_input->b_dead || !p_input->b_die )
503 msg_rc( STATUS_CHANGE "( new input: %s )",
504 input_GetItem(p_input)->psz_uri );
505 msg_rc( STATUS_CHANGE "( audio volume: %d )",
506 config_GetInt( p_intf, "volume" ));
508 var_AddCallback( p_input, "state", StateChanged, p_intf );
509 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
510 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
511 var_AddCallback( p_input, "rate", RateChanged, p_intf );
512 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
516 else if( p_input->b_dead )
518 var_DelCallback( p_input, "state", StateChanged, p_intf );
519 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
520 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
521 var_DelCallback( p_input, "rate", RateChanged, p_intf );
522 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
524 vlc_object_release( p_input );
529 vlc_mutex_lock( &p_playlist->object_lock );
530 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
531 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
532 vlc_mutex_unlock( &p_playlist->object_lock );
536 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
537 (p_playlist != NULL) )
539 vlc_mutex_lock( &p_playlist->object_lock );
540 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
541 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
543 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
544 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
547 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
548 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
550 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
551 msg_rc( STATUS_CHANGE "( play state: 1 )" );
554 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
555 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
557 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
558 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
560 vlc_mutex_unlock( &p_playlist->object_lock );
563 if( p_input && b_showpos )
565 i_newpos = 100 * var_GetFloat( p_input, "position" );
566 if( i_oldpos != i_newpos )
569 msg_rc( "pos: %d%%", i_newpos );
573 /* Is there something to do? */
574 if( !b_complete ) continue;
577 /* Skip heading spaces */
579 while( *psz_cmd == ' ' )
584 /* Split psz_cmd at the first space and make sure that
585 * psz_arg is valid */
586 psz_arg = strchr( psz_cmd, ' ' );
590 while( *psz_arg == ' ' )
600 /* module specfic commands: @<module name> <command> <args...> */
601 if( *psz_cmd == '@' && *psz_arg )
603 /* Parse miscellaneous commands */
604 char *psz_alias = psz_cmd + 1;
605 char *psz_mycmd = strdup( psz_arg );
606 char *psz_myarg = strchr( psz_mycmd, ' ' );
611 msg_rc( "Not enough parameters." );
618 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
629 /* If the user typed a registered local command, try it */
630 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
635 val.psz_string = psz_arg;
636 i_ret = var_Set( p_intf, psz_cmd, val );
637 msg_rc( "%s: returned %i (%s)",
638 psz_cmd, i_ret, vlc_error( i_ret ) );
640 /* Or maybe it's a global command */
641 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
646 val.psz_string = psz_arg;
647 /* FIXME: it's a global command, but we should pass the
648 * local object as an argument, not p_intf->p_libvlc. */
649 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
652 msg_rc( "%s: returned %i (%s)",
653 psz_cmd, i_ret, vlc_error( i_ret ) );
656 else if( !strcmp( psz_cmd, "logout" ) )
658 /* Close connection */
659 if( p_intf->p_sys->i_socket != -1 )
661 net_Close( p_intf->p_sys->i_socket );
663 p_intf->p_sys->i_socket = -1;
665 else if( !strcmp( psz_cmd, "info" ) )
670 vlc_mutex_lock( &input_GetItem(p_input)->lock );
671 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
673 info_category_t *p_category = input_GetItem(p_input)
676 msg_rc( "+----[ %s ]", p_category->psz_name );
678 for ( j = 0; j < p_category->i_infos; j++ )
680 info_t *p_info = p_category->pp_infos[j];
681 msg_rc( "| %s: %s", p_info->psz_name,
686 msg_rc( "+----[ end of stream info ]" );
687 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
691 msg_rc( "no input" );
694 else if( !strcmp( psz_cmd, "is_playing" ) )
705 else if( !strcmp( psz_cmd, "get_time" ) )
714 var_Get( p_input, "time", &time );
715 msg_rc( "%i", time.i_time / 1000000);
718 else if( !strcmp( psz_cmd, "get_length" ) )
727 var_Get( p_input, "length", &time );
728 msg_rc( "%i", time.i_time / 1000000);
731 else if( !strcmp( psz_cmd, "get_title" ) )
739 msg_rc( "%s", input_GetItem(p_input)->psz_name );
742 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
743 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
745 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
746 b_longhelp = VLC_TRUE;
747 else b_longhelp = VLC_FALSE;
749 Help( p_intf, b_longhelp );
751 else if( !strcmp( psz_cmd, "check-updates" ) )
753 checkUpdates( p_intf, psz_arg );
755 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
757 var_SetInteger( p_intf->p_libvlc, "key-pressed",
758 config_GetInt( p_intf, psz_arg ) );
760 else switch( psz_cmd[0] )
766 vout_thread_t *p_vout;
767 p_vout = vlc_object_find( p_input,
768 VLC_OBJECT_VOUT, FIND_CHILD );
773 vlc_bool_t b_update = VLC_FALSE;
774 var_Get( p_vout, "fullscreen", &val );
775 val.b_bool = !val.b_bool;
776 if( !strncmp( psz_arg, "on", 2 )
777 && ( val.b_bool == VLC_TRUE ) )
780 val.b_bool = VLC_TRUE;
782 else if( !strncmp( psz_arg, "off", 3 )
783 && ( val.b_bool == VLC_FALSE ) )
786 val.b_bool = VLC_FALSE;
788 else if( strncmp( psz_arg, "off", 3 )
789 && strncmp( psz_arg, "on", 2 ) )
791 if( b_update ) var_Set( p_vout, "fullscreen", val );
792 vlc_object_release( p_vout );
803 /* Ignore empty lines */
807 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
811 /* Command processed */
812 i_size = 0; p_buffer[0] = 0;
815 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
816 msg_rc( STATUS_CHANGE "( quit )" );
820 var_DelCallback( p_input, "state", StateChanged, p_intf );
821 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
822 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
823 var_DelCallback( p_input, "rate", RateChanged, p_intf );
824 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
825 vlc_object_release( p_input );
831 vlc_object_release( p_playlist );
835 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
838 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
840 msg_rc(_("+----[ Remote control commands ]"));
842 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
843 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
844 msg_rc(_("| playlist . . . . . show items currently in playlist"));
845 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
846 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
847 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
848 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
849 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
850 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
851 msg_rc(_("| loop [on|off] . . . . . . toggle playlist item loop"));
852 msg_rc(_("| clear . . . . . . . . . . . . . clear the playlist"));
853 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
854 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
855 msg_rc(_("| title_n . . . . . . . . next title in current item"));
856 msg_rc(_("| title_p . . . . . . previous title in current item"));
857 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
858 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
859 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
861 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
862 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
863 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
864 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
865 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
866 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
867 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
868 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
869 msg_rc(_("| info . . . . . information about the current stream"));
870 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
871 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
872 msg_rc(_("| get_title . . . . . the title of the current stream"));
873 msg_rc(_("| get_length . . . . the length of the current stream"));
875 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
876 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
877 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
878 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
879 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
880 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
881 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
882 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
883 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
884 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
885 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
886 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
887 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
892 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
893 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
894 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
895 msg_rc(_("| @name marq-position #. . . .relative position control"));
896 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
897 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
898 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
899 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
901 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
902 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
903 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
904 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
905 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
907 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
908 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
909 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
910 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
911 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
912 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
913 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
914 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
915 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
916 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
917 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
918 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
919 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
920 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
922 msg_rc(_("| check-updates [newer] [equal] [older]\n"
923 "| [undef] [info] [source] [binary] [plugin]"));
926 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
927 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
928 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
929 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
931 msg_rc(_("+----[ end of help ]"));
934 /********************************************************************
935 * Status callback routines
936 ********************************************************************/
937 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
938 vlc_value_t oldval, vlc_value_t newval, void *p_data )
940 intf_thread_t *p_intf = (intf_thread_t*)p_data;
941 input_thread_t *p_input = NULL;
943 vlc_mutex_lock( &p_intf->p_sys->status_lock );
944 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
947 msg_rc( STATUS_CHANGE "( time-offset: %d )",
948 var_GetInteger( p_input, "time-offset" ) );
949 vlc_object_release( p_input );
951 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
955 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
956 vlc_value_t oldval, vlc_value_t newval, void *p_data )
958 intf_thread_t *p_intf = (intf_thread_t*)p_data;
960 vlc_mutex_lock( &p_intf->p_sys->status_lock );
961 msg_rc( STATUS_CHANGE "( audio volume: %d )",
962 config_GetInt( p_this, "volume") );
963 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
967 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
968 vlc_value_t oldval, vlc_value_t newval, void *p_data )
970 intf_thread_t *p_intf = (intf_thread_t*)p_data;
971 playlist_t *p_playlist = NULL;
972 input_thread_t *p_input = NULL;
974 vlc_mutex_lock( &p_intf->p_sys->status_lock );
975 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
978 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
982 switch( p_playlist->status.i_status )
984 case PLAYLIST_STOPPED:
985 strncpy( &cmd[0], "stop", 4);
988 case PLAYLIST_RUNNING:
989 strncpy( &cmd[0], "play", 4);
992 case PLAYLIST_PAUSED:
993 strncpy( &cmd[0], "pause", 5);
996 } /* var_GetInteger( p_input, "state" ) */
997 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
998 vlc_object_release( p_playlist );
1000 vlc_object_release( p_input );
1002 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1006 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1007 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1009 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1010 input_thread_t *p_input = NULL;
1012 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1013 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1016 msg_rc( STATUS_CHANGE "( new rate: %d )",
1017 var_GetInteger( p_input, "rate" ) );
1018 vlc_object_release( p_input );
1020 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1024 /********************************************************************
1026 ********************************************************************/
1027 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1028 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1030 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1031 input_thread_t *p_input;
1034 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1035 if( !p_input ) return VLC_ENOOBJ;
1037 var_Get( p_input, "state", &val );
1038 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1039 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1041 msg_rc( _("Press menu select or pause to continue.") );
1042 vlc_object_release( p_input );
1043 return VLC_EGENERIC;
1046 /* Parse commands that only require an input */
1047 if( !strcmp( psz_cmd, "pause" ) )
1049 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1050 var_Set( p_intf->p_libvlc, "key-pressed", val );
1051 vlc_object_release( p_input );
1054 else if( !strcmp( psz_cmd, "seek" ) )
1056 if( strlen( newval.psz_string ) > 0 &&
1057 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1059 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1060 var_Set( p_input, "position", val );
1064 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1065 var_Set( p_input, "time", val );
1067 vlc_object_release( p_input );
1070 else if ( !strcmp( psz_cmd, "fastforward" ) )
1072 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1073 var_Set( p_intf->p_libvlc, "key-pressed", val );
1074 vlc_object_release( p_input );
1077 else if ( !strcmp( psz_cmd, "rewind" ) )
1079 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1080 var_Set( p_intf->p_libvlc, "key-pressed", val );
1081 vlc_object_release( p_input );
1084 else if ( !strcmp( psz_cmd, "faster" ) )
1086 val.b_bool = VLC_TRUE;
1087 var_Set( p_input, "rate-faster", val );
1088 vlc_object_release( p_input );
1091 else if ( !strcmp( psz_cmd, "slower" ) )
1093 val.b_bool = VLC_TRUE;
1094 var_Set( p_input, "rate-slower", val );
1095 vlc_object_release( p_input );
1098 else if ( !strcmp( psz_cmd, "normal" ) )
1100 val.i_int = INPUT_RATE_DEFAULT;
1101 var_Set( p_input, "rate", val );
1102 vlc_object_release( p_input );
1105 else if( !strcmp( psz_cmd, "chapter" ) ||
1106 !strcmp( psz_cmd, "chapter_n" ) ||
1107 !strcmp( psz_cmd, "chapter_p" ) )
1109 if( !strcmp( psz_cmd, "chapter" ) )
1111 if ( *newval.psz_string )
1114 val.i_int = atoi( newval.psz_string );
1115 var_Set( p_input, "chapter", val );
1119 vlc_value_t val_list;
1122 var_Get( p_input, "chapter", &val );
1123 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1125 msg_rc( "Currently playing chapter %d/%d.",
1126 val.i_int, val_list.p_list->i_count );
1127 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1131 else if( !strcmp( psz_cmd, "chapter_n" ) )
1133 val.b_bool = VLC_TRUE;
1134 var_Set( p_input, "next-chapter", val );
1136 else if( !strcmp( psz_cmd, "chapter_p" ) )
1138 val.b_bool = VLC_TRUE;
1139 var_Set( p_input, "prev-chapter", val );
1141 vlc_object_release( p_input );
1144 else if( !strcmp( psz_cmd, "title" ) ||
1145 !strcmp( psz_cmd, "title_n" ) ||
1146 !strcmp( psz_cmd, "title_p" ) )
1148 if( !strcmp( psz_cmd, "title" ) )
1150 if ( *newval.psz_string )
1153 val.i_int = atoi( newval.psz_string );
1154 var_Set( p_input, "title", val );
1158 vlc_value_t val_list;
1161 var_Get( p_input, "title", &val );
1162 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1164 msg_rc( "Currently playing title %d/%d.",
1165 val.i_int, val_list.p_list->i_count );
1166 var_Change( p_this, "title", VLC_VAR_FREELIST,
1170 else if( !strcmp( psz_cmd, "title_n" ) )
1172 val.b_bool = VLC_TRUE;
1173 var_Set( p_input, "next-title", val );
1175 else if( !strcmp( psz_cmd, "title_p" ) )
1177 val.b_bool = VLC_TRUE;
1178 var_Set( p_input, "prev-title", val );
1181 vlc_object_release( p_input );
1184 else if( !strcmp( psz_cmd, "atrack" )
1185 || !strcmp( psz_cmd, "vtrack" )
1186 || !strcmp( psz_cmd, "strack" ) )
1188 const char *psz_variable;
1189 vlc_value_t val_name;
1192 if( !strcmp( psz_cmd, "atrack" ) )
1194 psz_variable = "audio-es";
1196 else if( !strcmp( psz_cmd, "vtrack" ) )
1198 psz_variable = "video-es";
1202 psz_variable = "spu-es";
1205 /* Get the descriptive name of the variable */
1206 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1208 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1210 if( newval.psz_string && *newval.psz_string )
1214 val.i_int = atoi( newval.psz_string );
1216 i_error = var_Set( p_input, psz_variable, val );
1221 vlc_value_t val, text;
1224 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1226 vlc_object_release( p_input );
1227 return VLC_EGENERIC;
1229 i_value = val.i_int;
1231 if ( var_Change( p_input, psz_variable,
1232 VLC_VAR_GETLIST, &val, &text ) < 0 )
1234 vlc_object_release( p_input );
1235 return VLC_EGENERIC;
1238 msg_rc( "+----[ %s ]", val_name.psz_string );
1239 for ( i = 0; i < val.p_list->i_count; i++ )
1241 if ( i_value == val.p_list->p_values[i].i_int )
1242 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1243 text.p_list->p_values[i].psz_string );
1245 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1246 text.p_list->p_values[i].psz_string );
1248 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1250 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1252 if( val_name.psz_string ) free( val_name.psz_string );
1254 i_error = VLC_SUCCESS;
1256 vlc_object_release( p_input );
1260 /* Never reached. */
1261 vlc_object_release( p_input );
1262 return VLC_EGENERIC;
1265 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1266 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1270 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1271 playlist_t *p_playlist = pl_Yield( p_this );
1274 if( p_playlist->p_input )
1276 var_Get( p_playlist->p_input, "state", &val );
1277 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1279 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1280 vlc_object_release( p_playlist );
1282 return VLC_EGENERIC;
1287 /* Parse commands that require a playlist */
1288 if( !strcmp( psz_cmd, "prev" ) )
1290 playlist_Prev( p_playlist );
1292 else if( !strcmp( psz_cmd, "next" ) )
1294 playlist_Next( p_playlist );
1296 else if( !strcmp( psz_cmd, "play" ) )
1298 msg_Warn( p_playlist, "play" );
1299 playlist_Play( p_playlist );
1301 else if( !strcmp( psz_cmd, "repeat" ) )
1303 vlc_bool_t b_update = VLC_TRUE;
1305 var_Get( p_playlist, "repeat", &val );
1307 if( strlen( newval.psz_string ) > 0 )
1309 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1310 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1312 b_update = VLC_FALSE;
1318 val.b_bool = !val.b_bool;
1319 var_Set( p_playlist, "repeat", val );
1321 msg_rc( "Setting repeat to %d", val.b_bool );
1323 else if( !strcmp( psz_cmd, "loop" ) )
1325 vlc_bool_t b_update = VLC_TRUE;
1327 var_Get( p_playlist, "loop", &val );
1329 if( strlen( newval.psz_string ) > 0 )
1331 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1332 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1334 b_update = VLC_FALSE;
1340 val.b_bool = !val.b_bool;
1341 var_Set( p_playlist, "loop", val );
1343 msg_rc( "Setting loop to %d", val.b_bool );
1345 else if (!strcmp( psz_cmd, "goto" ) )
1347 msg_rc( _("goto is deprecated" ) );
1348 msg_Err( p_playlist, "goto is deprecated" );
1350 else if( !strcmp( psz_cmd, "stop" ) )
1352 playlist_Stop( p_playlist );
1354 else if( !strcmp( psz_cmd, "clear" ) )
1356 playlist_Stop( p_playlist );
1357 playlist_Clear( p_playlist, VLC_FALSE );
1359 else if( !strcmp( psz_cmd, "add" ) &&
1360 newval.psz_string && *newval.psz_string )
1362 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1366 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1367 playlist_AddInput( p_playlist, p_item,
1368 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1372 else if( !strcmp( psz_cmd, "enqueue" ) &&
1373 newval.psz_string && *newval.psz_string )
1375 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1379 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1380 playlist_AddInput( p_playlist, p_item,
1381 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1385 else if( !strcmp( psz_cmd, "playlist" ) )
1387 msg_Dbg( p_playlist, "Dumping category" );
1388 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1389 msg_Dbg( p_playlist, "Dumping Onelevel" );
1390 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1392 else if( !strcmp( psz_cmd, "sort" ))
1394 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1395 SORT_ARTIST, ORDER_NORMAL );
1397 else if( !strcmp( psz_cmd, "status" ) )
1399 if( p_playlist->p_input )
1401 /* Replay the current state of the system. */
1402 msg_rc( STATUS_CHANGE "( new input: %s )",
1403 input_GetItem(p_playlist->p_input)->psz_uri );
1404 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1405 config_GetInt( p_intf, "volume" ));
1407 vlc_mutex_lock( &p_playlist->object_lock );
1408 switch( p_playlist->status.i_status )
1410 case PLAYLIST_STOPPED:
1411 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1413 case PLAYLIST_RUNNING:
1414 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1416 case PLAYLIST_PAUSED:
1417 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1420 msg_rc( STATUS_CHANGE "( state unknown )" );
1423 vlc_mutex_unlock( &p_playlist->object_lock );
1432 msg_rc( "unknown command!" );
1435 vlc_object_release( p_playlist );
1439 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1440 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1442 playlist_t *p_playlist;
1444 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1447 playlist_Stop( p_playlist );
1448 vlc_object_release( p_playlist );
1450 vlc_object_kill( p_this->p_libvlc );
1454 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1455 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1457 intf_thread_t *p_newintf = NULL;
1459 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1462 p_newintf->b_block = VLC_FALSE;
1463 if( intf_RunThread( p_newintf ) )
1465 vlc_object_detach( p_newintf );
1466 intf_Destroy( p_newintf );
1473 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1474 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1476 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1477 input_thread_t *p_input = NULL;
1478 int i_error = VLC_EGENERIC;
1480 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1488 var_Get( p_input, "state", &val );
1489 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1491 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1492 vlc_object_release( p_input );
1493 return VLC_EGENERIC;
1495 vlc_object_release( p_input );
1498 if ( *newval.psz_string )
1501 audio_volume_t i_volume = atoi( newval.psz_string );
1502 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1504 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1506 i_error = VLC_EBADVAR;
1510 if( i_volume == AOUT_VOLUME_MIN )
1514 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1515 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1517 i_error = aout_VolumeSet( p_this, i_volume );
1518 osd_Volume( p_this );
1519 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1525 audio_volume_t i_volume;
1526 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1528 i_error = VLC_EGENERIC;
1532 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1533 i_error = VLC_SUCCESS;
1540 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1541 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1543 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1544 audio_volume_t i_volume;
1545 input_thread_t *p_input = NULL;
1546 int i_nb_steps = atoi(newval.psz_string);
1547 int i_error = VLC_SUCCESS;
1548 int i_volume_step = 0;
1550 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1558 var_Get( p_input, "state", &val );
1559 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1561 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1562 vlc_object_release( p_input );
1563 return VLC_EGENERIC;
1565 vlc_object_release( p_input );
1568 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1569 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1574 if ( !strcmp(psz_cmd, "volup") )
1576 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1577 i_error = VLC_EGENERIC;
1581 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1582 i_error = VLC_EGENERIC;
1584 osd_Volume( p_this );
1586 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1591 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1592 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1594 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1595 input_thread_t *p_input = NULL;
1596 vout_thread_t * p_vout;
1597 const char * psz_variable;
1598 vlc_value_t val_name;
1601 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1605 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1606 vlc_object_release( p_input );
1610 if( !strcmp( psz_cmd, "vcrop" ) )
1612 psz_variable = "crop";
1614 else if( !strcmp( psz_cmd, "vratio" ) )
1616 psz_variable = "aspect-ratio";
1618 else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1620 psz_variable = "zoom";
1624 /* Get the descriptive name of the variable */
1625 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1627 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1629 if( newval.psz_string && *newval.psz_string )
1632 if( !strcmp( psz_variable, "zoom" ) )
1635 val.f_float = atof( newval.psz_string );
1636 i_error = var_Set( p_vout, psz_variable, val );
1640 i_error = var_Set( p_vout, psz_variable, newval );
1646 vlc_value_t val, text;
1649 char *psz_value = NULL;
1651 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1653 vlc_object_release( p_vout );
1654 return VLC_EGENERIC;
1656 if( !strcmp( psz_variable, "zoom" ) )
1658 f_value = val.f_float;
1662 psz_value = strdup( val.psz_string );
1665 if ( var_Change( p_vout, psz_variable,
1666 VLC_VAR_GETLIST, &val, &text ) < 0 )
1668 vlc_object_release( p_vout );
1669 return VLC_EGENERIC;
1672 msg_rc( "+----[ %s ]", val_name.psz_string );
1673 if( !strcmp( psz_variable, "zoom" ) )
1675 for ( i = 0; i < val.p_list->i_count; i++ )
1677 if ( f_value == val.p_list->p_values[i].f_float )
1678 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1679 text.p_list->p_values[i].psz_string );
1681 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1682 text.p_list->p_values[i].psz_string );
1687 for ( i = 0; i < val.p_list->i_count; i++ )
1689 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1690 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1691 text.p_list->p_values[i].psz_string );
1693 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1694 text.p_list->p_values[i].psz_string );
1698 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1700 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1702 if( val_name.psz_string ) free( val_name.psz_string );
1704 i_error = VLC_SUCCESS;
1706 vlc_object_release( p_vout );
1710 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1711 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1713 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1714 input_thread_t *p_input = NULL;
1715 aout_instance_t * p_aout;
1716 const char * psz_variable;
1717 vlc_value_t val_name;
1720 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1728 var_Get( p_input, "state", &val );
1729 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1730 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1731 vlc_object_release( p_input );
1732 return VLC_EGENERIC;
1734 vlc_object_release( p_input );
1737 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1738 if ( p_aout == NULL ) return VLC_ENOOBJ;
1740 if ( !strcmp( psz_cmd, "adev" ) )
1742 psz_variable = "audio-device";
1746 psz_variable = "audio-channels";
1749 /* Get the descriptive name of the variable */
1750 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1752 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1754 if ( !*newval.psz_string )
1756 /* Retrieve all registered ***. */
1757 vlc_value_t val, text;
1760 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1762 vlc_object_release( (vlc_object_t *)p_aout );
1763 return VLC_EGENERIC;
1765 i_value = val.i_int;
1767 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1768 VLC_VAR_GETLIST, &val, &text ) < 0 )
1770 vlc_object_release( (vlc_object_t *)p_aout );
1771 return VLC_EGENERIC;
1774 msg_rc( "+----[ %s ]", val_name.psz_string );
1775 for ( i = 0; i < val.p_list->i_count; i++ )
1777 if ( i_value == val.p_list->p_values[i].i_int )
1778 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1779 text.p_list->p_values[i].psz_string );
1781 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1782 text.p_list->p_values[i].psz_string );
1784 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1786 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1788 if( val_name.psz_string ) free( val_name.psz_string );
1789 i_error = VLC_SUCCESS;
1794 val.i_int = atoi( newval.psz_string );
1796 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1798 vlc_object_release( (vlc_object_t *)p_aout );
1803 /* OSD menu commands */
1804 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1805 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1807 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1808 playlist_t *p_playlist = NULL;
1810 int i_error = VLC_EGENERIC;
1812 if ( !*newval.psz_string )
1814 msg_rc( _("Please provide one of the following parameters:") );
1815 msg_rc( "[on|off|up|down|left|right|select]" );
1819 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1823 if( p_playlist->p_input )
1825 var_Get( p_playlist->p_input, "state", &val );
1826 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1827 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1829 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1830 vlc_object_release( p_playlist );
1831 return VLC_EGENERIC;
1834 vlc_object_release( p_playlist );
1836 val.psz_string = strdup( newval.psz_string );
1837 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1838 osd_MenuShow( p_this );
1839 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1840 osd_MenuHide( p_this );
1841 else if( !strcmp( val.psz_string, "up" ) )
1842 osd_MenuUp( p_this );
1843 else if( !strcmp( val.psz_string, "down" ) )
1844 osd_MenuDown( p_this );
1845 else if( !strcmp( val.psz_string, "left" ) )
1846 osd_MenuPrev( p_this );
1847 else if( !strcmp( val.psz_string, "right" ) )
1848 osd_MenuNext( p_this );
1849 else if( !strcmp( val.psz_string, "select" ) )
1850 osd_MenuActivate( p_this );
1853 msg_rc( _("Please provide one of the following parameters:") );
1854 msg_rc( "[on|off|up|down|left|right|select]" );
1855 if( val.psz_string ) free( val.psz_string );
1859 i_error = VLC_SUCCESS;
1860 if( val.psz_string ) free( val.psz_string );
1865 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1867 INPUT_RECORD input_record;
1870 /* On Win32, select() only works on socket descriptors */
1871 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1872 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1874 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1875 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1878 if( input_record.EventType != KEY_EVENT ||
1879 !input_record.Event.KeyEvent.bKeyDown ||
1880 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1881 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1882 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1883 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1885 /* nothing interesting */
1889 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1891 /* Echo out the command */
1892 putc( p_buffer[ *pi_size ], stdout );
1894 /* Handle special keys */
1895 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1897 putc( '\n', stdout );
1900 switch( p_buffer[ *pi_size ] )
1906 putc( ' ', stdout );
1907 putc( '\b', stdout );
1918 if( *pi_size == MAX_LINE_LENGTH ||
1919 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1921 p_buffer[ *pi_size ] = 0;
1930 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1935 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1936 return ReadWin32( p_intf, p_buffer, pi_size );
1937 else if( p_intf->p_sys->i_socket == -1 )
1939 msleep( INTF_IDLE_SLEEP );
1944 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1945 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
1946 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1947 (uint8_t *)p_buffer + *pi_size, 1, VLC_FALSE ) ) > 0 )
1949 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1955 /* Connection closed */
1958 if( p_intf->p_sys->i_socket != -1 )
1960 net_Close( p_intf->p_sys->i_socket );
1961 p_intf->p_sys->i_socket = -1;
1964 /* Standard input closed: exit */
1965 vlc_object_kill( p_intf );
1967 p_buffer[ *pi_size ] = 0;
1971 if( *pi_size == MAX_LINE_LENGTH ||
1972 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1974 p_buffer[ *pi_size ] = 0;
1981 /*****************************************************************************
1982 * parse_MRL: build a input item from a full mrl
1983 *****************************************************************************
1984 * MRL format: "simplified-mrl [:option-name[=option-value]]"
1985 * We don't check for '"' or '\'', we just assume that a ':' that follows a
1986 * space is a new option. Should be good enough for our purpose.
1987 *****************************************************************************/
1988 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
1990 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
1991 #define SKIPTRAILINGSPACE( p, d ) \
1992 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
1994 input_item_t *p_item = NULL;
1995 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
1996 char **ppsz_options = NULL;
1997 int i, i_options = 0;
1999 if( !psz_mrl ) return 0;
2001 psz_mrl = psz_orig = strdup( psz_mrl );
2004 SKIPSPACE( psz_mrl );
2007 for( ; *psz_mrl; psz_mrl++ )
2009 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2011 /* We have a complete item */
2014 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2015 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2017 /* We have a complete item */
2022 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2023 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2025 /* Remove '"' and '\'' if necessary */
2026 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2027 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2028 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2029 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2031 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2032 else if( *psz_item )
2035 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2036 ppsz_options[i_options - 1] = &psz_item[1];
2039 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2042 /* Now create a playlist item */
2045 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2046 for( i = 0; i < i_options; i++ )
2048 input_ItemAddOption( p_item, ppsz_options[i] );
2052 if( i_options ) free( ppsz_options );
2058 /*****************************************************************************
2059 * checkUpdates : check for updates
2060 ****************************************************************************/
2061 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2063 update_iterator_t *p_uit;
2064 update_t *p_u = update_New( p_intf );
2065 if( p_u == NULL ) return;
2066 p_uit = update_iterator_New( p_u );
2071 if( strstr( psz_arg, "newer" ) )
2072 s |= UPDATE_RELEASE_STATUS_NEWER;
2073 if( strstr( psz_arg, "equal" ) )
2074 s |= UPDATE_RELEASE_STATUS_EQUAL;
2075 if( strstr( psz_arg, "older" ) )
2076 s |= UPDATE_RELEASE_STATUS_OLDER;
2077 if( s ) p_uit->i_rs = s;
2078 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2080 if( strstr( psz_arg, "undef" ) )
2081 t |= UPDATE_FILE_TYPE_UNDEF;
2082 if( strstr( psz_arg, "info" ) )
2083 t |= UPDATE_FILE_TYPE_INFO;
2084 if( strstr( psz_arg, "source" ) )
2085 t |= UPDATE_FILE_TYPE_SOURCE;
2086 if( strstr( psz_arg, "binary" ) )
2087 t |= UPDATE_FILE_TYPE_BINARY;
2088 if( strstr( psz_arg, "plugin" ) )
2089 t |= UPDATE_FILE_TYPE_PLUGIN;
2090 if( t ) p_uit->i_t = t;
2092 update_Check( p_u, VLC_FALSE );
2093 update_iterator_Action( p_uit, UPDATE_MIRROR );
2094 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2095 p_uit->mirror.psz_name,
2096 p_uit->mirror.psz_location,
2097 p_uit->mirror.psz_type );
2098 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2101 if( s & UPDATE_RELEASE )
2103 switch( p_uit->release.i_status )
2105 case UPDATE_RELEASE_STATUS_OLDER:
2106 psz_tmp = strdup( "older" );
2108 case UPDATE_RELEASE_STATUS_EQUAL:
2109 psz_tmp = strdup( "equal" );
2111 case UPDATE_RELEASE_STATUS_NEWER:
2112 psz_tmp = strdup( "newer" );
2115 psz_tmp = strdup( "?!?" );
2118 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2119 p_uit->release.psz_version,
2120 p_uit->release.psz_svn_revision,
2124 switch( p_uit->file.i_type )
2126 case UPDATE_FILE_TYPE_UNDEF:
2127 psz_tmp = strdup( "undef" );
2129 case UPDATE_FILE_TYPE_INFO:
2130 psz_tmp = strdup( "info" );
2132 case UPDATE_FILE_TYPE_SOURCE:
2133 psz_tmp = strdup( "source" );
2135 case UPDATE_FILE_TYPE_BINARY:
2136 psz_tmp = strdup( "binary" );
2138 case UPDATE_FILE_TYPE_PLUGIN:
2139 psz_tmp = strdup( "plugin" );
2142 psz_tmp = strdup( "?!?" );
2145 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2147 if( p_uit->file.l_size )
2149 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2150 asprintf( &psz_tmp, "(%ld GB)",
2151 p_uit->file.l_size / (1024*1024*1024) );
2152 if( p_uit->file.l_size > 1024 * 1024 )
2153 asprintf( &psz_tmp, "(%ld MB)",
2154 p_uit->file.l_size / (1024*1024) );
2155 else if( p_uit->file.l_size > 1024 )
2156 asprintf( &psz_tmp, "(%ld kB)",
2157 p_uit->file.l_size / 1024 );
2159 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2163 psz_tmp = strdup( "" );
2165 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2170 update_iterator_Delete( p_uit );
2172 update_Delete( p_u );