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 */
40 #include <vlc_interface.h>
44 #include <vlc_playlist.h>
51 #ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
54 #include <sys/types.h>
56 #include <vlc_network.h>
59 #include <vlc_charset.h>
61 #if defined(PF_UNIX) && !defined(PF_LOCAL)
62 # define PF_LOCAL PF_UNIX
65 #if defined(AF_LOCAL) && ! defined(WIN32)
69 #define MAX_LINE_LENGTH 1024
70 #define STATUS_CHANGE "status change: "
72 /* input_state_e from <vlc_input.h> */
73 static const char *ppsz_input_state[] = {
74 [INIT_S] = N_("Initializing"),
75 [OPENING_S] = N_("Opening"),
76 [PLAYING_S] = N_("Play"),
77 [PAUSE_S] = N_("Pause"),
79 [ERROR_S] = N_("Error"),
82 /*****************************************************************************
84 *****************************************************************************/
85 static int Activate ( vlc_object_t * );
86 static void Deactivate ( vlc_object_t * );
87 static void Run ( intf_thread_t * );
89 static void Help ( intf_thread_t *, bool );
90 static void RegisterCallbacks( intf_thread_t * );
92 static bool ReadCommand( intf_thread_t *, char *, int * );
94 static input_item_t *parse_MRL( intf_thread_t *, char * );
96 static int Input ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
98 static int Playlist ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int Quit ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int Intf ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int Volume ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int VolumeMove ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int VideoConfig ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
110 static int AudioConfig ( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t, void * );
112 static int Menu ( vlc_object_t *, char const *,
113 vlc_value_t, vlc_value_t, void * );
114 static int Statistics ( vlc_object_t *, char const *,
115 vlc_value_t, vlc_value_t, void * );
117 static int updateStatistics( intf_thread_t *, input_item_t *);
119 /* Status Callbacks */
120 static int VolumeChanged( vlc_object_t *, char const *,
121 vlc_value_t, vlc_value_t, void * );
122 static int InputEvent( vlc_object_t *, char const *,
123 vlc_value_t, vlc_value_t, void * );
127 int *pi_socket_listen;
132 vlc_mutex_t status_lock;
133 playlist_status_t i_last_state;
134 playlist_t *p_playlist;
135 bool b_input_buffering;
143 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
146 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
149 char fmt_eol[strlen (psz_fmt) + 3];
151 snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
152 va_start( args, psz_fmt );
154 if( p_intf->p_sys->i_socket == -1 )
155 utf8_vfprintf( stdout, fmt_eol, args );
157 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
161 /*****************************************************************************
163 *****************************************************************************/
164 #define POS_TEXT N_("Show stream position")
165 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
166 "stream from time to time." )
168 #define TTY_TEXT N_("Fake TTY")
169 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
171 #define UNIX_TEXT N_("UNIX socket command input")
172 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
175 #define HOST_TEXT N_("TCP command input")
176 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
177 "You can set the address and port the interface will bind to." )
180 #define QUIET_TEXT N_("Do not open a DOS command box interface")
181 #define QUIET_LONGTEXT N_( \
182 "By default the rc interface plugin will start a DOS command box. " \
183 "Enabling the quiet mode will not bring this command box but can also " \
184 "be pretty annoying when you want to stop VLC and no video window is " \
189 set_shortname( N_("RC"))
190 set_category( CAT_INTERFACE )
191 set_subcategory( SUBCAT_INTERFACE_MAIN )
192 set_description( N_("Remote control interface") )
193 add_bool( "rc-show-pos", false, NULL, POS_TEXT, POS_LONGTEXT, true )
196 add_bool( "rc-quiet", false, NULL, QUIET_TEXT, QUIET_LONGTEXT, false )
198 #if defined (HAVE_ISATTY)
199 add_bool( "rc-fake-tty", false, NULL, TTY_TEXT, TTY_LONGTEXT, true )
201 add_string( "rc-unix", NULL, NULL, UNIX_TEXT, UNIX_LONGTEXT, true )
203 add_string( "rc-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true )
205 set_capability( "interface", 20 )
207 set_callbacks( Activate, Deactivate )
210 /*****************************************************************************
211 * Activate: initialize and create stuff
212 *****************************************************************************/
213 static int Activate( vlc_object_t *p_this )
215 intf_thread_t *p_intf = (intf_thread_t*)p_this;
216 char *psz_host, *psz_unix_path = NULL;
217 int *pi_socket = NULL;
220 #if defined(HAVE_ISATTY)
221 /* Check that stdin is a TTY */
222 if( !var_InheritInteger( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
224 msg_Warn( p_intf, "fd 0 is not a TTY" );
229 psz_unix_path = var_InheritString( p_intf, "rc-unix" );
235 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
236 free( psz_unix_path );
239 struct sockaddr_un addr;
241 memset( &addr, 0, sizeof(struct sockaddr_un) );
243 msg_Dbg( p_intf, "trying UNIX socket" );
245 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
247 msg_Warn( p_intf, "can't open socket: %m" );
248 free( psz_unix_path );
252 addr.sun_family = AF_LOCAL;
253 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
254 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
256 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
257 && (errno == EADDRINUSE)
258 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
259 && (errno == ECONNREFUSED))
261 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
262 unlink (psz_unix_path);
264 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
266 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
268 free (psz_unix_path);
269 net_Close (i_socket);
274 if( listen( i_socket, 1 ) )
276 msg_Warn( p_intf, "can't listen on socket: %m");
277 free( psz_unix_path );
278 net_Close( i_socket );
282 /* FIXME: we need a core function to merge listening sockets sets */
283 pi_socket = calloc( 2, sizeof( int ) );
284 if( pi_socket == NULL )
286 free( psz_unix_path );
287 net_Close( i_socket );
290 pi_socket[0] = i_socket;
292 #endif /* AF_LOCAL */
296 if( ( pi_socket == NULL ) &&
297 ( psz_host = var_InheritString( p_intf, "rc-host" ) ) != NULL )
301 vlc_UrlParse( &url, psz_host, 0 );
303 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
305 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
306 if( pi_socket == NULL )
308 msg_Warn( p_intf, "can't listen to %s port %i",
309 url.psz_host, url.i_port );
310 vlc_UrlClean( &url );
315 vlc_UrlClean( &url );
319 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
323 p_intf->p_sys->pi_socket_listen = pi_socket;
324 p_intf->p_sys->i_socket = -1;
325 p_intf->p_sys->psz_unix_path = psz_unix_path;
326 vlc_mutex_init( &p_intf->p_sys->status_lock );
327 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
328 p_intf->p_sys->b_input_buffering = false;
330 /* Non-buffered stdout */
331 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
333 p_intf->pf_run = Run;
336 p_intf->p_sys->b_quiet = var_InheritInteger( p_intf, "rc-quiet" );
337 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
342 msg_rc( "%s", _("Remote control interface initialized. Type `help' for help.") );
346 /*****************************************************************************
347 * Deactivate: uninitialize and cleanup
348 *****************************************************************************/
349 static void Deactivate( vlc_object_t *p_this )
351 intf_thread_t *p_intf = (intf_thread_t*)p_this;
353 net_ListenClose( p_intf->p_sys->pi_socket_listen );
354 if( p_intf->p_sys->i_socket != -1 )
355 net_Close( p_intf->p_sys->i_socket );
356 if( p_intf->p_sys->psz_unix_path != NULL )
358 #if defined(AF_LOCAL) && !defined(WIN32)
359 unlink( p_intf->p_sys->psz_unix_path );
361 free( p_intf->p_sys->psz_unix_path );
363 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
364 free( p_intf->p_sys );
367 /*****************************************************************************
368 * RegisterCallbacks: Register callbacks to dynamic variables
369 *****************************************************************************/
370 static void RegisterCallbacks( intf_thread_t *p_intf )
372 /* Register commands that will be cleaned up upon object destruction */
373 #define ADD( name, type, target ) \
374 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
375 var_AddCallback( p_intf, name, target, NULL );
376 ADD( "quit", VOID, Quit )
377 ADD( "intf", STRING, Intf )
379 ADD( "add", STRING, Playlist )
380 ADD( "repeat", STRING, Playlist )
381 ADD( "loop", STRING, Playlist )
382 ADD( "random", STRING, Playlist )
383 ADD( "enqueue", STRING, Playlist )
384 ADD( "playlist", VOID, Playlist )
385 ADD( "sort", VOID, Playlist )
386 ADD( "play", VOID, Playlist )
387 ADD( "stop", VOID, Playlist )
388 ADD( "clear", VOID, Playlist )
389 ADD( "prev", VOID, Playlist )
390 ADD( "next", VOID, Playlist )
391 ADD( "goto", INTEGER, Playlist )
392 ADD( "status", INTEGER, Playlist )
394 /* OSD menu commands */
395 ADD( "menu", STRING, Menu )
398 ADD( "pause", VOID, Input )
399 ADD( "seek", INTEGER, Input )
400 ADD( "title", STRING, Input )
401 ADD( "title_n", VOID, Input )
402 ADD( "title_p", VOID, Input )
403 ADD( "chapter", STRING, Input )
404 ADD( "chapter_n", VOID, Input )
405 ADD( "chapter_p", VOID, Input )
407 ADD( "fastforward", VOID, Input )
408 ADD( "rewind", VOID, Input )
409 ADD( "faster", VOID, Input )
410 ADD( "slower", VOID, Input )
411 ADD( "normal", VOID, Input )
412 ADD( "frame", VOID, Input )
414 ADD( "atrack", STRING, Input )
415 ADD( "vtrack", STRING, Input )
416 ADD( "strack", STRING, Input )
419 ADD( "vratio", STRING, VideoConfig )
420 ADD( "vcrop", STRING, VideoConfig )
421 ADD( "vzoom", STRING, VideoConfig )
422 ADD( "snapshot", VOID, VideoConfig )
425 ADD( "volume", STRING, Volume )
426 ADD( "volup", STRING, VolumeMove )
427 ADD( "voldown", STRING, VolumeMove )
428 ADD( "adev", STRING, AudioConfig )
429 ADD( "achan", STRING, AudioConfig )
431 /* misc menu commands */
432 ADD( "stats", BOOL, Statistics )
437 /*****************************************************************************
439 *****************************************************************************
440 * This part of the interface is in a separate thread so that we can call
441 * exec() from within it without annoying the rest of the program.
442 *****************************************************************************/
443 static void Run( intf_thread_t *p_intf )
445 input_thread_t * p_input = NULL;
446 playlist_t * p_playlist = pl_Hold( p_intf );
448 char p_buffer[ MAX_LINE_LENGTH + 1 ];
449 bool b_showpos = var_InheritInteger( p_intf, "rc-show-pos" );
450 bool b_longhelp = false;
455 int canc = vlc_savecancel();
459 /* Register commands that will be cleaned up upon object destruction */
460 p_intf->p_sys->p_playlist = p_playlist;
461 RegisterCallbacks( p_intf );
463 /* status callbacks */
464 /* Listen to audio volume updates */
465 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
468 /* Get the file descriptor of the console input */
469 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
470 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
472 msg_Err( p_intf, "couldn't find user input handle" );
473 vlc_object_kill( p_intf );
477 while( vlc_object_alive( p_intf ) )
479 char *psz_cmd, *psz_arg;
482 if( p_intf->p_sys->pi_socket_listen != NULL &&
483 p_intf->p_sys->i_socket == -1 )
485 p_intf->p_sys->i_socket =
486 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen );
487 if( p_intf->p_sys->i_socket == -1 ) continue;
490 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
492 /* Manage the input part */
493 if( p_input == NULL )
495 p_input = playlist_CurrentInput( p_playlist );
496 /* New input has been registered */
499 if( !p_input->b_dead || vlc_object_alive (p_input) )
502 input_item_GetURI( input_GetItem( p_input ) );
503 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
505 msg_rc( STATUS_CHANGE "( audio volume: %d )",
506 config_GetInt( p_intf, "volume" ));
508 var_AddCallback( p_input, "intf-event", InputEvent, p_intf );
511 else if( p_input->b_dead )
513 var_DelCallback( p_input, "intf-event", InputEvent, p_intf );
514 vlc_object_release( p_input );
520 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
521 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
526 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
527 (p_playlist != NULL) )
530 int status = playlist_Status( p_playlist );
531 if( p_intf->p_sys->i_last_state != status )
533 if( status == PLAYLIST_STOPPED )
535 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
536 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
538 else if( status == PLAYLIST_RUNNING )
540 p_intf->p_sys->i_last_state = PLAYLIST_RUNNING;
541 msg_rc( STATUS_CHANGE "( play state: 3 )" );
543 else if( status == PLAYLIST_PAUSED )
545 p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
546 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
552 if( p_input && b_showpos )
554 i_newpos = 100 * var_GetFloat( p_input, "position" );
555 if( i_oldpos != i_newpos )
558 msg_rc( "pos: %d%%", i_newpos );
562 /* Is there something to do? */
563 if( !b_complete ) continue;
565 /* Skip heading spaces */
567 while( *psz_cmd == ' ' )
572 /* Split psz_cmd at the first space and make sure that
573 * psz_arg is valid */
574 psz_arg = strchr( psz_cmd, ' ' );
578 while( *psz_arg == ' ' )
588 /* module specfic commands: @<module name> <command> <args...> */
589 if( *psz_cmd == '@' && *psz_arg )
591 /* Parse miscellaneous commands */
592 char *psz_alias = psz_cmd + 1;
593 char *psz_mycmd = strdup( psz_arg );
594 char *psz_myarg = strchr( psz_mycmd, ' ' );
599 msg_rc( "Not enough parameters." );
606 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
611 msg_rc( "%s", psz_msg );
617 /* If the user typed a registered local command, try it */
618 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
623 val.psz_string = psz_arg;
624 i_ret = var_Set( p_intf, psz_cmd, val );
625 msg_rc( "%s: returned %i (%s)",
626 psz_cmd, i_ret, vlc_error( i_ret ) );
628 /* Or maybe it's a global command */
629 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
634 val.psz_string = psz_arg;
635 /* FIXME: it's a global command, but we should pass the
636 * local object as an argument, not p_intf->p_libvlc. */
637 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
640 msg_rc( "%s: returned %i (%s)",
641 psz_cmd, i_ret, vlc_error( i_ret ) );
644 else if( !strcmp( psz_cmd, "logout" ) )
646 /* Close connection */
647 if( p_intf->p_sys->i_socket != -1 )
649 net_Close( p_intf->p_sys->i_socket );
651 p_intf->p_sys->i_socket = -1;
653 else if( !strcmp( psz_cmd, "info" ) )
658 vlc_mutex_lock( &input_GetItem(p_input)->lock );
659 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
661 info_category_t *p_category = input_GetItem(p_input)
664 msg_rc( "+----[ %s ]", p_category->psz_name );
666 for ( j = 0; j < p_category->i_infos; j++ )
668 info_t *p_info = p_category->pp_infos[j];
669 msg_rc( "| %s: %s", p_info->psz_name,
674 msg_rc( "+----[ end of stream info ]" );
675 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
679 msg_rc( "no input" );
682 else if( !strcmp( psz_cmd, "is_playing" ) )
693 else if( !strcmp( psz_cmd, "get_time" ) )
702 var_Get( p_input, "time", &time );
703 msg_rc( "%"PRIu64, time.i_time / 1000000);
706 else if( !strcmp( psz_cmd, "get_length" ) )
715 var_Get( p_input, "length", &time );
716 msg_rc( "%"PRIu64, time.i_time / 1000000);
719 else if( !strcmp( psz_cmd, "get_title" ) )
727 msg_rc( "%s", input_GetItem(p_input)->psz_name );
730 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
731 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
733 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
735 else b_longhelp = false;
737 Help( p_intf, b_longhelp );
739 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
741 var_SetInteger( p_intf->p_libvlc, "key-action",
742 vlc_GetActionId( psz_arg ) );
744 else switch( psz_cmd[0] )
750 vout_thread_t *p_vout;
751 p_vout = input_GetVout( p_input );
756 bool b_update = false;
757 var_Get( p_vout, "fullscreen", &val );
758 val.b_bool = !val.b_bool;
759 if( !strncmp( psz_arg, "on", 2 )
760 && ( val.b_bool == true ) )
765 else if( !strncmp( psz_arg, "off", 3 )
766 && ( val.b_bool == false ) )
771 else if( strncmp( psz_arg, "off", 3 )
772 && strncmp( psz_arg, "on", 2 ) )
774 if( b_update ) var_Set( p_vout, "fullscreen", val );
775 vlc_object_release( p_vout );
786 /* Ignore empty lines */
790 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
794 /* Command processed */
795 i_size = 0; p_buffer[0] = 0;
798 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
799 msg_rc( STATUS_CHANGE "( quit )" );
803 var_DelCallback( p_input, "intf-event", InputEvent, p_intf );
804 vlc_object_release( p_input );
807 pl_Release( p_intf );
809 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
810 vlc_restorecancel( canc );
813 static void Help( intf_thread_t *p_intf, bool b_longhelp)
815 msg_rc("%s", _("+----[ Remote control commands ]"));
817 msg_rc("%s", _("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
818 msg_rc("%s", _("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
819 msg_rc("%s", _("| playlist . . . . . show items currently in playlist"));
820 msg_rc("%s", _("| play . . . . . . . . . . . . . . . . . . play stream"));
821 msg_rc("%s", _("| stop . . . . . . . . . . . . . . . . . . stop stream"));
822 msg_rc("%s", _("| next . . . . . . . . . . . . . . next playlist item"));
823 msg_rc("%s", _("| prev . . . . . . . . . . . . previous playlist item"));
824 msg_rc("%s", _("| goto . . . . . . . . . . . . . . goto item at index"));
825 msg_rc("%s", _("| repeat [on|off] . . . . toggle playlist item repeat"));
826 msg_rc("%s", _("| loop [on|off] . . . . . . . . . toggle playlist loop"));
827 msg_rc("%s", _("| random [on|off] . . . . . . . toggle random jumping"));
828 msg_rc("%s", _("| clear . . . . . . . . . . . . . . clear the playlist"));
829 msg_rc("%s", _("| status . . . . . . . . . . . current playlist status"));
830 msg_rc("%s", _("| title [X] . . . . . . set/get title in current item"));
831 msg_rc("%s", _("| title_n . . . . . . . . next title in current item"));
832 msg_rc("%s", _("| title_p . . . . . . previous title in current item"));
833 msg_rc("%s", _("| chapter [X] . . . . set/get chapter in current item"));
834 msg_rc("%s", _("| chapter_n . . . . . . next chapter in current item"));
835 msg_rc("%s", _("| chapter_p . . . . previous chapter in current item"));
837 msg_rc("%s", _("| seek X . . . seek in seconds, for instance `seek 12'"));
838 msg_rc("%s", _("| pause . . . . . . . . . . . . . . . . toggle pause"));
839 msg_rc("%s", _("| fastforward . . . . . . . . . set to maximum rate"));
840 msg_rc("%s", _("| rewind . . . . . . . . . . . . set to minimum rate"));
841 msg_rc("%s", _("| faster . . . . . . . . . . faster playing of stream"));
842 msg_rc("%s", _("| slower . . . . . . . . . . slower playing of stream"));
843 msg_rc("%s", _("| normal . . . . . . . . . . normal playing of stream"));
844 msg_rc("%s", _("| frame. . . . . . . . . . play frame by frame"));
845 msg_rc("%s", _("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
846 msg_rc("%s", _("| info . . . . . information about the current stream"));
847 msg_rc("%s", _("| stats . . . . . . . . show statistical information"));
848 msg_rc("%s", _("| get_time . . seconds elapsed since stream's beginning"));
849 msg_rc("%s", _("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
850 msg_rc("%s", _("| get_title . . . . . the title of the current stream"));
851 msg_rc("%s", _("| get_length . . . . the length of the current stream"));
853 msg_rc("%s", _("| volume [X] . . . . . . . . . . set/get audio volume"));
854 msg_rc("%s", _("| volup [X] . . . . . . . raise audio volume X steps"));
855 msg_rc("%s", _("| voldown [X] . . . . . . lower audio volume X steps"));
856 msg_rc("%s", _("| adev [X] . . . . . . . . . . . set/get audio device"));
857 msg_rc("%s", _("| achan [X]. . . . . . . . . . set/get audio channels"));
858 msg_rc("%s", _("| atrack [X] . . . . . . . . . . . set/get audio track"));
859 msg_rc("%s", _("| vtrack [X] . . . . . . . . . . . set/get video track"));
860 msg_rc("%s", _("| vratio [X] . . . . . . . set/get video aspect ratio"));
861 msg_rc("%s", _("| vcrop [X] . . . . . . . . . . . set/get video crop"));
862 msg_rc("%s", _("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
863 msg_rc("%s", _("| snapshot . . . . . . . . . . . . take video snapshot"));
864 msg_rc("%s", _("| strack [X] . . . . . . . . . set/get subtitles track"));
865 msg_rc("%s", _("| key [hotkey name] . . . . . . simulate hotkey press"));
866 msg_rc("%s", _("| menu . . [on|off|up|down|left|right|select] use menu"));
871 msg_rc("%s", _("| @name marq-marquee STRING . . overlay STRING in video"));
872 msg_rc("%s", _("| @name marq-x X . . . . . . . . . . . .offset from left"));
873 msg_rc("%s", _("| @name marq-y Y . . . . . . . . . . . . offset from top"));
874 msg_rc("%s", _("| @name marq-position #. . . .relative position control"));
875 msg_rc("%s", _("| @name marq-color # . . . . . . . . . . font color, RGB"));
876 msg_rc("%s", _("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
877 msg_rc("%s", _("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
878 msg_rc("%s", _("| @name marq-size # . . . . . . . . font size, in pixels"));
880 msg_rc("%s", _("| @name logo-file STRING . . .the overlay file path/name"));
881 msg_rc("%s", _("| @name logo-x X . . . . . . . . . . . .offset from left"));
882 msg_rc("%s", _("| @name logo-y Y . . . . . . . . . . . . offset from top"));
883 msg_rc("%s", _("| @name logo-position #. . . . . . . . relative position"));
884 msg_rc("%s", _("| @name logo-transparency #. . . . . . . . .transparency"));
886 msg_rc("%s", _("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
887 msg_rc("%s", _("| @name mosaic-height #. . . . . . . . . . . . . .height"));
888 msg_rc("%s", _("| @name mosaic-width # . . . . . . . . . . . . . . width"));
889 msg_rc("%s", _("| @name mosaic-xoffset # . . . .top left corner position"));
890 msg_rc("%s", _("| @name mosaic-yoffset # . . . .top left corner position"));
891 msg_rc("%s", _("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
892 msg_rc("%s", _("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
893 msg_rc("%s", _("| @name mosaic-vborder # . . . . . . . . vertical border"));
894 msg_rc("%s", _("| @name mosaic-hborder # . . . . . . . horizontal border"));
895 msg_rc("%s", _("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
896 msg_rc("%s", _("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
897 msg_rc("%s", _("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
898 msg_rc("%s", _("| @name mosaic-order id(,id)* . . . . order of pictures "));
899 msg_rc("%s", _("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
902 msg_rc("%s", _("| help . . . . . . . . . . . . . . . this help message"));
903 msg_rc("%s", _("| longhelp . . . . . . . . . . . a longer help message"));
904 msg_rc("%s", _("| logout . . . . . . . exit (if in socket connection)"));
905 msg_rc("%s", _("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
907 msg_rc("%s", _("+----[ end of help ]"));
910 /********************************************************************
911 * Status callback routines
912 ********************************************************************/
913 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
914 vlc_value_t oldval, vlc_value_t newval, void *p_data )
916 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
917 intf_thread_t *p_intf = (intf_thread_t*)p_data;
919 vlc_mutex_lock( &p_intf->p_sys->status_lock );
920 msg_rc( STATUS_CHANGE "( audio volume: %d )",
921 config_GetInt( p_this, "volume") );
922 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
926 static void StateChanged( intf_thread_t *p_intf, input_thread_t *p_input )
928 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
931 const int i_status = playlist_Status( p_playlist );
938 case PLAYLIST_STOPPED:
941 case PLAYLIST_RUNNING:
944 case PLAYLIST_PAUSED:
953 const int i_state = var_GetInteger( p_input, "state" );
955 vlc_mutex_lock( &p_intf->p_sys->status_lock );
956 msg_rc( STATUS_CHANGE "( %s state: %d ): %s", psz_cmd,
957 i_state, ppsz_input_state[i_state] );
958 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
960 static void RateChanged( intf_thread_t *p_intf,
961 input_thread_t *p_input )
963 vlc_mutex_lock( &p_intf->p_sys->status_lock );
964 msg_rc( STATUS_CHANGE "( new rate: %.3f )",
965 var_GetFloat( p_input, "rate" ) );
966 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
968 static void PositionChanged( intf_thread_t *p_intf,
969 input_thread_t *p_input )
971 vlc_mutex_lock( &p_intf->p_sys->status_lock );
972 if( p_intf->p_sys->b_input_buffering )
973 msg_rc( STATUS_CHANGE "( time: %"PRId64"s )",
974 (var_GetTime( p_input, "time" )/1000000) );
975 p_intf->p_sys->b_input_buffering = false;
976 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
978 static void CacheChanged( intf_thread_t *p_intf )
980 vlc_mutex_lock( &p_intf->p_sys->status_lock );
981 p_intf->p_sys->b_input_buffering = true;
982 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
985 static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
986 vlc_value_t oldval, vlc_value_t newval, void *p_data )
990 input_thread_t *p_input = (input_thread_t*)p_this;
991 intf_thread_t *p_intf = p_data;
993 switch( newval.i_int )
995 case INPUT_EVENT_STATE:
996 case INPUT_EVENT_DEAD:
997 StateChanged( p_intf, p_input );
999 case INPUT_EVENT_RATE:
1000 RateChanged( p_intf, p_input );
1002 case INPUT_EVENT_POSITION:
1003 PositionChanged( p_intf, p_input );
1005 case INPUT_EVENT_CACHE:
1006 CacheChanged( p_intf );
1014 /********************************************************************
1016 ********************************************************************/
1017 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1018 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1020 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1021 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1022 input_thread_t *p_input =
1023 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1024 int i_error = VLC_EGENERIC;
1029 int state = var_GetInteger( p_input, "state" );
1030 if( ( state == PAUSE_S ) &&
1031 ( strcmp( psz_cmd, "pause" ) != 0 ) && (strcmp( psz_cmd,"frame") != 0 ) )
1033 msg_rc( "%s", _("Press menu select or pause to continue.") );
1036 /* Parse commands that only require an input */
1037 if( !strcmp( psz_cmd, "pause" ) )
1039 playlist_Pause( p_intf->p_sys->p_playlist );
1040 i_error = VLC_SUCCESS;
1042 else if( !strcmp( psz_cmd, "seek" ) )
1044 if( strlen( newval.psz_string ) > 0 &&
1045 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1047 float f = atof( newval.psz_string ) / 100.0;
1048 var_SetFloat( p_input, "position", f );
1052 mtime_t t = ((int64_t)atoi( newval.psz_string )) * CLOCK_FREQ;
1053 var_SetTime( p_input, "time", t );
1055 i_error = VLC_SUCCESS;
1057 else if ( !strcmp( psz_cmd, "fastforward" ) )
1059 if( var_GetBool( p_input, "can-rate" ) )
1061 float f_rate = var_GetFloat( p_input, "rate" );
1062 f_rate = (f_rate < 0) ? -f_rate : f_rate * 2;
1063 var_SetFloat( p_input, "rate", f_rate );
1067 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_EXTRASHORT );
1069 i_error = VLC_SUCCESS;
1071 else if ( !strcmp( psz_cmd, "rewind" ) )
1073 if( var_GetBool( p_input, "can-rewind" ) )
1075 float f_rate = var_GetFloat( p_input, "rate" );
1076 f_rate = (f_rate > 0) ? -f_rate : f_rate * 2;
1077 var_SetFloat( p_input, "rate", f_rate );
1081 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_EXTRASHORT );
1083 i_error = VLC_SUCCESS;
1085 else if ( !strcmp( psz_cmd, "faster" ) )
1087 var_TriggerCallback( p_input, "rate-faster" );
1088 i_error = VLC_SUCCESS;
1090 else if ( !strcmp( psz_cmd, "slower" ) )
1092 var_TriggerCallback( p_input, "rate-slower" );
1093 i_error = VLC_SUCCESS;
1095 else if ( !strcmp( psz_cmd, "normal" ) )
1097 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
1098 i_error = VLC_SUCCESS;
1100 else if ( !strcmp( psz_cmd, "frame" ) )
1102 var_TriggerCallback( p_input, "frame-next" );
1103 i_error = VLC_SUCCESS;
1105 else if( !strcmp( psz_cmd, "chapter" ) ||
1106 !strcmp( psz_cmd, "chapter_n" ) ||
1107 !strcmp( psz_cmd, "chapter_p" ) )
1109 if( !strcmp( psz_cmd, "chapter" ) )
1111 if ( *newval.psz_string )
1114 var_SetInteger( p_input, "chapter", atoi( newval.psz_string ) );
1119 int i_chap = var_GetInteger( p_input, "chapter" );
1120 int i_chapter_count = var_CountChoices( p_input, "chapter" );
1121 msg_rc( "Currently playing chapter %d/%d.", i_chap,
1125 else if( !strcmp( psz_cmd, "chapter_n" ) )
1126 var_TriggerCallback( p_input, "next-chapter" );
1127 else if( !strcmp( psz_cmd, "chapter_p" ) )
1128 var_TriggerCallback( p_input, "prev-chapter" );
1129 i_error = VLC_SUCCESS;
1131 else if( !strcmp( psz_cmd, "title" ) ||
1132 !strcmp( psz_cmd, "title_n" ) ||
1133 !strcmp( psz_cmd, "title_p" ) )
1135 if( !strcmp( psz_cmd, "title" ) )
1137 if ( *newval.psz_string )
1139 var_SetInteger( p_input, "title", atoi( newval.psz_string ) );
1143 int i_title = var_GetInteger( p_input, "title" );
1144 int i_title_count = var_CountChoices( p_input, "title" );
1145 msg_rc( "Currently playing title %d/%d.", i_title,
1149 else if( !strcmp( psz_cmd, "title_n" ) )
1150 var_TriggerCallback( p_input, "next-title" );
1151 else if( !strcmp( psz_cmd, "title_p" ) )
1152 var_TriggerCallback( p_input, "prev-title" );
1154 i_error = VLC_SUCCESS;
1156 else if( !strcmp( psz_cmd, "atrack" )
1157 || !strcmp( psz_cmd, "vtrack" )
1158 || !strcmp( psz_cmd, "strack" ) )
1160 const char *psz_variable;
1161 vlc_value_t val_name;
1163 if( !strcmp( psz_cmd, "atrack" ) )
1165 psz_variable = "audio-es";
1167 else if( !strcmp( psz_cmd, "vtrack" ) )
1169 psz_variable = "video-es";
1173 psz_variable = "spu-es";
1176 /* Get the descriptive name of the variable */
1177 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1179 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1181 if( newval.psz_string && *newval.psz_string )
1184 i_error = var_SetInteger( p_input, psz_variable,
1185 atoi( newval.psz_string ) );
1190 vlc_value_t val, text;
1193 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1195 i_value = val.i_int;
1197 if ( var_Change( p_input, psz_variable,
1198 VLC_VAR_GETLIST, &val, &text ) < 0 )
1201 msg_rc( "+----[ %s ]", val_name.psz_string );
1202 for ( i = 0; i < val.p_list->i_count; i++ )
1204 if ( i_value == val.p_list->p_values[i].i_int )
1205 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1206 text.p_list->p_values[i].psz_string );
1208 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1209 text.p_list->p_values[i].psz_string );
1211 var_FreeList( &val, &text );
1212 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1214 free( val_name.psz_string );
1218 vlc_object_release( p_input );
1222 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1225 char psz_buffer[MSTRTIME_MAX_SIZE];
1226 for( i = 0; i< p_item->i_children; i++ )
1228 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1230 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1231 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1234 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1236 if( p_item->pp_children[i]->i_children >= 0 )
1237 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1241 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1242 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1244 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1247 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1248 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1249 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1253 int state = var_GetInteger( p_input, "state" );
1254 vlc_object_release( p_input );
1256 if( state == PAUSE_S )
1258 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1259 return VLC_EGENERIC;
1263 /* Parse commands that require a playlist */
1264 if( !strcmp( psz_cmd, "prev" ) )
1266 playlist_Prev( p_playlist );
1268 else if( !strcmp( psz_cmd, "next" ) )
1270 playlist_Next( p_playlist );
1272 else if( !strcmp( psz_cmd, "play" ) )
1274 msg_Warn( p_playlist, "play" );
1275 playlist_Play( p_playlist );
1277 else if( !strcmp( psz_cmd, "repeat" ) )
1279 bool b_update = true;
1281 var_Get( p_playlist, "repeat", &val );
1283 if( strlen( newval.psz_string ) > 0 )
1285 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1286 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1294 val.b_bool = !val.b_bool;
1295 var_Set( p_playlist, "repeat", val );
1297 msg_rc( "Setting repeat to %d", val.b_bool );
1299 else if( !strcmp( psz_cmd, "loop" ) )
1301 bool b_update = true;
1303 var_Get( p_playlist, "loop", &val );
1305 if( strlen( newval.psz_string ) > 0 )
1307 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1308 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1316 val.b_bool = !val.b_bool;
1317 var_Set( p_playlist, "loop", val );
1319 msg_rc( "Setting loop to %d", val.b_bool );
1321 else if( !strcmp( psz_cmd, "random" ) )
1323 bool b_update = true;
1325 var_Get( p_playlist, "random", &val );
1327 if( strlen( newval.psz_string ) > 0 )
1329 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1330 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1338 val.b_bool = !val.b_bool;
1339 var_Set( p_playlist, "random", val );
1341 msg_rc( "Setting random to %d", val.b_bool );
1343 else if (!strcmp( psz_cmd, "goto" ) )
1345 int i_pos = atoi( newval.psz_string );
1346 /* The playlist stores 2 times the same item: onelevel & category */
1347 int i_size = p_playlist->items.i_size / 2;
1350 msg_rc( "%s", _("Error: `goto' needs an argument greater than zero.") );
1351 else if( i_pos <= i_size )
1353 playlist_item_t *p_item, *p_parent;
1354 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1355 while( p_parent->p_parent )
1356 p_parent = p_parent->p_parent;
1357 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1361 msg_rc( _("Playlist has only %d elements"), i_size );
1363 else if( !strcmp( psz_cmd, "stop" ) )
1365 playlist_Stop( p_playlist );
1367 else if( !strcmp( psz_cmd, "clear" ) )
1369 playlist_Stop( p_playlist );
1370 playlist_Clear( p_playlist, pl_Unlocked );
1372 else if( !strcmp( psz_cmd, "add" ) &&
1373 newval.psz_string && *newval.psz_string )
1375 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1379 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1380 int i_ret =playlist_AddInput( p_playlist, p_item,
1381 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1383 vlc_gc_decref( p_item );
1384 if( i_ret != VLC_SUCCESS )
1386 return VLC_EGENERIC;
1390 else if( !strcmp( psz_cmd, "enqueue" ) &&
1391 newval.psz_string && *newval.psz_string )
1393 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1397 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1398 if( playlist_AddInput( p_playlist, p_item,
1399 PLAYLIST_APPEND, PLAYLIST_END, true,
1400 pl_Unlocked ) != VLC_SUCCESS )
1402 return VLC_EGENERIC;
1406 else if( !strcmp( psz_cmd, "playlist" ) )
1408 msg_rc( "+----[ Playlist ]" );
1409 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1410 msg_rc( "+----[ End of playlist ]" );
1413 else if( !strcmp( psz_cmd, "sort" ))
1415 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1416 SORT_ARTIST, ORDER_NORMAL );
1418 else if( !strcmp( psz_cmd, "status" ) )
1420 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1423 /* Replay the current state of the system. */
1425 input_item_GetURI( input_GetItem( p_input ) );
1426 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1428 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1429 config_GetInt( p_intf, "volume" ));
1432 switch( playlist_Status(p_playlist) )
1434 case PLAYLIST_STOPPED:
1435 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1437 case PLAYLIST_RUNNING:
1438 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1440 case PLAYLIST_PAUSED:
1441 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1444 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1448 vlc_object_release( p_input );
1457 msg_rc( "unknown command!" );
1463 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1464 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1466 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1467 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1469 libvlc_Quit( p_this->p_libvlc );
1473 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1474 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1476 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1478 return intf_Create( p_this->p_libvlc, newval.psz_string );
1481 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1482 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1484 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1485 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1486 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1487 input_thread_t *p_input = playlist_CurrentInput( p_playlist );
1488 int i_error = VLC_EGENERIC;
1495 int state = var_GetInteger( p_input, "state" );
1496 vlc_object_release( p_input );
1497 if( state == PAUSE_S )
1499 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1500 return VLC_EGENERIC;
1504 if ( *newval.psz_string )
1507 audio_volume_t i_volume = atoi( newval.psz_string );
1508 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1510 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1512 i_error = VLC_EBADVAR;
1516 if( i_volume == AOUT_VOLUME_MIN )
1517 aout_ToggleMute( p_playlist, NULL );
1518 if( !aout_VolumeSet( p_playlist, i_volume ) )
1519 i_error = VLC_SUCCESS;
1520 osd_Volume( p_this );
1521 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1527 audio_volume_t i_volume;
1528 if ( !aout_VolumeGet( p_playlist, &i_volume ) )
1530 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1531 i_error = VLC_SUCCESS;
1538 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1539 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1541 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1542 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1543 audio_volume_t i_volume;
1544 input_thread_t *p_input =
1545 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1546 int i_nb_steps = atoi(newval.psz_string);
1547 int i_error = VLC_SUCCESS;
1548 int i_volume_step = 0;
1553 int state = var_GetInteger( p_input, "state" );
1554 vlc_object_release( p_input );
1555 if( state == PAUSE_S )
1557 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1558 return VLC_EGENERIC;
1561 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1562 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1567 if ( !strcmp(psz_cmd, "volup") )
1569 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1570 i_error = VLC_EGENERIC;
1574 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1575 i_error = VLC_EGENERIC;
1577 osd_Volume( p_this );
1579 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1584 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1585 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1587 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1588 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1589 input_thread_t *p_input =
1590 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1591 vout_thread_t * p_vout;
1592 const char * psz_variable = NULL;
1593 int i_error = VLC_SUCCESS;
1598 p_vout = input_GetVout( p_input );
1599 vlc_object_release( p_input );
1603 if( !strcmp( psz_cmd, "vcrop" ) )
1605 psz_variable = "crop";
1607 else if( !strcmp( psz_cmd, "vratio" ) )
1609 psz_variable = "aspect-ratio";
1611 else if( !strcmp( psz_cmd, "vzoom" ) )
1613 psz_variable = "zoom";
1615 else if( !strcmp( psz_cmd, "snapshot" ) )
1617 psz_variable = "video-snapshot";
1620 /* This case can't happen */
1623 if( newval.psz_string && *newval.psz_string )
1626 if( !strcmp( psz_variable, "zoom" ) )
1629 val.f_float = atof( newval.psz_string );
1630 i_error = var_Set( p_vout, psz_variable, val );
1634 i_error = var_Set( p_vout, psz_variable, newval );
1637 else if( !strcmp( psz_cmd, "snapshot" ) )
1639 var_TriggerCallback( p_vout, psz_variable );
1644 vlc_value_t val_name;
1645 vlc_value_t val, text;
1648 char *psz_value = NULL;
1650 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1652 vlc_object_release( p_vout );
1653 return VLC_EGENERIC;
1655 if( !strcmp( psz_variable, "zoom" ) )
1657 f_value = val.f_float;
1661 psz_value = val.psz_string;
1664 if ( var_Change( p_vout, psz_variable,
1665 VLC_VAR_GETLIST, &val, &text ) < 0 )
1667 vlc_object_release( p_vout );
1669 return VLC_EGENERIC;
1672 /* Get the descriptive name of the variable */
1673 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1675 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1677 msg_rc( "+----[ %s ]", val_name.psz_string );
1678 if( !strcmp( psz_variable, "zoom" ) )
1680 for ( i = 0; i < val.p_list->i_count; i++ )
1682 if ( f_value == val.p_list->p_values[i].f_float )
1683 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1684 text.p_list->p_values[i].psz_string );
1686 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1687 text.p_list->p_values[i].psz_string );
1692 for ( i = 0; i < val.p_list->i_count; i++ )
1694 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1695 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1696 text.p_list->p_values[i].psz_string );
1698 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1699 text.p_list->p_values[i].psz_string );
1703 var_FreeList( &val, &text );
1704 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1706 free( val_name.psz_string );
1708 vlc_object_release( p_vout );
1712 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1713 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1715 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1716 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1717 input_thread_t *p_input =
1718 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1719 aout_instance_t * p_aout;
1720 const char * psz_variable;
1721 vlc_value_t val_name;
1727 int state = var_GetInteger( p_input, "state" );
1728 if( state == PAUSE_S )
1730 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1731 return VLC_EGENERIC;
1734 p_aout = input_GetAout( p_input );
1735 vlc_object_release( p_input );
1736 if ( p_aout == NULL )
1739 if ( !strcmp( psz_cmd, "adev" ) )
1741 psz_variable = "audio-device";
1745 psz_variable = "audio-channels";
1748 /* Get the descriptive name of the variable */
1749 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1751 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1753 if ( !*newval.psz_string )
1755 /* Retrieve all registered ***. */
1756 vlc_value_t val, text;
1759 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1761 vlc_object_release( (vlc_object_t *)p_aout );
1762 return VLC_EGENERIC;
1764 i_value = val.i_int;
1766 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1767 VLC_VAR_GETLIST, &val, &text ) < 0 )
1769 vlc_object_release( (vlc_object_t *)p_aout );
1770 return VLC_EGENERIC;
1773 msg_rc( "+----[ %s ]", val_name.psz_string );
1774 for ( i = 0; i < val.p_list->i_count; i++ )
1776 if ( i_value == val.p_list->p_values[i].i_int )
1777 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1778 text.p_list->p_values[i].psz_string );
1780 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1781 text.p_list->p_values[i].psz_string );
1783 var_FreeList( &val, &text );
1784 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1786 free( val_name.psz_string );
1787 i_error = VLC_SUCCESS;
1792 val.i_int = atoi( newval.psz_string );
1794 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1796 vlc_object_release( (vlc_object_t *)p_aout );
1801 /* OSD menu commands */
1802 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1803 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1805 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1806 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1807 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1808 int i_error = VLC_SUCCESS;
1811 if ( !*newval.psz_string )
1813 msg_rc( "%s", _("Please provide one of the following parameters:") );
1814 msg_rc( "[on|off|up|down|left|right|select]" );
1815 return VLC_EGENERIC;
1818 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1822 var_Get( p_input, "state", &val );
1823 vlc_object_release( p_input );
1825 if( ( val.i_int == PAUSE_S ) &&
1826 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1828 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1829 return VLC_EGENERIC;
1833 val.psz_string = strdup( newval.psz_string );
1834 if( !val.psz_string )
1836 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1837 osd_MenuShow( p_this );
1838 else if( !strcmp( val.psz_string, "off" )
1839 || !strcmp( val.psz_string, "hide" ) )
1840 osd_MenuHide( p_this );
1841 else if( !strcmp( val.psz_string, "up" ) )
1842 osd_MenuUp( p_this );
1843 else if( !strcmp( val.psz_string, "down" ) )
1844 osd_MenuDown( p_this );
1845 else if( !strcmp( val.psz_string, "left" ) )
1846 osd_MenuPrev( p_this );
1847 else if( !strcmp( val.psz_string, "right" ) )
1848 osd_MenuNext( p_this );
1849 else if( !strcmp( val.psz_string, "select" ) )
1850 osd_MenuActivate( p_this );
1853 msg_rc( "%s", _("Please provide one of the following parameters:") );
1854 msg_rc( "[on|off|up|down|left|right|select]" );
1855 i_error = VLC_EGENERIC;
1858 free( val.psz_string );
1862 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1863 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1865 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1866 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1867 input_thread_t *p_input =
1868 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1873 updateStatistics( p_intf, input_GetItem(p_input) );
1874 vlc_object_release( p_input );
1878 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1880 if( !p_item ) return VLC_EGENERIC;
1882 vlc_mutex_lock( &p_item->lock );
1883 vlc_mutex_lock( &p_item->p_stats->lock );
1884 msg_rc( "+----[ begin of statistical info ]" );
1887 msg_rc("%s", _("+-[Incoming]"));
1888 msg_rc(_("| input bytes read : %8.0f kB"),
1889 (float)(p_item->p_stats->i_read_bytes)/1000 );
1890 msg_rc(_("| input bitrate : %6.0f kb/s"),
1891 (float)(p_item->p_stats->f_input_bitrate)*8000 );
1892 msg_rc(_("| demux bytes read : %8.0f kB"),
1893 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
1894 msg_rc(_("| demux bitrate : %6.0f kb/s"),
1895 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
1896 msg_rc(_("| demux corrupted : %5i"),
1897 p_item->p_stats->i_demux_corrupted );
1898 msg_rc(_("| discontinuities : %5i"),
1899 p_item->p_stats->i_demux_discontinuity );
1902 msg_rc("%s", _("+-[Video Decoding]"));
1903 msg_rc(_("| video decoded : %5i"),
1904 p_item->p_stats->i_decoded_video );
1905 msg_rc(_("| frames displayed : %5i"),
1906 p_item->p_stats->i_displayed_pictures );
1907 msg_rc(_("| frames lost : %5i"),
1908 p_item->p_stats->i_lost_pictures );
1911 msg_rc("%s", _("+-[Audio Decoding]"));
1912 msg_rc(_("| audio decoded : %5i"),
1913 p_item->p_stats->i_decoded_audio );
1914 msg_rc(_("| buffers played : %5i"),
1915 p_item->p_stats->i_played_abuffers );
1916 msg_rc(_("| buffers lost : %5i"),
1917 p_item->p_stats->i_lost_abuffers );
1920 msg_rc("%s", _("+-[Streaming]"));
1921 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
1922 msg_rc(_("| bytes sent : %8.0f kB"),
1923 (float)(p_item->p_stats->i_sent_bytes)/1000 );
1924 msg_rc(_("| sending bitrate : %6.0f kb/s"),
1925 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
1927 msg_rc( "+----[ end of statistical info ]" );
1928 vlc_mutex_unlock( &p_item->p_stats->lock );
1929 vlc_mutex_unlock( &p_item->lock );
1935 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1937 INPUT_RECORD input_record;
1940 /* On Win32, select() only works on socket descriptors */
1941 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1942 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1944 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1945 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1948 if( input_record.EventType != KEY_EVENT ||
1949 !input_record.Event.KeyEvent.bKeyDown ||
1950 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1951 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1952 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1953 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1955 /* nothing interesting */
1959 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1961 /* Echo out the command */
1962 putc( p_buffer[ *pi_size ], stdout );
1964 /* Handle special keys */
1965 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1967 putc( '\n', stdout );
1970 switch( p_buffer[ *pi_size ] )
1976 putc( ' ', stdout );
1977 putc( '\b', stdout );
1988 if( *pi_size == MAX_LINE_LENGTH ||
1989 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1991 p_buffer[ *pi_size ] = 0;
2000 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2005 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2006 return ReadWin32( p_intf, p_buffer, pi_size );
2007 else if( p_intf->p_sys->i_socket == -1 )
2009 msleep( INTF_IDLE_SLEEP );
2014 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2015 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2016 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2017 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2019 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2025 /* Connection closed */
2028 if( p_intf->p_sys->i_socket != -1 )
2030 net_Close( p_intf->p_sys->i_socket );
2031 p_intf->p_sys->i_socket = -1;
2035 /* Standard input closed: exit */
2037 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2040 p_buffer[ *pi_size ] = 0;
2044 if( *pi_size == MAX_LINE_LENGTH ||
2045 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2047 p_buffer[ *pi_size ] = 0;
2054 /*****************************************************************************
2055 * parse_MRL: build a input item from a full mrl
2056 *****************************************************************************
2057 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2058 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2059 * space is a new option. Should be good enough for our purpose.
2060 *****************************************************************************/
2061 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2063 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2064 #define SKIPTRAILINGSPACE( p, d ) \
2065 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2067 input_item_t *p_item = NULL;
2068 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2069 char **ppsz_options = NULL;
2070 int i, i_options = 0;
2072 if( !psz_mrl ) return 0;
2074 psz_mrl = psz_orig = strdup( psz_mrl );
2077 SKIPSPACE( psz_mrl );
2080 for( ; *psz_mrl; psz_mrl++ )
2082 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2084 /* We have a complete item */
2087 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2088 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2090 /* We have a complete item */
2095 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2096 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2098 /* Remove '"' and '\'' if necessary */
2099 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2100 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2101 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2102 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2104 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2105 else if( *psz_item )
2108 ppsz_options = xrealloc( ppsz_options, i_options * sizeof(char *) );
2109 ppsz_options[i_options - 1] = &psz_item[1];
2112 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2115 /* Now create a playlist item */
2118 p_item = input_item_New( p_intf, psz_item_mrl, NULL );
2119 for( i = 0; i < i_options; i++ )
2121 input_item_AddOption( p_item, ppsz_options[i], VLC_INPUT_OPTION_TRUSTED );
2125 if( i_options ) free( ppsz_options );