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 *****************************************************************************/
33 #include <vlc_plugin.h>
35 #include <errno.h> /* ENOMEM */
39 #include <vlc_interface.h>
43 #include <vlc_playlist.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
52 #include <sys/types.h>
54 #include <vlc_network.h>
57 #include <vlc_charset.h>
59 #if defined(AF_UNIX) && !defined(AF_LOCAL)
60 # define AF_LOCAL AF_UNIX
63 #if defined(AF_LOCAL) && ! defined(WIN32)
67 #define MAX_LINE_LENGTH 256
68 #define STATUS_CHANGE "status change: "
70 static const char *ppsz_input_state[] = { N_("Initializing"), N_("Opening"), N_("Buffer"), N_("Play"), N_("Pause"), N_("Stop"), N_("Error") };
72 /*****************************************************************************
74 *****************************************************************************/
75 static int Activate ( vlc_object_t * );
76 static void Deactivate ( vlc_object_t * );
77 static void Run ( intf_thread_t * );
79 static void Help ( intf_thread_t *, bool );
80 static void RegisterCallbacks( intf_thread_t * );
82 static bool ReadCommand( intf_thread_t *, char *, int * );
84 static input_item_t *parse_MRL( intf_thread_t *, char * );
86 static int Input ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
88 static int Playlist ( vlc_object_t *, char const *,
89 vlc_value_t, vlc_value_t, void * );
90 static int Quit ( vlc_object_t *, char const *,
91 vlc_value_t, vlc_value_t, void * );
92 static int Intf ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int Volume ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
96 static int VolumeMove ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
98 static int VideoConfig ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int AudioConfig ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int Menu ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int Statistics ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
107 static int updateStatistics( intf_thread_t *, input_item_t *);
109 /* Status Callbacks */
110 static int TimeOffsetChanged( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t , void * );
112 static int VolumeChanged ( vlc_object_t *, char const *,
113 vlc_value_t, vlc_value_t, void * );
114 static int StateChanged ( vlc_object_t *, char const *,
115 vlc_value_t, vlc_value_t, void * );
116 static int RateChanged ( vlc_object_t *, char const *,
117 vlc_value_t, vlc_value_t, void * );
121 int *pi_socket_listen;
126 vlc_mutex_t status_lock;
127 playlist_status_t i_last_state;
135 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
137 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
140 va_start( args, psz_fmt );
142 if( p_intf->p_sys->i_socket == -1 )
144 utf8_vfprintf( stdout, psz_fmt, args );
149 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
150 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
155 /*****************************************************************************
157 *****************************************************************************/
158 #define POS_TEXT N_("Show stream position")
159 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
160 "stream from time to time." )
162 #define TTY_TEXT N_("Fake TTY")
163 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
165 #define UNIX_TEXT N_("UNIX socket command input")
166 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
169 #define HOST_TEXT N_("TCP command input")
170 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
171 "You can set the address and port the interface will bind to." )
174 #define QUIET_TEXT N_("Do not open a DOS command box interface")
175 #define QUIET_LONGTEXT N_( \
176 "By default the rc interface plugin will start a DOS command box. " \
177 "Enabling the quiet mode will not bring this command box but can also " \
178 "be pretty annoying when you want to stop VLC and no video window is " \
183 set_shortname( N_("RC"));
184 set_category( CAT_INTERFACE );
185 set_subcategory( SUBCAT_INTERFACE_MAIN );
186 set_description( N_("Remote control interface") );
187 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, true );
190 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, false );
192 #if defined (HAVE_ISATTY)
193 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, true );
195 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, true );
197 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, true );
199 set_capability( "interface", 20 );
201 set_callbacks( Activate, Deactivate );
204 /*****************************************************************************
205 * Activate: initialize and create stuff
206 *****************************************************************************/
207 static int Activate( vlc_object_t *p_this )
209 intf_thread_t *p_intf = (intf_thread_t*)p_this;
210 char *psz_host, *psz_unix_path;
211 int *pi_socket = NULL;
214 #if defined(HAVE_ISATTY)
215 /* Check that stdin is a TTY */
216 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
218 msg_Warn( p_intf, "fd 0 is not a TTY" );
223 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
229 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
230 free( psz_unix_path );
233 struct sockaddr_un addr;
235 memset( &addr, 0, sizeof(struct sockaddr_un) );
237 msg_Dbg( p_intf, "trying UNIX socket" );
239 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
241 msg_Warn( p_intf, "can't open socket: %m" );
242 free( psz_unix_path );
246 addr.sun_family = AF_LOCAL;
247 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
248 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
250 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
251 && (errno == EADDRINUSE)
252 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
253 && (errno == ECONNREFUSED))
255 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
256 unlink (psz_unix_path);
258 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
260 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
262 free (psz_unix_path);
263 net_Close (i_socket);
268 if( listen( i_socket, 1 ) )
270 msg_Warn( p_intf, "can't listen on socket: %m");
271 free( psz_unix_path );
272 net_Close( i_socket );
276 /* FIXME: we need a core function to merge listening sockets sets */
277 pi_socket = calloc( 2, sizeof( int ) );
278 if( pi_socket == NULL )
280 free( psz_unix_path );
281 net_Close( i_socket );
284 pi_socket[0] = i_socket;
286 #endif /* AF_LOCAL */
290 if( ( pi_socket == NULL ) &&
291 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
295 vlc_UrlParse( &url, psz_host, 0 );
297 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
299 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
300 if( pi_socket == NULL )
302 msg_Warn( p_intf, "can't listen to %s port %i",
303 url.psz_host, url.i_port );
304 vlc_UrlClean( &url );
309 vlc_UrlClean( &url );
313 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
316 msg_Err( p_intf, "no memory" );
320 p_intf->p_sys->pi_socket_listen = pi_socket;
321 p_intf->p_sys->i_socket = -1;
322 p_intf->p_sys->psz_unix_path = psz_unix_path;
323 vlc_mutex_init( &p_intf->p_sys->status_lock );
324 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
326 /* Non-buffered stdout */
327 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
329 p_intf->pf_run = Run;
332 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
333 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
338 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
342 /*****************************************************************************
343 * Deactivate: uninitialize and cleanup
344 *****************************************************************************/
345 static void Deactivate( vlc_object_t *p_this )
347 intf_thread_t *p_intf = (intf_thread_t*)p_this;
349 net_ListenClose( p_intf->p_sys->pi_socket_listen );
350 if( p_intf->p_sys->i_socket != -1 )
351 net_Close( p_intf->p_sys->i_socket );
352 if( p_intf->p_sys->psz_unix_path != NULL )
354 #if defined(AF_LOCAL) && !defined(WIN32)
355 unlink( p_intf->p_sys->psz_unix_path );
357 free( p_intf->p_sys->psz_unix_path );
359 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
360 free( p_intf->p_sys );
363 /*****************************************************************************
364 * RegisterCallbacks: Register callbacks to dynamic variables
365 *****************************************************************************/
366 static void RegisterCallbacks( intf_thread_t *p_intf )
368 /* Register commands that will be cleaned up upon object destruction */
369 #define ADD( name, type, target ) \
370 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
371 var_AddCallback( p_intf, name, target, NULL );
372 ADD( "quit", VOID, Quit )
373 ADD( "intf", STRING, Intf )
375 ADD( "add", STRING, Playlist )
376 ADD( "repeat", STRING, Playlist )
377 ADD( "loop", STRING, Playlist )
378 ADD( "random", STRING, Playlist )
379 ADD( "enqueue", STRING, Playlist )
380 ADD( "playlist", VOID, Playlist )
381 ADD( "sort", VOID, Playlist )
382 ADD( "play", VOID, Playlist )
383 ADD( "stop", VOID, Playlist )
384 ADD( "clear", VOID, Playlist )
385 ADD( "prev", VOID, Playlist )
386 ADD( "next", VOID, Playlist )
387 ADD( "goto", INTEGER, Playlist )
388 ADD( "status", INTEGER, Playlist )
390 /* OSD menu commands */
391 ADD( "menu", STRING, Menu )
394 ADD( "pause", VOID, Input )
395 ADD( "seek", INTEGER, Input )
396 ADD( "title", STRING, Input )
397 ADD( "title_n", VOID, Input )
398 ADD( "title_p", VOID, Input )
399 ADD( "chapter", STRING, Input )
400 ADD( "chapter_n", VOID, Input )
401 ADD( "chapter_p", VOID, Input )
403 ADD( "fastforward", VOID, Input )
404 ADD( "rewind", VOID, Input )
405 ADD( "faster", VOID, Input )
406 ADD( "slower", VOID, Input )
407 ADD( "normal", VOID, Input )
409 ADD( "atrack", STRING, Input )
410 ADD( "vtrack", STRING, Input )
411 ADD( "strack", STRING, Input )
414 ADD( "vratio", STRING, VideoConfig )
415 ADD( "vcrop", STRING, VideoConfig )
416 ADD( "vzoom", STRING, VideoConfig )
417 ADD( "snapshot", VOID, VideoConfig )
420 ADD( "volume", STRING, Volume )
421 ADD( "volup", STRING, VolumeMove )
422 ADD( "voldown", STRING, VolumeMove )
423 ADD( "adev", STRING, AudioConfig )
424 ADD( "achan", STRING, AudioConfig )
426 /* misc menu commands */
427 ADD( "stats", BOOL, Statistics )
432 /*****************************************************************************
434 *****************************************************************************
435 * This part of the interface is in a separate thread so that we can call
436 * exec() from within it without annoying the rest of the program.
437 *****************************************************************************/
438 static void Run( intf_thread_t *p_intf )
440 input_thread_t * p_input;
441 playlist_t * p_playlist;
443 char p_buffer[ MAX_LINE_LENGTH + 1 ];
444 bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
445 bool b_longhelp = false;
455 /* Register commands that will be cleaned up upon object destruction */
456 RegisterCallbacks( p_intf );
458 /* status callbacks */
459 /* Listen to audio volume updates */
460 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
463 /* Get the file descriptor of the console input */
464 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
465 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
467 msg_Err( p_intf, "couldn't find user input handle" );
468 vlc_object_kill( p_intf );
472 while( !intf_ShouldDie( p_intf ) )
474 char *psz_cmd, *psz_arg;
477 if( p_intf->p_sys->pi_socket_listen != NULL &&
478 p_intf->p_sys->i_socket == -1 )
480 p_intf->p_sys->i_socket =
481 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
483 if( p_intf->p_sys->i_socket == -1 ) continue;
486 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
488 /* Manage the input part */
489 if( p_input == NULL )
493 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
498 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
502 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
506 /* New input has been registered */
509 if( !p_input->b_dead || !p_input->b_die )
512 input_item_GetURI( input_GetItem( p_input ) );
513 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
515 msg_rc( STATUS_CHANGE "( audio volume: %d )",
516 config_GetInt( p_intf, "volume" ));
518 var_AddCallback( p_input, "state", StateChanged, p_intf );
519 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
520 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
521 var_AddCallback( p_input, "rate", RateChanged, p_intf );
522 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
526 else if( p_input->b_dead )
528 var_DelCallback( p_input, "state", StateChanged, p_intf );
529 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
530 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
531 var_DelCallback( p_input, "rate", RateChanged, p_intf );
532 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
534 vlc_object_release( p_input );
539 vlc_mutex_lock( &p_playlist->object_lock );
540 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
541 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
542 vlc_mutex_unlock( &p_playlist->object_lock );
546 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
547 (p_playlist != NULL) )
549 vlc_mutex_lock( &p_playlist->object_lock );
550 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
551 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
553 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
554 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
557 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
558 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
560 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
561 msg_rc( STATUS_CHANGE "( play state: 3 )" );
564 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
565 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
567 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
568 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
570 vlc_mutex_unlock( &p_playlist->object_lock );
573 if( p_input && b_showpos )
575 i_newpos = 100 * var_GetFloat( p_input, "position" );
576 if( i_oldpos != i_newpos )
579 msg_rc( "pos: %d%%", i_newpos );
583 /* Is there something to do? */
584 if( !b_complete ) continue;
586 /* Skip heading spaces */
588 while( *psz_cmd == ' ' )
593 /* Split psz_cmd at the first space and make sure that
594 * psz_arg is valid */
595 psz_arg = strchr( psz_cmd, ' ' );
599 while( *psz_arg == ' ' )
609 /* module specfic commands: @<module name> <command> <args...> */
610 if( *psz_cmd == '@' && *psz_arg )
612 /* Parse miscellaneous commands */
613 char *psz_alias = psz_cmd + 1;
614 char *psz_mycmd = strdup( psz_arg );
615 char *psz_myarg = strchr( psz_mycmd, ' ' );
620 msg_rc( "Not enough parameters." );
627 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
638 /* If the user typed a registered local command, try it */
639 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
644 val.psz_string = psz_arg;
645 i_ret = var_Set( p_intf, psz_cmd, val );
646 msg_rc( "%s: returned %i (%s)",
647 psz_cmd, i_ret, vlc_error( i_ret ) );
649 /* Or maybe it's a global command */
650 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
655 val.psz_string = psz_arg;
656 /* FIXME: it's a global command, but we should pass the
657 * local object as an argument, not p_intf->p_libvlc. */
658 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
661 msg_rc( "%s: returned %i (%s)",
662 psz_cmd, i_ret, vlc_error( i_ret ) );
665 else if( !strcmp( psz_cmd, "logout" ) )
667 /* Close connection */
668 if( p_intf->p_sys->i_socket != -1 )
670 net_Close( p_intf->p_sys->i_socket );
672 p_intf->p_sys->i_socket = -1;
674 else if( !strcmp( psz_cmd, "info" ) )
679 vlc_mutex_lock( &input_GetItem(p_input)->lock );
680 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
682 info_category_t *p_category = input_GetItem(p_input)
685 msg_rc( "+----[ %s ]", p_category->psz_name );
687 for ( j = 0; j < p_category->i_infos; j++ )
689 info_t *p_info = p_category->pp_infos[j];
690 msg_rc( "| %s: %s", p_info->psz_name,
695 msg_rc( "+----[ end of stream info ]" );
696 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
700 msg_rc( "no input" );
703 else if( !strcmp( psz_cmd, "is_playing" ) )
714 else if( !strcmp( psz_cmd, "get_time" ) )
723 var_Get( p_input, "time", &time );
724 msg_rc( "%i", time.i_time / 1000000);
727 else if( !strcmp( psz_cmd, "get_length" ) )
736 var_Get( p_input, "length", &time );
737 msg_rc( "%i", time.i_time / 1000000);
740 else if( !strcmp( psz_cmd, "get_title" ) )
748 msg_rc( "%s", input_GetItem(p_input)->psz_name );
751 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
752 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
754 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
756 else b_longhelp = false;
758 Help( p_intf, b_longhelp );
760 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
762 var_SetInteger( p_intf->p_libvlc, "key-pressed",
763 config_GetInt( p_intf, psz_arg ) );
765 else switch( psz_cmd[0] )
771 vout_thread_t *p_vout;
772 p_vout = vlc_object_find( p_input,
773 VLC_OBJECT_VOUT, FIND_CHILD );
778 bool b_update = false;
779 var_Get( p_vout, "fullscreen", &val );
780 val.b_bool = !val.b_bool;
781 if( !strncmp( psz_arg, "on", 2 )
782 && ( val.b_bool == true ) )
787 else if( !strncmp( psz_arg, "off", 3 )
788 && ( val.b_bool == false ) )
793 else if( strncmp( psz_arg, "off", 3 )
794 && strncmp( psz_arg, "on", 2 ) )
796 if( b_update ) var_Set( p_vout, "fullscreen", val );
797 vlc_object_release( p_vout );
808 /* Ignore empty lines */
812 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
816 /* Command processed */
817 i_size = 0; p_buffer[0] = 0;
820 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
821 msg_rc( STATUS_CHANGE "( quit )" );
825 var_DelCallback( p_input, "state", StateChanged, p_intf );
826 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
827 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
828 var_DelCallback( p_input, "rate", RateChanged, p_intf );
829 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
830 vlc_object_release( p_input );
836 vlc_object_release( p_playlist );
840 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
843 static void Help( intf_thread_t *p_intf, bool b_longhelp)
845 msg_rc(_("+----[ Remote control commands ]"));
847 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
848 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
849 msg_rc(_("| playlist . . . . . show items currently in playlist"));
850 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
851 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
852 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
853 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
854 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
855 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
856 msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
857 msg_rc(_("| random [on|off] . . . . . . . toggle random jumping"));
858 msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
859 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
860 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
861 msg_rc(_("| title_n . . . . . . . . next title in current item"));
862 msg_rc(_("| title_p . . . . . . previous title in current item"));
863 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
864 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
865 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
867 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
868 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
869 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
870 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
871 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
872 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
873 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
874 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
875 msg_rc(_("| info . . . . . information about the current stream"));
876 msg_rc(_("| stats . . . . . . . . show statistical information"));
877 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
878 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
879 msg_rc(_("| get_title . . . . . the title of the current stream"));
880 msg_rc(_("| get_length . . . . the length of the current stream"));
882 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
883 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
884 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
885 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
886 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
887 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
888 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
889 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
890 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
891 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
892 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
893 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
894 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
895 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
900 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
901 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
902 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
903 msg_rc(_("| @name marq-position #. . . .relative position control"));
904 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
905 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
906 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
907 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
909 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
910 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
911 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
912 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
913 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
915 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
916 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
917 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
918 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
919 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
920 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
921 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
922 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
923 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
924 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
925 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
926 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
927 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
928 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
931 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
932 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
933 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
934 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
936 msg_rc(_("+----[ end of help ]"));
939 /********************************************************************
940 * Status callback routines
941 ********************************************************************/
942 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
943 vlc_value_t oldval, vlc_value_t newval, void *p_data )
945 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
946 VLC_UNUSED(oldval); VLC_UNUSED(newval);
947 intf_thread_t *p_intf = (intf_thread_t*)p_data;
948 input_thread_t *p_input = NULL;
950 vlc_mutex_lock( &p_intf->p_sys->status_lock );
951 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
954 msg_rc( STATUS_CHANGE "( time-offset: %d )",
955 var_GetInteger( p_input, "time-offset" ) );
956 vlc_object_release( p_input );
958 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
962 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
963 vlc_value_t oldval, vlc_value_t newval, void *p_data )
965 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
966 intf_thread_t *p_intf = (intf_thread_t*)p_data;
968 vlc_mutex_lock( &p_intf->p_sys->status_lock );
969 msg_rc( STATUS_CHANGE "( audio volume: %d )",
970 config_GetInt( p_this, "volume") );
971 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
975 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
976 vlc_value_t oldval, vlc_value_t newval, void *p_data )
978 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
979 intf_thread_t *p_intf = (intf_thread_t*)p_data;
980 playlist_t *p_playlist = NULL;
981 input_thread_t *p_input = NULL;
983 vlc_mutex_lock( &p_intf->p_sys->status_lock );
984 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
987 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
991 switch( p_playlist->status.i_status )
993 case PLAYLIST_STOPPED:
994 strcpy( cmd, "stop" );
996 case PLAYLIST_RUNNING:
997 strcpy( cmd, "play" );
999 case PLAYLIST_PAUSED:
1000 strcpy( cmd, "pause" );
1004 } /* var_GetInteger( p_input, "state" ) */
1005 msg_rc( STATUS_CHANGE "( %s state: %d ): %s",
1006 &cmd[0], newval.i_int,
1007 ppsz_input_state[ newval.i_int ] );
1008 vlc_object_release( p_playlist );
1010 vlc_object_release( p_input );
1012 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1016 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1017 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1019 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
1020 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1021 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1022 input_thread_t *p_input = NULL;
1024 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1025 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1028 msg_rc( STATUS_CHANGE "( new rate: %d )",
1029 var_GetInteger( p_input, "rate" ) );
1030 vlc_object_release( p_input );
1032 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1036 /********************************************************************
1038 ********************************************************************/
1039 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1040 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1042 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1043 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1044 input_thread_t *p_input;
1047 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1048 if( !p_input ) return VLC_ENOOBJ;
1050 var_Get( p_input, "state", &val );
1051 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1052 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1054 msg_rc( _("Press menu select or pause to continue.") );
1055 vlc_object_release( p_input );
1056 return VLC_EGENERIC;
1059 /* Parse commands that only require an input */
1060 if( !strcmp( psz_cmd, "pause" ) )
1062 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1063 var_Set( p_intf->p_libvlc, "key-pressed", val );
1064 vlc_object_release( p_input );
1067 else if( !strcmp( psz_cmd, "seek" ) )
1069 if( strlen( newval.psz_string ) > 0 &&
1070 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1072 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1073 var_Set( p_input, "position", val );
1077 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1078 var_Set( p_input, "time", val );
1080 vlc_object_release( p_input );
1083 else if ( !strcmp( psz_cmd, "fastforward" ) )
1085 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1086 var_Set( p_intf->p_libvlc, "key-pressed", val );
1087 vlc_object_release( p_input );
1090 else if ( !strcmp( psz_cmd, "rewind" ) )
1092 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1093 var_Set( p_intf->p_libvlc, "key-pressed", val );
1094 vlc_object_release( p_input );
1097 else if ( !strcmp( psz_cmd, "faster" ) )
1099 var_Set( p_input, "rate-faster", val );
1100 vlc_object_release( p_input );
1103 else if ( !strcmp( psz_cmd, "slower" ) )
1105 var_Set( p_input, "rate-slower", val );
1106 vlc_object_release( p_input );
1109 else if ( !strcmp( psz_cmd, "normal" ) )
1111 val.i_int = INPUT_RATE_DEFAULT;
1112 var_Set( p_input, "rate", val );
1113 vlc_object_release( p_input );
1116 else if( !strcmp( psz_cmd, "chapter" ) ||
1117 !strcmp( psz_cmd, "chapter_n" ) ||
1118 !strcmp( psz_cmd, "chapter_p" ) )
1120 if( !strcmp( psz_cmd, "chapter" ) )
1122 if ( *newval.psz_string )
1125 val.i_int = atoi( newval.psz_string );
1126 var_Set( p_input, "chapter", val );
1130 vlc_value_t val_list;
1133 var_Get( p_input, "chapter", &val );
1134 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1136 msg_rc( "Currently playing chapter %d/%d.",
1137 val.i_int, val_list.p_list->i_count );
1138 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1142 else if( !strcmp( psz_cmd, "chapter_n" ) )
1145 var_Set( p_input, "next-chapter", val );
1147 else if( !strcmp( psz_cmd, "chapter_p" ) )
1150 var_Set( p_input, "prev-chapter", val );
1152 vlc_object_release( p_input );
1155 else if( !strcmp( psz_cmd, "title" ) ||
1156 !strcmp( psz_cmd, "title_n" ) ||
1157 !strcmp( psz_cmd, "title_p" ) )
1159 if( !strcmp( psz_cmd, "title" ) )
1161 if ( *newval.psz_string )
1164 val.i_int = atoi( newval.psz_string );
1165 var_Set( p_input, "title", val );
1169 vlc_value_t val_list;
1172 var_Get( p_input, "title", &val );
1173 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1175 msg_rc( "Currently playing title %d/%d.",
1176 val.i_int, val_list.p_list->i_count );
1177 var_Change( p_this, "title", VLC_VAR_FREELIST,
1181 else if( !strcmp( psz_cmd, "title_n" ) )
1184 var_Set( p_input, "next-title", val );
1186 else if( !strcmp( psz_cmd, "title_p" ) )
1189 var_Set( p_input, "prev-title", val );
1192 vlc_object_release( p_input );
1195 else if( !strcmp( psz_cmd, "atrack" )
1196 || !strcmp( psz_cmd, "vtrack" )
1197 || !strcmp( psz_cmd, "strack" ) )
1199 const char *psz_variable;
1200 vlc_value_t val_name;
1203 if( !strcmp( psz_cmd, "atrack" ) )
1205 psz_variable = "audio-es";
1207 else if( !strcmp( psz_cmd, "vtrack" ) )
1209 psz_variable = "video-es";
1213 psz_variable = "spu-es";
1216 /* Get the descriptive name of the variable */
1217 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1219 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1221 if( newval.psz_string && *newval.psz_string )
1225 val.i_int = atoi( newval.psz_string );
1227 i_error = var_Set( p_input, psz_variable, val );
1232 vlc_value_t val, text;
1235 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1237 vlc_object_release( p_input );
1238 return VLC_EGENERIC;
1240 i_value = val.i_int;
1242 if ( var_Change( p_input, psz_variable,
1243 VLC_VAR_GETLIST, &val, &text ) < 0 )
1245 vlc_object_release( p_input );
1246 return VLC_EGENERIC;
1249 msg_rc( "+----[ %s ]", val_name.psz_string );
1250 for ( i = 0; i < val.p_list->i_count; i++ )
1252 if ( i_value == val.p_list->p_values[i].i_int )
1253 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1254 text.p_list->p_values[i].psz_string );
1256 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1257 text.p_list->p_values[i].psz_string );
1259 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1261 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1263 free( val_name.psz_string );
1265 i_error = VLC_SUCCESS;
1267 vlc_object_release( p_input );
1271 /* Never reached. */
1272 vlc_object_release( p_input );
1273 return VLC_EGENERIC;
1276 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1279 char psz_buffer[MSTRTIME_MAX_SIZE];
1280 for( i = 0; i< p_item->i_children; i++ )
1282 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1284 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1285 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1288 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1290 if( p_item->pp_children[i]->i_children >= 0 )
1291 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1295 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1296 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1298 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1301 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1302 playlist_t *p_playlist = pl_Yield( p_this );
1305 if( p_playlist->p_input )
1307 var_Get( p_playlist->p_input, "state", &val );
1308 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1310 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1311 vlc_object_release( p_playlist );
1313 return VLC_EGENERIC;
1318 /* Parse commands that require a playlist */
1319 if( !strcmp( psz_cmd, "prev" ) )
1321 playlist_Prev( p_playlist );
1323 else if( !strcmp( psz_cmd, "next" ) )
1325 playlist_Next( p_playlist );
1327 else if( !strcmp( psz_cmd, "play" ) )
1329 msg_Warn( p_playlist, "play" );
1330 playlist_Play( p_playlist );
1332 else if( !strcmp( psz_cmd, "repeat" ) )
1334 bool b_update = true;
1336 var_Get( p_playlist, "repeat", &val );
1338 if( strlen( newval.psz_string ) > 0 )
1340 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1341 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1349 val.b_bool = !val.b_bool;
1350 var_Set( p_playlist, "repeat", val );
1352 msg_rc( "Setting repeat to %d", val.b_bool );
1354 else if( !strcmp( psz_cmd, "loop" ) )
1356 bool b_update = true;
1358 var_Get( p_playlist, "loop", &val );
1360 if( strlen( newval.psz_string ) > 0 )
1362 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1363 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1371 val.b_bool = !val.b_bool;
1372 var_Set( p_playlist, "loop", val );
1374 msg_rc( "Setting loop to %d", val.b_bool );
1376 else if( !strcmp( psz_cmd, "random" ) )
1378 bool b_update = true;
1380 var_Get( p_playlist, "random", &val );
1382 if( strlen( newval.psz_string ) > 0 )
1384 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1385 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1393 val.b_bool = !val.b_bool;
1394 var_Set( p_playlist, "random", val );
1396 msg_rc( "Setting random to %d", val.b_bool );
1398 else if (!strcmp( psz_cmd, "goto" ) )
1400 int i_pos = atoi( newval.psz_string );
1401 /* The playlist stores 2 times the same item: onelevel & category */
1402 int i_size = p_playlist->items.i_size / 2;
1405 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1406 else if( i_pos <= i_size )
1408 playlist_item_t *p_item, *p_parent;
1409 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1410 while( p_parent->p_parent )
1411 p_parent = p_parent->p_parent;
1412 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, true,
1416 msg_rc( _("Playlist has only %d elements"), i_size );
1418 else if( !strcmp( psz_cmd, "stop" ) )
1420 playlist_Stop( p_playlist );
1422 else if( !strcmp( psz_cmd, "clear" ) )
1424 playlist_Stop( p_playlist );
1425 playlist_Clear( p_playlist, false );
1427 else if( !strcmp( psz_cmd, "add" ) &&
1428 newval.psz_string && *newval.psz_string )
1430 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1434 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1435 int i_ret =playlist_AddInput( p_playlist, p_item,
1436 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1438 vlc_gc_decref( p_item );
1439 if( i_ret != VLC_SUCCESS )
1441 return VLC_EGENERIC;
1445 else if( !strcmp( psz_cmd, "enqueue" ) &&
1446 newval.psz_string && *newval.psz_string )
1448 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1452 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1453 if( playlist_AddInput( p_playlist, p_item,
1454 PLAYLIST_APPEND, PLAYLIST_END, true,
1455 false ) != VLC_SUCCESS )
1457 return VLC_EGENERIC;
1461 else if( !strcmp( psz_cmd, "playlist" ) )
1463 msg_rc( "+----[ Playlist ]" );
1464 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1465 msg_rc( "+----[ End of playlist ]" );
1468 else if( !strcmp( psz_cmd, "sort" ))
1470 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1471 SORT_ARTIST, ORDER_NORMAL );
1473 else if( !strcmp( psz_cmd, "status" ) )
1475 if( p_playlist->p_input )
1477 /* Replay the current state of the system. */
1479 input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1480 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1482 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1483 config_GetInt( p_intf, "volume" ));
1486 switch( p_playlist->status.i_status )
1488 case PLAYLIST_STOPPED:
1489 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1491 case PLAYLIST_RUNNING:
1492 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1494 case PLAYLIST_PAUSED:
1495 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1498 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1510 msg_rc( "unknown command!" );
1513 vlc_object_release( p_playlist );
1517 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1518 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1520 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1521 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1522 playlist_t *p_playlist;
1524 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1527 playlist_Stop( p_playlist );
1528 vlc_object_release( p_playlist );
1530 vlc_object_kill( p_this->p_libvlc );
1534 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1535 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1537 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1538 intf_thread_t *p_newintf = NULL;
1540 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1543 if( intf_RunThread( p_newintf ) )
1545 vlc_object_detach( p_newintf );
1546 vlc_object_release( p_newintf );
1553 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1554 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1556 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1557 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1558 input_thread_t *p_input = NULL;
1559 int i_error = VLC_EGENERIC;
1561 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1569 var_Get( p_input, "state", &val );
1570 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1572 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1573 vlc_object_release( p_input );
1574 return VLC_EGENERIC;
1576 vlc_object_release( p_input );
1579 if ( *newval.psz_string )
1582 audio_volume_t i_volume = atoi( newval.psz_string );
1583 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1585 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1587 i_error = VLC_EBADVAR;
1591 if( i_volume == AOUT_VOLUME_MIN )
1595 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1596 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1598 i_error = aout_VolumeSet( p_this, i_volume );
1599 osd_Volume( p_this );
1600 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1606 audio_volume_t i_volume;
1607 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1609 i_error = VLC_EGENERIC;
1613 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1614 i_error = VLC_SUCCESS;
1621 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1622 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1624 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1625 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1626 audio_volume_t i_volume;
1627 input_thread_t *p_input = NULL;
1628 int i_nb_steps = atoi(newval.psz_string);
1629 int i_error = VLC_SUCCESS;
1630 int i_volume_step = 0;
1632 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1640 var_Get( p_input, "state", &val );
1641 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1643 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1644 vlc_object_release( p_input );
1645 return VLC_EGENERIC;
1647 vlc_object_release( p_input );
1650 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1651 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1656 if ( !strcmp(psz_cmd, "volup") )
1658 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1659 i_error = VLC_EGENERIC;
1663 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1664 i_error = VLC_EGENERIC;
1666 osd_Volume( p_this );
1668 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1673 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1674 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1676 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1677 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1678 input_thread_t *p_input = NULL;
1679 vout_thread_t * p_vout;
1680 const char * psz_variable = NULL;
1683 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1687 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1688 vlc_object_release( p_input );
1692 if( !strcmp( psz_cmd, "vcrop" ) )
1694 psz_variable = "crop";
1696 else if( !strcmp( psz_cmd, "vratio" ) )
1698 psz_variable = "aspect-ratio";
1700 else if( !strcmp( psz_cmd, "vzoom" ) )
1702 psz_variable = "zoom";
1704 else if( !strcmp( psz_cmd, "snapshot" ) )
1706 psz_variable = "video-snapshot";
1709 if( newval.psz_string && *newval.psz_string )
1712 if( !strcmp( psz_variable, "zoom" ) )
1715 val.f_float = atof( newval.psz_string );
1716 i_error = var_Set( p_vout, psz_variable, val );
1720 i_error = var_Set( p_vout, psz_variable, newval );
1723 else if( !strcmp( psz_cmd, "snapshot" ) )
1727 i_error = var_Set( p_vout, psz_variable, val );
1732 vlc_value_t val_name;
1733 vlc_value_t val, text;
1736 char *psz_value = NULL;
1738 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1740 vlc_object_release( p_vout );
1741 return VLC_EGENERIC;
1743 if( !strcmp( psz_variable, "zoom" ) )
1745 f_value = val.f_float;
1749 psz_value = strdup( val.psz_string );
1752 if ( var_Change( p_vout, psz_variable,
1753 VLC_VAR_GETLIST, &val, &text ) < 0 )
1755 vlc_object_release( p_vout );
1756 return VLC_EGENERIC;
1759 /* Get the descriptive name of the variable */
1760 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1762 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1764 msg_rc( "+----[ %s ]", val_name.psz_string );
1765 if( !strcmp( psz_variable, "zoom" ) )
1767 for ( i = 0; i < val.p_list->i_count; i++ )
1769 if ( f_value == val.p_list->p_values[i].f_float )
1770 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1771 text.p_list->p_values[i].psz_string );
1773 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1774 text.p_list->p_values[i].psz_string );
1779 for ( i = 0; i < val.p_list->i_count; i++ )
1781 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1782 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1783 text.p_list->p_values[i].psz_string );
1785 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1786 text.p_list->p_values[i].psz_string );
1790 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1792 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1794 free( val_name.psz_string );
1796 i_error = VLC_SUCCESS;
1798 vlc_object_release( p_vout );
1802 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1803 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1805 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1806 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1807 input_thread_t *p_input = NULL;
1808 aout_instance_t * p_aout;
1809 const char * psz_variable;
1810 vlc_value_t val_name;
1813 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1821 var_Get( p_input, "state", &val );
1822 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1823 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1824 vlc_object_release( p_input );
1825 return VLC_EGENERIC;
1827 vlc_object_release( p_input );
1830 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1831 if ( p_aout == NULL ) return VLC_ENOOBJ;
1833 if ( !strcmp( psz_cmd, "adev" ) )
1835 psz_variable = "audio-device";
1839 psz_variable = "audio-channels";
1842 /* Get the descriptive name of the variable */
1843 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1845 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1847 if ( !*newval.psz_string )
1849 /* Retrieve all registered ***. */
1850 vlc_value_t val, text;
1853 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1855 vlc_object_release( (vlc_object_t *)p_aout );
1856 return VLC_EGENERIC;
1858 i_value = val.i_int;
1860 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1861 VLC_VAR_GETLIST, &val, &text ) < 0 )
1863 vlc_object_release( (vlc_object_t *)p_aout );
1864 return VLC_EGENERIC;
1867 msg_rc( "+----[ %s ]", val_name.psz_string );
1868 for ( i = 0; i < val.p_list->i_count; i++ )
1870 if ( i_value == val.p_list->p_values[i].i_int )
1871 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1872 text.p_list->p_values[i].psz_string );
1874 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1875 text.p_list->p_values[i].psz_string );
1877 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1879 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1881 free( val_name.psz_string );
1882 i_error = VLC_SUCCESS;
1887 val.i_int = atoi( newval.psz_string );
1889 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1891 vlc_object_release( (vlc_object_t *)p_aout );
1896 /* OSD menu commands */
1897 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1898 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1900 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1901 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1902 playlist_t *p_playlist = NULL;
1904 int i_error = VLC_EGENERIC;
1906 if ( !*newval.psz_string )
1908 msg_rc( _("Please provide one of the following parameters:") );
1909 msg_rc( "[on|off|up|down|left|right|select]" );
1913 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1917 if( p_playlist->p_input )
1919 var_Get( p_playlist->p_input, "state", &val );
1920 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1921 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1923 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1924 vlc_object_release( p_playlist );
1925 return VLC_EGENERIC;
1928 vlc_object_release( p_playlist );
1930 val.psz_string = strdup( newval.psz_string );
1931 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1932 osd_MenuShow( p_this );
1933 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1934 osd_MenuHide( p_this );
1935 else if( !strcmp( val.psz_string, "up" ) )
1936 osd_MenuUp( p_this );
1937 else if( !strcmp( val.psz_string, "down" ) )
1938 osd_MenuDown( p_this );
1939 else if( !strcmp( val.psz_string, "left" ) )
1940 osd_MenuPrev( p_this );
1941 else if( !strcmp( val.psz_string, "right" ) )
1942 osd_MenuNext( p_this );
1943 else if( !strcmp( val.psz_string, "select" ) )
1944 osd_MenuActivate( p_this );
1947 msg_rc( _("Please provide one of the following parameters:") );
1948 msg_rc( "[on|off|up|down|left|right|select]" );
1949 free( val.psz_string );
1953 i_error = VLC_SUCCESS;
1954 free( val.psz_string );
1958 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1959 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1961 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1962 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1963 input_thread_t *p_input = NULL;
1966 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1970 if( !strcmp( psz_cmd, "stats" ) )
1972 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1973 updateStatistics( p_intf, input_GetItem(p_input) );
1974 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1981 msg_rc(_("Unknown command!") );
1984 vlc_object_release( p_input );
1985 i_error = VLC_SUCCESS;
1989 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1991 if( !p_item ) return VLC_EGENERIC;
1993 vlc_mutex_lock( &p_item->p_stats->lock );
1994 msg_rc( "+----[ begin of statistical info ]" );
1997 msg_rc(_("+-[Incoming]"));
1998 msg_rc(_("| input bytes read : %8.0f kB"),
1999 (float)(p_item->p_stats->i_read_bytes)/1000 );
2000 msg_rc(_("| input bitrate : %6.0f kb/s"),
2001 (float)(p_item->p_stats->f_input_bitrate)*8000 );
2002 msg_rc(_("| demux bytes read : %8.0f kB"),
2003 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
2004 msg_rc(_("| demux bitrate : %6.0f kb/s"),
2005 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
2008 msg_rc(_("+-[Video Decoding]"));
2009 msg_rc(_("| video decoded : %5i"),
2010 p_item->p_stats->i_decoded_video );
2011 msg_rc(_("| frames displayed : %5i"),
2012 p_item->p_stats->i_displayed_pictures );
2013 msg_rc(_("| frames lost : %5i"),
2014 p_item->p_stats->i_lost_pictures );
2017 msg_rc(_("+-[Audio Decoding]"));
2018 msg_rc(_("| audio decoded : %5i"),
2019 p_item->p_stats->i_decoded_audio );
2020 msg_rc(_("| buffers played : %5i"),
2021 p_item->p_stats->i_played_abuffers );
2022 msg_rc(_("| buffers lost : %5i"),
2023 p_item->p_stats->i_lost_abuffers );
2026 msg_rc(_("+-[Streaming]"));
2027 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
2028 msg_rc(_("| bytes sent : %8.0f kB"),
2029 (float)(p_item->p_stats->i_sent_bytes)/1000 );
2030 msg_rc(_("| sending bitrate : %6.0f kb/s"),
2031 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
2033 msg_rc( "+----[ end of statistical info ]" );
2034 vlc_mutex_unlock( &p_item->p_stats->lock );
2040 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2042 INPUT_RECORD input_record;
2045 /* On Win32, select() only works on socket descriptors */
2046 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2047 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2049 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2050 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2053 if( input_record.EventType != KEY_EVENT ||
2054 !input_record.Event.KeyEvent.bKeyDown ||
2055 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2056 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2057 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2058 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2060 /* nothing interesting */
2064 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2066 /* Echo out the command */
2067 putc( p_buffer[ *pi_size ], stdout );
2069 /* Handle special keys */
2070 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2072 putc( '\n', stdout );
2075 switch( p_buffer[ *pi_size ] )
2081 putc( ' ', stdout );
2082 putc( '\b', stdout );
2093 if( *pi_size == MAX_LINE_LENGTH ||
2094 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2096 p_buffer[ *pi_size ] = 0;
2105 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2110 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2111 return ReadWin32( p_intf, p_buffer, pi_size );
2112 else if( p_intf->p_sys->i_socket == -1 )
2114 msleep( INTF_IDLE_SLEEP );
2119 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2120 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2121 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2122 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2124 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2130 /* Connection closed */
2133 if( p_intf->p_sys->i_socket != -1 )
2135 net_Close( p_intf->p_sys->i_socket );
2136 p_intf->p_sys->i_socket = -1;
2140 /* Standard input closed: exit */
2142 Quit( p_intf, NULL, empty, empty, NULL );
2145 p_buffer[ *pi_size ] = 0;
2149 if( *pi_size == MAX_LINE_LENGTH ||
2150 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2152 p_buffer[ *pi_size ] = 0;
2159 /*****************************************************************************
2160 * parse_MRL: build a input item from a full mrl
2161 *****************************************************************************
2162 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2163 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2164 * space is a new option. Should be good enough for our purpose.
2165 *****************************************************************************/
2166 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2168 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2169 #define SKIPTRAILINGSPACE( p, d ) \
2170 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2172 input_item_t *p_item = NULL;
2173 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2174 char **ppsz_options = NULL;
2175 int i, i_options = 0;
2177 if( !psz_mrl ) return 0;
2179 psz_mrl = psz_orig = strdup( psz_mrl );
2182 SKIPSPACE( psz_mrl );
2185 for( ; *psz_mrl; psz_mrl++ )
2187 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2189 /* We have a complete item */
2192 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2193 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2195 /* We have a complete item */
2200 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2201 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2203 /* Remove '"' and '\'' if necessary */
2204 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2205 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2206 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2207 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2209 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2210 else if( *psz_item )
2213 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2214 ppsz_options[i_options - 1] = &psz_item[1];
2217 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2220 /* Now create a playlist item */
2223 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2224 for( i = 0; i < i_options; i++ )
2226 input_ItemAddOption( p_item, ppsz_options[i] );
2230 if( i_options ) free( ppsz_options );