1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2009 the VideoLAN team
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8 * Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
34 #include <vlc_plugin.h>
36 #include <errno.h> /* ENOMEM */
41 #include <vlc_interface.h>
45 #include <vlc_playlist.h>
51 #ifdef HAVE_SYS_TIME_H
52 # include <sys/time.h>
54 #include <sys/types.h>
56 #include <vlc_network.h>
59 #include <vlc_charset.h>
61 #if defined(AF_UNIX) && !defined(AF_LOCAL)
62 # define AF_LOCAL AF_UNIX
65 #if defined(AF_LOCAL) && ! defined(WIN32)
69 #define MAX_LINE_LENGTH 1024
70 #define STATUS_CHANGE "status change: "
72 /* input_state_e from <vlc_input.h> */
73 static const char *ppsz_input_state[] = {
74 [INIT_S] = N_("Initializing"),
75 [OPENING_S] = N_("Opening"),
76 [PLAYING_S] = N_("Play"),
77 [PAUSE_S] = N_("Pause"),
79 [ERROR_S] = N_("Error"),
82 /*****************************************************************************
84 *****************************************************************************/
85 static int Activate ( vlc_object_t * );
86 static void Deactivate ( vlc_object_t * );
87 static void Run ( intf_thread_t * );
89 static void Help ( intf_thread_t *, bool );
90 static void RegisterCallbacks( intf_thread_t * );
92 static bool ReadCommand( intf_thread_t *, char *, int * );
94 static input_item_t *parse_MRL( intf_thread_t *, char * );
96 static int Input ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
98 static int Playlist ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int Quit ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int Intf ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int Volume ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int VolumeMove ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int VideoConfig ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
110 static int AudioConfig ( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t, void * );
112 static int Menu ( vlc_object_t *, char const *,
113 vlc_value_t, vlc_value_t, void * );
114 static int Statistics ( vlc_object_t *, char const *,
115 vlc_value_t, vlc_value_t, void * );
117 static int updateStatistics( intf_thread_t *, input_item_t *);
119 /* Status Callbacks */
120 static int TimeOffsetChanged( vlc_object_t *, char const *,
121 vlc_value_t, vlc_value_t , void * );
122 static int VolumeChanged ( vlc_object_t *, char const *,
123 vlc_value_t, vlc_value_t, void * );
124 static int StateChanged ( vlc_object_t *, char const *,
125 vlc_value_t, vlc_value_t, void * );
126 static int RateChanged ( vlc_object_t *, char const *,
127 vlc_value_t, vlc_value_t, void * );
131 int *pi_socket_listen;
136 vlc_mutex_t status_lock;
137 playlist_status_t i_last_state;
145 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
148 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
151 char fmt_eol[strlen (psz_fmt) + 3];
153 snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
154 va_start( args, psz_fmt );
156 if( p_intf->p_sys->i_socket == -1 )
157 utf8_vfprintf( stdout, fmt_eol, args );
159 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
163 /*****************************************************************************
165 *****************************************************************************/
166 #define POS_TEXT N_("Show stream position")
167 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
168 "stream from time to time." )
170 #define TTY_TEXT N_("Fake TTY")
171 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
173 #define UNIX_TEXT N_("UNIX socket command input")
174 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
177 #define HOST_TEXT N_("TCP command input")
178 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
179 "You can set the address and port the interface will bind to." )
182 #define QUIET_TEXT N_("Do not open a DOS command box interface")
183 #define QUIET_LONGTEXT N_( \
184 "By default the rc interface plugin will start a DOS command box. " \
185 "Enabling the quiet mode will not bring this command box but can also " \
186 "be pretty annoying when you want to stop VLC and no video window is " \
191 set_shortname( N_("RC"))
192 set_category( CAT_INTERFACE )
193 set_subcategory( SUBCAT_INTERFACE_MAIN )
194 set_description( N_("Remote control interface") )
195 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, true )
198 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, false )
200 #if defined (HAVE_ISATTY)
201 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, true )
203 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, true )
205 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, true )
207 set_capability( "interface", 20 )
209 set_callbacks( Activate, Deactivate )
212 /*****************************************************************************
213 * Activate: initialize and create stuff
214 *****************************************************************************/
215 static int Activate( vlc_object_t *p_this )
217 intf_thread_t *p_intf = (intf_thread_t*)p_this;
218 char *psz_host, *psz_unix_path = NULL;
219 int *pi_socket = NULL;
222 #if defined(HAVE_ISATTY)
223 /* Check that stdin is a TTY */
224 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
226 msg_Warn( p_intf, "fd 0 is not a TTY" );
231 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
237 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
238 free( psz_unix_path );
241 struct sockaddr_un addr;
243 memset( &addr, 0, sizeof(struct sockaddr_un) );
245 msg_Dbg( p_intf, "trying UNIX socket" );
247 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
249 msg_Warn( p_intf, "can't open socket: %m" );
250 free( psz_unix_path );
254 addr.sun_family = AF_LOCAL;
255 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
256 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
258 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
259 && (errno == EADDRINUSE)
260 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
261 && (errno == ECONNREFUSED))
263 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
264 unlink (psz_unix_path);
266 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
268 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
270 free (psz_unix_path);
271 net_Close (i_socket);
276 if( listen( i_socket, 1 ) )
278 msg_Warn( p_intf, "can't listen on socket: %m");
279 free( psz_unix_path );
280 net_Close( i_socket );
284 /* FIXME: we need a core function to merge listening sockets sets */
285 pi_socket = calloc( 2, sizeof( int ) );
286 if( pi_socket == NULL )
288 free( psz_unix_path );
289 net_Close( i_socket );
292 pi_socket[0] = i_socket;
294 #endif /* AF_LOCAL */
298 if( ( pi_socket == NULL ) &&
299 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
303 vlc_UrlParse( &url, psz_host, 0 );
305 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
307 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
308 if( pi_socket == NULL )
310 msg_Warn( p_intf, "can't listen to %s port %i",
311 url.psz_host, url.i_port );
312 vlc_UrlClean( &url );
317 vlc_UrlClean( &url );
321 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
325 p_intf->p_sys->pi_socket_listen = pi_socket;
326 p_intf->p_sys->i_socket = -1;
327 p_intf->p_sys->psz_unix_path = psz_unix_path;
328 vlc_mutex_init( &p_intf->p_sys->status_lock );
329 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
331 /* Non-buffered stdout */
332 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
334 p_intf->pf_run = Run;
337 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
338 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
343 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
347 /*****************************************************************************
348 * Deactivate: uninitialize and cleanup
349 *****************************************************************************/
350 static void Deactivate( vlc_object_t *p_this )
352 intf_thread_t *p_intf = (intf_thread_t*)p_this;
354 net_ListenClose( p_intf->p_sys->pi_socket_listen );
355 if( p_intf->p_sys->i_socket != -1 )
356 net_Close( p_intf->p_sys->i_socket );
357 if( p_intf->p_sys->psz_unix_path != NULL )
359 #if defined(AF_LOCAL) && !defined(WIN32)
360 unlink( p_intf->p_sys->psz_unix_path );
362 free( p_intf->p_sys->psz_unix_path );
364 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
365 free( p_intf->p_sys );
368 /*****************************************************************************
369 * RegisterCallbacks: Register callbacks to dynamic variables
370 *****************************************************************************/
371 static void RegisterCallbacks( intf_thread_t *p_intf )
373 /* Register commands that will be cleaned up upon object destruction */
374 #define ADD( name, type, target ) \
375 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
376 var_AddCallback( p_intf, name, target, NULL );
377 ADD( "quit", VOID, Quit )
378 ADD( "intf", STRING, Intf )
380 ADD( "add", STRING, Playlist )
381 ADD( "repeat", STRING, Playlist )
382 ADD( "loop", STRING, Playlist )
383 ADD( "random", STRING, Playlist )
384 ADD( "enqueue", STRING, Playlist )
385 ADD( "playlist", VOID, Playlist )
386 ADD( "sort", VOID, Playlist )
387 ADD( "play", VOID, Playlist )
388 ADD( "stop", VOID, Playlist )
389 ADD( "clear", VOID, Playlist )
390 ADD( "prev", VOID, Playlist )
391 ADD( "next", VOID, Playlist )
392 ADD( "goto", INTEGER, Playlist )
393 ADD( "status", INTEGER, Playlist )
395 /* OSD menu commands */
396 ADD( "menu", STRING, Menu )
399 ADD( "pause", VOID, Input )
400 ADD( "seek", INTEGER, Input )
401 ADD( "title", STRING, Input )
402 ADD( "title_n", VOID, Input )
403 ADD( "title_p", VOID, Input )
404 ADD( "chapter", STRING, Input )
405 ADD( "chapter_n", VOID, Input )
406 ADD( "chapter_p", VOID, Input )
408 ADD( "fastforward", VOID, Input )
409 ADD( "rewind", VOID, Input )
410 ADD( "faster", VOID, Input )
411 ADD( "slower", VOID, Input )
412 ADD( "normal", VOID, Input )
414 ADD( "atrack", STRING, Input )
415 ADD( "vtrack", STRING, Input )
416 ADD( "strack", STRING, Input )
419 ADD( "vratio", STRING, VideoConfig )
420 ADD( "vcrop", STRING, VideoConfig )
421 ADD( "vzoom", STRING, VideoConfig )
422 ADD( "snapshot", VOID, VideoConfig )
425 ADD( "volume", STRING, Volume )
426 ADD( "volup", STRING, VolumeMove )
427 ADD( "voldown", STRING, VolumeMove )
428 ADD( "adev", STRING, AudioConfig )
429 ADD( "achan", STRING, AudioConfig )
431 /* misc menu commands */
432 ADD( "stats", BOOL, Statistics )
437 /*****************************************************************************
439 *****************************************************************************
440 * This part of the interface is in a separate thread so that we can call
441 * exec() from within it without annoying the rest of the program.
442 *****************************************************************************/
443 static void Run( intf_thread_t *p_intf )
445 input_thread_t * p_input;
446 playlist_t * p_playlist;
448 char p_buffer[ MAX_LINE_LENGTH + 1 ];
449 bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
450 bool b_longhelp = false;
455 int canc = vlc_savecancel();
461 /* Register commands that will be cleaned up upon object destruction */
462 RegisterCallbacks( p_intf );
464 /* status callbacks */
465 /* Listen to audio volume updates */
466 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
469 /* Get the file descriptor of the console input */
470 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
471 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
473 msg_Err( p_intf, "couldn't find user input handle" );
474 vlc_object_kill( p_intf );
478 while( vlc_object_alive( p_intf ) )
480 char *psz_cmd, *psz_arg;
483 if( p_intf->p_sys->pi_socket_listen != NULL &&
484 p_intf->p_sys->i_socket == -1 )
486 p_intf->p_sys->i_socket =
487 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
489 if( p_intf->p_sys->i_socket == -1 ) continue;
492 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
494 /* Manage the input part */
495 if( p_input == NULL )
499 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
504 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
508 p_playlist = pl_Hold( p_input );
511 /* New input has been registered */
514 if( !p_input->b_dead || vlc_object_alive (p_input) )
517 input_item_GetURI( input_GetItem( p_input ) );
518 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
520 msg_rc( STATUS_CHANGE "( audio volume: %d )",
521 config_GetInt( p_intf, "volume" ));
523 var_AddCallback( p_input, "state", StateChanged, p_intf );
524 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
525 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
526 var_AddCallback( p_input, "rate", RateChanged, p_intf );
527 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
531 else if( p_input->b_dead )
533 var_DelCallback( p_input, "state", StateChanged, p_intf );
534 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
535 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
536 var_DelCallback( p_input, "rate", RateChanged, p_intf );
537 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
539 vlc_object_release( p_input );
545 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
546 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
551 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
552 (p_playlist != NULL) )
555 int status = playlist_Status( p_playlist );
556 if( p_intf->p_sys->i_last_state != status )
558 if( status == PLAYLIST_STOPPED )
560 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
561 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
563 else if( status == PLAYLIST_RUNNING )
565 p_intf->p_sys->i_last_state = PLAYLIST_RUNNING;
566 msg_rc( STATUS_CHANGE "( play state: 3 )" );
568 else if( status == PLAYLIST_PAUSED )
570 p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
571 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
577 if( p_input && b_showpos )
579 i_newpos = 100 * var_GetFloat( p_input, "position" );
580 if( i_oldpos != i_newpos )
583 msg_rc( "pos: %d%%", i_newpos );
587 /* Is there something to do? */
588 if( !b_complete ) continue;
590 /* Skip heading spaces */
592 while( *psz_cmd == ' ' )
597 /* Split psz_cmd at the first space and make sure that
598 * psz_arg is valid */
599 psz_arg = strchr( psz_cmd, ' ' );
603 while( *psz_arg == ' ' )
613 /* module specfic commands: @<module name> <command> <args...> */
614 if( *psz_cmd == '@' && *psz_arg )
616 /* Parse miscellaneous commands */
617 char *psz_alias = psz_cmd + 1;
618 char *psz_mycmd = strdup( psz_arg );
619 char *psz_myarg = strchr( psz_mycmd, ' ' );
624 msg_rc( "Not enough parameters." );
631 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
636 msg_rc( "%s", psz_msg );
642 /* If the user typed a registered local command, try it */
643 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
648 val.psz_string = psz_arg;
649 i_ret = var_Set( p_intf, psz_cmd, val );
650 msg_rc( "%s: returned %i (%s)",
651 psz_cmd, i_ret, vlc_error( i_ret ) );
653 /* Or maybe it's a global command */
654 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
659 val.psz_string = psz_arg;
660 /* FIXME: it's a global command, but we should pass the
661 * local object as an argument, not p_intf->p_libvlc. */
662 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
665 msg_rc( "%s: returned %i (%s)",
666 psz_cmd, i_ret, vlc_error( i_ret ) );
669 else if( !strcmp( psz_cmd, "logout" ) )
671 /* Close connection */
672 if( p_intf->p_sys->i_socket != -1 )
674 net_Close( p_intf->p_sys->i_socket );
676 p_intf->p_sys->i_socket = -1;
678 else if( !strcmp( psz_cmd, "info" ) )
683 vlc_mutex_lock( &input_GetItem(p_input)->lock );
684 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
686 info_category_t *p_category = input_GetItem(p_input)
689 msg_rc( "+----[ %s ]", p_category->psz_name );
691 for ( j = 0; j < p_category->i_infos; j++ )
693 info_t *p_info = p_category->pp_infos[j];
694 msg_rc( "| %s: %s", p_info->psz_name,
699 msg_rc( "+----[ end of stream info ]" );
700 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
704 msg_rc( "no input" );
707 else if( !strcmp( psz_cmd, "is_playing" ) )
718 else if( !strcmp( psz_cmd, "get_time" ) )
727 var_Get( p_input, "time", &time );
728 msg_rc( "%"PRIu64, time.i_time / 1000000);
731 else if( !strcmp( psz_cmd, "get_length" ) )
740 var_Get( p_input, "length", &time );
741 msg_rc( "%"PRIu64, time.i_time / 1000000);
744 else if( !strcmp( psz_cmd, "get_title" ) )
752 msg_rc( "%s", input_GetItem(p_input)->psz_name );
755 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
756 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
758 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
760 else b_longhelp = false;
762 Help( p_intf, b_longhelp );
764 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
766 var_SetInteger( p_intf->p_libvlc, "key-pressed",
767 config_GetInt( p_intf, psz_arg ) );
769 else switch( psz_cmd[0] )
775 vout_thread_t *p_vout;
776 p_vout = vlc_object_find( p_input,
777 VLC_OBJECT_VOUT, FIND_CHILD );
782 bool b_update = false;
783 var_Get( p_vout, "fullscreen", &val );
784 val.b_bool = !val.b_bool;
785 if( !strncmp( psz_arg, "on", 2 )
786 && ( val.b_bool == true ) )
791 else if( !strncmp( psz_arg, "off", 3 )
792 && ( val.b_bool == false ) )
797 else if( strncmp( psz_arg, "off", 3 )
798 && strncmp( psz_arg, "on", 2 ) )
800 if( b_update ) var_Set( p_vout, "fullscreen", val );
801 vlc_object_release( p_vout );
812 /* Ignore empty lines */
816 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
820 /* Command processed */
821 i_size = 0; p_buffer[0] = 0;
824 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
825 msg_rc( STATUS_CHANGE "( quit )" );
829 var_DelCallback( p_input, "state", StateChanged, p_intf );
830 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
831 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
832 var_DelCallback( p_input, "rate", RateChanged, p_intf );
833 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
834 vlc_object_release( p_input );
840 vlc_object_release( p_playlist );
844 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
845 vlc_restorecancel( canc );
848 static void Help( intf_thread_t *p_intf, bool b_longhelp)
850 msg_rc(_("+----[ Remote control commands ]"));
852 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
853 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
854 msg_rc(_("| playlist . . . . . show items currently in playlist"));
855 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
856 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
857 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
858 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
859 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
860 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
861 msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
862 msg_rc(_("| random [on|off] . . . . . . . toggle random jumping"));
863 msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
864 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
865 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
866 msg_rc(_("| title_n . . . . . . . . next title in current item"));
867 msg_rc(_("| title_p . . . . . . previous title in current item"));
868 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
869 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
870 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
872 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
873 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
874 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
875 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
876 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
877 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
878 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
879 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
880 msg_rc(_("| info . . . . . information about the current stream"));
881 msg_rc(_("| stats . . . . . . . . show statistical information"));
882 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
883 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
884 msg_rc(_("| get_title . . . . . the title of the current stream"));
885 msg_rc(_("| get_length . . . . the length of the current stream"));
887 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
888 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
889 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
890 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
891 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
892 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
893 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
894 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
895 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
896 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
897 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
898 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
899 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
900 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
905 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
906 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
907 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
908 msg_rc(_("| @name marq-position #. . . .relative position control"));
909 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
910 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
911 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
912 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
914 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
915 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
916 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
917 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
918 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
920 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
921 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
922 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
923 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
924 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
925 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
926 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
927 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
928 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
929 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
930 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
931 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
932 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
933 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
936 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
937 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
938 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
939 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
941 msg_rc(_("+----[ end of help ]"));
944 /********************************************************************
945 * Status callback routines
946 ********************************************************************/
947 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
948 vlc_value_t oldval, vlc_value_t newval, void *p_data )
950 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
951 VLC_UNUSED(oldval); VLC_UNUSED(newval);
952 intf_thread_t *p_intf = (intf_thread_t*)p_data;
953 input_thread_t *p_input = NULL;
955 vlc_mutex_lock( &p_intf->p_sys->status_lock );
956 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
959 msg_rc( STATUS_CHANGE "( time-offset: %"PRId64"s )",
960 (var_GetTime( p_input, "time-offset" )/1000000) );
961 vlc_object_release( p_input );
963 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
967 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
968 vlc_value_t oldval, vlc_value_t newval, void *p_data )
970 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
971 intf_thread_t *p_intf = (intf_thread_t*)p_data;
973 vlc_mutex_lock( &p_intf->p_sys->status_lock );
974 msg_rc( STATUS_CHANGE "( audio volume: %d )",
975 config_GetInt( p_this, "volume") );
976 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
980 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
981 vlc_value_t oldval, vlc_value_t newval, void *p_data )
983 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
984 intf_thread_t *p_intf = (intf_thread_t*)p_data;
985 playlist_t *p_playlist = NULL;
988 vlc_mutex_lock( &p_intf->p_sys->status_lock );
989 p_playlist = pl_Hold( p_intf );
991 int i_status = playlist_Status( p_playlist );
993 pl_Release( p_intf );
997 case PLAYLIST_STOPPED:
998 strcpy( cmd, "stop" );
1000 case PLAYLIST_RUNNING:
1001 strcpy( cmd, "play" );
1003 case PLAYLIST_PAUSED:
1004 strcpy( cmd, "pause" );
1008 } /* var_GetInteger( p_input, "state" ) */
1009 msg_rc( STATUS_CHANGE "( %s state: %d ): %s", cmd, newval.i_int,
1010 ppsz_input_state[ newval.i_int ] );
1012 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1016 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1017 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1019 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
1020 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1021 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1022 input_thread_t *p_input = NULL;
1024 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1025 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1028 msg_rc( STATUS_CHANGE "( new rate: %d )",
1029 var_GetInteger( p_input, "rate" ) );
1030 vlc_object_release( p_input );
1032 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1036 /********************************************************************
1038 ********************************************************************/
1039 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1040 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1042 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1043 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1044 input_thread_t *p_input;
1047 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1048 if( !p_input ) return VLC_ENOOBJ;
1050 var_Get( p_input, "state", &val );
1051 if( ( val.i_int == PAUSE_S ) &&
1052 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1054 msg_rc( _("Press menu select or pause to continue.") );
1055 vlc_object_release( p_input );
1056 return VLC_EGENERIC;
1059 /* Parse commands that only require an input */
1060 if( !strcmp( psz_cmd, "pause" ) )
1062 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1063 var_Set( p_intf->p_libvlc, "key-pressed", val );
1064 vlc_object_release( p_input );
1067 else if( !strcmp( psz_cmd, "seek" ) )
1069 if( strlen( newval.psz_string ) > 0 &&
1070 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1072 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1073 var_Set( p_input, "position", val );
1077 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1078 var_Set( p_input, "time", val );
1080 vlc_object_release( p_input );
1083 else if ( !strcmp( psz_cmd, "fastforward" ) )
1085 if( var_GetBool( p_input, "can-rate" ) )
1087 int i_rate = var_GetInteger( p_input, "rate" );
1088 i_rate = (i_rate < 0) ? -i_rate : i_rate * 2;
1089 var_SetInteger( p_input, "rate", i_rate );
1093 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1094 var_Set( p_intf->p_libvlc, "key-pressed", val );
1096 vlc_object_release( p_input );
1099 else if ( !strcmp( psz_cmd, "rewind" ) )
1101 if( var_GetBool( p_input, "can-rewind" ) )
1103 int i_rate = var_GetInteger( p_input, "rate" );
1104 i_rate = (i_rate > 0) ? -i_rate : i_rate / 2;
1105 var_SetInteger( p_input, "rate", i_rate );
1109 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1110 var_Set( p_intf->p_libvlc, "key-pressed", val );
1112 vlc_object_release( p_input );
1115 else if ( !strcmp( psz_cmd, "faster" ) )
1117 var_Set( p_input, "rate-faster", val );
1118 vlc_object_release( p_input );
1121 else if ( !strcmp( psz_cmd, "slower" ) )
1123 var_Set( p_input, "rate-slower", val );
1124 vlc_object_release( p_input );
1127 else if ( !strcmp( psz_cmd, "normal" ) )
1129 val.i_int = INPUT_RATE_DEFAULT;
1130 var_Set( p_input, "rate", val );
1131 vlc_object_release( p_input );
1134 else if( !strcmp( psz_cmd, "chapter" ) ||
1135 !strcmp( psz_cmd, "chapter_n" ) ||
1136 !strcmp( psz_cmd, "chapter_p" ) )
1138 if( !strcmp( psz_cmd, "chapter" ) )
1140 if ( *newval.psz_string )
1143 val.i_int = atoi( newval.psz_string );
1144 var_Set( p_input, "chapter", val );
1148 vlc_value_t val_list;
1151 var_Get( p_input, "chapter", &val );
1152 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1154 msg_rc( "Currently playing chapter %d/%d.",
1155 val.i_int, val_list.p_list->i_count );
1156 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1160 else if( !strcmp( psz_cmd, "chapter_n" ) )
1161 var_SetVoid( p_input, "next-chapter" );
1162 else if( !strcmp( psz_cmd, "chapter_p" ) )
1163 var_SetVoid( p_input, "prev-chapter" );
1164 vlc_object_release( p_input );
1167 else if( !strcmp( psz_cmd, "title" ) ||
1168 !strcmp( psz_cmd, "title_n" ) ||
1169 !strcmp( psz_cmd, "title_p" ) )
1171 if( !strcmp( psz_cmd, "title" ) )
1173 if ( *newval.psz_string )
1176 val.i_int = atoi( newval.psz_string );
1177 var_Set( p_input, "title", val );
1181 vlc_value_t val_list;
1184 var_Get( p_input, "title", &val );
1185 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1187 msg_rc( "Currently playing title %d/%d.",
1188 val.i_int, val_list.p_list->i_count );
1189 var_Change( p_this, "title", VLC_VAR_FREELIST,
1193 else if( !strcmp( psz_cmd, "title_n" ) )
1194 var_SetVoid( p_input, "next-title" );
1195 else if( !strcmp( psz_cmd, "title_p" ) )
1196 var_SetVoid( p_input, "prev-title" );
1198 vlc_object_release( p_input );
1201 else if( !strcmp( psz_cmd, "atrack" )
1202 || !strcmp( psz_cmd, "vtrack" )
1203 || !strcmp( psz_cmd, "strack" ) )
1205 const char *psz_variable;
1206 vlc_value_t val_name;
1209 if( !strcmp( psz_cmd, "atrack" ) )
1211 psz_variable = "audio-es";
1213 else if( !strcmp( psz_cmd, "vtrack" ) )
1215 psz_variable = "video-es";
1219 psz_variable = "spu-es";
1222 /* Get the descriptive name of the variable */
1223 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1225 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1227 if( newval.psz_string && *newval.psz_string )
1231 val.i_int = atoi( newval.psz_string );
1233 i_error = var_Set( p_input, psz_variable, val );
1238 vlc_value_t val, text;
1241 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1243 vlc_object_release( p_input );
1244 return VLC_EGENERIC;
1246 i_value = val.i_int;
1248 if ( var_Change( p_input, psz_variable,
1249 VLC_VAR_GETLIST, &val, &text ) < 0 )
1251 vlc_object_release( p_input );
1252 return VLC_EGENERIC;
1255 msg_rc( "+----[ %s ]", val_name.psz_string );
1256 for ( i = 0; i < val.p_list->i_count; i++ )
1258 if ( i_value == val.p_list->p_values[i].i_int )
1259 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1260 text.p_list->p_values[i].psz_string );
1262 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1263 text.p_list->p_values[i].psz_string );
1265 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1267 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1269 free( val_name.psz_string );
1271 i_error = VLC_SUCCESS;
1273 vlc_object_release( p_input );
1277 /* Never reached. */
1278 vlc_object_release( p_input );
1279 return VLC_EGENERIC;
1282 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1285 char psz_buffer[MSTRTIME_MAX_SIZE];
1286 for( i = 0; i< p_item->i_children; i++ )
1288 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1290 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1291 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1294 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1296 if( p_item->pp_children[i]->i_children >= 0 )
1297 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1301 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1302 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1304 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1307 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1308 playlist_t *p_playlist = pl_Hold( p_this );
1309 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1313 var_Get( p_input, "state", &val );
1314 vlc_object_release( p_input );
1316 if( val.i_int == PAUSE_S )
1318 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1319 pl_Release( p_this );
1320 return VLC_EGENERIC;
1324 /* Parse commands that require a playlist */
1325 if( !strcmp( psz_cmd, "prev" ) )
1327 playlist_Prev( p_playlist );
1329 else if( !strcmp( psz_cmd, "next" ) )
1331 playlist_Next( p_playlist );
1333 else if( !strcmp( psz_cmd, "play" ) )
1335 msg_Warn( p_playlist, "play" );
1336 playlist_Play( p_playlist );
1338 else if( !strcmp( psz_cmd, "repeat" ) )
1340 bool b_update = true;
1342 var_Get( p_playlist, "repeat", &val );
1344 if( strlen( newval.psz_string ) > 0 )
1346 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1347 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1355 val.b_bool = !val.b_bool;
1356 var_Set( p_playlist, "repeat", val );
1358 msg_rc( "Setting repeat to %d", val.b_bool );
1360 else if( !strcmp( psz_cmd, "loop" ) )
1362 bool b_update = true;
1364 var_Get( p_playlist, "loop", &val );
1366 if( strlen( newval.psz_string ) > 0 )
1368 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1369 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1377 val.b_bool = !val.b_bool;
1378 var_Set( p_playlist, "loop", val );
1380 msg_rc( "Setting loop to %d", val.b_bool );
1382 else if( !strcmp( psz_cmd, "random" ) )
1384 bool b_update = true;
1386 var_Get( p_playlist, "random", &val );
1388 if( strlen( newval.psz_string ) > 0 )
1390 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1391 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1399 val.b_bool = !val.b_bool;
1400 var_Set( p_playlist, "random", val );
1402 msg_rc( "Setting random to %d", val.b_bool );
1404 else if (!strcmp( psz_cmd, "goto" ) )
1406 int i_pos = atoi( newval.psz_string );
1407 /* The playlist stores 2 times the same item: onelevel & category */
1408 int i_size = p_playlist->items.i_size / 2;
1411 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1412 else if( i_pos <= i_size )
1414 playlist_item_t *p_item, *p_parent;
1415 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1416 while( p_parent->p_parent )
1417 p_parent = p_parent->p_parent;
1418 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1422 msg_rc( _("Playlist has only %d elements"), i_size );
1424 else if( !strcmp( psz_cmd, "stop" ) )
1426 playlist_Stop( p_playlist );
1428 else if( !strcmp( psz_cmd, "clear" ) )
1430 playlist_Stop( p_playlist );
1431 playlist_Clear( p_playlist, pl_Unlocked );
1433 else if( !strcmp( psz_cmd, "add" ) &&
1434 newval.psz_string && *newval.psz_string )
1436 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1440 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1441 int i_ret =playlist_AddInput( p_playlist, p_item,
1442 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1444 vlc_gc_decref( p_item );
1445 if( i_ret != VLC_SUCCESS )
1447 return VLC_EGENERIC;
1451 else if( !strcmp( psz_cmd, "enqueue" ) &&
1452 newval.psz_string && *newval.psz_string )
1454 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1458 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1459 if( playlist_AddInput( p_playlist, p_item,
1460 PLAYLIST_APPEND, PLAYLIST_END, true,
1461 pl_Unlocked ) != VLC_SUCCESS )
1463 return VLC_EGENERIC;
1467 else if( !strcmp( psz_cmd, "playlist" ) )
1469 msg_rc( "+----[ Playlist ]" );
1470 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1471 msg_rc( "+----[ End of playlist ]" );
1474 else if( !strcmp( psz_cmd, "sort" ))
1476 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1477 SORT_ARTIST, ORDER_NORMAL );
1479 else if( !strcmp( psz_cmd, "status" ) )
1481 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1484 /* Replay the current state of the system. */
1486 input_item_GetURI( input_GetItem( p_input ) );
1487 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1489 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1490 config_GetInt( p_intf, "volume" ));
1493 switch( playlist_Status(p_playlist) )
1495 case PLAYLIST_STOPPED:
1496 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1498 case PLAYLIST_RUNNING:
1499 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1501 case PLAYLIST_PAUSED:
1502 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1505 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1509 vlc_object_release( p_input );
1518 msg_rc( "unknown command!" );
1521 pl_Release( p_this );
1525 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1526 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1528 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1529 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1531 libvlc_Quit( p_this->p_libvlc );
1535 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1536 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1538 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1539 intf_thread_t *p_newintf = NULL;
1541 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string );
1544 if( intf_RunThread( p_newintf ) )
1546 vlc_object_detach( p_newintf );
1547 vlc_object_release( p_newintf );
1554 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1555 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1557 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1558 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1559 input_thread_t *p_input = NULL;
1560 int i_error = VLC_EGENERIC;
1562 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1570 var_Get( p_input, "state", &val );
1571 if( val.i_int == PAUSE_S )
1573 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1574 vlc_object_release( p_input );
1575 return VLC_EGENERIC;
1577 vlc_object_release( p_input );
1580 if ( *newval.psz_string )
1583 audio_volume_t i_volume = atoi( newval.psz_string );
1584 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1586 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1588 i_error = VLC_EBADVAR;
1592 if( i_volume == AOUT_VOLUME_MIN )
1596 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1597 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1599 i_error = aout_VolumeSet( p_this, i_volume );
1600 osd_Volume( p_this );
1601 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1607 audio_volume_t i_volume;
1608 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1610 i_error = VLC_EGENERIC;
1614 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1615 i_error = VLC_SUCCESS;
1622 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1623 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1625 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1626 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1627 audio_volume_t i_volume;
1628 input_thread_t *p_input = NULL;
1629 int i_nb_steps = atoi(newval.psz_string);
1630 int i_error = VLC_SUCCESS;
1631 int i_volume_step = 0;
1633 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1641 var_Get( p_input, "state", &val );
1642 if( val.i_int == PAUSE_S )
1644 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1645 vlc_object_release( p_input );
1646 return VLC_EGENERIC;
1648 vlc_object_release( p_input );
1651 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1652 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1657 if ( !strcmp(psz_cmd, "volup") )
1659 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1660 i_error = VLC_EGENERIC;
1664 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1665 i_error = VLC_EGENERIC;
1667 osd_Volume( p_this );
1669 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1674 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1675 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1677 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1678 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1679 input_thread_t *p_input = NULL;
1680 vout_thread_t * p_vout;
1681 const char * psz_variable = NULL;
1684 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1688 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1689 vlc_object_release( p_input );
1693 if( !strcmp( psz_cmd, "vcrop" ) )
1695 psz_variable = "crop";
1697 else if( !strcmp( psz_cmd, "vratio" ) )
1699 psz_variable = "aspect-ratio";
1701 else if( !strcmp( psz_cmd, "vzoom" ) )
1703 psz_variable = "zoom";
1705 else if( !strcmp( psz_cmd, "snapshot" ) )
1707 psz_variable = "video-snapshot";
1710 /* This case can't happen */
1713 if( newval.psz_string && *newval.psz_string )
1716 if( !strcmp( psz_variable, "zoom" ) )
1719 val.f_float = atof( newval.psz_string );
1720 i_error = var_Set( p_vout, psz_variable, val );
1724 i_error = var_Set( p_vout, psz_variable, newval );
1727 else if( !strcmp( psz_cmd, "snapshot" ) )
1731 i_error = var_Set( p_vout, psz_variable, val );
1736 vlc_value_t val_name;
1737 vlc_value_t val, text;
1740 char *psz_value = NULL;
1742 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1744 vlc_object_release( p_vout );
1745 return VLC_EGENERIC;
1747 if( !strcmp( psz_variable, "zoom" ) )
1749 f_value = val.f_float;
1753 psz_value = strdup( val.psz_string );
1756 if ( var_Change( p_vout, psz_variable,
1757 VLC_VAR_GETLIST, &val, &text ) < 0 )
1759 vlc_object_release( p_vout );
1761 return VLC_EGENERIC;
1764 /* Get the descriptive name of the variable */
1765 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1767 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1769 msg_rc( "+----[ %s ]", val_name.psz_string );
1770 if( !strcmp( psz_variable, "zoom" ) )
1772 for ( i = 0; i < val.p_list->i_count; i++ )
1774 if ( f_value == val.p_list->p_values[i].f_float )
1775 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1776 text.p_list->p_values[i].psz_string );
1778 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1779 text.p_list->p_values[i].psz_string );
1784 for ( i = 0; i < val.p_list->i_count; i++ )
1786 if ( !strcmp( psz_value, val.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 );
1790 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1791 text.p_list->p_values[i].psz_string );
1795 var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1797 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1799 free( val_name.psz_string );
1801 i_error = VLC_SUCCESS;
1803 vlc_object_release( p_vout );
1807 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1808 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1810 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1811 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1812 input_thread_t *p_input = NULL;
1813 aout_instance_t * p_aout;
1814 const char * psz_variable;
1815 vlc_value_t val_name;
1818 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1826 var_Get( p_input, "state", &val );
1827 if( val.i_int == PAUSE_S )
1829 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1830 vlc_object_release( p_input );
1831 return VLC_EGENERIC;
1833 vlc_object_release( p_input );
1836 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1837 if ( p_aout == NULL ) return VLC_ENOOBJ;
1839 if ( !strcmp( psz_cmd, "adev" ) )
1841 psz_variable = "audio-device";
1845 psz_variable = "audio-channels";
1848 /* Get the descriptive name of the variable */
1849 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1851 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1853 if ( !*newval.psz_string )
1855 /* Retrieve all registered ***. */
1856 vlc_value_t val, text;
1859 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1861 vlc_object_release( (vlc_object_t *)p_aout );
1862 return VLC_EGENERIC;
1864 i_value = val.i_int;
1866 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1867 VLC_VAR_GETLIST, &val, &text ) < 0 )
1869 vlc_object_release( (vlc_object_t *)p_aout );
1870 return VLC_EGENERIC;
1873 msg_rc( "+----[ %s ]", val_name.psz_string );
1874 for ( i = 0; i < val.p_list->i_count; i++ )
1876 if ( i_value == val.p_list->p_values[i].i_int )
1877 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1878 text.p_list->p_values[i].psz_string );
1880 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1881 text.p_list->p_values[i].psz_string );
1883 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1885 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1887 free( val_name.psz_string );
1888 i_error = VLC_SUCCESS;
1893 val.i_int = atoi( newval.psz_string );
1895 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1897 vlc_object_release( (vlc_object_t *)p_aout );
1902 /* OSD menu commands */
1903 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1904 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1906 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1907 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1908 playlist_t *p_playlist = NULL;
1909 int i_error = VLC_SUCCESS;
1912 if ( !*newval.psz_string )
1914 msg_rc( _("Please provide one of the following parameters:") );
1915 msg_rc( "[on|off|up|down|left|right|select]" );
1916 return VLC_EGENERIC;
1919 p_playlist = pl_Hold( p_this );
1920 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1924 var_Get( p_input, "state", &val );
1925 vlc_object_release( p_input );
1927 if( ( val.i_int == PAUSE_S ) &&
1928 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1930 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1931 pl_Release( p_this );
1932 return VLC_EGENERIC;
1935 pl_Release( p_this );
1937 val.psz_string = strdup( newval.psz_string );
1938 if( !val.psz_string )
1940 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1941 osd_MenuShow( p_this );
1942 else if( !strcmp( val.psz_string, "off" )
1943 || !strcmp( val.psz_string, "hide" ) )
1944 osd_MenuHide( p_this );
1945 else if( !strcmp( val.psz_string, "up" ) )
1946 osd_MenuUp( p_this );
1947 else if( !strcmp( val.psz_string, "down" ) )
1948 osd_MenuDown( p_this );
1949 else if( !strcmp( val.psz_string, "left" ) )
1950 osd_MenuPrev( p_this );
1951 else if( !strcmp( val.psz_string, "right" ) )
1952 osd_MenuNext( p_this );
1953 else if( !strcmp( val.psz_string, "select" ) )
1954 osd_MenuActivate( p_this );
1957 msg_rc( _("Please provide one of the following parameters:") );
1958 msg_rc( "[on|off|up|down|left|right|select]" );
1959 i_error = VLC_EGENERIC;
1962 free( val.psz_string );
1966 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1967 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1969 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1970 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1971 input_thread_t *p_input = NULL;
1974 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1978 if( !strcmp( psz_cmd, "stats" ) )
1980 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1981 updateStatistics( p_intf, input_GetItem(p_input) );
1982 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1989 msg_rc(_("Unknown command!") );
1992 vlc_object_release( p_input );
1993 i_error = VLC_SUCCESS;
1997 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1999 if( !p_item ) return VLC_EGENERIC;
2001 vlc_mutex_lock( &p_item->p_stats->lock );
2002 msg_rc( "+----[ begin of statistical info ]" );
2005 msg_rc(_("+-[Incoming]"));
2006 msg_rc(_("| input bytes read : %8.0f kB"),
2007 (float)(p_item->p_stats->i_read_bytes)/1000 );
2008 msg_rc(_("| input bitrate : %6.0f kb/s"),
2009 (float)(p_item->p_stats->f_input_bitrate)*8000 );
2010 msg_rc(_("| demux bytes read : %8.0f kB"),
2011 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
2012 msg_rc(_("| demux bitrate : %6.0f kb/s"),
2013 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
2016 msg_rc(_("+-[Video Decoding]"));
2017 msg_rc(_("| video decoded : %5i"),
2018 p_item->p_stats->i_decoded_video );
2019 msg_rc(_("| frames displayed : %5i"),
2020 p_item->p_stats->i_displayed_pictures );
2021 msg_rc(_("| frames lost : %5i"),
2022 p_item->p_stats->i_lost_pictures );
2025 msg_rc(_("+-[Audio Decoding]"));
2026 msg_rc(_("| audio decoded : %5i"),
2027 p_item->p_stats->i_decoded_audio );
2028 msg_rc(_("| buffers played : %5i"),
2029 p_item->p_stats->i_played_abuffers );
2030 msg_rc(_("| buffers lost : %5i"),
2031 p_item->p_stats->i_lost_abuffers );
2034 msg_rc(_("+-[Streaming]"));
2035 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
2036 msg_rc(_("| bytes sent : %8.0f kB"),
2037 (float)(p_item->p_stats->i_sent_bytes)/1000 );
2038 msg_rc(_("| sending bitrate : %6.0f kb/s"),
2039 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
2041 msg_rc( "+----[ end of statistical info ]" );
2042 vlc_mutex_unlock( &p_item->p_stats->lock );
2048 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2050 INPUT_RECORD input_record;
2053 /* On Win32, select() only works on socket descriptors */
2054 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2055 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2057 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2058 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2061 if( input_record.EventType != KEY_EVENT ||
2062 !input_record.Event.KeyEvent.bKeyDown ||
2063 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2064 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2065 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2066 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2068 /* nothing interesting */
2072 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2074 /* Echo out the command */
2075 putc( p_buffer[ *pi_size ], stdout );
2077 /* Handle special keys */
2078 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2080 putc( '\n', stdout );
2083 switch( p_buffer[ *pi_size ] )
2089 putc( ' ', stdout );
2090 putc( '\b', stdout );
2101 if( *pi_size == MAX_LINE_LENGTH ||
2102 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2104 p_buffer[ *pi_size ] = 0;
2113 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2118 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2119 return ReadWin32( p_intf, p_buffer, pi_size );
2120 else if( p_intf->p_sys->i_socket == -1 )
2122 msleep( INTF_IDLE_SLEEP );
2127 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2128 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2129 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2130 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2132 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2138 /* Connection closed */
2141 if( p_intf->p_sys->i_socket != -1 )
2143 net_Close( p_intf->p_sys->i_socket );
2144 p_intf->p_sys->i_socket = -1;
2148 /* Standard input closed: exit */
2150 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2153 p_buffer[ *pi_size ] = 0;
2157 if( *pi_size == MAX_LINE_LENGTH ||
2158 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2160 p_buffer[ *pi_size ] = 0;
2167 /*****************************************************************************
2168 * parse_MRL: build a input item from a full mrl
2169 *****************************************************************************
2170 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2171 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2172 * space is a new option. Should be good enough for our purpose.
2173 *****************************************************************************/
2174 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2176 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2177 #define SKIPTRAILINGSPACE( p, d ) \
2178 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2180 input_item_t *p_item = NULL;
2181 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2182 char **ppsz_options = NULL;
2183 int i, i_options = 0;
2185 if( !psz_mrl ) return 0;
2187 psz_mrl = psz_orig = strdup( psz_mrl );
2190 SKIPSPACE( psz_mrl );
2193 for( ; *psz_mrl; psz_mrl++ )
2195 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2197 /* We have a complete item */
2200 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2201 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2203 /* We have a complete item */
2208 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2209 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2211 /* Remove '"' and '\'' if necessary */
2212 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2213 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2214 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2215 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2217 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2218 else if( *psz_item )
2221 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2222 ppsz_options[i_options - 1] = &psz_item[1];
2225 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2228 /* Now create a playlist item */
2231 p_item = input_item_New( p_intf, psz_item_mrl, NULL );
2232 for( i = 0; i < i_options; i++ )
2234 input_item_AddOption( p_item, ppsz_options[i], VLC_INPUT_OPTION_TRUSTED );
2238 if( i_options ) free( ppsz_options );