1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 - 2005 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
31 #include <errno.h> /* ENOMEM */
46 #ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
49 #include <sys/types.h>
51 #include "vlc_error.h"
54 #if defined(AF_UNIX) && !defined(AF_LOCAL)
55 # define AF_LOCAL AF_UNIX
58 #if defined(AF_LOCAL) && ! defined(WIN32)
62 #define MAX_LINE_LENGTH 256
63 #define STATUS_CHANGE "status change: "
65 /*****************************************************************************
67 *****************************************************************************/
68 static int Activate ( vlc_object_t * );
69 static void Deactivate ( vlc_object_t * );
70 static void Run ( intf_thread_t * );
72 static void Help ( intf_thread_t *, vlc_bool_t );
74 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
76 static playlist_item_t *parse_MRL( intf_thread_t *, char * );
78 static int Input ( vlc_object_t *, char const *,
79 vlc_value_t, vlc_value_t, void * );
80 static int Playlist ( vlc_object_t *, char const *,
81 vlc_value_t, vlc_value_t, void * );
82 static int Other ( vlc_object_t *, char const *,
83 vlc_value_t, vlc_value_t, void * );
84 static int Quit ( vlc_object_t *, char const *,
85 vlc_value_t, vlc_value_t, void * );
86 static int Intf ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
88 static int Volume ( vlc_object_t *, char const *,
89 vlc_value_t, vlc_value_t, void * );
90 static int VolumeMove ( vlc_object_t *, char const *,
91 vlc_value_t, vlc_value_t, void * );
92 static int AudioConfig ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int Menu ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
97 /* Status Callbacks */
98 static int TimeOffsetChanged( vlc_object_t *, char const *,
99 vlc_value_t, vlc_value_t , void * );
100 static int VolumeChanged ( vlc_object_t *, char const *,
101 vlc_value_t, vlc_value_t, void * );
102 static int StateChanged ( vlc_object_t *, char const *,
103 vlc_value_t, vlc_value_t, void * );
104 static int RateChanged ( vlc_object_t *, char const *,
105 vlc_value_t, vlc_value_t, void * );
109 int *pi_socket_listen;
114 vlc_mutex_t status_lock;
115 playlist_status_t i_last_state;
123 #ifdef HAVE_VARIADIC_MACROS
124 # define msg_rc( psz_format, args... ) \
125 __msg_rc( p_intf, psz_format, ## args )
128 void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
131 va_start( args, psz_fmt );
132 if( p_intf->p_sys->i_socket == -1 )
133 vprintf( psz_fmt, args );
136 net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
137 net_Printf( VLC_OBJECT(p_intf), p_intf->p_sys->i_socket, NULL, "\r" );
142 /*****************************************************************************
144 *****************************************************************************/
145 #define POS_TEXT N_("Show stream position")
146 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
147 "stream from time to time." )
149 #define TTY_TEXT N_("Fake TTY")
150 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
152 #define UNIX_TEXT N_("UNIX socket command input")
153 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
156 #define HOST_TEXT N_("TCP command input")
157 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
158 "You can set the address and port the interface will bind to." )
161 #define QUIET_TEXT N_("Do not open a DOS command box interface")
162 #define QUIET_LONGTEXT N_( \
163 "By default the rc interface plugin will start a DOS command box. " \
164 "Enabling the quiet mode will not bring this command box but can also " \
165 "be pretty annoying when you want to stop VLC and no video window is " \
170 set_shortname( _("RC"));
171 set_category( CAT_INTERFACE );
172 set_subcategory( SUBCAT_INTERFACE_GENERAL );
173 set_description( _("Remote control interface") );
174 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
176 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
178 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
179 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
182 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
185 set_capability( "interface", 20 );
186 set_callbacks( Activate, Deactivate );
189 /*****************************************************************************
190 * Activate: initialize and create stuff
191 *****************************************************************************/
192 static int Activate( vlc_object_t *p_this )
194 intf_thread_t *p_intf = (intf_thread_t*)p_this;
195 playlist_t *p_playlist;
196 char *psz_host, *psz_unix_path;
197 int *pi_socket = NULL;
199 #if defined(HAVE_ISATTY) && !defined(WIN32)
200 /* Check that stdin is a TTY */
201 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
203 msg_Warn( p_intf, "fd 0 is not a TTY" );
208 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
213 #if !defined(AF_LOCAL) || defined(WIN32)
214 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
215 free( psz_unix_path );
218 struct sockaddr_un addr;
221 memset( &addr, 0, sizeof(struct sockaddr_un) );
223 msg_Dbg( p_intf, "trying UNIX socket" );
225 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
227 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
228 free( psz_unix_path );
232 addr.sun_family = AF_LOCAL;
233 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
234 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
236 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
237 sizeof(struct sockaddr_un) ) ) < 0 )
239 msg_Warn( p_intf, "couldn't bind socket to address: %s",
241 free( psz_unix_path );
242 net_Close( i_socket );
246 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
248 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
249 free( psz_unix_path );
250 net_Close( i_socket );
254 /* FIXME: we need a core function to merge listening sockets sets */
255 pi_socket = calloc( 2, sizeof( int ) );
256 if( pi_socket == NULL )
258 free( psz_unix_path );
259 net_Close( i_socket );
262 pi_socket[0] = i_socket;
267 if( ( pi_socket == NULL ) &&
268 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
272 vlc_UrlParse( &url, psz_host, 0 );
274 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
276 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
277 if( pi_socket == NULL )
279 msg_Warn( p_intf, "can't listen to %s port %i",
280 url.psz_host, url.i_port );
281 vlc_UrlClean( &url );
286 vlc_UrlClean( &url );
290 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
293 msg_Err( p_intf, "no memory" );
297 p_intf->p_sys->pi_socket_listen = pi_socket;
298 p_intf->p_sys->i_socket = -1;
299 p_intf->p_sys->psz_unix_path = psz_unix_path;
300 vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
301 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
303 /* Non-buffered stdout */
304 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
306 p_intf->pf_run = Run;
309 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
310 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
315 /* Force "no-view" mode */
316 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
320 vlc_mutex_lock( &p_playlist->object_lock );
321 p_playlist->status.i_view = -1;
322 vlc_mutex_unlock( &p_playlist->object_lock );
323 vlc_object_release( p_playlist );
326 msg_rc( _("Remote control interface initialized, `h' for help\n") );
330 /*****************************************************************************
331 * Deactivate: uninitialize and cleanup
332 *****************************************************************************/
333 static void Deactivate( vlc_object_t *p_this )
335 intf_thread_t *p_intf = (intf_thread_t*)p_this;
337 net_ListenClose( p_intf->p_sys->pi_socket_listen );
338 if( p_intf->p_sys->i_socket != -1 )
339 net_Close( p_intf->p_sys->i_socket );
340 if( p_intf->p_sys->psz_unix_path != NULL )
342 #if defined(AF_LOCAL) && !defined(WIN32)
343 unlink( p_intf->p_sys->psz_unix_path );
345 free( p_intf->p_sys->psz_unix_path );
347 vlc_mutex_destroy( &p_intf->p_sys->status_lock );
348 free( p_intf->p_sys );
351 /*****************************************************************************
353 *****************************************************************************
354 * This part of the interface is in a separate thread so that we can call
355 * exec() from within it without annoying the rest of the program.
356 *****************************************************************************/
357 static void Run( intf_thread_t *p_intf )
359 input_thread_t * p_input;
360 playlist_t * p_playlist;
362 char p_buffer[ MAX_LINE_LENGTH + 1 ];
363 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
364 vlc_bool_t b_longhelp = VLC_FALSE;
374 /* Register commands that will be cleaned up upon object destruction */
375 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
376 var_AddCallback( p_intf, "quit", Quit, NULL );
377 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
378 var_AddCallback( p_intf, "intf", Intf, NULL );
380 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
381 var_AddCallback( p_intf, "add", Playlist, NULL );
382 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
383 var_AddCallback( p_intf, "playlist", Playlist, NULL );
384 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
385 var_AddCallback( p_intf, "play", Playlist, NULL );
386 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
387 var_AddCallback( p_intf, "stop", Playlist, NULL );
388 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
389 var_AddCallback( p_intf, "prev", Playlist, NULL );
390 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
391 var_AddCallback( p_intf, "next", Playlist, NULL );
392 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
393 var_AddCallback( p_intf, "goto", Playlist, NULL );
395 /* marquee on the fly items */
396 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
397 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
398 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
399 var_AddCallback( p_intf, "marq-x", Other, NULL );
400 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
401 var_AddCallback( p_intf, "marq-y", Other, NULL );
402 var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
403 var_AddCallback( p_intf, "marq-position", Other, NULL );
404 var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
405 var_AddCallback( p_intf, "marq-color", Other, NULL );
406 var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
407 var_AddCallback( p_intf, "marq-opacity", Other, NULL );
408 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
409 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
410 var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
411 var_AddCallback( p_intf, "marq-size", Other, NULL );
413 var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
414 var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
415 var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
416 var_AddCallback( p_intf, "mosaic-height", Other, NULL );
417 var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
418 var_AddCallback( p_intf, "mosaic-width", Other, NULL );
419 var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
420 var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
421 var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
422 var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
423 var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
424 var_AddCallback( p_intf, "mosaic-align", Other, NULL );
425 var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
426 var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
427 var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
428 var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
429 var_Create( p_intf, "mosaic-position",
430 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
431 var_AddCallback( p_intf, "mosaic-position", Other, NULL );
432 var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
433 var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
434 var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
435 var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
436 var_Create( p_intf, "mosaic-keep-aspect-ratio",
437 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
438 var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
440 /* time on the fly items */
441 var_Create( p_intf, "time-format", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
442 var_AddCallback( p_intf, "time-format", Other, NULL );
443 var_Create( p_intf, "time-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
444 var_AddCallback( p_intf, "time-x", Other, NULL );
445 var_Create( p_intf, "time-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
446 var_AddCallback( p_intf, "time-y", Other, NULL );
447 var_Create( p_intf, "time-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
448 var_AddCallback( p_intf, "time-position", Other, NULL );
449 var_Create( p_intf, "time-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
450 var_AddCallback( p_intf, "time-color", Other, NULL );
451 var_Create( p_intf, "time-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
452 var_AddCallback( p_intf, "time-opacity", Other, NULL );
453 var_Create( p_intf, "time-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
454 var_AddCallback( p_intf, "time-size", Other, NULL );
456 /* logo on the fly items */
457 var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
458 var_AddCallback( p_intf, "logo-file", Other, NULL );
459 var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
460 var_AddCallback( p_intf, "logo-x", Other, NULL );
461 var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
462 var_AddCallback( p_intf, "logo-y", Other, NULL );
463 var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
464 var_AddCallback( p_intf, "logo-position", Other, NULL );
465 var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
466 var_AddCallback( p_intf, "logo-transparency", Other, NULL );
468 /* OSD menu commands */
469 var_Create( p_intf, "menu", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
470 var_AddCallback( p_intf, "menu", Menu, NULL );
473 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
474 var_AddCallback( p_intf, "pause", Input, NULL );
475 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
476 var_AddCallback( p_intf, "seek", Input, NULL );
477 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
478 var_AddCallback( p_intf, "title", Input, NULL );
479 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
480 var_AddCallback( p_intf, "title_n", Input, NULL );
481 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
482 var_AddCallback( p_intf, "title_p", Input, NULL );
483 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
484 var_AddCallback( p_intf, "chapter", Input, NULL );
485 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
486 var_AddCallback( p_intf, "chapter_n", Input, NULL );
487 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
488 var_AddCallback( p_intf, "chapter_p", Input, NULL );
490 var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
491 var_AddCallback( p_intf, "fastforward", Input, NULL );
492 var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
493 var_AddCallback( p_intf, "rewind", Input, NULL );
494 var_Create( p_intf, "faster", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
495 var_AddCallback( p_intf, "faster", Input, NULL );
496 var_Create( p_intf, "slower", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
497 var_AddCallback( p_intf, "slower", Input, NULL );
498 var_Create( p_intf, "normal", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
499 var_AddCallback( p_intf, "normal", Input, NULL );
502 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
503 var_AddCallback( p_intf, "volume", Volume, NULL );
504 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
505 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
506 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
507 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
508 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
509 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
510 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
511 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
513 /* status callbacks */
514 /* Listen to audio volume updates */
515 var_AddCallback( p_intf->p_vlc, "audio-volume", VolumeChanged, p_intf );
518 /* Get the file descriptor of the console input */
519 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
520 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
522 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
523 p_intf->b_die = VLC_TRUE;
527 while( !p_intf->b_die )
529 char *psz_cmd, *psz_arg;
530 vlc_bool_t b_complete;
532 if( p_intf->p_sys->pi_socket_listen != NULL &&
533 p_intf->p_sys->i_socket == -1 )
535 p_intf->p_sys->i_socket =
536 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
539 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
541 /* Manage the input part */
542 if( p_input == NULL )
546 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
551 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
555 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
559 /* New input has been registered */
562 if( !p_input->b_dead || !p_input->b_die )
564 msg_rc( STATUS_CHANGE "( New input: %s )\r\n", p_input->input.p_item->psz_uri );
565 msg_rc( STATUS_CHANGE "( audio volume: %d )\r\n", config_GetInt( p_intf, "volume" ));
567 var_AddCallback( p_input, "state", StateChanged, p_intf );
568 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
569 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
570 var_AddCallback( p_input, "rate", RateChanged, p_intf );
571 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
574 else if( p_input->b_dead )
576 var_DelCallback( p_input, "state", StateChanged, p_intf );
577 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
578 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
579 var_DelCallback( p_input, "rate", RateChanged, p_intf );
580 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
581 vlc_object_release( p_input );
586 vlc_mutex_lock( &p_playlist->object_lock );
587 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
588 msg_rc( STATUS_CHANGE "( stop state: 0 )\r\n" );
589 vlc_mutex_unlock( &p_playlist->object_lock );
593 if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
594 (p_playlist != NULL) )
596 vlc_mutex_lock( &p_playlist->object_lock );
597 if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
598 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
600 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
601 msg_rc( STATUS_CHANGE "( stop state: 0 )\r\n" );
603 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
604 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
606 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
607 msg_rc( STATUS_CHANGE "( play state: 1 )\r\n" );
609 else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
610 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
612 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
613 msg_rc( STATUS_CHANGE "( pause state: 2 )\r\n" );
615 vlc_mutex_unlock( &p_playlist->object_lock );
618 if( p_input && b_showpos )
620 i_newpos = 100 * var_GetFloat( p_input, "position" );
621 if( i_oldpos != i_newpos )
624 msg_rc( "pos: %d%%\n", i_newpos );
628 /* Is there something to do? */
629 if( !b_complete ) continue;
632 /* Skip heading spaces */
634 while( *psz_cmd == ' ' )
639 /* Split psz_cmd at the first space and make sure that
640 * psz_arg is valid */
641 psz_arg = strchr( psz_cmd, ' ' );
645 while( *psz_arg == ' ' )
655 /* If the user typed a registered local command, try it */
656 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
661 val.psz_string = psz_arg;
662 i_ret = var_Set( p_intf, psz_cmd, val );
663 msg_rc( "%s: returned %i (%s)\n",
664 psz_cmd, i_ret, vlc_error( i_ret ) );
666 /* Or maybe it's a global command */
667 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
672 val.psz_string = psz_arg;
673 /* FIXME: it's a global command, but we should pass the
674 * local object as an argument, not p_intf->p_libvlc. */
675 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
678 msg_rc( "%s: returned %i (%s)\n",
679 psz_cmd, i_ret, vlc_error( i_ret ) );
682 else if( !strcmp( psz_cmd, "logout" ) )
684 /* Close connection */
685 if( p_intf->p_sys->i_socket != -1 )
687 net_Close( p_intf->p_sys->i_socket );
689 p_intf->p_sys->i_socket = -1;
691 else if( !strcmp( psz_cmd, "info" ) )
696 vlc_mutex_lock( &p_input->input.p_item->lock );
697 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
699 info_category_t *p_category =
700 p_input->input.p_item->pp_categories[i];
702 msg_rc( "+----[ %s ]\n", p_category->psz_name );
704 for ( j = 0; j < p_category->i_infos; j++ )
706 info_t *p_info = p_category->pp_infos[j];
707 msg_rc( "| %s: %s\n", p_info->psz_name,
712 msg_rc( "+----[ end of stream info ]\n" );
713 vlc_mutex_unlock( &p_input->input.p_item->lock );
717 msg_rc( "no input\n" );
720 else if( !strcmp( psz_cmd, "is_playing" ) )
730 /* FIXME: This is a hack */
731 /* Replay the current state of the system. */
732 msg_rc( STATUS_CHANGE "( New input: %s )\r\n", p_input->input.p_item->psz_uri );
733 msg_rc( STATUS_CHANGE "( audio volume: %d )\r\n", config_GetInt( p_intf, "volume" ));
737 vlc_mutex_lock( &p_playlist->object_lock );
738 switch( p_playlist->status.i_status )
740 case PLAYLIST_STOPPED:
741 msg_rc( STATUS_CHANGE "( stop state: 0 )\r\n" );
743 case PLAYLIST_RUNNING:
744 msg_rc( STATUS_CHANGE "( play state: %d )\r\n", var_GetInteger( p_input, "state" ) );
746 case PLAYLIST_PAUSED:
747 msg_rc( STATUS_CHANGE "( pause state: 2 )\r\n" );
750 msg_rc( STATUS_CHANGE "( state unknown )\r\n" );
753 vlc_mutex_unlock( &p_playlist->object_lock );
754 } /* End of current playlist status */
757 else if( !strcmp( psz_cmd, "get_time" ) )
766 var_Get( p_input, "time", &time );
767 msg_rc( "%i\n", time.i_time / 1000000);
770 else if( !strcmp( psz_cmd, "get_length" ) )
779 var_Get( p_input, "length", &time );
780 msg_rc( "%i\n", time.i_time / 1000000);
783 else if( !strcmp( psz_cmd, "get_title" ) )
791 msg_rc( "%s\n", p_input->input.p_item->psz_name );
794 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
795 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
797 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
798 b_longhelp = VLC_TRUE;
799 else b_longhelp = VLC_FALSE;
801 Help( p_intf, b_longhelp );
803 else switch( psz_cmd[0] )
809 vout_thread_t *p_vout;
810 p_vout = vlc_object_find( p_input,
811 VLC_OBJECT_VOUT, FIND_CHILD );
815 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
816 vlc_object_release( p_vout );
827 /* Ignore empty lines */
831 msg_rc(_("unknown command `%s', type `help' for help\n"), psz_cmd);
835 /* Command processed */
836 i_size = 0; p_buffer[0] = 0;
839 msg_rc( STATUS_CHANGE "( stop state: 0 )\r\n" );
840 msg_rc( STATUS_CHANGE "( quit )\r\n" );
844 var_DelCallback( p_input, "state", StateChanged, p_intf );
845 var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
846 var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
847 var_DelCallback( p_input, "rate", RateChanged, p_intf );
848 var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
849 vlc_object_release( p_input );
855 vlc_object_release( p_playlist );
859 var_DelCallback( p_intf->p_vlc, "audio-volume", VolumeChanged, p_intf );
862 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
864 msg_rc(_("+----[ Remote control commands ]\n"));
866 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
867 msg_rc(_("| playlist . . . show items currently in playlist\n"));
868 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream\n"));
869 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
870 msg_rc(_("| next . . . . . . . . . . . . next playlist item\n"));
871 msg_rc(_("| prev . . . . . . . . . . previous playlist item\n"));
872 msg_rc(_("| goto . . . . . . . . . . . . goto item at index\n"));
873 msg_rc(_("| title [X] . . . . set/get title in current item\n"));
874 msg_rc(_("| title_n . . . . . . next title in current item\n"));
875 msg_rc(_("| title_p . . . . previous title in current item\n"));
876 msg_rc(_("| chapter [X] . . set/get chapter in current item\n"));
877 msg_rc(_("| chapter_n . . . . next chapter in current item\n"));
878 msg_rc(_("| chapter_p . . previous chapter in current item\n"));
880 msg_rc(_("| seek X . seek in seconds, for instance `seek 12'\n"));
881 msg_rc(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
882 msg_rc(_("| fastforward . . . . . . . set to maximum rate\n"));
883 msg_rc(_("| rewind . . . . . . . . . . set to minimum rate\n"));
884 msg_rc(_("| faster . . . . . . . . faster playing of stream\n"));
885 msg_rc(_("| slower . . . . . . . . slower playing of stream\n"));
886 msg_rc(_("| normal . . . . . . . . normal playing of stream\n"));
887 msg_rc(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
888 msg_rc(_("| info . . . information about the current stream\n"));
890 msg_rc(_("| volume [X] . . . . . . . . set/get audio volume\n"));
891 msg_rc(_("| volup [X] . . . . . raise audio volume X steps\n"));
892 msg_rc(_("| voldown [X] . . . . lower audio volume X steps\n"));
893 msg_rc(_("| adev [X] . . . . . . . . . set/get audio device\n"));
894 msg_rc(_("| achan [X]. . . . . . . . set/get audio channels\n"));
895 msg_rc(_("| menu [on|off|up|down|left|right|select] use menu\n"));
900 msg_rc(_("| marq-marquee STRING . . overlay STRING in video\n"));
901 msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left\n"));
902 msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top\n"));
903 msg_rc(_("| marq-position #. . . .relative position control\n"));
904 msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB\n"));
905 msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity\n"));
906 msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms\n"));
907 msg_rc(_("| marq-size # . . . . . . . . font size, in pixels\n"));
909 msg_rc(_("| time-format STRING . . . overlay STRING in video\n"));
910 msg_rc(_("| time-x X . . . . . . . . . . . .offset from left\n"));
911 msg_rc(_("| time-y Y . . . . . . . . . . . . offset from top\n"));
912 msg_rc(_("| time-position #. . . . . . . . relative position\n"));
913 msg_rc(_("| time-color # . . . . . . . . . . font color, RGB\n"));
914 msg_rc(_("| time-opacity # . . . . . . . . . . . . . opacity\n"));
915 msg_rc(_("| time-size # . . . . . . . . font size, in pixels\n"));
917 msg_rc(_("| logo-file STRING . . . the overlay file path/name\n"));
918 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left\n"));
919 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top\n"));
920 msg_rc(_("| logo-position #. . . . . . . . relative position\n"));
921 msg_rc(_("| logo-transparency #. . . . . . . . .transparency\n"));
923 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha\n"));
924 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height\n"));
925 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width\n"));
926 msg_rc(_("| mosaic-xoffset # . . . .top left corner position\n"));
927 msg_rc(_("| mosaic-yoffset # . . . .top left corner position\n"));
928 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment\n"));
929 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border\n"));
930 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border\n"));
931 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position\n"));
932 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows\n"));
933 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols\n"));
934 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio\n"));
937 msg_rc(_("| help . . . . . . . . . . . . . this help message\n"));
938 msg_rc(_("| longhelp . . . . . . . . . a longer help message\n"));
939 msg_rc(_("| logout . . . . . exit (if in socket connection)\n"));
940 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
942 msg_rc(_("+----[ end of help ]\n"));
945 /********************************************************************
946 * Status callback routines
947 ********************************************************************/
948 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
949 vlc_value_t oldval, vlc_value_t newval, void *p_data )
951 intf_thread_t *p_intf = (intf_thread_t*)p_data;
952 input_thread_t *p_input = NULL;
954 vlc_mutex_lock( &p_intf->p_sys->status_lock );
955 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
958 msg_rc( STATUS_CHANGE "( time-offset: %d )\r\n", var_GetInteger( p_input, "time-offset" ) );
959 vlc_object_release( p_input );
961 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
965 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
966 vlc_value_t oldval, vlc_value_t newval, void *p_data )
968 intf_thread_t *p_intf = (intf_thread_t*)p_data;
970 vlc_mutex_lock( &p_intf->p_sys->status_lock );
971 msg_rc( STATUS_CHANGE "( audio volume: %d )\r\n", newval.i_int );
972 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
976 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
977 vlc_value_t oldval, vlc_value_t newval, void *p_data )
979 intf_thread_t *p_intf = (intf_thread_t*)p_data;
980 playlist_t *p_playlist = NULL;
981 input_thread_t *p_input = NULL;
983 vlc_mutex_lock( &p_intf->p_sys->status_lock );
984 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
987 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
991 switch( p_playlist->status.i_status )
993 case PLAYLIST_STOPPED:
994 strncpy( &cmd[0], "stop", 4);
997 case PLAYLIST_RUNNING:
998 strncpy( &cmd[0], "play", 4);
1001 case PLAYLIST_PAUSED:
1002 strncpy( &cmd[0], "pause", 5);
1005 } /* var_GetInteger( p_input, "state" ) */
1006 msg_rc( STATUS_CHANGE "( %s state: %d )\r\n", &cmd[0], newval.i_int );
1007 vlc_object_release( p_playlist );
1009 vlc_object_release( p_input );
1011 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1015 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1016 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1018 intf_thread_t *p_intf = (intf_thread_t*)p_data;
1019 input_thread_t *p_input = NULL;
1021 vlc_mutex_lock( &p_intf->p_sys->status_lock );
1022 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1025 msg_rc( STATUS_CHANGE "( new rate: %d )\r\n", var_GetInteger( p_input, "rate" ) );
1026 vlc_object_release( p_input );
1028 vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1032 /********************************************************************
1034 ********************************************************************/
1035 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1036 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1038 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1039 input_thread_t *p_input;
1042 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1043 if( !p_input ) return VLC_ENOOBJ;
1045 var_Get( p_input, "state", &val );
1046 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1047 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1049 msg_rc( _("press pause to continue\r\n") );
1050 vlc_object_release( p_input );
1051 return VLC_EGENERIC;
1054 /* Parse commands that only require an input */
1055 if( !strcmp( psz_cmd, "pause" ) )
1057 val.i_int = PAUSE_S;
1059 var_Set( p_input, "state", val );
1060 vlc_object_release( p_input );
1063 else if( !strcmp( psz_cmd, "seek" ) )
1065 if( strlen( newval.psz_string ) > 0 &&
1066 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1068 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
1069 var_Set( p_input, "position", val );
1073 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1074 var_Set( p_input, "time", val );
1076 vlc_object_release( p_input );
1079 else if ( !strcmp( psz_cmd, "fastforward" ) )
1081 val.i_int = config_GetInt( p_intf, "key-jump+3sec" );
1082 var_Set( p_intf->p_vlc, "key-pressed", val );
1084 vlc_object_release( p_input );
1087 else if ( !strcmp( psz_cmd, "rewind" ) )
1089 val.i_int = config_GetInt( p_intf, "key-jump-3sec" );
1090 var_Set( p_intf->p_vlc, "key-pressed", val );
1092 vlc_object_release( p_input );
1095 else if ( !strcmp( psz_cmd, "faster" ) )
1097 val.b_bool = VLC_TRUE;
1099 var_Set( p_input, "rate-faster", val );
1100 vlc_object_release( p_input );
1103 else if ( !strcmp( psz_cmd, "slower" ) )
1105 val.b_bool = VLC_TRUE;
1107 var_Set( p_input, "rate-slower", val );
1108 vlc_object_release( p_input );
1111 else if ( !strcmp( psz_cmd, "normal" ) )
1113 val.i_int = INPUT_RATE_DEFAULT;
1115 var_Set( p_input, "rate", val );
1116 vlc_object_release( p_input );
1119 else if( !strcmp( psz_cmd, "chapter" ) ||
1120 !strcmp( psz_cmd, "chapter_n" ) ||
1121 !strcmp( psz_cmd, "chapter_p" ) )
1123 if( !strcmp( psz_cmd, "chapter" ) )
1125 if ( *newval.psz_string )
1128 val.i_int = atoi( newval.psz_string );
1129 var_Set( p_input, "chapter", val );
1133 vlc_value_t val_list;
1136 var_Get( p_input, "chapter", &val );
1137 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1139 msg_rc( "Currently playing chapter %d/%d\n",
1140 val.i_int, val_list.p_list->i_count );
1141 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1145 else if( !strcmp( psz_cmd, "chapter_n" ) )
1147 val.b_bool = VLC_TRUE;
1148 var_Set( p_input, "next-chapter", val );
1150 else if( !strcmp( psz_cmd, "chapter_p" ) )
1152 val.b_bool = VLC_TRUE;
1153 var_Set( p_input, "prev-chapter", val );
1156 vlc_object_release( p_input );
1159 else if( !strcmp( psz_cmd, "title" ) ||
1160 !strcmp( psz_cmd, "title_n" ) ||
1161 !strcmp( psz_cmd, "title_p" ) )
1163 if( !strcmp( psz_cmd, "title" ) )
1165 if ( *newval.psz_string )
1168 val.i_int = atoi( newval.psz_string );
1169 var_Set( p_input, "title", val );
1173 vlc_value_t val_list;
1176 var_Get( p_input, "title", &val );
1177 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1179 msg_rc( "Currently playing title %d/%d\n",
1180 val.i_int, val_list.p_list->i_count );
1181 var_Change( p_this, "title", VLC_VAR_FREELIST,
1185 else if( !strcmp( psz_cmd, "title_n" ) )
1187 val.b_bool = VLC_TRUE;
1188 var_Set( p_input, "next-title", val );
1190 else if( !strcmp( psz_cmd, "title_p" ) )
1192 val.b_bool = VLC_TRUE;
1193 var_Set( p_input, "prev-title", val );
1196 vlc_object_release( p_input );
1200 /* Never reached. */
1201 return VLC_EGENERIC;
1204 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1205 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1208 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1209 playlist_t *p_playlist;
1211 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1218 if( p_playlist->p_input )
1221 var_Get( p_playlist->p_input, "state", &val );
1222 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1223 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1225 msg_rc( _("press pause to continue\r\n") );
1226 vlc_object_release( p_playlist );
1227 return VLC_EGENERIC;
1231 /* Parse commands that require a playlist */
1232 if( !strcmp( psz_cmd, "prev" ) )
1234 playlist_Prev( p_playlist );
1236 else if( !strcmp( psz_cmd, "next" ) )
1238 playlist_Next( p_playlist );
1240 else if( !strcmp( psz_cmd, "play" ) )
1242 if( p_playlist->p_input )
1246 var_Get( p_playlist->p_input, "rate", &val );
1247 if( val.i_int != INPUT_RATE_DEFAULT )
1249 val.i_int = INPUT_RATE_DEFAULT;
1250 var_Set( p_playlist->p_input, "rate", val );
1254 playlist_Play( p_playlist );
1258 else if (!strcmp( psz_cmd, "goto" ) )
1260 if( strlen( newval.psz_string ) > 0)
1262 val.i_int = atoi( newval.psz_string );
1263 playlist_Goto( p_playlist, val.i_int);
1266 else if( !strcmp( psz_cmd, "stop" ) )
1268 playlist_Stop( p_playlist );
1270 else if( !strcmp( psz_cmd, "add" ) &&
1271 newval.psz_string && *newval.psz_string )
1273 playlist_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1277 msg_rc( "trying to add %s to playlist\n", newval.psz_string );
1278 playlist_AddItem( p_playlist, p_item,
1279 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
1282 else if( !strcmp( psz_cmd, "playlist" ) )
1285 for ( i = 0; i < p_playlist->i_size; i++ )
1287 msg_rc( "|%s%s %s|%s|\n", i == p_playlist->i_index ? "*" : " ",
1288 p_playlist->pp_items[i]->input.psz_name,
1289 p_playlist->pp_items[i]->input.psz_uri,
1290 p_playlist->pp_items[i]->i_parents > 0 ?
1291 p_playlist->pp_items[i]->pp_parents[0]->p_parent->input.psz_name : "" );
1295 msg_rc( "| no entries\n" );
1304 msg_rc( "unknown command!\n" );
1307 vlc_object_release( p_playlist );
1311 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1312 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1314 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1315 vlc_object_t *p_playlist;
1317 vlc_object_t *p_input;
1319 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1325 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1328 vlc_object_release( p_playlist );
1334 var_Get( p_input, "state", &val );
1335 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1336 ( strcmp( psz_cmd, "pause" ) != 0 ) )
1338 msg_rc( _("press pause to continue\r\n") );
1339 vlc_object_release( p_playlist );
1340 vlc_object_release( p_input );
1341 return VLC_EGENERIC;
1345 /* Parse miscellaneous commands */
1346 if( !strcmp( psz_cmd, "marq-marquee" ) )
1348 if( strlen( newval.psz_string ) > 0 )
1350 val.psz_string = newval.psz_string;
1351 var_Set( p_input->p_libvlc, "marq-marquee", val );
1355 val.psz_string = "";
1356 var_Set( p_input->p_libvlc, "marq-marquee", val);
1359 else if( !strcmp( psz_cmd, "marq-x" ) )
1361 if( strlen( newval.psz_string ) > 0)
1363 val.i_int = atoi( newval.psz_string );
1364 var_Set( p_input->p_libvlc, "marq-x", val );
1367 else if( !strcmp( psz_cmd, "marq-y" ) )
1369 if( strlen( newval.psz_string ) > 0)
1371 val.i_int = atoi( newval.psz_string );
1372 var_Set( p_input->p_libvlc, "marq-y", val );
1375 else if( !strcmp( psz_cmd, "marq-position" ) )
1377 if( strlen( newval.psz_string ) > 0)
1379 val.i_int = atoi( newval.psz_string );
1380 var_Set( p_input->p_libvlc, "marq-position", val );
1383 else if( !strcmp( psz_cmd, "marq-color" ) )
1385 if( strlen( newval.psz_string ) > 0)
1387 val.i_int = strtol( newval.psz_string, NULL, 0 );
1388 var_Set( p_input->p_libvlc, "marq-color", val );
1391 else if( !strcmp( psz_cmd, "marq-opacity" ) )
1393 if( strlen( newval.psz_string ) > 0)
1395 val.i_int = strtol( newval.psz_string, NULL, 0 );
1396 var_Set( p_input->p_libvlc, "marq-opacity", val );
1399 else if( !strcmp( psz_cmd, "marq-size" ) )
1401 if( strlen( newval.psz_string ) > 0)
1403 val.i_int = atoi( newval.psz_string );
1404 var_Set( p_input->p_libvlc, "marq-size", val );
1407 else if( !strcmp( psz_cmd, "marq-timeout" ) )
1409 if( strlen( newval.psz_string ) > 0)
1411 val.i_int = atoi( newval.psz_string );
1412 var_Set( p_input, "marq-timeout", val );
1415 else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1417 if( strlen( newval.psz_string ) > 0)
1419 val.i_int = atoi( newval.psz_string );
1420 var_Set( p_input->p_libvlc, "mosaic-alpha", val );
1423 else if( !strcmp( psz_cmd, "mosaic-height" ) )
1425 if( strlen( newval.psz_string ) > 0)
1427 val.i_int = atoi( newval.psz_string );
1428 var_Set( p_input->p_libvlc, "mosaic-height", val );
1431 else if( !strcmp( psz_cmd, "mosaic-width" ) )
1433 if( strlen( newval.psz_string ) > 0)
1435 val.i_int = atoi( newval.psz_string );
1436 var_Set( p_input->p_libvlc, "mosaic-width", val );
1439 else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1441 if( strlen( newval.psz_string ) > 0)
1443 val.i_int = atoi( newval.psz_string );
1444 var_Set( p_input->p_libvlc, "mosaic-xoffset", val );
1447 else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1449 if( strlen( newval.psz_string ) > 0)
1451 val.i_int = atoi( newval.psz_string );
1452 var_Set( p_input->p_libvlc, "mosaic-yoffset", val );
1455 else if( !strcmp( psz_cmd, "mosaic-align" ) )
1457 if( strlen( newval.psz_string ) > 0 )
1459 val.i_int = atoi( newval.psz_string );
1460 var_Set( p_input->p_libvlc, "mosaic-align", val );
1463 else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1465 if( strlen( newval.psz_string ) > 0)
1467 val.i_int = atoi( newval.psz_string );
1468 var_Set( p_input->p_libvlc, "mosaic-vborder", val );
1471 else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1473 if( strlen( newval.psz_string ) > 0)
1475 val.i_int = atoi( newval.psz_string );
1476 var_Set( p_input->p_libvlc, "mosaic-hborder", val );
1479 else if( !strcmp( psz_cmd, "mosaic-position" ) )
1481 if( strlen( newval.psz_string ) > 0)
1483 val.i_int = atoi( newval.psz_string );
1484 var_Set( p_input->p_libvlc, "mosaic-position", val );
1487 else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1489 if( strlen( newval.psz_string ) > 0)
1491 val.i_int = atoi( newval.psz_string );
1492 var_Set( p_input->p_libvlc, "mosaic-rows", val );
1495 else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1497 if( strlen( newval.psz_string ) > 0)
1499 val.i_int = atoi( newval.psz_string );
1500 var_Set( p_input->p_libvlc, "mosaic-cols", val );
1503 else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1505 if( strlen( newval.psz_string ) > 0)
1507 val.i_int = atoi( newval.psz_string );
1508 var_Set( p_input->p_libvlc, "mosaic-keep-aspect-ratio", val );
1511 else if( !strcmp( psz_cmd, "time-format" ) )
1513 if( strlen( newval.psz_string ) > 0 )
1515 val.psz_string = newval.psz_string;
1516 var_Set( p_input->p_libvlc, "time-format", val );
1520 val.psz_string = "";
1521 var_Set( p_input->p_libvlc, "time-format", val);
1524 else if( !strcmp( psz_cmd, "time-x" ) )
1526 if( strlen( newval.psz_string ) > 0)
1528 val.i_int = atoi( newval.psz_string );
1529 var_Set( p_input->p_libvlc, "time-x", val );
1532 else if( !strcmp( psz_cmd, "time-y" ) )
1534 if( strlen( newval.psz_string ) > 0)
1536 val.i_int = atoi( newval.psz_string );
1537 var_Set( p_input->p_libvlc, "time-y", val );
1540 else if( !strcmp( psz_cmd, "time-position" ) )
1542 if( strlen( newval.psz_string ) > 0)
1544 val.i_int = atoi( newval.psz_string );
1545 var_Set( p_input->p_libvlc, "time-position", val );
1548 else if( !strcmp( psz_cmd, "time-color" ) )
1550 if( strlen( newval.psz_string ) > 0)
1552 val.i_int = strtol( newval.psz_string, NULL, 0 );
1553 var_Set( p_input->p_libvlc, "time-color", val );
1556 else if( !strcmp( psz_cmd, "time-opacity" ) )
1558 if( strlen( newval.psz_string ) > 0)
1560 val.i_int = strtol( newval.psz_string, NULL, 0 );
1561 var_Set( p_input->p_libvlc, "time-opacity", val );
1564 else if( !strcmp( psz_cmd, "time-size" ) )
1566 if( strlen( newval.psz_string ) > 0)
1568 val.i_int = atoi( newval.psz_string );
1569 var_Set( p_input->p_libvlc, "time-size", val );
1572 else if( !strcmp( psz_cmd, "logo-file" ) )
1574 if( strlen( newval.psz_string ) > 0 )
1576 val.psz_string = newval.psz_string;
1577 var_Set( p_input->p_libvlc, "logo-file", val );
1580 else if( !strcmp( psz_cmd, "logo-x" ) )
1582 if( strlen( newval.psz_string ) > 0)
1584 val.i_int = atoi( newval.psz_string );
1585 var_Set( p_input->p_libvlc, "logo-x", val );
1588 else if( !strcmp( psz_cmd, "logo-y" ) )
1590 if( strlen( newval.psz_string ) > 0)
1592 val.i_int = atoi( newval.psz_string );
1593 var_Set( p_input->p_libvlc, "logo-y", val );
1596 else if( !strcmp( psz_cmd, "logo-position" ) )
1598 if( strlen( newval.psz_string ) > 0)
1600 val.i_int = atoi( newval.psz_string );
1601 var_Set( p_input->p_libvlc, "logo-position", val );
1604 else if( !strcmp( psz_cmd, "logo-transparency" ) )
1606 if( strlen( newval.psz_string ) > 0)
1608 val.i_int = strtol( newval.psz_string, NULL, 0 );
1609 var_Set( p_input->p_libvlc, "logo-transparency", val );
1618 msg_rc( "unknown command!\n" );
1621 vlc_object_release( p_playlist );
1622 vlc_object_release( p_input );
1626 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1627 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1629 playlist_t *p_playlist;
1631 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1634 playlist_Stop( p_playlist );
1635 vlc_object_release( p_playlist );
1637 p_this->p_vlc->b_die = VLC_TRUE;
1641 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1642 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1644 intf_thread_t *p_newintf;
1646 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
1650 p_newintf->b_block = VLC_FALSE;
1651 if( intf_RunThread( p_newintf ) )
1653 vlc_object_detach( p_newintf );
1654 intf_Destroy( p_newintf );
1661 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1662 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1664 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1667 if ( *newval.psz_string )
1670 audio_volume_t i_volume = atoi( newval.psz_string );
1671 if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1673 msg_rc( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
1675 i_error = VLC_EBADVAR;
1679 if( i_volume == AOUT_VOLUME_MIN )
1683 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1684 var_Set( p_intf->p_vlc, "key-pressed", keyval );
1686 i_error = aout_VolumeSet( p_this, i_volume );
1692 audio_volume_t i_volume;
1693 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1695 i_error = VLC_EGENERIC;
1699 msg_rc( STATUS_CHANGE "( audio volume: %d )\r\n", i_volume );
1700 i_error = VLC_SUCCESS;
1707 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1708 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1710 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1711 audio_volume_t i_volume;
1712 int i_nb_steps = atoi(newval.psz_string);
1713 int i_error = VLC_SUCCESS;
1715 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
1720 if ( !strcmp(psz_cmd, "volup") )
1722 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1723 i_error = VLC_EGENERIC;
1724 osd_VolumeUp( p_this );
1728 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1729 i_error = VLC_EGENERIC;
1730 osd_VolumeDown( p_this );
1733 if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )\r\n", i_volume );
1737 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1738 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1740 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1741 aout_instance_t * p_aout;
1742 const char * psz_variable;
1743 vlc_value_t val_name;
1746 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1747 if ( p_aout == NULL ) return VLC_ENOOBJ;
1749 if ( !strcmp( psz_cmd, "adev" ) )
1751 psz_variable = "audio-device";
1755 psz_variable = "audio-channels";
1758 /* Get the descriptive name of the variable */
1759 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1761 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1763 if ( !*newval.psz_string )
1765 /* Retrieve all registered ***. */
1766 vlc_value_t val, text;
1769 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1771 vlc_object_release( (vlc_object_t *)p_aout );
1772 return VLC_EGENERIC;
1774 i_value = val.i_int;
1776 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1777 VLC_VAR_GETLIST, &val, &text ) < 0 )
1779 vlc_object_release( (vlc_object_t *)p_aout );
1780 return VLC_EGENERIC;
1783 msg_rc( "+----[ %s ]\n", val_name.psz_string );
1784 for ( i = 0; i < val.p_list->i_count; i++ )
1786 if ( i_value == val.p_list->p_values[i].i_int )
1787 msg_rc( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1788 text.p_list->p_values[i].psz_string );
1790 msg_rc( "| %i - %s\n", val.p_list->p_values[i].i_int,
1791 text.p_list->p_values[i].psz_string );
1793 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1795 msg_rc( "+----[ end of %s ]\n", val_name.psz_string );
1797 if( val_name.psz_string ) free( val_name.psz_string );
1798 i_error = VLC_SUCCESS;
1803 val.i_int = atoi( newval.psz_string );
1805 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1807 vlc_object_release( (vlc_object_t *)p_aout );
1812 /* OSD menu commands */
1813 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1814 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1816 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1817 playlist_t *p_playlist = NULL;
1819 int i_error = VLC_EGENERIC;
1821 if ( !*newval.psz_string )
1823 msg_rc( "please provide one of the following paramaters\r\n[on|off|up|down|left|right|select]\r\n" );
1827 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1831 if( p_playlist->p_input )
1833 var_Get( p_playlist->p_input, "state", &val );
1834 if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1835 ( strcmp( newval.psz_string, "select" ) != 0 ) )
1837 msg_rc( _("press menu select to continue\r\n") );
1838 vlc_object_release( p_playlist );
1839 return VLC_EGENERIC;
1841 vlc_object_release( p_playlist );
1844 val.psz_string = strdup( newval.psz_string );
1845 if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1846 osd_MenuShow( p_this );
1847 else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1848 osd_MenuHide( p_this );
1849 else if( !strcmp( val.psz_string, "up" ) )
1850 osd_MenuUp( p_this );
1851 else if( !strcmp( val.psz_string, "down" ) )
1852 osd_MenuDown( p_this );
1853 else if( !strcmp( val.psz_string, "left" ) )
1854 osd_MenuPrev( p_this );
1855 else if( !strcmp( val.psz_string, "right" ) )
1856 osd_MenuNext( p_this );
1857 else if( !strcmp( val.psz_string, "select" ) )
1858 osd_MenuActivate( p_this );
1861 msg_rc( "please provide one of the following paramaters\r\n[on|off|up|down|left|right|select]\r\n" );
1862 if( val.psz_string ) free( val.psz_string );
1866 i_error = VLC_SUCCESS;
1867 if( val.psz_string ) free( val.psz_string );
1872 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1874 INPUT_RECORD input_record;
1877 /* On Win32, select() only works on socket descriptors */
1878 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1879 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1881 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1882 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1885 if( input_record.EventType != KEY_EVENT ||
1886 !input_record.Event.KeyEvent.bKeyDown ||
1887 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1888 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1889 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1890 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1892 /* nothing interesting */
1896 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1898 /* Echo out the command */
1899 putc( p_buffer[ *pi_size ], stdout );
1901 /* Handle special keys */
1902 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1904 putc( '\n', stdout );
1907 switch( p_buffer[ *pi_size ] )
1913 putc( ' ', stdout );
1914 putc( '\b', stdout );
1925 if( *pi_size == MAX_LINE_LENGTH ||
1926 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1928 p_buffer[ *pi_size ] = 0;
1937 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1942 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1943 return ReadWin32( p_intf, p_buffer, pi_size );
1944 else if( p_intf->p_sys->i_socket == -1 )
1946 msleep( INTF_IDLE_SLEEP );
1951 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1952 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1953 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1954 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1956 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1962 /* Connection closed */
1965 p_intf->p_sys->i_socket = -1;
1966 p_buffer[ *pi_size ] = 0;
1970 if( *pi_size == MAX_LINE_LENGTH ||
1971 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1973 p_buffer[ *pi_size ] = 0;
1980 /*****************************************************************************
1981 * parse_MRL: build a playlist item from a full mrl
1982 *****************************************************************************
1983 * MRL format: "simplified-mrl [:option-name[=option-value]]"
1984 * We don't check for '"' or '\'', we just assume that a ':' that follows a
1985 * space is a new option. Should be good enough for our purpose.
1986 *****************************************************************************/
1987 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
1989 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
1990 #define SKIPTRAILINGSPACE( p, d ) \
1991 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
1993 playlist_item_t *p_item = NULL;
1994 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
1995 char **ppsz_options = NULL;
1996 int i, i_options = 0;
1998 if( !psz_mrl ) return 0;
2000 psz_mrl = psz_orig = strdup( psz_mrl );
2003 SKIPSPACE( psz_mrl );
2006 for( ; *psz_mrl; psz_mrl++ )
2008 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2010 /* We have a complete item */
2013 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2014 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2016 /* We have a complete item */
2021 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2022 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2024 /* Remove '"' and '\'' if necessary */
2025 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2026 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2027 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2028 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2030 if( !psz_item_mrl ) psz_item_mrl = psz_item;
2031 else if( *psz_item )
2034 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2035 ppsz_options[i_options - 1] = &psz_item[1];
2038 if( *psz_mrl ) SKIPSPACE( psz_mrl );
2041 /* Now create a playlist item */
2044 p_item = playlist_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
2045 for( i = 0; i < i_options; i++ )
2047 playlist_ItemAddOption( p_item, ppsz_options[i] );
2051 if( i_options ) free( ppsz_options );