1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2009 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_common.h>
34 #include <vlc_plugin.h>
36 #include <errno.h> /* ENOMEM */
41 #include <vlc_interface.h>
45 #include <vlc_playlist.h>
52 #ifdef HAVE_SYS_TIME_H
53 # include <sys/time.h>
55 #include <sys/types.h>
57 #include <vlc_network.h>
60 #include <vlc_charset.h>
62 #if defined(PF_UNIX) && !defined(PF_LOCAL)
63 # define PF_LOCAL PF_UNIX
66 #if defined(AF_LOCAL) && ! defined(WIN32)
70 #define MAX_LINE_LENGTH 1024
71 #define STATUS_CHANGE "status change: "
73 /* input_state_e from <vlc_input.h> */
74 static const char *ppsz_input_state[] = {
75 [INIT_S] = N_("Initializing"),
76 [OPENING_S] = N_("Opening"),
77 [PLAYING_S] = N_("Play"),
78 [PAUSE_S] = N_("Pause"),
80 [ERROR_S] = N_("Error"),
83 /*****************************************************************************
85 *****************************************************************************/
86 static int Activate ( vlc_object_t * );
87 static void Deactivate ( vlc_object_t * );
88 static void Run ( intf_thread_t * );
90 static void Help ( intf_thread_t *, bool );
91 static void RegisterCallbacks( intf_thread_t * );
93 static bool ReadCommand( intf_thread_t *, char *, int * );
95 static input_item_t *parse_MRL( intf_thread_t *, char * );
97 static int Input ( vlc_object_t *, char const *,
98 vlc_value_t, vlc_value_t, void * );
99 static int Playlist ( vlc_object_t *, char const *,
100 vlc_value_t, vlc_value_t, void * );
101 static int Quit ( vlc_object_t *, char const *,
102 vlc_value_t, vlc_value_t, void * );
103 static int Intf ( vlc_object_t *, char const *,
104 vlc_value_t, vlc_value_t, void * );
105 static int Volume ( vlc_object_t *, char const *,
106 vlc_value_t, vlc_value_t, void * );
107 static int VolumeMove ( vlc_object_t *, char const *,
108 vlc_value_t, vlc_value_t, void * );
109 static int VideoConfig ( vlc_object_t *, char const *,
110 vlc_value_t, vlc_value_t, void * );
111 static int AudioConfig ( vlc_object_t *, char const *,
112 vlc_value_t, vlc_value_t, void * );
113 static int Menu ( vlc_object_t *, char const *,
114 vlc_value_t, vlc_value_t, void * );
115 static int Statistics ( vlc_object_t *, char const *,
116 vlc_value_t, vlc_value_t, void * );
118 static int updateStatistics( intf_thread_t *, input_item_t *);
120 /* Status Callbacks */
121 static int TimeOffsetChanged( vlc_object_t *, char const *,
122 vlc_value_t, vlc_value_t , void * );
123 static int VolumeChanged ( vlc_object_t *, char const *,
124 vlc_value_t, vlc_value_t, void * );
125 static int StateChanged ( vlc_object_t *, char const *,
126 vlc_value_t, vlc_value_t, void * );
127 static int RateChanged ( vlc_object_t *, char const *,
128 vlc_value_t, vlc_value_t, void * );
132 int *pi_socket_listen;
137 vlc_mutex_t status_lock;
138 playlist_status_t i_last_state;
139 playlist_t *p_playlist;
147 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
150 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
153 char fmt_eol[strlen (psz_fmt) + 3];
155 snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
156 va_start( args, psz_fmt );
158 if( p_intf->p_sys->i_socket == -1 )
159 utf8_vfprintf( stdout, fmt_eol, args );
161 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
165 /*****************************************************************************
167 *****************************************************************************/
168 #define POS_TEXT N_("Show stream position")
169 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
170 "stream from time to time." )
172 #define TTY_TEXT N_("Fake TTY")
173 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
175 #define UNIX_TEXT N_("UNIX socket command input")
176 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
179 #define HOST_TEXT N_("TCP command input")
180 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
181 "You can set the address and port the interface will bind to." )
184 #define QUIET_TEXT N_("Do not open a DOS command box interface")
185 #define QUIET_LONGTEXT N_( \
186 "By default the rc interface plugin will start a DOS command box. " \
187 "Enabling the quiet mode will not bring this command box but can also " \
188 "be pretty annoying when you want to stop VLC and no video window is " \
193 set_shortname( N_("RC"))
194 set_category( CAT_INTERFACE )
195 set_subcategory( SUBCAT_INTERFACE_MAIN )
196 set_description( N_("Remote control interface") )
197 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, true )
200 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, false )
202 #if defined (HAVE_ISATTY)
203 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, true )
205 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, true )
207 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, true )
209 set_capability( "interface", 20 )
211 set_callbacks( Activate, Deactivate )
214 /*****************************************************************************
215 * Activate: initialize and create stuff
216 *****************************************************************************/
217 static int Activate( vlc_object_t *p_this )
219 intf_thread_t *p_intf = (intf_thread_t*)p_this;
220 char *psz_host, *psz_unix_path = NULL;
221 int *pi_socket = NULL;
224 #if defined(HAVE_ISATTY)
225 /* Check that stdin is a TTY */
226 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
228 msg_Warn( p_intf, "fd 0 is not a TTY" );
233 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
239 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
240 free( psz_unix_path );
243 struct sockaddr_un addr;
245 memset( &addr, 0, sizeof(struct sockaddr_un) );
247 msg_Dbg( p_intf, "trying UNIX socket" );
249 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
251 msg_Warn( p_intf, "can't open socket: %m" );
252 free( psz_unix_path );
256 addr.sun_family = AF_LOCAL;
257 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
258 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
260 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
261 && (errno == EADDRINUSE)
262 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
263 && (errno == ECONNREFUSED))
265 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
266 unlink (psz_unix_path);
268 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
270 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
272 free (psz_unix_path);
273 net_Close (i_socket);
278 if( listen( i_socket, 1 ) )
280 msg_Warn( p_intf, "can't listen on socket: %m");
281 free( psz_unix_path );
282 net_Close( i_socket );
286 /* FIXME: we need a core function to merge listening sockets sets */
287 pi_socket = calloc( 2, sizeof( int ) );
288 if( pi_socket == NULL )
290 free( psz_unix_path );
291 net_Close( i_socket );
294 pi_socket[0] = i_socket;
296 #endif /* AF_LOCAL */
300 if( ( pi_socket == NULL ) &&
301 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
305 vlc_UrlParse( &url, psz_host, 0 );
307 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
309 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
310 if( pi_socket == NULL )
312 msg_Warn( p_intf, "can't listen to %s port %i",
313 url.psz_host, url.i_port );
314 vlc_UrlClean( &url );
319 vlc_UrlClean( &url );
323 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
327 p_intf->p_sys->pi_socket_listen = pi_socket;
328 p_intf->p_sys->i_socket = -1;
329 p_intf->p_sys->psz_unix_path = psz_unix_path;
330 vlc_mutex_init( &p_intf->p_sys->status_lock );
331 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
333 /* Non-buffered stdout */
334 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
336 p_intf->pf_run = Run;
339 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
340 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
345 msg_rc( "%s", _("Remote control interface initialized. Type `help' for help.") );
349 /*****************************************************************************
350 * Deactivate: uninitialize and cleanup
351 *****************************************************************************/
352 static void Deactivate( vlc_object_t *p_this )
354 intf_thread_t *p_intf = (intf_thread_t*)p_this;
356 net_ListenClose( p_intf->p_sys->pi_socket_listen );
357 if( p_intf->p_sys->i_socket != -1 )
358 net_Close( p_intf->p_sys->i_socket );
359 if( p_intf->p_sys->psz_unix_path != NULL )
361 #if defined(AF_LOCAL) && !defined(WIN32)
362 unlink( p_intf->p_sys->psz_unix_path );
364 free( p_intf->p_sys->psz_unix_path );
366 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
367 free( p_intf->p_sys );
370 /*****************************************************************************
371 * RegisterCallbacks: Register callbacks to dynamic variables
372 *****************************************************************************/
373 static void RegisterCallbacks( intf_thread_t *p_intf )
375 /* Register commands that will be cleaned up upon object destruction */
376 #define ADD( name, type, target ) \
377 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
378 var_AddCallback( p_intf, name, target, NULL );
379 ADD( "quit", VOID, Quit )
380 ADD( "intf", STRING, Intf )
382 ADD( "add", STRING, Playlist )
383 ADD( "repeat", STRING, Playlist )
384 ADD( "loop", STRING, Playlist )
385 ADD( "random", STRING, Playlist )
386 ADD( "enqueue", STRING, Playlist )
387 ADD( "playlist", VOID, Playlist )
388 ADD( "sort", VOID, Playlist )
389 ADD( "play", VOID, Playlist )
390 ADD( "stop", VOID, Playlist )
391 ADD( "clear", VOID, Playlist )
392 ADD( "prev", VOID, Playlist )
393 ADD( "next", VOID, Playlist )
394 ADD( "goto", INTEGER, Playlist )
395 ADD( "status", INTEGER, Playlist )
397 /* OSD menu commands */
398 ADD( "menu", STRING, Menu )
401 ADD( "pause", VOID, Input )
402 ADD( "seek", INTEGER, Input )
403 ADD( "title", STRING, Input )
404 ADD( "title_n", VOID, Input )
405 ADD( "title_p", VOID, Input )
406 ADD( "chapter", STRING, Input )
407 ADD( "chapter_n", VOID, Input )
408 ADD( "chapter_p", VOID, Input )
410 ADD( "fastforward", VOID, Input )
411 ADD( "rewind", VOID, Input )
412 ADD( "faster", VOID, Input )
413 ADD( "slower", VOID, Input )
414 ADD( "normal", VOID, Input )
415 ADD( "frame", VOID, Input )
417 ADD( "atrack", STRING, Input )
418 ADD( "vtrack", STRING, Input )
419 ADD( "strack", STRING, Input )
422 ADD( "vratio", STRING, VideoConfig )
423 ADD( "vcrop", STRING, VideoConfig )
424 ADD( "vzoom", STRING, VideoConfig )
425 ADD( "snapshot", VOID, VideoConfig )
428 ADD( "volume", STRING, Volume )
429 ADD( "volup", STRING, VolumeMove )
430 ADD( "voldown", STRING, VolumeMove )
431 ADD( "adev", STRING, AudioConfig )
432 ADD( "achan", STRING, AudioConfig )
434 /* misc menu commands */
435 ADD( "stats", BOOL, Statistics )
440 /*****************************************************************************
442 *****************************************************************************
443 * This part of the interface is in a separate thread so that we can call
444 * exec() from within it without annoying the rest of the program.
445 *****************************************************************************/
446 static void Run( intf_thread_t *p_intf )
448 input_thread_t * p_input = NULL;
449 playlist_t * p_playlist = pl_Hold( p_intf );
451 char p_buffer[ MAX_LINE_LENGTH + 1 ];
452 bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
453 bool b_longhelp = false;
458 int canc = vlc_savecancel();
462 /* Register commands that will be cleaned up upon object destruction */
463 p_intf->p_sys->p_playlist = p_playlist;
464 RegisterCallbacks( p_intf );
466 /* status callbacks */
467 /* Listen to audio volume updates */
468 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
471 /* Get the file descriptor of the console input */
472 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
473 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
475 msg_Err( p_intf, "couldn't find user input handle" );
476 vlc_object_kill( p_intf );
480 while( vlc_object_alive( p_intf ) )
482 char *psz_cmd, *psz_arg;
485 if( p_intf->p_sys->pi_socket_listen != NULL &&
486 p_intf->p_sys->i_socket == -1 )
488 p_intf->p_sys->i_socket =
489 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
491 if( p_intf->p_sys->i_socket == -1 ) continue;
494 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
496 /* Manage the input part */
497 if( p_input == NULL )
499 p_input = playlist_CurrentInput( p_playlist );
500 /* New input has been registered */
503 if( !p_input->b_dead || vlc_object_alive (p_input) )
506 input_item_GetURI( input_GetItem( p_input ) );
507 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
509 msg_rc( STATUS_CHANGE "( audio volume: %d )",
510 config_GetInt( p_intf, "volume" ));
512 var_AddCallback( p_input, "state", StateChanged, p_intf );
513 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
514 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
515 var_AddCallback( p_input, "rate", RateChanged, p_intf );
516 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
518 var_AddCallback( p_input, "frame-next", RateChanged, p_intf );
521 else if( p_input->b_dead )
523 var_DelCallback( p_input, "state", StateChanged, p_intf );
524 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
525 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
526 var_DelCallback( p_input, "rate", RateChanged, p_intf );
527 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
529 var_DelCallback( p_input, "frame-next", RateChanged, p_intf );
530 vlc_object_release( p_input );
536 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
537 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
542 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
543 (p_playlist != NULL) )
546 int status = playlist_Status( p_playlist );
547 if( p_intf->p_sys->i_last_state != status )
549 if( status == PLAYLIST_STOPPED )
551 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
552 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
554 else if( status == PLAYLIST_RUNNING )
556 p_intf->p_sys->i_last_state = PLAYLIST_RUNNING;
557 msg_rc( STATUS_CHANGE "( play state: 3 )" );
559 else if( status == PLAYLIST_PAUSED )
561 p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
562 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
568 if( p_input && b_showpos )
570 i_newpos = 100 * var_GetFloat( p_input, "position" );
571 if( i_oldpos != i_newpos )
574 msg_rc( "pos: %d%%", i_newpos );
578 /* Is there something to do? */
579 if( !b_complete ) continue;
581 /* Skip heading spaces */
583 while( *psz_cmd == ' ' )
588 /* Split psz_cmd at the first space and make sure that
589 * psz_arg is valid */
590 psz_arg = strchr( psz_cmd, ' ' );
594 while( *psz_arg == ' ' )
604 /* module specfic commands: @<module name> <command> <args...> */
605 if( *psz_cmd == '@' && *psz_arg )
607 /* Parse miscellaneous commands */
608 char *psz_alias = psz_cmd + 1;
609 char *psz_mycmd = strdup( psz_arg );
610 char *psz_myarg = strchr( psz_mycmd, ' ' );
615 msg_rc( "Not enough parameters." );
622 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
627 msg_rc( "%s", psz_msg );
633 /* If the user typed a registered local command, try it */
634 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
639 val.psz_string = psz_arg;
640 i_ret = var_Set( p_intf, psz_cmd, val );
641 msg_rc( "%s: returned %i (%s)",
642 psz_cmd, i_ret, vlc_error( i_ret ) );
644 /* Or maybe it's a global command */
645 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
650 val.psz_string = psz_arg;
651 /* FIXME: it's a global command, but we should pass the
652 * local object as an argument, not p_intf->p_libvlc. */
653 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
656 msg_rc( "%s: returned %i (%s)",
657 psz_cmd, i_ret, vlc_error( i_ret ) );
660 else if( !strcmp( psz_cmd, "logout" ) )
662 /* Close connection */
663 if( p_intf->p_sys->i_socket != -1 )
665 net_Close( p_intf->p_sys->i_socket );
667 p_intf->p_sys->i_socket = -1;
669 else if( !strcmp( psz_cmd, "info" ) )
674 vlc_mutex_lock( &input_GetItem(p_input)->lock );
675 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
677 info_category_t *p_category = input_GetItem(p_input)
680 msg_rc( "+----[ %s ]", p_category->psz_name );
682 for ( j = 0; j < p_category->i_infos; j++ )
684 info_t *p_info = p_category->pp_infos[j];
685 msg_rc( "| %s: %s", p_info->psz_name,
690 msg_rc( "+----[ end of stream info ]" );
691 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
695 msg_rc( "no input" );
698 else if( !strcmp( psz_cmd, "is_playing" ) )
709 else if( !strcmp( psz_cmd, "get_time" ) )
718 var_Get( p_input, "time", &time );
719 msg_rc( "%"PRIu64, time.i_time / 1000000);
722 else if( !strcmp( psz_cmd, "get_length" ) )
731 var_Get( p_input, "length", &time );
732 msg_rc( "%"PRIu64, time.i_time / 1000000);
735 else if( !strcmp( psz_cmd, "get_title" ) )
743 msg_rc( "%s", input_GetItem(p_input)->psz_name );
746 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
747 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
749 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
751 else b_longhelp = false;
753 Help( p_intf, b_longhelp );
755 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
757 var_SetInteger( p_intf->p_libvlc, "key-pressed",
758 config_GetInt( p_intf, psz_arg ) );
760 else switch( psz_cmd[0] )
766 vout_thread_t *p_vout;
767 p_vout = input_GetVout( p_input );
772 bool b_update = false;
773 var_Get( p_vout, "fullscreen", &val );
774 val.b_bool = !val.b_bool;
775 if( !strncmp( psz_arg, "on", 2 )
776 && ( val.b_bool == true ) )
781 else if( !strncmp( psz_arg, "off", 3 )
782 && ( val.b_bool == false ) )
787 else if( strncmp( psz_arg, "off", 3 )
788 && strncmp( psz_arg, "on", 2 ) )
790 if( b_update ) var_Set( p_vout, "fullscreen", val );
791 vlc_object_release( p_vout );
802 /* Ignore empty lines */
806 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
810 /* Command processed */
811 i_size = 0; p_buffer[0] = 0;
814 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
815 msg_rc( STATUS_CHANGE "( quit )" );
819 var_DelCallback( p_input, "state", StateChanged, p_intf );
820 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
821 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
822 var_DelCallback( p_input, "rate", RateChanged, p_intf );
823 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
824 var_DelCallback( p_input, "frame-next", RateChanged, p_intf );
825 vlc_object_release( p_input );
828 pl_Release( p_intf );
830 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
831 vlc_restorecancel( canc );
834 static void Help( intf_thread_t *p_intf, bool b_longhelp)
836 msg_rc("%s", _("+----[ Remote control commands ]"));
838 msg_rc("%s", _("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
839 msg_rc("%s", _("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
840 msg_rc("%s", _("| playlist . . . . . show items currently in playlist"));
841 msg_rc("%s", _("| play . . . . . . . . . . . . . . . . . . play stream"));
842 msg_rc("%s", _("| stop . . . . . . . . . . . . . . . . . . stop stream"));
843 msg_rc("%s", _("| next . . . . . . . . . . . . . . next playlist item"));
844 msg_rc("%s", _("| prev . . . . . . . . . . . . previous playlist item"));
845 msg_rc("%s", _("| goto . . . . . . . . . . . . . . goto item at index"));
846 msg_rc("%s", _("| repeat [on|off] . . . . toggle playlist item repeat"));
847 msg_rc("%s", _("| loop [on|off] . . . . . . . . . toggle playlist loop"));
848 msg_rc("%s", _("| random [on|off] . . . . . . . toggle random jumping"));
849 msg_rc("%s", _("| clear . . . . . . . . . . . . . . clear the playlist"));
850 msg_rc("%s", _("| status . . . . . . . . . . . current playlist status"));
851 msg_rc("%s", _("| title [X] . . . . . . set/get title in current item"));
852 msg_rc("%s", _("| title_n . . . . . . . . next title in current item"));
853 msg_rc("%s", _("| title_p . . . . . . previous title in current item"));
854 msg_rc("%s", _("| chapter [X] . . . . set/get chapter in current item"));
855 msg_rc("%s", _("| chapter_n . . . . . . next chapter in current item"));
856 msg_rc("%s", _("| chapter_p . . . . previous chapter in current item"));
858 msg_rc("%s", _("| seek X . . . seek in seconds, for instance `seek 12'"));
859 msg_rc("%s", _("| pause . . . . . . . . . . . . . . . . toggle pause"));
860 msg_rc("%s", _("| fastforward . . . . . . . . . set to maximum rate"));
861 msg_rc("%s", _("| rewind . . . . . . . . . . . . set to minimum rate"));
862 msg_rc("%s", _("| faster . . . . . . . . . . faster playing of stream"));
863 msg_rc("%s", _("| slower . . . . . . . . . . slower playing of stream"));
864 msg_rc("%s", _("| normal . . . . . . . . . . normal playing of stream"));
865 msg_rc("%s", _("| frame. . . . . . . . . . play frame by frame"));
866 msg_rc("%s", _("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
867 msg_rc("%s", _("| info . . . . . information about the current stream"));
868 msg_rc("%s", _("| stats . . . . . . . . show statistical information"));
869 msg_rc("%s", _("| get_time . . seconds elapsed since stream's beginning"));
870 msg_rc("%s", _("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
871 msg_rc("%s", _("| get_title . . . . . the title of the current stream"));
872 msg_rc("%s", _("| get_length . . . . the length of the current stream"));
874 msg_rc("%s", _("| volume [X] . . . . . . . . . . set/get audio volume"));
875 msg_rc("%s", _("| volup [X] . . . . . . . raise audio volume X steps"));
876 msg_rc("%s", _("| voldown [X] . . . . . . lower audio volume X steps"));
877 msg_rc("%s", _("| adev [X] . . . . . . . . . . . set/get audio device"));
878 msg_rc("%s", _("| achan [X]. . . . . . . . . . set/get audio channels"));
879 msg_rc("%s", _("| atrack [X] . . . . . . . . . . . set/get audio track"));
880 msg_rc("%s", _("| vtrack [X] . . . . . . . . . . . set/get video track"));
881 msg_rc("%s", _("| vratio [X] . . . . . . . set/get video aspect ratio"));
882 msg_rc("%s", _("| vcrop [X] . . . . . . . . . . . set/get video crop"));
883 msg_rc("%s", _("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
884 msg_rc("%s", _("| snapshot . . . . . . . . . . . . take video snapshot"));
885 msg_rc("%s", _("| strack [X] . . . . . . . . . set/get subtitles track"));
886 msg_rc("%s", _("| key [hotkey name] . . . . . . simulate hotkey press"));
887 msg_rc("%s", _("| menu . . [on|off|up|down|left|right|select] use menu"));
892 msg_rc("%s", _("| @name marq-marquee STRING . . overlay STRING in video"));
893 msg_rc("%s", _("| @name marq-x X . . . . . . . . . . . .offset from left"));
894 msg_rc("%s", _("| @name marq-y Y . . . . . . . . . . . . offset from top"));
895 msg_rc("%s", _("| @name marq-position #. . . .relative position control"));
896 msg_rc("%s", _("| @name marq-color # . . . . . . . . . . font color, RGB"));
897 msg_rc("%s", _("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
898 msg_rc("%s", _("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
899 msg_rc("%s", _("| @name marq-size # . . . . . . . . font size, in pixels"));
901 msg_rc("%s", _("| @name logo-file STRING . . .the overlay file path/name"));
902 msg_rc("%s", _("| @name logo-x X . . . . . . . . . . . .offset from left"));
903 msg_rc("%s", _("| @name logo-y Y . . . . . . . . . . . . offset from top"));
904 msg_rc("%s", _("| @name logo-position #. . . . . . . . relative position"));
905 msg_rc("%s", _("| @name logo-transparency #. . . . . . . . .transparency"));
907 msg_rc("%s", _("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
908 msg_rc("%s", _("| @name mosaic-height #. . . . . . . . . . . . . .height"));
909 msg_rc("%s", _("| @name mosaic-width # . . . . . . . . . . . . . . width"));
910 msg_rc("%s", _("| @name mosaic-xoffset # . . . .top left corner position"));
911 msg_rc("%s", _("| @name mosaic-yoffset # . . . .top left corner position"));
912 msg_rc("%s", _("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
913 msg_rc("%s", _("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
914 msg_rc("%s", _("| @name mosaic-vborder # . . . . . . . . vertical border"));
915 msg_rc("%s", _("| @name mosaic-hborder # . . . . . . . horizontal border"));
916 msg_rc("%s", _("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
917 msg_rc("%s", _("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
918 msg_rc("%s", _("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
919 msg_rc("%s", _("| @name mosaic-order id(,id)* . . . . order of pictures "));
920 msg_rc("%s", _("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
923 msg_rc("%s", _("| help . . . . . . . . . . . . . . . this help message"));
924 msg_rc("%s", _("| longhelp . . . . . . . . . . . a longer help message"));
925 msg_rc("%s", _("| logout . . . . . . . exit (if in socket connection)"));
926 msg_rc("%s", _("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
928 msg_rc("%s", _("+----[ end of help ]"));
931 /********************************************************************
932 * Status callback routines
933 ********************************************************************/
934 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
935 vlc_value_t oldval, vlc_value_t newval, void *p_data )
937 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
938 VLC_UNUSED(oldval); VLC_UNUSED(newval);
939 intf_thread_t *p_intf = (intf_thread_t*)p_data;
940 input_thread_t *p_input =
941 playlist_CurrentInput( p_intf->p_sys->p_playlist );
945 vlc_mutex_lock( &p_intf->p_sys->status_lock );
946 msg_rc( STATUS_CHANGE "( time-offset: %"PRId64"s )",
947 (var_GetTime( p_input, "time-offset" )/1000000) );
948 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
949 vlc_object_release( p_input );
954 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
955 vlc_value_t oldval, vlc_value_t newval, void *p_data )
957 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
958 intf_thread_t *p_intf = (intf_thread_t*)p_data;
960 vlc_mutex_lock( &p_intf->p_sys->status_lock );
961 msg_rc( STATUS_CHANGE "( audio volume: %d )",
962 config_GetInt( p_this, "volume") );
963 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
967 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
968 vlc_value_t oldval, vlc_value_t newval, void *p_data )
970 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
971 intf_thread_t *p_intf = (intf_thread_t*)p_data;
972 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
977 i_status = playlist_Status( p_playlist );
982 case PLAYLIST_STOPPED:
983 strcpy( cmd, "stop" );
985 case PLAYLIST_RUNNING:
986 strcpy( cmd, "play" );
988 case PLAYLIST_PAUSED:
989 strcpy( cmd, "pause" );
993 } /* var_GetInteger( p_input, "state" ) */
994 vlc_mutex_lock( &p_intf->p_sys->status_lock );
995 msg_rc( STATUS_CHANGE "( %s state: %d ): %s", cmd, newval.i_int,
996 ppsz_input_state[ newval.i_int ] );
998 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1002 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1003 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1005 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
1006 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1007 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1008 input_thread_t *p_input = playlist_CurrentInput( p_intf->p_sys->p_playlist );
1012 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1013 msg_rc( STATUS_CHANGE "( new rate: %d )",
1014 var_GetInteger( p_input, "rate" ) );
1015 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1016 vlc_object_release( p_input );
1021 /********************************************************************
1023 ********************************************************************/
1024 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1025 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1027 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1028 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1029 input_thread_t *p_input =
1030 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1031 int i_error = VLC_EGENERIC;
1036 int state = var_GetInteger( p_input, "state" );
1037 if( ( state == PAUSE_S ) &&
1038 ( strcmp( psz_cmd, "pause" ) != 0 ) && (strcmp( psz_cmd,"frame") != 0 ) )
1040 msg_rc( "%s", _("Press menu select or pause to continue.") );
1043 /* Parse commands that only require an input */
1044 if( !strcmp( psz_cmd, "pause" ) )
1046 playlist_Pause( p_intf->p_sys->p_playlist );
1047 i_error = VLC_SUCCESS;
1049 else if( !strcmp( psz_cmd, "seek" ) )
1051 if( strlen( newval.psz_string ) > 0 &&
1052 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1054 float f = atof( newval.psz_string ) / 100.0;
1055 var_SetFloat( p_input, "position", f );
1059 mtime_t t = ((int64_t)atoi( newval.psz_string )) * CLOCK_FREQ;
1060 var_SetTime( p_input, "time", t );
1062 i_error = VLC_SUCCESS;
1064 else if ( !strcmp( psz_cmd, "fastforward" ) )
1066 if( var_GetBool( p_input, "can-rate" ) )
1068 int i_rate = var_GetInteger( p_input, "rate" );
1069 i_rate = (i_rate < 0) ? -i_rate : i_rate * 2;
1070 var_SetInteger( p_input, "rate", i_rate );
1074 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_EXTRASHORT );
1076 i_error = VLC_SUCCESS;
1078 else if ( !strcmp( psz_cmd, "rewind" ) )
1080 if( var_GetBool( p_input, "can-rewind" ) )
1082 int i_rate = var_GetInteger( p_input, "rate" );
1083 i_rate = (i_rate > 0) ? -i_rate : i_rate / 2;
1084 var_SetInteger( p_input, "rate", i_rate );
1088 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_EXTRASHORT );
1090 i_error = VLC_SUCCESS;
1092 else if ( !strcmp( psz_cmd, "faster" ) )
1094 var_TriggerCallback( p_input, "rate-faster" );
1095 i_error = VLC_SUCCESS;
1097 else if ( !strcmp( psz_cmd, "slower" ) )
1099 var_TriggerCallback( p_input, "rate-slower" );
1100 i_error = VLC_SUCCESS;
1102 else if ( !strcmp( psz_cmd, "normal" ) )
1104 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
1105 i_error = VLC_SUCCESS;
1107 else if ( !strcmp( psz_cmd, "frame" ) )
1109 var_TriggerCallback( p_input, "frame-next" );
1110 i_error = VLC_SUCCESS;
1112 else if( !strcmp( psz_cmd, "chapter" ) ||
1113 !strcmp( psz_cmd, "chapter_n" ) ||
1114 !strcmp( psz_cmd, "chapter_p" ) )
1116 if( !strcmp( psz_cmd, "chapter" ) )
1118 if ( *newval.psz_string )
1121 var_SetInteger( p_input, "chapter", atoi( newval.psz_string ) );
1126 int i_chap = var_GetInteger( p_input, "chapter" );
1127 int i_chapter_count = var_CountChoices( p_input, "chapter" );
1128 msg_rc( "Currently playing chapter %d/%d.", i_chap,
1132 else if( !strcmp( psz_cmd, "chapter_n" ) )
1133 var_TriggerCallback( p_input, "next-chapter" );
1134 else if( !strcmp( psz_cmd, "chapter_p" ) )
1135 var_TriggerCallback( p_input, "prev-chapter" );
1136 i_error = VLC_SUCCESS;
1138 else if( !strcmp( psz_cmd, "title" ) ||
1139 !strcmp( psz_cmd, "title_n" ) ||
1140 !strcmp( psz_cmd, "title_p" ) )
1142 if( !strcmp( psz_cmd, "title" ) )
1144 if ( *newval.psz_string )
1146 var_SetInteger( p_input, "title", atoi( newval.psz_string ) );
1150 int i_title = var_GetInteger( p_input, "title" );
1151 int i_title_count = var_CountChoices( p_input, "title" );
1152 msg_rc( "Currently playing title %d/%d.", i_title,
1156 else if( !strcmp( psz_cmd, "title_n" ) )
1157 var_TriggerCallback( p_input, "next-title" );
1158 else if( !strcmp( psz_cmd, "title_p" ) )
1159 var_TriggerCallback( p_input, "prev-title" );
1161 i_error = VLC_SUCCESS;
1163 else if( !strcmp( psz_cmd, "atrack" )
1164 || !strcmp( psz_cmd, "vtrack" )
1165 || !strcmp( psz_cmd, "strack" ) )
1167 const char *psz_variable;
1168 vlc_value_t val_name;
1170 if( !strcmp( psz_cmd, "atrack" ) )
1172 psz_variable = "audio-es";
1174 else if( !strcmp( psz_cmd, "vtrack" ) )
1176 psz_variable = "video-es";
1180 psz_variable = "spu-es";
1183 /* Get the descriptive name of the variable */
1184 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1186 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1188 if( newval.psz_string && *newval.psz_string )
1191 i_error = var_SetInteger( p_input, psz_variable,
1192 atoi( newval.psz_string ) );
1197 vlc_value_t val, text;
1200 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1202 i_value = val.i_int;
1204 if ( var_Change( p_input, psz_variable,
1205 VLC_VAR_GETLIST, &val, &text ) < 0 )
1208 msg_rc( "+----[ %s ]", val_name.psz_string );
1209 for ( i = 0; i < val.p_list->i_count; i++ )
1211 if ( i_value == val.p_list->p_values[i].i_int )
1212 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1213 text.p_list->p_values[i].psz_string );
1215 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1216 text.p_list->p_values[i].psz_string );
1218 var_FreeList( &val, &text );
1219 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1221 free( val_name.psz_string );
1225 vlc_object_release( p_input );
1229 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1232 char psz_buffer[MSTRTIME_MAX_SIZE];
1233 for( i = 0; i< p_item->i_children; i++ )
1235 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1237 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1238 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1241 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1243 if( p_item->pp_children[i]->i_children >= 0 )
1244 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1248 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1249 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1251 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1254 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1255 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1256 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1260 int state = var_GetInteger( p_input, "state" );
1261 vlc_object_release( p_input );
1263 if( state == PAUSE_S )
1265 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1266 return VLC_EGENERIC;
1270 /* Parse commands that require a playlist */
1271 if( !strcmp( psz_cmd, "prev" ) )
1273 playlist_Prev( p_playlist );
1275 else if( !strcmp( psz_cmd, "next" ) )
1277 playlist_Next( p_playlist );
1279 else if( !strcmp( psz_cmd, "play" ) )
1281 msg_Warn( p_playlist, "play" );
1282 playlist_Play( p_playlist );
1284 else if( !strcmp( psz_cmd, "repeat" ) )
1286 bool b_update = true;
1288 var_Get( p_playlist, "repeat", &val );
1290 if( strlen( newval.psz_string ) > 0 )
1292 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1293 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1301 val.b_bool = !val.b_bool;
1302 var_Set( p_playlist, "repeat", val );
1304 msg_rc( "Setting repeat to %d", val.b_bool );
1306 else if( !strcmp( psz_cmd, "loop" ) )
1308 bool b_update = true;
1310 var_Get( p_playlist, "loop", &val );
1312 if( strlen( newval.psz_string ) > 0 )
1314 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1315 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1323 val.b_bool = !val.b_bool;
1324 var_Set( p_playlist, "loop", val );
1326 msg_rc( "Setting loop to %d", val.b_bool );
1328 else if( !strcmp( psz_cmd, "random" ) )
1330 bool b_update = true;
1332 var_Get( p_playlist, "random", &val );
1334 if( strlen( newval.psz_string ) > 0 )
1336 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1337 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1345 val.b_bool = !val.b_bool;
1346 var_Set( p_playlist, "random", val );
1348 msg_rc( "Setting random to %d", val.b_bool );
1350 else if (!strcmp( psz_cmd, "goto" ) )
1352 int i_pos = atoi( newval.psz_string );
1353 /* The playlist stores 2 times the same item: onelevel & category */
1354 int i_size = p_playlist->items.i_size / 2;
1357 msg_rc( "%s", _("Error: `goto' needs an argument greater than zero.") );
1358 else if( i_pos <= i_size )
1360 playlist_item_t *p_item, *p_parent;
1361 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1362 while( p_parent->p_parent )
1363 p_parent = p_parent->p_parent;
1364 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1368 msg_rc( _("Playlist has only %d elements"), i_size );
1370 else if( !strcmp( psz_cmd, "stop" ) )
1372 playlist_Stop( p_playlist );
1374 else if( !strcmp( psz_cmd, "clear" ) )
1376 playlist_Stop( p_playlist );
1377 playlist_Clear( p_playlist, pl_Unlocked );
1379 else if( !strcmp( psz_cmd, "add" ) &&
1380 newval.psz_string && *newval.psz_string )
1382 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1386 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1387 int i_ret =playlist_AddInput( p_playlist, p_item,
1388 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1390 vlc_gc_decref( p_item );
1391 if( i_ret != VLC_SUCCESS )
1393 return VLC_EGENERIC;
1397 else if( !strcmp( psz_cmd, "enqueue" ) &&
1398 newval.psz_string && *newval.psz_string )
1400 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1404 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1405 if( playlist_AddInput( p_playlist, p_item,
1406 PLAYLIST_APPEND, PLAYLIST_END, true,
1407 pl_Unlocked ) != VLC_SUCCESS )
1409 return VLC_EGENERIC;
1413 else if( !strcmp( psz_cmd, "playlist" ) )
1415 msg_rc( "+----[ Playlist ]" );
1416 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1417 msg_rc( "+----[ End of playlist ]" );
1420 else if( !strcmp( psz_cmd, "sort" ))
1422 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1423 SORT_ARTIST, ORDER_NORMAL );
1425 else if( !strcmp( psz_cmd, "status" ) )
1427 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1430 /* Replay the current state of the system. */
1432 input_item_GetURI( input_GetItem( p_input ) );
1433 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1435 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1436 config_GetInt( p_intf, "volume" ));
1439 switch( playlist_Status(p_playlist) )
1441 case PLAYLIST_STOPPED:
1442 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1444 case PLAYLIST_RUNNING:
1445 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1447 case PLAYLIST_PAUSED:
1448 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1451 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1455 vlc_object_release( p_input );
1464 msg_rc( "unknown command!" );
1470 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1471 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1473 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1474 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1476 libvlc_Quit( p_this->p_libvlc );
1480 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1481 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1483 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1485 return intf_Create( p_this->p_libvlc, newval.psz_string );
1488 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1489 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1491 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1492 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1493 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1494 input_thread_t *p_input = playlist_CurrentInput( p_playlist );
1495 int i_error = VLC_EGENERIC;
1502 int state = var_GetInteger( p_input, "state" );
1503 vlc_object_release( p_input );
1504 if( state == PAUSE_S )
1506 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1507 return VLC_EGENERIC;
1511 if ( *newval.psz_string )
1514 audio_volume_t i_volume = atoi( newval.psz_string );
1515 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1517 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1519 i_error = VLC_EBADVAR;
1523 if( i_volume == AOUT_VOLUME_MIN )
1524 aout_ToggleMute( p_playlist, NULL );
1525 if( !aout_VolumeSet( p_playlist, i_volume ) )
1526 i_error = VLC_SUCCESS;
1527 osd_Volume( p_this );
1528 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1534 audio_volume_t i_volume;
1535 if ( !aout_VolumeGet( p_playlist, &i_volume ) )
1537 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1538 i_error = VLC_SUCCESS;
1545 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1546 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1548 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1549 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1550 audio_volume_t i_volume;
1551 input_thread_t *p_input =
1552 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1553 int i_nb_steps = atoi(newval.psz_string);
1554 int i_error = VLC_SUCCESS;
1555 int i_volume_step = 0;
1560 int state = var_GetInteger( p_input, "state" );
1561 vlc_object_release( p_input );
1562 if( state == PAUSE_S )
1564 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1565 return VLC_EGENERIC;
1568 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1569 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1574 if ( !strcmp(psz_cmd, "volup") )
1576 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1577 i_error = VLC_EGENERIC;
1581 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1582 i_error = VLC_EGENERIC;
1584 osd_Volume( p_this );
1586 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1591 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1592 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1594 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1595 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1596 input_thread_t *p_input =
1597 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1598 vout_thread_t * p_vout;
1599 const char * psz_variable = NULL;
1605 p_vout = input_GetVout( p_input );
1606 vlc_object_release( p_input );
1610 if( !strcmp( psz_cmd, "vcrop" ) )
1612 psz_variable = "crop";
1614 else if( !strcmp( psz_cmd, "vratio" ) )
1616 psz_variable = "aspect-ratio";
1618 else if( !strcmp( psz_cmd, "vzoom" ) )
1620 psz_variable = "zoom";
1622 else if( !strcmp( psz_cmd, "snapshot" ) )
1624 psz_variable = "video-snapshot";
1627 /* This case can't happen */
1630 if( newval.psz_string && *newval.psz_string )
1633 if( !strcmp( psz_variable, "zoom" ) )
1636 val.f_float = atof( newval.psz_string );
1637 i_error = var_Set( p_vout, psz_variable, val );
1641 i_error = var_Set( p_vout, psz_variable, newval );
1644 else if( !strcmp( psz_cmd, "snapshot" ) )
1646 i_error = var_SetBool( p_vout, psz_variable, true );
1651 vlc_value_t val_name;
1652 vlc_value_t val, text;
1655 char *psz_value = NULL;
1657 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1659 vlc_object_release( p_vout );
1660 return VLC_EGENERIC;
1662 if( !strcmp( psz_variable, "zoom" ) )
1664 f_value = val.f_float;
1668 psz_value = val.psz_string;
1671 if ( var_Change( p_vout, psz_variable,
1672 VLC_VAR_GETLIST, &val, &text ) < 0 )
1674 vlc_object_release( p_vout );
1676 return VLC_EGENERIC;
1679 /* Get the descriptive name of the variable */
1680 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1682 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1684 msg_rc( "+----[ %s ]", val_name.psz_string );
1685 if( !strcmp( psz_variable, "zoom" ) )
1687 for ( i = 0; i < val.p_list->i_count; i++ )
1689 if ( f_value == val.p_list->p_values[i].f_float )
1690 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1691 text.p_list->p_values[i].psz_string );
1693 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1694 text.p_list->p_values[i].psz_string );
1699 for ( i = 0; i < val.p_list->i_count; i++ )
1701 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1702 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1703 text.p_list->p_values[i].psz_string );
1705 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1706 text.p_list->p_values[i].psz_string );
1710 var_FreeList( &val, &text );
1711 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1713 free( val_name.psz_string );
1715 i_error = VLC_SUCCESS;
1717 vlc_object_release( p_vout );
1721 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1722 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1724 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1725 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1726 input_thread_t *p_input =
1727 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1728 aout_instance_t * p_aout;
1729 const char * psz_variable;
1730 vlc_value_t val_name;
1736 int state = var_GetInteger( p_input, "state" );
1737 if( state == PAUSE_S )
1739 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1740 return VLC_EGENERIC;
1743 p_aout = input_GetAout( p_input );
1744 vlc_object_release( p_input );
1745 if ( p_aout == NULL )
1748 if ( !strcmp( psz_cmd, "adev" ) )
1750 psz_variable = "audio-device";
1754 psz_variable = "audio-channels";
1757 /* Get the descriptive name of the variable */
1758 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1760 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1762 if ( !*newval.psz_string )
1764 /* Retrieve all registered ***. */
1765 vlc_value_t val, text;
1768 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1770 vlc_object_release( (vlc_object_t *)p_aout );
1771 return VLC_EGENERIC;
1773 i_value = val.i_int;
1775 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1776 VLC_VAR_GETLIST, &val, &text ) < 0 )
1778 vlc_object_release( (vlc_object_t *)p_aout );
1779 return VLC_EGENERIC;
1782 msg_rc( "+----[ %s ]", val_name.psz_string );
1783 for ( i = 0; i < val.p_list->i_count; i++ )
1785 if ( i_value == val.p_list->p_values[i].i_int )
1786 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1787 text.p_list->p_values[i].psz_string );
1789 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1790 text.p_list->p_values[i].psz_string );
1792 var_FreeList( &val, &text );
1793 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1795 free( val_name.psz_string );
1796 i_error = VLC_SUCCESS;
1801 val.i_int = atoi( newval.psz_string );
1803 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1805 vlc_object_release( (vlc_object_t *)p_aout );
1810 /* OSD menu commands */
1811 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1812 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1814 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1815 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1816 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1817 int i_error = VLC_SUCCESS;
1820 if ( !*newval.psz_string )
1822 msg_rc( "%s", _("Please provide one of the following parameters:") );
1823 msg_rc( "[on|off|up|down|left|right|select]" );
1824 return VLC_EGENERIC;
1827 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1831 var_Get( p_input, "state", &val );
1832 vlc_object_release( p_input );
1834 if( ( val.i_int == PAUSE_S ) &&
1835 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1837 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1838 return VLC_EGENERIC;
1842 val.psz_string = strdup( newval.psz_string );
1843 if( !val.psz_string )
1845 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1846 osd_MenuShow( p_this );
1847 else if( !strcmp( val.psz_string, "off" )
1848 || !strcmp( val.psz_string, "hide" ) )
1849 osd_MenuHide( p_this );
1850 else if( !strcmp( val.psz_string, "up" ) )
1851 osd_MenuUp( p_this );
1852 else if( !strcmp( val.psz_string, "down" ) )
1853 osd_MenuDown( p_this );
1854 else if( !strcmp( val.psz_string, "left" ) )
1855 osd_MenuPrev( p_this );
1856 else if( !strcmp( val.psz_string, "right" ) )
1857 osd_MenuNext( p_this );
1858 else if( !strcmp( val.psz_string, "select" ) )
1859 osd_MenuActivate( p_this );
1862 msg_rc( "%s", _("Please provide one of the following parameters:") );
1863 msg_rc( "[on|off|up|down|left|right|select]" );
1864 i_error = VLC_EGENERIC;
1867 free( val.psz_string );
1871 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1872 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1874 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1875 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1876 input_thread_t *p_input =
1877 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1882 if( !strcmp( psz_cmd, "stats" ) )
1884 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1885 updateStatistics( p_intf, input_GetItem(p_input) );
1886 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1893 msg_rc("%s", _("Unknown command!") );
1896 vlc_object_release( p_input );
1900 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1902 if( !p_item ) return VLC_EGENERIC;
1904 vlc_mutex_lock( &p_item->p_stats->lock );
1905 msg_rc( "+----[ begin of statistical info ]" );
1908 msg_rc("%s", _("+-[Incoming]"));
1909 msg_rc(_("| input bytes read : %8.0f kB"),
1910 (float)(p_item->p_stats->i_read_bytes)/1000 );
1911 msg_rc(_("| input bitrate : %6.0f kb/s"),
1912 (float)(p_item->p_stats->f_input_bitrate)*8000 );
1913 msg_rc(_("| demux bytes read : %8.0f kB"),
1914 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
1915 msg_rc(_("| demux bitrate : %6.0f kb/s"),
1916 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
1919 msg_rc("%s", _("+-[Video Decoding]"));
1920 msg_rc(_("| video decoded : %5i"),
1921 p_item->p_stats->i_decoded_video );
1922 msg_rc(_("| frames displayed : %5i"),
1923 p_item->p_stats->i_displayed_pictures );
1924 msg_rc(_("| frames lost : %5i"),
1925 p_item->p_stats->i_lost_pictures );
1928 msg_rc("%s", _("+-[Audio Decoding]"));
1929 msg_rc(_("| audio decoded : %5i"),
1930 p_item->p_stats->i_decoded_audio );
1931 msg_rc(_("| buffers played : %5i"),
1932 p_item->p_stats->i_played_abuffers );
1933 msg_rc(_("| buffers lost : %5i"),
1934 p_item->p_stats->i_lost_abuffers );
1937 msg_rc("%s", _("+-[Streaming]"));
1938 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
1939 msg_rc(_("| bytes sent : %8.0f kB"),
1940 (float)(p_item->p_stats->i_sent_bytes)/1000 );
1941 msg_rc(_("| sending bitrate : %6.0f kb/s"),
1942 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
1944 msg_rc( "+----[ end of statistical info ]" );
1945 vlc_mutex_unlock( &p_item->p_stats->lock );
1951 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1953 INPUT_RECORD input_record;
1956 /* On Win32, select() only works on socket descriptors */
1957 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1958 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1960 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1961 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1964 if( input_record.EventType != KEY_EVENT ||
1965 !input_record.Event.KeyEvent.bKeyDown ||
1966 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1967 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1968 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1969 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1971 /* nothing interesting */
1975 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1977 /* Echo out the command */
1978 putc( p_buffer[ *pi_size ], stdout );
1980 /* Handle special keys */
1981 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1983 putc( '\n', stdout );
1986 switch( p_buffer[ *pi_size ] )
1992 putc( ' ', stdout );
1993 putc( '\b', stdout );
2004 if( *pi_size == MAX_LINE_LENGTH ||
2005 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2007 p_buffer[ *pi_size ] = 0;
2016 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2021 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2022 return ReadWin32( p_intf, p_buffer, pi_size );
2023 else if( p_intf->p_sys->i_socket == -1 )
2025 msleep( INTF_IDLE_SLEEP );
2030 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2031 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2032 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2033 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2035 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2041 /* Connection closed */
2044 if( p_intf->p_sys->i_socket != -1 )
2046 net_Close( p_intf->p_sys->i_socket );
2047 p_intf->p_sys->i_socket = -1;
2051 /* Standard input closed: exit */
2053 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2056 p_buffer[ *pi_size ] = 0;
2060 if( *pi_size == MAX_LINE_LENGTH ||
2061 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2063 p_buffer[ *pi_size ] = 0;
2070 /*****************************************************************************
2071 * parse_MRL: build a input item from a full mrl
2072 *****************************************************************************
2073 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2074 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2075 * space is a new option. Should be good enough for our purpose.
2076 *****************************************************************************/
2077 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2079 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2080 #define SKIPTRAILINGSPACE( p, d ) \
2081 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2083 input_item_t *p_item = NULL;
2084 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2085 char **ppsz_options = NULL;
2086 int i, i_options = 0;
2088 if( !psz_mrl ) return 0;
2090 psz_mrl = psz_orig = strdup( psz_mrl );
2093 SKIPSPACE( psz_mrl );
2096 for( ; *psz_mrl; psz_mrl++ )
2098 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2100 /* We have a complete item */
2103 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2104 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2106 /* We have a complete item */
2111 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2112 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2114 /* Remove '"' and '\'' if necessary */
2115 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2116 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2117 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2118 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2120 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2121 else if( *psz_item )
2124 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2125 ppsz_options[i_options - 1] = &psz_item[1];
2128 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2131 /* Now create a playlist item */
2134 p_item = input_item_New( p_intf, psz_item_mrl, NULL );
2135 for( i = 0; i < i_options; i++ )
2137 input_item_AddOption( p_item, ppsz_options[i], VLC_INPUT_OPTION_TRUSTED );
2141 if( i_options ) free( ppsz_options );