1 /*****************************************************************************
2 * rc.c : remote control stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
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(PF_UNIX) || defined(PF_LOCAL)
54 # if !defined(PF_UNIX)
55 # define PF_UNIX PF_LOCAL
59 #define MAX_LINE_LENGTH 256
61 /*****************************************************************************
63 *****************************************************************************/
64 static int Activate ( vlc_object_t * );
65 static void Deactivate ( vlc_object_t * );
66 static void Run ( intf_thread_t * );
68 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
70 static int Input ( vlc_object_t *, char const *,
71 vlc_value_t, vlc_value_t, void * );
72 static int Playlist ( vlc_object_t *, char const *,
73 vlc_value_t, vlc_value_t, void * );
74 static int Quit ( vlc_object_t *, char const *,
75 vlc_value_t, vlc_value_t, void * );
76 static int Intf ( vlc_object_t *, char const *,
77 vlc_value_t, vlc_value_t, void * );
78 static int Volume ( vlc_object_t *, char const *,
79 vlc_value_t, vlc_value_t, void * );
80 static int VolumeMove ( vlc_object_t *, char const *,
81 vlc_value_t, vlc_value_t, void * );
82 static int AudioConfig ( vlc_object_t *, char const *,
83 vlc_value_t, vlc_value_t, void * );
95 #ifdef HAVE_VARIADIC_MACROS
96 # define printf( psz_format, args... ) \
97 Printf( p_intf, psz_format, ## args )
100 void Printf( intf_thread_t *p_intf, const char *psz_fmt, ... )
103 va_start( args, psz_fmt );
104 if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
105 else net_vaPrintf( p_intf, p_intf->p_sys->i_socket, psz_fmt, args );
109 /*****************************************************************************
111 *****************************************************************************/
112 #define POS_TEXT N_("Show stream position")
113 #define POS_LONGTEXT N_("Show the current position in seconds within the stream from time to time.")
115 #define TTY_TEXT N_("Fake TTY")
116 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
118 #define CF_TEXT N_("Command input")
119 #define CF_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
120 "You can set the address and port the interface will bind to." )
123 set_description( _("Remote control interface") );
124 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
126 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
128 add_string( "rc-host", 0, NULL, CF_TEXT, CF_LONGTEXT, VLC_TRUE );
129 set_capability( "interface", 20 );
130 set_callbacks( Activate, Deactivate );
133 /*****************************************************************************
134 * Activate: initialize and create stuff
135 *****************************************************************************/
136 static int Activate( vlc_object_t *p_this )
138 intf_thread_t *p_intf = (intf_thread_t*)p_this;
142 #if defined(HAVE_ISATTY) && !defined(WIN32)
143 /* Check that stdin is a TTY */
144 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
146 msg_Warn( p_intf, "fd 0 is not a TTY" );
151 psz_host = config_GetPsz( p_intf, "rc-host" );
152 if( psz_host && (psz_host[0] == '/' || psz_host[0] == '.' ) )
154 #if !defined(PF_UNIX) && !defined(PF_LOCAL)
155 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
160 struct sockaddr_un addr;
163 memset( &addr, 0, sizeof(struct sockaddr_un) );
165 msg_Dbg( p_intf, "trying UNIX socket" );
167 if( (i_socket = socket( PF_UNIX, SOCK_STREAM, 0 ) ) < 0 )
169 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
174 addr.sun_family = AF_UNIX;
175 strcpy( addr.sun_path, psz_host );
177 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
178 sizeof(struct sockaddr_un) ) ) < 0 )
180 msg_Warn( p_intf, "couldn't bind socket to address: %s",
187 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
189 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
196 else if( psz_host && *psz_host )
200 memset( &url, 0, sizeof(vlc_url_t) );
202 /* If it doesn't include a :, it's a port number rather than an URL */
203 if( strchr( psz_host, ':' ) ) vlc_UrlParse( &url, psz_host, 0 );
204 else url.i_port = atoi( psz_host );
206 /* By default, we listen on localhost only for security reasons.
207 * If you need to listen on all IP addresses, specify 0.0.0.0
209 psz_addr = url.psz_host ? url.psz_host : "127.0.0.1";
210 msg_Dbg( p_intf, "base %s:%d", psz_addr, url.i_port );
212 if( (i_socket = net_ListenTCP( p_this, psz_addr, url.i_port )) == -1 )
214 msg_Warn( p_intf, "can't listen to %s:%i", psz_addr, url.i_port );
215 vlc_UrlClean( &url );
220 vlc_UrlClean( &url );
222 if( psz_host ) free( psz_host );
224 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
227 msg_Err( p_intf, "no memory" );
231 p_intf->p_sys->i_socket_listen = i_socket;
232 p_intf->p_sys->i_socket = -1;
234 /* Non-buffered stdout */
235 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
237 p_intf->pf_run = Run;
241 printf( _("Remote control interface initialized, `h' for help\n") );
245 /*****************************************************************************
246 * Deactivate: uninitialize and cleanup
247 *****************************************************************************/
248 static void Deactivate( vlc_object_t *p_this )
250 intf_thread_t *p_intf = (intf_thread_t*)p_this;
252 if( p_intf->p_sys->i_socket_listen != -1 )
253 net_Close( p_intf->p_sys->i_socket_listen );
254 if( p_intf->p_sys->i_socket != -1 )
255 net_Close( p_intf->p_sys->i_socket );
256 free( p_intf->p_sys );
259 /*****************************************************************************
261 *****************************************************************************
262 * This part of the interface is in a separate thread so that we can call
263 * exec() from within it without annoying the rest of the program.
264 *****************************************************************************/
265 static void Run( intf_thread_t *p_intf )
267 input_thread_t * p_input;
268 playlist_t * p_playlist;
270 char p_buffer[ MAX_LINE_LENGTH + 1 ];
271 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
281 /* Register commands that will be cleaned up upon object destruction */
282 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
283 var_AddCallback( p_intf, "quit", Quit, NULL );
284 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
285 var_AddCallback( p_intf, "intf", Intf, NULL );
287 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
288 var_AddCallback( p_intf, "add", Playlist, NULL );
289 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
290 var_AddCallback( p_intf, "playlist", Playlist, NULL );
291 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
292 var_AddCallback( p_intf, "play", Playlist, NULL );
293 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
294 var_AddCallback( p_intf, "stop", Playlist, NULL );
295 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
296 var_AddCallback( p_intf, "prev", Playlist, NULL );
297 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
298 var_AddCallback( p_intf, "next", Playlist, NULL );
300 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
301 var_AddCallback( p_intf, "pause", Input, NULL );
302 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
303 var_AddCallback( p_intf, "seek", Input, NULL );
304 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
305 var_AddCallback( p_intf, "title", Input, NULL );
306 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
307 var_AddCallback( p_intf, "title_n", Input, NULL );
308 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
309 var_AddCallback( p_intf, "title_p", Input, NULL );
310 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
311 var_AddCallback( p_intf, "chapter", Input, NULL );
312 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
313 var_AddCallback( p_intf, "chapter_n", Input, NULL );
314 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
315 var_AddCallback( p_intf, "chapter_p", Input, NULL );
317 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
318 var_AddCallback( p_intf, "volume", Volume, NULL );
319 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
320 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
321 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
322 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
323 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
324 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
325 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
326 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
329 /* Get the file descriptor of the console input */
330 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
331 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
333 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
334 p_intf->b_die = VLC_TRUE;
338 while( !p_intf->b_die )
340 char *psz_cmd, *psz_arg;
341 vlc_bool_t b_complete;
343 if( p_intf->p_sys->i_socket_listen != - 1 &&
344 p_intf->p_sys->i_socket == -1 )
346 p_intf->p_sys->i_socket =
347 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
350 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
352 /* Manage the input part */
353 if( p_input == NULL )
357 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
362 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
366 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
371 else if( p_input->b_dead )
373 vlc_object_release( p_input );
377 if( p_input && b_showpos )
379 i_newpos = 100 * var_GetFloat( p_input, "position" );
380 if( i_oldpos != i_newpos )
383 printf( "pos: %d%%\n", i_newpos );
387 /* Is there something to do? */
388 if( !b_complete ) continue;
391 /* Skip heading spaces */
393 while( *psz_cmd == ' ' )
398 /* Split psz_cmd at the first space and make sure that
399 * psz_arg is valid */
400 psz_arg = strchr( psz_cmd, ' ' );
404 while( *psz_arg == ' ' )
414 /* If the user typed a registered local command, try it */
415 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
420 val.psz_string = psz_arg;
421 i_ret = var_Set( p_intf, psz_cmd, val );
422 printf( _("%s: returned %i (%s)\n"),
423 psz_cmd, i_ret, vlc_error( i_ret ) );
425 /* Or maybe it's a global command */
426 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
431 val.psz_string = psz_arg;
432 /* FIXME: it's a global command, but we should pass the
433 * local object as an argument, not p_intf->p_libvlc. */
434 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
435 printf( _("%s: returned %i (%s)\n"),
436 psz_cmd, i_ret, vlc_error( i_ret ) );
438 else if( !strcmp( psz_cmd, "info" ) )
443 vlc_mutex_lock( &p_input->input.p_item->lock );
444 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
446 info_category_t *p_category =
447 p_input->input.p_item->pp_categories[i];
449 printf( "+----[ %s ]\n", p_category->psz_name );
451 for ( j = 0; j < p_category->i_infos; j++ )
453 info_t *p_info = p_category->pp_infos[j];
454 printf( "| %s: %s\n", p_info->psz_name,
459 printf( _("+----[ end of stream info ]\n") );
460 vlc_mutex_unlock( &p_input->input.p_item->lock );
464 printf( _("no input\n") );
467 else switch( psz_cmd[0] )
473 vout_thread_t *p_vout;
474 p_vout = vlc_object_find( p_input,
475 VLC_OBJECT_VOUT, FIND_CHILD );
479 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
480 vlc_object_release( p_vout );
493 printf(_("+----[ Remote control commands ]\n"));
495 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
496 printf(_("| playlist . . . show items currently in playlist\n"));
497 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
498 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
499 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
500 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
501 printf(_("| title [X] . . . . set/get title in current item\n"));
502 printf(_("| title_n . . . . . . next title in current item\n"));
503 printf(_("| title_p . . . . previous title in current item\n"));
504 printf(_("| chapter [X] . . set/get chapter in current item\n"));
505 printf(_("| chapter_n . . . . next chapter in current item\n"));
506 printf(_("| chapter_p . . previous chapter in current item\n"));
508 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
509 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
510 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
511 printf(_("| info . . . information about the current stream\n"));
513 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
514 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
515 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
516 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
517 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
519 printf(_("| help . . . . . . . . . . . . . this help message\n"));
520 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
522 printf(_("+----[ end of help ]\n"));
526 /* Ignore empty lines */
530 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
534 /* Command processed */
535 i_size = 0; p_buffer[0] = 0;
540 vlc_object_release( p_input );
546 vlc_object_release( p_playlist );
551 static int Input( vlc_object_t *p_this, char const *psz_cmd,
552 vlc_value_t oldval, vlc_value_t newval, void *p_data )
554 intf_thread_t *p_intf = (intf_thread_t*)p_this;
555 input_thread_t *p_input;
558 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
559 if( !p_input ) return VLC_ENOOBJ;
561 /* Parse commands that only require an input */
562 if( !strcmp( psz_cmd, "pause" ) )
566 var_Set( p_input, "state", val );
567 vlc_object_release( p_input );
570 else if( !strcmp( psz_cmd, "seek" ) )
572 if( strlen( newval.psz_string ) > 0 &&
573 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
575 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
576 var_Set( p_input, "position", val );
580 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
581 var_Set( p_input, "time", val );
583 vlc_object_release( p_input );
586 else if( !strcmp( psz_cmd, "chapter" ) ||
587 !strcmp( psz_cmd, "chapter_n" ) ||
588 !strcmp( psz_cmd, "chapter_p" ) )
590 if( !strcmp( psz_cmd, "chapter" ) )
592 if ( *newval.psz_string )
595 val.i_int = atoi( newval.psz_string );
596 var_Set( p_input, "chapter", val );
600 vlc_value_t val_list;
603 var_Get( p_input, "chapter", &val );
604 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
606 printf( _("Currently playing chapter %d/%d\n"),
607 val.i_int, val_list.p_list->i_count );
608 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
612 else if( !strcmp( psz_cmd, "chapter_n" ) )
614 val.b_bool = VLC_TRUE;
615 var_Set( p_input, "next-chapter", val );
617 else if( !strcmp( psz_cmd, "chapter_p" ) )
619 val.b_bool = VLC_TRUE;
620 var_Set( p_input, "prev-chapter", val );
623 vlc_object_release( p_input );
626 else if( !strcmp( psz_cmd, "title" ) ||
627 !strcmp( psz_cmd, "title_n" ) ||
628 !strcmp( psz_cmd, "title_p" ) )
630 if( !strcmp( psz_cmd, "title" ) )
632 if ( *newval.psz_string )
635 val.i_int = atoi( newval.psz_string );
636 var_Set( p_input, "title", val );
640 vlc_value_t val_list;
643 var_Get( p_input, "title", &val );
644 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
646 printf( _("Currently playing title %d/%d\n"),
647 val.i_int, val_list.p_list->i_count );
648 var_Change( p_this, "title", VLC_VAR_FREELIST,
652 else if( !strcmp( psz_cmd, "title_n" ) )
654 val.b_bool = VLC_TRUE;
655 var_Set( p_input, "next-title", val );
657 else if( !strcmp( psz_cmd, "title_p" ) )
659 val.b_bool = VLC_TRUE;
660 var_Set( p_input, "prev-title", val );
663 vlc_object_release( p_input );
671 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
672 vlc_value_t oldval, vlc_value_t newval, void *p_data )
674 intf_thread_t *p_intf = (intf_thread_t*)p_this;
675 playlist_t *p_playlist;
677 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
684 /* Parse commands that require a playlist */
685 if( !strcmp( psz_cmd, "prev" ) )
687 playlist_Prev( p_playlist );
689 else if( !strcmp( psz_cmd, "next" ) )
691 playlist_Next( p_playlist );
693 else if( !strcmp( psz_cmd, "play" ) )
695 playlist_Play( p_playlist );
697 else if( !strcmp( psz_cmd, "stop" ) )
699 playlist_Stop( p_playlist );
701 else if( !strcmp( psz_cmd, "add" ) )
703 printf( _("trying to add %s to playlist\n"), newval.psz_string );
704 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
705 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
707 else if( !strcmp( psz_cmd, "playlist" ) )
710 for ( i = 0; i < p_playlist->i_size; i++ )
712 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
713 p_playlist->pp_items[i]->input.psz_name,
714 p_playlist->pp_items[i]->input.psz_uri );
718 printf( _("| no entries\n") );
726 printf( _("unknown command!\n") );
729 vlc_object_release( p_playlist );
733 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
734 vlc_value_t oldval, vlc_value_t newval, void *p_data )
736 p_this->p_vlc->b_die = VLC_TRUE;
740 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
741 vlc_value_t oldval, vlc_value_t newval, void *p_data )
743 intf_thread_t *p_newintf;
745 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
749 p_newintf->b_block = VLC_FALSE;
750 if( intf_RunThread( p_newintf ) )
752 vlc_object_detach( p_newintf );
753 intf_Destroy( p_newintf );
760 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
761 vlc_value_t oldval, vlc_value_t newval, void *p_data )
763 intf_thread_t *p_intf = (intf_thread_t*)p_this;
766 if ( *newval.psz_string )
769 audio_volume_t i_volume = atoi( newval.psz_string );
770 if ( i_volume > AOUT_VOLUME_MAX )
772 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
774 i_error = VLC_EBADVAR;
776 else i_error = aout_VolumeSet( p_this, i_volume );
781 audio_volume_t i_volume;
782 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
784 i_error = VLC_EGENERIC;
788 printf( _("Volume is %d\n"), i_volume );
789 i_error = VLC_SUCCESS;
796 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
797 vlc_value_t oldval, vlc_value_t newval, void *p_data )
799 intf_thread_t *p_intf = (intf_thread_t*)p_this;
800 audio_volume_t i_volume;
801 int i_nb_steps = atoi(newval.psz_string);
802 int i_error = VLC_SUCCESS;
804 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
809 if ( !strcmp(psz_cmd, "volup") )
811 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
812 i_error = VLC_EGENERIC;
816 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
817 i_error = VLC_EGENERIC;
820 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
824 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
825 vlc_value_t oldval, vlc_value_t newval, void *p_data )
827 intf_thread_t *p_intf = (intf_thread_t*)p_this;
828 aout_instance_t * p_aout;
829 const char * psz_variable;
830 vlc_value_t val_name;
833 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
834 if ( p_aout == NULL ) return VLC_ENOOBJ;
836 if ( !strcmp( psz_cmd, "adev" ) )
838 psz_variable = "audio-device";
842 psz_variable = "audio-channels";
845 /* Get the descriptive name of the variable */
846 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
848 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
850 if ( !*newval.psz_string )
852 /* Retrieve all registered ***. */
853 vlc_value_t val, text;
856 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
858 vlc_object_release( (vlc_object_t *)p_aout );
863 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
864 VLC_VAR_GETLIST, &val, &text ) < 0 )
866 vlc_object_release( (vlc_object_t *)p_aout );
870 printf( "+----[ %s ]\n", val_name.psz_string );
871 for ( i = 0; i < val.p_list->i_count; i++ )
873 if ( i_value == val.p_list->p_values[i].i_int )
874 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
875 text.p_list->p_values[i].psz_string );
877 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
878 text.p_list->p_values[i].psz_string );
880 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
882 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
884 if( val_name.psz_string ) free( val_name.psz_string );
885 i_error = VLC_SUCCESS;
890 val.i_int = atoi( newval.psz_string );
892 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
894 vlc_object_release( (vlc_object_t *)p_aout );
900 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
902 INPUT_RECORD input_record;
905 /* On Win32, select() only works on socket descriptors */
906 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
907 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
909 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
910 ReadConsoleInput( p_sys->hConsoleIn, &input_record, 1, &i_dw ) )
912 if( input_record.EventType != KEY_EVENT ||
913 !input_record.Event.KeyEvent.bKeyDown ||
914 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
915 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
916 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
917 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
919 /* nothing interesting */
923 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
925 /* Echo out the command */
926 putc( p_buffer[ *pi_size ], stdout );
928 /* Handle special keys */
929 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
931 putc( '\n', stdout );
934 switch( p_buffer[ *pi_size ] )
941 putc( '\b', stdout );
952 if( *pi_size == MAX_LINE_LENGTH ||
953 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
955 p_buffer[ *pi_size ] = 0;
964 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
969 if( p_intf->p_sys->i_socket == -1 )
970 return ReadWin32( p_intf, p_buffer, pi_size, pb_complete );
973 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
974 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
975 STDIN_FILENO : p_intf->p_sys->i_socket,
976 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
978 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
984 /* Connection closed */
987 p_intf->p_sys->i_socket = -1;
988 p_buffer[ *pi_size ] = 0;
992 if( *pi_size == MAX_LINE_LENGTH ||
993 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
995 p_buffer[ *pi_size ] = 0;