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 *****************************************************************************/
34 #include <errno.h> /* ENOMEM */
38 #include <vlc_interface.h>
42 #include <vlc_playlist.h>
48 #ifdef HAVE_SYS_TIME_H
49 # include <sys/time.h>
51 #include <sys/types.h>
53 #include <vlc_network.h>
56 #include <vlc_charset.h>
58 #if defined(AF_UNIX) && !defined(AF_LOCAL)
59 # define AF_LOCAL AF_UNIX
62 #if defined(AF_LOCAL) && ! defined(WIN32)
66 #define MAX_LINE_LENGTH 256
67 #define STATUS_CHANGE "status change: "
69 /*****************************************************************************
71 *****************************************************************************/
72 static int Activate ( vlc_object_t * );
73 static void Deactivate ( vlc_object_t * );
74 static void Run ( intf_thread_t * );
76 static void Help ( intf_thread_t *, vlc_bool_t );
77 static void RegisterCallbacks( intf_thread_t * );
79 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
81 static input_item_t *parse_MRL( intf_thread_t *, char * );
83 static int Input ( vlc_object_t *, char const *,
84 vlc_value_t, vlc_value_t, void * );
85 static int Playlist ( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
87 static int Quit ( vlc_object_t *, char const *,
88 vlc_value_t, vlc_value_t, void * );
89 static int Intf ( vlc_object_t *, char const *,
90 vlc_value_t, vlc_value_t, void * );
91 static int Volume ( vlc_object_t *, char const *,
92 vlc_value_t, vlc_value_t, void * );
93 static int VolumeMove ( vlc_object_t *, char const *,
94 vlc_value_t, vlc_value_t, void * );
95 static int VideoConfig ( vlc_object_t *, char const *,
96 vlc_value_t, vlc_value_t, void * );
97 static int AudioConfig ( vlc_object_t *, char const *,
98 vlc_value_t, vlc_value_t, void * );
99 static int Menu ( vlc_object_t *, char const *,
100 vlc_value_t, vlc_value_t, void * );
101 static int Statistics ( vlc_object_t *, char const *,
102 vlc_value_t, vlc_value_t, void * );
104 static int updateStatistics( intf_thread_t *, input_item_t *);
106 /* Status Callbacks */
107 static int TimeOffsetChanged( vlc_object_t *, char const *,
108 vlc_value_t, vlc_value_t , void * );
109 static int VolumeChanged ( vlc_object_t *, char const *,
110 vlc_value_t, vlc_value_t, void * );
111 static int StateChanged ( vlc_object_t *, char const *,
112 vlc_value_t, vlc_value_t, void * );
113 static int RateChanged ( vlc_object_t *, char const *,
114 vlc_value_t, vlc_value_t, void * );
118 int *pi_socket_listen;
123 vlc_mutex_t status_lock;
124 playlist_status_t i_last_state;
132 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
134 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
137 va_start( args, psz_fmt );
139 if( p_intf->p_sys->i_socket == -1 )
141 utf8_vfprintf( stdout, psz_fmt, args );
146 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
147 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
152 /*****************************************************************************
154 *****************************************************************************/
155 #define POS_TEXT N_("Show stream position")
156 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
157 "stream from time to time." )
159 #define TTY_TEXT N_("Fake TTY")
160 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
162 #define UNIX_TEXT N_("UNIX socket command input")
163 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
166 #define HOST_TEXT N_("TCP command input")
167 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
168 "You can set the address and port the interface will bind to." )
171 #define QUIET_TEXT N_("Do not open a DOS command box interface")
172 #define QUIET_LONGTEXT N_( \
173 "By default the rc interface plugin will start a DOS command box. " \
174 "Enabling the quiet mode will not bring this command box but can also " \
175 "be pretty annoying when you want to stop VLC and no video window is " \
180 set_shortname( _("RC"));
181 set_category( CAT_INTERFACE );
182 set_subcategory( SUBCAT_INTERFACE_MAIN );
183 set_description( _("Remote control interface") );
184 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
187 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
189 #if defined (HAVE_ISATTY)
190 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
192 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
194 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
196 set_capability( "interface", 20 );
198 set_callbacks( Activate, Deactivate );
201 /*****************************************************************************
202 * Activate: initialize and create stuff
203 *****************************************************************************/
204 static int Activate( vlc_object_t *p_this )
206 intf_thread_t *p_intf = (intf_thread_t*)p_this;
207 char *psz_host, *psz_unix_path;
208 int *pi_socket = NULL;
211 #if defined(HAVE_ISATTY)
212 /* Check that stdin is a TTY */
213 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
215 msg_Warn( p_intf, "fd 0 is not a TTY" );
220 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
226 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
227 free( psz_unix_path );
230 struct sockaddr_un addr;
232 memset( &addr, 0, sizeof(struct sockaddr_un) );
234 msg_Dbg( p_intf, "trying UNIX socket" );
236 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
238 msg_Warn( p_intf, "can't open socket: %m" );
239 free( psz_unix_path );
243 addr.sun_family = AF_LOCAL;
244 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
245 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
247 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
248 && (errno == EADDRINUSE)
249 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
250 && (errno == ECONNREFUSED))
252 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
253 unlink (psz_unix_path);
255 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
257 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
259 free (psz_unix_path);
260 net_Close (i_socket);
265 if( listen( i_socket, 1 ) )
267 msg_Warn( p_intf, "can't listen on socket: %m");
268 free( psz_unix_path );
269 net_Close( i_socket );
273 /* FIXME: we need a core function to merge listening sockets sets */
274 pi_socket = calloc( 2, sizeof( int ) );
275 if( pi_socket == NULL )
277 free( psz_unix_path );
278 net_Close( i_socket );
281 pi_socket[0] = i_socket;
283 #endif /* AF_LOCAL */
287 if( ( pi_socket == NULL ) &&
288 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
292 vlc_UrlParse( &url, psz_host, 0 );
294 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
296 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
297 if( pi_socket == NULL )
299 msg_Warn( p_intf, "can't listen to %s port %i",
300 url.psz_host, url.i_port );
301 vlc_UrlClean( &url );
306 vlc_UrlClean( &url );
310 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
313 msg_Err( p_intf, "no memory" );
317 p_intf->p_sys->pi_socket_listen = pi_socket;
318 p_intf->p_sys->i_socket = -1;
319 p_intf->p_sys->psz_unix_path = psz_unix_path;
320 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
321 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
323 /* Non-buffered stdout */
324 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
326 p_intf->pf_run = Run;
329 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
330 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
335 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
339 /*****************************************************************************
340 * Deactivate: uninitialize and cleanup
341 *****************************************************************************/
342 static void Deactivate( vlc_object_t *p_this )
344 intf_thread_t *p_intf = (intf_thread_t*)p_this;
346 net_ListenClose( p_intf->p_sys->pi_socket_listen );
347 if( p_intf->p_sys->i_socket != -1 )
348 net_Close( p_intf->p_sys->i_socket );
349 if( p_intf->p_sys->psz_unix_path != NULL )
351 #if defined(AF_LOCAL) && !defined(WIN32)
352 unlink( p_intf->p_sys->psz_unix_path );
354 free( p_intf->p_sys->psz_unix_path );
356 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
357 free( p_intf->p_sys );
360 /*****************************************************************************
361 * RegisterCallbacks: Register callbacks to dynamic variables
362 *****************************************************************************/
363 static void RegisterCallbacks( intf_thread_t *p_intf )
365 /* Register commands that will be cleaned up upon object destruction */
366 #define ADD( name, type, target ) \
367 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
368 var_AddCallback( p_intf, name, target, NULL );
369 ADD( "quit", VOID, Quit )
370 ADD( "intf", STRING, Intf )
372 ADD( "add", STRING, Playlist )
373 ADD( "repeat", STRING, Playlist )
374 ADD( "loop", STRING, Playlist )
375 ADD( "random", STRING, Playlist )
376 ADD( "enqueue", STRING, Playlist )
377 ADD( "playlist", VOID, Playlist )
378 ADD( "sort", VOID, Playlist )
379 ADD( "play", VOID, Playlist )
380 ADD( "stop", VOID, Playlist )
381 ADD( "clear", VOID, Playlist )
382 ADD( "prev", VOID, Playlist )
383 ADD( "next", VOID, Playlist )
384 ADD( "goto", INTEGER, Playlist )
385 ADD( "status", INTEGER, Playlist )
387 /* OSD menu commands */
388 ADD( "menu", STRING, Menu )
391 ADD( "pause", VOID, Input )
392 ADD( "seek", INTEGER, Input )
393 ADD( "title", STRING, Input )
394 ADD( "title_n", VOID, Input )
395 ADD( "title_p", VOID, Input )
396 ADD( "chapter", STRING, Input )
397 ADD( "chapter_n", VOID, Input )
398 ADD( "chapter_p", VOID, Input )
400 ADD( "fastforward", VOID, Input )
401 ADD( "rewind", VOID, Input )
402 ADD( "faster", VOID, Input )
403 ADD( "slower", VOID, Input )
404 ADD( "normal", VOID, Input )
406 ADD( "atrack", STRING, Input )
407 ADD( "vtrack", STRING, Input )
408 ADD( "strack", STRING, Input )
411 ADD( "vratio", STRING, VideoConfig )
412 ADD( "vcrop", STRING, VideoConfig )
413 ADD( "vzoom", STRING, VideoConfig )
414 ADD( "snapshot", VOID, VideoConfig )
417 ADD( "volume", STRING, Volume )
418 ADD( "volup", STRING, VolumeMove )
419 ADD( "voldown", STRING, VolumeMove )
420 ADD( "adev", STRING, AudioConfig )
421 ADD( "achan", STRING, AudioConfig )
423 /* misc menu commands */
424 ADD( "stats", BOOL, Statistics )
429 /*****************************************************************************
431 *****************************************************************************
432 * This part of the interface is in a separate thread so that we can call
433 * exec() from within it without annoying the rest of the program.
434 *****************************************************************************/
435 static void Run( intf_thread_t *p_intf )
437 input_thread_t * p_input;
438 playlist_t * p_playlist;
440 char p_buffer[ MAX_LINE_LENGTH + 1 ];
441 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
442 vlc_bool_t b_longhelp = VLC_FALSE;
452 /* Register commands that will be cleaned up upon object destruction */
453 RegisterCallbacks( p_intf );
455 /* status callbacks */
456 /* Listen to audio volume updates */
457 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
460 /* Get the file descriptor of the console input */
461 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
462 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
464 msg_Err( p_intf, "couldn't find user input handle" );
465 vlc_object_kill( p_intf );
469 while( !intf_ShouldDie( p_intf ) )
471 char *psz_cmd, *psz_arg;
472 vlc_bool_t b_complete;
474 if( p_intf->p_sys->pi_socket_listen != NULL &&
475 p_intf->p_sys->i_socket == -1 )
477 p_intf->p_sys->i_socket =
478 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
480 if( p_intf->p_sys->i_socket == -1 ) continue;
483 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
485 /* Manage the input part */
486 if( p_input == NULL )
490 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
495 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
499 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
503 /* New input has been registered */
506 if( !p_input->b_dead || !p_input->b_die )
509 input_item_GetURI( input_GetItem( p_input ) );
510 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
512 msg_rc( STATUS_CHANGE "( audio volume: %d )",
513 config_GetInt( p_intf, "volume" ));
515 var_AddCallback( p_input, "state", StateChanged, p_intf );
516 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
517 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
518 var_AddCallback( p_input, "rate", RateChanged, p_intf );
519 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
523 else if( p_input->b_dead )
525 var_DelCallback( p_input, "state", StateChanged, p_intf );
526 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
527 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
528 var_DelCallback( p_input, "rate", RateChanged, p_intf );
529 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
531 vlc_object_release( p_input );
536 vlc_mutex_lock( &p_playlist->object_lock );
537 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
538 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
539 vlc_mutex_unlock( &p_playlist->object_lock );
543 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
544 (p_playlist != NULL) )
546 vlc_mutex_lock( &p_playlist->object_lock );
547 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
548 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
550 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
551 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
554 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
555 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
557 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
558 msg_rc( STATUS_CHANGE "( play state: 1 )" );
561 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
562 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
564 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
565 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
567 vlc_mutex_unlock( &p_playlist->object_lock );
570 if( p_input && b_showpos )
572 i_newpos = 100 * var_GetFloat( p_input, "position" );
573 if( i_oldpos != i_newpos )
576 msg_rc( "pos: %d%%", i_newpos );
580 /* Is there something to do? */
581 if( !b_complete ) continue;
583 /* Skip heading spaces */
585 while( *psz_cmd == ' ' )
590 /* Split psz_cmd at the first space and make sure that
591 * psz_arg is valid */
592 psz_arg = strchr( psz_cmd, ' ' );
596 while( *psz_arg == ' ' )
606 /* module specfic commands: @<module name> <command> <args...> */
607 if( *psz_cmd == '@' && *psz_arg )
609 /* Parse miscellaneous commands */
610 char *psz_alias = psz_cmd + 1;
611 char *psz_mycmd = strdup( psz_arg );
612 char *psz_myarg = strchr( psz_mycmd, ' ' );
617 msg_rc( "Not enough parameters." );
624 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
635 /* If the user typed a registered local command, try it */
636 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
641 val.psz_string = psz_arg;
642 i_ret = var_Set( p_intf, psz_cmd, val );
643 msg_rc( "%s: returned %i (%s)",
644 psz_cmd, i_ret, vlc_error( i_ret ) );
646 /* Or maybe it's a global command */
647 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
652 val.psz_string = psz_arg;
653 /* FIXME: it's a global command, but we should pass the
654 * local object as an argument, not p_intf->p_libvlc. */
655 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
658 msg_rc( "%s: returned %i (%s)",
659 psz_cmd, i_ret, vlc_error( i_ret ) );
662 else if( !strcmp( psz_cmd, "logout" ) )
664 /* Close connection */
665 if( p_intf->p_sys->i_socket != -1 )
667 net_Close( p_intf->p_sys->i_socket );
669 p_intf->p_sys->i_socket = -1;
671 else if( !strcmp( psz_cmd, "info" ) )
676 vlc_mutex_lock( &input_GetItem(p_input)->lock );
677 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
679 info_category_t *p_category = input_GetItem(p_input)
682 msg_rc( "+----[ %s ]", p_category->psz_name );
684 for ( j = 0; j < p_category->i_infos; j++ )
686 info_t *p_info = p_category->pp_infos[j];
687 msg_rc( "| %s: %s", p_info->psz_name,
692 msg_rc( "+----[ end of stream info ]" );
693 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
697 msg_rc( "no input" );
700 else if( !strcmp( psz_cmd, "is_playing" ) )
711 else if( !strcmp( psz_cmd, "get_time" ) )
720 var_Get( p_input, "time", &time );
721 msg_rc( "%i", time.i_time / 1000000);
724 else if( !strcmp( psz_cmd, "get_length" ) )
733 var_Get( p_input, "length", &time );
734 msg_rc( "%i", time.i_time / 1000000);
737 else if( !strcmp( psz_cmd, "get_title" ) )
745 msg_rc( "%s", input_GetItem(p_input)->psz_name );
748 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
749 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
751 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
752 b_longhelp = VLC_TRUE;
753 else b_longhelp = VLC_FALSE;
755 Help( p_intf, b_longhelp );
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(_("| stats . . . . . . . . show statistical information"));
874 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
875 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
876 msg_rc(_("| get_title . . . . . the title of the current stream"));
877 msg_rc(_("| get_length . . . . the length of the current stream"));
879 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
880 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
881 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
882 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
883 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
884 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
885 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
886 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
887 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
888 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
889 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
890 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
891 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
892 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
897 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
898 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
899 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
900 msg_rc(_("| @name marq-position #. . . .relative position control"));
901 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
902 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
903 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
904 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
906 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
907 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
908 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
909 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
910 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
912 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
913 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
914 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
915 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
916 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
917 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
918 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
919 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
920 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
921 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
922 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
923 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
924 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
925 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
928 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
929 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
930 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
931 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
933 msg_rc(_("+----[ end of help ]"));
936 /********************************************************************
937 * Status callback routines
938 ********************************************************************/
939 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
940 vlc_value_t oldval, vlc_value_t newval, void *p_data )
942 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
943 VLC_UNUSED(oldval); VLC_UNUSED(newval);
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 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
963 intf_thread_t *p_intf = (intf_thread_t*)p_data;
965 vlc_mutex_lock( &p_intf->p_sys->status_lock );
966 msg_rc( STATUS_CHANGE "( audio volume: %d )",
967 config_GetInt( p_this, "volume") );
968 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
972 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
973 vlc_value_t oldval, vlc_value_t newval, void *p_data )
975 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
976 intf_thread_t *p_intf = (intf_thread_t*)p_data;
977 playlist_t *p_playlist = NULL;
978 input_thread_t *p_input = NULL;
980 vlc_mutex_lock( &p_intf->p_sys->status_lock );
981 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
984 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
988 switch( p_playlist->status.i_status )
990 case PLAYLIST_STOPPED:
991 strcpy( cmd, "stop" );
993 case PLAYLIST_RUNNING:
994 strcpy( cmd, "play" );
996 case PLAYLIST_PAUSED:
997 strcpy( cmd, "pause" );
1001 } /* var_GetInteger( p_input, "state" ) */
1002 msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1003 vlc_object_release( p_playlist );
1005 vlc_object_release( p_input );
1007 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1011 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1012 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1014 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
1015 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1016 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1017 input_thread_t *p_input = NULL;
1019 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1020 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1023 msg_rc( STATUS_CHANGE "( new rate: %d )",
1024 var_GetInteger( p_input, "rate" ) );
1025 vlc_object_release( p_input );
1027 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1031 /********************************************************************
1033 ********************************************************************/
1034 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1035 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1037 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1038 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1039 input_thread_t *p_input;
1042 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1043 if( !p_input ) return VLC_ENOOBJ;
1045 var_Get( p_input, "state", &val );
1046 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1047 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1049 msg_rc( _("Press menu select or pause to continue.") );
1050 vlc_object_release( p_input );
1051 return VLC_EGENERIC;
1054 /* Parse commands that only require an input */
1055 if( !strcmp( psz_cmd, "pause" ) )
1057 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1058 var_Set( p_intf->p_libvlc, "key-pressed", val );
1059 vlc_object_release( p_input );
1062 else if( !strcmp( psz_cmd, "seek" ) )
1064 if( strlen( newval.psz_string ) > 0 &&
1065 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1067 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1068 var_Set( p_input, "position", val );
1072 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1073 var_Set( p_input, "time", val );
1075 vlc_object_release( p_input );
1078 else if ( !strcmp( psz_cmd, "fastforward" ) )
1080 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1081 var_Set( p_intf->p_libvlc, "key-pressed", val );
1082 vlc_object_release( p_input );
1085 else if ( !strcmp( psz_cmd, "rewind" ) )
1087 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1088 var_Set( p_intf->p_libvlc, "key-pressed", val );
1089 vlc_object_release( p_input );
1092 else if ( !strcmp( psz_cmd, "faster" ) )
1094 var_Set( p_input, "rate-faster", val );
1095 vlc_object_release( p_input );
1098 else if ( !strcmp( psz_cmd, "slower" ) )
1100 var_Set( p_input, "rate-slower", val );
1101 vlc_object_release( p_input );
1104 else if ( !strcmp( psz_cmd, "normal" ) )
1106 val.i_int = INPUT_RATE_DEFAULT;
1107 var_Set( p_input, "rate", val );
1108 vlc_object_release( p_input );
1111 else if( !strcmp( psz_cmd, "chapter" ) ||
1112 !strcmp( psz_cmd, "chapter_n" ) ||
1113 !strcmp( psz_cmd, "chapter_p" ) )
1115 if( !strcmp( psz_cmd, "chapter" ) )
1117 if ( *newval.psz_string )
1120 val.i_int = atoi( newval.psz_string );
1121 var_Set( p_input, "chapter", val );
1125 vlc_value_t val_list;
1128 var_Get( p_input, "chapter", &val );
1129 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1131 msg_rc( "Currently playing chapter %d/%d.",
1132 val.i_int, val_list.p_list->i_count );
1133 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1137 else if( !strcmp( psz_cmd, "chapter_n" ) )
1139 val.b_bool = VLC_TRUE;
1140 var_Set( p_input, "next-chapter", val );
1142 else if( !strcmp( psz_cmd, "chapter_p" ) )
1144 val.b_bool = VLC_TRUE;
1145 var_Set( p_input, "prev-chapter", val );
1147 vlc_object_release( p_input );
1150 else if( !strcmp( psz_cmd, "title" ) ||
1151 !strcmp( psz_cmd, "title_n" ) ||
1152 !strcmp( psz_cmd, "title_p" ) )
1154 if( !strcmp( psz_cmd, "title" ) )
1156 if ( *newval.psz_string )
1159 val.i_int = atoi( newval.psz_string );
1160 var_Set( p_input, "title", val );
1164 vlc_value_t val_list;
1167 var_Get( p_input, "title", &val );
1168 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1170 msg_rc( "Currently playing title %d/%d.",
1171 val.i_int, val_list.p_list->i_count );
1172 var_Change( p_this, "title", VLC_VAR_FREELIST,
1176 else if( !strcmp( psz_cmd, "title_n" ) )
1178 val.b_bool = VLC_TRUE;
1179 var_Set( p_input, "next-title", val );
1181 else if( !strcmp( psz_cmd, "title_p" ) )
1183 val.b_bool = VLC_TRUE;
1184 var_Set( p_input, "prev-title", val );
1187 vlc_object_release( p_input );
1190 else if( !strcmp( psz_cmd, "atrack" )
1191 || !strcmp( psz_cmd, "vtrack" )
1192 || !strcmp( psz_cmd, "strack" ) )
1194 const char *psz_variable;
1195 vlc_value_t val_name;
1198 if( !strcmp( psz_cmd, "atrack" ) )
1200 psz_variable = "audio-es";
1202 else if( !strcmp( psz_cmd, "vtrack" ) )
1204 psz_variable = "video-es";
1208 psz_variable = "spu-es";
1211 /* Get the descriptive name of the variable */
1212 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1214 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1216 if( newval.psz_string && *newval.psz_string )
1220 val.i_int = atoi( newval.psz_string );
1222 i_error = var_Set( p_input, psz_variable, val );
1227 vlc_value_t val, text;
1230 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1232 vlc_object_release( p_input );
1233 return VLC_EGENERIC;
1235 i_value = val.i_int;
1237 if ( var_Change( p_input, psz_variable,
1238 VLC_VAR_GETLIST, &val, &text ) < 0 )
1240 vlc_object_release( p_input );
1241 return VLC_EGENERIC;
1244 msg_rc( "+----[ %s ]", val_name.psz_string );
1245 for ( i = 0; i < val.p_list->i_count; i++ )
1247 if ( i_value == val.p_list->p_values[i].i_int )
1248 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1249 text.p_list->p_values[i].psz_string );
1251 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1252 text.p_list->p_values[i].psz_string );
1254 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1256 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1258 free( val_name.psz_string );
1260 i_error = VLC_SUCCESS;
1262 vlc_object_release( p_input );
1266 /* Never reached. */
1267 vlc_object_release( p_input );
1268 return VLC_EGENERIC;
1271 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1272 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1274 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1277 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1278 playlist_t *p_playlist = pl_Yield( p_this );
1281 if( p_playlist->p_input )
1283 var_Get( p_playlist->p_input, "state", &val );
1284 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1286 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1287 vlc_object_release( p_playlist );
1289 return VLC_EGENERIC;
1294 /* Parse commands that require a playlist */
1295 if( !strcmp( psz_cmd, "prev" ) )
1297 playlist_Prev( p_playlist );
1299 else if( !strcmp( psz_cmd, "next" ) )
1301 playlist_Next( p_playlist );
1303 else if( !strcmp( psz_cmd, "play" ) )
1305 msg_Warn( p_playlist, "play" );
1306 playlist_Play( p_playlist );
1308 else if( !strcmp( psz_cmd, "repeat" ) )
1310 vlc_bool_t b_update = VLC_TRUE;
1312 var_Get( p_playlist, "repeat", &val );
1314 if( strlen( newval.psz_string ) > 0 )
1316 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1317 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1319 b_update = VLC_FALSE;
1325 val.b_bool = !val.b_bool;
1326 var_Set( p_playlist, "repeat", val );
1328 msg_rc( "Setting repeat to %d", val.b_bool );
1330 else if( !strcmp( psz_cmd, "loop" ) )
1332 vlc_bool_t b_update = VLC_TRUE;
1334 var_Get( p_playlist, "loop", &val );
1336 if( strlen( newval.psz_string ) > 0 )
1338 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1339 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1341 b_update = VLC_FALSE;
1347 val.b_bool = !val.b_bool;
1348 var_Set( p_playlist, "loop", val );
1350 msg_rc( "Setting loop to %d", val.b_bool );
1352 else if( !strcmp( psz_cmd, "random" ) )
1354 vlc_bool_t b_update = VLC_TRUE;
1356 var_Get( p_playlist, "random", &val );
1358 if( strlen( newval.psz_string ) > 0 )
1360 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1361 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1363 b_update = VLC_FALSE;
1369 val.b_bool = !val.b_bool;
1370 var_Set( p_playlist, "random", val );
1372 msg_rc( "Setting random to %d", val.b_bool );
1374 else if (!strcmp( psz_cmd, "goto" ) )
1376 int i_pos = atoi( newval.psz_string );
1377 /* The playlist stores 2 times the same item: onelevel & category */
1378 int i_size = p_playlist->items.i_size / 2;
1381 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1382 else if( i_pos <= i_size )
1384 playlist_item_t *p_item, *p_parent;
1385 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1386 while( p_parent->p_parent )
1387 p_parent = p_parent->p_parent;
1388 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE,
1392 msg_rc( _("Playlist has only %d elements"), i_size );
1394 else if( !strcmp( psz_cmd, "stop" ) )
1396 playlist_Stop( p_playlist );
1398 else if( !strcmp( psz_cmd, "clear" ) )
1400 playlist_Stop( p_playlist );
1401 playlist_Clear( p_playlist, VLC_FALSE );
1403 else if( !strcmp( psz_cmd, "add" ) &&
1404 newval.psz_string && *newval.psz_string )
1406 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1410 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1411 if( playlist_AddInput( p_playlist, p_item,
1412 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1413 VLC_FALSE ) != VLC_SUCCESS )
1415 return VLC_EGENERIC;
1419 else if( !strcmp( psz_cmd, "enqueue" ) &&
1420 newval.psz_string && *newval.psz_string )
1422 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1426 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1427 if( playlist_AddInput( p_playlist, p_item,
1428 PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1429 VLC_FALSE ) != VLC_SUCCESS )
1431 return VLC_EGENERIC;
1435 else if( !strcmp( psz_cmd, "playlist" ) )
1437 msg_Dbg( p_playlist, "Dumping category" );
1438 playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1439 msg_Dbg( p_playlist, "Dumping Onelevel" );
1440 playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1442 else if( !strcmp( psz_cmd, "sort" ))
1444 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1445 SORT_ARTIST, ORDER_NORMAL );
1447 else if( !strcmp( psz_cmd, "status" ) )
1449 if( p_playlist->p_input )
1451 /* Replay the current state of the system. */
1453 input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1454 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1456 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1457 config_GetInt( p_intf, "volume" ));
1460 switch( p_playlist->status.i_status )
1462 case PLAYLIST_STOPPED:
1463 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1465 case PLAYLIST_RUNNING:
1466 msg_rc( STATUS_CHANGE "( play state: 1 )" );
1468 case PLAYLIST_PAUSED:
1469 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1472 msg_rc( STATUS_CHANGE "( state unknown )" );
1484 msg_rc( "unknown command!" );
1487 vlc_object_release( p_playlist );
1491 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1492 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1494 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1495 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1496 playlist_t *p_playlist;
1498 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1501 playlist_Stop( p_playlist );
1502 vlc_object_release( p_playlist );
1504 vlc_object_kill( p_this->p_libvlc );
1508 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1509 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1511 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1512 intf_thread_t *p_newintf = NULL;
1514 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1517 if( intf_RunThread( p_newintf ) )
1519 vlc_object_detach( p_newintf );
1520 intf_Destroy( p_newintf );
1527 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1528 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1530 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1531 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1532 input_thread_t *p_input = NULL;
1533 int i_error = VLC_EGENERIC;
1535 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1543 var_Get( p_input, "state", &val );
1544 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1546 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1547 vlc_object_release( p_input );
1548 return VLC_EGENERIC;
1550 vlc_object_release( p_input );
1553 if ( *newval.psz_string )
1556 audio_volume_t i_volume = atoi( newval.psz_string );
1557 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1559 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1561 i_error = VLC_EBADVAR;
1565 if( i_volume == AOUT_VOLUME_MIN )
1569 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1570 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1572 i_error = aout_VolumeSet( p_this, i_volume );
1573 osd_Volume( p_this );
1574 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1580 audio_volume_t i_volume;
1581 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1583 i_error = VLC_EGENERIC;
1587 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1588 i_error = VLC_SUCCESS;
1595 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1596 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1598 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1599 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1600 audio_volume_t i_volume;
1601 input_thread_t *p_input = NULL;
1602 int i_nb_steps = atoi(newval.psz_string);
1603 int i_error = VLC_SUCCESS;
1604 int i_volume_step = 0;
1606 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1614 var_Get( p_input, "state", &val );
1615 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1617 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1618 vlc_object_release( p_input );
1619 return VLC_EGENERIC;
1621 vlc_object_release( p_input );
1624 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1625 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1630 if ( !strcmp(psz_cmd, "volup") )
1632 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1633 i_error = VLC_EGENERIC;
1637 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1638 i_error = VLC_EGENERIC;
1640 osd_Volume( p_this );
1642 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1647 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1648 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1650 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1651 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1652 input_thread_t *p_input = NULL;
1653 vout_thread_t * p_vout;
1654 const char * psz_variable = NULL;
1657 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1661 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1662 vlc_object_release( p_input );
1666 if( !strcmp( psz_cmd, "vcrop" ) )
1668 psz_variable = "crop";
1670 else if( !strcmp( psz_cmd, "vratio" ) )
1672 psz_variable = "aspect-ratio";
1674 else if( !strcmp( psz_cmd, "vzoom" ) )
1676 psz_variable = "zoom";
1678 else if( !strcmp( psz_cmd, "snapshot" ) )
1680 psz_variable = "video-snapshot";
1683 if( newval.psz_string && *newval.psz_string )
1686 if( !strcmp( psz_variable, "zoom" ) )
1689 val.f_float = atof( newval.psz_string );
1690 i_error = var_Set( p_vout, psz_variable, val );
1694 i_error = var_Set( p_vout, psz_variable, newval );
1697 else if( !strcmp( psz_cmd, "snapshot" ) )
1699 i_error = var_Set( p_vout, psz_variable, newval );
1704 vlc_value_t val_name;
1705 vlc_value_t val, text;
1708 char *psz_value = NULL;
1710 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1712 vlc_object_release( p_vout );
1713 return VLC_EGENERIC;
1715 if( !strcmp( psz_variable, "zoom" ) )
1717 f_value = val.f_float;
1721 psz_value = strdup( val.psz_string );
1724 if ( var_Change( p_vout, psz_variable,
1725 VLC_VAR_GETLIST, &val, &text ) < 0 )
1727 vlc_object_release( p_vout );
1728 return VLC_EGENERIC;
1731 /* Get the descriptive name of the variable */
1732 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1734 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1736 msg_rc( "+----[ %s ]", val_name.psz_string );
1737 if( !strcmp( psz_variable, "zoom" ) )
1739 for ( i = 0; i < val.p_list->i_count; i++ )
1741 if ( f_value == val.p_list->p_values[i].f_float )
1742 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1743 text.p_list->p_values[i].psz_string );
1745 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1746 text.p_list->p_values[i].psz_string );
1751 for ( i = 0; i < val.p_list->i_count; i++ )
1753 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1754 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1755 text.p_list->p_values[i].psz_string );
1757 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1758 text.p_list->p_values[i].psz_string );
1762 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1764 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1766 free( val_name.psz_string );
1768 i_error = VLC_SUCCESS;
1770 vlc_object_release( p_vout );
1774 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1775 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1777 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1778 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1779 input_thread_t *p_input = NULL;
1780 aout_instance_t * p_aout;
1781 const char * psz_variable;
1782 vlc_value_t val_name;
1785 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1793 var_Get( p_input, "state", &val );
1794 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1795 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1796 vlc_object_release( p_input );
1797 return VLC_EGENERIC;
1799 vlc_object_release( p_input );
1802 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1803 if ( p_aout == NULL ) return VLC_ENOOBJ;
1805 if ( !strcmp( psz_cmd, "adev" ) )
1807 psz_variable = "audio-device";
1811 psz_variable = "audio-channels";
1814 /* Get the descriptive name of the variable */
1815 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1817 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1819 if ( !*newval.psz_string )
1821 /* Retrieve all registered ***. */
1822 vlc_value_t val, text;
1825 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1827 vlc_object_release( (vlc_object_t *)p_aout );
1828 return VLC_EGENERIC;
1830 i_value = val.i_int;
1832 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1833 VLC_VAR_GETLIST, &val, &text ) < 0 )
1835 vlc_object_release( (vlc_object_t *)p_aout );
1836 return VLC_EGENERIC;
1839 msg_rc( "+----[ %s ]", val_name.psz_string );
1840 for ( i = 0; i < val.p_list->i_count; i++ )
1842 if ( i_value == val.p_list->p_values[i].i_int )
1843 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1844 text.p_list->p_values[i].psz_string );
1846 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1847 text.p_list->p_values[i].psz_string );
1849 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1851 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1853 free( val_name.psz_string );
1854 i_error = VLC_SUCCESS;
1859 val.i_int = atoi( newval.psz_string );
1861 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1863 vlc_object_release( (vlc_object_t *)p_aout );
1868 /* OSD menu commands */
1869 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1870 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1872 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1873 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1874 playlist_t *p_playlist = NULL;
1876 int i_error = VLC_EGENERIC;
1878 if ( !*newval.psz_string )
1880 msg_rc( _("Please provide one of the following parameters:") );
1881 msg_rc( "[on|off|up|down|left|right|select]" );
1885 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1889 if( p_playlist->p_input )
1891 var_Get( p_playlist->p_input, "state", &val );
1892 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1893 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1895 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1896 vlc_object_release( p_playlist );
1897 return VLC_EGENERIC;
1900 vlc_object_release( p_playlist );
1902 val.psz_string = strdup( newval.psz_string );
1903 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1904 osd_MenuShow( p_this );
1905 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1906 osd_MenuHide( p_this );
1907 else if( !strcmp( val.psz_string, "up" ) )
1908 osd_MenuUp( p_this );
1909 else if( !strcmp( val.psz_string, "down" ) )
1910 osd_MenuDown( p_this );
1911 else if( !strcmp( val.psz_string, "left" ) )
1912 osd_MenuPrev( p_this );
1913 else if( !strcmp( val.psz_string, "right" ) )
1914 osd_MenuNext( p_this );
1915 else if( !strcmp( val.psz_string, "select" ) )
1916 osd_MenuActivate( p_this );
1919 msg_rc( _("Please provide one of the following parameters:") );
1920 msg_rc( "[on|off|up|down|left|right|select]" );
1921 free( val.psz_string );
1925 i_error = VLC_SUCCESS;
1926 free( val.psz_string );
1930 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1931 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1933 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1934 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1935 input_thread_t *p_input = NULL;
1938 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1942 if( !strcmp( psz_cmd, "stats" ) )
1944 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1945 updateStatistics( p_intf, input_GetItem(p_input) );
1946 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1953 msg_rc(_("Unknown command!") );
1956 vlc_object_release( p_input );
1957 i_error = VLC_SUCCESS;
1961 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1963 if( !p_item ) return VLC_EGENERIC;
1965 vlc_mutex_lock( &p_item->p_stats->lock );
1966 msg_rc( "+----[ begin of statistical info ]" );
1969 msg_rc(_("+-[Incoming]"));
1970 msg_rc(_("| input bytes read : %8.0f kB"),
1971 (float)(p_item->p_stats->i_read_bytes)/1000 );
1972 msg_rc(_("| input bitrate : %6.0f kb/s"),
1973 (float)(p_item->p_stats->f_input_bitrate)*8000 );
1974 msg_rc(_("| demux bytes read : %8.0f kB"),
1975 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
1976 msg_rc(_("| demux bitrate : %6.0f kb/s"),
1977 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
1980 msg_rc(_("+-[Video Decoding]"));
1981 msg_rc(_("| video decoded : %5i"),
1982 p_item->p_stats->i_decoded_video );
1983 msg_rc(_("| frames displayed : %5i"),
1984 p_item->p_stats->i_displayed_pictures );
1985 msg_rc(_("| frames lost : %5i"),
1986 p_item->p_stats->i_lost_pictures );
1989 msg_rc(_("+-[Audio Decoding]"));
1990 msg_rc(_("| audio decoded : %5i"),
1991 p_item->p_stats->i_decoded_audio );
1992 msg_rc(_("| buffers played : %5i"),
1993 p_item->p_stats->i_played_abuffers );
1994 msg_rc(_("| buffers lost : %5i"),
1995 p_item->p_stats->i_lost_abuffers );
1998 msg_rc(_("+-[Streaming]"));
1999 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
2000 msg_rc(_("| bytes sent : %8.0f kB"),
2001 (float)(p_item->p_stats->i_sent_bytes)/1000 );
2002 msg_rc(_("| sending bitrate : %6.0f kb/s"),
2003 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
2005 msg_rc( "+----[ end of statistical info ]" );
2006 vlc_mutex_unlock( &p_item->p_stats->lock );
2012 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2014 INPUT_RECORD input_record;
2017 /* On Win32, select() only works on socket descriptors */
2018 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2019 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2021 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2022 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2025 if( input_record.EventType != KEY_EVENT ||
2026 !input_record.Event.KeyEvent.bKeyDown ||
2027 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2028 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2029 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2030 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2032 /* nothing interesting */
2036 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2038 /* Echo out the command */
2039 putc( p_buffer[ *pi_size ], stdout );
2041 /* Handle special keys */
2042 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2044 putc( '\n', stdout );
2047 switch( p_buffer[ *pi_size ] )
2053 putc( ' ', stdout );
2054 putc( '\b', stdout );
2065 if( *pi_size == MAX_LINE_LENGTH ||
2066 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2068 p_buffer[ *pi_size ] = 0;
2077 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2082 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2083 return ReadWin32( p_intf, p_buffer, pi_size );
2084 else if( p_intf->p_sys->i_socket == -1 )
2086 msleep( INTF_IDLE_SLEEP );
2091 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2092 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2093 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2094 (uint8_t *)p_buffer + *pi_size, 1, VLC_FALSE ) ) > 0 )
2096 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2102 /* Connection closed */
2105 if( p_intf->p_sys->i_socket != -1 )
2107 net_Close( p_intf->p_sys->i_socket );
2108 p_intf->p_sys->i_socket = -1;
2112 /* Standard input closed: exit */
2114 Quit( p_intf, NULL, empty, empty, NULL );
2117 p_buffer[ *pi_size ] = 0;
2121 if( *pi_size == MAX_LINE_LENGTH ||
2122 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2124 p_buffer[ *pi_size ] = 0;
2131 /*****************************************************************************
2132 * parse_MRL: build a input item from a full mrl
2133 *****************************************************************************
2134 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2135 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2136 * space is a new option. Should be good enough for our purpose.
2137 *****************************************************************************/
2138 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2140 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2141 #define SKIPTRAILINGSPACE( p, d ) \
2142 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2144 input_item_t *p_item = NULL;
2145 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2146 char **ppsz_options = NULL;
2147 int i, i_options = 0;
2149 if( !psz_mrl ) return 0;
2151 psz_mrl = psz_orig = strdup( psz_mrl );
2154 SKIPSPACE( psz_mrl );
2157 for( ; *psz_mrl; psz_mrl++ )
2159 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2161 /* We have a complete item */
2164 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2165 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2167 /* We have a complete item */
2172 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2173 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2175 /* Remove '"' and '\'' if necessary */
2176 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2177 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2178 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2179 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2181 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2182 else if( *psz_item )
2185 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2186 ppsz_options[i_options - 1] = &psz_item[1];
2189 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2192 /* Now create a playlist item */
2195 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2196 for( i = 0; i < i_options; i++ )
2198 input_ItemAddOption( p_item, ppsz_options[i] );
2202 if( i_options ) free( ppsz_options );