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 VolumeChanged( vlc_object_t *, char const *,
122 vlc_value_t, vlc_value_t, void * );
123 static int InputEvent( vlc_object_t *, char const *,
124 vlc_value_t, vlc_value_t, void * );
128 int *pi_socket_listen;
133 vlc_mutex_t status_lock;
134 playlist_status_t i_last_state;
135 playlist_t *p_playlist;
136 bool b_input_buffering;
144 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
147 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
150 char fmt_eol[strlen (psz_fmt) + 3];
152 snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
153 va_start( args, psz_fmt );
155 if( p_intf->p_sys->i_socket == -1 )
156 utf8_vfprintf( stdout, fmt_eol, args );
158 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
162 /*****************************************************************************
164 *****************************************************************************/
165 #define POS_TEXT N_("Show stream position")
166 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
167 "stream from time to time." )
169 #define TTY_TEXT N_("Fake TTY")
170 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
172 #define UNIX_TEXT N_("UNIX socket command input")
173 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
176 #define HOST_TEXT N_("TCP command input")
177 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
178 "You can set the address and port the interface will bind to." )
181 #define QUIET_TEXT N_("Do not open a DOS command box interface")
182 #define QUIET_LONGTEXT N_( \
183 "By default the rc interface plugin will start a DOS command box. " \
184 "Enabling the quiet mode will not bring this command box but can also " \
185 "be pretty annoying when you want to stop VLC and no video window is " \
190 set_shortname( N_("RC"))
191 set_category( CAT_INTERFACE )
192 set_subcategory( SUBCAT_INTERFACE_MAIN )
193 set_description( N_("Remote control interface") )
194 add_bool( "rc-show-pos", false, NULL, POS_TEXT, POS_LONGTEXT, true )
197 add_bool( "rc-quiet", false, NULL, QUIET_TEXT, QUIET_LONGTEXT, false )
199 #if defined (HAVE_ISATTY)
200 add_bool( "rc-fake-tty", false, NULL, TTY_TEXT, TTY_LONGTEXT, true )
202 add_string( "rc-unix", NULL, NULL, UNIX_TEXT, UNIX_LONGTEXT, true )
204 add_string( "rc-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true )
206 set_capability( "interface", 20 )
208 set_callbacks( Activate, Deactivate )
211 /*****************************************************************************
212 * Activate: initialize and create stuff
213 *****************************************************************************/
214 static int Activate( vlc_object_t *p_this )
216 intf_thread_t *p_intf = (intf_thread_t*)p_this;
217 char *psz_host, *psz_unix_path = NULL;
218 int *pi_socket = NULL;
221 #if defined(HAVE_ISATTY)
222 /* Check that stdin is a TTY */
223 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
225 msg_Warn( p_intf, "fd 0 is not a TTY" );
230 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
236 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
237 free( psz_unix_path );
240 struct sockaddr_un addr;
242 memset( &addr, 0, sizeof(struct sockaddr_un) );
244 msg_Dbg( p_intf, "trying UNIX socket" );
246 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
248 msg_Warn( p_intf, "can't open socket: %m" );
249 free( psz_unix_path );
253 addr.sun_family = AF_LOCAL;
254 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
255 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
257 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
258 && (errno == EADDRINUSE)
259 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
260 && (errno == ECONNREFUSED))
262 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
263 unlink (psz_unix_path);
265 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
267 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
269 free (psz_unix_path);
270 net_Close (i_socket);
275 if( listen( i_socket, 1 ) )
277 msg_Warn( p_intf, "can't listen on socket: %m");
278 free( psz_unix_path );
279 net_Close( i_socket );
283 /* FIXME: we need a core function to merge listening sockets sets */
284 pi_socket = calloc( 2, sizeof( int ) );
285 if( pi_socket == NULL )
287 free( psz_unix_path );
288 net_Close( i_socket );
291 pi_socket[0] = i_socket;
293 #endif /* AF_LOCAL */
297 if( ( pi_socket == NULL ) &&
298 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
302 vlc_UrlParse( &url, psz_host, 0 );
304 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
306 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
307 if( pi_socket == NULL )
309 msg_Warn( p_intf, "can't listen to %s port %i",
310 url.psz_host, url.i_port );
311 vlc_UrlClean( &url );
316 vlc_UrlClean( &url );
320 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
324 p_intf->p_sys->pi_socket_listen = pi_socket;
325 p_intf->p_sys->i_socket = -1;
326 p_intf->p_sys->psz_unix_path = psz_unix_path;
327 vlc_mutex_init( &p_intf->p_sys->status_lock );
328 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
329 p_intf->p_sys->b_input_buffering = false;
331 /* Non-buffered stdout */
332 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
334 p_intf->pf_run = Run;
337 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
338 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
343 msg_rc( "%s", _("Remote control interface initialized. Type `help' for help.") );
347 /*****************************************************************************
348 * Deactivate: uninitialize and cleanup
349 *****************************************************************************/
350 static void Deactivate( vlc_object_t *p_this )
352 intf_thread_t *p_intf = (intf_thread_t*)p_this;
354 net_ListenClose( p_intf->p_sys->pi_socket_listen );
355 if( p_intf->p_sys->i_socket != -1 )
356 net_Close( p_intf->p_sys->i_socket );
357 if( p_intf->p_sys->psz_unix_path != NULL )
359 #if defined(AF_LOCAL) && !defined(WIN32)
360 unlink( p_intf->p_sys->psz_unix_path );
362 free( p_intf->p_sys->psz_unix_path );
364 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
365 free( p_intf->p_sys );
368 /*****************************************************************************
369 * RegisterCallbacks: Register callbacks to dynamic variables
370 *****************************************************************************/
371 static void RegisterCallbacks( intf_thread_t *p_intf )
373 /* Register commands that will be cleaned up upon object destruction */
374 #define ADD( name, type, target ) \
375 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
376 var_AddCallback( p_intf, name, target, NULL );
377 ADD( "quit", VOID, Quit )
378 ADD( "intf", STRING, Intf )
380 ADD( "add", STRING, Playlist )
381 ADD( "repeat", STRING, Playlist )
382 ADD( "loop", STRING, Playlist )
383 ADD( "random", STRING, Playlist )
384 ADD( "enqueue", STRING, Playlist )
385 ADD( "playlist", VOID, Playlist )
386 ADD( "sort", VOID, Playlist )
387 ADD( "play", VOID, Playlist )
388 ADD( "stop", VOID, Playlist )
389 ADD( "clear", VOID, Playlist )
390 ADD( "prev", VOID, Playlist )
391 ADD( "next", VOID, Playlist )
392 ADD( "goto", INTEGER, Playlist )
393 ADD( "status", INTEGER, Playlist )
395 /* OSD menu commands */
396 ADD( "menu", STRING, Menu )
399 ADD( "pause", VOID, Input )
400 ADD( "seek", INTEGER, Input )
401 ADD( "title", STRING, Input )
402 ADD( "title_n", VOID, Input )
403 ADD( "title_p", VOID, Input )
404 ADD( "chapter", STRING, Input )
405 ADD( "chapter_n", VOID, Input )
406 ADD( "chapter_p", VOID, Input )
408 ADD( "fastforward", VOID, Input )
409 ADD( "rewind", VOID, Input )
410 ADD( "faster", VOID, Input )
411 ADD( "slower", VOID, Input )
412 ADD( "normal", VOID, Input )
413 ADD( "frame", VOID, Input )
415 ADD( "atrack", STRING, Input )
416 ADD( "vtrack", STRING, Input )
417 ADD( "strack", STRING, Input )
420 ADD( "vratio", STRING, VideoConfig )
421 ADD( "vcrop", STRING, VideoConfig )
422 ADD( "vzoom", STRING, VideoConfig )
423 ADD( "snapshot", VOID, VideoConfig )
426 ADD( "volume", STRING, Volume )
427 ADD( "volup", STRING, VolumeMove )
428 ADD( "voldown", STRING, VolumeMove )
429 ADD( "adev", STRING, AudioConfig )
430 ADD( "achan", STRING, AudioConfig )
432 /* misc menu commands */
433 ADD( "stats", BOOL, Statistics )
438 /*****************************************************************************
440 *****************************************************************************
441 * This part of the interface is in a separate thread so that we can call
442 * exec() from within it without annoying the rest of the program.
443 *****************************************************************************/
444 static void Run( intf_thread_t *p_intf )
446 input_thread_t * p_input = NULL;
447 playlist_t * p_playlist = pl_Hold( p_intf );
449 char p_buffer[ MAX_LINE_LENGTH + 1 ];
450 bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
451 bool b_longhelp = false;
456 int canc = vlc_savecancel();
460 /* Register commands that will be cleaned up upon object destruction */
461 p_intf->p_sys->p_playlist = p_playlist;
462 RegisterCallbacks( p_intf );
464 /* status callbacks */
465 /* Listen to audio volume updates */
466 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
469 /* Get the file descriptor of the console input */
470 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
471 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
473 msg_Err( p_intf, "couldn't find user input handle" );
474 vlc_object_kill( p_intf );
478 while( vlc_object_alive( p_intf ) )
480 char *psz_cmd, *psz_arg;
483 if( p_intf->p_sys->pi_socket_listen != NULL &&
484 p_intf->p_sys->i_socket == -1 )
486 p_intf->p_sys->i_socket =
487 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
489 if( p_intf->p_sys->i_socket == -1 ) continue;
492 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
494 /* Manage the input part */
495 if( p_input == NULL )
497 p_input = playlist_CurrentInput( p_playlist );
498 /* New input has been registered */
501 if( !p_input->b_dead || vlc_object_alive (p_input) )
504 input_item_GetURI( input_GetItem( p_input ) );
505 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
507 msg_rc( STATUS_CHANGE "( audio volume: %d )",
508 config_GetInt( p_intf, "volume" ));
510 var_AddCallback( p_input, "intf-event", InputEvent, p_intf );
513 else if( p_input->b_dead )
515 var_DelCallback( p_input, "intf-event", InputEvent, p_intf );
516 vlc_object_release( p_input );
522 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
523 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
528 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
529 (p_playlist != NULL) )
532 int status = playlist_Status( p_playlist );
533 if( p_intf->p_sys->i_last_state != status )
535 if( status == PLAYLIST_STOPPED )
537 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
538 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
540 else if( status == PLAYLIST_RUNNING )
542 p_intf->p_sys->i_last_state = PLAYLIST_RUNNING;
543 msg_rc( STATUS_CHANGE "( play state: 3 )" );
545 else if( status == PLAYLIST_PAUSED )
547 p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
548 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
554 if( p_input && b_showpos )
556 i_newpos = 100 * var_GetFloat( p_input, "position" );
557 if( i_oldpos != i_newpos )
560 msg_rc( "pos: %d%%", i_newpos );
564 /* Is there something to do? */
565 if( !b_complete ) continue;
567 /* Skip heading spaces */
569 while( *psz_cmd == ' ' )
574 /* Split psz_cmd at the first space and make sure that
575 * psz_arg is valid */
576 psz_arg = strchr( psz_cmd, ' ' );
580 while( *psz_arg == ' ' )
590 /* module specfic commands: @<module name> <command> <args...> */
591 if( *psz_cmd == '@' && *psz_arg )
593 /* Parse miscellaneous commands */
594 char *psz_alias = psz_cmd + 1;
595 char *psz_mycmd = strdup( psz_arg );
596 char *psz_myarg = strchr( psz_mycmd, ' ' );
601 msg_rc( "Not enough parameters." );
608 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
613 msg_rc( "%s", psz_msg );
619 /* If the user typed a registered local command, try it */
620 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
625 val.psz_string = psz_arg;
626 i_ret = var_Set( p_intf, psz_cmd, val );
627 msg_rc( "%s: returned %i (%s)",
628 psz_cmd, i_ret, vlc_error( i_ret ) );
630 /* Or maybe it's a global command */
631 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
636 val.psz_string = psz_arg;
637 /* FIXME: it's a global command, but we should pass the
638 * local object as an argument, not p_intf->p_libvlc. */
639 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
642 msg_rc( "%s: returned %i (%s)",
643 psz_cmd, i_ret, vlc_error( i_ret ) );
646 else if( !strcmp( psz_cmd, "logout" ) )
648 /* Close connection */
649 if( p_intf->p_sys->i_socket != -1 )
651 net_Close( p_intf->p_sys->i_socket );
653 p_intf->p_sys->i_socket = -1;
655 else if( !strcmp( psz_cmd, "info" ) )
660 vlc_mutex_lock( &input_GetItem(p_input)->lock );
661 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
663 info_category_t *p_category = input_GetItem(p_input)
666 msg_rc( "+----[ %s ]", p_category->psz_name );
668 for ( j = 0; j < p_category->i_infos; j++ )
670 info_t *p_info = p_category->pp_infos[j];
671 msg_rc( "| %s: %s", p_info->psz_name,
676 msg_rc( "+----[ end of stream info ]" );
677 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
681 msg_rc( "no input" );
684 else if( !strcmp( psz_cmd, "is_playing" ) )
695 else if( !strcmp( psz_cmd, "get_time" ) )
704 var_Get( p_input, "time", &time );
705 msg_rc( "%"PRIu64, time.i_time / 1000000);
708 else if( !strcmp( psz_cmd, "get_length" ) )
717 var_Get( p_input, "length", &time );
718 msg_rc( "%"PRIu64, time.i_time / 1000000);
721 else if( !strcmp( psz_cmd, "get_title" ) )
729 msg_rc( "%s", input_GetItem(p_input)->psz_name );
732 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
733 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
735 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
737 else b_longhelp = false;
739 Help( p_intf, b_longhelp );
741 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
743 var_SetInteger( p_intf->p_libvlc, "key-pressed",
744 config_GetInt( p_intf, psz_arg ) );
746 else switch( psz_cmd[0] )
752 vout_thread_t *p_vout;
753 p_vout = input_GetVout( p_input );
758 bool b_update = false;
759 var_Get( p_vout, "fullscreen", &val );
760 val.b_bool = !val.b_bool;
761 if( !strncmp( psz_arg, "on", 2 )
762 && ( val.b_bool == true ) )
767 else if( !strncmp( psz_arg, "off", 3 )
768 && ( val.b_bool == false ) )
773 else if( strncmp( psz_arg, "off", 3 )
774 && strncmp( psz_arg, "on", 2 ) )
776 if( b_update ) var_Set( p_vout, "fullscreen", val );
777 vlc_object_release( p_vout );
788 /* Ignore empty lines */
792 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
796 /* Command processed */
797 i_size = 0; p_buffer[0] = 0;
800 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
801 msg_rc( STATUS_CHANGE "( quit )" );
805 var_DelCallback( p_input, "intf-event", InputEvent, p_intf );
806 vlc_object_release( p_input );
809 pl_Release( p_intf );
811 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
812 vlc_restorecancel( canc );
815 static void Help( intf_thread_t *p_intf, bool b_longhelp)
817 msg_rc("%s", _("+----[ Remote control commands ]"));
819 msg_rc("%s", _("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
820 msg_rc("%s", _("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
821 msg_rc("%s", _("| playlist . . . . . show items currently in playlist"));
822 msg_rc("%s", _("| play . . . . . . . . . . . . . . . . . . play stream"));
823 msg_rc("%s", _("| stop . . . . . . . . . . . . . . . . . . stop stream"));
824 msg_rc("%s", _("| next . . . . . . . . . . . . . . next playlist item"));
825 msg_rc("%s", _("| prev . . . . . . . . . . . . previous playlist item"));
826 msg_rc("%s", _("| goto . . . . . . . . . . . . . . goto item at index"));
827 msg_rc("%s", _("| repeat [on|off] . . . . toggle playlist item repeat"));
828 msg_rc("%s", _("| loop [on|off] . . . . . . . . . toggle playlist loop"));
829 msg_rc("%s", _("| random [on|off] . . . . . . . toggle random jumping"));
830 msg_rc("%s", _("| clear . . . . . . . . . . . . . . clear the playlist"));
831 msg_rc("%s", _("| status . . . . . . . . . . . current playlist status"));
832 msg_rc("%s", _("| title [X] . . . . . . set/get title in current item"));
833 msg_rc("%s", _("| title_n . . . . . . . . next title in current item"));
834 msg_rc("%s", _("| title_p . . . . . . previous title in current item"));
835 msg_rc("%s", _("| chapter [X] . . . . set/get chapter in current item"));
836 msg_rc("%s", _("| chapter_n . . . . . . next chapter in current item"));
837 msg_rc("%s", _("| chapter_p . . . . previous chapter in current item"));
839 msg_rc("%s", _("| seek X . . . seek in seconds, for instance `seek 12'"));
840 msg_rc("%s", _("| pause . . . . . . . . . . . . . . . . toggle pause"));
841 msg_rc("%s", _("| fastforward . . . . . . . . . set to maximum rate"));
842 msg_rc("%s", _("| rewind . . . . . . . . . . . . set to minimum rate"));
843 msg_rc("%s", _("| faster . . . . . . . . . . faster playing of stream"));
844 msg_rc("%s", _("| slower . . . . . . . . . . slower playing of stream"));
845 msg_rc("%s", _("| normal . . . . . . . . . . normal playing of stream"));
846 msg_rc("%s", _("| frame. . . . . . . . . . play frame by frame"));
847 msg_rc("%s", _("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
848 msg_rc("%s", _("| info . . . . . information about the current stream"));
849 msg_rc("%s", _("| stats . . . . . . . . show statistical information"));
850 msg_rc("%s", _("| get_time . . seconds elapsed since stream's beginning"));
851 msg_rc("%s", _("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
852 msg_rc("%s", _("| get_title . . . . . the title of the current stream"));
853 msg_rc("%s", _("| get_length . . . . the length of the current stream"));
855 msg_rc("%s", _("| volume [X] . . . . . . . . . . set/get audio volume"));
856 msg_rc("%s", _("| volup [X] . . . . . . . raise audio volume X steps"));
857 msg_rc("%s", _("| voldown [X] . . . . . . lower audio volume X steps"));
858 msg_rc("%s", _("| adev [X] . . . . . . . . . . . set/get audio device"));
859 msg_rc("%s", _("| achan [X]. . . . . . . . . . set/get audio channels"));
860 msg_rc("%s", _("| atrack [X] . . . . . . . . . . . set/get audio track"));
861 msg_rc("%s", _("| vtrack [X] . . . . . . . . . . . set/get video track"));
862 msg_rc("%s", _("| vratio [X] . . . . . . . set/get video aspect ratio"));
863 msg_rc("%s", _("| vcrop [X] . . . . . . . . . . . set/get video crop"));
864 msg_rc("%s", _("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
865 msg_rc("%s", _("| snapshot . . . . . . . . . . . . take video snapshot"));
866 msg_rc("%s", _("| strack [X] . . . . . . . . . set/get subtitles track"));
867 msg_rc("%s", _("| key [hotkey name] . . . . . . simulate hotkey press"));
868 msg_rc("%s", _("| menu . . [on|off|up|down|left|right|select] use menu"));
873 msg_rc("%s", _("| @name marq-marquee STRING . . overlay STRING in video"));
874 msg_rc("%s", _("| @name marq-x X . . . . . . . . . . . .offset from left"));
875 msg_rc("%s", _("| @name marq-y Y . . . . . . . . . . . . offset from top"));
876 msg_rc("%s", _("| @name marq-position #. . . .relative position control"));
877 msg_rc("%s", _("| @name marq-color # . . . . . . . . . . font color, RGB"));
878 msg_rc("%s", _("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
879 msg_rc("%s", _("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
880 msg_rc("%s", _("| @name marq-size # . . . . . . . . font size, in pixels"));
882 msg_rc("%s", _("| @name logo-file STRING . . .the overlay file path/name"));
883 msg_rc("%s", _("| @name logo-x X . . . . . . . . . . . .offset from left"));
884 msg_rc("%s", _("| @name logo-y Y . . . . . . . . . . . . offset from top"));
885 msg_rc("%s", _("| @name logo-position #. . . . . . . . relative position"));
886 msg_rc("%s", _("| @name logo-transparency #. . . . . . . . .transparency"));
888 msg_rc("%s", _("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
889 msg_rc("%s", _("| @name mosaic-height #. . . . . . . . . . . . . .height"));
890 msg_rc("%s", _("| @name mosaic-width # . . . . . . . . . . . . . . width"));
891 msg_rc("%s", _("| @name mosaic-xoffset # . . . .top left corner position"));
892 msg_rc("%s", _("| @name mosaic-yoffset # . . . .top left corner position"));
893 msg_rc("%s", _("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
894 msg_rc("%s", _("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
895 msg_rc("%s", _("| @name mosaic-vborder # . . . . . . . . vertical border"));
896 msg_rc("%s", _("| @name mosaic-hborder # . . . . . . . horizontal border"));
897 msg_rc("%s", _("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
898 msg_rc("%s", _("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
899 msg_rc("%s", _("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
900 msg_rc("%s", _("| @name mosaic-order id(,id)* . . . . order of pictures "));
901 msg_rc("%s", _("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
904 msg_rc("%s", _("| help . . . . . . . . . . . . . . . this help message"));
905 msg_rc("%s", _("| longhelp . . . . . . . . . . . a longer help message"));
906 msg_rc("%s", _("| logout . . . . . . . exit (if in socket connection)"));
907 msg_rc("%s", _("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
909 msg_rc("%s", _("+----[ end of help ]"));
912 /********************************************************************
913 * Status callback routines
914 ********************************************************************/
915 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
916 vlc_value_t oldval, vlc_value_t newval, void *p_data )
918 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
919 intf_thread_t *p_intf = (intf_thread_t*)p_data;
921 vlc_mutex_lock( &p_intf->p_sys->status_lock );
922 msg_rc( STATUS_CHANGE "( audio volume: %d )",
923 config_GetInt( p_this, "volume") );
924 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
928 static void StateChanged( intf_thread_t *p_intf, input_thread_t *p_input )
930 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
933 const int i_status = playlist_Status( p_playlist );
940 case PLAYLIST_STOPPED:
943 case PLAYLIST_RUNNING:
946 case PLAYLIST_PAUSED:
955 const int i_state = var_GetInteger( p_input, "state" );
957 vlc_mutex_lock( &p_intf->p_sys->status_lock );
958 msg_rc( STATUS_CHANGE "( %s state: %d ): %s", psz_cmd,
959 i_state, ppsz_input_state[i_state] );
960 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
962 static void RateChanged( intf_thread_t *p_intf,
963 input_thread_t *p_input )
965 vlc_mutex_lock( &p_intf->p_sys->status_lock );
966 msg_rc( STATUS_CHANGE "( new rate: %d )",
967 var_GetInteger( p_input, "rate" ) );
968 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
970 static void PositionChanged( intf_thread_t *p_intf,
971 input_thread_t *p_input )
973 vlc_mutex_lock( &p_intf->p_sys->status_lock );
974 if( p_intf->p_sys->b_input_buffering )
975 msg_rc( STATUS_CHANGE "( time: %"PRId64"s )",
976 (var_GetTime( p_input, "time" )/1000000) );
977 p_intf->p_sys->b_input_buffering = false;
978 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
980 static void CacheChanged( intf_thread_t *p_intf )
982 vlc_mutex_lock( &p_intf->p_sys->status_lock );
983 p_intf->p_sys->b_input_buffering = true;
984 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
987 static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
988 vlc_value_t oldval, vlc_value_t newval, void *p_data )
992 input_thread_t *p_input = (input_thread_t*)p_this;
993 intf_thread_t *p_intf = p_data;
995 switch( newval.i_int )
997 case INPUT_EVENT_STATE:
998 case INPUT_EVENT_DEAD:
999 StateChanged( p_intf, p_input );
1001 case INPUT_EVENT_RATE:
1002 RateChanged( p_intf, p_input );
1004 case INPUT_EVENT_POSITION:
1005 PositionChanged( p_intf, p_input );
1007 case INPUT_EVENT_CACHE:
1008 CacheChanged( p_intf );
1016 /********************************************************************
1018 ********************************************************************/
1019 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1020 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1022 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1023 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1024 input_thread_t *p_input =
1025 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1026 int i_error = VLC_EGENERIC;
1031 int state = var_GetInteger( p_input, "state" );
1032 if( ( state == PAUSE_S ) &&
1033 ( strcmp( psz_cmd, "pause" ) != 0 ) && (strcmp( psz_cmd,"frame") != 0 ) )
1035 msg_rc( "%s", _("Press menu select or pause to continue.") );
1038 /* Parse commands that only require an input */
1039 if( !strcmp( psz_cmd, "pause" ) )
1041 playlist_Pause( p_intf->p_sys->p_playlist );
1042 i_error = VLC_SUCCESS;
1044 else if( !strcmp( psz_cmd, "seek" ) )
1046 if( strlen( newval.psz_string ) > 0 &&
1047 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1049 float f = atof( newval.psz_string ) / 100.0;
1050 var_SetFloat( p_input, "position", f );
1054 mtime_t t = ((int64_t)atoi( newval.psz_string )) * CLOCK_FREQ;
1055 var_SetTime( p_input, "time", t );
1057 i_error = VLC_SUCCESS;
1059 else if ( !strcmp( psz_cmd, "fastforward" ) )
1061 if( var_GetBool( p_input, "can-rate" ) )
1063 int i_rate = var_GetInteger( p_input, "rate" );
1064 i_rate = (i_rate < 0) ? -i_rate : i_rate * 2;
1065 var_SetInteger( p_input, "rate", i_rate );
1069 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_EXTRASHORT );
1071 i_error = VLC_SUCCESS;
1073 else if ( !strcmp( psz_cmd, "rewind" ) )
1075 if( var_GetBool( p_input, "can-rewind" ) )
1077 int i_rate = var_GetInteger( p_input, "rate" );
1078 i_rate = (i_rate > 0) ? -i_rate : i_rate / 2;
1079 var_SetInteger( p_input, "rate", i_rate );
1083 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_EXTRASHORT );
1085 i_error = VLC_SUCCESS;
1087 else if ( !strcmp( psz_cmd, "faster" ) )
1089 var_TriggerCallback( p_input, "rate-faster" );
1090 i_error = VLC_SUCCESS;
1092 else if ( !strcmp( psz_cmd, "slower" ) )
1094 var_TriggerCallback( p_input, "rate-slower" );
1095 i_error = VLC_SUCCESS;
1097 else if ( !strcmp( psz_cmd, "normal" ) )
1099 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
1100 i_error = VLC_SUCCESS;
1102 else if ( !strcmp( psz_cmd, "frame" ) )
1104 var_TriggerCallback( p_input, "frame-next" );
1105 i_error = VLC_SUCCESS;
1107 else if( !strcmp( psz_cmd, "chapter" ) ||
1108 !strcmp( psz_cmd, "chapter_n" ) ||
1109 !strcmp( psz_cmd, "chapter_p" ) )
1111 if( !strcmp( psz_cmd, "chapter" ) )
1113 if ( *newval.psz_string )
1116 var_SetInteger( p_input, "chapter", atoi( newval.psz_string ) );
1121 int i_chap = var_GetInteger( p_input, "chapter" );
1122 int i_chapter_count = var_CountChoices( p_input, "chapter" );
1123 msg_rc( "Currently playing chapter %d/%d.", i_chap,
1127 else if( !strcmp( psz_cmd, "chapter_n" ) )
1128 var_TriggerCallback( p_input, "next-chapter" );
1129 else if( !strcmp( psz_cmd, "chapter_p" ) )
1130 var_TriggerCallback( p_input, "prev-chapter" );
1131 i_error = VLC_SUCCESS;
1133 else if( !strcmp( psz_cmd, "title" ) ||
1134 !strcmp( psz_cmd, "title_n" ) ||
1135 !strcmp( psz_cmd, "title_p" ) )
1137 if( !strcmp( psz_cmd, "title" ) )
1139 if ( *newval.psz_string )
1141 var_SetInteger( p_input, "title", atoi( newval.psz_string ) );
1145 int i_title = var_GetInteger( p_input, "title" );
1146 int i_title_count = var_CountChoices( p_input, "title" );
1147 msg_rc( "Currently playing title %d/%d.", i_title,
1151 else if( !strcmp( psz_cmd, "title_n" ) )
1152 var_TriggerCallback( p_input, "next-title" );
1153 else if( !strcmp( psz_cmd, "title_p" ) )
1154 var_TriggerCallback( p_input, "prev-title" );
1156 i_error = VLC_SUCCESS;
1158 else if( !strcmp( psz_cmd, "atrack" )
1159 || !strcmp( psz_cmd, "vtrack" )
1160 || !strcmp( psz_cmd, "strack" ) )
1162 const char *psz_variable;
1163 vlc_value_t val_name;
1165 if( !strcmp( psz_cmd, "atrack" ) )
1167 psz_variable = "audio-es";
1169 else if( !strcmp( psz_cmd, "vtrack" ) )
1171 psz_variable = "video-es";
1175 psz_variable = "spu-es";
1178 /* Get the descriptive name of the variable */
1179 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1181 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1183 if( newval.psz_string && *newval.psz_string )
1186 i_error = var_SetInteger( p_input, psz_variable,
1187 atoi( newval.psz_string ) );
1192 vlc_value_t val, text;
1195 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1197 i_value = val.i_int;
1199 if ( var_Change( p_input, psz_variable,
1200 VLC_VAR_GETLIST, &val, &text ) < 0 )
1203 msg_rc( "+----[ %s ]", val_name.psz_string );
1204 for ( i = 0; i < val.p_list->i_count; i++ )
1206 if ( i_value == val.p_list->p_values[i].i_int )
1207 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1208 text.p_list->p_values[i].psz_string );
1210 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1211 text.p_list->p_values[i].psz_string );
1213 var_FreeList( &val, &text );
1214 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1216 free( val_name.psz_string );
1220 vlc_object_release( p_input );
1224 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1227 char psz_buffer[MSTRTIME_MAX_SIZE];
1228 for( i = 0; i< p_item->i_children; i++ )
1230 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1232 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1233 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1236 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1238 if( p_item->pp_children[i]->i_children >= 0 )
1239 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1243 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1244 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1246 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1249 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1250 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1251 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1255 int state = var_GetInteger( p_input, "state" );
1256 vlc_object_release( p_input );
1258 if( state == PAUSE_S )
1260 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1261 return VLC_EGENERIC;
1265 /* Parse commands that require a playlist */
1266 if( !strcmp( psz_cmd, "prev" ) )
1268 playlist_Prev( p_playlist );
1270 else if( !strcmp( psz_cmd, "next" ) )
1272 playlist_Next( p_playlist );
1274 else if( !strcmp( psz_cmd, "play" ) )
1276 msg_Warn( p_playlist, "play" );
1277 playlist_Play( p_playlist );
1279 else if( !strcmp( psz_cmd, "repeat" ) )
1281 bool b_update = true;
1283 var_Get( p_playlist, "repeat", &val );
1285 if( strlen( newval.psz_string ) > 0 )
1287 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1288 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1296 val.b_bool = !val.b_bool;
1297 var_Set( p_playlist, "repeat", val );
1299 msg_rc( "Setting repeat to %d", val.b_bool );
1301 else if( !strcmp( psz_cmd, "loop" ) )
1303 bool b_update = true;
1305 var_Get( p_playlist, "loop", &val );
1307 if( strlen( newval.psz_string ) > 0 )
1309 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1310 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1318 val.b_bool = !val.b_bool;
1319 var_Set( p_playlist, "loop", val );
1321 msg_rc( "Setting loop to %d", val.b_bool );
1323 else if( !strcmp( psz_cmd, "random" ) )
1325 bool b_update = true;
1327 var_Get( p_playlist, "random", &val );
1329 if( strlen( newval.psz_string ) > 0 )
1331 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1332 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1340 val.b_bool = !val.b_bool;
1341 var_Set( p_playlist, "random", val );
1343 msg_rc( "Setting random to %d", val.b_bool );
1345 else if (!strcmp( psz_cmd, "goto" ) )
1347 int i_pos = atoi( newval.psz_string );
1348 /* The playlist stores 2 times the same item: onelevel & category */
1349 int i_size = p_playlist->items.i_size / 2;
1352 msg_rc( "%s", _("Error: `goto' needs an argument greater than zero.") );
1353 else if( i_pos <= i_size )
1355 playlist_item_t *p_item, *p_parent;
1356 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1357 while( p_parent->p_parent )
1358 p_parent = p_parent->p_parent;
1359 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1363 msg_rc( _("Playlist has only %d elements"), i_size );
1365 else if( !strcmp( psz_cmd, "stop" ) )
1367 playlist_Stop( p_playlist );
1369 else if( !strcmp( psz_cmd, "clear" ) )
1371 playlist_Stop( p_playlist );
1372 playlist_Clear( p_playlist, pl_Unlocked );
1374 else if( !strcmp( psz_cmd, "add" ) &&
1375 newval.psz_string && *newval.psz_string )
1377 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1381 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1382 int i_ret =playlist_AddInput( p_playlist, p_item,
1383 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1385 vlc_gc_decref( p_item );
1386 if( i_ret != VLC_SUCCESS )
1388 return VLC_EGENERIC;
1392 else if( !strcmp( psz_cmd, "enqueue" ) &&
1393 newval.psz_string && *newval.psz_string )
1395 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1399 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1400 if( playlist_AddInput( p_playlist, p_item,
1401 PLAYLIST_APPEND, PLAYLIST_END, true,
1402 pl_Unlocked ) != VLC_SUCCESS )
1404 return VLC_EGENERIC;
1408 else if( !strcmp( psz_cmd, "playlist" ) )
1410 msg_rc( "+----[ Playlist ]" );
1411 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1412 msg_rc( "+----[ End of playlist ]" );
1415 else if( !strcmp( psz_cmd, "sort" ))
1417 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1418 SORT_ARTIST, ORDER_NORMAL );
1420 else if( !strcmp( psz_cmd, "status" ) )
1422 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1425 /* Replay the current state of the system. */
1427 input_item_GetURI( input_GetItem( p_input ) );
1428 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1430 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1431 config_GetInt( p_intf, "volume" ));
1434 switch( playlist_Status(p_playlist) )
1436 case PLAYLIST_STOPPED:
1437 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1439 case PLAYLIST_RUNNING:
1440 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1442 case PLAYLIST_PAUSED:
1443 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1446 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1450 vlc_object_release( p_input );
1459 msg_rc( "unknown command!" );
1465 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1466 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1468 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1469 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1471 libvlc_Quit( p_this->p_libvlc );
1475 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1476 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1478 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1480 return intf_Create( p_this->p_libvlc, newval.psz_string );
1483 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1484 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1486 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1487 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1488 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1489 input_thread_t *p_input = playlist_CurrentInput( p_playlist );
1490 int i_error = VLC_EGENERIC;
1497 int state = var_GetInteger( p_input, "state" );
1498 vlc_object_release( p_input );
1499 if( state == PAUSE_S )
1501 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1502 return VLC_EGENERIC;
1506 if ( *newval.psz_string )
1509 audio_volume_t i_volume = atoi( newval.psz_string );
1510 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1512 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1514 i_error = VLC_EBADVAR;
1518 if( i_volume == AOUT_VOLUME_MIN )
1519 aout_ToggleMute( p_playlist, NULL );
1520 if( !aout_VolumeSet( p_playlist, i_volume ) )
1521 i_error = VLC_SUCCESS;
1522 osd_Volume( p_this );
1523 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1529 audio_volume_t i_volume;
1530 if ( !aout_VolumeGet( p_playlist, &i_volume ) )
1532 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1533 i_error = VLC_SUCCESS;
1540 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1541 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1543 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1544 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1545 audio_volume_t i_volume;
1546 input_thread_t *p_input =
1547 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1548 int i_nb_steps = atoi(newval.psz_string);
1549 int i_error = VLC_SUCCESS;
1550 int i_volume_step = 0;
1555 int state = var_GetInteger( p_input, "state" );
1556 vlc_object_release( p_input );
1557 if( state == PAUSE_S )
1559 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1560 return VLC_EGENERIC;
1563 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1564 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1569 if ( !strcmp(psz_cmd, "volup") )
1571 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1572 i_error = VLC_EGENERIC;
1576 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1577 i_error = VLC_EGENERIC;
1579 osd_Volume( p_this );
1581 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1586 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1587 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1589 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1590 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1591 input_thread_t *p_input =
1592 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1593 vout_thread_t * p_vout;
1594 const char * psz_variable = NULL;
1600 p_vout = input_GetVout( p_input );
1601 vlc_object_release( p_input );
1605 if( !strcmp( psz_cmd, "vcrop" ) )
1607 psz_variable = "crop";
1609 else if( !strcmp( psz_cmd, "vratio" ) )
1611 psz_variable = "aspect-ratio";
1613 else if( !strcmp( psz_cmd, "vzoom" ) )
1615 psz_variable = "zoom";
1617 else if( !strcmp( psz_cmd, "snapshot" ) )
1619 psz_variable = "video-snapshot";
1622 /* This case can't happen */
1625 if( newval.psz_string && *newval.psz_string )
1628 if( !strcmp( psz_variable, "zoom" ) )
1631 val.f_float = atof( newval.psz_string );
1632 i_error = var_Set( p_vout, psz_variable, val );
1636 i_error = var_Set( p_vout, psz_variable, newval );
1639 else if( !strcmp( psz_cmd, "snapshot" ) )
1641 i_error = var_SetBool( p_vout, psz_variable, true );
1646 vlc_value_t val_name;
1647 vlc_value_t val, text;
1650 char *psz_value = NULL;
1652 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1654 vlc_object_release( p_vout );
1655 return VLC_EGENERIC;
1657 if( !strcmp( psz_variable, "zoom" ) )
1659 f_value = val.f_float;
1663 psz_value = val.psz_string;
1666 if ( var_Change( p_vout, psz_variable,
1667 VLC_VAR_GETLIST, &val, &text ) < 0 )
1669 vlc_object_release( p_vout );
1671 return VLC_EGENERIC;
1674 /* Get the descriptive name of the variable */
1675 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1677 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1679 msg_rc( "+----[ %s ]", val_name.psz_string );
1680 if( !strcmp( psz_variable, "zoom" ) )
1682 for ( i = 0; i < val.p_list->i_count; i++ )
1684 if ( f_value == val.p_list->p_values[i].f_float )
1685 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1686 text.p_list->p_values[i].psz_string );
1688 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1689 text.p_list->p_values[i].psz_string );
1694 for ( i = 0; i < val.p_list->i_count; i++ )
1696 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1697 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1698 text.p_list->p_values[i].psz_string );
1700 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1701 text.p_list->p_values[i].psz_string );
1705 var_FreeList( &val, &text );
1706 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1708 free( val_name.psz_string );
1710 i_error = VLC_SUCCESS;
1712 vlc_object_release( p_vout );
1716 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1717 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1719 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1720 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1721 input_thread_t *p_input =
1722 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1723 aout_instance_t * p_aout;
1724 const char * psz_variable;
1725 vlc_value_t val_name;
1731 int state = var_GetInteger( p_input, "state" );
1732 if( state == PAUSE_S )
1734 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1735 return VLC_EGENERIC;
1738 p_aout = input_GetAout( p_input );
1739 vlc_object_release( p_input );
1740 if ( p_aout == NULL )
1743 if ( !strcmp( psz_cmd, "adev" ) )
1745 psz_variable = "audio-device";
1749 psz_variable = "audio-channels";
1752 /* Get the descriptive name of the variable */
1753 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1755 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1757 if ( !*newval.psz_string )
1759 /* Retrieve all registered ***. */
1760 vlc_value_t val, text;
1763 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1765 vlc_object_release( (vlc_object_t *)p_aout );
1766 return VLC_EGENERIC;
1768 i_value = val.i_int;
1770 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1771 VLC_VAR_GETLIST, &val, &text ) < 0 )
1773 vlc_object_release( (vlc_object_t *)p_aout );
1774 return VLC_EGENERIC;
1777 msg_rc( "+----[ %s ]", val_name.psz_string );
1778 for ( i = 0; i < val.p_list->i_count; i++ )
1780 if ( i_value == val.p_list->p_values[i].i_int )
1781 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1782 text.p_list->p_values[i].psz_string );
1784 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1785 text.p_list->p_values[i].psz_string );
1787 var_FreeList( &val, &text );
1788 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1790 free( val_name.psz_string );
1791 i_error = VLC_SUCCESS;
1796 val.i_int = atoi( newval.psz_string );
1798 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1800 vlc_object_release( (vlc_object_t *)p_aout );
1805 /* OSD menu commands */
1806 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1807 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1809 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1810 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1811 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1812 int i_error = VLC_SUCCESS;
1815 if ( !*newval.psz_string )
1817 msg_rc( "%s", _("Please provide one of the following parameters:") );
1818 msg_rc( "[on|off|up|down|left|right|select]" );
1819 return VLC_EGENERIC;
1822 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1826 var_Get( p_input, "state", &val );
1827 vlc_object_release( p_input );
1829 if( ( val.i_int == PAUSE_S ) &&
1830 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1832 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1833 return VLC_EGENERIC;
1837 val.psz_string = strdup( newval.psz_string );
1838 if( !val.psz_string )
1840 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1841 osd_MenuShow( p_this );
1842 else if( !strcmp( val.psz_string, "off" )
1843 || !strcmp( val.psz_string, "hide" ) )
1844 osd_MenuHide( p_this );
1845 else if( !strcmp( val.psz_string, "up" ) )
1846 osd_MenuUp( p_this );
1847 else if( !strcmp( val.psz_string, "down" ) )
1848 osd_MenuDown( p_this );
1849 else if( !strcmp( val.psz_string, "left" ) )
1850 osd_MenuPrev( p_this );
1851 else if( !strcmp( val.psz_string, "right" ) )
1852 osd_MenuNext( p_this );
1853 else if( !strcmp( val.psz_string, "select" ) )
1854 osd_MenuActivate( p_this );
1857 msg_rc( "%s", _("Please provide one of the following parameters:") );
1858 msg_rc( "[on|off|up|down|left|right|select]" );
1859 i_error = VLC_EGENERIC;
1862 free( val.psz_string );
1866 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1867 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1869 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1870 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1871 input_thread_t *p_input =
1872 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1877 if( !strcmp( psz_cmd, "stats" ) )
1879 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1880 updateStatistics( p_intf, input_GetItem(p_input) );
1881 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1888 msg_rc("%s", _("Unknown command!") );
1891 vlc_object_release( p_input );
1895 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1897 if( !p_item ) return VLC_EGENERIC;
1899 vlc_mutex_lock( &p_item->p_stats->lock );
1900 msg_rc( "+----[ begin of statistical info ]" );
1903 msg_rc("%s", _("+-[Incoming]"));
1904 msg_rc(_("| input bytes read : %8.0f kB"),
1905 (float)(p_item->p_stats->i_read_bytes)/1000 );
1906 msg_rc(_("| input bitrate : %6.0f kb/s"),
1907 (float)(p_item->p_stats->f_input_bitrate)*8000 );
1908 msg_rc(_("| demux bytes read : %8.0f kB"),
1909 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
1910 msg_rc(_("| demux bitrate : %6.0f kb/s"),
1911 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
1914 msg_rc("%s", _("+-[Video Decoding]"));
1915 msg_rc(_("| video decoded : %5i"),
1916 p_item->p_stats->i_decoded_video );
1917 msg_rc(_("| frames displayed : %5i"),
1918 p_item->p_stats->i_displayed_pictures );
1919 msg_rc(_("| frames lost : %5i"),
1920 p_item->p_stats->i_lost_pictures );
1923 msg_rc("%s", _("+-[Audio Decoding]"));
1924 msg_rc(_("| audio decoded : %5i"),
1925 p_item->p_stats->i_decoded_audio );
1926 msg_rc(_("| buffers played : %5i"),
1927 p_item->p_stats->i_played_abuffers );
1928 msg_rc(_("| buffers lost : %5i"),
1929 p_item->p_stats->i_lost_abuffers );
1932 msg_rc("%s", _("+-[Streaming]"));
1933 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
1934 msg_rc(_("| bytes sent : %8.0f kB"),
1935 (float)(p_item->p_stats->i_sent_bytes)/1000 );
1936 msg_rc(_("| sending bitrate : %6.0f kb/s"),
1937 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
1939 msg_rc( "+----[ end of statistical info ]" );
1940 vlc_mutex_unlock( &p_item->p_stats->lock );
1946 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1948 INPUT_RECORD input_record;
1951 /* On Win32, select() only works on socket descriptors */
1952 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1953 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1955 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1956 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1959 if( input_record.EventType != KEY_EVENT ||
1960 !input_record.Event.KeyEvent.bKeyDown ||
1961 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1962 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1963 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1964 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1966 /* nothing interesting */
1970 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1972 /* Echo out the command */
1973 putc( p_buffer[ *pi_size ], stdout );
1975 /* Handle special keys */
1976 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1978 putc( '\n', stdout );
1981 switch( p_buffer[ *pi_size ] )
1987 putc( ' ', stdout );
1988 putc( '\b', stdout );
1999 if( *pi_size == MAX_LINE_LENGTH ||
2000 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2002 p_buffer[ *pi_size ] = 0;
2011 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2016 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2017 return ReadWin32( p_intf, p_buffer, pi_size );
2018 else if( p_intf->p_sys->i_socket == -1 )
2020 msleep( INTF_IDLE_SLEEP );
2025 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2026 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2027 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2028 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2030 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2036 /* Connection closed */
2039 if( p_intf->p_sys->i_socket != -1 )
2041 net_Close( p_intf->p_sys->i_socket );
2042 p_intf->p_sys->i_socket = -1;
2046 /* Standard input closed: exit */
2048 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2051 p_buffer[ *pi_size ] = 0;
2055 if( *pi_size == MAX_LINE_LENGTH ||
2056 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2058 p_buffer[ *pi_size ] = 0;
2065 /*****************************************************************************
2066 * parse_MRL: build a input item from a full mrl
2067 *****************************************************************************
2068 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2069 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2070 * space is a new option. Should be good enough for our purpose.
2071 *****************************************************************************/
2072 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2074 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2075 #define SKIPTRAILINGSPACE( p, d ) \
2076 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2078 input_item_t *p_item = NULL;
2079 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2080 char **ppsz_options = NULL;
2081 int i, i_options = 0;
2083 if( !psz_mrl ) return 0;
2085 psz_mrl = psz_orig = strdup( psz_mrl );
2088 SKIPSPACE( psz_mrl );
2091 for( ; *psz_mrl; psz_mrl++ )
2093 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2095 /* We have a complete item */
2098 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2099 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2101 /* We have a complete item */
2106 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2107 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2109 /* Remove '"' and '\'' if necessary */
2110 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2111 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2112 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2113 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2115 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2116 else if( *psz_item )
2119 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2120 ppsz_options[i_options - 1] = &psz_item[1];
2123 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2126 /* Now create a playlist item */
2129 p_item = input_item_New( p_intf, psz_item_mrl, NULL );
2130 for( i = 0; i < i_options; i++ )
2132 input_item_AddOption( p_item, ppsz_options[i], VLC_INPUT_OPTION_TRUSTED );
2136 if( i_options ) free( ppsz_options );