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 );
187 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
189 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
190 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
193 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
196 set_capability( "interface", 20 );
197 set_callbacks( Activate, Deactivate );
200 /*****************************************************************************
201 * Activate: initialize and create stuff
202 *****************************************************************************/
203 static int Activate( vlc_object_t *p_this )
205 intf_thread_t *p_intf = (intf_thread_t*)p_this;
206 char *psz_host, *psz_unix_path;
207 int *pi_socket = NULL;
209 #if defined(HAVE_ISATTY) && !defined(WIN32)
210 /* Check that stdin is a TTY */
211 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
213 msg_Warn( p_intf, "fd 0 is not a TTY" );
218 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
223 #if !defined(AF_LOCAL) || defined(WIN32)
224 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
225 free( psz_unix_path );
228 struct sockaddr_un addr;
230 memset( &addr, 0, sizeof(struct sockaddr_un) );
232 msg_Dbg( p_intf, "trying UNIX socket" );
234 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
236 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
237 free( psz_unix_path );
241 addr.sun_family = AF_LOCAL;
242 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
243 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
245 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
246 && (errno == EADDRINUSE)
247 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
248 && (errno == ECONNREFUSED))
250 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
251 unlink (psz_unix_path);
253 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
255 msg_Err (p_intf, "cannot bind UNIX socket at %s: %s",
256 psz_unix_path, strerror (errno));
257 free (psz_unix_path);
258 net_Close (i_socket);
263 if( listen( i_socket, 1 ) )
265 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
266 free( psz_unix_path );
267 net_Close( i_socket );
271 /* FIXME: we need a core function to merge listening sockets sets */
272 pi_socket = calloc( 2, sizeof( int ) );
273 if( pi_socket == NULL )
275 free( psz_unix_path );
276 net_Close( i_socket );
279 pi_socket[0] = i_socket;
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 p_intf->b_die = VLC_TRUE;
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 )
500 msg_rc( STATUS_CHANGE "( new input: %s )",
501 input_GetItem(p_input)->psz_uri );
502 msg_rc( STATUS_CHANGE "( audio volume: %d )",
503 config_GetInt( p_intf, "volume" ));
505 var_AddCallback( p_input, "state", StateChanged, p_intf );
506 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
507 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
508 var_AddCallback( p_input, "rate", RateChanged, p_intf );
509 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
513 else if( p_input->b_dead )
515 var_DelCallback( p_input, "state", StateChanged, p_intf );
516 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
517 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
518 var_DelCallback( p_input, "rate", RateChanged, p_intf );
519 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
521 vlc_object_release( p_input );
526 vlc_mutex_lock( &p_playlist->object_lock );
527 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
528 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
529 vlc_mutex_unlock( &p_playlist->object_lock );
533 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
534 (p_playlist != NULL) )
536 vlc_mutex_lock( &p_playlist->object_lock );
537 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
538 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
540 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
541 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
544 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
545 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
547 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
548 msg_rc( STATUS_CHANGE "( play state: 1 )" );
551 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
552 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
554 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
555 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
557 vlc_mutex_unlock( &p_playlist->object_lock );
560 if( p_input && b_showpos )
562 i_newpos = 100 * var_GetFloat( p_input, "position" );
563 if( i_oldpos != i_newpos )
566 msg_rc( "pos: %d%%", i_newpos );
570 /* Is there something to do? */
571 if( !b_complete ) continue;
574 /* Skip heading spaces */
576 while( *psz_cmd == ' ' )
581 /* Split psz_cmd at the first space and make sure that
582 * psz_arg is valid */
583 psz_arg = strchr( psz_cmd, ' ' );
587 while( *psz_arg == ' ' )
597 /* module specfic commands: @<module name> <command> <args...> */
598 if( *psz_cmd == '@' && *psz_arg )
600 /* Parse miscellaneous commands */
601 char *psz_alias = psz_cmd + 1;
602 char *psz_mycmd = strdup( psz_arg );
603 char *psz_myarg = strchr( psz_mycmd, ' ' );
604 int i_ret = VLC_EGENERIC;
608 vlc_object_t *p_obj =
609 vlc_object_find_name( p_input->p_libvlc, psz_alias,
613 msg_rc( "Unknown destination object!" );
617 if( (i_type = var_Type( p_obj, psz_mycmd )) & VLC_VAR_ISCOMMAND )
620 if( i_type == VLC_VAR_INTEGER )
622 i_ret = var_SetInteger( p_obj, psz_mycmd,
625 else if( i_type == VLC_VAR_FLOAT )
627 i_ret = var_SetFloat( p_obj, psz_mycmd,
630 else if( i_type == VLC_VAR_STRING )
632 i_ret = var_SetString( p_obj, psz_mycmd,
635 else if( i_type == VLC_VAR_BOOL )
637 i_ret = var_SetBool( p_obj, psz_mycmd,
642 msg_rc( "Unhandled command type. Fix the code!" );
647 msg_rc( "Unknown command! %d", i_type );
649 vlc_object_release( p_obj );
652 msg_rc( "%s on object %s: returned %i (%s)",
653 psz_mycmd, psz_alias, i_ret, vlc_error( i_ret ) );
655 /* If the user typed a registered local command, try it */
656 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
661 val.psz_string = psz_arg;
662 i_ret = var_Set( p_intf, psz_cmd, val );
663 msg_rc( "%s: returned %i (%s)",
664 psz_cmd, i_ret, vlc_error( i_ret ) );
666 /* Or maybe it's a global command */
667 else if( var_Type( p_intf->p_libvlc_global, psz_cmd ) & VLC_VAR_ISCOMMAND )
672 val.psz_string = psz_arg;
673 /* FIXME: it's a global command, but we should pass the
674 * local object as an argument, not p_intf->p_libvlc_global. */
675 i_ret = var_Set( p_intf->p_libvlc_global, psz_cmd, val );
678 msg_rc( "%s: returned %i (%s)",
679 psz_cmd, i_ret, vlc_error( i_ret ) );
682 else if( !strcmp( psz_cmd, "logout" ) )
684 /* Close connection */
685 if( p_intf->p_sys->i_socket != -1 )
687 net_Close( p_intf->p_sys->i_socket );
689 p_intf->p_sys->i_socket = -1;
691 else if( !strcmp( psz_cmd, "info" ) )
696 vlc_mutex_lock( &input_GetItem(p_input)->lock );
697 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
699 info_category_t *p_category = input_GetItem(p_input)
702 msg_rc( "+----[ %s ]", p_category->psz_name );
704 for ( j = 0; j < p_category->i_infos; j++ )
706 info_t *p_info = p_category->pp_infos[j];
707 msg_rc( "| %s: %s", p_info->psz_name,
712 msg_rc( "+----[ end of stream info ]" );
713 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
717 msg_rc( "no input" );
720 else if( !strcmp( psz_cmd, "is_playing" ) )
731 else if( !strcmp( psz_cmd, "get_time" ) )
740 var_Get( p_input, "time", &time );
741 msg_rc( "%i", time.i_time / 1000000);
744 else if( !strcmp( psz_cmd, "get_length" ) )
753 var_Get( p_input, "length", &time );
754 msg_rc( "%i", time.i_time / 1000000);
757 else if( !strcmp( psz_cmd, "get_title" ) )
765 msg_rc( "%s", input_GetItem(p_input)->psz_name );
768 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
769 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
771 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
772 b_longhelp = VLC_TRUE;
773 else b_longhelp = VLC_FALSE;
775 Help( p_intf, b_longhelp );
777 else if( !strcmp( psz_cmd, "check-updates" ) )
779 checkUpdates( p_intf, psz_arg );
781 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
783 var_SetInteger( p_intf->p_libvlc, "key-pressed",
784 config_GetInt( p_intf, psz_arg ) );
786 else switch( psz_cmd[0] )
792 vout_thread_t *p_vout;
793 p_vout = vlc_object_find( p_input,
794 VLC_OBJECT_VOUT, FIND_CHILD );
799 vlc_bool_t b_update = VLC_FALSE;
800 var_Get( p_vout, "fullscreen", &val );
801 val.b_bool = !val.b_bool;
802 if( !strncmp( psz_arg, "on", 2 )
803 && ( val.b_bool == VLC_TRUE ) )
806 val.b_bool = VLC_TRUE;
808 else if( !strncmp( psz_arg, "off", 3 )
809 && ( val.b_bool == VLC_FALSE ) )
812 val.b_bool = VLC_FALSE;
814 else if( strncmp( psz_arg, "off", 3 )
815 && strncmp( psz_arg, "on", 2 ) )
817 if( b_update ) var_Set( p_vout, "fullscreen", val );
818 vlc_object_release( p_vout );
829 /* Ignore empty lines */
833 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
837 /* Command processed */
838 i_size = 0; p_buffer[0] = 0;
841 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
842 msg_rc( STATUS_CHANGE "( quit )" );
846 var_DelCallback( p_input, "state", StateChanged, p_intf );
847 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
848 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
849 var_DelCallback( p_input, "rate", RateChanged, p_intf );
850 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
851 vlc_object_release( p_input );
857 vlc_object_release( p_playlist );
861 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
864 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
866 msg_rc(_("+----[ Remote control commands ]"));
868 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
869 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
870 msg_rc(_("| playlist . . . . . show items currently in playlist"));
871 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
872 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
873 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
874 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
875 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
876 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
877 msg_rc(_("| loop [on|off] . . . . . . toggle playlist item loop"));
878 msg_rc(_("| clear . . . . . . . . . . . . . clear the playlist"));
879 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
880 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
881 msg_rc(_("| title_n . . . . . . . . next title in current item"));
882 msg_rc(_("| title_p . . . . . . previous title in current item"));
883 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
884 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
885 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
887 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
888 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
889 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
890 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
891 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
892 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
893 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
894 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
895 msg_rc(_("| info . . . . . information about the current stream"));
896 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
897 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
898 msg_rc(_("| get_title . . . . . the title of the current stream"));
899 msg_rc(_("| get_length . . . . the length of the current stream"));
901 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
902 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
903 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
904 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
905 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
906 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
907 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
908 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
909 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
910 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
911 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
912 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
913 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
918 msg_rc(_("| marq-marquee name STRING . . overlay STRING in video"));
919 msg_rc(_("| marq-x name X . . . . . . . . . . . .offset from left"));
920 msg_rc(_("| marq-y name Y . . . . . . . . . . . . offset from top"));
921 msg_rc(_("| marq-position name #. . . .relative position control"));
922 msg_rc(_("| marq-color name # . . . . . . . . . . font color, RGB"));
923 msg_rc(_("| marq-opacity name # . . . . . . . . . . . . . opacity"));
924 msg_rc(_("| marq-timeout name T. . . . . . . . . . timeout, in ms"));
925 msg_rc(_("| marq-size name # . . . . . . . . font size, in pixels"));
927 msg_rc(_("| logo-file name STRING . . .the overlay file path/name"));
928 msg_rc(_("| logo-x name X . . . . . . . . . . . .offset from left"));
929 msg_rc(_("| logo-y name Y . . . . . . . . . . . . offset from top"));
930 msg_rc(_("| logo-position name #. . . . . . . . relative position"));
931 msg_rc(_("| logo-transparency name #. . . . . . . . .transparency"));
933 msg_rc(_("| mosaic-alpha name # . . . . . . . . . . . . . . alpha"));
934 msg_rc(_("| mosaic-height name #. . . . . . . . . . . . . .height"));
935 msg_rc(_("| mosaic-width name # . . . . . . . . . . . . . . width"));
936 msg_rc(_("| mosaic-xoffset name # . . . .top left corner position"));
937 msg_rc(_("| mosaic-yoffset name # . . . .top left corner position"));
938 msg_rc(_("| mosaic-offsets name x,y(,x,y)*. . . . list of offsets"));
939 msg_rc(_("| mosaic-align name 0..2,4..6,8..10. . .mosaic alignment"));
940 msg_rc(_("| mosaic-vborder name # . . . . . . . . vertical border"));
941 msg_rc(_("| mosaic-hborder name # . . . . . . . horizontal border"));
942 msg_rc(_("| mosaic-position name {0=auto,1=fixed} . . . .position"));
943 msg_rc(_("| mosaic-rows name #. . . . . . . . . . .number of rows"));
944 msg_rc(_("| mosaic-cols name #. . . . . . . . . . .number of cols"));
945 msg_rc(_("| mosaic-order name id(,id)* . . . . order of pictures "));
946 msg_rc(_("| mosaic-keep-aspect-ratio name {0,1} . . .aspect ratio"));
948 msg_rc(_("| check-updates [newer] [equal] [older]\n"
949 "| [undef] [info] [source] [binary] [plugin]"));
952 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
953 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
954 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
955 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
957 msg_rc(_("+----[ end of help ]"));
960 /********************************************************************
961 * Status callback routines
962 ********************************************************************/
963 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
964 vlc_value_t oldval, vlc_value_t newval, void *p_data )
966 intf_thread_t *p_intf = (intf_thread_t*)p_data;
967 input_thread_t *p_input = NULL;
969 vlc_mutex_lock( &p_intf->p_sys->status_lock );
970 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
973 msg_rc( STATUS_CHANGE "( time-offset: %d )",
974 var_GetInteger( p_input, "time-offset" ) );
975 vlc_object_release( p_input );
977 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
981 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
982 vlc_value_t oldval, vlc_value_t newval, void *p_data )
984 intf_thread_t *p_intf = (intf_thread_t*)p_data;
986 vlc_mutex_lock( &p_intf->p_sys->status_lock );
987 msg_rc( STATUS_CHANGE "( audio volume: %d )",
988 config_GetInt( p_this, "volume") );
989 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
993 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
994 vlc_value_t oldval, vlc_value_t newval, void *p_data )
996 intf_thread_t *p_intf = (intf_thread_t*)p_data;
997 playlist_t *p_playlist = NULL;
998 input_thread_t *p_input = NULL;
1000 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1001 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1004 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
1008 switch( p_playlist->status.i_status )
1010 case PLAYLIST_STOPPED:
1011 strncpy( &cmd[0], "stop", 4);
1014 case PLAYLIST_RUNNING:
1015 strncpy( &cmd[0], "play", 4);
1018 case PLAYLIST_PAUSED:
1019 strncpy( &cmd[0], "pause", 5);
1022 } /* var_GetInteger( p_input, "state" ) */
1023 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1024 vlc_object_release( p_playlist );
1026 vlc_object_release( p_input );
1028 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1032 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1033 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1035 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1036 input_thread_t *p_input = NULL;
1038 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1039 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1042 msg_rc( STATUS_CHANGE "( new rate: %d )",
1043 var_GetInteger( p_input, "rate" ) );
1044 vlc_object_release( p_input );
1046 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1050 /********************************************************************
1052 ********************************************************************/
1053 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1054 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1056 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1057 input_thread_t *p_input;
1060 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1061 if( !p_input ) return VLC_ENOOBJ;
1063 var_Get( p_input, "state", &val );
1064 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1065 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1067 msg_rc( _("Press menu select or pause to continue.") );
1068 vlc_object_release( p_input );
1069 return VLC_EGENERIC;
1072 /* Parse commands that only require an input */
1073 if( !strcmp( psz_cmd, "pause" ) )
1075 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1076 var_Set( p_intf->p_libvlc, "key-pressed", val );
1077 vlc_object_release( p_input );
1080 else if( !strcmp( psz_cmd, "seek" ) )
1082 if( strlen( newval.psz_string ) > 0 &&
1083 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1085 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1086 var_Set( p_input, "position", val );
1090 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1091 var_Set( p_input, "time", val );
1093 vlc_object_release( p_input );
1096 else if ( !strcmp( psz_cmd, "fastforward" ) )
1098 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1099 var_Set( p_intf->p_libvlc, "key-pressed", val );
1100 vlc_object_release( p_input );
1103 else if ( !strcmp( psz_cmd, "rewind" ) )
1105 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1106 var_Set( p_intf->p_libvlc, "key-pressed", val );
1107 vlc_object_release( p_input );
1110 else if ( !strcmp( psz_cmd, "faster" ) )
1112 val.b_bool = VLC_TRUE;
1113 var_Set( p_input, "rate-faster", val );
1114 vlc_object_release( p_input );
1117 else if ( !strcmp( psz_cmd, "slower" ) )
1119 val.b_bool = VLC_TRUE;
1120 var_Set( p_input, "rate-slower", val );
1121 vlc_object_release( p_input );
1124 else if ( !strcmp( psz_cmd, "normal" ) )
1126 val.i_int = INPUT_RATE_DEFAULT;
1127 var_Set( p_input, "rate", val );
1128 vlc_object_release( p_input );
1131 else if( !strcmp( psz_cmd, "chapter" ) ||
1132 !strcmp( psz_cmd, "chapter_n" ) ||
1133 !strcmp( psz_cmd, "chapter_p" ) )
1135 if( !strcmp( psz_cmd, "chapter" ) )
1137 if ( *newval.psz_string )
1140 val.i_int = atoi( newval.psz_string );
1141 var_Set( p_input, "chapter", val );
1145 vlc_value_t val_list;
1148 var_Get( p_input, "chapter", &val );
1149 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1151 msg_rc( "Currently playing chapter %d/%d.",
1152 val.i_int, val_list.p_list->i_count );
1153 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1157 else if( !strcmp( psz_cmd, "chapter_n" ) )
1159 val.b_bool = VLC_TRUE;
1160 var_Set( p_input, "next-chapter", val );
1162 else if( !strcmp( psz_cmd, "chapter_p" ) )
1164 val.b_bool = VLC_TRUE;
1165 var_Set( p_input, "prev-chapter", val );
1167 vlc_object_release( p_input );
1170 else if( !strcmp( psz_cmd, "title" ) ||
1171 !strcmp( psz_cmd, "title_n" ) ||
1172 !strcmp( psz_cmd, "title_p" ) )
1174 if( !strcmp( psz_cmd, "title" ) )
1176 if ( *newval.psz_string )
1179 val.i_int = atoi( newval.psz_string );
1180 var_Set( p_input, "title", val );
1184 vlc_value_t val_list;
1187 var_Get( p_input, "title", &val );
1188 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1190 msg_rc( "Currently playing title %d/%d.",
1191 val.i_int, val_list.p_list->i_count );
1192 var_Change( p_this, "title", VLC_VAR_FREELIST,
1196 else if( !strcmp( psz_cmd, "title_n" ) )
1198 val.b_bool = VLC_TRUE;
1199 var_Set( p_input, "next-title", val );
1201 else if( !strcmp( psz_cmd, "title_p" ) )
1203 val.b_bool = VLC_TRUE;
1204 var_Set( p_input, "prev-title", val );
1207 vlc_object_release( p_input );
1210 else if( !strcmp( psz_cmd, "atrack" )
1211 || !strcmp( psz_cmd, "vtrack" )
1212 || !strcmp( psz_cmd, "strack" ) )
1214 const char *psz_variable;
1215 vlc_value_t val_name;
1218 if( !strcmp( psz_cmd, "atrack" ) )
1220 psz_variable = "audio-es";
1222 else if( !strcmp( psz_cmd, "vtrack" ) )
1224 psz_variable = "video-es";
1228 psz_variable = "spu-es";
1231 /* Get the descriptive name of the variable */
1232 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1234 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1236 if( newval.psz_string && *newval.psz_string )
1240 val.i_int = atoi( newval.psz_string );
1242 i_error = var_Set( p_input, psz_variable, val );
1247 vlc_value_t val, text;
1250 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1252 vlc_object_release( p_input );
1253 return VLC_EGENERIC;
1255 i_value = val.i_int;
1257 if ( var_Change( p_input, psz_variable,
1258 VLC_VAR_GETLIST, &val, &text ) < 0 )
1260 vlc_object_release( p_input );
1261 return VLC_EGENERIC;
1264 msg_rc( "+----[ %s ]", val_name.psz_string );
1265 for ( i = 0; i < val.p_list->i_count; i++ )
1267 if ( i_value == val.p_list->p_values[i].i_int )
1268 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1269 text.p_list->p_values[i].psz_string );
1271 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1272 text.p_list->p_values[i].psz_string );
1274 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1276 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1278 if( val_name.psz_string ) free( val_name.psz_string );
1280 i_error = VLC_SUCCESS;
1282 vlc_object_release( p_input );
1286 /* Never reached. */
1287 vlc_object_release( p_input );
1288 return VLC_EGENERIC;
1291 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1292 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1296 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1297 playlist_t *p_playlist = pl_Yield( p_this );
1300 if( p_playlist->p_input )
1302 var_Get( p_playlist->p_input, "state", &val );
1303 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1305 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1306 vlc_object_release( p_playlist );
1308 return VLC_EGENERIC;
1313 /* Parse commands that require a playlist */
1314 if( !strcmp( psz_cmd, "prev" ) )
1316 playlist_Prev( p_playlist );
1318 else if( !strcmp( psz_cmd, "next" ) )
1320 playlist_Next( p_playlist );
1322 else if( !strcmp( psz_cmd, "play" ) )
1324 msg_Warn( p_playlist, "play" );
1325 playlist_Play( p_playlist );
1327 else if( !strcmp( psz_cmd, "repeat" ) )
1329 vlc_bool_t b_update = VLC_TRUE;
1331 var_Get( p_playlist, "repeat", &val );
1333 if( strlen( newval.psz_string ) > 0 )
1335 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1336 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1338 b_update = VLC_FALSE;
1344 val.b_bool = !val.b_bool;
1345 var_Set( p_playlist, "repeat", val );
1347 msg_rc( "Setting repeat to %d", val.b_bool );
1349 else if( !strcmp( psz_cmd, "loop" ) )
1351 vlc_bool_t b_update = VLC_TRUE;
1353 var_Get( p_playlist, "loop", &val );
1355 if( strlen( newval.psz_string ) > 0 )
1357 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1358 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1360 b_update = VLC_FALSE;
1366 val.b_bool = !val.b_bool;
1367 var_Set( p_playlist, "loop", val );
1369 msg_rc( "Setting loop to %d", val.b_bool );
1371 else if (!strcmp( psz_cmd, "goto" ) )
1373 msg_rc( _("goto is deprecated" ) );
1374 msg_Err( p_playlist, "goto is deprecated" );
1376 else if( !strcmp( psz_cmd, "stop" ) )
1378 playlist_Stop( p_playlist );
1380 else if( !strcmp( psz_cmd, "clear" ) )
1382 playlist_Stop( p_playlist );
1383 playlist_Clear( p_playlist, VLC_FALSE );
1385 else if( !strcmp( psz_cmd, "add" ) &&
1386 newval.psz_string && *newval.psz_string )
1388 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1392 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1393 playlist_AddInput( p_playlist, p_item,
1394 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1398 else if( !strcmp( psz_cmd, "enqueue" ) &&
1399 newval.psz_string && *newval.psz_string )
1401 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1405 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1406 playlist_AddInput( p_playlist, p_item,
1407 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1411 else if( !strcmp( psz_cmd, "playlist" ) )
1413 msg_Dbg( p_playlist, "Dumping category" );
1414 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1415 msg_Dbg( p_playlist, "Dumping Onelevel" );
1416 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1418 else if( !strcmp( psz_cmd, "sort" ))
1420 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1421 SORT_ARTIST, ORDER_NORMAL );
1423 else if( !strcmp( psz_cmd, "status" ) )
1425 if( p_playlist->p_input )
1427 /* Replay the current state of the system. */
1428 msg_rc( STATUS_CHANGE "( new input: %s )",
1429 input_GetItem(p_playlist->p_input)->psz_uri );
1430 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1431 config_GetInt( p_intf, "volume" ));
1433 vlc_mutex_lock( &p_playlist->object_lock );
1434 switch( p_playlist->status.i_status )
1436 case PLAYLIST_STOPPED:
1437 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1439 case PLAYLIST_RUNNING:
1440 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1442 case PLAYLIST_PAUSED:
1443 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1446 msg_rc( STATUS_CHANGE "( state unknown )" );
1449 vlc_mutex_unlock( &p_playlist->object_lock );
1458 msg_rc( "unknown command!" );
1461 vlc_object_release( p_playlist );
1465 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1466 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1468 playlist_t *p_playlist;
1470 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1473 playlist_Stop( p_playlist );
1474 vlc_object_release( p_playlist );
1476 p_this->p_libvlc->b_die = VLC_TRUE;
1480 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1481 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1483 intf_thread_t *p_newintf = NULL;
1485 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1488 p_newintf->b_block = VLC_FALSE;
1489 if( intf_RunThread( p_newintf ) )
1491 vlc_object_detach( p_newintf );
1492 intf_Destroy( p_newintf );
1499 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1500 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1502 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1503 input_thread_t *p_input = NULL;
1504 int i_error = VLC_EGENERIC;
1506 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1514 var_Get( p_input, "state", &val );
1515 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1517 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1518 vlc_object_release( p_input );
1519 return VLC_EGENERIC;
1521 vlc_object_release( p_input );
1524 if ( *newval.psz_string )
1527 audio_volume_t i_volume = atoi( newval.psz_string );
1528 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1530 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1532 i_error = VLC_EBADVAR;
1536 if( i_volume == AOUT_VOLUME_MIN )
1540 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1541 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1543 i_error = aout_VolumeSet( p_this, i_volume );
1544 osd_Volume( p_this );
1545 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1551 audio_volume_t i_volume;
1552 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1554 i_error = VLC_EGENERIC;
1558 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1559 i_error = VLC_SUCCESS;
1566 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1567 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1569 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1570 audio_volume_t i_volume;
1571 input_thread_t *p_input = NULL;
1572 int i_nb_steps = atoi(newval.psz_string);
1573 int i_error = VLC_SUCCESS;
1574 int i_volume_step = 0;
1576 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1584 var_Get( p_input, "state", &val );
1585 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1587 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1588 vlc_object_release( p_input );
1589 return VLC_EGENERIC;
1591 vlc_object_release( p_input );
1594 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1595 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1600 if ( !strcmp(psz_cmd, "volup") )
1602 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1603 i_error = VLC_EGENERIC;
1607 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1608 i_error = VLC_EGENERIC;
1610 osd_Volume( p_this );
1612 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1617 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1618 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1620 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1621 input_thread_t *p_input = NULL;
1622 vout_thread_t * p_vout;
1623 const char * psz_variable;
1624 vlc_value_t val_name;
1627 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1631 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1632 vlc_object_release( p_input );
1636 if( !strcmp( psz_cmd, "vcrop" ) )
1638 psz_variable = "crop";
1640 else if( !strcmp( psz_cmd, "vratio" ) )
1642 psz_variable = "aspect-ratio";
1644 else /* if( !strcmp( psz_cmd, "vzoom" ) ) */
1646 psz_variable = "zoom";
1650 /* Get the descriptive name of the variable */
1651 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1653 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1655 if( newval.psz_string && *newval.psz_string )
1658 if( !strcmp( psz_variable, "zoom" ) )
1661 val.f_float = atof( newval.psz_string );
1662 i_error = var_Set( p_vout, psz_variable, val );
1666 i_error = var_Set( p_vout, psz_variable, newval );
1672 vlc_value_t val, text;
1675 char *psz_value = NULL;
1677 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1679 vlc_object_release( p_vout );
1680 return VLC_EGENERIC;
1682 if( !strcmp( psz_variable, "zoom" ) )
1684 f_value = val.f_float;
1688 psz_value = strdup( val.psz_string );
1691 if ( var_Change( p_vout, psz_variable,
1692 VLC_VAR_GETLIST, &val, &text ) < 0 )
1694 vlc_object_release( p_vout );
1695 return VLC_EGENERIC;
1698 msg_rc( "+----[ %s ]", val_name.psz_string );
1699 if( !strcmp( psz_variable, "zoom" ) )
1701 for ( i = 0; i < val.p_list->i_count; i++ )
1703 if ( f_value == val.p_list->p_values[i].f_float )
1704 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1705 text.p_list->p_values[i].psz_string );
1707 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1708 text.p_list->p_values[i].psz_string );
1713 for ( i = 0; i < val.p_list->i_count; i++ )
1715 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1716 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1717 text.p_list->p_values[i].psz_string );
1719 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1720 text.p_list->p_values[i].psz_string );
1724 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1726 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1728 if( val_name.psz_string ) free( val_name.psz_string );
1730 i_error = VLC_SUCCESS;
1732 vlc_object_release( p_vout );
1736 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1737 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1739 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1740 input_thread_t *p_input = NULL;
1741 aout_instance_t * p_aout;
1742 const char * psz_variable;
1743 vlc_value_t val_name;
1746 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1754 var_Get( p_input, "state", &val );
1755 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1756 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1757 vlc_object_release( p_input );
1758 return VLC_EGENERIC;
1760 vlc_object_release( p_input );
1763 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1764 if ( p_aout == NULL ) return VLC_ENOOBJ;
1766 if ( !strcmp( psz_cmd, "adev" ) )
1768 psz_variable = "audio-device";
1772 psz_variable = "audio-channels";
1775 /* Get the descriptive name of the variable */
1776 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1778 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1780 if ( !*newval.psz_string )
1782 /* Retrieve all registered ***. */
1783 vlc_value_t val, text;
1786 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1788 vlc_object_release( (vlc_object_t *)p_aout );
1789 return VLC_EGENERIC;
1791 i_value = val.i_int;
1793 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1794 VLC_VAR_GETLIST, &val, &text ) < 0 )
1796 vlc_object_release( (vlc_object_t *)p_aout );
1797 return VLC_EGENERIC;
1800 msg_rc( "+----[ %s ]", val_name.psz_string );
1801 for ( i = 0; i < val.p_list->i_count; i++ )
1803 if ( i_value == val.p_list->p_values[i].i_int )
1804 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1805 text.p_list->p_values[i].psz_string );
1807 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1808 text.p_list->p_values[i].psz_string );
1810 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1812 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1814 if( val_name.psz_string ) free( val_name.psz_string );
1815 i_error = VLC_SUCCESS;
1820 val.i_int = atoi( newval.psz_string );
1822 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1824 vlc_object_release( (vlc_object_t *)p_aout );
1829 /* OSD menu commands */
1830 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1831 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1833 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1834 playlist_t *p_playlist = NULL;
1836 int i_error = VLC_EGENERIC;
1838 if ( !*newval.psz_string )
1840 msg_rc( _("Please provide one of the following parameters:") );
1841 msg_rc( "[on|off|up|down|left|right|select]" );
1845 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1849 if( p_playlist->p_input )
1851 var_Get( p_playlist->p_input, "state", &val );
1852 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1853 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1855 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1856 vlc_object_release( p_playlist );
1857 return VLC_EGENERIC;
1860 vlc_object_release( p_playlist );
1862 val.psz_string = strdup( newval.psz_string );
1863 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1864 osd_MenuShow( p_this );
1865 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1866 osd_MenuHide( p_this );
1867 else if( !strcmp( val.psz_string, "up" ) )
1868 osd_MenuUp( p_this );
1869 else if( !strcmp( val.psz_string, "down" ) )
1870 osd_MenuDown( p_this );
1871 else if( !strcmp( val.psz_string, "left" ) )
1872 osd_MenuPrev( p_this );
1873 else if( !strcmp( val.psz_string, "right" ) )
1874 osd_MenuNext( p_this );
1875 else if( !strcmp( val.psz_string, "select" ) )
1876 osd_MenuActivate( p_this );
1879 msg_rc( _("Please provide one of the following parameters:") );
1880 msg_rc( "[on|off|up|down|left|right|select]" );
1881 if( val.psz_string ) free( val.psz_string );
1885 i_error = VLC_SUCCESS;
1886 if( val.psz_string ) free( val.psz_string );
1891 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1893 INPUT_RECORD input_record;
1896 /* On Win32, select() only works on socket descriptors */
1897 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1898 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1900 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1901 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1904 if( input_record.EventType != KEY_EVENT ||
1905 !input_record.Event.KeyEvent.bKeyDown ||
1906 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1907 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1908 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1909 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1911 /* nothing interesting */
1915 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1917 /* Echo out the command */
1918 putc( p_buffer[ *pi_size ], stdout );
1920 /* Handle special keys */
1921 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1923 putc( '\n', stdout );
1926 switch( p_buffer[ *pi_size ] )
1932 putc( ' ', stdout );
1933 putc( '\b', stdout );
1944 if( *pi_size == MAX_LINE_LENGTH ||
1945 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1947 p_buffer[ *pi_size ] = 0;
1956 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1961 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1962 return ReadWin32( p_intf, p_buffer, pi_size );
1963 else if( p_intf->p_sys->i_socket == -1 )
1965 msleep( INTF_IDLE_SLEEP );
1970 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1971 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
1972 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1973 (uint8_t *)p_buffer + *pi_size, 1, VLC_FALSE ) ) > 0 )
1975 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1981 /* Connection closed */
1984 if( p_intf->p_sys->i_socket != -1 )
1986 net_Close( p_intf->p_sys->i_socket );
1987 p_intf->p_sys->i_socket = -1;
1990 /* Standard input closed: exit */
1991 p_intf->b_die = VLC_TRUE;
1993 p_buffer[ *pi_size ] = 0;
1997 if( *pi_size == MAX_LINE_LENGTH ||
1998 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2000 p_buffer[ *pi_size ] = 0;
2007 /*****************************************************************************
2008 * parse_MRL: build a input item from a full mrl
2009 *****************************************************************************
2010 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2011 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2012 * space is a new option. Should be good enough for our purpose.
2013 *****************************************************************************/
2014 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2016 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2017 #define SKIPTRAILINGSPACE( p, d ) \
2018 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2020 input_item_t *p_item = NULL;
2021 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2022 char **ppsz_options = NULL;
2023 int i, i_options = 0;
2025 if( !psz_mrl ) return 0;
2027 psz_mrl = psz_orig = strdup( psz_mrl );
2030 SKIPSPACE( psz_mrl );
2033 for( ; *psz_mrl; psz_mrl++ )
2035 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2037 /* We have a complete item */
2040 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2041 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2043 /* We have a complete item */
2048 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2049 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2051 /* Remove '"' and '\'' if necessary */
2052 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2053 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2054 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2055 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2057 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2058 else if( *psz_item )
2061 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2062 ppsz_options[i_options - 1] = &psz_item[1];
2065 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2068 /* Now create a playlist item */
2071 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2072 for( i = 0; i < i_options; i++ )
2074 input_ItemAddOption( p_item, ppsz_options[i] );
2078 if( i_options ) free( ppsz_options );
2084 /*****************************************************************************
2085 * checkUpdates : check for updates
2086 ****************************************************************************/
2087 static void checkUpdates( intf_thread_t *p_intf, char *psz_arg )
2089 update_iterator_t *p_uit;
2090 update_t *p_u = update_New( p_intf );
2091 if( p_u == NULL ) return;
2092 p_uit = update_iterator_New( p_u );
2097 if( strstr( psz_arg, "newer" ) )
2098 s |= UPDATE_RELEASE_STATUS_NEWER;
2099 if( strstr( psz_arg, "equal" ) )
2100 s |= UPDATE_RELEASE_STATUS_EQUAL;
2101 if( strstr( psz_arg, "older" ) )
2102 s |= UPDATE_RELEASE_STATUS_OLDER;
2103 if( s ) p_uit->i_rs = s;
2104 else p_uit->i_rs = UPDATE_RELEASE_STATUS_NEWER;
2106 if( strstr( psz_arg, "undef" ) )
2107 t |= UPDATE_FILE_TYPE_UNDEF;
2108 if( strstr( psz_arg, "info" ) )
2109 t |= UPDATE_FILE_TYPE_INFO;
2110 if( strstr( psz_arg, "source" ) )
2111 t |= UPDATE_FILE_TYPE_SOURCE;
2112 if( strstr( psz_arg, "binary" ) )
2113 t |= UPDATE_FILE_TYPE_BINARY;
2114 if( strstr( psz_arg, "plugin" ) )
2115 t |= UPDATE_FILE_TYPE_PLUGIN;
2116 if( t ) p_uit->i_t = t;
2118 update_Check( p_u, VLC_FALSE );
2119 update_iterator_Action( p_uit, UPDATE_MIRROR );
2120 msg_rc( "\nUsing mirror: %s (%s) [%s]",
2121 p_uit->mirror.psz_name,
2122 p_uit->mirror.psz_location,
2123 p_uit->mirror.psz_type );
2124 while( (s = update_iterator_Action( p_uit, UPDATE_FILE )) != UPDATE_FAIL )
2127 if( s & UPDATE_RELEASE )
2129 switch( p_uit->release.i_status )
2131 case UPDATE_RELEASE_STATUS_OLDER:
2132 psz_tmp = strdup( "older" );
2134 case UPDATE_RELEASE_STATUS_EQUAL:
2135 psz_tmp = strdup( "equal" );
2137 case UPDATE_RELEASE_STATUS_NEWER:
2138 psz_tmp = strdup( "newer" );
2141 psz_tmp = strdup( "?!?" );
2144 msg_rc( "\n+----[ VLC %s %s (%s) ] ",
2145 p_uit->release.psz_version,
2146 p_uit->release.psz_svn_revision,
2150 switch( p_uit->file.i_type )
2152 case UPDATE_FILE_TYPE_UNDEF:
2153 psz_tmp = strdup( "undef" );
2155 case UPDATE_FILE_TYPE_INFO:
2156 psz_tmp = strdup( "info" );
2158 case UPDATE_FILE_TYPE_SOURCE:
2159 psz_tmp = strdup( "source" );
2161 case UPDATE_FILE_TYPE_BINARY:
2162 psz_tmp = strdup( "binary" );
2164 case UPDATE_FILE_TYPE_PLUGIN:
2165 psz_tmp = strdup( "plugin" );
2168 psz_tmp = strdup( "?!?" );
2171 msg_rc( "| %s (%s)", p_uit->file.psz_description, psz_tmp );
2173 if( p_uit->file.l_size )
2175 if( p_uit->file.l_size > 1024 * 1024 * 1024 )
2176 asprintf( &psz_tmp, "(%ld GB)",
2177 p_uit->file.l_size / (1024*1024*1024) );
2178 if( p_uit->file.l_size > 1024 * 1024 )
2179 asprintf( &psz_tmp, "(%ld MB)",
2180 p_uit->file.l_size / (1024*1024) );
2181 else if( p_uit->file.l_size > 1024 )
2182 asprintf( &psz_tmp, "(%ld kB)",
2183 p_uit->file.l_size / 1024 );
2185 asprintf( &psz_tmp, "(%ld B)", p_uit->file.l_size );
2189 psz_tmp = strdup( "" );
2191 msg_rc( "| %s %s", p_uit->file.psz_url, psz_tmp );
2196 update_iterator_Delete( p_uit );
2198 update_Delete( p_u );