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>
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,
1041 vlc_object_release( p_pl );
1045 /* Parse miscellaneous commands */
1046 if( !strcmp( psz_cmd, "marq-marquee" ) )
1048 if( strlen( newval.psz_string ) > 0 )
1050 val.psz_string = newval.psz_string;
1051 var_Set( p_inp->p_libvlc, "marq-marquee", val );
1055 val.psz_string = "";
1056 var_Set( p_inp->p_libvlc, "marq-marquee", val);
1059 else if( !strcmp( psz_cmd, "marq-x" ) )
1061 if( strlen( newval.psz_string ) > 0)
1063 val.i_int = atoi( newval.psz_string );
1064 var_Set( p_inp->p_libvlc, "marq-x", val );
1067 else if( !strcmp( psz_cmd, "marq-y" ) )
1069 if( strlen( newval.psz_string ) > 0)
1071 val.i_int = atoi( newval.psz_string );
1072 var_Set( p_inp->p_libvlc, "marq-y", val );
1075 else if( !strcmp( psz_cmd, "marq-position" ) )
1077 if( strlen( newval.psz_string ) > 0)
1079 val.i_int = atoi( newval.psz_string );
1080 var_Set( p_inp->p_libvlc, "marq-position", val );
1083 else if( !strcmp( psz_cmd, "marq-color" ) )
1085 if( strlen( newval.psz_string ) > 0)
1087 val.i_int = strtol( newval.psz_string, NULL, 0 );
1088 var_Set( p_inp->p_libvlc, "marq-color", val );
1091 else if( !strcmp( psz_cmd, "marq-opacity" ) )
1093 if( strlen( newval.psz_string ) > 0)
1095 val.i_int = strtol( newval.psz_string, NULL, 0 );
1096 var_Set( p_inp->p_libvlc, "marq-opacity", val );
1099 else if( !strcmp( psz_cmd, "marq-size" ) )
1101 if( strlen( newval.psz_string ) > 0)
1103 val.i_int = atoi( newval.psz_string );
1104 var_Set( p_inp->p_libvlc, "marq-size", val );
1107 else if( !strcmp( psz_cmd, "marq-timeout" ) )
1109 if( strlen( newval.psz_string ) > 0)
1111 val.i_int = atoi( newval.psz_string );
1112 var_Set( p_inp, "marq-timeout", val );
1115 else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
1117 if( strlen( newval.psz_string ) > 0)
1119 val.i_int = atoi( newval.psz_string );
1120 var_Set( p_inp->p_libvlc, "mosaic-alpha", val );
1123 else if( !strcmp( psz_cmd, "mosaic-height" ) )
1125 if( strlen( newval.psz_string ) > 0)
1127 val.i_int = atoi( newval.psz_string );
1128 var_Set( p_inp->p_libvlc, "mosaic-height", val );
1131 else if( !strcmp( psz_cmd, "mosaic-width" ) )
1133 if( strlen( newval.psz_string ) > 0)
1135 val.i_int = atoi( newval.psz_string );
1136 var_Set( p_inp->p_libvlc, "mosaic-width", val );
1139 else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
1141 if( strlen( newval.psz_string ) > 0)
1143 val.i_int = atoi( newval.psz_string );
1144 var_Set( p_inp->p_libvlc, "mosaic-xoffset", val );
1147 else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
1149 if( strlen( newval.psz_string ) > 0)
1151 val.i_int = atoi( newval.psz_string );
1152 var_Set( p_inp->p_libvlc, "mosaic-yoffset", val );
1155 else if( !strcmp( psz_cmd, "mosaic-align" ) )
1157 if( strlen( newval.psz_string ) > 0 )
1159 val.i_int = atoi( newval.psz_string );
1160 var_Set( p_inp->p_libvlc, "mosaic-align", val );
1163 else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
1165 if( strlen( newval.psz_string ) > 0)
1167 val.i_int = atoi( newval.psz_string );
1168 var_Set( p_inp->p_libvlc, "mosaic-vborder", val );
1171 else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
1173 if( strlen( newval.psz_string ) > 0)
1175 val.i_int = atoi( newval.psz_string );
1176 var_Set( p_inp->p_libvlc, "mosaic-hborder", val );
1179 else if( !strcmp( psz_cmd, "mosaic-position" ) )
1181 if( strlen( newval.psz_string ) > 0)
1183 val.i_int = atoi( newval.psz_string );
1184 var_Set( p_inp->p_libvlc, "mosaic-position", val );
1187 else if( !strcmp( psz_cmd, "mosaic-rows" ) )
1189 if( strlen( newval.psz_string ) > 0)
1191 val.i_int = atoi( newval.psz_string );
1192 var_Set( p_inp->p_libvlc, "mosaic-rows", val );
1195 else if( !strcmp( psz_cmd, "mosaic-cols" ) )
1197 if( strlen( newval.psz_string ) > 0)
1199 val.i_int = atoi( newval.psz_string );
1200 var_Set( p_inp->p_libvlc, "mosaic-cols", val );
1203 else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
1205 if( strlen( newval.psz_string ) > 0)
1207 val.i_int = atoi( newval.psz_string );
1208 var_Set( p_inp->p_libvlc, "mosaic-keep-aspect-ratio", val );
1211 else if( !strcmp( psz_cmd, "time-format" ) )
1213 if( strlen( newval.psz_string ) > 0 )
1215 val.psz_string = newval.psz_string;
1216 var_Set( p_inp->p_libvlc, "time-format", val );
1220 val.psz_string = "";
1221 var_Set( p_inp->p_libvlc, "time-format", val);
1224 else if( !strcmp( psz_cmd, "time-x" ) )
1226 if( strlen( newval.psz_string ) > 0)
1228 val.i_int = atoi( newval.psz_string );
1229 var_Set( p_inp->p_libvlc, "time-x", val );
1232 else if( !strcmp( psz_cmd, "time-y" ) )
1234 if( strlen( newval.psz_string ) > 0)
1236 val.i_int = atoi( newval.psz_string );
1237 var_Set( p_inp->p_libvlc, "time-y", val );
1240 else if( !strcmp( psz_cmd, "time-position" ) )
1242 if( strlen( newval.psz_string ) > 0)
1244 val.i_int = atoi( newval.psz_string );
1245 var_Set( p_inp->p_libvlc, "time-position", val );
1248 else if( !strcmp( psz_cmd, "time-color" ) )
1250 if( strlen( newval.psz_string ) > 0)
1252 val.i_int = strtol( newval.psz_string, NULL, 0 );
1253 var_Set( p_inp->p_libvlc, "time-color", val );
1256 else if( !strcmp( psz_cmd, "time-opacity" ) )
1258 if( strlen( newval.psz_string ) > 0)
1260 val.i_int = strtol( newval.psz_string, NULL, 0 );
1261 var_Set( p_inp->p_libvlc, "time-opacity", val );
1264 else if( !strcmp( psz_cmd, "time-size" ) )
1266 if( strlen( newval.psz_string ) > 0)
1268 val.i_int = atoi( newval.psz_string );
1269 var_Set( p_inp->p_libvlc, "time-size", val );
1272 else if( !strcmp( psz_cmd, "logo-file" ) )
1274 if( strlen( newval.psz_string ) > 0 )
1276 val.psz_string = newval.psz_string;
1277 var_Set( p_inp->p_libvlc, "logo-file", val );
1280 else if( !strcmp( psz_cmd, "logo-x" ) )
1282 if( strlen( newval.psz_string ) > 0)
1284 val.i_int = atoi( newval.psz_string );
1285 var_Set( p_inp->p_libvlc, "logo-x", val );
1288 else if( !strcmp( psz_cmd, "logo-y" ) )
1290 if( strlen( newval.psz_string ) > 0)
1292 val.i_int = atoi( newval.psz_string );
1293 var_Set( p_inp->p_libvlc, "logo-y", val );
1296 else if( !strcmp( psz_cmd, "logo-position" ) )
1298 if( strlen( newval.psz_string ) > 0)
1300 val.i_int = atoi( newval.psz_string );
1301 var_Set( p_inp->p_libvlc, "logo-position", val );
1304 else if( !strcmp( psz_cmd, "logo-transparency" ) )
1306 if( strlen( newval.psz_string ) > 0)
1308 val.i_int = strtol( newval.psz_string, NULL, 0 );
1309 var_Set( p_inp->p_libvlc, "logo-transparency", val );
1318 msg_rc( "unknown command!\n" );
1321 vlc_object_release( p_pl );
1322 vlc_object_release( p_inp );
1326 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1327 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1329 p_this->p_vlc->b_die = VLC_TRUE;
1333 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1334 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1336 intf_thread_t *p_newintf;
1338 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
1342 p_newintf->b_block = VLC_FALSE;
1343 if( intf_RunThread( p_newintf ) )
1345 vlc_object_detach( p_newintf );
1346 intf_Destroy( p_newintf );
1353 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1354 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1356 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1359 if ( *newval.psz_string )
1362 audio_volume_t i_volume = atoi( newval.psz_string );
1363 if ( i_volume > AOUT_VOLUME_MAX )
1365 msg_rc( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
1367 i_error = VLC_EBADVAR;
1369 else i_error = aout_VolumeSet( p_this, i_volume );
1374 audio_volume_t i_volume;
1375 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1377 i_error = VLC_EGENERIC;
1381 msg_rc( "Volume is %d\n", i_volume );
1382 i_error = VLC_SUCCESS;
1389 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1390 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1392 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1393 audio_volume_t i_volume;
1394 int i_nb_steps = atoi(newval.psz_string);
1395 int i_error = VLC_SUCCESS;
1397 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
1402 if ( !strcmp(psz_cmd, "volup") )
1404 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1405 i_error = VLC_EGENERIC;
1409 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1410 i_error = VLC_EGENERIC;
1413 if ( !i_error ) msg_rc( "Volume is %d\n", i_volume );
1417 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1418 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1420 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1421 aout_instance_t * p_aout;
1422 const char * psz_variable;
1423 vlc_value_t val_name;
1426 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1427 if ( p_aout == NULL ) return VLC_ENOOBJ;
1429 if ( !strcmp( psz_cmd, "adev" ) )
1431 psz_variable = "audio-device";
1435 psz_variable = "audio-channels";
1438 /* Get the descriptive name of the variable */
1439 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1441 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1443 if ( !*newval.psz_string )
1445 /* Retrieve all registered ***. */
1446 vlc_value_t val, text;
1449 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1451 vlc_object_release( (vlc_object_t *)p_aout );
1452 return VLC_EGENERIC;
1454 i_value = val.i_int;
1456 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1457 VLC_VAR_GETLIST, &val, &text ) < 0 )
1459 vlc_object_release( (vlc_object_t *)p_aout );
1460 return VLC_EGENERIC;
1463 msg_rc( "+----[ %s ]\n", val_name.psz_string );
1464 for ( i = 0; i < val.p_list->i_count; i++ )
1466 if ( i_value == val.p_list->p_values[i].i_int )
1467 msg_rc( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1468 text.p_list->p_values[i].psz_string );
1470 msg_rc( "| %i - %s\n", val.p_list->p_values[i].i_int,
1471 text.p_list->p_values[i].psz_string );
1473 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1475 msg_rc( "+----[ end of %s ]\n", val_name.psz_string );
1477 if( val_name.psz_string ) free( val_name.psz_string );
1478 i_error = VLC_SUCCESS;
1483 val.i_int = atoi( newval.psz_string );
1485 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1487 vlc_object_release( (vlc_object_t *)p_aout );
1493 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1495 INPUT_RECORD input_record;
1498 /* On Win32, select() only works on socket descriptors */
1499 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1500 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1502 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1503 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1506 if( input_record.EventType != KEY_EVENT ||
1507 !input_record.Event.KeyEvent.bKeyDown ||
1508 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1509 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1510 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1511 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1513 /* nothing interesting */
1517 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1519 /* Echo out the command */
1520 putc( p_buffer[ *pi_size ], stdout );
1522 /* Handle special keys */
1523 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1525 putc( '\n', stdout );
1528 switch( p_buffer[ *pi_size ] )
1534 putc( ' ', stdout );
1535 putc( '\b', stdout );
1546 if( *pi_size == MAX_LINE_LENGTH ||
1547 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1549 p_buffer[ *pi_size ] = 0;
1558 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1563 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1564 return ReadWin32( p_intf, p_buffer, pi_size );
1565 else if( p_intf->p_sys->i_socket == -1 )
1567 msleep( INTF_IDLE_SLEEP );
1572 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1573 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1574 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1575 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1577 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1583 /* Connection closed */
1586 p_intf->p_sys->i_socket = -1;
1587 p_buffer[ *pi_size ] = 0;
1591 if( *pi_size == MAX_LINE_LENGTH ||
1592 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1594 p_buffer[ *pi_size ] = 0;
1601 /*****************************************************************************
1602 * parse_MRL: build a playlist item from a full mrl
1603 *****************************************************************************
1604 * MRL format: "simplified-mrl [:option-name[=option-value]]"
1605 * We don't check for '"' or '\'', we just assume that a ':' that follows a
1606 * space is a new option. Should be good enough for our purpose.
1607 *****************************************************************************/
1608 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
1610 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
1611 #define SKIPTRAILINGSPACE( p, d ) \
1612 { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
1614 playlist_item_t *p_item = NULL;
1615 char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
1616 char **ppsz_options = NULL;
1617 int i, i_options = 0;
1619 if( !psz_mrl ) return 0;
1621 psz_mrl = psz_orig = strdup( psz_mrl );
1624 SKIPSPACE( psz_mrl );
1627 for( ; *psz_mrl; psz_mrl++ )
1629 if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
1631 /* We have a complete item */
1634 if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
1635 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
1637 /* We have a complete item */
1642 if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
1643 SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
1645 /* Remove '"' and '\'' if necessary */
1646 if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
1647 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
1648 if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
1649 { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
1651 if( !psz_item_mrl ) psz_item_mrl = psz_item;
1652 else if( *psz_item )
1655 ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
1656 ppsz_options[i_options - 1] = &psz_item[1];
1659 if( *psz_mrl ) SKIPSPACE( psz_mrl );
1662 /* Now create a playlist item */
1665 p_item = playlist_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
1666 for( i = 0; i < i_options; i++ )
1668 playlist_ItemAddOption( p_item, ppsz_options[i] );
1672 if( i_options ) free( ppsz_options );