1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 - 2005 VideoLAN (Centrale Réseaux) and its contributors
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <errno.h> /* ENOMEM */
44 #ifdef HAVE_SYS_TIME_H
45 # include <sys/time.h>
47 #include <sys/types.h>
49 #include "vlc_error.h"
52 #if defined(AF_UNIX) && !defined(AF_LOCAL)
53 # define AF_LOCAL AF_UNIX
56 #if defined(AF_LOCAL) && ! defined(WIN32)
60 #define MAX_LINE_LENGTH 256
62 /*****************************************************************************
64 *****************************************************************************/
65 static int Activate ( vlc_object_t * );
66 static void Deactivate ( vlc_object_t * );
67 static void Run ( intf_thread_t * );
69 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
71 static playlist_item_t *parse_MRL( intf_thread_t *, char * );
73 static int Input ( vlc_object_t *, char const *,
74 vlc_value_t, vlc_value_t, void * );
75 static int Playlist ( vlc_object_t *, char const *,
76 vlc_value_t, vlc_value_t, void * );
77 static int Other ( vlc_object_t *, char const *,
78 vlc_value_t, vlc_value_t, void * );
79 static int Quit ( vlc_object_t *, char const *,
80 vlc_value_t, vlc_value_t, void * );
81 static int Intf ( vlc_object_t *, char const *,
82 vlc_value_t, vlc_value_t, void * );
83 static int Volume ( vlc_object_t *, char const *,
84 vlc_value_t, vlc_value_t, void * );
85 static int VolumeMove ( vlc_object_t *, char const *,
86 vlc_value_t, vlc_value_t, void * );
87 static int AudioConfig ( vlc_object_t *, char const *,
88 vlc_value_t, vlc_value_t, void * );
92 int *pi_socket_listen;
102 #ifdef HAVE_VARIADIC_MACROS
103 # define msg_rc( psz_format, args... ) \
104 __msg_rc( p_intf, psz_format, ## args )
107 void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
110 va_start( args, psz_fmt );
111 if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
113 { net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
114 net_Printf( VLC_OBJECT(p_intf), p_intf->p_sys->i_socket, NULL, "\r" ); }
118 /*****************************************************************************
120 *****************************************************************************/
121 #define POS_TEXT N_("Show stream position")
122 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
123 "stream from time to time." )
125 #define TTY_TEXT N_("Fake TTY")
126 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
128 #define UNIX_TEXT N_("UNIX socket command input")
129 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
132 #define HOST_TEXT N_("TCP command input")
133 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
134 "You can set the address and port the interface will bind to." )
137 #define QUIET_TEXT N_("Do not open a DOS command box interface")
138 #define QUIET_LONGTEXT N_( \
139 "By default the rc interface plugin will start a DOS command box. " \
140 "Enabling the quiet mode will not bring this command box but can also " \
141 "be pretty annoying when you want to stop VLC and no video window is " \
146 set_shortname( _("RC"));
147 set_category( CAT_INTERFACE );
148 set_subcategory( SUBCAT_INTERFACE_GENERAL );
149 set_description( _("Remote control interface") );
150 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
152 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
154 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
155 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
158 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
161 set_capability( "interface", 20 );
162 set_callbacks( Activate, Deactivate );
165 /*****************************************************************************
166 * Activate: initialize and create stuff
167 *****************************************************************************/
168 static int Activate( vlc_object_t *p_this )
170 intf_thread_t *p_intf = (intf_thread_t*)p_this;
171 playlist_t *p_playlist;
172 char *psz_host, *psz_unix_path;
173 int *pi_socket = NULL;
175 #if defined(HAVE_ISATTY) && !defined(WIN32)
176 /* Check that stdin is a TTY */
177 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
179 msg_Warn( p_intf, "fd 0 is not a TTY" );
184 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
189 #if !defined(AF_LOCAL) || defined(WIN32)
190 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
191 free( psz_unix_path );
194 struct sockaddr_un addr;
197 memset( &addr, 0, sizeof(struct sockaddr_un) );
199 msg_Dbg( p_intf, "trying UNIX socket" );
201 if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
203 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
204 free( psz_unix_path );
208 addr.sun_family = AF_LOCAL;
209 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
210 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
212 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
213 sizeof(struct sockaddr_un) ) ) < 0 )
215 msg_Warn( p_intf, "couldn't bind socket to address: %s",
217 free( psz_unix_path );
218 net_Close( i_socket );
222 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
224 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
225 free( psz_unix_path );
226 net_Close( i_socket );
230 /* FIXME: we need a core function to merge listening sockets sets */
231 pi_socket = calloc( 2, sizeof( int ) );
232 if( pi_socket == NULL )
234 free( psz_unix_path );
235 net_Close( i_socket );
238 pi_socket[0] = i_socket;
243 if( ( pi_socket == NULL ) &&
244 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
248 vlc_UrlParse( &url, psz_host, 0 );
250 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
252 pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
253 if( pi_socket == NULL )
255 msg_Warn( p_intf, "can't listen to %s port %i",
256 url.psz_host, url.i_port );
257 vlc_UrlClean( &url );
262 vlc_UrlClean( &url );
266 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
269 msg_Err( p_intf, "no memory" );
273 p_intf->p_sys->pi_socket_listen = pi_socket;
274 p_intf->p_sys->i_socket = -1;
275 p_intf->p_sys->psz_unix_path = psz_unix_path;
277 /* Non-buffered stdout */
278 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
280 p_intf->pf_run = Run;
283 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
284 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
289 /* Force "no-view" mode */
290 p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
294 vlc_mutex_lock( &p_playlist->object_lock );
295 p_playlist->status.i_view = -1;
296 vlc_mutex_unlock( &p_playlist->object_lock );
297 vlc_object_release( p_playlist );
300 msg_rc( _("Remote control interface initialized, `h' for help\n") );
304 /*****************************************************************************
305 * Deactivate: uninitialize and cleanup
306 *****************************************************************************/
307 static void Deactivate( vlc_object_t *p_this )
309 intf_thread_t *p_intf = (intf_thread_t*)p_this;
311 net_ListenClose( p_intf->p_sys->pi_socket_listen );
312 if( p_intf->p_sys->i_socket != -1 )
313 net_Close( p_intf->p_sys->i_socket );
314 if( p_intf->p_sys->psz_unix_path != NULL )
316 #if defined(AF_LOCAL) && !defined(WIN32)
317 unlink( p_intf->p_sys->psz_unix_path );
319 free( p_intf->p_sys->psz_unix_path );
321 free( p_intf->p_sys );
324 /*****************************************************************************
326 *****************************************************************************
327 * This part of the interface is in a separate thread so that we can call
328 * exec() from within it without annoying the rest of the program.
329 *****************************************************************************/
330 static void Run( intf_thread_t *p_intf )
332 input_thread_t * p_input;
333 playlist_t * p_playlist;
335 char p_buffer[ MAX_LINE_LENGTH + 1 ];
336 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
337 vlc_bool_t b_longhelp = VLC_FALSE;
347 /* Register commands that will be cleaned up upon object destruction */
348 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
349 var_AddCallback( p_intf, "quit", Quit, NULL );
350 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
351 var_AddCallback( p_intf, "intf", Intf, NULL );
353 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
354 var_AddCallback( p_intf, "add", Playlist, NULL );
355 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
356 var_AddCallback( p_intf, "playlist", Playlist, NULL );
357 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
358 var_AddCallback( p_intf, "play", Playlist, NULL );
359 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
360 var_AddCallback( p_intf, "stop", Playlist, NULL );
361 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
362 var_AddCallback( p_intf, "prev", Playlist, NULL );
363 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
364 var_AddCallback( p_intf, "next", Playlist, NULL );
365 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
366 var_AddCallback( p_intf, "goto", Playlist, NULL );
368 /* marquee on the fly items */
369 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
370 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
371 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
372 var_AddCallback( p_intf, "marq-x", Other, NULL );
373 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
374 var_AddCallback( p_intf, "marq-y", Other, NULL );
375 var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
376 var_AddCallback( p_intf, "marq-position", Other, NULL );
377 var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
378 var_AddCallback( p_intf, "marq-color", Other, NULL );
379 var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
380 var_AddCallback( p_intf, "marq-opacity", Other, NULL );
381 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
382 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
383 var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
384 var_AddCallback( p_intf, "marq-size", Other, NULL );
386 var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
387 var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
388 var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
389 var_AddCallback( p_intf, "mosaic-height", Other, NULL );
390 var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
391 var_AddCallback( p_intf, "mosaic-width", Other, NULL );
392 var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
393 var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
394 var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
395 var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
396 var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
397 var_AddCallback( p_intf, "mosaic-align", Other, NULL );
398 var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
399 var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
400 var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
401 var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
402 var_Create( p_intf, "mosaic-position",
403 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
404 var_AddCallback( p_intf, "mosaic-position", Other, NULL );
405 var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
406 var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
407 var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
408 var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
409 var_Create( p_intf, "mosaic-keep-aspect-ratio",
410 VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
411 var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
413 /* time on the fly items */
414 var_Create( p_intf, "time-format", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
415 var_AddCallback( p_intf, "time-format", Other, NULL );
416 var_Create( p_intf, "time-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
417 var_AddCallback( p_intf, "time-x", Other, NULL );
418 var_Create( p_intf, "time-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
419 var_AddCallback( p_intf, "time-y", Other, NULL );
420 var_Create( p_intf, "time-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
421 var_AddCallback( p_intf, "time-position", Other, NULL );
422 var_Create( p_intf, "time-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
423 var_AddCallback( p_intf, "time-color", Other, NULL );
424 var_Create( p_intf, "time-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
425 var_AddCallback( p_intf, "time-opacity", Other, NULL );
426 var_Create( p_intf, "time-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
427 var_AddCallback( p_intf, "time-size", Other, NULL );
429 /* logo on the fly items */
430 var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
431 var_AddCallback( p_intf, "logo-file", Other, NULL );
432 var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
433 var_AddCallback( p_intf, "logo-x", Other, NULL );
434 var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
435 var_AddCallback( p_intf, "logo-y", Other, NULL );
436 var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
437 var_AddCallback( p_intf, "logo-position", Other, NULL );
438 var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
439 var_AddCallback( p_intf, "logo-transparency", Other, NULL );
442 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
443 var_AddCallback( p_intf, "pause", Input, NULL );
444 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
445 var_AddCallback( p_intf, "seek", Input, NULL );
446 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
447 var_AddCallback( p_intf, "title", Input, NULL );
448 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
449 var_AddCallback( p_intf, "title_n", Input, NULL );
450 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
451 var_AddCallback( p_intf, "title_p", Input, NULL );
452 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
453 var_AddCallback( p_intf, "chapter", Input, NULL );
454 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
455 var_AddCallback( p_intf, "chapter_n", Input, NULL );
456 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
457 var_AddCallback( p_intf, "chapter_p", Input, NULL );
459 var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
460 var_AddCallback( p_intf, "fastforward", Input, NULL );
461 var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
462 var_AddCallback( p_intf, "rewind", Input, NULL );
464 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
465 var_AddCallback( p_intf, "volume", Volume, NULL );
466 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
467 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
468 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
469 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
470 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
471 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
472 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
473 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
476 /* Get the file descriptor of the console input */
477 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
478 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
480 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
481 p_intf->b_die = VLC_TRUE;
485 while( !p_intf->b_die )
487 char *psz_cmd, *psz_arg;
488 vlc_bool_t b_complete;
490 if( p_intf->p_sys->pi_socket_listen != NULL &&
491 p_intf->p_sys->i_socket == -1 )
493 p_intf->p_sys->i_socket =
494 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
497 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
499 /* Manage the input part */
500 if( p_input == NULL )
504 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
509 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
513 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
518 else if( p_input->b_dead )
520 vlc_object_release( p_input );
524 if( p_input && b_showpos )
526 i_newpos = 100 * var_GetFloat( p_input, "position" );
527 if( i_oldpos != i_newpos )
530 msg_rc( "pos: %d%%\n", i_newpos );
534 /* Is there something to do? */
535 if( !b_complete ) continue;
538 /* Skip heading spaces */
540 while( *psz_cmd == ' ' )
545 /* Split psz_cmd at the first space and make sure that
546 * psz_arg is valid */
547 psz_arg = strchr( psz_cmd, ' ' );
551 while( *psz_arg == ' ' )
561 /* If the user typed a registered local command, try it */
562 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
567 val.psz_string = psz_arg;
568 i_ret = var_Set( p_intf, psz_cmd, val );
569 msg_rc( "%s: returned %i (%s)\n",
570 psz_cmd, i_ret, vlc_error( i_ret ) );
572 /* Or maybe it's a global command */
573 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
578 val.psz_string = psz_arg;
579 /* FIXME: it's a global command, but we should pass the
580 * local object as an argument, not p_intf->p_libvlc. */
581 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
584 msg_rc( "%s: returned %i (%s)\n",
585 psz_cmd, i_ret, vlc_error( i_ret ) );
588 else if( !strcmp( psz_cmd, "logout" ) )
590 /* Close connection */
591 if( p_intf->p_sys->i_socket != -1 )
593 net_Close( p_intf->p_sys->i_socket );
595 p_intf->p_sys->i_socket = -1;
597 else if( !strcmp( psz_cmd, "info" ) )
602 vlc_mutex_lock( &p_input->input.p_item->lock );
603 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
605 info_category_t *p_category =
606 p_input->input.p_item->pp_categories[i];
608 msg_rc( "+----[ %s ]\n", p_category->psz_name );
610 for ( j = 0; j < p_category->i_infos; j++ )
612 info_t *p_info = p_category->pp_infos[j];
613 msg_rc( "| %s: %s\n", p_info->psz_name,
618 msg_rc( "+----[ end of stream info ]\n" );
619 vlc_mutex_unlock( &p_input->input.p_item->lock );
623 msg_rc( "no input\n" );
626 else if( !strcmp( psz_cmd, "is_playing" ) )
637 else if( !strcmp( psz_cmd, "get_time" ) )
646 var_Get( p_input, "time", &time );
647 msg_rc( "%i\n", time.i_time / 1000000);
650 else if( !strcmp( psz_cmd, "get_length" ) )
659 var_Get( p_input, "length", &time );
660 msg_rc( "%i\n", time.i_time / 1000000);
663 else if( !strcmp( psz_cmd, "get_title" ) )
671 msg_rc( "%s\n", p_input->input.p_item->psz_name );
674 else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
675 || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
677 if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
678 b_longhelp = VLC_TRUE;
679 else b_longhelp = VLC_FALSE;
681 msg_rc(_("+----[ Remote control commands ]\n"));
683 msg_rc(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
684 msg_rc(_("| playlist . . . show items currently in playlist\n"));
685 msg_rc(_("| play . . . . . . . . . . . . . . . . play stream\n"));
686 msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
687 msg_rc(_("| next . . . . . . . . . . . . next playlist item\n"));
688 msg_rc(_("| prev . . . . . . . . . . previous playlist item\n"));
689 msg_rc(_("| goto . . . . . . . . . . . . goto item at index\n"));
690 msg_rc(_("| title [X] . . . . set/get title in current item\n"));
691 msg_rc(_("| title_n . . . . . . next title in current item\n"));
692 msg_rc(_("| title_p . . . . previous title in current item\n"));
693 msg_rc(_("| chapter [X] . . set/get chapter in current item\n"));
694 msg_rc(_("| chapter_n . . . . next chapter in current item\n"));
695 msg_rc(_("| chapter_p . . previous chapter in current item\n"));
697 msg_rc(_("| seek X . seek in seconds, for instance `seek 12'\n"));
698 msg_rc(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
699 msg_rc(_("| fastforward . . . . . . . set to maximum rate\n"));
700 msg_rc(_("| rewind . . . . . . . . . . set to minimum rate\n"));
701 msg_rc(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
702 msg_rc(_("| info . . . information about the current stream\n"));
704 msg_rc(_("| volume [X] . . . . . . . . set/get audio volume\n"));
705 msg_rc(_("| volup [X] . . . . . raise audio volume X steps\n"));
706 msg_rc(_("| voldown [X] . . . . lower audio volume X steps\n"));
707 msg_rc(_("| adev [X] . . . . . . . . . set/get audio device\n"));
708 msg_rc(_("| achan [X]. . . . . . . . set/get audio channels\n"));
713 msg_rc(_("| marq-marquee STRING . . overlay STRING in video\n"));
714 msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left\n"));
715 msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top\n"));
716 msg_rc(_("| marq-position #. . . .relative position control\n"));
717 msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB\n"));
718 msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity\n"));
719 msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms\n"));
720 msg_rc(_("| marq-size # . . . . . . . . font size, in pixels\n"));
722 msg_rc(_("| time-format STRING . . . overlay STRING in video\n"));
723 msg_rc(_("| time-x X . . . . . . . . . . . .offset from left\n"));
724 msg_rc(_("| time-y Y . . . . . . . . . . . . offset from top\n"));
725 msg_rc(_("| time-position #. . . . . . . . relative position\n"));
726 msg_rc(_("| time-color # . . . . . . . . . . font color, RGB\n"));
727 msg_rc(_("| time-opacity # . . . . . . . . . . . . . opacity\n"));
728 msg_rc(_("| time-size # . . . . . . . . font size, in pixels\n"));
730 msg_rc(_("| logo-file STRING . . . the overlay file path/name\n"));
731 msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left\n"));
732 msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top\n"));
733 msg_rc(_("| logo-position #. . . . . . . . relative position\n"));
734 msg_rc(_("| logo-transparency #. . . . . . . . .transparency\n"));
736 msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha\n"));
737 msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height\n"));
738 msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width\n"));
739 msg_rc(_("| mosaic-xoffset # . . . .top left corner position\n"));
740 msg_rc(_("| mosaic-yoffset # . . . .top left corner position\n"));
741 msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment\n"));
742 msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border\n"));
743 msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border\n"));
744 msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position\n"));
745 msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows\n"));
746 msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols\n"));
747 msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio\n"));
750 msg_rc(_("| help . . . . . . . . . . . . . this help message\n"));
751 msg_rc(_("| longhelp . . . . . . . . . a longer help message\n"));
752 msg_rc(_("| logout . . . . . exit (if in socket connection)\n"));
753 msg_rc(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
755 msg_rc(_("+----[ end of help ]\n"));
757 else switch( psz_cmd[0] )
763 vout_thread_t *p_vout;
764 p_vout = vlc_object_find( p_input,
765 VLC_OBJECT_VOUT, FIND_CHILD );
769 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
770 vlc_object_release( p_vout );
781 /* Ignore empty lines */
785 msg_rc(_("unknown command `%s', type `help' for help\n"), psz_cmd);
789 /* Command processed */
790 i_size = 0; p_buffer[0] = 0;
795 vlc_object_release( p_input );
801 vlc_object_release( p_playlist );
806 static int Input( vlc_object_t *p_this, char const *psz_cmd,
807 vlc_value_t oldval, vlc_value_t newval, void *p_data )
809 intf_thread_t *p_intf = (intf_thread_t*)p_this;
810 input_thread_t *p_input;
813 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
814 if( !p_input ) return VLC_ENOOBJ;
816 /* Parse commands that only require an input */
817 if( !strcmp( psz_cmd, "pause" ) )
821 var_Set( p_input, "state", val );
822 vlc_object_release( p_input );
825 else if( !strcmp( psz_cmd, "seek" ) )
827 if( strlen( newval.psz_string ) > 0 &&
828 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
830 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
831 var_Set( p_input, "position", val );
835 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
836 var_Set( p_input, "time", val );
838 vlc_object_release( p_input );
841 else if ( !strcmp( psz_cmd, "fastforward" ) )
843 val.i_int = INPUT_RATE_MAX;
845 var_Set( p_input, "rate", val );
846 vlc_object_release( p_input );
849 else if ( !strcmp( psz_cmd, "rewind" ) )
851 val.i_int = INPUT_RATE_MIN;
853 var_Set( p_input, "rate", val );
854 vlc_object_release( p_input );
857 else if( !strcmp( psz_cmd, "chapter" ) ||
858 !strcmp( psz_cmd, "chapter_n" ) ||
859 !strcmp( psz_cmd, "chapter_p" ) )
861 if( !strcmp( psz_cmd, "chapter" ) )
863 if ( *newval.psz_string )
866 val.i_int = atoi( newval.psz_string );
867 var_Set( p_input, "chapter", val );
871 vlc_value_t val_list;
874 var_Get( p_input, "chapter", &val );
875 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
877 msg_rc( "Currently playing chapter %d/%d\n",
878 val.i_int, val_list.p_list->i_count );
879 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
883 else if( !strcmp( psz_cmd, "chapter_n" ) )
885 val.b_bool = VLC_TRUE;
886 var_Set( p_input, "next-chapter", val );
888 else if( !strcmp( psz_cmd, "chapter_p" ) )
890 val.b_bool = VLC_TRUE;
891 var_Set( p_input, "prev-chapter", val );
894 vlc_object_release( p_input );
897 else if( !strcmp( psz_cmd, "title" ) ||
898 !strcmp( psz_cmd, "title_n" ) ||
899 !strcmp( psz_cmd, "title_p" ) )
901 if( !strcmp( psz_cmd, "title" ) )
903 if ( *newval.psz_string )
906 val.i_int = atoi( newval.psz_string );
907 var_Set( p_input, "title", val );
911 vlc_value_t val_list;
914 var_Get( p_input, "title", &val );
915 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
917 msg_rc( "Currently playing title %d/%d\n",
918 val.i_int, val_list.p_list->i_count );
919 var_Change( p_this, "title", VLC_VAR_FREELIST,
923 else if( !strcmp( psz_cmd, "title_n" ) )
925 val.b_bool = VLC_TRUE;
926 var_Set( p_input, "next-title", val );
928 else if( !strcmp( psz_cmd, "title_p" ) )
930 val.b_bool = VLC_TRUE;
931 var_Set( p_input, "prev-title", val );
934 vlc_object_release( p_input );
942 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
943 vlc_value_t oldval, vlc_value_t newval, void *p_data )
946 intf_thread_t *p_intf = (intf_thread_t*)p_this;
947 playlist_t *p_playlist;
949 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
956 /* Parse commands that require a playlist */
957 if( !strcmp( psz_cmd, "prev" ) )
959 playlist_Prev( p_playlist );
961 else if( !strcmp( psz_cmd, "next" ) )
963 playlist_Next( p_playlist );
965 else if( !strcmp( psz_cmd, "play" ) )
967 playlist_Play( p_playlist );
969 else if (!strcmp( psz_cmd, "goto" ) )
971 if( strlen( newval.psz_string ) > 0)
973 val.i_int = atoi( newval.psz_string );
974 playlist_Goto( p_playlist, val.i_int);
977 else if( !strcmp( psz_cmd, "stop" ) )
979 playlist_Stop( p_playlist );
981 else if( !strcmp( psz_cmd, "add" ) &&
982 newval.psz_string && *newval.psz_string )
984 playlist_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
988 msg_rc( "trying to add %s to playlist\n", newval.psz_string );
989 playlist_AddItem( p_playlist, p_item,
990 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
993 else if( !strcmp( psz_cmd, "playlist" ) )
996 for ( i = 0; i < p_playlist->i_size; i++ )
998 msg_rc( "|%s%s %s|%s|\n", i == p_playlist->i_index ? "*" : " ",
999 p_playlist->pp_items[i]->input.psz_name,
1000 p_playlist->pp_items[i]->input.psz_uri,
1001 p_playlist->pp_items[i]->i_parents > 0 ?
1002 p_playlist->pp_items[i]->pp_parents[0]->p_parent->input.psz_name : "" );
1006 msg_rc( "| no entries\n" );
1015 msg_rc( "unknown command!\n" );
1018 vlc_object_release( p_playlist );
1022 static int Other( vlc_object_t *p_this, char const *psz_cmd,
1023 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1025 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1028 vlc_object_t *p_inp;
1030 p_pl = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
1037 p_inp = vlc_object_find( p_this, VLC_OBJECT_INPUT,
1044 /* Parse miscellaneous commands */
1045 if( !strcmp( psz_cmd, "marq-marquee" ) )
1047 if( strlen( newval.psz_string ) > 0 )
1049 val.psz_string = newval.psz_string;
1050 var_Set( p_inp->p_libvlc, "marq-marquee", val );
1054 val.psz_string = "";
1055 var_Set( p_inp->p_libvlc, "marq-marquee", val);
1058 else if( !strcmp( psz_cmd, "marq-x" ) )
1060 if( strlen( newval.psz_string ) > 0)
1062 val.i_int = atoi( newval.psz_string );
1063 var_Set( p_inp->p_libvlc, "marq-x", val );
1066 else if( !strcmp( psz_cmd, "marq-y" ) )
1068 if( strlen( newval.psz_string ) > 0)
1070 val.i_int = atoi( newval.psz_string );
1071 var_Set( p_inp->p_libvlc, "marq-y", val );
1074 else if( !strcmp( psz_cmd, "marq-position" ) )
1076 if( strlen( newval.psz_string ) > 0)
1078 val.i_int = atoi( newval.psz_string );
1079 var_Set( p_inp->p_libvlc, "marq-position", val );
1082 else if( !strcmp( psz_cmd, "marq-color" ) )
1084 if( strlen( newval.psz_string ) > 0)
1086 val.i_int = strtol( newval.psz_string, NULL, 0 );
1087 var_Set( p_inp->p_libvlc, "marq-color", val );
1090 else if( !strcmp( psz_cmd, "marq-opacity" ) )
1092 if( strlen( newval.psz_string ) > 0)
1094 val.i_int = strtol( newval.psz_string, NULL, 0 );
1095 var_Set( p_inp->p_libvlc, "marq-opacity", val );
1098 else if( !strcmp( psz_cmd, "marq-size" ) )
1100 if( strlen( newval.psz_string ) > 0)
1102 val.i_int = atoi( newval.psz_string );
1103 var_Set( p_inp->p_libvlc, "marq-size", val );
1106 else if( !strcmp( psz_cmd, "marq-timeout" ) )
1108 if( strlen( newval.psz_string ) > 0)
1110 val.i_int = atoi( newval.psz_string );
1111 var_Set( p_inp, "marq-timeout", val );
1114 else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1116 if( strlen( newval.psz_string ) > 0)
1118 val.i_int = atoi( newval.psz_string );
1119 var_Set( p_inp->p_libvlc, "mosaic-alpha", val );
1122 else if( !strcmp( psz_cmd, "mosaic-height" ) )
1124 if( strlen( newval.psz_string ) > 0)
1126 val.i_int = atoi( newval.psz_string );
1127 var_Set( p_inp->p_libvlc, "mosaic-height", val );
1130 else if( !strcmp( psz_cmd, "mosaic-width" ) )
1132 if( strlen( newval.psz_string ) > 0)
1134 val.i_int = atoi( newval.psz_string );
1135 var_Set( p_inp->p_libvlc, "mosaic-width", val );
1138 else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1140 if( strlen( newval.psz_string ) > 0)
1142 val.i_int = atoi( newval.psz_string );
1143 var_Set( p_inp->p_libvlc, "mosaic-xoffset", val );
1146 else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1148 if( strlen( newval.psz_string ) > 0)
1150 val.i_int = atoi( newval.psz_string );
1151 var_Set( p_inp->p_libvlc, "mosaic-yoffset", val );
1154 else if( !strcmp( psz_cmd, "mosaic-align" ) )
1156 if( strlen( newval.psz_string ) > 0 )
1158 val.i_int = atoi( newval.psz_string );
1159 var_Set( p_inp->p_libvlc, "mosaic-align", val );
1162 else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1164 if( strlen( newval.psz_string ) > 0)
1166 val.i_int = atoi( newval.psz_string );
1167 var_Set( p_inp->p_libvlc, "mosaic-vborder", val );
1170 else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1172 if( strlen( newval.psz_string ) > 0)
1174 val.i_int = atoi( newval.psz_string );
1175 var_Set( p_inp->p_libvlc, "mosaic-hborder", val );
1178 else if( !strcmp( psz_cmd, "mosaic-position" ) )
1180 if( strlen( newval.psz_string ) > 0)
1182 val.i_int = atoi( newval.psz_string );
1183 var_Set( p_inp->p_libvlc, "mosaic-position", val );
1186 else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1188 if( strlen( newval.psz_string ) > 0)
1190 val.i_int = atoi( newval.psz_string );
1191 var_Set( p_inp->p_libvlc, "mosaic-rows", val );
1194 else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1196 if( strlen( newval.psz_string ) > 0)
1198 val.i_int = atoi( newval.psz_string );
1199 var_Set( p_inp->p_libvlc, "mosaic-cols", val );
1202 else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1204 if( strlen( newval.psz_string ) > 0)
1206 val.i_int = atoi( newval.psz_string );
1207 var_Set( p_inp->p_libvlc, "mosaic-keep-aspect-ratio", val );
1210 else if( !strcmp( psz_cmd, "time-format" ) )
1212 if( strlen( newval.psz_string ) > 0 )
1214 val.psz_string = newval.psz_string;
1215 var_Set( p_inp->p_libvlc, "time-format", val );
1219 val.psz_string = "";
1220 var_Set( p_inp->p_libvlc, "time-format", val);
1223 else if( !strcmp( psz_cmd, "time-x" ) )
1225 if( strlen( newval.psz_string ) > 0)
1227 val.i_int = atoi( newval.psz_string );
1228 var_Set( p_inp->p_libvlc, "time-x", val );
1231 else if( !strcmp( psz_cmd, "time-y" ) )
1233 if( strlen( newval.psz_string ) > 0)
1235 val.i_int = atoi( newval.psz_string );
1236 var_Set( p_inp->p_libvlc, "time-y", val );
1239 else if( !strcmp( psz_cmd, "time-position" ) )
1241 if( strlen( newval.psz_string ) > 0)
1243 val.i_int = atoi( newval.psz_string );
1244 var_Set( p_inp->p_libvlc, "time-position", val );
1247 else if( !strcmp( psz_cmd, "time-color" ) )
1249 if( strlen( newval.psz_string ) > 0)
1251 val.i_int = strtol( newval.psz_string, NULL, 0 );
1252 var_Set( p_inp->p_libvlc, "time-color", val );
1255 else if( !strcmp( psz_cmd, "time-opacity" ) )
1257 if( strlen( newval.psz_string ) > 0)
1259 val.i_int = strtol( newval.psz_string, NULL, 0 );
1260 var_Set( p_inp->p_libvlc, "time-opacity", val );
1263 else if( !strcmp( psz_cmd, "time-size" ) )
1265 if( strlen( newval.psz_string ) > 0)
1267 val.i_int = atoi( newval.psz_string );
1268 var_Set( p_inp->p_libvlc, "time-size", val );
1271 else if( !strcmp( psz_cmd, "logo-file" ) )
1273 if( strlen( newval.psz_string ) > 0 )
1275 val.psz_string = newval.psz_string;
1276 var_Set( p_inp->p_libvlc, "logo-file", val );
1279 else if( !strcmp( psz_cmd, "logo-x" ) )
1281 if( strlen( newval.psz_string ) > 0)
1283 val.i_int = atoi( newval.psz_string );
1284 var_Set( p_inp->p_libvlc, "logo-x", val );
1287 else if( !strcmp( psz_cmd, "logo-y" ) )
1289 if( strlen( newval.psz_string ) > 0)
1291 val.i_int = atoi( newval.psz_string );
1292 var_Set( p_inp->p_libvlc, "logo-y", val );
1295 else if( !strcmp( psz_cmd, "logo-position" ) )
1297 if( strlen( newval.psz_string ) > 0)
1299 val.i_int = atoi( newval.psz_string );
1300 var_Set( p_inp->p_libvlc, "logo-position", val );
1303 else if( !strcmp( psz_cmd, "logo-transparency" ) )
1305 if( strlen( newval.psz_string ) > 0)
1307 val.i_int = strtol( newval.psz_string, NULL, 0 );
1308 var_Set( p_inp->p_libvlc, "logo-transparency", val );
1317 msg_rc( "unknown command!\n" );
1320 vlc_object_release( p_pl );
1321 vlc_object_release( p_inp );
1325 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1326 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1328 p_this->p_vlc->b_die = VLC_TRUE;
1332 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1333 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1335 intf_thread_t *p_newintf;
1337 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
1341 p_newintf->b_block = VLC_FALSE;
1342 if( intf_RunThread( p_newintf ) )
1344 vlc_object_detach( p_newintf );
1345 intf_Destroy( p_newintf );
1352 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1353 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1355 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1358 if ( *newval.psz_string )
1361 audio_volume_t i_volume = atoi( newval.psz_string );
1362 if ( i_volume > AOUT_VOLUME_MAX )
1364 msg_rc( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
1366 i_error = VLC_EBADVAR;
1368 else i_error = aout_VolumeSet( p_this, i_volume );
1373 audio_volume_t i_volume;
1374 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1376 i_error = VLC_EGENERIC;
1380 msg_rc( "Volume is %d\n", i_volume );
1381 i_error = VLC_SUCCESS;
1388 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1389 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1391 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1392 audio_volume_t i_volume;
1393 int i_nb_steps = atoi(newval.psz_string);
1394 int i_error = VLC_SUCCESS;
1396 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
1401 if ( !strcmp(psz_cmd, "volup") )
1403 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1404 i_error = VLC_EGENERIC;
1408 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1409 i_error = VLC_EGENERIC;
1412 if ( !i_error ) msg_rc( "Volume is %d\n", i_volume );
1416 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1417 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1419 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1420 aout_instance_t * p_aout;
1421 const char * psz_variable;
1422 vlc_value_t val_name;
1425 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1426 if ( p_aout == NULL ) return VLC_ENOOBJ;
1428 if ( !strcmp( psz_cmd, "adev" ) )
1430 psz_variable = "audio-device";
1434 psz_variable = "audio-channels";
1437 /* Get the descriptive name of the variable */
1438 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1440 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1442 if ( !*newval.psz_string )
1444 /* Retrieve all registered ***. */
1445 vlc_value_t val, text;
1448 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1450 vlc_object_release( (vlc_object_t *)p_aout );
1451 return VLC_EGENERIC;
1453 i_value = val.i_int;
1455 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1456 VLC_VAR_GETLIST, &val, &text ) < 0 )
1458 vlc_object_release( (vlc_object_t *)p_aout );
1459 return VLC_EGENERIC;
1462 msg_rc( "+----[ %s ]\n", val_name.psz_string );
1463 for ( i = 0; i < val.p_list->i_count; i++ )
1465 if ( i_value == val.p_list->p_values[i].i_int )
1466 msg_rc( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1467 text.p_list->p_values[i].psz_string );
1469 msg_rc( "| %i - %s\n", val.p_list->p_values[i].i_int,
1470 text.p_list->p_values[i].psz_string );
1472 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1474 msg_rc( "+----[ end of %s ]\n", val_name.psz_string );
1476 if( val_name.psz_string ) free( val_name.psz_string );
1477 i_error = VLC_SUCCESS;
1482 val.i_int = atoi( newval.psz_string );
1484 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1486 vlc_object_release( (vlc_object_t *)p_aout );
1492 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1494 INPUT_RECORD input_record;
1497 /* On Win32, select() only works on socket descriptors */
1498 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1499 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1501 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1502 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1505 if( input_record.EventType != KEY_EVENT ||
1506 !input_record.Event.KeyEvent.bKeyDown ||
1507 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1508 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1509 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1510 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1512 /* nothing interesting */
1516 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1518 /* Echo out the command */
1519 putc( p_buffer[ *pi_size ], stdout );
1521 /* Handle special keys */
1522 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1524 putc( '\n', stdout );
1527 switch( p_buffer[ *pi_size ] )
1533 putc( ' ', stdout );
1534 putc( '\b', stdout );
1545 if( *pi_size == MAX_LINE_LENGTH ||
1546 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1548 p_buffer[ *pi_size ] = 0;
1557 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1562 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1563 return ReadWin32( p_intf, p_buffer, pi_size );
1564 else if( p_intf->p_sys->i_socket == -1 )
1566 msleep( INTF_IDLE_SLEEP );
1571 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1572 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1573 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1574 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1576 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1582 /* Connection closed */
1585 p_intf->p_sys->i_socket = -1;
1586 p_buffer[ *pi_size ] = 0;
1590 if( *pi_size == MAX_LINE_LENGTH ||
1591 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1593 p_buffer[ *pi_size ] = 0;
1600 /*****************************************************************************
1601 * parse_MRL: build a playlist item from a full mrl
1602 *****************************************************************************
1603 * MRL format: "simplified-mrl [:option-name[=option-value]]"
1604 * We don't check for '"' or '\'', we just assume that a ':' that follows a
1605 * space is a new option. Should be good enough for our purpose.
1606 *****************************************************************************/
1607 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
1609 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
1610 #define SKIPTRAILINGSPACE( p, d ) \
1611 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
1613 playlist_item_t *p_item = NULL;
1614 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
1615 char **ppsz_options = NULL;
1616 int i, i_options = 0;
1618 if( !psz_mrl ) return 0;
1620 psz_mrl = psz_orig = strdup( psz_mrl );
1623 SKIPSPACE( psz_mrl );
1626 for( ; *psz_mrl; psz_mrl++ )
1628 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
1630 /* We have a complete item */
1633 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
1634 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
1636 /* We have a complete item */
1641 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
1642 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
1644 /* Remove '"' and '\'' if necessary */
1645 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
1646 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
1647 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
1648 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
1650 if( !psz_item_mrl ) psz_item_mrl = psz_item;
1651 else if( *psz_item )
1654 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
1655 ppsz_options[i_options - 1] = &psz_item[1];
1658 if( *psz_mrl ) SKIPSPACE( psz_mrl );
1661 /* Now create a playlist item */
1664 p_item = playlist_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
1665 for( i = 0; i < i_options; i++ )
1667 playlist_ItemAddOption( p_item, ppsz_options[i] );
1671 if( i_options ) free( ppsz_options );