1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2007 the VideoLAN team
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8 * Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include <errno.h> /* ENOMEM */
35 #include <vlc_interface.h>
39 #include <vlc_playlist.h>
40 #include <vlc_update.h>
46 #ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
49 #include <sys/types.h>
51 #include <vlc_network.h>
54 #include <vlc_charset.h>
56 #if defined(AF_UNIX) && !defined(AF_LOCAL)
57 # define AF_LOCAL AF_UNIX
60 #if defined(AF_LOCAL) && ! defined(WIN32)
64 #define MAX_LINE_LENGTH 256
65 #define STATUS_CHANGE "status change: "
67 /*****************************************************************************
69 *****************************************************************************/
70 static int Activate ( vlc_object_t * );
71 static void Deactivate ( vlc_object_t * );
72 static void Run ( intf_thread_t * );
74 static void Help ( intf_thread_t *, vlc_bool_t );
75 static void RegisterCallbacks( intf_thread_t * );
77 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
79 static input_item_t *parse_MRL( intf_thread_t *, char * );
81 static int Input ( vlc_object_t *, char const *,
82 vlc_value_t, vlc_value_t, void * );
83 static int Playlist ( vlc_object_t *, char const *,
84 vlc_value_t, vlc_value_t, void * );
85 static int Quit ( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
87 static int Intf ( vlc_object_t *, char const *,
88 vlc_value_t, vlc_value_t, void * );
89 static int Volume ( vlc_object_t *, char const *,
90 vlc_value_t, vlc_value_t, void * );
91 static int VolumeMove ( vlc_object_t *, char const *,
92 vlc_value_t, vlc_value_t, void * );
93 static int VideoConfig ( vlc_object_t *, char const *,
94 vlc_value_t, vlc_value_t, void * );
95 static int AudioConfig ( vlc_object_t *, char const *,
96 vlc_value_t, vlc_value_t, void * );
97 static int Menu ( vlc_object_t *, char const *,
98 vlc_value_t, vlc_value_t, void * );
99 static void checkUpdates( intf_thread_t *p_intf );
101 /* Status Callbacks */
102 static int TimeOffsetChanged( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t , void * );
104 static int VolumeChanged ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int StateChanged ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int RateChanged ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
113 int *pi_socket_listen;
118 vlc_mutex_t status_lock;
119 playlist_status_t i_last_state;
127 #ifdef HAVE_VARIADIC_MACROS
128 # define msg_rc( psz_format, args... ) \
129 __msg_rc( p_intf, psz_format, ## args )
132 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
135 va_start( args, psz_fmt );
137 if( p_intf->p_sys->i_socket == -1 )
139 utf8_vfprintf( stdout, psz_fmt, args );
144 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
145 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
150 /*****************************************************************************
152 *****************************************************************************/
153 #define POS_TEXT N_("Show stream position")
154 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
155 "stream from time to time." )
157 #define TTY_TEXT N_("Fake TTY")
158 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
160 #define UNIX_TEXT N_("UNIX socket command input")
161 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
164 #define HOST_TEXT N_("TCP command input")
165 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
166 "You can set the address and port the interface will bind to." )
169 #define QUIET_TEXT N_("Do not open a DOS command box interface")
170 #define QUIET_LONGTEXT N_( \
171 "By default the rc interface plugin will start a DOS command box. " \
172 "Enabling the quiet mode will not bring this command box but can also " \
173 "be pretty annoying when you want to stop VLC and no video window is " \
178 set_shortname( _("RC"));
179 set_category( CAT_INTERFACE );
180 set_subcategory( SUBCAT_INTERFACE_MAIN );
181 set_description( _("Remote control interface") );
182 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
185 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
187 #if defined (HAVE_ISATTY)
188 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
190 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
192 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
194 set_capability( "interface", 20 );
196 set_callbacks( Activate, Deactivate );
199 /*****************************************************************************
200 * Activate: initialize and create stuff
201 *****************************************************************************/
202 static int Activate( vlc_object_t *p_this )
204 intf_thread_t *p_intf = (intf_thread_t*)p_this;
205 char *psz_host, *psz_unix_path;
206 int *pi_socket = NULL;
209 #if defined(HAVE_ISATTY)
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" );
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: %m" );
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: %m",
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: %m");
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;
281 #endif /* AF_LOCAL */
285 if( ( pi_socket == NULL ) &&
286 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
290 vlc_UrlParse( &url, psz_host, 0 );
292 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
294 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
295 if( pi_socket == NULL )
297 msg_Warn( p_intf, "can't listen to %s port %i",
298 url.psz_host, url.i_port );
299 vlc_UrlClean( &url );
304 vlc_UrlClean( &url );
308 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
311 msg_Err( p_intf, "no memory" );
315 p_intf->p_sys->pi_socket_listen = pi_socket;
316 p_intf->p_sys->i_socket = -1;
317 p_intf->p_sys->psz_unix_path = psz_unix_path;
318 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
319 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
321 /* Non-buffered stdout */
322 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
324 p_intf->pf_run = Run;
327 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
328 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
333 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
337 /*****************************************************************************
338 * Deactivate: uninitialize and cleanup
339 *****************************************************************************/
340 static void Deactivate( vlc_object_t *p_this )
342 intf_thread_t *p_intf = (intf_thread_t*)p_this;
344 net_ListenClose( p_intf->p_sys->pi_socket_listen );
345 if( p_intf->p_sys->i_socket != -1 )
346 net_Close( p_intf->p_sys->i_socket );
347 if( p_intf->p_sys->psz_unix_path != NULL )
349 #if defined(AF_LOCAL) && !defined(WIN32)
350 unlink( p_intf->p_sys->psz_unix_path );
352 free( p_intf->p_sys->psz_unix_path );
354 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
355 free( p_intf->p_sys );
358 /*****************************************************************************
359 * RegisterCallbacks: Register callbacks to dynamic variables
360 *****************************************************************************/
361 static void RegisterCallbacks( intf_thread_t *p_intf )
363 /* Register commands that will be cleaned up upon object destruction */
364 #define ADD( name, type, target ) \
365 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
366 var_AddCallback( p_intf, name, target, NULL );
367 ADD( "quit", VOID, Quit )
368 ADD( "intf", STRING, Intf )
370 ADD( "add", STRING, Playlist )
371 ADD( "repeat", STRING, Playlist )
372 ADD( "loop", STRING, Playlist )
373 ADD( "random", STRING, Playlist )
374 ADD( "enqueue", STRING, Playlist )
375 ADD( "playlist", VOID, Playlist )
376 ADD( "sort", VOID, Playlist )
377 ADD( "play", VOID, Playlist )
378 ADD( "stop", VOID, Playlist )
379 ADD( "clear", VOID, Playlist )
380 ADD( "prev", VOID, Playlist )
381 ADD( "next", VOID, Playlist )
382 ADD( "goto", INTEGER, Playlist )
383 ADD( "status", INTEGER, Playlist )
385 /* OSD menu commands */
386 ADD( "menu", STRING, Menu )
389 ADD( "pause", VOID, Input )
390 ADD( "seek", INTEGER, Input )
391 ADD( "title", STRING, Input )
392 ADD( "title_n", VOID, Input )
393 ADD( "title_p", VOID, Input )
394 ADD( "chapter", STRING, Input )
395 ADD( "chapter_n", VOID, Input )
396 ADD( "chapter_p", VOID, Input )
398 ADD( "fastforward", VOID, Input )
399 ADD( "rewind", VOID, Input )
400 ADD( "faster", VOID, Input )
401 ADD( "slower", VOID, Input )
402 ADD( "normal", VOID, Input )
404 ADD( "atrack", STRING, Input )
405 ADD( "vtrack", STRING, Input )
406 ADD( "strack", STRING, Input )
409 ADD( "vratio", STRING, VideoConfig )
410 ADD( "vcrop", STRING, VideoConfig )
411 ADD( "vzoom", STRING, VideoConfig )
412 ADD( "snapshot", VOID, 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 )
504 input_item_GetURI( input_GetItem( p_input ) );
505 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
507 msg_rc( STATUS_CHANGE "( audio volume: %d )",
508 config_GetInt( p_intf, "volume" ));
510 var_AddCallback( p_input, "state", StateChanged, p_intf );
511 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
512 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
513 var_AddCallback( p_input, "rate", RateChanged, p_intf );
514 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
518 else if( p_input->b_dead )
520 var_DelCallback( p_input, "state", StateChanged, p_intf );
521 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
522 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
523 var_DelCallback( p_input, "rate", RateChanged, p_intf );
524 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
526 vlc_object_release( p_input );
531 vlc_mutex_lock( &p_playlist->object_lock );
532 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
533 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
534 vlc_mutex_unlock( &p_playlist->object_lock );
538 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
539 (p_playlist != NULL) )
541 vlc_mutex_lock( &p_playlist->object_lock );
542 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
543 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
545 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
546 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
549 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
550 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
552 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
553 msg_rc( STATUS_CHANGE "( play state: 1 )" );
556 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
557 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
559 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
560 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
562 vlc_mutex_unlock( &p_playlist->object_lock );
565 if( p_input && b_showpos )
567 i_newpos = 100 * var_GetFloat( p_input, "position" );
568 if( i_oldpos != i_newpos )
571 msg_rc( "pos: %d%%", i_newpos );
575 /* Is there something to do? */
576 if( !b_complete ) continue;
579 /* Skip heading spaces */
581 while( *psz_cmd == ' ' )
586 /* Split psz_cmd at the first space and make sure that
587 * psz_arg is valid */
588 psz_arg = strchr( psz_cmd, ' ' );
592 while( *psz_arg == ' ' )
602 /* module specfic commands: @<module name> <command> <args...> */
603 if( *psz_cmd == '@' && *psz_arg )
605 /* Parse miscellaneous commands */
606 char *psz_alias = psz_cmd + 1;
607 char *psz_mycmd = strdup( psz_arg );
608 char *psz_myarg = strchr( psz_mycmd, ' ' );
613 msg_rc( "Not enough parameters." );
620 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
631 /* If the user typed a registered local command, try it */
632 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
637 val.psz_string = psz_arg;
638 i_ret = var_Set( p_intf, psz_cmd, val );
639 msg_rc( "%s: returned %i (%s)",
640 psz_cmd, i_ret, vlc_error( i_ret ) );
642 /* Or maybe it's a global command */
643 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
648 val.psz_string = psz_arg;
649 /* FIXME: it's a global command, but we should pass the
650 * local object as an argument, not p_intf->p_libvlc. */
651 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
654 msg_rc( "%s: returned %i (%s)",
655 psz_cmd, i_ret, vlc_error( i_ret ) );
658 else if( !strcmp( psz_cmd, "logout" ) )
660 /* Close connection */
661 if( p_intf->p_sys->i_socket != -1 )
663 net_Close( p_intf->p_sys->i_socket );
665 p_intf->p_sys->i_socket = -1;
667 else if( !strcmp( psz_cmd, "info" ) )
672 vlc_mutex_lock( &input_GetItem(p_input)->lock );
673 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
675 info_category_t *p_category = input_GetItem(p_input)
678 msg_rc( "+----[ %s ]", p_category->psz_name );
680 for ( j = 0; j < p_category->i_infos; j++ )
682 info_t *p_info = p_category->pp_infos[j];
683 msg_rc( "| %s: %s", p_info->psz_name,
688 msg_rc( "+----[ end of stream info ]" );
689 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
693 msg_rc( "no input" );
696 else if( !strcmp( psz_cmd, "is_playing" ) )
707 else if( !strcmp( psz_cmd, "get_time" ) )
716 var_Get( p_input, "time", &time );
717 msg_rc( "%i", time.i_time / 1000000);
720 else if( !strcmp( psz_cmd, "get_length" ) )
729 var_Get( p_input, "length", &time );
730 msg_rc( "%i", time.i_time / 1000000);
733 else if( !strcmp( psz_cmd, "get_title" ) )
741 msg_rc( "%s", input_GetItem(p_input)->psz_name );
744 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
745 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
747 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
748 b_longhelp = VLC_TRUE;
749 else b_longhelp = VLC_FALSE;
751 Help( p_intf, b_longhelp );
753 else if( !strcmp( psz_cmd, "check-updates" ) )
755 checkUpdates( p_intf );
757 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
759 var_SetInteger( p_intf->p_libvlc, "key-pressed",
760 config_GetInt( p_intf, psz_arg ) );
762 else switch( psz_cmd[0] )
768 vout_thread_t *p_vout;
769 p_vout = vlc_object_find( p_input,
770 VLC_OBJECT_VOUT, FIND_CHILD );
775 vlc_bool_t b_update = VLC_FALSE;
776 var_Get( p_vout, "fullscreen", &val );
777 val.b_bool = !val.b_bool;
778 if( !strncmp( psz_arg, "on", 2 )
779 && ( val.b_bool == VLC_TRUE ) )
782 val.b_bool = VLC_TRUE;
784 else if( !strncmp( psz_arg, "off", 3 )
785 && ( val.b_bool == VLC_FALSE ) )
788 val.b_bool = VLC_FALSE;
790 else if( strncmp( psz_arg, "off", 3 )
791 && strncmp( psz_arg, "on", 2 ) )
793 if( b_update ) var_Set( p_vout, "fullscreen", val );
794 vlc_object_release( p_vout );
805 /* Ignore empty lines */
809 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
813 /* Command processed */
814 i_size = 0; p_buffer[0] = 0;
817 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
818 msg_rc( STATUS_CHANGE "( quit )" );
822 var_DelCallback( p_input, "state", StateChanged, p_intf );
823 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
824 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
825 var_DelCallback( p_input, "rate", RateChanged, p_intf );
826 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
827 vlc_object_release( p_input );
833 vlc_object_release( p_playlist );
837 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
840 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
842 msg_rc(_("+----[ Remote control commands ]"));
844 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
845 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
846 msg_rc(_("| playlist . . . . . show items currently in playlist"));
847 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
848 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
849 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
850 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
851 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
852 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
853 msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
854 msg_rc(_("| random [on|off] . . . . . . . toggle random jumping"));
855 msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
856 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
857 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
858 msg_rc(_("| title_n . . . . . . . . next title in current item"));
859 msg_rc(_("| title_p . . . . . . previous title in current item"));
860 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
861 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
862 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
864 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
865 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
866 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
867 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
868 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
869 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
870 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
871 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
872 msg_rc(_("| info . . . . . information about the current stream"));
873 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
874 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
875 msg_rc(_("| get_title . . . . . the title of the current stream"));
876 msg_rc(_("| get_length . . . . the length of the current stream"));
878 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
879 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
880 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
881 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
882 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
883 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
884 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
885 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
886 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
887 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
888 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
889 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
890 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
891 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
896 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
897 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
898 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
899 msg_rc(_("| @name marq-position #. . . .relative position control"));
900 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
901 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
902 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
903 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
905 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
906 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
907 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
908 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
909 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
911 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
912 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
913 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
914 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
915 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
916 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
917 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
918 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
919 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
920 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
921 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
922 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
923 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
924 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
926 msg_rc(_("| check-updates [newer] [equal] [older]\n"
927 "| [undef] [info] [source] [binary] [plugin]"));
930 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
931 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
932 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
933 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
935 msg_rc(_("+----[ end of help ]"));
938 /********************************************************************
939 * Status callback routines
940 ********************************************************************/
941 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
942 vlc_value_t oldval, vlc_value_t newval, void *p_data )
944 intf_thread_t *p_intf = (intf_thread_t*)p_data;
945 input_thread_t *p_input = NULL;
947 vlc_mutex_lock( &p_intf->p_sys->status_lock );
948 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
951 msg_rc( STATUS_CHANGE "( time-offset: %d )",
952 var_GetInteger( p_input, "time-offset" ) );
953 vlc_object_release( p_input );
955 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
959 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
960 vlc_value_t oldval, vlc_value_t newval, void *p_data )
962 intf_thread_t *p_intf = (intf_thread_t*)p_data;
964 vlc_mutex_lock( &p_intf->p_sys->status_lock );
965 msg_rc( STATUS_CHANGE "( audio volume: %d )",
966 config_GetInt( p_this, "volume") );
967 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
971 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
972 vlc_value_t oldval, vlc_value_t newval, void *p_data )
974 intf_thread_t *p_intf = (intf_thread_t*)p_data;
975 playlist_t *p_playlist = NULL;
976 input_thread_t *p_input = NULL;
978 vlc_mutex_lock( &p_intf->p_sys->status_lock );
979 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
982 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
986 switch( p_playlist->status.i_status )
988 case PLAYLIST_STOPPED:
989 strncpy( &cmd[0], "stop", 4);
992 case PLAYLIST_RUNNING:
993 strncpy( &cmd[0], "play", 4);
996 case PLAYLIST_PAUSED:
997 strncpy( &cmd[0], "pause", 5);
1000 } /* var_GetInteger( p_input, "state" ) */
1001 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1002 vlc_object_release( p_playlist );
1004 vlc_object_release( p_input );
1006 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1010 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1011 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1013 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1014 input_thread_t *p_input = NULL;
1016 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1017 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1020 msg_rc( STATUS_CHANGE "( new rate: %d )",
1021 var_GetInteger( p_input, "rate" ) );
1022 vlc_object_release( p_input );
1024 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1028 /********************************************************************
1030 ********************************************************************/
1031 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1032 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1034 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1035 input_thread_t *p_input;
1038 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1039 if( !p_input ) return VLC_ENOOBJ;
1041 var_Get( p_input, "state", &val );
1042 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1043 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1045 msg_rc( _("Press menu select or pause to continue.") );
1046 vlc_object_release( p_input );
1047 return VLC_EGENERIC;
1050 /* Parse commands that only require an input */
1051 if( !strcmp( psz_cmd, "pause" ) )
1053 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1054 var_Set( p_intf->p_libvlc, "key-pressed", val );
1055 vlc_object_release( p_input );
1058 else if( !strcmp( psz_cmd, "seek" ) )
1060 if( strlen( newval.psz_string ) > 0 &&
1061 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1063 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1064 var_Set( p_input, "position", val );
1068 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1069 var_Set( p_input, "time", val );
1071 vlc_object_release( p_input );
1074 else if ( !strcmp( psz_cmd, "fastforward" ) )
1076 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1077 var_Set( p_intf->p_libvlc, "key-pressed", val );
1078 vlc_object_release( p_input );
1081 else if ( !strcmp( psz_cmd, "rewind" ) )
1083 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1084 var_Set( p_intf->p_libvlc, "key-pressed", val );
1085 vlc_object_release( p_input );
1088 else if ( !strcmp( psz_cmd, "faster" ) )
1090 var_Set( p_input, "rate-faster", val );
1091 vlc_object_release( p_input );
1094 else if ( !strcmp( psz_cmd, "slower" ) )
1096 var_Set( p_input, "rate-slower", val );
1097 vlc_object_release( p_input );
1100 else if ( !strcmp( psz_cmd, "normal" ) )
1102 val.i_int = INPUT_RATE_DEFAULT;
1103 var_Set( p_input, "rate", val );
1104 vlc_object_release( p_input );
1107 else if( !strcmp( psz_cmd, "chapter" ) ||
1108 !strcmp( psz_cmd, "chapter_n" ) ||
1109 !strcmp( psz_cmd, "chapter_p" ) )
1111 if( !strcmp( psz_cmd, "chapter" ) )
1113 if ( *newval.psz_string )
1116 val.i_int = atoi( newval.psz_string );
1117 var_Set( p_input, "chapter", val );
1121 vlc_value_t val_list;
1124 var_Get( p_input, "chapter", &val );
1125 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1127 msg_rc( "Currently playing chapter %d/%d.",
1128 val.i_int, val_list.p_list->i_count );
1129 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1133 else if( !strcmp( psz_cmd, "chapter_n" ) )
1135 val.b_bool = VLC_TRUE;
1136 var_Set( p_input, "next-chapter", val );
1138 else if( !strcmp( psz_cmd, "chapter_p" ) )
1140 val.b_bool = VLC_TRUE;
1141 var_Set( p_input, "prev-chapter", val );
1143 vlc_object_release( p_input );
1146 else if( !strcmp( psz_cmd, "title" ) ||
1147 !strcmp( psz_cmd, "title_n" ) ||
1148 !strcmp( psz_cmd, "title_p" ) )
1150 if( !strcmp( psz_cmd, "title" ) )
1152 if ( *newval.psz_string )
1155 val.i_int = atoi( newval.psz_string );
1156 var_Set( p_input, "title", val );
1160 vlc_value_t val_list;
1163 var_Get( p_input, "title", &val );
1164 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1166 msg_rc( "Currently playing title %d/%d.",
1167 val.i_int, val_list.p_list->i_count );
1168 var_Change( p_this, "title", VLC_VAR_FREELIST,
1172 else if( !strcmp( psz_cmd, "title_n" ) )
1174 val.b_bool = VLC_TRUE;
1175 var_Set( p_input, "next-title", val );
1177 else if( !strcmp( psz_cmd, "title_p" ) )
1179 val.b_bool = VLC_TRUE;
1180 var_Set( p_input, "prev-title", val );
1183 vlc_object_release( p_input );
1186 else if( !strcmp( psz_cmd, "atrack" )
1187 || !strcmp( psz_cmd, "vtrack" )
1188 || !strcmp( psz_cmd, "strack" ) )
1190 const char *psz_variable;
1191 vlc_value_t val_name;
1194 if( !strcmp( psz_cmd, "atrack" ) )
1196 psz_variable = "audio-es";
1198 else if( !strcmp( psz_cmd, "vtrack" ) )
1200 psz_variable = "video-es";
1204 psz_variable = "spu-es";
1207 /* Get the descriptive name of the variable */
1208 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1210 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1212 if( newval.psz_string && *newval.psz_string )
1216 val.i_int = atoi( newval.psz_string );
1218 i_error = var_Set( p_input, psz_variable, val );
1223 vlc_value_t val, text;
1226 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1228 vlc_object_release( p_input );
1229 return VLC_EGENERIC;
1231 i_value = val.i_int;
1233 if ( var_Change( p_input, psz_variable,
1234 VLC_VAR_GETLIST, &val, &text ) < 0 )
1236 vlc_object_release( p_input );
1237 return VLC_EGENERIC;
1240 msg_rc( "+----[ %s ]", val_name.psz_string );
1241 for ( i = 0; i < val.p_list->i_count; i++ )
1243 if ( i_value == val.p_list->p_values[i].i_int )
1244 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1245 text.p_list->p_values[i].psz_string );
1247 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1248 text.p_list->p_values[i].psz_string );
1250 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1252 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1254 if( val_name.psz_string ) free( val_name.psz_string );
1256 i_error = VLC_SUCCESS;
1258 vlc_object_release( p_input );
1262 /* Never reached. */
1263 vlc_object_release( p_input );
1264 return VLC_EGENERIC;
1267 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1268 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1272 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1273 playlist_t *p_playlist = pl_Yield( p_this );
1276 if( p_playlist->p_input )
1278 var_Get( p_playlist->p_input, "state", &val );
1279 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1281 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1282 vlc_object_release( p_playlist );
1284 return VLC_EGENERIC;
1289 /* Parse commands that require a playlist */
1290 if( !strcmp( psz_cmd, "prev" ) )
1292 playlist_Prev( p_playlist );
1294 else if( !strcmp( psz_cmd, "next" ) )
1296 playlist_Next( p_playlist );
1298 else if( !strcmp( psz_cmd, "play" ) )
1300 msg_Warn( p_playlist, "play" );
1301 playlist_Play( p_playlist );
1303 else if( !strcmp( psz_cmd, "repeat" ) )
1305 vlc_bool_t b_update = VLC_TRUE;
1307 var_Get( p_playlist, "repeat", &val );
1309 if( strlen( newval.psz_string ) > 0 )
1311 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1312 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1314 b_update = VLC_FALSE;
1320 val.b_bool = !val.b_bool;
1321 var_Set( p_playlist, "repeat", val );
1323 msg_rc( "Setting repeat to %d", val.b_bool );
1325 else if( !strcmp( psz_cmd, "loop" ) )
1327 vlc_bool_t b_update = VLC_TRUE;
1329 var_Get( p_playlist, "loop", &val );
1331 if( strlen( newval.psz_string ) > 0 )
1333 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1334 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1336 b_update = VLC_FALSE;
1342 val.b_bool = !val.b_bool;
1343 var_Set( p_playlist, "loop", val );
1345 msg_rc( "Setting loop to %d", val.b_bool );
1347 else if( !strcmp( psz_cmd, "random" ) )
1349 vlc_bool_t b_update = VLC_TRUE;
1351 var_Get( p_playlist, "random", &val );
1353 if( strlen( newval.psz_string ) > 0 )
1355 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1356 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1358 b_update = VLC_FALSE;
1364 val.b_bool = !val.b_bool;
1365 var_Set( p_playlist, "random", val );
1367 msg_rc( "Setting random to %d", val.b_bool );
1369 else if (!strcmp( psz_cmd, "goto" ) )
1371 int i_pos = atoi( newval.psz_string );
1372 /* The playlist stores 2 times the same item: onelevel & category */
1373 int i_size = p_playlist->items.i_size / 2;
1376 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1377 else if( i_pos <= i_size )
1379 playlist_item_t *p_item, *p_parent;
1380 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1381 while( p_parent->p_parent )
1382 p_parent = p_parent->p_parent;
1383 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE,
1387 msg_rc( _("Playlist has only %d elements"), i_size );
1389 else if( !strcmp( psz_cmd, "stop" ) )
1391 playlist_Stop( p_playlist );
1393 else if( !strcmp( psz_cmd, "clear" ) )
1395 playlist_Stop( p_playlist );
1396 playlist_Clear( p_playlist, VLC_FALSE );
1398 else if( !strcmp( psz_cmd, "add" ) &&
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 add %s to playlist.", newval.psz_string );
1406 playlist_AddInput( p_playlist, p_item,
1407 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1411 else if( !strcmp( psz_cmd, "enqueue" ) &&
1412 newval.psz_string && *newval.psz_string )
1414 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1418 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1419 playlist_AddInput( p_playlist, p_item,
1420 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1424 else if( !strcmp( psz_cmd, "playlist" ) )
1426 msg_Dbg( p_playlist, "Dumping category" );
1427 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1428 msg_Dbg( p_playlist, "Dumping Onelevel" );
1429 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1431 else if( !strcmp( psz_cmd, "sort" ))
1433 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1434 SORT_ARTIST, ORDER_NORMAL );
1436 else if( !strcmp( psz_cmd, "status" ) )
1438 if( p_playlist->p_input )
1440 /* Replay the current state of the system. */
1442 input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1443 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1445 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1446 config_GetInt( p_intf, "volume" ));
1448 vlc_mutex_lock( &p_playlist->object_lock );
1449 switch( p_playlist->status.i_status )
1451 case PLAYLIST_STOPPED:
1452 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1454 case PLAYLIST_RUNNING:
1455 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1457 case PLAYLIST_PAUSED:
1458 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1461 msg_rc( STATUS_CHANGE "( state unknown )" );
1464 vlc_mutex_unlock( &p_playlist->object_lock );
1473 msg_rc( "unknown command!" );
1476 vlc_object_release( p_playlist );
1480 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1481 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1483 playlist_t *p_playlist;
1485 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1488 playlist_Stop( p_playlist );
1489 vlc_object_release( p_playlist );
1491 vlc_object_kill( p_this->p_libvlc );
1495 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1496 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1498 intf_thread_t *p_newintf = NULL;
1500 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1503 if( intf_RunThread( p_newintf ) )
1505 vlc_object_detach( p_newintf );
1506 intf_Destroy( p_newintf );
1513 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1514 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1516 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1517 input_thread_t *p_input = NULL;
1518 int i_error = VLC_EGENERIC;
1520 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1528 var_Get( p_input, "state", &val );
1529 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1531 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1532 vlc_object_release( p_input );
1533 return VLC_EGENERIC;
1535 vlc_object_release( p_input );
1538 if ( *newval.psz_string )
1541 audio_volume_t i_volume = atoi( newval.psz_string );
1542 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1544 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1546 i_error = VLC_EBADVAR;
1550 if( i_volume == AOUT_VOLUME_MIN )
1554 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1555 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1557 i_error = aout_VolumeSet( p_this, i_volume );
1558 osd_Volume( p_this );
1559 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1565 audio_volume_t i_volume;
1566 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1568 i_error = VLC_EGENERIC;
1572 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1573 i_error = VLC_SUCCESS;
1580 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1581 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1583 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1584 audio_volume_t i_volume;
1585 input_thread_t *p_input = NULL;
1586 int i_nb_steps = atoi(newval.psz_string);
1587 int i_error = VLC_SUCCESS;
1588 int i_volume_step = 0;
1590 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1598 var_Get( p_input, "state", &val );
1599 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1601 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1602 vlc_object_release( p_input );
1603 return VLC_EGENERIC;
1605 vlc_object_release( p_input );
1608 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1609 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1614 if ( !strcmp(psz_cmd, "volup") )
1616 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1617 i_error = VLC_EGENERIC;
1621 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1622 i_error = VLC_EGENERIC;
1624 osd_Volume( p_this );
1626 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1631 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1632 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1634 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1635 input_thread_t *p_input = NULL;
1636 vout_thread_t * p_vout;
1637 const char * psz_variable;
1640 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1644 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1645 vlc_object_release( p_input );
1649 if( !strcmp( psz_cmd, "vcrop" ) )
1651 psz_variable = "crop";
1653 else if( !strcmp( psz_cmd, "vratio" ) )
1655 psz_variable = "aspect-ratio";
1657 else if( !strcmp( psz_cmd, "vzoom" ) )
1659 psz_variable = "zoom";
1661 else if( !strcmp( psz_cmd, "snapshot" ) )
1663 psz_variable = "video-snapshot";
1666 if( newval.psz_string && *newval.psz_string )
1669 if( !strcmp( psz_variable, "zoom" ) )
1672 val.f_float = atof( newval.psz_string );
1673 i_error = var_Set( p_vout, psz_variable, val );
1677 i_error = var_Set( p_vout, psz_variable, newval );
1680 else if( !strcmp( psz_cmd, "snapshot" ) )
1682 i_error = var_Set( p_vout, psz_variable, newval );
1687 vlc_value_t val_name;
1688 vlc_value_t val, text;
1691 char *psz_value = NULL;
1693 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1695 vlc_object_release( p_vout );
1696 return VLC_EGENERIC;
1698 if( !strcmp( psz_variable, "zoom" ) )
1700 f_value = val.f_float;
1704 psz_value = strdup( val.psz_string );
1707 if ( var_Change( p_vout, psz_variable,
1708 VLC_VAR_GETLIST, &val, &text ) < 0 )
1710 vlc_object_release( p_vout );
1711 return VLC_EGENERIC;
1714 /* Get the descriptive name of the variable */
1715 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1717 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1719 msg_rc( "+----[ %s ]", val_name.psz_string );
1720 if( !strcmp( psz_variable, "zoom" ) )
1722 for ( i = 0; i < val.p_list->i_count; i++ )
1724 if ( f_value == val.p_list->p_values[i].f_float )
1725 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1726 text.p_list->p_values[i].psz_string );
1728 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1729 text.p_list->p_values[i].psz_string );
1734 for ( i = 0; i < val.p_list->i_count; i++ )
1736 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1737 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1738 text.p_list->p_values[i].psz_string );
1740 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1741 text.p_list->p_values[i].psz_string );
1745 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1747 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1749 if( val_name.psz_string ) free( val_name.psz_string );
1751 i_error = VLC_SUCCESS;
1753 vlc_object_release( p_vout );
1757 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1758 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1760 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1761 input_thread_t *p_input = NULL;
1762 aout_instance_t * p_aout;
1763 const char * psz_variable;
1764 vlc_value_t val_name;
1767 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1775 var_Get( p_input, "state", &val );
1776 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1777 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1778 vlc_object_release( p_input );
1779 return VLC_EGENERIC;
1781 vlc_object_release( p_input );
1784 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1785 if ( p_aout == NULL ) return VLC_ENOOBJ;
1787 if ( !strcmp( psz_cmd, "adev" ) )
1789 psz_variable = "audio-device";
1793 psz_variable = "audio-channels";
1796 /* Get the descriptive name of the variable */
1797 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1799 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1801 if ( !*newval.psz_string )
1803 /* Retrieve all registered ***. */
1804 vlc_value_t val, text;
1807 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1809 vlc_object_release( (vlc_object_t *)p_aout );
1810 return VLC_EGENERIC;
1812 i_value = val.i_int;
1814 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1815 VLC_VAR_GETLIST, &val, &text ) < 0 )
1817 vlc_object_release( (vlc_object_t *)p_aout );
1818 return VLC_EGENERIC;
1821 msg_rc( "+----[ %s ]", val_name.psz_string );
1822 for ( i = 0; i < val.p_list->i_count; i++ )
1824 if ( i_value == val.p_list->p_values[i].i_int )
1825 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1826 text.p_list->p_values[i].psz_string );
1828 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1829 text.p_list->p_values[i].psz_string );
1831 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1833 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1835 if( val_name.psz_string ) free( val_name.psz_string );
1836 i_error = VLC_SUCCESS;
1841 val.i_int = atoi( newval.psz_string );
1843 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1845 vlc_object_release( (vlc_object_t *)p_aout );
1850 /* OSD menu commands */
1851 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1852 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1854 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1855 playlist_t *p_playlist = NULL;
1857 int i_error = VLC_EGENERIC;
1859 if ( !*newval.psz_string )
1861 msg_rc( _("Please provide one of the following parameters:") );
1862 msg_rc( "[on|off|up|down|left|right|select]" );
1866 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1870 if( p_playlist->p_input )
1872 var_Get( p_playlist->p_input, "state", &val );
1873 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1874 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1876 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1877 vlc_object_release( p_playlist );
1878 return VLC_EGENERIC;
1881 vlc_object_release( p_playlist );
1883 val.psz_string = strdup( newval.psz_string );
1884 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1885 osd_MenuShow( p_this );
1886 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1887 osd_MenuHide( p_this );
1888 else if( !strcmp( val.psz_string, "up" ) )
1889 osd_MenuUp( p_this );
1890 else if( !strcmp( val.psz_string, "down" ) )
1891 osd_MenuDown( p_this );
1892 else if( !strcmp( val.psz_string, "left" ) )
1893 osd_MenuPrev( p_this );
1894 else if( !strcmp( val.psz_string, "right" ) )
1895 osd_MenuNext( p_this );
1896 else if( !strcmp( val.psz_string, "select" ) )
1897 osd_MenuActivate( p_this );
1900 msg_rc( _("Please provide one of the following parameters:") );
1901 msg_rc( "[on|off|up|down|left|right|select]" );
1902 if( val.psz_string ) free( val.psz_string );
1906 i_error = VLC_SUCCESS;
1907 if( val.psz_string ) free( val.psz_string );
1912 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1914 INPUT_RECORD input_record;
1917 /* On Win32, select() only works on socket descriptors */
1918 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1919 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1921 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1922 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1925 if( input_record.EventType != KEY_EVENT ||
1926 !input_record.Event.KeyEvent.bKeyDown ||
1927 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1928 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1929 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1930 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1932 /* nothing interesting */
1936 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1938 /* Echo out the command */
1939 putc( p_buffer[ *pi_size ], stdout );
1941 /* Handle special keys */
1942 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1944 putc( '\n', stdout );
1947 switch( p_buffer[ *pi_size ] )
1953 putc( ' ', stdout );
1954 putc( '\b', stdout );
1965 if( *pi_size == MAX_LINE_LENGTH ||
1966 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1968 p_buffer[ *pi_size ] = 0;
1977 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1982 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1983 return ReadWin32( p_intf, p_buffer, pi_size );
1984 else if( p_intf->p_sys->i_socket == -1 )
1986 msleep( INTF_IDLE_SLEEP );
1991 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1992 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
1993 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1994 (uint8_t *)p_buffer + *pi_size, 1, VLC_FALSE ) ) > 0 )
1996 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2002 /* Connection closed */
2005 if( p_intf->p_sys->i_socket != -1 )
2007 net_Close( p_intf->p_sys->i_socket );
2008 p_intf->p_sys->i_socket = -1;
2011 /* Standard input closed: exit */
2012 vlc_object_kill( p_intf );
2014 p_buffer[ *pi_size ] = 0;
2018 if( *pi_size == MAX_LINE_LENGTH ||
2019 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2021 p_buffer[ *pi_size ] = 0;
2028 /*****************************************************************************
2029 * parse_MRL: build a input item from a full mrl
2030 *****************************************************************************
2031 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2032 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2033 * space is a new option. Should be good enough for our purpose.
2034 *****************************************************************************/
2035 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2037 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2038 #define SKIPTRAILINGSPACE( p, d ) \
2039 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2041 input_item_t *p_item = NULL;
2042 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2043 char **ppsz_options = NULL;
2044 int i, i_options = 0;
2046 if( !psz_mrl ) return 0;
2048 psz_mrl = psz_orig = strdup( psz_mrl );
2051 SKIPSPACE( psz_mrl );
2054 for( ; *psz_mrl; psz_mrl++ )
2056 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2058 /* We have a complete item */
2061 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2062 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2064 /* We have a complete item */
2069 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2070 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2072 /* Remove '"' and '\'' if necessary */
2073 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2074 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2075 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2076 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2078 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2079 else if( *psz_item )
2082 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2083 ppsz_options[i_options - 1] = &psz_item[1];
2086 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2089 /* Now create a playlist item */
2092 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2093 for( i = 0; i < i_options; i++ )
2095 input_ItemAddOption( p_item, ppsz_options[i] );
2099 if( i_options ) free( ppsz_options );
2105 /*****************************************************************************
2106 * checkUpdates : check for updates
2107 ****************************************************************************/
2108 static void checkUpdates( intf_thread_t *p_intf )
2110 update_t *p_u = update_New( p_intf );
2111 if( p_u == NULL ) return;
2113 update_Check( p_u );
2114 msg_rc( "\nChecking for updates" );
2116 if( update_CompareReleaseToCurrent( p_u ) == UpdateReleaseStatusNewer )
2117 msg_rc( "\n+----[ VLC %i.%i.%i%s ] ", p_u->release.i_major,
2118 p_u->release.i_minor,
2119 p_u->release.i_revision,
2120 p_u->release.psz_extra );
2122 msg_rc( "\n+----Last version" );
2123 update_Delete( p_u );