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>
44 #include <vlc_playlist.h>
50 #include <sys/types.h>
52 #include <vlc_network.h>
55 #include <vlc_charset.h>
57 #if defined(PF_UNIX) && !defined(PF_LOCAL)
58 # define PF_LOCAL PF_UNIX
61 #if defined(AF_LOCAL) && ! defined(WIN32)
65 #define MAX_LINE_LENGTH 1024
66 #define STATUS_CHANGE "status change: "
68 /* input_state_e from <vlc_input.h> */
69 static const char *ppsz_input_state[] = {
70 [INIT_S] = N_("Initializing"),
71 [OPENING_S] = N_("Opening"),
72 [PLAYING_S] = N_("Play"),
73 [PAUSE_S] = N_("Pause"),
75 [ERROR_S] = N_("Error"),
78 /*****************************************************************************
80 *****************************************************************************/
81 static int Activate ( vlc_object_t * );
82 static void Deactivate ( vlc_object_t * );
83 static void *Run ( void * );
85 static void Help ( intf_thread_t *, bool );
86 static void RegisterCallbacks( intf_thread_t * );
88 static bool ReadCommand( intf_thread_t *, char *, int * );
90 static input_item_t *parse_MRL( const char * );
92 static int Input ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int Playlist ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
96 static int Quit ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
98 static int Intf ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int Volume ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int VolumeMove ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int VideoConfig ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int AudioDevice ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int AudioChannel ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
110 static int Statistics ( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t, void * );
113 static int updateStatistics( intf_thread_t *, input_item_t *);
115 /* Status Callbacks */
116 static int VolumeChanged( vlc_object_t *, char const *,
117 vlc_value_t, vlc_value_t, void * );
118 static int InputEvent( vlc_object_t *, char const *,
119 vlc_value_t, vlc_value_t, void * );
123 int *pi_socket_listen;
129 vlc_mutex_t status_lock;
131 playlist_t *p_playlist;
132 input_thread_t *p_input;
133 bool b_input_buffering;
142 static void msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
145 char fmt_eol[strlen (psz_fmt) + 3];
147 snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
148 va_start( args, psz_fmt );
150 if( p_intf->p_sys->i_socket == -1 )
151 utf8_vfprintf( stdout, fmt_eol, args );
153 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
156 #define msg_rc( ... ) msg_rc( p_intf, __VA_ARGS__ )
158 /*****************************************************************************
160 *****************************************************************************/
161 #define POS_TEXT N_("Show stream position")
162 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
163 "stream from time to time." )
165 #define TTY_TEXT N_("Fake TTY")
166 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
168 #define UNIX_TEXT N_("UNIX socket command input")
169 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
172 #define HOST_TEXT N_("TCP command input")
173 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
174 "You can set the address and port the interface will bind to." )
177 #define QUIET_TEXT N_("Do not open a DOS command box interface")
178 #define QUIET_LONGTEXT N_( \
179 "By default the rc interface plugin will start a DOS command box. " \
180 "Enabling the quiet mode will not bring this command box but can also " \
181 "be pretty annoying when you want to stop VLC and no video window is " \
186 set_shortname( N_("RC"))
187 set_category( CAT_INTERFACE )
188 set_subcategory( SUBCAT_INTERFACE_MAIN )
189 set_description( N_("Remote control interface") )
190 add_bool( "rc-show-pos", false, POS_TEXT, POS_LONGTEXT, true )
193 add_bool( "rc-quiet", false, QUIET_TEXT, QUIET_LONGTEXT, false )
195 #if defined (HAVE_ISATTY)
196 add_bool( "rc-fake-tty", false, TTY_TEXT, TTY_LONGTEXT, true )
198 add_string( "rc-unix", NULL, UNIX_TEXT, UNIX_LONGTEXT, true )
200 add_string( "rc-host", NULL, HOST_TEXT, HOST_LONGTEXT, true )
202 set_capability( "interface", 20 )
204 set_callbacks( Activate, Deactivate )
210 /*****************************************************************************
211 * Activate: initialize and create stuff
212 *****************************************************************************/
213 static int Activate( vlc_object_t *p_this )
215 /* FIXME: This function is full of memory leaks and bugs in error paths. */
216 intf_thread_t *p_intf = (intf_thread_t*)p_this;
217 playlist_t *p_playlist = pl_Get( p_intf );
218 char *psz_host, *psz_unix_path = NULL;
219 int *pi_socket = NULL;
222 #if defined(HAVE_ISATTY)
223 /* Check that stdin is a TTY */
224 if( !var_InheritBool( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
226 msg_Warn( p_intf, "fd 0 is not a TTY" );
231 psz_unix_path = var_InheritString( p_intf, "rc-unix" );
237 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
238 free( psz_unix_path );
241 struct sockaddr_un addr;
243 memset( &addr, 0, sizeof(struct sockaddr_un) );
245 msg_Dbg( p_intf, "trying UNIX socket" );
247 if( (i_socket = vlc_socket( PF_LOCAL, SOCK_STREAM, 0, false ) ) < 0 )
249 msg_Warn( p_intf, "can't open socket: %m" );
250 free( psz_unix_path );
254 addr.sun_family = AF_LOCAL;
255 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
256 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
258 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
259 && (errno == EADDRINUSE)
260 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
261 && (errno == ECONNREFUSED))
263 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
264 unlink (psz_unix_path);
266 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
268 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
270 free (psz_unix_path);
271 net_Close (i_socket);
276 if( listen( i_socket, 1 ) )
278 msg_Warn( p_intf, "can't listen on socket: %m");
279 free( psz_unix_path );
280 net_Close( i_socket );
284 /* FIXME: we need a core function to merge listening sockets sets */
285 pi_socket = calloc( 2, sizeof( int ) );
286 if( pi_socket == NULL )
288 free( psz_unix_path );
289 net_Close( i_socket );
292 pi_socket[0] = i_socket;
294 #endif /* AF_LOCAL */
298 if( ( pi_socket == NULL ) &&
299 ( psz_host = var_InheritString( p_intf, "rc-host" ) ) != NULL )
303 vlc_UrlParse( &url, psz_host, 0 );
305 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
307 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
308 if( pi_socket == NULL )
310 msg_Warn( p_intf, "can't listen to %s port %i",
311 url.psz_host, url.i_port );
312 vlc_UrlClean( &url );
317 vlc_UrlClean( &url );
321 intf_sys_t *p_sys = malloc( sizeof( *p_sys ) );
322 if( unlikely(p_sys == NULL) )
325 p_intf->p_sys = p_sys;
326 p_sys->pi_socket_listen = pi_socket;
327 p_sys->i_socket = -1;
328 p_sys->psz_unix_path = psz_unix_path;
329 vlc_mutex_init( &p_sys->status_lock );
330 p_sys->i_last_state = PLAYLIST_STOPPED;
331 p_sys->b_input_buffering = false;
332 p_sys->p_playlist = p_playlist;
333 p_sys->p_input = NULL;
335 /* Non-buffered stdout */
336 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
339 p_sys->b_quiet = var_InheritBool( p_intf, "rc-quiet" );
340 if( !p_sys->b_quiet )
346 if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) )
349 msg_rc( "%s", _("Remote control interface initialized. Type `help' for help.") );
351 /* Listen to audio volume updates */
352 var_AddCallback( p_sys->p_playlist, "volume", VolumeChanged, p_intf );
356 /*****************************************************************************
357 * Deactivate: uninitialize and cleanup
358 *****************************************************************************/
359 static void Deactivate( vlc_object_t *p_this )
361 intf_thread_t *p_intf = (intf_thread_t*)p_this;
362 intf_sys_t *p_sys = p_intf->p_sys;
364 var_DelCallback( p_sys->p_playlist, "volume", VolumeChanged, p_intf );
365 vlc_join( p_sys->thread, NULL );
367 if( p_sys->p_input != NULL )
369 var_DelCallback( p_sys->p_input, "intf-event", InputEvent, p_intf );
370 vlc_object_release( p_sys->p_input );
373 net_ListenClose( p_sys->pi_socket_listen );
374 if( p_sys->i_socket != -1 )
375 net_Close( p_sys->i_socket );
376 if( p_sys->psz_unix_path != NULL )
378 #if defined(AF_LOCAL) && !defined(WIN32)
379 unlink( p_sys->psz_unix_path );
381 free( p_sys->psz_unix_path );
383 vlc_mutex_destroy( &p_sys->status_lock );
387 /*****************************************************************************
388 * RegisterCallbacks: Register callbacks to dynamic variables
389 *****************************************************************************/
390 static void RegisterCallbacks( intf_thread_t *p_intf )
392 /* Register commands that will be cleaned up upon object destruction */
393 #define ADD( name, type, target ) \
394 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
395 var_AddCallback( p_intf, name, target, NULL );
396 ADD( "quit", VOID, Quit )
397 ADD( "intf", STRING, Intf )
399 ADD( "add", STRING, Playlist )
400 ADD( "repeat", STRING, Playlist )
401 ADD( "loop", STRING, Playlist )
402 ADD( "random", STRING, Playlist )
403 ADD( "enqueue", STRING, Playlist )
404 ADD( "playlist", VOID, Playlist )
405 ADD( "sort", VOID, Playlist )
406 ADD( "play", VOID, Playlist )
407 ADD( "stop", VOID, Playlist )
408 ADD( "clear", VOID, Playlist )
409 ADD( "prev", VOID, Playlist )
410 ADD( "next", VOID, Playlist )
411 ADD( "goto", INTEGER, Playlist )
412 ADD( "status", INTEGER, Playlist )
415 ADD( "pause", VOID, Input )
416 ADD( "seek", INTEGER, Input )
417 ADD( "title", STRING, Input )
418 ADD( "title_n", VOID, Input )
419 ADD( "title_p", VOID, Input )
420 ADD( "chapter", STRING, Input )
421 ADD( "chapter_n", VOID, Input )
422 ADD( "chapter_p", VOID, Input )
424 ADD( "fastforward", VOID, Input )
425 ADD( "rewind", VOID, Input )
426 ADD( "faster", VOID, Input )
427 ADD( "slower", VOID, Input )
428 ADD( "normal", VOID, Input )
429 ADD( "frame", VOID, Input )
431 ADD( "atrack", STRING, Input )
432 ADD( "vtrack", STRING, Input )
433 ADD( "strack", STRING, Input )
436 ADD( "vratio", STRING, VideoConfig )
437 ADD( "vcrop", STRING, VideoConfig )
438 ADD( "vzoom", STRING, VideoConfig )
439 ADD( "snapshot", VOID, VideoConfig )
442 ADD( "volume", STRING, Volume )
443 ADD( "volup", STRING, VolumeMove )
444 ADD( "voldown", STRING, VolumeMove )
445 ADD( "adev", STRING, AudioDevice )
446 ADD( "achan", STRING, AudioChannel )
448 /* misc menu commands */
449 ADD( "stats", BOOL, Statistics )
454 /*****************************************************************************
456 *****************************************************************************
457 * This part of the interface is in a separate thread so that we can call
458 * exec() from within it without annoying the rest of the program.
459 *****************************************************************************/
460 static void *Run( void *data )
462 intf_thread_t *p_intf = data;
463 intf_sys_t *p_sys = p_intf->p_sys;
465 char p_buffer[ MAX_LINE_LENGTH + 1 ];
466 bool b_showpos = var_InheritBool( p_intf, "rc-show-pos" );
467 bool b_longhelp = false;
476 /* Get the file descriptor of the console input */
477 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
478 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
480 msg_Err( p_intf, "couldn't find user input handle" );
485 /* Register commands that will be cleaned up upon object destruction */
486 RegisterCallbacks( p_intf );
488 /* status callbacks */
492 char *psz_cmd, *psz_arg;
495 if( p_sys->pi_socket_listen != NULL && p_sys->i_socket == -1 )
498 net_Accept( p_intf, p_sys->pi_socket_listen );
499 if( p_sys->i_socket == -1 ) continue;
502 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
504 /* Manage the input part */
505 if( p_sys->p_input == NULL )
507 p_sys->p_input = playlist_CurrentInput( p_sys->p_playlist );
508 /* New input has been registered */
511 char *psz_uri = input_item_GetURI( input_GetItem( p_sys->p_input ) );
512 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
515 var_AddCallback( p_sys->p_input, "intf-event", InputEvent, p_intf );
518 #warning This is not reliable...
519 else if( p_sys->p_input->b_dead )
521 var_DelCallback( p_sys->p_input, "intf-event", InputEvent, p_intf );
522 vlc_object_release( p_sys->p_input );
523 p_sys->p_input = NULL;
525 p_sys->i_last_state = PLAYLIST_STOPPED;
526 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
529 if( p_sys->p_input != NULL )
531 playlist_t *p_playlist = p_sys->p_playlist;
534 int status = playlist_Status( p_playlist );
537 if( p_sys->i_last_state != status )
539 if( status == PLAYLIST_STOPPED )
541 p_sys->i_last_state = PLAYLIST_STOPPED;
542 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
544 else if( status == PLAYLIST_RUNNING )
546 p_sys->i_last_state = PLAYLIST_RUNNING;
547 msg_rc( STATUS_CHANGE "( play state: 3 )" );
549 else if( status == PLAYLIST_PAUSED )
551 p_sys->i_last_state = PLAYLIST_PAUSED;
552 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
557 if( p_sys->p_input && b_showpos )
559 i_newpos = 100 * var_GetFloat( p_sys->p_input, "position" );
560 if( i_oldpos != i_newpos )
563 msg_rc( "pos: %d%%", i_newpos );
567 /* Is there something to do? */
568 if( !b_complete ) continue;
570 /* Skip heading spaces */
572 while( *psz_cmd == ' ' )
577 /* Split psz_cmd at the first space and make sure that
578 * psz_arg is valid */
579 psz_arg = strchr( psz_cmd, ' ' );
583 while( *psz_arg == ' ' )
593 /* module specfic commands: @<module name> <command> <args...> */
594 if( *psz_cmd == '@' && *psz_arg )
596 /* Parse miscellaneous commands */
597 char *psz_alias = psz_cmd + 1;
598 char *psz_mycmd = strdup( psz_arg );
599 char *psz_myarg = strchr( psz_mycmd, ' ' );
604 msg_rc( "Not enough parameters." );
611 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
616 msg_rc( "%s", psz_msg );
622 /* If the user typed a registered local command, try it */
623 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
627 val.psz_string = psz_arg;
629 if ((var_Type( p_intf, psz_cmd) & VLC_VAR_CLASS) == VLC_VAR_VOID)
630 i_ret = var_TriggerCallback( p_intf, psz_cmd );
632 i_ret = var_Set( p_intf, psz_cmd, val );
633 msg_rc( "%s: returned %i (%s)",
634 psz_cmd, i_ret, vlc_error( i_ret ) );
636 /* Or maybe it's a global command */
637 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
642 val.psz_string = psz_arg;
643 /* FIXME: it's a global command, but we should pass the
644 * local object as an argument, not p_intf->p_libvlc. */
645 if ((var_Type( p_intf->p_libvlc, psz_cmd) & VLC_VAR_CLASS) == VLC_VAR_VOID)
646 i_ret = var_TriggerCallback( p_intf, psz_cmd );
648 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
651 msg_rc( "%s: returned %i (%s)",
652 psz_cmd, i_ret, vlc_error( i_ret ) );
655 else if( !strcmp( psz_cmd, "logout" ) )
657 /* Close connection */
658 if( p_sys->i_socket != -1 )
660 net_Close( p_sys->i_socket );
661 p_sys->i_socket = -1;
664 else if( !strcmp( psz_cmd, "info" ) )
669 vlc_mutex_lock( &input_GetItem(p_sys->p_input)->lock );
670 for ( i = 0; i < input_GetItem(p_sys->p_input)->i_categories; i++ )
672 info_category_t *p_category = input_GetItem(p_sys->p_input)
675 msg_rc( "+----[ %s ]", p_category->psz_name );
677 for ( j = 0; j < p_category->i_infos; j++ )
679 info_t *p_info = p_category->pp_infos[j];
680 msg_rc( "| %s: %s", p_info->psz_name,
685 msg_rc( "+----[ end of stream info ]" );
686 vlc_mutex_unlock( &input_GetItem(p_sys->p_input)->lock );
690 msg_rc( "no input" );
693 else if( !strcmp( psz_cmd, "is_playing" ) )
695 if( p_sys->p_input == NULL )
704 else if( !strcmp( psz_cmd, "get_time" ) )
706 if( p_sys->p_input == NULL )
713 var_Get( p_sys->p_input, "time", &time );
714 msg_rc( "%"PRIu64, time.i_time / 1000000);
717 else if( !strcmp( psz_cmd, "get_length" ) )
719 if( p_sys->p_input == NULL )
726 var_Get( p_sys->p_input, "length", &time );
727 msg_rc( "%"PRIu64, time.i_time / 1000000);
730 else if( !strcmp( psz_cmd, "get_title" ) )
732 if( p_sys->p_input == NULL )
738 msg_rc( "%s", input_GetItem(p_sys->p_input)->psz_name );
741 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
742 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
744 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
746 else b_longhelp = false;
748 Help( p_intf, b_longhelp );
750 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
752 var_SetInteger( p_intf->p_libvlc, "key-action",
753 vlc_GetActionId( psz_arg ) );
755 else switch( psz_cmd[0] )
762 if( !strncasecmp( psz_arg, "on", 2 ) )
763 var_SetBool( p_sys->p_playlist, "fullscreen", fs = true );
764 else if( !strncasecmp( psz_arg, "off", 3 ) )
765 var_SetBool( p_sys->p_playlist, "fullscreen", fs = false );
767 fs = var_ToggleBool( p_sys->p_playlist, "fullscreen" );
769 if( p_sys->p_input == NULL )
771 vout_thread_t *p_vout = input_GetVout( p_sys->p_input );
774 var_SetBool( p_vout, "fullscreen", fs );
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 )" );
804 static void Help( intf_thread_t *p_intf, bool b_longhelp)
806 msg_rc("%s", _("+----[ Remote control commands ]"));
808 msg_rc("%s", _("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
809 msg_rc("%s", _("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
810 msg_rc("%s", _("| playlist . . . . . show items currently in playlist"));
811 msg_rc("%s", _("| play . . . . . . . . . . . . . . . . . . play stream"));
812 msg_rc("%s", _("| stop . . . . . . . . . . . . . . . . . . stop stream"));
813 msg_rc("%s", _("| next . . . . . . . . . . . . . . next playlist item"));
814 msg_rc("%s", _("| prev . . . . . . . . . . . . previous playlist item"));
815 msg_rc("%s", _("| goto . . . . . . . . . . . . . . goto item at index"));
816 msg_rc("%s", _("| repeat [on|off] . . . . toggle playlist item repeat"));
817 msg_rc("%s", _("| loop [on|off] . . . . . . . . . toggle playlist loop"));
818 msg_rc("%s", _("| random [on|off] . . . . . . . toggle random jumping"));
819 msg_rc("%s", _("| clear . . . . . . . . . . . . . . clear the playlist"));
820 msg_rc("%s", _("| status . . . . . . . . . . . current playlist status"));
821 msg_rc("%s", _("| title [X] . . . . . . set/get title in current item"));
822 msg_rc("%s", _("| title_n . . . . . . . . next title in current item"));
823 msg_rc("%s", _("| title_p . . . . . . previous title in current item"));
824 msg_rc("%s", _("| chapter [X] . . . . set/get chapter in current item"));
825 msg_rc("%s", _("| chapter_n . . . . . . next chapter in current item"));
826 msg_rc("%s", _("| chapter_p . . . . previous chapter in current item"));
828 msg_rc("%s", _("| seek X . . . seek in seconds, for instance `seek 12'"));
829 msg_rc("%s", _("| pause . . . . . . . . . . . . . . . . toggle pause"));
830 msg_rc("%s", _("| fastforward . . . . . . . . . set to maximum rate"));
831 msg_rc("%s", _("| rewind . . . . . . . . . . . . set to minimum rate"));
832 msg_rc("%s", _("| faster . . . . . . . . . . faster playing of stream"));
833 msg_rc("%s", _("| slower . . . . . . . . . . slower playing of stream"));
834 msg_rc("%s", _("| normal . . . . . . . . . . normal playing of stream"));
835 msg_rc("%s", _("| frame. . . . . . . . . . play frame by frame"));
836 msg_rc("%s", _("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
837 msg_rc("%s", _("| info . . . . . information about the current stream"));
838 msg_rc("%s", _("| stats . . . . . . . . show statistical information"));
839 msg_rc("%s", _("| get_time . . seconds elapsed since stream's beginning"));
840 msg_rc("%s", _("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
841 msg_rc("%s", _("| get_title . . . . . the title of the current stream"));
842 msg_rc("%s", _("| get_length . . . . the length of the current stream"));
844 msg_rc("%s", _("| volume [X] . . . . . . . . . . set/get audio volume"));
845 msg_rc("%s", _("| volup [X] . . . . . . . raise audio volume X steps"));
846 msg_rc("%s", _("| voldown [X] . . . . . . lower audio volume X steps"));
847 msg_rc("%s", _("| adev [device] . . . . . . . . set/get audio device"));
848 msg_rc("%s", _("| achan [X]. . . . . . . . . . set/get audio channels"));
849 msg_rc("%s", _("| atrack [X] . . . . . . . . . . . set/get audio track"));
850 msg_rc("%s", _("| vtrack [X] . . . . . . . . . . . set/get video track"));
851 msg_rc("%s", _("| vratio [X] . . . . . . . set/get video aspect ratio"));
852 msg_rc("%s", _("| vcrop [X] . . . . . . . . . . . set/get video crop"));
853 msg_rc("%s", _("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
854 msg_rc("%s", _("| snapshot . . . . . . . . . . . . take video snapshot"));
855 msg_rc("%s", _("| strack [X] . . . . . . . . . set/get subtitle track"));
856 msg_rc("%s", _("| key [hotkey name] . . . . . . simulate hotkey press"));
857 msg_rc("%s", _("| menu . . [on|off|up|down|left|right|select] use menu"));
862 msg_rc("%s", _("| @name marq-marquee STRING . . overlay STRING in video"));
863 msg_rc("%s", _("| @name marq-x X . . . . . . . . . . . .offset from left"));
864 msg_rc("%s", _("| @name marq-y Y . . . . . . . . . . . . offset from top"));
865 msg_rc("%s", _("| @name marq-position #. . . .relative position control"));
866 msg_rc("%s", _("| @name marq-color # . . . . . . . . . . font color, RGB"));
867 msg_rc("%s", _("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
868 msg_rc("%s", _("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
869 msg_rc("%s", _("| @name marq-size # . . . . . . . . font size, in pixels"));
871 msg_rc("%s", _("| @name logo-file STRING . . .the overlay file path/name"));
872 msg_rc("%s", _("| @name logo-x X . . . . . . . . . . . .offset from left"));
873 msg_rc("%s", _("| @name logo-y Y . . . . . . . . . . . . offset from top"));
874 msg_rc("%s", _("| @name logo-position #. . . . . . . . relative position"));
875 msg_rc("%s", _("| @name logo-transparency #. . . . . . . . .transparency"));
877 msg_rc("%s", _("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
878 msg_rc("%s", _("| @name mosaic-height #. . . . . . . . . . . . . .height"));
879 msg_rc("%s", _("| @name mosaic-width # . . . . . . . . . . . . . . width"));
880 msg_rc("%s", _("| @name mosaic-xoffset # . . . .top left corner position"));
881 msg_rc("%s", _("| @name mosaic-yoffset # . . . .top left corner position"));
882 msg_rc("%s", _("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
883 msg_rc("%s", _("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
884 msg_rc("%s", _("| @name mosaic-vborder # . . . . . . . . vertical border"));
885 msg_rc("%s", _("| @name mosaic-hborder # . . . . . . . horizontal border"));
886 msg_rc("%s", _("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
887 msg_rc("%s", _("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
888 msg_rc("%s", _("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
889 msg_rc("%s", _("| @name mosaic-order id(,id)* . . . . order of pictures "));
890 msg_rc("%s", _("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
893 msg_rc("%s", _("| help . . . . . . . . . . . . . . . this help message"));
894 msg_rc("%s", _("| longhelp . . . . . . . . . . . a longer help message"));
895 msg_rc("%s", _("| logout . . . . . . . exit (if in socket connection)"));
896 msg_rc("%s", _("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
898 msg_rc("%s", _("+----[ end of help ]"));
901 /********************************************************************
902 * Status callback routines
903 ********************************************************************/
904 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
905 vlc_value_t oldval, vlc_value_t newval, void *p_data )
908 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
909 intf_thread_t *p_intf = (intf_thread_t*)p_data;
911 vlc_mutex_lock( &p_intf->p_sys->status_lock );
912 msg_rc( STATUS_CHANGE "( audio volume: %ld )",
913 lroundf(newval.f_float * AOUT_VOLUME_DEFAULT) );
914 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
918 static void StateChanged( intf_thread_t *p_intf, input_thread_t *p_input )
920 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
923 const int i_status = playlist_Status( p_playlist );
930 case PLAYLIST_STOPPED:
933 case PLAYLIST_RUNNING:
936 case PLAYLIST_PAUSED:
945 const int i_state = var_GetInteger( p_input, "state" );
947 vlc_mutex_lock( &p_intf->p_sys->status_lock );
948 msg_rc( STATUS_CHANGE "( %s state: %d ): %s", psz_cmd,
949 i_state, ppsz_input_state[i_state] );
950 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
952 static void RateChanged( intf_thread_t *p_intf,
953 input_thread_t *p_input )
955 vlc_mutex_lock( &p_intf->p_sys->status_lock );
956 msg_rc( STATUS_CHANGE "( new rate: %.3f )",
957 var_GetFloat( p_input, "rate" ) );
958 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
960 static void PositionChanged( intf_thread_t *p_intf,
961 input_thread_t *p_input )
963 vlc_mutex_lock( &p_intf->p_sys->status_lock );
964 if( p_intf->p_sys->b_input_buffering )
965 msg_rc( STATUS_CHANGE "( time: %"PRId64"s )",
966 (var_GetTime( p_input, "time" )/1000000) );
967 p_intf->p_sys->b_input_buffering = false;
968 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
970 static void CacheChanged( intf_thread_t *p_intf )
972 vlc_mutex_lock( &p_intf->p_sys->status_lock );
973 p_intf->p_sys->b_input_buffering = true;
974 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
977 static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
978 vlc_value_t oldval, vlc_value_t newval, void *p_data )
982 input_thread_t *p_input = (input_thread_t*)p_this;
983 intf_thread_t *p_intf = p_data;
985 switch( newval.i_int )
987 case INPUT_EVENT_STATE:
988 case INPUT_EVENT_DEAD:
989 StateChanged( p_intf, p_input );
991 case INPUT_EVENT_RATE:
992 RateChanged( p_intf, p_input );
994 case INPUT_EVENT_POSITION:
995 PositionChanged( p_intf, p_input );
997 case INPUT_EVENT_CACHE:
998 CacheChanged( p_intf );
1006 /********************************************************************
1008 ********************************************************************/
1009 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1010 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1012 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1013 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1014 input_thread_t *p_input =
1015 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1016 int i_error = VLC_EGENERIC;
1021 int state = var_GetInteger( p_input, "state" );
1022 if( ( state == PAUSE_S ) &&
1023 ( strcmp( psz_cmd, "pause" ) != 0 ) && (strcmp( psz_cmd,"frame") != 0 ) )
1025 msg_rc( "%s", _("Press menu select or pause to continue.") );
1028 /* Parse commands that only require an input */
1029 if( !strcmp( psz_cmd, "pause" ) )
1031 playlist_Pause( p_intf->p_sys->p_playlist );
1032 i_error = VLC_SUCCESS;
1034 else if( !strcmp( psz_cmd, "seek" ) )
1036 if( strlen( newval.psz_string ) > 0 &&
1037 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1039 float f = atof( newval.psz_string ) / 100.0;
1040 var_SetFloat( p_input, "position", f );
1044 mtime_t t = ((int64_t)atoi( newval.psz_string )) * CLOCK_FREQ;
1045 var_SetTime( p_input, "time", t );
1047 i_error = VLC_SUCCESS;
1049 else if ( !strcmp( psz_cmd, "fastforward" ) )
1051 if( var_GetBool( p_input, "can-rate" ) )
1053 float f_rate = var_GetFloat( p_input, "rate" );
1054 f_rate = (f_rate < 0) ? -f_rate : f_rate * 2;
1055 var_SetFloat( p_input, "rate", f_rate );
1059 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_EXTRASHORT );
1061 i_error = VLC_SUCCESS;
1063 else if ( !strcmp( psz_cmd, "rewind" ) )
1065 if( var_GetBool( p_input, "can-rewind" ) )
1067 float f_rate = var_GetFloat( p_input, "rate" );
1068 f_rate = (f_rate > 0) ? -f_rate : f_rate * 2;
1069 var_SetFloat( p_input, "rate", f_rate );
1073 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_EXTRASHORT );
1075 i_error = VLC_SUCCESS;
1077 else if ( !strcmp( psz_cmd, "faster" ) )
1079 var_TriggerCallback( p_intf->p_sys->p_playlist, "rate-faster" );
1080 i_error = VLC_SUCCESS;
1082 else if ( !strcmp( psz_cmd, "slower" ) )
1084 var_TriggerCallback( p_intf->p_sys->p_playlist, "rate-slower" );
1085 i_error = VLC_SUCCESS;
1087 else if ( !strcmp( psz_cmd, "normal" ) )
1089 var_SetFloat( p_intf->p_sys->p_playlist, "rate", 1. );
1090 i_error = VLC_SUCCESS;
1092 else if ( !strcmp( psz_cmd, "frame" ) )
1094 var_TriggerCallback( p_input, "frame-next" );
1095 i_error = VLC_SUCCESS;
1097 else if( !strcmp( psz_cmd, "chapter" ) ||
1098 !strcmp( psz_cmd, "chapter_n" ) ||
1099 !strcmp( psz_cmd, "chapter_p" ) )
1101 if( !strcmp( psz_cmd, "chapter" ) )
1103 if ( *newval.psz_string )
1106 var_SetInteger( p_input, "chapter", atoi( newval.psz_string ) );
1111 int i_chap = var_GetInteger( p_input, "chapter" );
1112 int i_chapter_count = var_CountChoices( p_input, "chapter" );
1113 msg_rc( "Currently playing chapter %d/%d.", i_chap,
1117 else if( !strcmp( psz_cmd, "chapter_n" ) )
1118 var_TriggerCallback( p_input, "next-chapter" );
1119 else if( !strcmp( psz_cmd, "chapter_p" ) )
1120 var_TriggerCallback( p_input, "prev-chapter" );
1121 i_error = VLC_SUCCESS;
1123 else if( !strcmp( psz_cmd, "title" ) ||
1124 !strcmp( psz_cmd, "title_n" ) ||
1125 !strcmp( psz_cmd, "title_p" ) )
1127 if( !strcmp( psz_cmd, "title" ) )
1129 if ( *newval.psz_string )
1131 var_SetInteger( p_input, "title", atoi( newval.psz_string ) );
1135 int i_title = var_GetInteger( p_input, "title" );
1136 int i_title_count = var_CountChoices( p_input, "title" );
1137 msg_rc( "Currently playing title %d/%d.", i_title,
1141 else if( !strcmp( psz_cmd, "title_n" ) )
1142 var_TriggerCallback( p_input, "next-title" );
1143 else if( !strcmp( psz_cmd, "title_p" ) )
1144 var_TriggerCallback( p_input, "prev-title" );
1146 i_error = VLC_SUCCESS;
1148 else if( !strcmp( psz_cmd, "atrack" )
1149 || !strcmp( psz_cmd, "vtrack" )
1150 || !strcmp( psz_cmd, "strack" ) )
1152 const char *psz_variable;
1153 vlc_value_t val_name;
1155 if( !strcmp( psz_cmd, "atrack" ) )
1157 psz_variable = "audio-es";
1159 else if( !strcmp( psz_cmd, "vtrack" ) )
1161 psz_variable = "video-es";
1165 psz_variable = "spu-es";
1168 /* Get the descriptive name of the variable */
1169 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1171 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1173 if( newval.psz_string && *newval.psz_string )
1176 i_error = var_SetInteger( p_input, psz_variable,
1177 atoi( newval.psz_string ) );
1182 vlc_value_t val, text;
1185 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1187 i_value = val.i_int;
1189 if ( var_Change( p_input, psz_variable,
1190 VLC_VAR_GETLIST, &val, &text ) < 0 )
1193 msg_rc( "+----[ %s ]", val_name.psz_string );
1194 for ( i = 0; i < val.p_list->i_count; i++ )
1196 if ( i_value == val.p_list->p_values[i].i_int )
1197 msg_rc( "| %"PRId64" - %s *",
1198 val.p_list->p_values[i].i_int,
1199 text.p_list->p_values[i].psz_string );
1201 msg_rc( "| %"PRId64" - %s",
1202 val.p_list->p_values[i].i_int,
1203 text.p_list->p_values[i].psz_string );
1205 var_FreeList( &val, &text );
1206 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1208 free( val_name.psz_string );
1211 vlc_object_release( p_input );
1215 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1218 char psz_buffer[MSTRTIME_MAX_SIZE];
1219 for( i = 0; i< p_item->i_children; i++ )
1221 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1223 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1224 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1227 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1229 if( p_item->pp_children[i]->i_children >= 0 )
1230 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1234 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1235 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1237 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1240 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1241 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1242 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1246 int state = var_GetInteger( p_input, "state" );
1247 vlc_object_release( p_input );
1249 if( state == PAUSE_S )
1251 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1252 return VLC_EGENERIC;
1256 /* Parse commands that require a playlist */
1257 if( !strcmp( psz_cmd, "prev" ) )
1259 playlist_Prev( p_playlist );
1261 else if( !strcmp( psz_cmd, "next" ) )
1263 playlist_Next( p_playlist );
1265 else if( !strcmp( psz_cmd, "play" ) )
1267 msg_Warn( p_playlist, "play" );
1268 playlist_Play( p_playlist );
1270 else if( !strcmp( psz_cmd, "repeat" ) )
1272 bool b_update = true;
1274 var_Get( p_playlist, "repeat", &val );
1276 if( strlen( newval.psz_string ) > 0 )
1278 if ( ( !strncmp( newval.psz_string, "on", 2 ) && val.b_bool ) ||
1279 ( !strncmp( newval.psz_string, "off", 3 ) && !val.b_bool ) )
1287 val.b_bool = !val.b_bool;
1288 var_Set( p_playlist, "repeat", val );
1290 msg_rc( "Setting repeat to %d", val.b_bool );
1292 else if( !strcmp( psz_cmd, "loop" ) )
1294 bool b_update = true;
1296 var_Get( p_playlist, "loop", &val );
1298 if( strlen( newval.psz_string ) > 0 )
1300 if ( ( !strncmp( newval.psz_string, "on", 2 ) && val.b_bool ) ||
1301 ( !strncmp( newval.psz_string, "off", 3 ) && !val.b_bool ) )
1309 val.b_bool = !val.b_bool;
1310 var_Set( p_playlist, "loop", val );
1312 msg_rc( "Setting loop to %d", val.b_bool );
1314 else if( !strcmp( psz_cmd, "random" ) )
1316 bool b_update = true;
1318 var_Get( p_playlist, "random", &val );
1320 if( strlen( newval.psz_string ) > 0 )
1322 if ( ( !strncmp( newval.psz_string, "on", 2 ) && val.b_bool ) ||
1323 ( !strncmp( newval.psz_string, "off", 3 ) && !val.b_bool ) )
1331 val.b_bool = !val.b_bool;
1332 var_Set( p_playlist, "random", val );
1334 msg_rc( "Setting random to %d", val.b_bool );
1336 else if (!strcmp( psz_cmd, "goto" ) )
1339 unsigned i_pos = atoi( newval.psz_string );
1340 unsigned i_size = p_playlist->items.i_size;
1343 msg_rc( "%s", _("Error: `goto' needs an argument greater than zero.") );
1344 else if( i_pos <= i_size )
1346 playlist_item_t *p_item, *p_parent;
1347 p_item = p_parent = p_playlist->items.p_elems[i_pos-1];
1348 while( p_parent->p_parent )
1349 p_parent = p_parent->p_parent;
1350 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Locked,
1354 msg_rc( vlc_ngettext("Playlist has only %u element",
1355 "Playlist has only %u elements", i_size),
1359 else if( !strcmp( psz_cmd, "stop" ) )
1361 playlist_Stop( p_playlist );
1363 else if( !strcmp( psz_cmd, "clear" ) )
1365 playlist_Stop( p_playlist );
1366 playlist_Clear( p_playlist, pl_Unlocked );
1368 else if( !strcmp( psz_cmd, "add" ) &&
1369 newval.psz_string && *newval.psz_string )
1371 input_item_t *p_item = parse_MRL( newval.psz_string );
1375 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1376 int i_ret =playlist_AddInput( p_playlist, p_item,
1377 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1379 vlc_gc_decref( p_item );
1380 if( i_ret != VLC_SUCCESS )
1382 return VLC_EGENERIC;
1386 else if( !strcmp( psz_cmd, "enqueue" ) &&
1387 newval.psz_string && *newval.psz_string )
1389 input_item_t *p_item = parse_MRL( newval.psz_string );
1393 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1394 if( playlist_AddInput( p_playlist, p_item,
1395 PLAYLIST_APPEND, PLAYLIST_END, true,
1396 pl_Unlocked ) != VLC_SUCCESS )
1398 return VLC_EGENERIC;
1402 else if( !strcmp( psz_cmd, "playlist" ) )
1404 msg_rc( "+----[ Playlist ]" );
1405 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1406 msg_rc( "+----[ End of playlist ]" );
1409 else if( !strcmp( psz_cmd, "sort" ))
1412 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1413 SORT_ARTIST, ORDER_NORMAL );
1416 else if( !strcmp( psz_cmd, "status" ) )
1418 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1421 /* Replay the current state of the system. */
1423 input_item_GetURI( input_GetItem( p_input ) );
1424 vlc_object_release( p_input );
1425 if( likely(psz_uri != NULL) )
1427 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1432 float volume = playlist_VolumeGet( p_playlist );
1434 msg_rc( STATUS_CHANGE "( audio volume: %ld )",
1435 lroundf(volume * AOUT_VOLUME_DEFAULT) );
1439 status = playlist_Status(p_playlist);
1443 case PLAYLIST_STOPPED:
1444 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1446 case PLAYLIST_RUNNING:
1447 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1449 case PLAYLIST_PAUSED:
1450 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1453 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1463 msg_rc( "unknown command!" );
1469 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1470 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1472 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1473 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1475 libvlc_Quit( p_this->p_libvlc );
1479 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1480 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1482 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1484 return intf_Create( p_this->p_libvlc, newval.psz_string );
1487 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1488 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1490 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1491 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1492 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1493 input_thread_t *p_input = playlist_CurrentInput( p_playlist );
1494 int i_error = VLC_EGENERIC;
1501 int state = var_GetInteger( p_input, "state" );
1502 vlc_object_release( p_input );
1503 if( state == PAUSE_S )
1505 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1506 return VLC_EGENERIC;
1510 if ( *newval.psz_string )
1513 int i_volume = atoi( newval.psz_string );
1514 if( !playlist_VolumeSet( p_playlist,
1515 i_volume / (float)AOUT_VOLUME_DEFAULT ) )
1516 i_error = VLC_SUCCESS;
1517 playlist_MuteSet( p_playlist, i_volume == 0 );
1518 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1523 msg_rc( STATUS_CHANGE "( audio volume: %ld )",
1524 lroundf( playlist_VolumeGet( p_playlist ) * AOUT_VOLUME_DEFAULT ) );
1525 i_error = VLC_SUCCESS;
1531 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1532 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1534 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1535 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1537 input_thread_t *p_input =
1538 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1539 int i_nb_steps = atoi(newval.psz_string);
1540 int i_error = VLC_SUCCESS;
1545 int state = var_GetInteger( p_input, "state" );
1546 vlc_object_release( p_input );
1547 if( state == PAUSE_S )
1549 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1550 return VLC_EGENERIC;
1553 if( !strcmp(psz_cmd, "voldown") )
1555 if( playlist_VolumeUp( p_intf->p_sys->p_playlist, i_nb_steps, &volume ) < 0 )
1556 i_error = VLC_EGENERIC;
1559 msg_rc( STATUS_CHANGE "( audio volume: %ld )",
1560 lroundf( volume * AOUT_VOLUME_DEFAULT ) );
1565 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1566 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1568 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1569 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1570 input_thread_t *p_input =
1571 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1572 vout_thread_t * p_vout;
1573 const char * psz_variable = NULL;
1574 int i_error = VLC_SUCCESS;
1579 p_vout = input_GetVout( p_input );
1580 vlc_object_release( p_input );
1584 if( !strcmp( psz_cmd, "vcrop" ) )
1586 psz_variable = "crop";
1588 else if( !strcmp( psz_cmd, "vratio" ) )
1590 psz_variable = "aspect-ratio";
1592 else if( !strcmp( psz_cmd, "vzoom" ) )
1594 psz_variable = "zoom";
1596 else if( !strcmp( psz_cmd, "snapshot" ) )
1598 psz_variable = "video-snapshot";
1601 /* This case can't happen */
1604 if( newval.psz_string && *newval.psz_string )
1607 if( !strcmp( psz_variable, "zoom" ) )
1610 val.f_float = atof( newval.psz_string );
1611 i_error = var_Set( p_vout, psz_variable, val );
1615 i_error = var_Set( p_vout, psz_variable, newval );
1618 else if( !strcmp( psz_cmd, "snapshot" ) )
1620 var_TriggerCallback( p_vout, psz_variable );
1625 vlc_value_t val_name;
1626 vlc_value_t val, text;
1629 char *psz_value = NULL;
1631 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1633 vlc_object_release( p_vout );
1634 return VLC_EGENERIC;
1636 if( !strcmp( psz_variable, "zoom" ) )
1638 f_value = val.f_float;
1642 psz_value = val.psz_string;
1645 if ( var_Change( p_vout, psz_variable,
1646 VLC_VAR_GETLIST, &val, &text ) < 0 )
1648 vlc_object_release( p_vout );
1650 return VLC_EGENERIC;
1653 /* Get the descriptive name of the variable */
1654 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1656 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1658 msg_rc( "+----[ %s ]", val_name.psz_string );
1659 if( !strcmp( psz_variable, "zoom" ) )
1661 for ( i = 0; i < val.p_list->i_count; i++ )
1663 if ( f_value == val.p_list->p_values[i].f_float )
1664 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1665 text.p_list->p_values[i].psz_string );
1667 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1668 text.p_list->p_values[i].psz_string );
1673 for ( i = 0; i < val.p_list->i_count; i++ )
1675 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1676 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1677 text.p_list->p_values[i].psz_string );
1679 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1680 text.p_list->p_values[i].psz_string );
1684 var_FreeList( &val, &text );
1685 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1687 free( val_name.psz_string );
1689 vlc_object_release( p_vout );
1693 static int AudioDevice( vlc_object_t *obj, char const *cmd,
1694 vlc_value_t old, vlc_value_t cur, void *dummy )
1696 intf_thread_t *p_intf = (intf_thread_t *)obj;
1697 audio_output_t *p_aout = playlist_GetAout( pl_Get(p_intf) );
1698 if( p_aout == NULL )
1701 if( !*cur.psz_string )
1703 char **ids, **names;
1704 int n = aout_DevicesList( p_aout, &ids, &names );
1708 char *dev = aout_DeviceGet( p_aout );
1709 const char *devstr = (dev != NULL) ? dev : "";
1711 msg_rc( "+----[ %s ]", cmd );
1712 for ( int i = 0; i < n; i++ )
1714 const char *fmt = "| %s - %s";
1716 if( !strcmp(devstr, ids[i]) )
1717 fmt = "| %s - %s *";
1718 msg_rc( fmt, ids[i], names[i] );
1722 msg_rc( "+----[ end of %s ]", cmd );
1729 aout_DeviceSet( p_aout, cur.psz_string );
1731 vlc_object_release( p_aout );
1732 (void) old; (void) dummy;
1736 static int AudioChannel( vlc_object_t *obj, char const *cmd,
1737 vlc_value_t old, vlc_value_t cur, void *dummy )
1739 intf_thread_t *p_intf = (intf_thread_t*)obj;
1740 vlc_object_t *p_aout = (vlc_object_t *)playlist_GetAout( pl_Get(p_intf) );
1741 if ( p_aout == NULL )
1744 int ret = VLC_SUCCESS;
1746 if ( !*cur.psz_string )
1748 /* Retrieve all registered ***. */
1749 vlc_value_t val, text;
1750 if ( var_Change( p_aout, "stereo-mode",
1751 VLC_VAR_GETLIST, &val, &text ) < 0 )
1757 int i_value = var_GetInteger( p_aout, "stereo-mode" );
1759 msg_rc( "+----[ %s ]", cmd );
1760 for ( int i = 0; i < val.p_list->i_count; i++ )
1762 if ( i_value == val.p_list->p_values[i].i_int )
1763 msg_rc( "| %"PRId64" - %s *", val.p_list->p_values[i].i_int,
1764 text.p_list->p_values[i].psz_string );
1766 msg_rc( "| %"PRId64" - %s", val.p_list->p_values[i].i_int,
1767 text.p_list->p_values[i].psz_string );
1769 var_FreeList( &val, &text );
1770 msg_rc( "+----[ end of %s ]", cmd );
1773 ret = var_SetInteger( p_aout, "stereo-mode", atoi( cur.psz_string ) );
1775 vlc_object_release( p_aout );
1776 (void) old; (void) dummy;
1780 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1781 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1783 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1784 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1785 input_thread_t *p_input =
1786 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1791 updateStatistics( p_intf, input_GetItem(p_input) );
1792 vlc_object_release( p_input );
1796 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1798 if( !p_item ) return VLC_EGENERIC;
1800 vlc_mutex_lock( &p_item->lock );
1801 vlc_mutex_lock( &p_item->p_stats->lock );
1802 msg_rc( "+----[ begin of statistical info ]" );
1805 msg_rc("%s", _("+-[Incoming]"));
1806 msg_rc(_("| input bytes read : %8.0f KiB"),
1807 (float)(p_item->p_stats->i_read_bytes)/1024 );
1808 msg_rc(_("| input bitrate : %6.0f kb/s"),
1809 (float)(p_item->p_stats->f_input_bitrate)*8000 );
1810 msg_rc(_("| demux bytes read : %8.0f KiB"),
1811 (float)(p_item->p_stats->i_demux_read_bytes)/1024 );
1812 msg_rc(_("| demux bitrate : %6.0f kb/s"),
1813 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
1814 msg_rc(_("| demux corrupted : %5"PRIi64),
1815 p_item->p_stats->i_demux_corrupted );
1816 msg_rc(_("| discontinuities : %5"PRIi64),
1817 p_item->p_stats->i_demux_discontinuity );
1820 msg_rc("%s", _("+-[Video Decoding]"));
1821 msg_rc(_("| video decoded : %5"PRIi64),
1822 p_item->p_stats->i_decoded_video );
1823 msg_rc(_("| frames displayed : %5"PRIi64),
1824 p_item->p_stats->i_displayed_pictures );
1825 msg_rc(_("| frames lost : %5"PRIi64),
1826 p_item->p_stats->i_lost_pictures );
1829 msg_rc("%s", _("+-[Audio Decoding]"));
1830 msg_rc(_("| audio decoded : %5"PRIi64),
1831 p_item->p_stats->i_decoded_audio );
1832 msg_rc(_("| buffers played : %5"PRIi64),
1833 p_item->p_stats->i_played_abuffers );
1834 msg_rc(_("| buffers lost : %5"PRIi64),
1835 p_item->p_stats->i_lost_abuffers );
1838 msg_rc("%s", _("+-[Streaming]"));
1839 msg_rc(_("| packets sent : %5"PRIi64),
1840 p_item->p_stats->i_sent_packets );
1841 msg_rc(_("| bytes sent : %8.0f KiB"),
1842 (float)(p_item->p_stats->i_sent_bytes)/1024 );
1843 msg_rc(_("| sending bitrate : %6.0f kb/s"),
1844 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
1846 msg_rc( "+----[ end of statistical info ]" );
1847 vlc_mutex_unlock( &p_item->p_stats->lock );
1848 vlc_mutex_unlock( &p_item->lock );
1854 static bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1856 INPUT_RECORD input_record;
1859 /* On Win32, select() only works on socket descriptors */
1860 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1861 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1863 while( *pi_size < MAX_LINE_LENGTH &&
1864 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1867 if( input_record.EventType != KEY_EVENT ||
1868 !input_record.Event.KeyEvent.bKeyDown ||
1869 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1870 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1871 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1872 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1874 /* nothing interesting */
1878 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1880 /* Echo out the command */
1881 putc( p_buffer[ *pi_size ], stdout );
1883 /* Handle special keys */
1884 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1886 putc( '\n', stdout );
1889 switch( p_buffer[ *pi_size ] )
1895 putc( ' ', stdout );
1896 putc( '\b', stdout );
1907 if( *pi_size == MAX_LINE_LENGTH ||
1908 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1910 p_buffer[ *pi_size ] = 0;
1919 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1924 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1925 return ReadWin32( p_intf, p_buffer, pi_size );
1926 else if( p_intf->p_sys->i_socket == -1 )
1928 msleep( INTF_IDLE_SLEEP );
1933 while( *pi_size < MAX_LINE_LENGTH &&
1934 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
1935 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1936 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
1938 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1944 /* Connection closed */
1947 if( p_intf->p_sys->i_socket != -1 )
1949 net_Close( p_intf->p_sys->i_socket );
1950 p_intf->p_sys->i_socket = -1;
1954 /* Standard input closed: exit */
1956 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
1959 p_buffer[ *pi_size ] = 0;
1963 if( *pi_size == MAX_LINE_LENGTH ||
1964 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1966 p_buffer[ *pi_size ] = 0;
1973 /*****************************************************************************
1974 * parse_MRL: build a input item from a full mrl
1975 *****************************************************************************
1976 * MRL format: "simplified-mrl [:option-name[=option-value]]"
1977 * We don't check for '"' or '\'', we just assume that a ':' that follows a
1978 * space is a new option. Should be good enough for our purpose.
1979 *****************************************************************************/
1980 static input_item_t *parse_MRL( const char *mrl )
1982 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
1983 #define SKIPTRAILINGSPACE( p, d ) \
1984 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
1986 input_item_t *p_item = NULL;
1987 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig, *psz_mrl;
1988 char **ppsz_options = NULL;
1989 int i, i_options = 0;
1991 if( !mrl ) return 0;
1993 psz_mrl = psz_orig = strdup( mrl );
1998 SKIPSPACE( psz_mrl );
2001 for( ; *psz_mrl; psz_mrl++ )
2003 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2005 /* We have a complete item */
2008 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2009 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2011 /* We have a complete item */
2016 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2017 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2019 /* Remove '"' and '\'' if necessary */
2020 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2021 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2022 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2023 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2027 if( strstr( psz_item, "://" ) != NULL )
2028 psz_item_mrl = strdup( psz_item );
2030 psz_item_mrl = vlc_path2uri( psz_item, NULL );
2031 if( psz_item_mrl == NULL )
2037 else if( *psz_item )
2040 ppsz_options = xrealloc( ppsz_options, i_options * sizeof(char *) );
2041 ppsz_options[i_options - 1] = &psz_item[1];
2044 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2047 /* Now create a playlist item */
2050 p_item = input_item_New( psz_item_mrl, NULL );
2051 for( i = 0; i < i_options; i++ )
2053 input_item_AddOption( p_item, ppsz_options[i], VLC_INPUT_OPTION_TRUSTED );
2055 free( psz_item_mrl );
2058 if( i_options ) free( ppsz_options );