1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2007 the VideoLAN team
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8 * Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
35 #include <errno.h> /* ENOMEM */
39 #include <vlc_interface.h>
43 #include <vlc_playlist.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
52 #include <sys/types.h>
54 #include <vlc_network.h>
57 #include <vlc_charset.h>
59 #if defined(AF_UNIX) && !defined(AF_LOCAL)
60 # define AF_LOCAL AF_UNIX
63 #if defined(AF_LOCAL) && ! defined(WIN32)
67 #define MAX_LINE_LENGTH 256
68 #define STATUS_CHANGE "status change: "
70 /* input_state_e from <vlc_input.h> */
71 static const char *ppsz_input_state[] = {
84 /*****************************************************************************
86 *****************************************************************************/
87 static int Activate ( vlc_object_t * );
88 static void Deactivate ( vlc_object_t * );
89 static void Run ( intf_thread_t * );
91 static void Help ( intf_thread_t *, bool );
92 static void RegisterCallbacks( intf_thread_t * );
94 static bool ReadCommand( intf_thread_t *, char *, int * );
96 static input_item_t *parse_MRL( intf_thread_t *, char * );
98 static int Input ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int Playlist ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int Quit ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int Intf ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int Volume ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int VolumeMove ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
110 static int VideoConfig ( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t, void * );
112 static int AudioConfig ( vlc_object_t *, char const *,
113 vlc_value_t, vlc_value_t, void * );
114 static int Menu ( vlc_object_t *, char const *,
115 vlc_value_t, vlc_value_t, void * );
116 static int Statistics ( vlc_object_t *, char const *,
117 vlc_value_t, vlc_value_t, void * );
119 static int updateStatistics( intf_thread_t *, input_item_t *);
121 /* Status Callbacks */
122 static int TimeOffsetChanged( vlc_object_t *, char const *,
123 vlc_value_t, vlc_value_t , void * );
124 static int VolumeChanged ( vlc_object_t *, char const *,
125 vlc_value_t, vlc_value_t, void * );
126 static int StateChanged ( vlc_object_t *, char const *,
127 vlc_value_t, vlc_value_t, void * );
128 static int RateChanged ( vlc_object_t *, char const *,
129 vlc_value_t, vlc_value_t, void * );
133 int *pi_socket_listen;
138 vlc_mutex_t status_lock;
139 playlist_status_t i_last_state;
147 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
149 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
152 va_start( args, psz_fmt );
154 if( p_intf->p_sys->i_socket == -1 )
156 utf8_vfprintf( stdout, psz_fmt, args );
161 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
162 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
167 /*****************************************************************************
169 *****************************************************************************/
170 #define POS_TEXT N_("Show stream position")
171 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
172 "stream from time to time." )
174 #define TTY_TEXT N_("Fake TTY")
175 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
177 #define UNIX_TEXT N_("UNIX socket command input")
178 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
181 #define HOST_TEXT N_("TCP command input")
182 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
183 "You can set the address and port the interface will bind to." )
186 #define QUIET_TEXT N_("Do not open a DOS command box interface")
187 #define QUIET_LONGTEXT N_( \
188 "By default the rc interface plugin will start a DOS command box. " \
189 "Enabling the quiet mode will not bring this command box but can also " \
190 "be pretty annoying when you want to stop VLC and no video window is " \
195 set_shortname( N_("RC"));
196 set_category( CAT_INTERFACE );
197 set_subcategory( SUBCAT_INTERFACE_MAIN );
198 set_description( N_("Remote control interface") );
199 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, true );
202 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, false );
204 #if defined (HAVE_ISATTY)
205 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, true );
207 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, true );
209 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, true );
211 set_capability( "interface", 20 );
213 set_callbacks( Activate, Deactivate );
216 /*****************************************************************************
217 * Activate: initialize and create stuff
218 *****************************************************************************/
219 static int Activate( vlc_object_t *p_this )
221 intf_thread_t *p_intf = (intf_thread_t*)p_this;
222 char *psz_host, *psz_unix_path;
223 int *pi_socket = NULL;
226 #if defined(HAVE_ISATTY)
227 /* Check that stdin is a TTY */
228 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
230 msg_Warn( p_intf, "fd 0 is not a TTY" );
235 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
241 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
242 free( psz_unix_path );
245 struct sockaddr_un addr;
247 memset( &addr, 0, sizeof(struct sockaddr_un) );
249 msg_Dbg( p_intf, "trying UNIX socket" );
251 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
253 msg_Warn( p_intf, "can't open socket: %m" );
254 free( psz_unix_path );
258 addr.sun_family = AF_LOCAL;
259 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
260 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
262 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
263 && (errno == EADDRINUSE)
264 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
265 && (errno == ECONNREFUSED))
267 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
268 unlink (psz_unix_path);
270 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
272 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
274 free (psz_unix_path);
275 net_Close (i_socket);
280 if( listen( i_socket, 1 ) )
282 msg_Warn( p_intf, "can't listen on socket: %m");
283 free( psz_unix_path );
284 net_Close( i_socket );
288 /* FIXME: we need a core function to merge listening sockets sets */
289 pi_socket = calloc( 2, sizeof( int ) );
290 if( pi_socket == NULL )
292 free( psz_unix_path );
293 net_Close( i_socket );
296 pi_socket[0] = i_socket;
298 #endif /* AF_LOCAL */
302 if( ( pi_socket == NULL ) &&
303 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
307 vlc_UrlParse( &url, psz_host, 0 );
309 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
311 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
312 if( pi_socket == NULL )
314 msg_Warn( p_intf, "can't listen to %s port %i",
315 url.psz_host, url.i_port );
316 vlc_UrlClean( &url );
321 vlc_UrlClean( &url );
325 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
329 p_intf->p_sys->pi_socket_listen = pi_socket;
330 p_intf->p_sys->i_socket = -1;
331 p_intf->p_sys->psz_unix_path = psz_unix_path;
332 vlc_mutex_init( &p_intf->p_sys->status_lock );
333 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
335 /* Non-buffered stdout */
336 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
338 p_intf->pf_run = Run;
341 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
342 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
347 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
351 /*****************************************************************************
352 * Deactivate: uninitialize and cleanup
353 *****************************************************************************/
354 static void Deactivate( vlc_object_t *p_this )
356 intf_thread_t *p_intf = (intf_thread_t*)p_this;
358 net_ListenClose( p_intf->p_sys->pi_socket_listen );
359 if( p_intf->p_sys->i_socket != -1 )
360 net_Close( p_intf->p_sys->i_socket );
361 if( p_intf->p_sys->psz_unix_path != NULL )
363 #if defined(AF_LOCAL) && !defined(WIN32)
364 unlink( p_intf->p_sys->psz_unix_path );
366 free( p_intf->p_sys->psz_unix_path );
368 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
369 free( p_intf->p_sys );
372 /*****************************************************************************
373 * RegisterCallbacks: Register callbacks to dynamic variables
374 *****************************************************************************/
375 static void RegisterCallbacks( intf_thread_t *p_intf )
377 /* Register commands that will be cleaned up upon object destruction */
378 #define ADD( name, type, target ) \
379 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
380 var_AddCallback( p_intf, name, target, NULL );
381 ADD( "quit", VOID, Quit )
382 ADD( "intf", STRING, Intf )
384 ADD( "add", STRING, Playlist )
385 ADD( "repeat", STRING, Playlist )
386 ADD( "loop", STRING, Playlist )
387 ADD( "random", STRING, Playlist )
388 ADD( "enqueue", STRING, Playlist )
389 ADD( "playlist", VOID, Playlist )
390 ADD( "sort", VOID, Playlist )
391 ADD( "play", VOID, Playlist )
392 ADD( "stop", VOID, Playlist )
393 ADD( "clear", VOID, Playlist )
394 ADD( "prev", VOID, Playlist )
395 ADD( "next", VOID, Playlist )
396 ADD( "goto", INTEGER, Playlist )
397 ADD( "status", INTEGER, Playlist )
399 /* OSD menu commands */
400 ADD( "menu", STRING, Menu )
403 ADD( "pause", VOID, Input )
404 ADD( "seek", INTEGER, Input )
405 ADD( "title", STRING, Input )
406 ADD( "title_n", VOID, Input )
407 ADD( "title_p", VOID, Input )
408 ADD( "chapter", STRING, Input )
409 ADD( "chapter_n", VOID, Input )
410 ADD( "chapter_p", VOID, Input )
412 ADD( "fastforward", VOID, Input )
413 ADD( "rewind", VOID, Input )
414 ADD( "faster", VOID, Input )
415 ADD( "slower", VOID, Input )
416 ADD( "normal", VOID, Input )
418 ADD( "atrack", STRING, Input )
419 ADD( "vtrack", STRING, Input )
420 ADD( "strack", STRING, Input )
423 ADD( "vratio", STRING, VideoConfig )
424 ADD( "vcrop", STRING, VideoConfig )
425 ADD( "vzoom", STRING, VideoConfig )
426 ADD( "snapshot", VOID, VideoConfig )
429 ADD( "volume", STRING, Volume )
430 ADD( "volup", STRING, VolumeMove )
431 ADD( "voldown", STRING, VolumeMove )
432 ADD( "adev", STRING, AudioConfig )
433 ADD( "achan", STRING, AudioConfig )
435 /* misc menu commands */
436 ADD( "stats", BOOL, Statistics )
441 /*****************************************************************************
443 *****************************************************************************
444 * This part of the interface is in a separate thread so that we can call
445 * exec() from within it without annoying the rest of the program.
446 *****************************************************************************/
447 static void Run( intf_thread_t *p_intf )
449 input_thread_t * p_input;
450 playlist_t * p_playlist;
452 char p_buffer[ MAX_LINE_LENGTH + 1 ];
453 bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
454 bool b_longhelp = false;
464 /* Register commands that will be cleaned up upon object destruction */
465 RegisterCallbacks( p_intf );
467 /* status callbacks */
468 /* Listen to audio volume updates */
469 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
472 /* Get the file descriptor of the console input */
473 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
474 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
476 msg_Err( p_intf, "couldn't find user input handle" );
477 vlc_object_kill( p_intf );
481 while( !intf_ShouldDie( p_intf ) )
483 char *psz_cmd, *psz_arg;
486 if( p_intf->p_sys->pi_socket_listen != NULL &&
487 p_intf->p_sys->i_socket == -1 )
489 p_intf->p_sys->i_socket =
490 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
492 if( p_intf->p_sys->i_socket == -1 ) continue;
495 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
497 /* Manage the input part */
498 if( p_input == NULL )
502 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
507 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
511 p_playlist = pl_Yield( p_input );
514 /* New input has been registered */
517 if( !p_input->b_dead || vlc_object_alive (p_input) )
520 input_item_GetURI( input_GetItem( p_input ) );
521 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
523 msg_rc( STATUS_CHANGE "( audio volume: %d )",
524 config_GetInt( p_intf, "volume" ));
526 var_AddCallback( p_input, "state", StateChanged, p_intf );
527 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
528 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
529 var_AddCallback( p_input, "rate", RateChanged, p_intf );
530 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
534 else if( p_input->b_dead )
536 var_DelCallback( p_input, "state", StateChanged, p_intf );
537 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
538 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
539 var_DelCallback( p_input, "rate", RateChanged, p_intf );
540 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
542 vlc_object_release( p_input );
547 vlc_object_lock( p_playlist );
548 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
549 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
550 vlc_object_unlock( p_playlist );
554 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
555 (p_playlist != NULL) )
557 vlc_object_lock( p_playlist );
558 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
559 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
561 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
562 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
565 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
566 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
568 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
569 msg_rc( STATUS_CHANGE "( play state: 3 )" );
572 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
573 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
575 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
576 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
578 vlc_object_unlock( p_playlist );
581 if( p_input && b_showpos )
583 i_newpos = 100 * var_GetFloat( p_input, "position" );
584 if( i_oldpos != i_newpos )
587 msg_rc( "pos: %d%%", i_newpos );
591 /* Is there something to do? */
592 if( !b_complete ) continue;
594 /* Skip heading spaces */
596 while( *psz_cmd == ' ' )
601 /* Split psz_cmd at the first space and make sure that
602 * psz_arg is valid */
603 psz_arg = strchr( psz_cmd, ' ' );
607 while( *psz_arg == ' ' )
617 /* module specfic commands: @<module name> <command> <args...> */
618 if( *psz_cmd == '@' && *psz_arg )
620 /* Parse miscellaneous commands */
621 char *psz_alias = psz_cmd + 1;
622 char *psz_mycmd = strdup( psz_arg );
623 char *psz_myarg = strchr( psz_mycmd, ' ' );
628 msg_rc( "Not enough parameters." );
635 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
646 /* If the user typed a registered local command, try it */
647 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
652 val.psz_string = psz_arg;
653 i_ret = var_Set( p_intf, psz_cmd, val );
654 msg_rc( "%s: returned %i (%s)",
655 psz_cmd, i_ret, vlc_error( i_ret ) );
657 /* Or maybe it's a global command */
658 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
663 val.psz_string = psz_arg;
664 /* FIXME: it's a global command, but we should pass the
665 * local object as an argument, not p_intf->p_libvlc. */
666 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
669 msg_rc( "%s: returned %i (%s)",
670 psz_cmd, i_ret, vlc_error( i_ret ) );
673 else if( !strcmp( psz_cmd, "logout" ) )
675 /* Close connection */
676 if( p_intf->p_sys->i_socket != -1 )
678 net_Close( p_intf->p_sys->i_socket );
680 p_intf->p_sys->i_socket = -1;
682 else if( !strcmp( psz_cmd, "info" ) )
687 vlc_mutex_lock( &input_GetItem(p_input)->lock );
688 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
690 info_category_t *p_category = input_GetItem(p_input)
693 msg_rc( "+----[ %s ]", p_category->psz_name );
695 for ( j = 0; j < p_category->i_infos; j++ )
697 info_t *p_info = p_category->pp_infos[j];
698 msg_rc( "| %s: %s", p_info->psz_name,
703 msg_rc( "+----[ end of stream info ]" );
704 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
708 msg_rc( "no input" );
711 else if( !strcmp( psz_cmd, "is_playing" ) )
722 else if( !strcmp( psz_cmd, "get_time" ) )
731 var_Get( p_input, "time", &time );
732 msg_rc( "%i", time.i_time / 1000000);
735 else if( !strcmp( psz_cmd, "get_length" ) )
744 var_Get( p_input, "length", &time );
745 msg_rc( "%i", time.i_time / 1000000);
748 else if( !strcmp( psz_cmd, "get_title" ) )
756 msg_rc( "%s", input_GetItem(p_input)->psz_name );
759 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
760 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
762 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
764 else b_longhelp = false;
766 Help( p_intf, b_longhelp );
768 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
770 var_SetInteger( p_intf->p_libvlc, "key-pressed",
771 config_GetInt( p_intf, psz_arg ) );
773 else switch( psz_cmd[0] )
779 vout_thread_t *p_vout;
780 p_vout = vlc_object_find( p_input,
781 VLC_OBJECT_VOUT, FIND_CHILD );
786 bool b_update = false;
787 var_Get( p_vout, "fullscreen", &val );
788 val.b_bool = !val.b_bool;
789 if( !strncmp( psz_arg, "on", 2 )
790 && ( val.b_bool == true ) )
795 else if( !strncmp( psz_arg, "off", 3 )
796 && ( val.b_bool == false ) )
801 else if( strncmp( psz_arg, "off", 3 )
802 && strncmp( psz_arg, "on", 2 ) )
804 if( b_update ) var_Set( p_vout, "fullscreen", val );
805 vlc_object_release( p_vout );
816 /* Ignore empty lines */
820 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
824 /* Command processed */
825 i_size = 0; p_buffer[0] = 0;
828 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
829 msg_rc( STATUS_CHANGE "( quit )" );
833 var_DelCallback( p_input, "state", StateChanged, p_intf );
834 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
835 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
836 var_DelCallback( p_input, "rate", RateChanged, p_intf );
837 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
838 vlc_object_release( p_input );
844 vlc_object_release( p_playlist );
848 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
851 static void Help( intf_thread_t *p_intf, bool b_longhelp)
853 msg_rc(_("+----[ Remote control commands ]"));
855 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
856 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
857 msg_rc(_("| playlist . . . . . show items currently in playlist"));
858 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
859 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
860 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
861 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
862 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
863 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
864 msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
865 msg_rc(_("| random [on|off] . . . . . . . toggle random jumping"));
866 msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
867 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
868 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
869 msg_rc(_("| title_n . . . . . . . . next title in current item"));
870 msg_rc(_("| title_p . . . . . . previous title in current item"));
871 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
872 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
873 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
875 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
876 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
877 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
878 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
879 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
880 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
881 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
882 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
883 msg_rc(_("| info . . . . . information about the current stream"));
884 msg_rc(_("| stats . . . . . . . . show statistical information"));
885 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
886 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
887 msg_rc(_("| get_title . . . . . the title of the current stream"));
888 msg_rc(_("| get_length . . . . the length of the current stream"));
890 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
891 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
892 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
893 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
894 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
895 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
896 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
897 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
898 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
899 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
900 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
901 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
902 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
903 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
908 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
909 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
910 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
911 msg_rc(_("| @name marq-position #. . . .relative position control"));
912 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
913 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
914 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
915 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
917 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
918 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
919 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
920 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
921 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
923 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
924 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
925 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
926 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
927 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
928 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
929 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
930 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
931 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
932 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
933 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
934 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
935 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
936 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
939 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
940 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
941 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
942 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
944 msg_rc(_("+----[ end of help ]"));
947 /********************************************************************
948 * Status callback routines
949 ********************************************************************/
950 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
951 vlc_value_t oldval, vlc_value_t newval, void *p_data )
953 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
954 VLC_UNUSED(oldval); VLC_UNUSED(newval);
955 intf_thread_t *p_intf = (intf_thread_t*)p_data;
956 input_thread_t *p_input = NULL;
958 vlc_mutex_lock( &p_intf->p_sys->status_lock );
959 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
962 msg_rc( STATUS_CHANGE "( time-offset: %d )",
963 var_GetInteger( p_input, "time-offset" ) );
964 vlc_object_release( p_input );
966 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
970 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
971 vlc_value_t oldval, vlc_value_t newval, void *p_data )
973 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
974 intf_thread_t *p_intf = (intf_thread_t*)p_data;
976 vlc_mutex_lock( &p_intf->p_sys->status_lock );
977 msg_rc( STATUS_CHANGE "( audio volume: %d )",
978 config_GetInt( p_this, "volume") );
979 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
983 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
984 vlc_value_t oldval, vlc_value_t newval, void *p_data )
986 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
987 intf_thread_t *p_intf = (intf_thread_t*)p_data;
988 playlist_t *p_playlist = NULL;
989 input_thread_t *p_input = NULL;
991 vlc_mutex_lock( &p_intf->p_sys->status_lock );
992 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
995 p_playlist = pl_Yield( p_input );
997 switch( p_playlist->status.i_status )
999 case PLAYLIST_STOPPED:
1000 strcpy( cmd, "stop" );
1002 case PLAYLIST_RUNNING:
1003 strcpy( cmd, "play" );
1005 case PLAYLIST_PAUSED:
1006 strcpy( cmd, "pause" );
1010 } /* var_GetInteger( p_input, "state" ) */
1011 msg_rc( STATUS_CHANGE "( %s state: %d ): %s",
1013 ppsz_input_state[ newval.i_int ] );
1014 vlc_object_release( p_playlist );
1015 vlc_object_release( p_input );
1017 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1021 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1022 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1024 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
1025 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1026 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1027 input_thread_t *p_input = NULL;
1029 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1030 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1033 msg_rc( STATUS_CHANGE "( new rate: %d )",
1034 var_GetInteger( p_input, "rate" ) );
1035 vlc_object_release( p_input );
1037 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1041 /********************************************************************
1043 ********************************************************************/
1044 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1045 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1047 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1048 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1049 input_thread_t *p_input;
1052 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1053 if( !p_input ) return VLC_ENOOBJ;
1055 var_Get( p_input, "state", &val );
1056 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1057 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1059 msg_rc( _("Press menu select or pause to continue.") );
1060 vlc_object_release( p_input );
1061 return VLC_EGENERIC;
1064 /* Parse commands that only require an input */
1065 if( !strcmp( psz_cmd, "pause" ) )
1067 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1068 var_Set( p_intf->p_libvlc, "key-pressed", val );
1069 vlc_object_release( p_input );
1072 else if( !strcmp( psz_cmd, "seek" ) )
1074 if( strlen( newval.psz_string ) > 0 &&
1075 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1077 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1078 var_Set( p_input, "position", val );
1082 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1083 var_Set( p_input, "time", val );
1085 vlc_object_release( p_input );
1088 else if ( !strcmp( psz_cmd, "fastforward" ) )
1090 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1091 var_Set( p_intf->p_libvlc, "key-pressed", val );
1092 vlc_object_release( p_input );
1095 else if ( !strcmp( psz_cmd, "rewind" ) )
1097 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1098 var_Set( p_intf->p_libvlc, "key-pressed", val );
1099 vlc_object_release( p_input );
1102 else if ( !strcmp( psz_cmd, "faster" ) )
1104 var_Set( p_input, "rate-faster", val );
1105 vlc_object_release( p_input );
1108 else if ( !strcmp( psz_cmd, "slower" ) )
1110 var_Set( p_input, "rate-slower", val );
1111 vlc_object_release( p_input );
1114 else if ( !strcmp( psz_cmd, "normal" ) )
1116 val.i_int = INPUT_RATE_DEFAULT;
1117 var_Set( p_input, "rate", val );
1118 vlc_object_release( p_input );
1121 else if( !strcmp( psz_cmd, "chapter" ) ||
1122 !strcmp( psz_cmd, "chapter_n" ) ||
1123 !strcmp( psz_cmd, "chapter_p" ) )
1125 if( !strcmp( psz_cmd, "chapter" ) )
1127 if ( *newval.psz_string )
1130 val.i_int = atoi( newval.psz_string );
1131 var_Set( p_input, "chapter", val );
1135 vlc_value_t val_list;
1138 var_Get( p_input, "chapter", &val );
1139 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1141 msg_rc( "Currently playing chapter %d/%d.",
1142 val.i_int, val_list.p_list->i_count );
1143 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1147 else if( !strcmp( psz_cmd, "chapter_n" ) )
1150 var_Set( p_input, "next-chapter", val );
1152 else if( !strcmp( psz_cmd, "chapter_p" ) )
1155 var_Set( p_input, "prev-chapter", val );
1157 vlc_object_release( p_input );
1160 else if( !strcmp( psz_cmd, "title" ) ||
1161 !strcmp( psz_cmd, "title_n" ) ||
1162 !strcmp( psz_cmd, "title_p" ) )
1164 if( !strcmp( psz_cmd, "title" ) )
1166 if ( *newval.psz_string )
1169 val.i_int = atoi( newval.psz_string );
1170 var_Set( p_input, "title", val );
1174 vlc_value_t val_list;
1177 var_Get( p_input, "title", &val );
1178 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1180 msg_rc( "Currently playing title %d/%d.",
1181 val.i_int, val_list.p_list->i_count );
1182 var_Change( p_this, "title", VLC_VAR_FREELIST,
1186 else if( !strcmp( psz_cmd, "title_n" ) )
1189 var_Set( p_input, "next-title", val );
1191 else if( !strcmp( psz_cmd, "title_p" ) )
1194 var_Set( p_input, "prev-title", val );
1197 vlc_object_release( p_input );
1200 else if( !strcmp( psz_cmd, "atrack" )
1201 || !strcmp( psz_cmd, "vtrack" )
1202 || !strcmp( psz_cmd, "strack" ) )
1204 const char *psz_variable;
1205 vlc_value_t val_name;
1208 if( !strcmp( psz_cmd, "atrack" ) )
1210 psz_variable = "audio-es";
1212 else if( !strcmp( psz_cmd, "vtrack" ) )
1214 psz_variable = "video-es";
1218 psz_variable = "spu-es";
1221 /* Get the descriptive name of the variable */
1222 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1224 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1226 if( newval.psz_string && *newval.psz_string )
1230 val.i_int = atoi( newval.psz_string );
1232 i_error = var_Set( p_input, psz_variable, val );
1237 vlc_value_t val, text;
1240 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1242 vlc_object_release( p_input );
1243 return VLC_EGENERIC;
1245 i_value = val.i_int;
1247 if ( var_Change( p_input, psz_variable,
1248 VLC_VAR_GETLIST, &val, &text ) < 0 )
1250 vlc_object_release( p_input );
1251 return VLC_EGENERIC;
1254 msg_rc( "+----[ %s ]", val_name.psz_string );
1255 for ( i = 0; i < val.p_list->i_count; i++ )
1257 if ( i_value == val.p_list->p_values[i].i_int )
1258 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1259 text.p_list->p_values[i].psz_string );
1261 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1262 text.p_list->p_values[i].psz_string );
1264 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1266 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1268 free( val_name.psz_string );
1270 i_error = VLC_SUCCESS;
1272 vlc_object_release( p_input );
1276 /* Never reached. */
1277 vlc_object_release( p_input );
1278 return VLC_EGENERIC;
1281 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1284 char psz_buffer[MSTRTIME_MAX_SIZE];
1285 for( i = 0; i< p_item->i_children; i++ )
1287 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1289 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1290 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1293 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1295 if( p_item->pp_children[i]->i_children >= 0 )
1296 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1300 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1301 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1303 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1306 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1307 playlist_t *p_playlist = pl_Yield( p_this );
1310 if( p_playlist->p_input )
1312 var_Get( p_playlist->p_input, "state", &val );
1313 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1315 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1316 vlc_object_release( p_playlist );
1318 return VLC_EGENERIC;
1323 /* Parse commands that require a playlist */
1324 if( !strcmp( psz_cmd, "prev" ) )
1326 playlist_Prev( p_playlist );
1328 else if( !strcmp( psz_cmd, "next" ) )
1330 playlist_Next( p_playlist );
1332 else if( !strcmp( psz_cmd, "play" ) )
1334 msg_Warn( p_playlist, "play" );
1335 playlist_Play( p_playlist );
1337 else if( !strcmp( psz_cmd, "repeat" ) )
1339 bool b_update = true;
1341 var_Get( p_playlist, "repeat", &val );
1343 if( strlen( newval.psz_string ) > 0 )
1345 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1346 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1354 val.b_bool = !val.b_bool;
1355 var_Set( p_playlist, "repeat", val );
1357 msg_rc( "Setting repeat to %d", val.b_bool );
1359 else if( !strcmp( psz_cmd, "loop" ) )
1361 bool b_update = true;
1363 var_Get( p_playlist, "loop", &val );
1365 if( strlen( newval.psz_string ) > 0 )
1367 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1368 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1376 val.b_bool = !val.b_bool;
1377 var_Set( p_playlist, "loop", val );
1379 msg_rc( "Setting loop to %d", val.b_bool );
1381 else if( !strcmp( psz_cmd, "random" ) )
1383 bool b_update = true;
1385 var_Get( p_playlist, "random", &val );
1387 if( strlen( newval.psz_string ) > 0 )
1389 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1390 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1398 val.b_bool = !val.b_bool;
1399 var_Set( p_playlist, "random", val );
1401 msg_rc( "Setting random to %d", val.b_bool );
1403 else if (!strcmp( psz_cmd, "goto" ) )
1405 int i_pos = atoi( newval.psz_string );
1406 /* The playlist stores 2 times the same item: onelevel & category */
1407 int i_size = p_playlist->items.i_size / 2;
1410 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1411 else if( i_pos <= i_size )
1413 playlist_item_t *p_item, *p_parent;
1414 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1415 while( p_parent->p_parent )
1416 p_parent = p_parent->p_parent;
1417 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1421 msg_rc( _("Playlist has only %d elements"), i_size );
1423 else if( !strcmp( psz_cmd, "stop" ) )
1425 playlist_Stop( p_playlist );
1427 else if( !strcmp( psz_cmd, "clear" ) )
1429 playlist_Stop( p_playlist );
1430 playlist_Clear( p_playlist, pl_Unlocked );
1432 else if( !strcmp( psz_cmd, "add" ) &&
1433 newval.psz_string && *newval.psz_string )
1435 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1439 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1440 int i_ret =playlist_AddInput( p_playlist, p_item,
1441 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1443 vlc_gc_decref( p_item );
1444 if( i_ret != VLC_SUCCESS )
1446 return VLC_EGENERIC;
1450 else if( !strcmp( psz_cmd, "enqueue" ) &&
1451 newval.psz_string && *newval.psz_string )
1453 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1457 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1458 if( playlist_AddInput( p_playlist, p_item,
1459 PLAYLIST_APPEND, PLAYLIST_END, true,
1460 pl_Unlocked ) != VLC_SUCCESS )
1462 return VLC_EGENERIC;
1466 else if( !strcmp( psz_cmd, "playlist" ) )
1468 msg_rc( "+----[ Playlist ]" );
1469 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1470 msg_rc( "+----[ End of playlist ]" );
1473 else if( !strcmp( psz_cmd, "sort" ))
1475 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1476 SORT_ARTIST, ORDER_NORMAL );
1478 else if( !strcmp( psz_cmd, "status" ) )
1480 if( p_playlist->p_input )
1482 /* Replay the current state of the system. */
1484 input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1485 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1487 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1488 config_GetInt( p_intf, "volume" ));
1491 switch( p_playlist->status.i_status )
1493 case PLAYLIST_STOPPED:
1494 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1496 case PLAYLIST_RUNNING:
1497 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1499 case PLAYLIST_PAUSED:
1500 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1503 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1515 msg_rc( "unknown command!" );
1518 vlc_object_release( p_playlist );
1522 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1523 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1525 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1526 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1527 playlist_t *p_playlist;
1529 p_playlist = pl_Yield( p_this );
1530 playlist_Stop( p_playlist );
1531 vlc_object_release( p_playlist );
1533 vlc_object_kill( p_this->p_libvlc );
1537 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1538 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1540 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1541 intf_thread_t *p_newintf = NULL;
1543 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string );
1546 if( intf_RunThread( p_newintf ) )
1548 vlc_object_detach( p_newintf );
1549 vlc_object_release( p_newintf );
1556 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1557 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1559 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1560 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1561 input_thread_t *p_input = NULL;
1562 int i_error = VLC_EGENERIC;
1564 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1572 var_Get( p_input, "state", &val );
1573 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1575 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1576 vlc_object_release( p_input );
1577 return VLC_EGENERIC;
1579 vlc_object_release( p_input );
1582 if ( *newval.psz_string )
1585 audio_volume_t i_volume = atoi( newval.psz_string );
1586 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1588 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1590 i_error = VLC_EBADVAR;
1594 if( i_volume == AOUT_VOLUME_MIN )
1598 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1599 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1601 i_error = aout_VolumeSet( p_this, i_volume );
1602 osd_Volume( p_this );
1603 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1609 audio_volume_t i_volume;
1610 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1612 i_error = VLC_EGENERIC;
1616 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1617 i_error = VLC_SUCCESS;
1624 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1625 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1627 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1628 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1629 audio_volume_t i_volume;
1630 input_thread_t *p_input = NULL;
1631 int i_nb_steps = atoi(newval.psz_string);
1632 int i_error = VLC_SUCCESS;
1633 int i_volume_step = 0;
1635 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1643 var_Get( p_input, "state", &val );
1644 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1646 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1647 vlc_object_release( p_input );
1648 return VLC_EGENERIC;
1650 vlc_object_release( p_input );
1653 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1654 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1659 if ( !strcmp(psz_cmd, "volup") )
1661 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1662 i_error = VLC_EGENERIC;
1666 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1667 i_error = VLC_EGENERIC;
1669 osd_Volume( p_this );
1671 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1676 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1677 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1679 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1680 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1681 input_thread_t *p_input = NULL;
1682 vout_thread_t * p_vout;
1683 const char * psz_variable = NULL;
1686 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1690 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1691 vlc_object_release( p_input );
1695 if( !strcmp( psz_cmd, "vcrop" ) )
1697 psz_variable = "crop";
1699 else if( !strcmp( psz_cmd, "vratio" ) )
1701 psz_variable = "aspect-ratio";
1703 else if( !strcmp( psz_cmd, "vzoom" ) )
1705 psz_variable = "zoom";
1707 else if( !strcmp( psz_cmd, "snapshot" ) )
1709 psz_variable = "video-snapshot";
1712 if( newval.psz_string && *newval.psz_string )
1715 if( !strcmp( psz_variable, "zoom" ) )
1718 val.f_float = atof( newval.psz_string );
1719 i_error = var_Set( p_vout, psz_variable, val );
1723 i_error = var_Set( p_vout, psz_variable, newval );
1726 else if( !strcmp( psz_cmd, "snapshot" ) )
1730 i_error = var_Set( p_vout, psz_variable, val );
1735 vlc_value_t val_name;
1736 vlc_value_t val, text;
1739 char *psz_value = NULL;
1741 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1743 vlc_object_release( p_vout );
1744 return VLC_EGENERIC;
1746 if( !strcmp( psz_variable, "zoom" ) )
1748 f_value = val.f_float;
1752 psz_value = strdup( val.psz_string );
1755 if ( var_Change( p_vout, psz_variable,
1756 VLC_VAR_GETLIST, &val, &text ) < 0 )
1758 vlc_object_release( p_vout );
1759 return VLC_EGENERIC;
1762 /* Get the descriptive name of the variable */
1763 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1765 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1767 msg_rc( "+----[ %s ]", val_name.psz_string );
1768 if( !strcmp( psz_variable, "zoom" ) )
1770 for ( i = 0; i < val.p_list->i_count; i++ )
1772 if ( f_value == val.p_list->p_values[i].f_float )
1773 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1774 text.p_list->p_values[i].psz_string );
1776 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1777 text.p_list->p_values[i].psz_string );
1782 for ( i = 0; i < val.p_list->i_count; i++ )
1784 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1785 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1786 text.p_list->p_values[i].psz_string );
1788 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1789 text.p_list->p_values[i].psz_string );
1793 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1795 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1797 free( val_name.psz_string );
1799 i_error = VLC_SUCCESS;
1801 vlc_object_release( p_vout );
1805 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1806 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1808 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1809 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1810 input_thread_t *p_input = NULL;
1811 aout_instance_t * p_aout;
1812 const char * psz_variable;
1813 vlc_value_t val_name;
1816 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1824 var_Get( p_input, "state", &val );
1825 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1826 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1827 vlc_object_release( p_input );
1828 return VLC_EGENERIC;
1830 vlc_object_release( p_input );
1833 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1834 if ( p_aout == NULL ) return VLC_ENOOBJ;
1836 if ( !strcmp( psz_cmd, "adev" ) )
1838 psz_variable = "audio-device";
1842 psz_variable = "audio-channels";
1845 /* Get the descriptive name of the variable */
1846 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1848 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1850 if ( !*newval.psz_string )
1852 /* Retrieve all registered ***. */
1853 vlc_value_t val, text;
1856 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1858 vlc_object_release( (vlc_object_t *)p_aout );
1859 return VLC_EGENERIC;
1861 i_value = val.i_int;
1863 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1864 VLC_VAR_GETLIST, &val, &text ) < 0 )
1866 vlc_object_release( (vlc_object_t *)p_aout );
1867 return VLC_EGENERIC;
1870 msg_rc( "+----[ %s ]", val_name.psz_string );
1871 for ( i = 0; i < val.p_list->i_count; i++ )
1873 if ( i_value == val.p_list->p_values[i].i_int )
1874 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1875 text.p_list->p_values[i].psz_string );
1877 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1878 text.p_list->p_values[i].psz_string );
1880 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1882 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1884 free( val_name.psz_string );
1885 i_error = VLC_SUCCESS;
1890 val.i_int = atoi( newval.psz_string );
1892 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1894 vlc_object_release( (vlc_object_t *)p_aout );
1899 /* OSD menu commands */
1900 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1901 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1903 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1904 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1905 playlist_t *p_playlist = NULL;
1906 int i_error = VLC_SUCCESS;
1909 if ( !*newval.psz_string )
1911 msg_rc( _("Please provide one of the following parameters:") );
1912 msg_rc( "[on|off|up|down|left|right|select]" );
1913 return VLC_EGENERIC;
1916 p_playlist = pl_Yield( p_this );
1918 if( p_playlist->p_input )
1920 var_Get( p_playlist->p_input, "state", &val );
1921 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1922 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1924 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1925 vlc_object_release( p_playlist );
1926 return VLC_EGENERIC;
1929 vlc_object_release( p_playlist );
1931 val.psz_string = strdup( newval.psz_string );
1932 if( !val.psz_string )
1934 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1935 osd_MenuShow( p_this );
1936 else if( !strcmp( val.psz_string, "off" )
1937 || !strcmp( val.psz_string, "hide" ) )
1938 osd_MenuHide( p_this );
1939 else if( !strcmp( val.psz_string, "up" ) )
1940 osd_MenuUp( p_this );
1941 else if( !strcmp( val.psz_string, "down" ) )
1942 osd_MenuDown( p_this );
1943 else if( !strcmp( val.psz_string, "left" ) )
1944 osd_MenuPrev( p_this );
1945 else if( !strcmp( val.psz_string, "right" ) )
1946 osd_MenuNext( p_this );
1947 else if( !strcmp( val.psz_string, "select" ) )
1948 osd_MenuActivate( p_this );
1951 msg_rc( _("Please provide one of the following parameters:") );
1952 msg_rc( "[on|off|up|down|left|right|select]" );
1953 i_error = VLC_EGENERIC;
1956 free( val.psz_string );
1960 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1961 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1963 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1964 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1965 input_thread_t *p_input = NULL;
1968 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1972 if( !strcmp( psz_cmd, "stats" ) )
1974 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1975 updateStatistics( p_intf, input_GetItem(p_input) );
1976 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1983 msg_rc(_("Unknown command!") );
1986 vlc_object_release( p_input );
1987 i_error = VLC_SUCCESS;
1991 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1993 if( !p_item ) return VLC_EGENERIC;
1995 vlc_mutex_lock( &p_item->p_stats->lock );
1996 msg_rc( "+----[ begin of statistical info ]" );
1999 msg_rc(_("+-[Incoming]"));
2000 msg_rc(_("| input bytes read : %8.0f kB"),
2001 (float)(p_item->p_stats->i_read_bytes)/1000 );
2002 msg_rc(_("| input bitrate : %6.0f kb/s"),
2003 (float)(p_item->p_stats->f_input_bitrate)*8000 );
2004 msg_rc(_("| demux bytes read : %8.0f kB"),
2005 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
2006 msg_rc(_("| demux bitrate : %6.0f kb/s"),
2007 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
2010 msg_rc(_("+-[Video Decoding]"));
2011 msg_rc(_("| video decoded : %5i"),
2012 p_item->p_stats->i_decoded_video );
2013 msg_rc(_("| frames displayed : %5i"),
2014 p_item->p_stats->i_displayed_pictures );
2015 msg_rc(_("| frames lost : %5i"),
2016 p_item->p_stats->i_lost_pictures );
2019 msg_rc(_("+-[Audio Decoding]"));
2020 msg_rc(_("| audio decoded : %5i"),
2021 p_item->p_stats->i_decoded_audio );
2022 msg_rc(_("| buffers played : %5i"),
2023 p_item->p_stats->i_played_abuffers );
2024 msg_rc(_("| buffers lost : %5i"),
2025 p_item->p_stats->i_lost_abuffers );
2028 msg_rc(_("+-[Streaming]"));
2029 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
2030 msg_rc(_("| bytes sent : %8.0f kB"),
2031 (float)(p_item->p_stats->i_sent_bytes)/1000 );
2032 msg_rc(_("| sending bitrate : %6.0f kb/s"),
2033 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
2035 msg_rc( "+----[ end of statistical info ]" );
2036 vlc_mutex_unlock( &p_item->p_stats->lock );
2042 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2044 INPUT_RECORD input_record;
2047 /* On Win32, select() only works on socket descriptors */
2048 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2049 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2051 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2052 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2055 if( input_record.EventType != KEY_EVENT ||
2056 !input_record.Event.KeyEvent.bKeyDown ||
2057 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2058 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2059 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2060 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2062 /* nothing interesting */
2066 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2068 /* Echo out the command */
2069 putc( p_buffer[ *pi_size ], stdout );
2071 /* Handle special keys */
2072 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2074 putc( '\n', stdout );
2077 switch( p_buffer[ *pi_size ] )
2083 putc( ' ', stdout );
2084 putc( '\b', stdout );
2095 if( *pi_size == MAX_LINE_LENGTH ||
2096 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2098 p_buffer[ *pi_size ] = 0;
2107 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2112 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2113 return ReadWin32( p_intf, p_buffer, pi_size );
2114 else if( p_intf->p_sys->i_socket == -1 )
2116 msleep( INTF_IDLE_SLEEP );
2121 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2122 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2123 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2124 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2126 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2132 /* Connection closed */
2135 if( p_intf->p_sys->i_socket != -1 )
2137 net_Close( p_intf->p_sys->i_socket );
2138 p_intf->p_sys->i_socket = -1;
2142 /* Standard input closed: exit */
2144 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2147 p_buffer[ *pi_size ] = 0;
2151 if( *pi_size == MAX_LINE_LENGTH ||
2152 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2154 p_buffer[ *pi_size ] = 0;
2161 /*****************************************************************************
2162 * parse_MRL: build a input item from a full mrl
2163 *****************************************************************************
2164 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2165 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2166 * space is a new option. Should be good enough for our purpose.
2167 *****************************************************************************/
2168 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2170 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2171 #define SKIPTRAILINGSPACE( p, d ) \
2172 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2174 input_item_t *p_item = NULL;
2175 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2176 char **ppsz_options = NULL;
2177 int i, i_options = 0;
2179 if( !psz_mrl ) return 0;
2181 psz_mrl = psz_orig = strdup( psz_mrl );
2184 SKIPSPACE( psz_mrl );
2187 for( ; *psz_mrl; psz_mrl++ )
2189 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2191 /* We have a complete item */
2194 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2195 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2197 /* We have a complete item */
2202 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2203 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2205 /* Remove '"' and '\'' if necessary */
2206 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2207 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2208 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2209 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2211 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2212 else if( *psz_item )
2215 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2216 ppsz_options[i_options - 1] = &psz_item[1];
2219 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2222 /* Now create a playlist item */
2225 p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2226 for( i = 0; i < i_options; i++ )
2228 input_ItemAddOption( p_item, ppsz_options[i] );
2232 if( i_options ) free( ppsz_options );