1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2007 the VideoLAN team
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8 * Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
35 #include <errno.h> /* ENOMEM */
39 #include <vlc_interface.h>
43 #include <vlc_playlist.h>
49 #ifdef HAVE_SYS_TIME_H
50 # include <sys/time.h>
52 #include <sys/types.h>
54 #include <vlc_network.h>
57 #include <vlc_charset.h>
59 #if defined(AF_UNIX) && !defined(AF_LOCAL)
60 # define AF_LOCAL AF_UNIX
63 #if defined(AF_LOCAL) && ! defined(WIN32)
67 #define MAX_LINE_LENGTH 256
68 #define STATUS_CHANGE "status change: "
70 /* input_state_e from <vlc_input.h> */
71 static const char *ppsz_input_state[] = {
84 /*****************************************************************************
86 *****************************************************************************/
87 static int Activate ( vlc_object_t * );
88 static void Deactivate ( vlc_object_t * );
89 static void Run ( intf_thread_t * );
91 static void Help ( intf_thread_t *, bool );
92 static void RegisterCallbacks( intf_thread_t * );
94 static bool ReadCommand( intf_thread_t *, char *, int * );
96 static input_item_t *parse_MRL( intf_thread_t *, char * );
98 static int Input ( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t, void * );
100 static int Playlist ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int Quit ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int Intf ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
106 static int Volume ( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
108 static int VolumeMove ( vlc_object_t *, char const *,
109 vlc_value_t, vlc_value_t, void * );
110 static int VideoConfig ( vlc_object_t *, char const *,
111 vlc_value_t, vlc_value_t, void * );
112 static int AudioConfig ( vlc_object_t *, char const *,
113 vlc_value_t, vlc_value_t, void * );
114 static int Menu ( vlc_object_t *, char const *,
115 vlc_value_t, vlc_value_t, void * );
116 static int Statistics ( vlc_object_t *, char const *,
117 vlc_value_t, vlc_value_t, void * );
119 static int updateStatistics( intf_thread_t *, input_item_t *);
121 /* Status Callbacks */
122 static int TimeOffsetChanged( vlc_object_t *, char const *,
123 vlc_value_t, vlc_value_t , void * );
124 static int VolumeChanged ( vlc_object_t *, char const *,
125 vlc_value_t, vlc_value_t, void * );
126 static int StateChanged ( vlc_object_t *, char const *,
127 vlc_value_t, vlc_value_t, void * );
128 static int RateChanged ( vlc_object_t *, char const *,
129 vlc_value_t, vlc_value_t, void * );
133 int *pi_socket_listen;
138 vlc_mutex_t status_lock;
139 playlist_status_t i_last_state;
147 #define msg_rc( ... ) __msg_rc( p_intf, __VA_ARGS__ )
149 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
152 va_start( args, psz_fmt );
154 if( p_intf->p_sys->i_socket == -1 )
156 utf8_vfprintf( stdout, psz_fmt, args );
161 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
162 net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
167 /*****************************************************************************
169 *****************************************************************************/
170 #define POS_TEXT N_("Show stream position")
171 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
172 "stream from time to time." )
174 #define TTY_TEXT N_("Fake TTY")
175 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
177 #define UNIX_TEXT N_("UNIX socket command input")
178 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
181 #define HOST_TEXT N_("TCP command input")
182 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
183 "You can set the address and port the interface will bind to." )
186 #define QUIET_TEXT N_("Do not open a DOS command box interface")
187 #define QUIET_LONGTEXT N_( \
188 "By default the rc interface plugin will start a DOS command box. " \
189 "Enabling the quiet mode will not bring this command box but can also " \
190 "be pretty annoying when you want to stop VLC and no video window is " \
195 set_shortname( N_("RC"));
196 set_category( CAT_INTERFACE );
197 set_subcategory( SUBCAT_INTERFACE_MAIN );
198 set_description( N_("Remote control interface") );
199 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, true );
202 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, false );
204 #if defined (HAVE_ISATTY)
205 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, true );
207 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, true );
209 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, true );
211 set_capability( "interface", 20 );
213 set_callbacks( Activate, Deactivate );
216 /*****************************************************************************
217 * Activate: initialize and create stuff
218 *****************************************************************************/
219 static int Activate( vlc_object_t *p_this )
221 intf_thread_t *p_intf = (intf_thread_t*)p_this;
222 char *psz_host, *psz_unix_path;
223 int *pi_socket = NULL;
226 #if defined(HAVE_ISATTY)
227 /* Check that stdin is a TTY */
228 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
230 msg_Warn( p_intf, "fd 0 is not a TTY" );
235 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
241 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
242 free( psz_unix_path );
245 struct sockaddr_un addr;
247 memset( &addr, 0, sizeof(struct sockaddr_un) );
249 msg_Dbg( p_intf, "trying UNIX socket" );
251 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
253 msg_Warn( p_intf, "can't open socket: %m" );
254 free( psz_unix_path );
258 addr.sun_family = AF_LOCAL;
259 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
260 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
262 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
263 && (errno == EADDRINUSE)
264 && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
265 && (errno == ECONNREFUSED))
267 msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
268 unlink (psz_unix_path);
270 if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
272 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
274 free (psz_unix_path);
275 net_Close (i_socket);
280 if( listen( i_socket, 1 ) )
282 msg_Warn( p_intf, "can't listen on socket: %m");
283 free( psz_unix_path );
284 net_Close( i_socket );
288 /* FIXME: we need a core function to merge listening sockets sets */
289 pi_socket = calloc( 2, sizeof( int ) );
290 if( pi_socket == NULL )
292 free( psz_unix_path );
293 net_Close( i_socket );
296 pi_socket[0] = i_socket;
298 #endif /* AF_LOCAL */
302 if( ( pi_socket == NULL ) &&
303 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
307 vlc_UrlParse( &url, psz_host, 0 );
309 msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
311 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
312 if( pi_socket == NULL )
314 msg_Warn( p_intf, "can't listen to %s port %i",
315 url.psz_host, url.i_port );
316 vlc_UrlClean( &url );
321 vlc_UrlClean( &url );
325 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
329 p_intf->p_sys->pi_socket_listen = pi_socket;
330 p_intf->p_sys->i_socket = -1;
331 p_intf->p_sys->psz_unix_path = psz_unix_path;
332 vlc_mutex_init( &p_intf->p_sys->status_lock );
333 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
335 /* Non-buffered stdout */
336 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
338 p_intf->pf_run = Run;
341 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
342 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
347 msg_rc( _("Remote control interface initialized. Type `help' for help.") );
351 /*****************************************************************************
352 * Deactivate: uninitialize and cleanup
353 *****************************************************************************/
354 static void Deactivate( vlc_object_t *p_this )
356 intf_thread_t *p_intf = (intf_thread_t*)p_this;
358 net_ListenClose( p_intf->p_sys->pi_socket_listen );
359 if( p_intf->p_sys->i_socket != -1 )
360 net_Close( p_intf->p_sys->i_socket );
361 if( p_intf->p_sys->psz_unix_path != NULL )
363 #if defined(AF_LOCAL) && !defined(WIN32)
364 unlink( p_intf->p_sys->psz_unix_path );
366 free( p_intf->p_sys->psz_unix_path );
368 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
369 free( p_intf->p_sys );
372 /*****************************************************************************
373 * RegisterCallbacks: Register callbacks to dynamic variables
374 *****************************************************************************/
375 static void RegisterCallbacks( intf_thread_t *p_intf )
377 /* Register commands that will be cleaned up upon object destruction */
378 #define ADD( name, type, target ) \
379 var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
380 var_AddCallback( p_intf, name, target, NULL );
381 ADD( "quit", VOID, Quit )
382 ADD( "intf", STRING, Intf )
384 ADD( "add", STRING, Playlist )
385 ADD( "repeat", STRING, Playlist )
386 ADD( "loop", STRING, Playlist )
387 ADD( "random", STRING, Playlist )
388 ADD( "enqueue", STRING, Playlist )
389 ADD( "playlist", VOID, Playlist )
390 ADD( "sort", VOID, Playlist )
391 ADD( "play", VOID, Playlist )
392 ADD( "stop", VOID, Playlist )
393 ADD( "clear", VOID, Playlist )
394 ADD( "prev", VOID, Playlist )
395 ADD( "next", VOID, Playlist )
396 ADD( "goto", INTEGER, Playlist )
397 ADD( "status", INTEGER, Playlist )
399 /* OSD menu commands */
400 ADD( "menu", STRING, Menu )
403 ADD( "pause", VOID, Input )
404 ADD( "seek", INTEGER, Input )
405 ADD( "title", STRING, Input )
406 ADD( "title_n", VOID, Input )
407 ADD( "title_p", VOID, Input )
408 ADD( "chapter", STRING, Input )
409 ADD( "chapter_n", VOID, Input )
410 ADD( "chapter_p", VOID, Input )
412 ADD( "fastforward", VOID, Input )
413 ADD( "rewind", VOID, Input )
414 ADD( "faster", VOID, Input )
415 ADD( "slower", VOID, Input )
416 ADD( "normal", VOID, Input )
418 ADD( "atrack", STRING, Input )
419 ADD( "vtrack", STRING, Input )
420 ADD( "strack", STRING, Input )
423 ADD( "vratio", STRING, VideoConfig )
424 ADD( "vcrop", STRING, VideoConfig )
425 ADD( "vzoom", STRING, VideoConfig )
426 ADD( "snapshot", VOID, VideoConfig )
429 ADD( "volume", STRING, Volume )
430 ADD( "volup", STRING, VolumeMove )
431 ADD( "voldown", STRING, VolumeMove )
432 ADD( "adev", STRING, AudioConfig )
433 ADD( "achan", STRING, AudioConfig )
435 /* misc menu commands */
436 ADD( "stats", BOOL, Statistics )
441 /*****************************************************************************
443 *****************************************************************************
444 * This part of the interface is in a separate thread so that we can call
445 * exec() from within it without annoying the rest of the program.
446 *****************************************************************************/
447 static void Run( intf_thread_t *p_intf )
449 input_thread_t * p_input;
450 playlist_t * p_playlist;
452 char p_buffer[ MAX_LINE_LENGTH + 1 ];
453 bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
454 bool b_longhelp = false;
459 int canc = vlc_savecancel();
465 /* Register commands that will be cleaned up upon object destruction */
466 RegisterCallbacks( p_intf );
468 /* status callbacks */
469 /* Listen to audio volume updates */
470 var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
473 /* Get the file descriptor of the console input */
474 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
475 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
477 msg_Err( p_intf, "couldn't find user input handle" );
478 vlc_object_kill( p_intf );
482 while( !intf_ShouldDie( p_intf ) )
484 char *psz_cmd, *psz_arg;
487 if( p_intf->p_sys->pi_socket_listen != NULL &&
488 p_intf->p_sys->i_socket == -1 )
490 p_intf->p_sys->i_socket =
491 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
493 if( p_intf->p_sys->i_socket == -1 ) continue;
496 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
498 /* Manage the input part */
499 if( p_input == NULL )
503 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
508 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
512 p_playlist = pl_Yield( p_input );
515 /* New input has been registered */
518 if( !p_input->b_dead || vlc_object_alive (p_input) )
521 input_item_GetURI( input_GetItem( p_input ) );
522 msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
524 msg_rc( STATUS_CHANGE "( audio volume: %d )",
525 config_GetInt( p_intf, "volume" ));
527 var_AddCallback( p_input, "state", StateChanged, p_intf );
528 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
529 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
530 var_AddCallback( p_input, "rate", RateChanged, p_intf );
531 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
535 else if( p_input->b_dead )
537 var_DelCallback( p_input, "state", StateChanged, p_intf );
538 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
539 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
540 var_DelCallback( p_input, "rate", RateChanged, p_intf );
541 var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
543 vlc_object_release( p_input );
548 vlc_object_lock( p_playlist );
549 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
550 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
551 vlc_object_unlock( p_playlist );
555 if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
556 (p_playlist != NULL) )
558 vlc_object_lock( p_playlist );
559 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
560 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
562 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
563 msg_rc( STATUS_CHANGE "( stop state: 5 )" );
566 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
567 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
569 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
570 msg_rc( STATUS_CHANGE "( play state: 3 )" );
573 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
574 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
576 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
577 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
579 vlc_object_unlock( p_playlist );
582 if( p_input && b_showpos )
584 i_newpos = 100 * var_GetFloat( p_input, "position" );
585 if( i_oldpos != i_newpos )
588 msg_rc( "pos: %d%%", i_newpos );
592 /* Is there something to do? */
593 if( !b_complete ) continue;
595 /* Skip heading spaces */
597 while( *psz_cmd == ' ' )
602 /* Split psz_cmd at the first space and make sure that
603 * psz_arg is valid */
604 psz_arg = strchr( psz_cmd, ' ' );
608 while( *psz_arg == ' ' )
618 /* module specfic commands: @<module name> <command> <args...> */
619 if( *psz_cmd == '@' && *psz_arg )
621 /* Parse miscellaneous commands */
622 char *psz_alias = psz_cmd + 1;
623 char *psz_mycmd = strdup( psz_arg );
624 char *psz_myarg = strchr( psz_mycmd, ' ' );
629 msg_rc( "Not enough parameters." );
636 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
647 /* If the user typed a registered local command, try it */
648 else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
653 val.psz_string = psz_arg;
654 i_ret = var_Set( p_intf, psz_cmd, val );
655 msg_rc( "%s: returned %i (%s)",
656 psz_cmd, i_ret, vlc_error( i_ret ) );
658 /* Or maybe it's a global command */
659 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
664 val.psz_string = psz_arg;
665 /* FIXME: it's a global command, but we should pass the
666 * local object as an argument, not p_intf->p_libvlc. */
667 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
670 msg_rc( "%s: returned %i (%s)",
671 psz_cmd, i_ret, vlc_error( i_ret ) );
674 else if( !strcmp( psz_cmd, "logout" ) )
676 /* Close connection */
677 if( p_intf->p_sys->i_socket != -1 )
679 net_Close( p_intf->p_sys->i_socket );
681 p_intf->p_sys->i_socket = -1;
683 else if( !strcmp( psz_cmd, "info" ) )
688 vlc_mutex_lock( &input_GetItem(p_input)->lock );
689 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
691 info_category_t *p_category = input_GetItem(p_input)
694 msg_rc( "+----[ %s ]", p_category->psz_name );
696 for ( j = 0; j < p_category->i_infos; j++ )
698 info_t *p_info = p_category->pp_infos[j];
699 msg_rc( "| %s: %s", p_info->psz_name,
704 msg_rc( "+----[ end of stream info ]" );
705 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
709 msg_rc( "no input" );
712 else if( !strcmp( psz_cmd, "is_playing" ) )
723 else if( !strcmp( psz_cmd, "get_time" ) )
732 var_Get( p_input, "time", &time );
733 msg_rc( "%i", time.i_time / 1000000);
736 else if( !strcmp( psz_cmd, "get_length" ) )
745 var_Get( p_input, "length", &time );
746 msg_rc( "%i", time.i_time / 1000000);
749 else if( !strcmp( psz_cmd, "get_title" ) )
757 msg_rc( "%s", input_GetItem(p_input)->psz_name );
760 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
761 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
763 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
765 else b_longhelp = false;
767 Help( p_intf, b_longhelp );
769 else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
771 var_SetInteger( p_intf->p_libvlc, "key-pressed",
772 config_GetInt( p_intf, psz_arg ) );
774 else switch( psz_cmd[0] )
780 vout_thread_t *p_vout;
781 p_vout = vlc_object_find( p_input,
782 VLC_OBJECT_VOUT, FIND_CHILD );
787 bool b_update = false;
788 var_Get( p_vout, "fullscreen", &val );
789 val.b_bool = !val.b_bool;
790 if( !strncmp( psz_arg, "on", 2 )
791 && ( val.b_bool == true ) )
796 else if( !strncmp( psz_arg, "off", 3 )
797 && ( val.b_bool == false ) )
802 else if( strncmp( psz_arg, "off", 3 )
803 && strncmp( psz_arg, "on", 2 ) )
805 if( b_update ) var_Set( p_vout, "fullscreen", val );
806 vlc_object_release( p_vout );
817 /* Ignore empty lines */
821 msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
825 /* Command processed */
826 i_size = 0; p_buffer[0] = 0;
829 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
830 msg_rc( STATUS_CHANGE "( quit )" );
834 var_DelCallback( p_input, "state", StateChanged, p_intf );
835 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
836 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
837 var_DelCallback( p_input, "rate", RateChanged, p_intf );
838 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
839 vlc_object_release( p_input );
845 vlc_object_release( p_playlist );
849 var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
850 vlc_restorecancel( canc );
853 static void Help( intf_thread_t *p_intf, bool b_longhelp)
855 msg_rc(_("+----[ Remote control commands ]"));
857 msg_rc(_("| add XYZ . . . . . . . . . . . . add XYZ to playlist"));
858 msg_rc(_("| enqueue XYZ . . . . . . . . . queue XYZ to playlist"));
859 msg_rc(_("| playlist . . . . . show items currently in playlist"));
860 msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
861 msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
862 msg_rc(_("| next . . . . . . . . . . . . . . next playlist item"));
863 msg_rc(_("| prev . . . . . . . . . . . . previous playlist item"));
864 msg_rc(_("| goto . . . . . . . . . . . . . . goto item at index"));
865 msg_rc(_("| repeat [on|off] . . . . toggle playlist item repeat"));
866 msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
867 msg_rc(_("| random [on|off] . . . . . . . toggle random jumping"));
868 msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
869 msg_rc(_("| status . . . . . . . . . . . current playlist status"));
870 msg_rc(_("| title [X] . . . . . . set/get title in current item"));
871 msg_rc(_("| title_n . . . . . . . . next title in current item"));
872 msg_rc(_("| title_p . . . . . . previous title in current item"));
873 msg_rc(_("| chapter [X] . . . . set/get chapter in current item"));
874 msg_rc(_("| chapter_n . . . . . . next chapter in current item"));
875 msg_rc(_("| chapter_p . . . . previous chapter in current item"));
877 msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
878 msg_rc(_("| pause . . . . . . . . . . . . . . . . toggle pause"));
879 msg_rc(_("| fastforward . . . . . . . . . set to maximum rate"));
880 msg_rc(_("| rewind . . . . . . . . . . . . set to minimum rate"));
881 msg_rc(_("| faster . . . . . . . . . . faster playing of stream"));
882 msg_rc(_("| slower . . . . . . . . . . slower playing of stream"));
883 msg_rc(_("| normal . . . . . . . . . . normal playing of stream"));
884 msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
885 msg_rc(_("| info . . . . . information about the current stream"));
886 msg_rc(_("| stats . . . . . . . . show statistical information"));
887 msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
888 msg_rc(_("| is_playing . . . . 1 if a stream plays, 0 otherwise"));
889 msg_rc(_("| get_title . . . . . the title of the current stream"));
890 msg_rc(_("| get_length . . . . the length of the current stream"));
892 msg_rc(_("| volume [X] . . . . . . . . . . set/get audio volume"));
893 msg_rc(_("| volup [X] . . . . . . . raise audio volume X steps"));
894 msg_rc(_("| voldown [X] . . . . . . lower audio volume X steps"));
895 msg_rc(_("| adev [X] . . . . . . . . . . . set/get audio device"));
896 msg_rc(_("| achan [X]. . . . . . . . . . set/get audio channels"));
897 msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
898 msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
899 msg_rc(_("| vratio [X] . . . . . . . set/get video aspect ratio"));
900 msg_rc(_("| vcrop [X] . . . . . . . . . . . set/get video crop"));
901 msg_rc(_("| vzoom [X] . . . . . . . . . . . set/get video zoom"));
902 msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
903 msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
904 msg_rc(_("| key [hotkey name] . . . . . . simulate hotkey press"));
905 msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
910 msg_rc(_("| @name marq-marquee STRING . . overlay STRING in video"));
911 msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
912 msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
913 msg_rc(_("| @name marq-position #. . . .relative position control"));
914 msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
915 msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
916 msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
917 msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
919 msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
920 msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
921 msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
922 msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
923 msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
925 msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
926 msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
927 msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
928 msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
929 msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
930 msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
931 msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
932 msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
933 msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
934 msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
935 msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
936 msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
937 msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
938 msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
941 msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
942 msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
943 msg_rc(_("| logout . . . . . . . exit (if in socket connection)"));
944 msg_rc(_("| quit . . . . . . . . . . . . . . . . . . . quit vlc"));
946 msg_rc(_("+----[ end of help ]"));
949 /********************************************************************
950 * Status callback routines
951 ********************************************************************/
952 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
953 vlc_value_t oldval, vlc_value_t newval, void *p_data )
955 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
956 VLC_UNUSED(oldval); VLC_UNUSED(newval);
957 intf_thread_t *p_intf = (intf_thread_t*)p_data;
958 input_thread_t *p_input = NULL;
960 vlc_mutex_lock( &p_intf->p_sys->status_lock );
961 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
964 msg_rc( STATUS_CHANGE "( time-offset: %d )",
965 var_GetInteger( p_input, "time-offset" ) );
966 vlc_object_release( p_input );
968 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
972 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
973 vlc_value_t oldval, vlc_value_t newval, void *p_data )
975 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(newval);
976 intf_thread_t *p_intf = (intf_thread_t*)p_data;
978 vlc_mutex_lock( &p_intf->p_sys->status_lock );
979 msg_rc( STATUS_CHANGE "( audio volume: %d )",
980 config_GetInt( p_this, "volume") );
981 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
985 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
986 vlc_value_t oldval, vlc_value_t newval, void *p_data )
988 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
989 intf_thread_t *p_intf = (intf_thread_t*)p_data;
990 playlist_t *p_playlist = NULL;
991 input_thread_t *p_input = NULL;
993 vlc_mutex_lock( &p_intf->p_sys->status_lock );
994 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
997 p_playlist = pl_Yield( p_input );
999 switch( p_playlist->status.i_status )
1001 case PLAYLIST_STOPPED:
1002 strcpy( cmd, "stop" );
1004 case PLAYLIST_RUNNING:
1005 strcpy( cmd, "play" );
1007 case PLAYLIST_PAUSED:
1008 strcpy( cmd, "pause" );
1012 } /* var_GetInteger( p_input, "state" ) */
1013 msg_rc( STATUS_CHANGE "( %s state: %d ): %s",
1015 ppsz_input_state[ newval.i_int ] );
1016 vlc_object_release( p_playlist );
1017 vlc_object_release( p_input );
1019 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1023 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1024 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1026 VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd);
1027 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1028 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1029 input_thread_t *p_input = NULL;
1031 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1032 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1035 msg_rc( STATUS_CHANGE "( new rate: %d )",
1036 var_GetInteger( p_input, "rate" ) );
1037 vlc_object_release( p_input );
1039 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1043 /********************************************************************
1045 ********************************************************************/
1046 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1047 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1049 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1050 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1051 input_thread_t *p_input;
1054 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1055 if( !p_input ) return VLC_ENOOBJ;
1057 var_Get( p_input, "state", &val );
1058 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1059 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1061 msg_rc( _("Press menu select or pause to continue.") );
1062 vlc_object_release( p_input );
1063 return VLC_EGENERIC;
1066 /* Parse commands that only require an input */
1067 if( !strcmp( psz_cmd, "pause" ) )
1069 val.i_int = config_GetInt( p_intf, "key-play-pause" );
1070 var_Set( p_intf->p_libvlc, "key-pressed", val );
1071 vlc_object_release( p_input );
1074 else if( !strcmp( psz_cmd, "seek" ) )
1076 if( strlen( newval.psz_string ) > 0 &&
1077 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1079 val.f_float = (float)atof( newval.psz_string ) / 100.0;
1080 var_Set( p_input, "position", val );
1084 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1085 var_Set( p_input, "time", val );
1087 vlc_object_release( p_input );
1090 else if ( !strcmp( psz_cmd, "fastforward" ) )
1092 val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1093 var_Set( p_intf->p_libvlc, "key-pressed", val );
1094 vlc_object_release( p_input );
1097 else if ( !strcmp( psz_cmd, "rewind" ) )
1099 val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1100 var_Set( p_intf->p_libvlc, "key-pressed", val );
1101 vlc_object_release( p_input );
1104 else if ( !strcmp( psz_cmd, "faster" ) )
1106 var_Set( p_input, "rate-faster", val );
1107 vlc_object_release( p_input );
1110 else if ( !strcmp( psz_cmd, "slower" ) )
1112 var_Set( p_input, "rate-slower", val );
1113 vlc_object_release( p_input );
1116 else if ( !strcmp( psz_cmd, "normal" ) )
1118 val.i_int = INPUT_RATE_DEFAULT;
1119 var_Set( p_input, "rate", val );
1120 vlc_object_release( p_input );
1123 else if( !strcmp( psz_cmd, "chapter" ) ||
1124 !strcmp( psz_cmd, "chapter_n" ) ||
1125 !strcmp( psz_cmd, "chapter_p" ) )
1127 if( !strcmp( psz_cmd, "chapter" ) )
1129 if ( *newval.psz_string )
1132 val.i_int = atoi( newval.psz_string );
1133 var_Set( p_input, "chapter", val );
1137 vlc_value_t val_list;
1140 var_Get( p_input, "chapter", &val );
1141 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1143 msg_rc( "Currently playing chapter %d/%d.",
1144 val.i_int, val_list.p_list->i_count );
1145 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1149 else if( !strcmp( psz_cmd, "chapter_n" ) )
1152 var_Set( p_input, "next-chapter", val );
1154 else if( !strcmp( psz_cmd, "chapter_p" ) )
1157 var_Set( p_input, "prev-chapter", val );
1159 vlc_object_release( p_input );
1162 else if( !strcmp( psz_cmd, "title" ) ||
1163 !strcmp( psz_cmd, "title_n" ) ||
1164 !strcmp( psz_cmd, "title_p" ) )
1166 if( !strcmp( psz_cmd, "title" ) )
1168 if ( *newval.psz_string )
1171 val.i_int = atoi( newval.psz_string );
1172 var_Set( p_input, "title", val );
1176 vlc_value_t val_list;
1179 var_Get( p_input, "title", &val );
1180 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1182 msg_rc( "Currently playing title %d/%d.",
1183 val.i_int, val_list.p_list->i_count );
1184 var_Change( p_this, "title", VLC_VAR_FREELIST,
1188 else if( !strcmp( psz_cmd, "title_n" ) )
1191 var_Set( p_input, "next-title", val );
1193 else if( !strcmp( psz_cmd, "title_p" ) )
1196 var_Set( p_input, "prev-title", val );
1199 vlc_object_release( p_input );
1202 else if( !strcmp( psz_cmd, "atrack" )
1203 || !strcmp( psz_cmd, "vtrack" )
1204 || !strcmp( psz_cmd, "strack" ) )
1206 const char *psz_variable;
1207 vlc_value_t val_name;
1210 if( !strcmp( psz_cmd, "atrack" ) )
1212 psz_variable = "audio-es";
1214 else if( !strcmp( psz_cmd, "vtrack" ) )
1216 psz_variable = "video-es";
1220 psz_variable = "spu-es";
1223 /* Get the descriptive name of the variable */
1224 var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1226 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1228 if( newval.psz_string && *newval.psz_string )
1232 val.i_int = atoi( newval.psz_string );
1234 i_error = var_Set( p_input, psz_variable, val );
1239 vlc_value_t val, text;
1242 if ( var_Get( p_input, psz_variable, &val ) < 0 )
1244 vlc_object_release( p_input );
1245 return VLC_EGENERIC;
1247 i_value = val.i_int;
1249 if ( var_Change( p_input, psz_variable,
1250 VLC_VAR_GETLIST, &val, &text ) < 0 )
1252 vlc_object_release( p_input );
1253 return VLC_EGENERIC;
1256 msg_rc( "+----[ %s ]", val_name.psz_string );
1257 for ( i = 0; i < val.p_list->i_count; i++ )
1259 if ( i_value == val.p_list->p_values[i].i_int )
1260 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1261 text.p_list->p_values[i].psz_string );
1263 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1264 text.p_list->p_values[i].psz_string );
1266 var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1268 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1270 free( val_name.psz_string );
1272 i_error = VLC_SUCCESS;
1274 vlc_object_release( p_input );
1278 /* Never reached. */
1279 vlc_object_release( p_input );
1280 return VLC_EGENERIC;
1283 static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
1286 char psz_buffer[MSTRTIME_MAX_SIZE];
1287 for( i = 0; i< p_item->i_children; i++ )
1289 if( p_item->pp_children[i]->p_input->i_duration != -1 )
1291 secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
1292 msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
1295 msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
1297 if( p_item->pp_children[i]->i_children >= 0 )
1298 print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
1302 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1303 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1305 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1308 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1309 playlist_t *p_playlist = pl_Yield( p_this );
1312 if( p_playlist->p_input )
1314 var_Get( p_playlist->p_input, "state", &val );
1315 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1317 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1318 vlc_object_release( p_playlist );
1320 return VLC_EGENERIC;
1325 /* Parse commands that require a playlist */
1326 if( !strcmp( psz_cmd, "prev" ) )
1328 playlist_Prev( p_playlist );
1330 else if( !strcmp( psz_cmd, "next" ) )
1332 playlist_Next( p_playlist );
1334 else if( !strcmp( psz_cmd, "play" ) )
1336 msg_Warn( p_playlist, "play" );
1337 playlist_Play( p_playlist );
1339 else if( !strcmp( psz_cmd, "repeat" ) )
1341 bool b_update = true;
1343 var_Get( p_playlist, "repeat", &val );
1345 if( strlen( newval.psz_string ) > 0 )
1347 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1348 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1356 val.b_bool = !val.b_bool;
1357 var_Set( p_playlist, "repeat", val );
1359 msg_rc( "Setting repeat to %d", val.b_bool );
1361 else if( !strcmp( psz_cmd, "loop" ) )
1363 bool b_update = true;
1365 var_Get( p_playlist, "loop", &val );
1367 if( strlen( newval.psz_string ) > 0 )
1369 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1370 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1378 val.b_bool = !val.b_bool;
1379 var_Set( p_playlist, "loop", val );
1381 msg_rc( "Setting loop to %d", val.b_bool );
1383 else if( !strcmp( psz_cmd, "random" ) )
1385 bool b_update = true;
1387 var_Get( p_playlist, "random", &val );
1389 if( strlen( newval.psz_string ) > 0 )
1391 if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == true ) ) ||
1392 ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == false ) ) )
1400 val.b_bool = !val.b_bool;
1401 var_Set( p_playlist, "random", val );
1403 msg_rc( "Setting random to %d", val.b_bool );
1405 else if (!strcmp( psz_cmd, "goto" ) )
1407 int i_pos = atoi( newval.psz_string );
1408 /* The playlist stores 2 times the same item: onelevel & category */
1409 int i_size = p_playlist->items.i_size / 2;
1412 msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1413 else if( i_pos <= i_size )
1415 playlist_item_t *p_item, *p_parent;
1416 p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1417 while( p_parent->p_parent )
1418 p_parent = p_parent->p_parent;
1419 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, pl_Unlocked,
1423 msg_rc( _("Playlist has only %d elements"), i_size );
1425 else if( !strcmp( psz_cmd, "stop" ) )
1427 playlist_Stop( p_playlist );
1429 else if( !strcmp( psz_cmd, "clear" ) )
1431 playlist_Stop( p_playlist );
1432 playlist_Clear( p_playlist, pl_Unlocked );
1434 else if( !strcmp( psz_cmd, "add" ) &&
1435 newval.psz_string && *newval.psz_string )
1437 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1441 msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1442 int i_ret =playlist_AddInput( p_playlist, p_item,
1443 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, true,
1445 vlc_gc_decref( p_item );
1446 if( i_ret != VLC_SUCCESS )
1448 return VLC_EGENERIC;
1452 else if( !strcmp( psz_cmd, "enqueue" ) &&
1453 newval.psz_string && *newval.psz_string )
1455 input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1459 msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1460 if( playlist_AddInput( p_playlist, p_item,
1461 PLAYLIST_APPEND, PLAYLIST_END, true,
1462 pl_Unlocked ) != VLC_SUCCESS )
1464 return VLC_EGENERIC;
1468 else if( !strcmp( psz_cmd, "playlist" ) )
1470 msg_rc( "+----[ Playlist ]" );
1471 print_playlist( p_intf, p_playlist->p_root_category, 0 );
1472 msg_rc( "+----[ End of playlist ]" );
1475 else if( !strcmp( psz_cmd, "sort" ))
1477 playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1478 SORT_ARTIST, ORDER_NORMAL );
1480 else if( !strcmp( psz_cmd, "status" ) )
1482 if( p_playlist->p_input )
1484 /* Replay the current state of the system. */
1486 input_item_GetURI( input_GetItem( p_playlist->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( p_playlist->status.i_status )
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 )" );
1517 msg_rc( "unknown command!" );
1520 vlc_object_release( p_playlist );
1524 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1525 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1527 VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
1528 VLC_UNUSED(oldval); VLC_UNUSED(newval);
1529 playlist_t *p_playlist;
1531 p_playlist = pl_Yield( p_this );
1532 playlist_Stop( p_playlist );
1533 vlc_object_release( p_playlist );
1535 vlc_object_kill( p_this->p_libvlc );
1539 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1540 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1542 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1543 intf_thread_t *p_newintf = NULL;
1545 p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string );
1548 if( intf_RunThread( p_newintf ) )
1550 vlc_object_detach( p_newintf );
1551 vlc_object_release( p_newintf );
1558 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1559 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1561 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1562 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1563 input_thread_t *p_input = NULL;
1564 int i_error = VLC_EGENERIC;
1566 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1574 var_Get( p_input, "state", &val );
1575 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1577 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1578 vlc_object_release( p_input );
1579 return VLC_EGENERIC;
1581 vlc_object_release( p_input );
1584 if ( *newval.psz_string )
1587 audio_volume_t i_volume = atoi( newval.psz_string );
1588 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1590 msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1592 i_error = VLC_EBADVAR;
1596 if( i_volume == AOUT_VOLUME_MIN )
1600 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1601 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1603 i_error = aout_VolumeSet( p_this, i_volume );
1604 osd_Volume( p_this );
1605 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1611 audio_volume_t i_volume;
1612 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1614 i_error = VLC_EGENERIC;
1618 msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1619 i_error = VLC_SUCCESS;
1626 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1627 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1629 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1630 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1631 audio_volume_t i_volume;
1632 input_thread_t *p_input = NULL;
1633 int i_nb_steps = atoi(newval.psz_string);
1634 int i_error = VLC_SUCCESS;
1635 int i_volume_step = 0;
1637 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1645 var_Get( p_input, "state", &val );
1646 if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1648 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1649 vlc_object_release( p_input );
1650 return VLC_EGENERIC;
1652 vlc_object_release( p_input );
1655 i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1656 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1661 if ( !strcmp(psz_cmd, "volup") )
1663 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1664 i_error = VLC_EGENERIC;
1668 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1669 i_error = VLC_EGENERIC;
1671 osd_Volume( p_this );
1673 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1678 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1679 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1681 VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1682 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1683 input_thread_t *p_input = NULL;
1684 vout_thread_t * p_vout;
1685 const char * psz_variable = NULL;
1688 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1692 p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1693 vlc_object_release( p_input );
1697 if( !strcmp( psz_cmd, "vcrop" ) )
1699 psz_variable = "crop";
1701 else if( !strcmp( psz_cmd, "vratio" ) )
1703 psz_variable = "aspect-ratio";
1705 else if( !strcmp( psz_cmd, "vzoom" ) )
1707 psz_variable = "zoom";
1709 else if( !strcmp( psz_cmd, "snapshot" ) )
1711 psz_variable = "video-snapshot";
1714 if( newval.psz_string && *newval.psz_string )
1717 if( !strcmp( psz_variable, "zoom" ) )
1720 val.f_float = atof( newval.psz_string );
1721 i_error = var_Set( p_vout, psz_variable, val );
1725 i_error = var_Set( p_vout, psz_variable, newval );
1728 else if( !strcmp( psz_cmd, "snapshot" ) )
1732 i_error = var_Set( p_vout, psz_variable, val );
1737 vlc_value_t val_name;
1738 vlc_value_t val, text;
1741 char *psz_value = NULL;
1743 if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1745 vlc_object_release( p_vout );
1746 return VLC_EGENERIC;
1748 if( !strcmp( psz_variable, "zoom" ) )
1750 f_value = val.f_float;
1754 psz_value = strdup( val.psz_string );
1757 if ( var_Change( p_vout, psz_variable,
1758 VLC_VAR_GETLIST, &val, &text ) < 0 )
1760 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 ) || ( val.i_int == PLAYLIST_PAUSED ) ) {
1828 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1829 vlc_object_release( p_input );
1830 return VLC_EGENERIC;
1832 vlc_object_release( p_input );
1835 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1836 if ( p_aout == NULL ) return VLC_ENOOBJ;
1838 if ( !strcmp( psz_cmd, "adev" ) )
1840 psz_variable = "audio-device";
1844 psz_variable = "audio-channels";
1847 /* Get the descriptive name of the variable */
1848 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1850 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1852 if ( !*newval.psz_string )
1854 /* Retrieve all registered ***. */
1855 vlc_value_t val, text;
1858 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1860 vlc_object_release( (vlc_object_t *)p_aout );
1861 return VLC_EGENERIC;
1863 i_value = val.i_int;
1865 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1866 VLC_VAR_GETLIST, &val, &text ) < 0 )
1868 vlc_object_release( (vlc_object_t *)p_aout );
1869 return VLC_EGENERIC;
1872 msg_rc( "+----[ %s ]", val_name.psz_string );
1873 for ( i = 0; i < val.p_list->i_count; i++ )
1875 if ( i_value == val.p_list->p_values[i].i_int )
1876 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1877 text.p_list->p_values[i].psz_string );
1879 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1880 text.p_list->p_values[i].psz_string );
1882 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1884 msg_rc( "+----[ end of %s ]", val_name.psz_string );
1886 free( val_name.psz_string );
1887 i_error = VLC_SUCCESS;
1892 val.i_int = atoi( newval.psz_string );
1894 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1896 vlc_object_release( (vlc_object_t *)p_aout );
1901 /* OSD menu commands */
1902 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1903 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1905 VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
1906 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1907 playlist_t *p_playlist = NULL;
1908 int i_error = VLC_SUCCESS;
1911 if ( !*newval.psz_string )
1913 msg_rc( _("Please provide one of the following parameters:") );
1914 msg_rc( "[on|off|up|down|left|right|select]" );
1915 return VLC_EGENERIC;
1918 p_playlist = pl_Yield( p_this );
1920 if( p_playlist->p_input )
1922 var_Get( p_playlist->p_input, "state", &val );
1923 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1924 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1926 msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1927 vlc_object_release( p_playlist );
1928 return VLC_EGENERIC;
1931 vlc_object_release( p_playlist );
1933 val.psz_string = strdup( newval.psz_string );
1934 if( !val.psz_string )
1936 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1937 osd_MenuShow( p_this );
1938 else if( !strcmp( val.psz_string, "off" )
1939 || !strcmp( val.psz_string, "hide" ) )
1940 osd_MenuHide( p_this );
1941 else if( !strcmp( val.psz_string, "up" ) )
1942 osd_MenuUp( p_this );
1943 else if( !strcmp( val.psz_string, "down" ) )
1944 osd_MenuDown( p_this );
1945 else if( !strcmp( val.psz_string, "left" ) )
1946 osd_MenuPrev( p_this );
1947 else if( !strcmp( val.psz_string, "right" ) )
1948 osd_MenuNext( p_this );
1949 else if( !strcmp( val.psz_string, "select" ) )
1950 osd_MenuActivate( p_this );
1953 msg_rc( _("Please provide one of the following parameters:") );
1954 msg_rc( "[on|off|up|down|left|right|select]" );
1955 i_error = VLC_EGENERIC;
1958 free( val.psz_string );
1962 static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
1963 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1965 VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(p_data);
1966 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1967 input_thread_t *p_input = NULL;
1970 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1974 if( !strcmp( psz_cmd, "stats" ) )
1976 vlc_mutex_lock( &input_GetItem(p_input)->lock );
1977 updateStatistics( p_intf, input_GetItem(p_input) );
1978 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
1985 msg_rc(_("Unknown command!") );
1988 vlc_object_release( p_input );
1989 i_error = VLC_SUCCESS;
1993 static int updateStatistics( intf_thread_t *p_intf, input_item_t *p_item )
1995 if( !p_item ) return VLC_EGENERIC;
1997 vlc_mutex_lock( &p_item->p_stats->lock );
1998 msg_rc( "+----[ begin of statistical info ]" );
2001 msg_rc(_("+-[Incoming]"));
2002 msg_rc(_("| input bytes read : %8.0f kB"),
2003 (float)(p_item->p_stats->i_read_bytes)/1000 );
2004 msg_rc(_("| input bitrate : %6.0f kb/s"),
2005 (float)(p_item->p_stats->f_input_bitrate)*8000 );
2006 msg_rc(_("| demux bytes read : %8.0f kB"),
2007 (float)(p_item->p_stats->i_demux_read_bytes)/1000 );
2008 msg_rc(_("| demux bitrate : %6.0f kb/s"),
2009 (float)(p_item->p_stats->f_demux_bitrate)*8000 );
2012 msg_rc(_("+-[Video Decoding]"));
2013 msg_rc(_("| video decoded : %5i"),
2014 p_item->p_stats->i_decoded_video );
2015 msg_rc(_("| frames displayed : %5i"),
2016 p_item->p_stats->i_displayed_pictures );
2017 msg_rc(_("| frames lost : %5i"),
2018 p_item->p_stats->i_lost_pictures );
2021 msg_rc(_("+-[Audio Decoding]"));
2022 msg_rc(_("| audio decoded : %5i"),
2023 p_item->p_stats->i_decoded_audio );
2024 msg_rc(_("| buffers played : %5i"),
2025 p_item->p_stats->i_played_abuffers );
2026 msg_rc(_("| buffers lost : %5i"),
2027 p_item->p_stats->i_lost_abuffers );
2030 msg_rc(_("+-[Streaming]"));
2031 msg_rc(_("| packets sent : %5i"), p_item->p_stats->i_sent_packets );
2032 msg_rc(_("| bytes sent : %8.0f kB"),
2033 (float)(p_item->p_stats->i_sent_bytes)/1000 );
2034 msg_rc(_("| sending bitrate : %6.0f kb/s"),
2035 (float)(p_item->p_stats->f_send_bitrate*8)*1000 );
2037 msg_rc( "+----[ end of statistical info ]" );
2038 vlc_mutex_unlock( &p_item->p_stats->lock );
2044 bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2046 INPUT_RECORD input_record;
2049 /* On Win32, select() only works on socket descriptors */
2050 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
2051 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
2053 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2054 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
2057 if( input_record.EventType != KEY_EVENT ||
2058 !input_record.Event.KeyEvent.bKeyDown ||
2059 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
2060 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
2061 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
2062 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
2064 /* nothing interesting */
2068 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
2070 /* Echo out the command */
2071 putc( p_buffer[ *pi_size ], stdout );
2073 /* Handle special keys */
2074 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2076 putc( '\n', stdout );
2079 switch( p_buffer[ *pi_size ] )
2085 putc( ' ', stdout );
2086 putc( '\b', stdout );
2097 if( *pi_size == MAX_LINE_LENGTH ||
2098 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2100 p_buffer[ *pi_size ] = 0;
2109 bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
2114 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
2115 return ReadWin32( p_intf, p_buffer, pi_size );
2116 else if( p_intf->p_sys->i_socket == -1 )
2118 msleep( INTF_IDLE_SLEEP );
2123 while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
2124 (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
2125 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
2126 (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )
2128 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2134 /* Connection closed */
2137 if( p_intf->p_sys->i_socket != -1 )
2139 net_Close( p_intf->p_sys->i_socket );
2140 p_intf->p_sys->i_socket = -1;
2144 /* Standard input closed: exit */
2146 Quit( VLC_OBJECT(p_intf), NULL, empty, empty, NULL );
2149 p_buffer[ *pi_size ] = 0;
2153 if( *pi_size == MAX_LINE_LENGTH ||
2154 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2156 p_buffer[ *pi_size ] = 0;
2163 /*****************************************************************************
2164 * parse_MRL: build a input item from a full mrl
2165 *****************************************************************************
2166 * MRL format: "simplified-mrl [:option-name[=option-value]]"
2167 * We don't check for '"' or '\'', we just assume that a ':' that follows a
2168 * space is a new option. Should be good enough for our purpose.
2169 *****************************************************************************/
2170 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2172 #define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
2173 #define SKIPTRAILINGSPACE( p, d ) \
2174 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2176 input_item_t *p_item = NULL;
2177 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2178 char **ppsz_options = NULL;
2179 int i, i_options = 0;
2181 if( !psz_mrl ) return 0;
2183 psz_mrl = psz_orig = strdup( psz_mrl );
2186 SKIPSPACE( psz_mrl );
2189 for( ; *psz_mrl; psz_mrl++ )
2191 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2193 /* We have a complete item */
2196 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2197 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2199 /* We have a complete item */
2204 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2205 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2207 /* Remove '"' and '\'' if necessary */
2208 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2209 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2210 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2211 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2213 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2214 else if( *psz_item )
2217 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2218 ppsz_options[i_options - 1] = &psz_item[1];
2221 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2224 /* Now create a playlist item */
2227 p_item = input_item_New( p_intf, psz_item_mrl, NULL );
2228 for( i = 0; i < i_options; i++ )
2230 input_item_AddOption( p_item, ppsz_options[i] );
2234 if( i_options ) free( ppsz_options );