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 char fmt_eol[strlen (psz_fmt) + 3];
154 snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
155 va_start( args, psz_fmt );
157 if( p_intf->p_sys->i_socket == -1 )
158 utf8_vfprintf( stdout, fmt_eol, args );
160 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
164 /*****************************************************************************
166 *****************************************************************************/
167 #define POS_TEXT N_("Show stream position")
168 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
169 "stream from time to time." )
171 #define TTY_TEXT N_("Fake TTY")
172 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
174 #define UNIX_TEXT N_("UNIX socket command input")
175 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
178 #define HOST_TEXT N_("TCP command input")
179 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
180 "You can set the address and port the interface will bind to." )
183 #define QUIET_TEXT N_("Do not open a DOS command box interface")
184 #define QUIET_LONGTEXT N_( \
185 "By default the rc interface plugin will start a DOS command box. " \
186 "Enabling the quiet mode will not bring this command box but can also " \
187 "be pretty annoying when you want to stop VLC and no video window is " \
192 set_shortname( N_("RC"));
193 set_category( CAT_INTERFACE );
194 set_subcategory( SUBCAT_INTERFACE_MAIN );
195 set_description( N_("Remote control interface") );
196 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, true );
199 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, false );
201 #if defined (HAVE_ISATTY)
202 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, true );
204 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, true );
206 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, true );
208 set_capability( "interface", 20 );
210 set_callbacks( Activate, Deactivate );
213 /*****************************************************************************
214 * Activate: initialize and create stuff
215 *****************************************************************************/
216 static int Activate( vlc_object_t *p_this )
218 intf_thread_t *p_intf = (intf_thread_t*)p_this;
219 char *psz_host, *psz_unix_path;
220 int *pi_socket = NULL;
223 #if defined(HAVE_ISATTY)
224 /* Check that stdin is a TTY */
225 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
227 msg_Warn( p_intf, "fd 0 is not a TTY" );
232 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
238 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
239 free( psz_unix_path );
242 struct sockaddr_un addr;
244 memset( &addr, 0, sizeof(struct sockaddr_un) );
246 msg_Dbg( p_intf, "trying UNIX socket" );
248 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
250 msg_Warn( p_intf, "can't open socket: %m" );
251 free( psz_unix_path );
255 addr.sun_family = AF_LOCAL;
256 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
257 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
259 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
260 && (errno == EADDRINUSE)
261 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
262 && (errno == ECONNREFUSED))
264 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
265 unlink (psz_unix_path);
267 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
269 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
271 free (psz_unix_path);
272 net_Close (i_socket);
277 if( listen( i_socket, 1 ) )
279 msg_Warn( p_intf, "can't listen on socket: %m");
280 free( psz_unix_path );
281 net_Close( i_socket );
285 /* FIXME: we need a core function to merge listening sockets sets */
286 pi_socket = calloc( 2, sizeof( int ) );
287 if( pi_socket == NULL )
289 free( psz_unix_path );
290 net_Close( i_socket );
293 pi_socket[0] = i_socket;
295 #endif /* AF_LOCAL */
299 if( ( pi_socket == NULL ) &&
300 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
304 vlc_UrlParse( &url, psz_host, 0 );
306 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
308 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
309 if( pi_socket == NULL )
311 msg_Warn( p_intf, "can't listen to %s port %i",
312 url.psz_host, url.i_port );
313 vlc_UrlClean( &url );
318 vlc_UrlClean( &url );
322 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
326 p_intf->p_sys->pi_socket_listen = pi_socket;
327 p_intf->p_sys->i_socket = -1;
328 p_intf->p_sys->psz_unix_path = psz_unix_path;
329 vlc_mutex_init( &p_intf->p_sys->status_lock );
330 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
332 /* Non-buffered stdout */
333 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
335 p_intf->pf_run = Run;
338 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
339 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
344 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
348 /*****************************************************************************
349 * Deactivate: uninitialize and cleanup
350 *****************************************************************************/
351 static void Deactivate( vlc_object_t *p_this )
353 intf_thread_t *p_intf = (intf_thread_t*)p_this;
355 net_ListenClose( p_intf->p_sys->pi_socket_listen );
356 if( p_intf->p_sys->i_socket != -1 )
357 net_Close( p_intf->p_sys->i_socket );
358 if( p_intf->p_sys->psz_unix_path != NULL )
360 #if defined(AF_LOCAL) && !defined(WIN32)
361 unlink( p_intf->p_sys->psz_unix_path );
363 free( p_intf->p_sys->psz_unix_path );
365 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
366 free( p_intf->p_sys );
369 /*****************************************************************************
370 * RegisterCallbacks: Register callbacks to dynamic variables
371 *****************************************************************************/
372 static void RegisterCallbacks( intf_thread_t *p_intf )
374 /* Register commands that will be cleaned up upon object destruction */
375 #define ADD( name, type, target ) \
376 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
377 var_AddCallback( p_intf, name, target, NULL );
378 ADD( "quit", VOID, Quit )
379 ADD( "intf", STRING, Intf )
381 ADD( "add", STRING, Playlist )
382 ADD( "repeat", STRING, Playlist )
383 ADD( "loop", STRING, Playlist )
384 ADD( "random", STRING, Playlist )
385 ADD( "enqueue", STRING, Playlist )
386 ADD( "playlist", VOID, Playlist )
387 ADD( "sort", VOID, Playlist )
388 ADD( "play", VOID, Playlist )
389 ADD( "stop", VOID, Playlist )
390 ADD( "clear", VOID, Playlist )
391 ADD( "prev", VOID, Playlist )
392 ADD( "next", VOID, Playlist )
393 ADD( "goto", INTEGER, Playlist )
394 ADD( "status", INTEGER, Playlist )
396 /* OSD menu commands */
397 ADD( "menu", STRING, Menu )
400 ADD( "pause", VOID, Input )
401 ADD( "seek", INTEGER, Input )
402 ADD( "title", STRING, Input )
403 ADD( "title_n", VOID, Input )
404 ADD( "title_p", VOID, Input )
405 ADD( "chapter", STRING, Input )
406 ADD( "chapter_n", VOID, Input )
407 ADD( "chapter_p", VOID, Input )
409 ADD( "fastforward", VOID, Input )
410 ADD( "rewind", VOID, Input )
411 ADD( "faster", VOID, Input )
412 ADD( "slower", VOID, Input )
413 ADD( "normal", VOID, Input )
415 ADD( "atrack", STRING, Input )
416 ADD( "vtrack", STRING, Input )
417 ADD( "strack", STRING, Input )
420 ADD( "vratio", STRING, VideoConfig )
421 ADD( "vcrop", STRING, VideoConfig )
422 ADD( "vzoom", STRING, VideoConfig )
423 ADD( "snapshot", VOID, VideoConfig )
426 ADD( "volume", STRING, Volume )
427 ADD( "volup", STRING, VolumeMove )
428 ADD( "voldown", STRING, VolumeMove )
429 ADD( "adev", STRING, AudioConfig )
430 ADD( "achan", STRING, AudioConfig )
432 /* misc menu commands */
433 ADD( "stats", BOOL, Statistics )
438 /*****************************************************************************
440 *****************************************************************************
441 * This part of the interface is in a separate thread so that we can call
442 * exec() from within it without annoying the rest of the program.
443 *****************************************************************************/
444 static void Run( intf_thread_t *p_intf )
446 input_thread_t * p_input;
447 playlist_t * p_playlist;
449 char p_buffer[ MAX_LINE_LENGTH + 1 ];
450 bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
451 bool b_longhelp = false;
456 int canc = vlc_savecancel();
462 /* Register commands that will be cleaned up upon object destruction */
463 RegisterCallbacks( p_intf );
465 /* status callbacks */
466 /* Listen to audio volume updates */
467 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
470 /* Get the file descriptor of the console input */
471 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
472 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
474 msg_Err( p_intf, "couldn't find user input handle" );
475 vlc_object_kill( p_intf );
479 while( vlc_object_alive( p_intf ) )
481 char *psz_cmd, *psz_arg;
484 if( p_intf->p_sys->pi_socket_listen != NULL &&
485 p_intf->p_sys->i_socket == -1 )
487 p_intf->p_sys->i_socket =
488 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
490 if( p_intf->p_sys->i_socket == -1 ) continue;
493 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
495 /* Manage the input part */
496 if( p_input == NULL )
500 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
505 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
509 p_playlist = pl_Hold( p_input );
512 /* New input has been registered */
515 if( !p_input->b_dead || vlc_object_alive (p_input) )
518 input_item_GetURI( input_GetItem( p_input ) );
519 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
521 msg_rc( STATUS_CHANGE "( audio volume: %d )",
522 config_GetInt( p_intf, "volume" ));
524 var_AddCallback( p_input, "state", StateChanged, p_intf );
525 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
526 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
527 var_AddCallback( p_input, "rate", RateChanged, p_intf );
528 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
532 else if( p_input->b_dead )
534 var_DelCallback( p_input, "state", StateChanged, p_intf );
535 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
536 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
537 var_DelCallback( p_input, "rate", RateChanged, p_intf );
538 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
540 vlc_object_release( p_input );
546 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
547 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
552 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
553 (p_playlist != NULL) )
556 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
557 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
559 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
560 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
563 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
564 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
566 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
567 msg_rc( STATUS_CHANGE "( play state: 3 )" );
570 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
571 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
573 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
574 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
579 if( p_input && b_showpos )
581 i_newpos = 100 * var_GetFloat( p_input, "position" );
582 if( i_oldpos != i_newpos )
585 msg_rc( "pos: %d%%", i_newpos );
589 /* Is there something to do? */
590 if( !b_complete ) continue;
592 /* Skip heading spaces */
594 while( *psz_cmd == ' ' )
599 /* Split psz_cmd at the first space and make sure that
600 * psz_arg is valid */
601 psz_arg = strchr( psz_cmd, ' ' );
605 while( *psz_arg == ' ' )
615 /* module specfic commands: @<module name> <command> <args...> */
616 if( *psz_cmd == '@' && *psz_arg )
618 /* Parse miscellaneous commands */
619 char *psz_alias = psz_cmd + 1;
620 char *psz_mycmd = strdup( psz_arg );
621 char *psz_myarg = strchr( psz_mycmd, ' ' );
626 msg_rc( "Not enough parameters." );
633 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
644 /* If the user typed a registered local command, try it */
645 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
650 val.psz_string = psz_arg;
651 i_ret = var_Set( p_intf, psz_cmd, val );
652 msg_rc( "%s: returned %i (%s)",
653 psz_cmd, i_ret, vlc_error( i_ret ) );
655 /* Or maybe it's a global command */
656 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
661 val.psz_string = psz_arg;
662 /* FIXME: it's a global command, but we should pass the
663 * local object as an argument, not p_intf->p_libvlc. */
664 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
667 msg_rc( "%s: returned %i (%s)",
668 psz_cmd, i_ret, vlc_error( i_ret ) );
671 else if( !strcmp( psz_cmd, "logout" ) )
673 /* Close connection */
674 if( p_intf->p_sys->i_socket != -1 )
676 net_Close( p_intf->p_sys->i_socket );
678 p_intf->p_sys->i_socket = -1;
680 else if( !strcmp( psz_cmd, "info" ) )
685 vlc_mutex_lock( &input_GetItem(p_input)->lock );
686 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
688 info_category_t *p_category = input_GetItem(p_input)
691 msg_rc( "+----[ %s ]", p_category->psz_name );
693 for ( j = 0; j < p_category->i_infos; j++ )
695 info_t *p_info = p_category->pp_infos[j];
696 msg_rc( "| %s: %s", p_info->psz_name,
701 msg_rc( "+----[ end of stream info ]" );
702 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
706 msg_rc( "no input" );
709 else if( !strcmp( psz_cmd, "is_playing" ) )
720 else if( !strcmp( psz_cmd, "get_time" ) )
729 var_Get( p_input, "time", &time );
730 msg_rc( "%i", time.i_time / 1000000);
733 else if( !strcmp( psz_cmd, "get_length" ) )
742 var_Get( p_input, "length", &time );
743 msg_rc( "%i", time.i_time / 1000000);
746 else if( !strcmp( psz_cmd, "get_title" ) )
754 msg_rc( "%s", input_GetItem(p_input)->psz_name );
757 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
758 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
760 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
762 else b_longhelp = false;
764 Help( p_intf, b_longhelp );
766 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
768 var_SetInteger( p_intf->p_libvlc, "key-pressed",
769 config_GetInt( p_intf, psz_arg ) );
771 else switch( psz_cmd[0] )
777 vout_thread_t *p_vout;
778 p_vout = vlc_object_find( p_input,
779 VLC_OBJECT_VOUT, FIND_CHILD );
784 bool b_update = false;
785 var_Get( p_vout, "fullscreen", &val );
786 val.b_bool = !val.b_bool;
787 if( !strncmp( psz_arg, "on", 2 )
788 && ( val.b_bool == true ) )
793 else if( !strncmp( psz_arg, "off", 3 )
794 && ( val.b_bool == false ) )
799 else if( strncmp( psz_arg, "off", 3 )
800 && strncmp( psz_arg, "on", 2 ) )
802 if( b_update ) var_Set( p_vout, "fullscreen", val );
803 vlc_object_release( p_vout );
814 /* Ignore empty lines */
818 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
822 /* Command processed */
823 i_size = 0; p_buffer[0] = 0;
826 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
827 msg_rc( STATUS_CHANGE "( quit )" );
831 var_DelCallback( p_input, "state", StateChanged, p_intf );
832 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
833 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
834 var_DelCallback( p_input, "rate", RateChanged, p_intf );
835 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
836 vlc_object_release( p_input );
842 vlc_object_release( p_playlist );
846 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
847 vlc_restorecancel( canc );
850 static void Help( intf_thread_t *p_intf, bool b_longhelp)
852 msg_rc(_("+----[ Remote control commands ]"));
854 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
855 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
856 msg_rc(_("| playlist . . . . . show items currently in playlist"));
857 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
858 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
859 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
860 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
861 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
862 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
863 msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
864 msg_rc(_("| random [on|off] . . . . . . . toggle random jumping"));
865 msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
866 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
867 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
868 msg_rc(_("| title_n . . . . . . . . next title in current item"));
869 msg_rc(_("| title_p . . . . . . previous title in current item"));
870 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
871 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
872 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
874 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
875 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
876 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
877 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
878 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
879 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
880 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
881 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
882 msg_rc(_("| info . . . . . information about the current stream"));
883 msg_rc(_("| stats . . . . . . . . show statistical information"));
884 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
885 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
886 msg_rc(_("| get_title . . . . . the title of the current stream"));
887 msg_rc(_("| get_length . . . . the length of the current stream"));
889 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
890 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
891 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
892 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
893 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
894 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
895 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
896 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
897 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
898 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
899 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
900 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
901 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
902 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
907 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
908 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
909 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
910 msg_rc(_("| @name marq-position #. . . .relative position control"));
911 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
912 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
913 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
914 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
916 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
917 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
918 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
919 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
920 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
922 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
923 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
924 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
925 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
926 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
927 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
928 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
929 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
930 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
931 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
932 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
933 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
934 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
935 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
938 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
939 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
940 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
941 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
943 msg_rc(_("+----[ end of help ]"));
946 /********************************************************************
947 * Status callback routines
948 ********************************************************************/
949 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
950 vlc_value_t oldval, vlc_value_t newval, void *p_data )
952 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
953 VLC_UNUSED(oldval); VLC_UNUSED(newval);
954 intf_thread_t *p_intf = (intf_thread_t*)p_data;
955 input_thread_t *p_input = NULL;
957 vlc_mutex_lock( &p_intf->p_sys->status_lock );
958 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
961 msg_rc( STATUS_CHANGE "( time-offset: %d )",
962 var_GetInteger( p_input, "time-offset" ) );
963 vlc_object_release( p_input );
965 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
969 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
970 vlc_value_t oldval, vlc_value_t newval, void *p_data )
972 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
973 intf_thread_t *p_intf = (intf_thread_t*)p_data;
975 vlc_mutex_lock( &p_intf->p_sys->status_lock );
976 msg_rc( STATUS_CHANGE "( audio volume: %d )",
977 config_GetInt( p_this, "volume") );
978 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
982 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
983 vlc_value_t oldval, vlc_value_t newval, void *p_data )
985 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
986 intf_thread_t *p_intf = (intf_thread_t*)p_data;
987 playlist_t *p_playlist = NULL;
988 input_thread_t *p_input = NULL;
990 vlc_mutex_lock( &p_intf->p_sys->status_lock );
991 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
994 p_playlist = pl_Hold( p_input );
996 switch( p_playlist->status.i_status )
998 case PLAYLIST_STOPPED:
999 strcpy( cmd, "stop" );
1001 case PLAYLIST_RUNNING:
1002 strcpy( cmd, "play" );
1004 case PLAYLIST_PAUSED:
1005 strcpy( cmd, "pause" );
1009 } /* var_GetInteger( p_input, "state" ) */
1010 msg_rc( STATUS_CHANGE "( %s state: %d ): %s",
1012 ppsz_input_state[ newval.i_int ] );
1013 vlc_object_release( p_playlist );
1014 vlc_object_release( p_input );
1016 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1020 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1021 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1023 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
1024 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1025 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1026 input_thread_t *p_input = NULL;
1028 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1029 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1032 msg_rc( STATUS_CHANGE "( new rate: %d )",
1033 var_GetInteger( p_input, "rate" ) );
1034 vlc_object_release( p_input );
1036 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1040 /********************************************************************
1042 ********************************************************************/
1043 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1044 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1046 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1047 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1048 input_thread_t *p_input;
1051 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1052 if( !p_input ) return VLC_ENOOBJ;
1054 var_Get( p_input, "state", &val );
1055 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1056 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1058 msg_rc( _("Press menu select or pause to continue.") );
1059 vlc_object_release( p_input );
1060 return VLC_EGENERIC;
1063 /* Parse commands that only require an input */
1064 if( !strcmp( psz_cmd, "pause" ) )
1066 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1067 var_Set( p_intf->p_libvlc, "key-pressed", val );
1068 vlc_object_release( p_input );
1071 else if( !strcmp( psz_cmd, "seek" ) )
1073 if( strlen( newval.psz_string ) > 0 &&
1074 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1076 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1077 var_Set( p_input, "position", val );
1081 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1082 var_Set( p_input, "time", val );
1084 vlc_object_release( p_input );
1087 else if ( !strcmp( psz_cmd, "fastforward" ) )
1089 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1090 var_Set( p_intf->p_libvlc, "key-pressed", val );
1091 vlc_object_release( p_input );
1094 else if ( !strcmp( psz_cmd, "rewind" ) )
1096 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1097 var_Set( p_intf->p_libvlc, "key-pressed", val );
1098 vlc_object_release( p_input );
1101 else if ( !strcmp( psz_cmd, "faster" ) )
1103 var_Set( p_input, "rate-faster", val );
1104 vlc_object_release( p_input );
1107 else if ( !strcmp( psz_cmd, "slower" ) )
1109 var_Set( p_input, "rate-slower", val );
1110 vlc_object_release( p_input );
1113 else if ( !strcmp( psz_cmd, "normal" ) )
1115 val.i_int = INPUT_RATE_DEFAULT;
1116 var_Set( p_input, "rate", val );
1117 vlc_object_release( p_input );
1120 else if( !strcmp( psz_cmd, "chapter" ) ||
1121 !strcmp( psz_cmd, "chapter_n" ) ||
1122 !strcmp( psz_cmd, "chapter_p" ) )
1124 if( !strcmp( psz_cmd, "chapter" ) )
1126 if ( *newval.psz_string )
1129 val.i_int = atoi( newval.psz_string );
1130 var_Set( p_input, "chapter", val );
1134 vlc_value_t val_list;
1137 var_Get( p_input, "chapter", &val );
1138 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1140 msg_rc( "Currently playing chapter %d/%d.",
1141 val.i_int, val_list.p_list->i_count );
1142 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1146 else if( !strcmp( psz_cmd, "chapter_n" ) )
1149 var_Set( p_input, "next-chapter", val );
1151 else if( !strcmp( psz_cmd, "chapter_p" ) )
1154 var_Set( p_input, "prev-chapter", val );
1156 vlc_object_release( p_input );
1159 else if( !strcmp( psz_cmd, "title" ) ||
1160 !strcmp( psz_cmd, "title_n" ) ||
1161 !strcmp( psz_cmd, "title_p" ) )
1163 if( !strcmp( psz_cmd, "title" ) )
1165 if ( *newval.psz_string )
1168 val.i_int = atoi( newval.psz_string );
1169 var_Set( p_input, "title", val );
1173 vlc_value_t val_list;
1176 var_Get( p_input, "title", &val );
1177 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1179 msg_rc( "Currently playing title %d/%d.",
1180 val.i_int, val_list.p_list->i_count );
1181 var_Change( p_this, "title", VLC_VAR_FREELIST,
1185 else if( !strcmp( psz_cmd, "title_n" ) )
1188 var_Set( p_input, "next-title", val );
1190 else if( !strcmp( psz_cmd, "title_p" ) )
1193 var_Set( p_input, "prev-title", val );
1196 vlc_object_release( p_input );
1199 else if( !strcmp( psz_cmd, "atrack" )
1200 || !strcmp( psz_cmd, "vtrack" )
1201 || !strcmp( psz_cmd, "strack" ) )
1203 const char *psz_variable;
1204 vlc_value_t val_name;
1207 if( !strcmp( psz_cmd, "atrack" ) )
1209 psz_variable = "audio-es";
1211 else if( !strcmp( psz_cmd, "vtrack" ) )
1213 psz_variable = "video-es";
1217 psz_variable = "spu-es";
1220 /* Get the descriptive name of the variable */
1221 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1223 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1225 if( newval.psz_string && *newval.psz_string )
1229 val.i_int = atoi( newval.psz_string );
1231 i_error = var_Set( p_input, psz_variable, val );
1236 vlc_value_t val, text;
1239 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1241 vlc_object_release( p_input );
1242 return VLC_EGENERIC;
1244 i_value = val.i_int;
1246 if ( var_Change( p_input, psz_variable,
1247 VLC_VAR_GETLIST, &val, &text ) < 0 )
1249 vlc_object_release( p_input );
1250 return VLC_EGENERIC;
1253 msg_rc( "+----[ %s ]", val_name.psz_string );
1254 for ( i = 0; i < val.p_list->i_count; i++ )
1256 if ( i_value == val.p_list->p_values[i].i_int )
1257 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1258 text.p_list->p_values[i].psz_string );
1260 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1261 text.p_list->p_values[i].psz_string );
1263 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1265 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1267 free( val_name.psz_string );
1269 i_error = VLC_SUCCESS;
1271 vlc_object_release( p_input );
1275 /* Never reached. */
1276 vlc_object_release( p_input );
1277 return VLC_EGENERIC;
1280 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1283 char psz_buffer[MSTRTIME_MAX_SIZE];
1284 for( i = 0; i< p_item->i_children; i++ )
1286 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1288 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1289 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1292 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1294 if( p_item->pp_children[i]->i_children >= 0 )
1295 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1299 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1300 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1302 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1305 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1306 playlist_t *p_playlist = pl_Hold( p_this );
1309 if( p_playlist->p_input )
1311 var_Get( p_playlist->p_input, "state", &val );
1312 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1314 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1315 vlc_object_release( p_playlist );
1317 return VLC_EGENERIC;
1322 /* Parse commands that require a playlist */
1323 if( !strcmp( psz_cmd, "prev" ) )
1325 playlist_Prev( p_playlist );
1327 else if( !strcmp( psz_cmd, "next" ) )
1329 playlist_Next( p_playlist );
1331 else if( !strcmp( psz_cmd, "play" ) )
1333 msg_Warn( p_playlist, "play" );
1334 playlist_Play( p_playlist );
1336 else if( !strcmp( psz_cmd, "repeat" ) )
1338 bool b_update = true;
1340 var_Get( p_playlist, "repeat", &val );
1342 if( strlen( newval.psz_string ) > 0 )
1344 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1345 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1353 val.b_bool = !val.b_bool;
1354 var_Set( p_playlist, "repeat", val );
1356 msg_rc( "Setting repeat to %d", val.b_bool );
1358 else if( !strcmp( psz_cmd, "loop" ) )
1360 bool b_update = true;
1362 var_Get( p_playlist, "loop", &val );
1364 if( strlen( newval.psz_string ) > 0 )
1366 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1367 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1375 val.b_bool = !val.b_bool;
1376 var_Set( p_playlist, "loop", val );
1378 msg_rc( "Setting loop to %d", val.b_bool );
1380 else if( !strcmp( psz_cmd, "random" ) )
1382 bool b_update = true;
1384 var_Get( p_playlist, "random", &val );
1386 if( strlen( newval.psz_string ) > 0 )
1388 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1389 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1397 val.b_bool = !val.b_bool;
1398 var_Set( p_playlist, "random", val );
1400 msg_rc( "Setting random to %d", val.b_bool );
1402 else if (!strcmp( psz_cmd, "goto" ) )
1404 int i_pos = atoi( newval.psz_string );
1405 /* The playlist stores 2 times the same item: onelevel & category */
1406 int i_size = p_playlist->items.i_size / 2;
1409 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1410 else if( i_pos <= i_size )
1412 playlist_item_t *p_item, *p_parent;
1413 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1414 while( p_parent->p_parent )
1415 p_parent = p_parent->p_parent;
1416 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1420 msg_rc( _("Playlist has only %d elements"), i_size );
1422 else if( !strcmp( psz_cmd, "stop" ) )
1424 playlist_Stop( p_playlist );
1426 else if( !strcmp( psz_cmd, "clear" ) )
1428 playlist_Stop( p_playlist );
1429 playlist_Clear( p_playlist, pl_Unlocked );
1431 else if( !strcmp( psz_cmd, "add" ) &&
1432 newval.psz_string && *newval.psz_string )
1434 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1438 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1439 int i_ret =playlist_AddInput( p_playlist, p_item,
1440 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1442 vlc_gc_decref( p_item );
1443 if( i_ret != VLC_SUCCESS )
1445 return VLC_EGENERIC;
1449 else if( !strcmp( psz_cmd, "enqueue" ) &&
1450 newval.psz_string && *newval.psz_string )
1452 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1456 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1457 if( playlist_AddInput( p_playlist, p_item,
1458 PLAYLIST_APPEND, PLAYLIST_END, true,
1459 pl_Unlocked ) != VLC_SUCCESS )
1461 return VLC_EGENERIC;
1465 else if( !strcmp( psz_cmd, "playlist" ) )
1467 msg_rc( "+----[ Playlist ]" );
1468 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1469 msg_rc( "+----[ End of playlist ]" );
1472 else if( !strcmp( psz_cmd, "sort" ))
1474 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1475 SORT_ARTIST, ORDER_NORMAL );
1477 else if( !strcmp( psz_cmd, "status" ) )
1479 if( p_playlist->p_input )
1481 /* Replay the current state of the system. */
1483 input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1484 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1486 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1487 config_GetInt( p_intf, "volume" ));
1490 switch( p_playlist->status.i_status )
1492 case PLAYLIST_STOPPED:
1493 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1495 case PLAYLIST_RUNNING:
1496 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1498 case PLAYLIST_PAUSED:
1499 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1502 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1514 msg_rc( "unknown command!" );
1517 vlc_object_release( p_playlist );
1521 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1522 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1524 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1525 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1526 playlist_t *p_playlist;
1528 p_playlist = pl_Hold( p_this );
1529 playlist_Stop( p_playlist );
1530 vlc_object_release( p_playlist );
1532 vlc_object_kill( p_this->p_libvlc );
1536 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1537 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1539 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1540 intf_thread_t *p_newintf = NULL;
1542 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string );
1545 if( intf_RunThread( p_newintf ) )
1547 vlc_object_detach( p_newintf );
1548 vlc_object_release( p_newintf );
1555 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1556 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1558 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1559 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1560 input_thread_t *p_input = NULL;
1561 int i_error = VLC_EGENERIC;
1563 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1571 var_Get( p_input, "state", &val );
1572 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1574 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1575 vlc_object_release( p_input );
1576 return VLC_EGENERIC;
1578 vlc_object_release( p_input );
1581 if ( *newval.psz_string )
1584 audio_volume_t i_volume = atoi( newval.psz_string );
1585 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1587 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1589 i_error = VLC_EBADVAR;
1593 if( i_volume == AOUT_VOLUME_MIN )
1597 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1598 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1600 i_error = aout_VolumeSet( p_this, i_volume );
1601 osd_Volume( p_this );
1602 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1608 audio_volume_t i_volume;
1609 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1611 i_error = VLC_EGENERIC;
1615 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1616 i_error = VLC_SUCCESS;
1623 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1624 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1626 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1627 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1628 audio_volume_t i_volume;
1629 input_thread_t *p_input = NULL;
1630 int i_nb_steps = atoi(newval.psz_string);
1631 int i_error = VLC_SUCCESS;
1632 int i_volume_step = 0;
1634 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1642 var_Get( p_input, "state", &val );
1643 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1645 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1646 vlc_object_release( p_input );
1647 return VLC_EGENERIC;
1649 vlc_object_release( p_input );
1652 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1653 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1658 if ( !strcmp(psz_cmd, "volup") )
1660 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1661 i_error = VLC_EGENERIC;
1665 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1666 i_error = VLC_EGENERIC;
1668 osd_Volume( p_this );
1670 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1675 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1676 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1678 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1679 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1680 input_thread_t *p_input = NULL;
1681 vout_thread_t * p_vout;
1682 const char * psz_variable = NULL;
1685 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1689 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1690 vlc_object_release( p_input );
1694 if( !strcmp( psz_cmd, "vcrop" ) )
1696 psz_variable = "crop";
1698 else if( !strcmp( psz_cmd, "vratio" ) )
1700 psz_variable = "aspect-ratio";
1702 else if( !strcmp( psz_cmd, "vzoom" ) )
1704 psz_variable = "zoom";
1706 else if( !strcmp( psz_cmd, "snapshot" ) )
1708 psz_variable = "video-snapshot";
1711 if( newval.psz_string && *newval.psz_string )
1714 if( !strcmp( psz_variable, "zoom" ) )
1717 val.f_float = atof( newval.psz_string );
1718 i_error = var_Set( p_vout, psz_variable, val );
1722 i_error = var_Set( p_vout, psz_variable, newval );
1725 else if( !strcmp( psz_cmd, "snapshot" ) )
1729 i_error = var_Set( p_vout, psz_variable, val );
1734 vlc_value_t val_name;
1735 vlc_value_t val, text;
1738 char *psz_value = NULL;
1740 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1742 vlc_object_release( p_vout );
1743 return VLC_EGENERIC;
1745 if( !strcmp( psz_variable, "zoom" ) )
1747 f_value = val.f_float;
1751 psz_value = strdup( val.psz_string );
1754 if ( var_Change( p_vout, psz_variable,
1755 VLC_VAR_GETLIST, &val, &text ) < 0 )
1757 vlc_object_release( p_vout );
1758 return VLC_EGENERIC;
1761 /* Get the descriptive name of the variable */
1762 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1764 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1766 msg_rc( "+----[ %s ]", val_name.psz_string );
1767 if( !strcmp( psz_variable, "zoom" ) )
1769 for ( i = 0; i < val.p_list->i_count; i++ )
1771 if ( f_value == val.p_list->p_values[i].f_float )
1772 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1773 text.p_list->p_values[i].psz_string );
1775 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1776 text.p_list->p_values[i].psz_string );
1781 for ( i = 0; i < val.p_list->i_count; i++ )
1783 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1784 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1785 text.p_list->p_values[i].psz_string );
1787 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1788 text.p_list->p_values[i].psz_string );
1792 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1794 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1796 free( val_name.psz_string );
1798 i_error = VLC_SUCCESS;
1800 vlc_object_release( p_vout );
1804 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1805 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1807 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1808 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1809 input_thread_t *p_input = NULL;
1810 aout_instance_t * p_aout;
1811 const char * psz_variable;
1812 vlc_value_t val_name;
1815 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1823 var_Get( p_input, "state", &val );
1824 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1825 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1826 vlc_object_release( p_input );
1827 return VLC_EGENERIC;
1829 vlc_object_release( p_input );
1832 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1833 if ( p_aout == NULL ) return VLC_ENOOBJ;
1835 if ( !strcmp( psz_cmd, "adev" ) )
1837 psz_variable = "audio-device";
1841 psz_variable = "audio-channels";
1844 /* Get the descriptive name of the variable */
1845 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1847 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1849 if ( !*newval.psz_string )
1851 /* Retrieve all registered ***. */
1852 vlc_value_t val, text;
1855 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1857 vlc_object_release( (vlc_object_t *)p_aout );
1858 return VLC_EGENERIC;
1860 i_value = val.i_int;
1862 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1863 VLC_VAR_GETLIST, &val, &text ) < 0 )
1865 vlc_object_release( (vlc_object_t *)p_aout );
1866 return VLC_EGENERIC;
1869 msg_rc( "+----[ %s ]", val_name.psz_string );
1870 for ( i = 0; i < val.p_list->i_count; i++ )
1872 if ( i_value == val.p_list->p_values[i].i_int )
1873 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1874 text.p_list->p_values[i].psz_string );
1876 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1877 text.p_list->p_values[i].psz_string );
1879 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1881 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1883 free( val_name.psz_string );
1884 i_error = VLC_SUCCESS;
1889 val.i_int = atoi( newval.psz_string );
1891 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1893 vlc_object_release( (vlc_object_t *)p_aout );
1898 /* OSD menu commands */
1899 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1900 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1902 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1903 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1904 playlist_t *p_playlist = NULL;
1905 int i_error = VLC_SUCCESS;
1908 if ( !*newval.psz_string )
1910 msg_rc( _("Please provide one of the following parameters:") );
1911 msg_rc( "[on|off|up|down|left|right|select]" );
1912 return VLC_EGENERIC;
1915 p_playlist = pl_Hold( p_this );
1917 if( p_playlist->p_input )
1919 var_Get( p_playlist->p_input, "state", &val );
1920 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1921 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1923 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1924 vlc_object_release( p_playlist );
1925 return VLC_EGENERIC;
1928 vlc_object_release( p_playlist );
1930 val.psz_string = strdup( newval.psz_string );
1931 if( !val.psz_string )
1933 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1934 osd_MenuShow( p_this );
1935 else if( !strcmp( val.psz_string, "off" )
1936 || !strcmp( val.psz_string, "hide" ) )
1937 osd_MenuHide( p_this );
1938 else if( !strcmp( val.psz_string, "up" ) )
1939 osd_MenuUp( p_this );
1940 else if( !strcmp( val.psz_string, "down" ) )
1941 osd_MenuDown( p_this );
1942 else if( !strcmp( val.psz_string, "left" ) )
1943 osd_MenuPrev( p_this );
1944 else if( !strcmp( val.psz_string, "right" ) )
1945 osd_MenuNext( p_this );
1946 else if( !strcmp( val.psz_string, "select" ) )
1947 osd_MenuActivate( p_this );
1950 msg_rc( _("Please provide one of the following parameters:") );
1951 msg_rc( "[on|off|up|down|left|right|select]" );
1952 i_error = VLC_EGENERIC;
1955 free( val.psz_string );
1959 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1960 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1962 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1963 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1964 input_thread_t *p_input = NULL;
1967 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1971 if( !strcmp( psz_cmd, "stats" ) )
1973 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1974 updateStatistics( p_intf, input_GetItem(p_input) );
1975 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1982 msg_rc(_("Unknown command!") );
1985 vlc_object_release( p_input );
1986 i_error = VLC_SUCCESS;
1990 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1992 if( !p_item ) return VLC_EGENERIC;
1994 vlc_mutex_lock( &p_item->p_stats->lock );
1995 msg_rc( "+----[ begin of statistical info ]" );
1998 msg_rc(_("+-[Incoming]"));
1999 msg_rc(_("| input bytes read : %8.0f kB"),
2000 (float)(p_item->p_stats->i_read_bytes)/1000 );
2001 msg_rc(_("| input bitrate : %6.0f kb/s"),
2002 (float)(p_item->p_stats->f_input_bitrate)*8000 );
2003 msg_rc(_("| demux bytes read : %8.0f kB"),
2004 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
2005 msg_rc(_("| demux bitrate : %6.0f kb/s"),
2006 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
2009 msg_rc(_("+-[Video Decoding]"));
2010 msg_rc(_("| video decoded : %5i"),
2011 p_item->p_stats->i_decoded_video );
2012 msg_rc(_("| frames displayed : %5i"),
2013 p_item->p_stats->i_displayed_pictures );
2014 msg_rc(_("| frames lost : %5i"),
2015 p_item->p_stats->i_lost_pictures );
2018 msg_rc(_("+-[Audio Decoding]"));
2019 msg_rc(_("| audio decoded : %5i"),
2020 p_item->p_stats->i_decoded_audio );
2021 msg_rc(_("| buffers played : %5i"),
2022 p_item->p_stats->i_played_abuffers );
2023 msg_rc(_("| buffers lost : %5i"),
2024 p_item->p_stats->i_lost_abuffers );
2027 msg_rc(_("+-[Streaming]"));
2028 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
2029 msg_rc(_("| bytes sent : %8.0f kB"),
2030 (float)(p_item->p_stats->i_sent_bytes)/1000 );
2031 msg_rc(_("| sending bitrate : %6.0f kb/s"),
2032 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
2034 msg_rc( "+----[ end of statistical info ]" );
2035 vlc_mutex_unlock( &p_item->p_stats->lock );
2041 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2043 INPUT_RECORD input_record;
2046 /* On Win32, select() only works on socket descriptors */
2047 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2048 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2050 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2051 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2054 if( input_record.EventType != KEY_EVENT ||
2055 !input_record.Event.KeyEvent.bKeyDown ||
2056 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2057 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2058 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2059 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2061 /* nothing interesting */
2065 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2067 /* Echo out the command */
2068 putc( p_buffer[ *pi_size ], stdout );
2070 /* Handle special keys */
2071 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2073 putc( '\n', stdout );
2076 switch( p_buffer[ *pi_size ] )
2082 putc( ' ', stdout );
2083 putc( '\b', stdout );
2094 if( *pi_size == MAX_LINE_LENGTH ||
2095 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2097 p_buffer[ *pi_size ] = 0;
2106 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2111 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2112 return ReadWin32( p_intf, p_buffer, pi_size );
2113 else if( p_intf->p_sys->i_socket == -1 )
2115 msleep( INTF_IDLE_SLEEP );
2120 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2121 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2122 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2123 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2125 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2131 /* Connection closed */
2134 if( p_intf->p_sys->i_socket != -1 )
2136 net_Close( p_intf->p_sys->i_socket );
2137 p_intf->p_sys->i_socket = -1;
2141 /* Standard input closed: exit */
2143 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2146 p_buffer[ *pi_size ] = 0;
2150 if( *pi_size == MAX_LINE_LENGTH ||
2151 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2153 p_buffer[ *pi_size ] = 0;
2160 /*****************************************************************************
2161 * parse_MRL: build a input item from a full mrl
2162 *****************************************************************************
2163 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2164 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2165 * space is a new option. Should be good enough for our purpose.
2166 *****************************************************************************/
2167 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2169 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2170 #define SKIPTRAILINGSPACE( p, d ) \
2171 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2173 input_item_t *p_item = NULL;
2174 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2175 char **ppsz_options = NULL;
2176 int i, i_options = 0;
2178 if( !psz_mrl ) return 0;
2180 psz_mrl = psz_orig = strdup( psz_mrl );
2183 SKIPSPACE( psz_mrl );
2186 for( ; *psz_mrl; psz_mrl++ )
2188 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2190 /* We have a complete item */
2193 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2194 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2196 /* We have a complete item */
2201 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2202 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2204 /* Remove '"' and '\'' if necessary */
2205 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2206 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2207 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2208 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2210 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2211 else if( *psz_item )
2214 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2215 ppsz_options[i_options - 1] = &psz_item[1];
2218 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2221 /* Now create a playlist item */
2224 p_item = input_item_New( p_intf, psz_item_mrl, NULL );
2225 for( i = 0; i < i_options; i++ )
2227 input_item_AddOption( p_item, ppsz_options[i] );
2231 if( i_options ) free( ppsz_options );