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 */
40 #include <vlc_interface.h>
44 #include <vlc_playlist.h>
50 #include <sys/types.h>
52 #include <vlc_network.h>
55 #include <vlc_charset.h>
57 #if defined(PF_UNIX) && !defined(PF_LOCAL)
58 # define PF_LOCAL PF_UNIX
61 #if defined(AF_LOCAL) && ! defined(WIN32)
65 #define MAX_LINE_LENGTH 1024
66 #define STATUS_CHANGE "status change: "
68 /* input_state_e from <vlc_input.h> */
69 static const char *ppsz_input_state[] = {
70 [INIT_S] = N_("Initializing"),
71 [OPENING_S] = N_("Opening"),
72 [PLAYING_S] = N_("Play"),
73 [PAUSE_S] = N_("Pause"),
75 [ERROR_S] = N_("Error"),
78 /*****************************************************************************
80 *****************************************************************************/
81 static int Activate ( vlc_object_t * );
82 static void Deactivate ( vlc_object_t * );
83 static void Run ( intf_thread_t * );
85 static void Help ( intf_thread_t *, bool );
86 static void RegisterCallbacks( intf_thread_t * );
88 static bool ReadCommand( intf_thread_t *, char *, int * );
90 static input_item_t *parse_MRL( intf_thread_t *, char * );
92 static int Input ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int Playlist ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
96 static int Quit ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
98 static int Intf ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int Volume ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int VolumeMove ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int VideoConfig ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int AudioConfig ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int Menu ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
110 static int Statistics ( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t, void * );
113 static int updateStatistics( intf_thread_t *, input_item_t *);
115 /* Status Callbacks */
116 static int VolumeChanged( vlc_object_t *, char const *,
117 vlc_value_t, vlc_value_t, void * );
118 static int InputEvent( vlc_object_t *, char const *,
119 vlc_value_t, vlc_value_t, void * );
123 int *pi_socket_listen;
128 vlc_mutex_t status_lock;
129 playlist_status_t i_last_state;
130 playlist_t *p_playlist;
131 bool b_input_buffering;
139 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
142 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
145 char fmt_eol[strlen (psz_fmt) + 3];
147 snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
148 va_start( args, psz_fmt );
150 if( p_intf->p_sys->i_socket == -1 )
151 utf8_vfprintf( stdout, fmt_eol, args );
153 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
157 /*****************************************************************************
159 *****************************************************************************/
160 #define POS_TEXT N_("Show stream position")
161 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
162 "stream from time to time." )
164 #define TTY_TEXT N_("Fake TTY")
165 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
167 #define UNIX_TEXT N_("UNIX socket command input")
168 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
171 #define HOST_TEXT N_("TCP command input")
172 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
173 "You can set the address and port the interface will bind to." )
176 #define QUIET_TEXT N_("Do not open a DOS command box interface")
177 #define QUIET_LONGTEXT N_( \
178 "By default the rc interface plugin will start a DOS command box. " \
179 "Enabling the quiet mode will not bring this command box but can also " \
180 "be pretty annoying when you want to stop VLC and no video window is " \
185 set_shortname( N_("RC"))
186 set_category( CAT_INTERFACE )
187 set_subcategory( SUBCAT_INTERFACE_MAIN )
188 set_description( N_("Remote control interface") )
189 add_bool( "rc-show-pos", false, NULL, POS_TEXT, POS_LONGTEXT, true )
192 add_bool( "rc-quiet", false, NULL, QUIET_TEXT, QUIET_LONGTEXT, false )
194 #if defined (HAVE_ISATTY)
195 add_bool( "rc-fake-tty", false, NULL, TTY_TEXT, TTY_LONGTEXT, true )
197 add_string( "rc-unix", NULL, NULL, UNIX_TEXT, UNIX_LONGTEXT, true )
199 add_string( "rc-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, true )
201 set_capability( "interface", 20 )
203 set_callbacks( Activate, Deactivate )
206 /*****************************************************************************
207 * Activate: initialize and create stuff
208 *****************************************************************************/
209 static int Activate( vlc_object_t *p_this )
211 intf_thread_t *p_intf = (intf_thread_t*)p_this;
212 char *psz_host, *psz_unix_path = NULL;
213 int *pi_socket = NULL;
216 #if defined(HAVE_ISATTY)
217 /* Check that stdin is a TTY */
218 if( !var_InheritInteger( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
220 msg_Warn( p_intf, "fd 0 is not a TTY" );
225 psz_unix_path = var_InheritString( p_intf, "rc-unix" );
231 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
232 free( psz_unix_path );
235 struct sockaddr_un addr;
237 memset( &addr, 0, sizeof(struct sockaddr_un) );
239 msg_Dbg( p_intf, "trying UNIX socket" );
241 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
243 msg_Warn( p_intf, "can't open socket: %m" );
244 free( psz_unix_path );
248 addr.sun_family = AF_LOCAL;
249 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
250 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
252 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
253 && (errno == EADDRINUSE)
254 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
255 && (errno == ECONNREFUSED))
257 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
258 unlink (psz_unix_path);
260 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
262 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
264 free (psz_unix_path);
265 net_Close (i_socket);
270 if( listen( i_socket, 1 ) )
272 msg_Warn( p_intf, "can't listen on socket: %m");
273 free( psz_unix_path );
274 net_Close( i_socket );
278 /* FIXME: we need a core function to merge listening sockets sets */
279 pi_socket = calloc( 2, sizeof( int ) );
280 if( pi_socket == NULL )
282 free( psz_unix_path );
283 net_Close( i_socket );
286 pi_socket[0] = i_socket;
288 #endif /* AF_LOCAL */
292 if( ( pi_socket == NULL ) &&
293 ( psz_host = var_InheritString( p_intf, "rc-host" ) ) != NULL )
297 vlc_UrlParse( &url, psz_host, 0 );
299 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
301 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
302 if( pi_socket == NULL )
304 msg_Warn( p_intf, "can't listen to %s port %i",
305 url.psz_host, url.i_port );
306 vlc_UrlClean( &url );
311 vlc_UrlClean( &url );
315 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
319 p_intf->p_sys->pi_socket_listen = pi_socket;
320 p_intf->p_sys->i_socket = -1;
321 p_intf->p_sys->psz_unix_path = psz_unix_path;
322 vlc_mutex_init( &p_intf->p_sys->status_lock );
323 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
324 p_intf->p_sys->b_input_buffering = false;
326 /* Non-buffered stdout */
327 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
329 p_intf->pf_run = Run;
332 p_intf->p_sys->b_quiet = var_InheritInteger( p_intf, "rc-quiet" );
333 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
338 msg_rc( "%s", _("Remote control interface initialized. Type `help' for help.") );
342 /*****************************************************************************
343 * Deactivate: uninitialize and cleanup
344 *****************************************************************************/
345 static void Deactivate( vlc_object_t *p_this )
347 intf_thread_t *p_intf = (intf_thread_t*)p_this;
349 net_ListenClose( p_intf->p_sys->pi_socket_listen );
350 if( p_intf->p_sys->i_socket != -1 )
351 net_Close( p_intf->p_sys->i_socket );
352 if( p_intf->p_sys->psz_unix_path != NULL )
354 #if defined(AF_LOCAL) && !defined(WIN32)
355 unlink( p_intf->p_sys->psz_unix_path );
357 free( p_intf->p_sys->psz_unix_path );
359 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
360 free( p_intf->p_sys );
363 /*****************************************************************************
364 * RegisterCallbacks: Register callbacks to dynamic variables
365 *****************************************************************************/
366 static void RegisterCallbacks( intf_thread_t *p_intf )
368 /* Register commands that will be cleaned up upon object destruction */
369 #define ADD( name, type, target ) \
370 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
371 var_AddCallback( p_intf, name, target, NULL );
372 ADD( "quit", VOID, Quit )
373 ADD( "intf", STRING, Intf )
375 ADD( "add", STRING, Playlist )
376 ADD( "repeat", STRING, Playlist )
377 ADD( "loop", STRING, Playlist )
378 ADD( "random", STRING, Playlist )
379 ADD( "enqueue", STRING, Playlist )
380 ADD( "playlist", VOID, Playlist )
381 ADD( "sort", VOID, Playlist )
382 ADD( "play", VOID, Playlist )
383 ADD( "stop", VOID, Playlist )
384 ADD( "clear", VOID, Playlist )
385 ADD( "prev", VOID, Playlist )
386 ADD( "next", VOID, Playlist )
387 ADD( "goto", INTEGER, Playlist )
388 ADD( "status", INTEGER, Playlist )
390 /* OSD menu commands */
391 ADD( "menu", STRING, Menu )
394 ADD( "pause", VOID, Input )
395 ADD( "seek", INTEGER, Input )
396 ADD( "title", STRING, Input )
397 ADD( "title_n", VOID, Input )
398 ADD( "title_p", VOID, Input )
399 ADD( "chapter", STRING, Input )
400 ADD( "chapter_n", VOID, Input )
401 ADD( "chapter_p", VOID, Input )
403 ADD( "fastforward", VOID, Input )
404 ADD( "rewind", VOID, Input )
405 ADD( "faster", VOID, Input )
406 ADD( "slower", VOID, Input )
407 ADD( "normal", VOID, Input )
408 ADD( "frame", VOID, Input )
410 ADD( "atrack", STRING, Input )
411 ADD( "vtrack", STRING, Input )
412 ADD( "strack", STRING, Input )
415 ADD( "vratio", STRING, VideoConfig )
416 ADD( "vcrop", STRING, VideoConfig )
417 ADD( "vzoom", STRING, VideoConfig )
418 ADD( "snapshot", VOID, VideoConfig )
421 ADD( "volume", STRING, Volume )
422 ADD( "volup", STRING, VolumeMove )
423 ADD( "voldown", STRING, VolumeMove )
424 ADD( "adev", STRING, AudioConfig )
425 ADD( "achan", STRING, AudioConfig )
427 /* misc menu commands */
428 ADD( "stats", BOOL, Statistics )
433 /*****************************************************************************
435 *****************************************************************************
436 * This part of the interface is in a separate thread so that we can call
437 * exec() from within it without annoying the rest of the program.
438 *****************************************************************************/
439 static void Run( intf_thread_t *p_intf )
441 input_thread_t * p_input = NULL;
442 playlist_t * p_playlist = pl_Get( p_intf );
444 char p_buffer[ MAX_LINE_LENGTH + 1 ];
445 bool b_showpos = var_InheritInteger( p_intf, "rc-show-pos" );
446 bool b_longhelp = false;
451 int canc = vlc_savecancel();
455 /* Register commands that will be cleaned up upon object destruction */
456 p_intf->p_sys->p_playlist = p_playlist;
457 RegisterCallbacks( p_intf );
459 /* status callbacks */
460 /* Listen to audio volume updates */
461 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
464 /* Get the file descriptor of the console input */
465 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
466 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
468 msg_Err( p_intf, "couldn't find user input handle" );
469 vlc_object_kill( p_intf );
473 while( vlc_object_alive( p_intf ) )
475 char *psz_cmd, *psz_arg;
478 if( p_intf->p_sys->pi_socket_listen != NULL &&
479 p_intf->p_sys->i_socket == -1 )
481 p_intf->p_sys->i_socket =
482 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen );
483 if( p_intf->p_sys->i_socket == -1 ) continue;
486 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
488 /* Manage the input part */
489 if( p_input == NULL )
491 p_input = playlist_CurrentInput( p_playlist );
492 /* New input has been registered */
495 if( !p_input->b_dead || vlc_object_alive (p_input) )
498 input_item_GetURI( input_GetItem( p_input ) );
499 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
501 msg_rc( STATUS_CHANGE "( audio volume: %d )",
502 config_GetInt( p_intf, "volume" ));
504 var_AddCallback( p_input, "intf-event", InputEvent, p_intf );
507 else if( p_input->b_dead )
509 var_DelCallback( p_input, "intf-event", InputEvent, p_intf );
510 vlc_object_release( p_input );
516 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
517 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
522 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
523 (p_playlist != NULL) )
526 int status = playlist_Status( p_playlist );
527 if( p_intf->p_sys->i_last_state != status )
529 if( status == PLAYLIST_STOPPED )
531 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
532 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
534 else if( status == PLAYLIST_RUNNING )
536 p_intf->p_sys->i_last_state = PLAYLIST_RUNNING;
537 msg_rc( STATUS_CHANGE "( play state: 3 )" );
539 else if( status == PLAYLIST_PAUSED )
541 p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
542 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
548 if( p_input && b_showpos )
550 i_newpos = 100 * var_GetFloat( p_input, "position" );
551 if( i_oldpos != i_newpos )
554 msg_rc( "pos: %d%%", i_newpos );
558 /* Is there something to do? */
559 if( !b_complete ) continue;
561 /* Skip heading spaces */
563 while( *psz_cmd == ' ' )
568 /* Split psz_cmd at the first space and make sure that
569 * psz_arg is valid */
570 psz_arg = strchr( psz_cmd, ' ' );
574 while( *psz_arg == ' ' )
584 /* module specfic commands: @<module name> <command> <args...> */
585 if( *psz_cmd == '@' && *psz_arg )
587 /* Parse miscellaneous commands */
588 char *psz_alias = psz_cmd + 1;
589 char *psz_mycmd = strdup( psz_arg );
590 char *psz_myarg = strchr( psz_mycmd, ' ' );
595 msg_rc( "Not enough parameters." );
602 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
607 msg_rc( "%s", psz_msg );
613 /* If the user typed a registered local command, try it */
614 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
619 val.psz_string = psz_arg;
620 i_ret = var_Set( p_intf, psz_cmd, val );
621 msg_rc( "%s: returned %i (%s)",
622 psz_cmd, i_ret, vlc_error( i_ret ) );
624 /* Or maybe it's a global command */
625 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
630 val.psz_string = psz_arg;
631 /* FIXME: it's a global command, but we should pass the
632 * local object as an argument, not p_intf->p_libvlc. */
633 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
636 msg_rc( "%s: returned %i (%s)",
637 psz_cmd, i_ret, vlc_error( i_ret ) );
640 else if( !strcmp( psz_cmd, "logout" ) )
642 /* Close connection */
643 if( p_intf->p_sys->i_socket != -1 )
645 net_Close( p_intf->p_sys->i_socket );
647 p_intf->p_sys->i_socket = -1;
649 else if( !strcmp( psz_cmd, "info" ) )
654 vlc_mutex_lock( &input_GetItem(p_input)->lock );
655 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
657 info_category_t *p_category = input_GetItem(p_input)
660 msg_rc( "+----[ %s ]", p_category->psz_name );
662 for ( j = 0; j < p_category->i_infos; j++ )
664 info_t *p_info = p_category->pp_infos[j];
665 msg_rc( "| %s: %s", p_info->psz_name,
670 msg_rc( "+----[ end of stream info ]" );
671 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
675 msg_rc( "no input" );
678 else if( !strcmp( psz_cmd, "is_playing" ) )
689 else if( !strcmp( psz_cmd, "get_time" ) )
698 var_Get( p_input, "time", &time );
699 msg_rc( "%"PRIu64, time.i_time / 1000000);
702 else if( !strcmp( psz_cmd, "get_length" ) )
711 var_Get( p_input, "length", &time );
712 msg_rc( "%"PRIu64, time.i_time / 1000000);
715 else if( !strcmp( psz_cmd, "get_title" ) )
723 msg_rc( "%s", input_GetItem(p_input)->psz_name );
726 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
727 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
729 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
731 else b_longhelp = false;
733 Help( p_intf, b_longhelp );
735 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
737 var_SetInteger( p_intf->p_libvlc, "key-action",
738 vlc_GetActionId( psz_arg ) );
740 else switch( psz_cmd[0] )
746 vout_thread_t *p_vout;
747 p_vout = input_GetVout( p_input );
752 bool b_update = false;
753 var_Get( p_vout, "fullscreen", &val );
754 val.b_bool = !val.b_bool;
755 if( !strncmp( psz_arg, "on", 2 )
756 && ( val.b_bool == true ) )
761 else if( !strncmp( psz_arg, "off", 3 )
762 && ( val.b_bool == false ) )
767 else if( strncmp( psz_arg, "off", 3 )
768 && strncmp( psz_arg, "on", 2 ) )
770 if( b_update ) var_Set( p_vout, "fullscreen", val );
771 vlc_object_release( p_vout );
782 /* Ignore empty lines */
786 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
790 /* Command processed */
791 i_size = 0; p_buffer[0] = 0;
794 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
795 msg_rc( STATUS_CHANGE "( quit )" );
799 var_DelCallback( p_input, "intf-event", InputEvent, p_intf );
800 vlc_object_release( p_input );
803 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
804 vlc_restorecancel( canc );
807 static void Help( intf_thread_t *p_intf, bool b_longhelp)
809 msg_rc("%s", _("+----[ Remote control commands ]"));
811 msg_rc("%s", _("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
812 msg_rc("%s", _("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
813 msg_rc("%s", _("| playlist . . . . . show items currently in playlist"));
814 msg_rc("%s", _("| play . . . . . . . . . . . . . . . . . . play stream"));
815 msg_rc("%s", _("| stop . . . . . . . . . . . . . . . . . . stop stream"));
816 msg_rc("%s", _("| next . . . . . . . . . . . . . . next playlist item"));
817 msg_rc("%s", _("| prev . . . . . . . . . . . . previous playlist item"));
818 msg_rc("%s", _("| goto . . . . . . . . . . . . . . goto item at index"));
819 msg_rc("%s", _("| repeat [on|off] . . . . toggle playlist item repeat"));
820 msg_rc("%s", _("| loop [on|off] . . . . . . . . . toggle playlist loop"));
821 msg_rc("%s", _("| random [on|off] . . . . . . . toggle random jumping"));
822 msg_rc("%s", _("| clear . . . . . . . . . . . . . . clear the playlist"));
823 msg_rc("%s", _("| status . . . . . . . . . . . current playlist status"));
824 msg_rc("%s", _("| title [X] . . . . . . set/get title in current item"));
825 msg_rc("%s", _("| title_n . . . . . . . . next title in current item"));
826 msg_rc("%s", _("| title_p . . . . . . previous title in current item"));
827 msg_rc("%s", _("| chapter [X] . . . . set/get chapter in current item"));
828 msg_rc("%s", _("| chapter_n . . . . . . next chapter in current item"));
829 msg_rc("%s", _("| chapter_p . . . . previous chapter in current item"));
831 msg_rc("%s", _("| seek X . . . seek in seconds, for instance `seek 12'"));
832 msg_rc("%s", _("| pause . . . . . . . . . . . . . . . . toggle pause"));
833 msg_rc("%s", _("| fastforward . . . . . . . . . set to maximum rate"));
834 msg_rc("%s", _("| rewind . . . . . . . . . . . . set to minimum rate"));
835 msg_rc("%s", _("| faster . . . . . . . . . . faster playing of stream"));
836 msg_rc("%s", _("| slower . . . . . . . . . . slower playing of stream"));
837 msg_rc("%s", _("| normal . . . . . . . . . . normal playing of stream"));
838 msg_rc("%s", _("| frame. . . . . . . . . . play frame by frame"));
839 msg_rc("%s", _("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
840 msg_rc("%s", _("| info . . . . . information about the current stream"));
841 msg_rc("%s", _("| stats . . . . . . . . show statistical information"));
842 msg_rc("%s", _("| get_time . . seconds elapsed since stream's beginning"));
843 msg_rc("%s", _("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
844 msg_rc("%s", _("| get_title . . . . . the title of the current stream"));
845 msg_rc("%s", _("| get_length . . . . the length of the current stream"));
847 msg_rc("%s", _("| volume [X] . . . . . . . . . . set/get audio volume"));
848 msg_rc("%s", _("| volup [X] . . . . . . . raise audio volume X steps"));
849 msg_rc("%s", _("| voldown [X] . . . . . . lower audio volume X steps"));
850 msg_rc("%s", _("| adev [X] . . . . . . . . . . . set/get audio device"));
851 msg_rc("%s", _("| achan [X]. . . . . . . . . . set/get audio channels"));
852 msg_rc("%s", _("| atrack [X] . . . . . . . . . . . set/get audio track"));
853 msg_rc("%s", _("| vtrack [X] . . . . . . . . . . . set/get video track"));
854 msg_rc("%s", _("| vratio [X] . . . . . . . set/get video aspect ratio"));
855 msg_rc("%s", _("| vcrop [X] . . . . . . . . . . . set/get video crop"));
856 msg_rc("%s", _("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
857 msg_rc("%s", _("| snapshot . . . . . . . . . . . . take video snapshot"));
858 msg_rc("%s", _("| strack [X] . . . . . . . . . set/get subtitles track"));
859 msg_rc("%s", _("| key [hotkey name] . . . . . . simulate hotkey press"));
860 msg_rc("%s", _("| menu . . [on|off|up|down|left|right|select] use menu"));
865 msg_rc("%s", _("| @name marq-marquee STRING . . overlay STRING in video"));
866 msg_rc("%s", _("| @name marq-x X . . . . . . . . . . . .offset from left"));
867 msg_rc("%s", _("| @name marq-y Y . . . . . . . . . . . . offset from top"));
868 msg_rc("%s", _("| @name marq-position #. . . .relative position control"));
869 msg_rc("%s", _("| @name marq-color # . . . . . . . . . . font color, RGB"));
870 msg_rc("%s", _("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
871 msg_rc("%s", _("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
872 msg_rc("%s", _("| @name marq-size # . . . . . . . . font size, in pixels"));
874 msg_rc("%s", _("| @name logo-file STRING . . .the overlay file path/name"));
875 msg_rc("%s", _("| @name logo-x X . . . . . . . . . . . .offset from left"));
876 msg_rc("%s", _("| @name logo-y Y . . . . . . . . . . . . offset from top"));
877 msg_rc("%s", _("| @name logo-position #. . . . . . . . relative position"));
878 msg_rc("%s", _("| @name logo-transparency #. . . . . . . . .transparency"));
880 msg_rc("%s", _("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
881 msg_rc("%s", _("| @name mosaic-height #. . . . . . . . . . . . . .height"));
882 msg_rc("%s", _("| @name mosaic-width # . . . . . . . . . . . . . . width"));
883 msg_rc("%s", _("| @name mosaic-xoffset # . . . .top left corner position"));
884 msg_rc("%s", _("| @name mosaic-yoffset # . . . .top left corner position"));
885 msg_rc("%s", _("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
886 msg_rc("%s", _("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
887 msg_rc("%s", _("| @name mosaic-vborder # . . . . . . . . vertical border"));
888 msg_rc("%s", _("| @name mosaic-hborder # . . . . . . . horizontal border"));
889 msg_rc("%s", _("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
890 msg_rc("%s", _("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
891 msg_rc("%s", _("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
892 msg_rc("%s", _("| @name mosaic-order id(,id)* . . . . order of pictures "));
893 msg_rc("%s", _("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
896 msg_rc("%s", _("| help . . . . . . . . . . . . . . . this help message"));
897 msg_rc("%s", _("| longhelp . . . . . . . . . . . a longer help message"));
898 msg_rc("%s", _("| logout . . . . . . . exit (if in socket connection)"));
899 msg_rc("%s", _("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
901 msg_rc("%s", _("+----[ end of help ]"));
904 /********************************************************************
905 * Status callback routines
906 ********************************************************************/
907 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
908 vlc_value_t oldval, vlc_value_t newval, void *p_data )
910 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
911 intf_thread_t *p_intf = (intf_thread_t*)p_data;
913 vlc_mutex_lock( &p_intf->p_sys->status_lock );
914 msg_rc( STATUS_CHANGE "( audio volume: %d )",
915 config_GetInt( p_this, "volume") );
916 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
920 static void StateChanged( intf_thread_t *p_intf, input_thread_t *p_input )
922 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
925 const int i_status = playlist_Status( p_playlist );
932 case PLAYLIST_STOPPED:
935 case PLAYLIST_RUNNING:
938 case PLAYLIST_PAUSED:
947 const int i_state = var_GetInteger( p_input, "state" );
949 vlc_mutex_lock( &p_intf->p_sys->status_lock );
950 msg_rc( STATUS_CHANGE "( %s state: %d ): %s", psz_cmd,
951 i_state, ppsz_input_state[i_state] );
952 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
954 static void RateChanged( intf_thread_t *p_intf,
955 input_thread_t *p_input )
957 vlc_mutex_lock( &p_intf->p_sys->status_lock );
958 msg_rc( STATUS_CHANGE "( new rate: %.3f )",
959 var_GetFloat( p_input, "rate" ) );
960 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
962 static void PositionChanged( intf_thread_t *p_intf,
963 input_thread_t *p_input )
965 vlc_mutex_lock( &p_intf->p_sys->status_lock );
966 if( p_intf->p_sys->b_input_buffering )
967 msg_rc( STATUS_CHANGE "( time: %"PRId64"s )",
968 (var_GetTime( p_input, "time" )/1000000) );
969 p_intf->p_sys->b_input_buffering = false;
970 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
972 static void CacheChanged( intf_thread_t *p_intf )
974 vlc_mutex_lock( &p_intf->p_sys->status_lock );
975 p_intf->p_sys->b_input_buffering = true;
976 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
979 static int InputEvent( vlc_object_t *p_this, char const *psz_cmd,
980 vlc_value_t oldval, vlc_value_t newval, void *p_data )
984 input_thread_t *p_input = (input_thread_t*)p_this;
985 intf_thread_t *p_intf = p_data;
987 switch( newval.i_int )
989 case INPUT_EVENT_STATE:
990 case INPUT_EVENT_DEAD:
991 StateChanged( p_intf, p_input );
993 case INPUT_EVENT_RATE:
994 RateChanged( p_intf, p_input );
996 case INPUT_EVENT_POSITION:
997 PositionChanged( p_intf, p_input );
999 case INPUT_EVENT_CACHE:
1000 CacheChanged( p_intf );
1008 /********************************************************************
1010 ********************************************************************/
1011 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1012 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1014 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1015 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1016 input_thread_t *p_input =
1017 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1018 int i_error = VLC_EGENERIC;
1023 int state = var_GetInteger( p_input, "state" );
1024 if( ( state == PAUSE_S ) &&
1025 ( strcmp( psz_cmd, "pause" ) != 0 ) && (strcmp( psz_cmd,"frame") != 0 ) )
1027 msg_rc( "%s", _("Press menu select or pause to continue.") );
1030 /* Parse commands that only require an input */
1031 if( !strcmp( psz_cmd, "pause" ) )
1033 playlist_Pause( p_intf->p_sys->p_playlist );
1034 i_error = VLC_SUCCESS;
1036 else if( !strcmp( psz_cmd, "seek" ) )
1038 if( strlen( newval.psz_string ) > 0 &&
1039 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1041 float f = atof( newval.psz_string ) / 100.0;
1042 var_SetFloat( p_input, "position", f );
1046 mtime_t t = ((int64_t)atoi( newval.psz_string )) * CLOCK_FREQ;
1047 var_SetTime( p_input, "time", t );
1049 i_error = VLC_SUCCESS;
1051 else if ( !strcmp( psz_cmd, "fastforward" ) )
1053 if( var_GetBool( p_input, "can-rate" ) )
1055 float f_rate = var_GetFloat( p_input, "rate" );
1056 f_rate = (f_rate < 0) ? -f_rate : f_rate * 2;
1057 var_SetFloat( p_input, "rate", f_rate );
1061 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_EXTRASHORT );
1063 i_error = VLC_SUCCESS;
1065 else if ( !strcmp( psz_cmd, "rewind" ) )
1067 if( var_GetBool( p_input, "can-rewind" ) )
1069 float f_rate = var_GetFloat( p_input, "rate" );
1070 f_rate = (f_rate > 0) ? -f_rate : f_rate * 2;
1071 var_SetFloat( p_input, "rate", f_rate );
1075 var_SetInteger( p_intf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_EXTRASHORT );
1077 i_error = VLC_SUCCESS;
1079 else if ( !strcmp( psz_cmd, "faster" ) )
1081 var_TriggerCallback( p_input, "rate-faster" );
1082 i_error = VLC_SUCCESS;
1084 else if ( !strcmp( psz_cmd, "slower" ) )
1086 var_TriggerCallback( p_input, "rate-slower" );
1087 i_error = VLC_SUCCESS;
1089 else if ( !strcmp( psz_cmd, "normal" ) )
1091 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
1092 i_error = VLC_SUCCESS;
1094 else if ( !strcmp( psz_cmd, "frame" ) )
1096 var_TriggerCallback( p_input, "frame-next" );
1097 i_error = VLC_SUCCESS;
1099 else if( !strcmp( psz_cmd, "chapter" ) ||
1100 !strcmp( psz_cmd, "chapter_n" ) ||
1101 !strcmp( psz_cmd, "chapter_p" ) )
1103 if( !strcmp( psz_cmd, "chapter" ) )
1105 if ( *newval.psz_string )
1108 var_SetInteger( p_input, "chapter", atoi( newval.psz_string ) );
1113 int i_chap = var_GetInteger( p_input, "chapter" );
1114 int i_chapter_count = var_CountChoices( p_input, "chapter" );
1115 msg_rc( "Currently playing chapter %d/%d.", i_chap,
1119 else if( !strcmp( psz_cmd, "chapter_n" ) )
1120 var_TriggerCallback( p_input, "next-chapter" );
1121 else if( !strcmp( psz_cmd, "chapter_p" ) )
1122 var_TriggerCallback( p_input, "prev-chapter" );
1123 i_error = VLC_SUCCESS;
1125 else if( !strcmp( psz_cmd, "title" ) ||
1126 !strcmp( psz_cmd, "title_n" ) ||
1127 !strcmp( psz_cmd, "title_p" ) )
1129 if( !strcmp( psz_cmd, "title" ) )
1131 if ( *newval.psz_string )
1133 var_SetInteger( p_input, "title", atoi( newval.psz_string ) );
1137 int i_title = var_GetInteger( p_input, "title" );
1138 int i_title_count = var_CountChoices( p_input, "title" );
1139 msg_rc( "Currently playing title %d/%d.", i_title,
1143 else if( !strcmp( psz_cmd, "title_n" ) )
1144 var_TriggerCallback( p_input, "next-title" );
1145 else if( !strcmp( psz_cmd, "title_p" ) )
1146 var_TriggerCallback( p_input, "prev-title" );
1148 i_error = VLC_SUCCESS;
1150 else if( !strcmp( psz_cmd, "atrack" )
1151 || !strcmp( psz_cmd, "vtrack" )
1152 || !strcmp( psz_cmd, "strack" ) )
1154 const char *psz_variable;
1155 vlc_value_t val_name;
1157 if( !strcmp( psz_cmd, "atrack" ) )
1159 psz_variable = "audio-es";
1161 else if( !strcmp( psz_cmd, "vtrack" ) )
1163 psz_variable = "video-es";
1167 psz_variable = "spu-es";
1170 /* Get the descriptive name of the variable */
1171 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1173 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1175 if( newval.psz_string && *newval.psz_string )
1178 i_error = var_SetInteger( p_input, psz_variable,
1179 atoi( newval.psz_string ) );
1184 vlc_value_t val, text;
1187 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1189 i_value = val.i_int;
1191 if ( var_Change( p_input, psz_variable,
1192 VLC_VAR_GETLIST, &val, &text ) < 0 )
1195 msg_rc( "+----[ %s ]", val_name.psz_string );
1196 for ( i = 0; i < val.p_list->i_count; i++ )
1198 if ( i_value == val.p_list->p_values[i].i_int )
1199 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1200 text.p_list->p_values[i].psz_string );
1202 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1203 text.p_list->p_values[i].psz_string );
1205 var_FreeList( &val, &text );
1206 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1208 free( val_name.psz_string );
1212 vlc_object_release( p_input );
1216 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1219 char psz_buffer[MSTRTIME_MAX_SIZE];
1220 for( i = 0; i< p_item->i_children; i++ )
1222 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1224 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1225 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1228 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1230 if( p_item->pp_children[i]->i_children >= 0 )
1231 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1235 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1236 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1238 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1241 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1242 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1243 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1247 int state = var_GetInteger( p_input, "state" );
1248 vlc_object_release( p_input );
1250 if( state == PAUSE_S )
1252 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1253 return VLC_EGENERIC;
1257 /* Parse commands that require a playlist */
1258 if( !strcmp( psz_cmd, "prev" ) )
1260 playlist_Prev( p_playlist );
1262 else if( !strcmp( psz_cmd, "next" ) )
1264 playlist_Next( p_playlist );
1266 else if( !strcmp( psz_cmd, "play" ) )
1268 msg_Warn( p_playlist, "play" );
1269 playlist_Play( p_playlist );
1271 else if( !strcmp( psz_cmd, "repeat" ) )
1273 bool b_update = true;
1275 var_Get( p_playlist, "repeat", &val );
1277 if( strlen( newval.psz_string ) > 0 )
1279 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1280 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1288 val.b_bool = !val.b_bool;
1289 var_Set( p_playlist, "repeat", val );
1291 msg_rc( "Setting repeat to %d", val.b_bool );
1293 else if( !strcmp( psz_cmd, "loop" ) )
1295 bool b_update = true;
1297 var_Get( p_playlist, "loop", &val );
1299 if( strlen( newval.psz_string ) > 0 )
1301 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1302 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1310 val.b_bool = !val.b_bool;
1311 var_Set( p_playlist, "loop", val );
1313 msg_rc( "Setting loop to %d", val.b_bool );
1315 else if( !strcmp( psz_cmd, "random" ) )
1317 bool b_update = true;
1319 var_Get( p_playlist, "random", &val );
1321 if( strlen( newval.psz_string ) > 0 )
1323 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1324 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1332 val.b_bool = !val.b_bool;
1333 var_Set( p_playlist, "random", val );
1335 msg_rc( "Setting random to %d", val.b_bool );
1337 else if (!strcmp( psz_cmd, "goto" ) )
1339 int i_pos = atoi( newval.psz_string );
1340 /* The playlist stores 2 times the same item: onelevel & category */
1341 int i_size = p_playlist->items.i_size / 2;
1344 msg_rc( "%s", _("Error: `goto' needs an argument greater than zero.") );
1345 else if( i_pos <= i_size )
1347 playlist_item_t *p_item, *p_parent;
1348 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1349 while( p_parent->p_parent )
1350 p_parent = p_parent->p_parent;
1351 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1355 msg_rc( _("Playlist has only %d elements"), i_size );
1357 else if( !strcmp( psz_cmd, "stop" ) )
1359 playlist_Stop( p_playlist );
1361 else if( !strcmp( psz_cmd, "clear" ) )
1363 playlist_Stop( p_playlist );
1364 playlist_Clear( p_playlist, pl_Unlocked );
1366 else if( !strcmp( psz_cmd, "add" ) &&
1367 newval.psz_string && *newval.psz_string )
1369 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1373 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1374 int i_ret =playlist_AddInput( p_playlist, p_item,
1375 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1377 vlc_gc_decref( p_item );
1378 if( i_ret != VLC_SUCCESS )
1380 return VLC_EGENERIC;
1384 else if( !strcmp( psz_cmd, "enqueue" ) &&
1385 newval.psz_string && *newval.psz_string )
1387 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1391 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1392 if( playlist_AddInput( p_playlist, p_item,
1393 PLAYLIST_APPEND, PLAYLIST_END, true,
1394 pl_Unlocked ) != VLC_SUCCESS )
1396 return VLC_EGENERIC;
1400 else if( !strcmp( psz_cmd, "playlist" ) )
1402 msg_rc( "+----[ Playlist ]" );
1403 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1404 msg_rc( "+----[ End of playlist ]" );
1407 else if( !strcmp( psz_cmd, "sort" ))
1409 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1410 SORT_ARTIST, ORDER_NORMAL );
1412 else if( !strcmp( psz_cmd, "status" ) )
1414 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1417 /* Replay the current state of the system. */
1419 input_item_GetURI( input_GetItem( p_input ) );
1420 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1422 msg_rc( STATUS_CHANGE "( audio volume: %d )",
1423 config_GetInt( p_intf, "volume" ));
1426 switch( playlist_Status(p_playlist) )
1428 case PLAYLIST_STOPPED:
1429 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
1431 case PLAYLIST_RUNNING:
1432 msg_rc( STATUS_CHANGE "( play state: 3 )" );
1434 case PLAYLIST_PAUSED:
1435 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
1438 msg_rc( STATUS_CHANGE "( unknown state: -1 )" );
1442 vlc_object_release( p_input );
1451 msg_rc( "unknown command!" );
1457 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1458 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1460 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1461 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1463 libvlc_Quit( p_this->p_libvlc );
1467 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1468 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1470 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1472 return intf_Create( p_this->p_libvlc, newval.psz_string );
1475 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1476 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1478 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1479 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1480 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1481 input_thread_t *p_input = playlist_CurrentInput( p_playlist );
1482 int i_error = VLC_EGENERIC;
1489 int state = var_GetInteger( p_input, "state" );
1490 vlc_object_release( p_input );
1491 if( state == PAUSE_S )
1493 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1494 return VLC_EGENERIC;
1498 if ( *newval.psz_string )
1501 audio_volume_t i_volume = atoi( newval.psz_string );
1502 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1504 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1506 i_error = VLC_EBADVAR;
1510 if( i_volume == AOUT_VOLUME_MIN )
1511 aout_ToggleMute( p_playlist, NULL );
1512 if( !aout_VolumeSet( p_playlist, i_volume ) )
1513 i_error = VLC_SUCCESS;
1514 osd_Volume( p_this );
1515 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1521 audio_volume_t i_volume;
1522 if ( !aout_VolumeGet( p_playlist, &i_volume ) )
1524 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1525 i_error = VLC_SUCCESS;
1532 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1533 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1535 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1536 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1537 audio_volume_t i_volume;
1538 input_thread_t *p_input =
1539 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1540 int i_nb_steps = atoi(newval.psz_string);
1541 int i_error = VLC_SUCCESS;
1542 int i_volume_step = 0;
1547 int state = var_GetInteger( p_input, "state" );
1548 vlc_object_release( p_input );
1549 if( state == PAUSE_S )
1551 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1552 return VLC_EGENERIC;
1555 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1556 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1561 if ( !strcmp(psz_cmd, "volup") )
1563 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1564 i_error = VLC_EGENERIC;
1568 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1569 i_error = VLC_EGENERIC;
1571 osd_Volume( p_this );
1573 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1578 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1579 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1581 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1582 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1583 input_thread_t *p_input =
1584 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1585 vout_thread_t * p_vout;
1586 const char * psz_variable = NULL;
1587 int i_error = VLC_SUCCESS;
1592 p_vout = input_GetVout( p_input );
1593 vlc_object_release( p_input );
1597 if( !strcmp( psz_cmd, "vcrop" ) )
1599 psz_variable = "crop";
1601 else if( !strcmp( psz_cmd, "vratio" ) )
1603 psz_variable = "aspect-ratio";
1605 else if( !strcmp( psz_cmd, "vzoom" ) )
1607 psz_variable = "zoom";
1609 else if( !strcmp( psz_cmd, "snapshot" ) )
1611 psz_variable = "video-snapshot";
1614 /* This case can't happen */
1617 if( newval.psz_string && *newval.psz_string )
1620 if( !strcmp( psz_variable, "zoom" ) )
1623 val.f_float = atof( newval.psz_string );
1624 i_error = var_Set( p_vout, psz_variable, val );
1628 i_error = var_Set( p_vout, psz_variable, newval );
1631 else if( !strcmp( psz_cmd, "snapshot" ) )
1633 var_TriggerCallback( p_vout, psz_variable );
1638 vlc_value_t val_name;
1639 vlc_value_t val, text;
1642 char *psz_value = NULL;
1644 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1646 vlc_object_release( p_vout );
1647 return VLC_EGENERIC;
1649 if( !strcmp( psz_variable, "zoom" ) )
1651 f_value = val.f_float;
1655 psz_value = val.psz_string;
1658 if ( var_Change( p_vout, psz_variable,
1659 VLC_VAR_GETLIST, &val, &text ) < 0 )
1661 vlc_object_release( p_vout );
1663 return VLC_EGENERIC;
1666 /* Get the descriptive name of the variable */
1667 var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1669 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1671 msg_rc( "+----[ %s ]", val_name.psz_string );
1672 if( !strcmp( psz_variable, "zoom" ) )
1674 for ( i = 0; i < val.p_list->i_count; i++ )
1676 if ( f_value == val.p_list->p_values[i].f_float )
1677 msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1678 text.p_list->p_values[i].psz_string );
1680 msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1681 text.p_list->p_values[i].psz_string );
1686 for ( i = 0; i < val.p_list->i_count; i++ )
1688 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1689 msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1690 text.p_list->p_values[i].psz_string );
1692 msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1693 text.p_list->p_values[i].psz_string );
1697 var_FreeList( &val, &text );
1698 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1700 free( val_name.psz_string );
1702 vlc_object_release( p_vout );
1706 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1707 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1709 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1710 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1711 input_thread_t *p_input =
1712 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1713 aout_instance_t * p_aout;
1714 const char * psz_variable;
1715 vlc_value_t val_name;
1721 int state = var_GetInteger( p_input, "state" );
1722 if( state == PAUSE_S )
1724 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1725 return VLC_EGENERIC;
1728 p_aout = input_GetAout( p_input );
1729 vlc_object_release( p_input );
1730 if ( p_aout == NULL )
1733 if ( !strcmp( psz_cmd, "adev" ) )
1735 psz_variable = "audio-device";
1739 psz_variable = "audio-channels";
1742 /* Get the descriptive name of the variable */
1743 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1745 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1747 if ( !*newval.psz_string )
1749 /* Retrieve all registered ***. */
1750 vlc_value_t val, text;
1753 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1755 vlc_object_release( (vlc_object_t *)p_aout );
1756 return VLC_EGENERIC;
1758 i_value = val.i_int;
1760 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1761 VLC_VAR_GETLIST, &val, &text ) < 0 )
1763 vlc_object_release( (vlc_object_t *)p_aout );
1764 return VLC_EGENERIC;
1767 msg_rc( "+----[ %s ]", val_name.psz_string );
1768 for ( i = 0; i < val.p_list->i_count; i++ )
1770 if ( i_value == val.p_list->p_values[i].i_int )
1771 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1772 text.p_list->p_values[i].psz_string );
1774 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1775 text.p_list->p_values[i].psz_string );
1777 var_FreeList( &val, &text );
1778 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1780 free( val_name.psz_string );
1781 i_error = VLC_SUCCESS;
1786 val.i_int = atoi( newval.psz_string );
1788 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1790 vlc_object_release( (vlc_object_t *)p_aout );
1795 /* OSD menu commands */
1796 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1797 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1799 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1800 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1801 playlist_t *p_playlist = p_intf->p_sys->p_playlist;
1802 int i_error = VLC_SUCCESS;
1805 if ( !*newval.psz_string )
1807 msg_rc( "%s", _("Please provide one of the following parameters:") );
1808 msg_rc( "[on|off|up|down|left|right|select]" );
1809 return VLC_EGENERIC;
1812 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1816 var_Get( p_input, "state", &val );
1817 vlc_object_release( p_input );
1819 if( ( val.i_int == PAUSE_S ) &&
1820 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1822 msg_rc( "%s", _("Type 'menu select' or 'pause' to continue.") );
1823 return VLC_EGENERIC;
1827 val.psz_string = strdup( newval.psz_string );
1828 if( !val.psz_string )
1830 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1831 osd_MenuShow( p_this );
1832 else if( !strcmp( val.psz_string, "off" )
1833 || !strcmp( val.psz_string, "hide" ) )
1834 osd_MenuHide( p_this );
1835 else if( !strcmp( val.psz_string, "up" ) )
1836 osd_MenuUp( p_this );
1837 else if( !strcmp( val.psz_string, "down" ) )
1838 osd_MenuDown( p_this );
1839 else if( !strcmp( val.psz_string, "left" ) )
1840 osd_MenuPrev( p_this );
1841 else if( !strcmp( val.psz_string, "right" ) )
1842 osd_MenuNext( p_this );
1843 else if( !strcmp( val.psz_string, "select" ) )
1844 osd_MenuActivate( p_this );
1847 msg_rc( "%s", _("Please provide one of the following parameters:") );
1848 msg_rc( "[on|off|up|down|left|right|select]" );
1849 i_error = VLC_EGENERIC;
1852 free( val.psz_string );
1856 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1857 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1859 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1860 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1861 input_thread_t *p_input =
1862 playlist_CurrentInput( p_intf->p_sys->p_playlist );
1867 updateStatistics( p_intf, input_GetItem(p_input) );
1868 vlc_object_release( p_input );
1872 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1874 if( !p_item ) return VLC_EGENERIC;
1876 vlc_mutex_lock( &p_item->lock );
1877 vlc_mutex_lock( &p_item->p_stats->lock );
1878 msg_rc( "+----[ begin of statistical info ]" );
1881 msg_rc("%s", _("+-[Incoming]"));
1882 msg_rc(_("| input bytes read : %8.0f kB"),
1883 (float)(p_item->p_stats->i_read_bytes)/1000 );
1884 msg_rc(_("| input bitrate : %6.0f kb/s"),
1885 (float)(p_item->p_stats->f_input_bitrate)*8000 );
1886 msg_rc(_("| demux bytes read : %8.0f kB"),
1887 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
1888 msg_rc(_("| demux bitrate : %6.0f kb/s"),
1889 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
1890 msg_rc(_("| demux corrupted : %5i"),
1891 p_item->p_stats->i_demux_corrupted );
1892 msg_rc(_("| discontinuities : %5i"),
1893 p_item->p_stats->i_demux_discontinuity );
1896 msg_rc("%s", _("+-[Video Decoding]"));
1897 msg_rc(_("| video decoded : %5i"),
1898 p_item->p_stats->i_decoded_video );
1899 msg_rc(_("| frames displayed : %5i"),
1900 p_item->p_stats->i_displayed_pictures );
1901 msg_rc(_("| frames lost : %5i"),
1902 p_item->p_stats->i_lost_pictures );
1905 msg_rc("%s", _("+-[Audio Decoding]"));
1906 msg_rc(_("| audio decoded : %5i"),
1907 p_item->p_stats->i_decoded_audio );
1908 msg_rc(_("| buffers played : %5i"),
1909 p_item->p_stats->i_played_abuffers );
1910 msg_rc(_("| buffers lost : %5i"),
1911 p_item->p_stats->i_lost_abuffers );
1914 msg_rc("%s", _("+-[Streaming]"));
1915 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
1916 msg_rc(_("| bytes sent : %8.0f kB"),
1917 (float)(p_item->p_stats->i_sent_bytes)/1000 );
1918 msg_rc(_("| sending bitrate : %6.0f kb/s"),
1919 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
1921 msg_rc( "+----[ end of statistical info ]" );
1922 vlc_mutex_unlock( &p_item->p_stats->lock );
1923 vlc_mutex_unlock( &p_item->lock );
1929 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1931 INPUT_RECORD input_record;
1934 /* On Win32, select() only works on socket descriptors */
1935 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1936 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1938 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1939 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1942 if( input_record.EventType != KEY_EVENT ||
1943 !input_record.Event.KeyEvent.bKeyDown ||
1944 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1945 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1946 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1947 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1949 /* nothing interesting */
1953 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1955 /* Echo out the command */
1956 putc( p_buffer[ *pi_size ], stdout );
1958 /* Handle special keys */
1959 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1961 putc( '\n', stdout );
1964 switch( p_buffer[ *pi_size ] )
1970 putc( ' ', stdout );
1971 putc( '\b', stdout );
1982 if( *pi_size == MAX_LINE_LENGTH ||
1983 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1985 p_buffer[ *pi_size ] = 0;
1994 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1999 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2000 return ReadWin32( p_intf, p_buffer, pi_size );
2001 else if( p_intf->p_sys->i_socket == -1 )
2003 msleep( INTF_IDLE_SLEEP );
2008 while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2009 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2010 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2011 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2013 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2019 /* Connection closed */
2022 if( p_intf->p_sys->i_socket != -1 )
2024 net_Close( p_intf->p_sys->i_socket );
2025 p_intf->p_sys->i_socket = -1;
2029 /* Standard input closed: exit */
2031 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2034 p_buffer[ *pi_size ] = 0;
2038 if( *pi_size == MAX_LINE_LENGTH ||
2039 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2041 p_buffer[ *pi_size ] = 0;
2048 /*****************************************************************************
2049 * parse_MRL: build a input item from a full mrl
2050 *****************************************************************************
2051 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2052 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2053 * space is a new option. Should be good enough for our purpose.
2054 *****************************************************************************/
2055 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2057 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2058 #define SKIPTRAILINGSPACE( p, d ) \
2059 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2061 input_item_t *p_item = NULL;
2062 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2063 char **ppsz_options = NULL;
2064 int i, i_options = 0;
2066 if( !psz_mrl ) return 0;
2068 psz_mrl = psz_orig = strdup( psz_mrl );
2071 SKIPSPACE( psz_mrl );
2074 for( ; *psz_mrl; psz_mrl++ )
2076 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2078 /* We have a complete item */
2081 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2082 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2084 /* We have a complete item */
2089 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2090 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2092 /* Remove '"' and '\'' if necessary */
2093 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2094 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2095 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2096 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2098 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2099 else if( *psz_item )
2102 ppsz_options = xrealloc( ppsz_options, i_options * sizeof(char *) );
2103 ppsz_options[i_options - 1] = &psz_item[1];
2106 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2109 /* Now create a playlist item */
2112 p_item = input_item_New( p_intf, psz_item_mrl, NULL );
2113 for( i = 0; i < i_options; i++ )
2115 input_item_AddOption( p_item, ppsz_options[i], VLC_INPUT_OPTION_TRUSTED );
2119 if( i_options ) free( ppsz_options );