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)
53 # define PF_LOCAL PF_UNIX
55 #if defined(AF_UNIX) && !defined(AF_LOCAL)
56 # define AF_LOCAL AF_UNIX
63 #define MAX_LINE_LENGTH 256
65 /*****************************************************************************
67 *****************************************************************************/
68 static int Activate ( vlc_object_t * );
69 static void Deactivate ( vlc_object_t * );
70 static void Run ( intf_thread_t * );
72 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
74 static int Input ( vlc_object_t *, char const *,
75 vlc_value_t, vlc_value_t, void * );
76 static int Playlist ( vlc_object_t *, char const *,
77 vlc_value_t, vlc_value_t, void * );
78 static int Quit ( vlc_object_t *, char const *,
79 vlc_value_t, vlc_value_t, void * );
80 static int Intf ( vlc_object_t *, char const *,
81 vlc_value_t, vlc_value_t, void * );
82 static int Volume ( vlc_object_t *, char const *,
83 vlc_value_t, vlc_value_t, void * );
84 static int VolumeMove ( vlc_object_t *, char const *,
85 vlc_value_t, vlc_value_t, void * );
86 static int AudioConfig ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
100 #ifdef HAVE_VARIADIC_MACROS
101 # define printf( psz_format, args... ) \
102 Printf( p_intf, psz_format, ## args )
105 void Printf( intf_thread_t *p_intf, const char *psz_fmt, ... )
108 va_start( args, psz_fmt );
109 if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
110 else net_vaPrintf( p_intf, p_intf->p_sys->i_socket, psz_fmt, args );
114 /*****************************************************************************
116 *****************************************************************************/
117 #define POS_TEXT N_("Show stream position")
118 #define POS_LONGTEXT N_("Show the current position in seconds within the stream from time to time.")
120 #define TTY_TEXT N_("Fake TTY")
121 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
123 #define UNIX_TEXT N_("UNIX socket command input")
124 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than stdin. " )
126 #define HOST_TEXT N_("IP command input")
127 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
128 "You can set the address and port the interface will bind to." )
131 set_description( _("Remote control interface") );
132 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
134 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
136 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
137 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
138 set_capability( "interface", 20 );
139 set_callbacks( Activate, Deactivate );
142 /*****************************************************************************
143 * Activate: initialize and create stuff
144 *****************************************************************************/
145 static int Activate( vlc_object_t *p_this )
147 intf_thread_t *p_intf = (intf_thread_t*)p_this;
148 char *psz_host, *psz_unix_path;
151 #if defined(HAVE_ISATTY) && !defined(WIN32)
152 /* Check that stdin is a TTY */
153 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
155 msg_Warn( p_intf, "fd 0 is not a TTY" );
160 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
164 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
165 free( psz_unix_path );
168 struct sockaddr_un addr;
171 memset( &addr, 0, sizeof(struct sockaddr_un) );
173 msg_Dbg( p_intf, "trying UNIX socket" );
175 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
177 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
178 free( psz_unix_path );
182 addr.sun_family = AF_LOCAL;
183 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
184 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
186 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
187 sizeof(struct sockaddr_un) ) ) < 0 )
189 msg_Warn( p_intf, "couldn't bind socket to address: %s",
191 free( psz_unix_path );
192 net_Close( i_socket );
196 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
198 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
199 free( psz_unix_path );
200 net_Close( i_socket );
206 if( ( i_socket == -1) &&
207 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
211 vlc_UrlParse( &url, psz_host, 0 );
213 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
215 if( (i_socket = net_ListenTCP(p_this, url.psz_host, url.i_port)) == -1)
217 msg_Warn( p_intf, "can't listen to %s port %i",
218 url.psz_host, url.i_port );
219 vlc_UrlClean( &url );
224 vlc_UrlClean( &url );
228 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
231 msg_Err( p_intf, "no memory" );
235 p_intf->p_sys->i_socket_listen = i_socket;
236 p_intf->p_sys->i_socket = -1;
237 p_intf->p_sys->psz_unix_path = psz_unix_path;
239 /* Non-buffered stdout */
240 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
242 p_intf->pf_run = Run;
246 printf( _("Remote control interface initialized, `h' for help\n") );
250 /*****************************************************************************
251 * Deactivate: uninitialize and cleanup
252 *****************************************************************************/
253 static void Deactivate( vlc_object_t *p_this )
255 intf_thread_t *p_intf = (intf_thread_t*)p_this;
257 if( p_intf->p_sys->i_socket_listen != -1 )
258 net_Close( p_intf->p_sys->i_socket_listen );
259 if( p_intf->p_sys->i_socket != -1 )
260 net_Close( p_intf->p_sys->i_socket );
261 if( p_intf->p_sys->psz_unix_path != NULL )
264 unlink( p_intf->p_sys->psz_unix_path );
266 free( p_intf->p_sys->psz_unix_path );
268 free( p_intf->p_sys );
271 /*****************************************************************************
273 *****************************************************************************
274 * This part of the interface is in a separate thread so that we can call
275 * exec() from within it without annoying the rest of the program.
276 *****************************************************************************/
277 static void Run( intf_thread_t *p_intf )
279 input_thread_t * p_input;
280 playlist_t * p_playlist;
282 char p_buffer[ MAX_LINE_LENGTH + 1 ];
283 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
293 /* Register commands that will be cleaned up upon object destruction */
294 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
295 var_AddCallback( p_intf, "quit", Quit, NULL );
296 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
297 var_AddCallback( p_intf, "intf", Intf, NULL );
299 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
300 var_AddCallback( p_intf, "add", Playlist, NULL );
301 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
302 var_AddCallback( p_intf, "playlist", Playlist, NULL );
303 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
304 var_AddCallback( p_intf, "play", Playlist, NULL );
305 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
306 var_AddCallback( p_intf, "stop", Playlist, NULL );
307 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
308 var_AddCallback( p_intf, "prev", Playlist, NULL );
309 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
310 var_AddCallback( p_intf, "next", Playlist, NULL );
312 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
313 var_AddCallback( p_intf, "pause", Input, NULL );
314 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
315 var_AddCallback( p_intf, "seek", Input, NULL );
316 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
317 var_AddCallback( p_intf, "title", Input, NULL );
318 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
319 var_AddCallback( p_intf, "title_n", Input, NULL );
320 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
321 var_AddCallback( p_intf, "title_p", Input, NULL );
322 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
323 var_AddCallback( p_intf, "chapter", Input, NULL );
324 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
325 var_AddCallback( p_intf, "chapter_n", Input, NULL );
326 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
327 var_AddCallback( p_intf, "chapter_p", Input, NULL );
329 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
330 var_AddCallback( p_intf, "volume", Volume, NULL );
331 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
332 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
333 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
334 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
335 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
336 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
337 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
338 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
341 /* Get the file descriptor of the console input */
342 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
343 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
345 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
346 p_intf->b_die = VLC_TRUE;
350 while( !p_intf->b_die )
352 char *psz_cmd, *psz_arg;
353 vlc_bool_t b_complete;
355 if( p_intf->p_sys->i_socket_listen != - 1 &&
356 p_intf->p_sys->i_socket == -1 )
358 p_intf->p_sys->i_socket =
359 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
362 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
364 /* Manage the input part */
365 if( p_input == NULL )
369 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
374 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
378 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
383 else if( p_input->b_dead )
385 vlc_object_release( p_input );
389 if( p_input && b_showpos )
391 i_newpos = 100 * var_GetFloat( p_input, "position" );
392 if( i_oldpos != i_newpos )
395 printf( "pos: %d%%\n", i_newpos );
399 /* Is there something to do? */
400 if( !b_complete ) continue;
403 /* Skip heading spaces */
405 while( *psz_cmd == ' ' )
410 /* Split psz_cmd at the first space and make sure that
411 * psz_arg is valid */
412 psz_arg = strchr( psz_cmd, ' ' );
416 while( *psz_arg == ' ' )
426 /* If the user typed a registered local command, try it */
427 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
432 val.psz_string = psz_arg;
433 i_ret = var_Set( p_intf, psz_cmd, val );
434 printf( _("%s: returned %i (%s)\n"),
435 psz_cmd, i_ret, vlc_error( i_ret ) );
437 /* Or maybe it's a global command */
438 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
443 val.psz_string = psz_arg;
444 /* FIXME: it's a global command, but we should pass the
445 * local object as an argument, not p_intf->p_libvlc. */
446 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
447 printf( _("%s: returned %i (%s)\n"),
448 psz_cmd, i_ret, vlc_error( i_ret ) );
450 else if( !strcmp( psz_cmd, "info" ) )
455 vlc_mutex_lock( &p_input->input.p_item->lock );
456 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
458 info_category_t *p_category =
459 p_input->input.p_item->pp_categories[i];
461 printf( "+----[ %s ]\n", p_category->psz_name );
463 for ( j = 0; j < p_category->i_infos; j++ )
465 info_t *p_info = p_category->pp_infos[j];
466 printf( "| %s: %s\n", p_info->psz_name,
471 printf( _("+----[ end of stream info ]\n") );
472 vlc_mutex_unlock( &p_input->input.p_item->lock );
476 printf( _("no input\n") );
479 else switch( psz_cmd[0] )
485 vout_thread_t *p_vout;
486 p_vout = vlc_object_find( p_input,
487 VLC_OBJECT_VOUT, FIND_CHILD );
491 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
492 vlc_object_release( p_vout );
505 printf(_("+----[ Remote control commands ]\n"));
507 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
508 printf(_("| playlist . . . show items currently in playlist\n"));
509 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
510 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
511 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
512 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
513 printf(_("| title [X] . . . . set/get title in current item\n"));
514 printf(_("| title_n . . . . . . next title in current item\n"));
515 printf(_("| title_p . . . . previous title in current item\n"));
516 printf(_("| chapter [X] . . set/get chapter in current item\n"));
517 printf(_("| chapter_n . . . . next chapter in current item\n"));
518 printf(_("| chapter_p . . previous chapter in current item\n"));
520 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
521 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
522 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
523 printf(_("| info . . . information about the current stream\n"));
525 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
526 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
527 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
528 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
529 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
531 printf(_("| help . . . . . . . . . . . . . this help message\n"));
532 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
534 printf(_("+----[ end of help ]\n"));
538 /* Ignore empty lines */
542 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
546 /* Command processed */
547 i_size = 0; p_buffer[0] = 0;
552 vlc_object_release( p_input );
558 vlc_object_release( p_playlist );
563 static int Input( vlc_object_t *p_this, char const *psz_cmd,
564 vlc_value_t oldval, vlc_value_t newval, void *p_data )
566 intf_thread_t *p_intf = (intf_thread_t*)p_this;
567 input_thread_t *p_input;
570 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
571 if( !p_input ) return VLC_ENOOBJ;
573 /* Parse commands that only require an input */
574 if( !strcmp( psz_cmd, "pause" ) )
578 var_Set( p_input, "state", val );
579 vlc_object_release( p_input );
582 else if( !strcmp( psz_cmd, "seek" ) )
584 if( strlen( newval.psz_string ) > 0 &&
585 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
587 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
588 var_Set( p_input, "position", val );
592 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
593 var_Set( p_input, "time", val );
595 vlc_object_release( p_input );
598 else if( !strcmp( psz_cmd, "chapter" ) ||
599 !strcmp( psz_cmd, "chapter_n" ) ||
600 !strcmp( psz_cmd, "chapter_p" ) )
602 if( !strcmp( psz_cmd, "chapter" ) )
604 if ( *newval.psz_string )
607 val.i_int = atoi( newval.psz_string );
608 var_Set( p_input, "chapter", val );
612 vlc_value_t val_list;
615 var_Get( p_input, "chapter", &val );
616 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
618 printf( _("Currently playing chapter %d/%d\n"),
619 val.i_int, val_list.p_list->i_count );
620 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
624 else if( !strcmp( psz_cmd, "chapter_n" ) )
626 val.b_bool = VLC_TRUE;
627 var_Set( p_input, "next-chapter", val );
629 else if( !strcmp( psz_cmd, "chapter_p" ) )
631 val.b_bool = VLC_TRUE;
632 var_Set( p_input, "prev-chapter", val );
635 vlc_object_release( p_input );
638 else if( !strcmp( psz_cmd, "title" ) ||
639 !strcmp( psz_cmd, "title_n" ) ||
640 !strcmp( psz_cmd, "title_p" ) )
642 if( !strcmp( psz_cmd, "title" ) )
644 if ( *newval.psz_string )
647 val.i_int = atoi( newval.psz_string );
648 var_Set( p_input, "title", val );
652 vlc_value_t val_list;
655 var_Get( p_input, "title", &val );
656 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
658 printf( _("Currently playing title %d/%d\n"),
659 val.i_int, val_list.p_list->i_count );
660 var_Change( p_this, "title", VLC_VAR_FREELIST,
664 else if( !strcmp( psz_cmd, "title_n" ) )
666 val.b_bool = VLC_TRUE;
667 var_Set( p_input, "next-title", val );
669 else if( !strcmp( psz_cmd, "title_p" ) )
671 val.b_bool = VLC_TRUE;
672 var_Set( p_input, "prev-title", val );
675 vlc_object_release( p_input );
683 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
684 vlc_value_t oldval, vlc_value_t newval, void *p_data )
686 intf_thread_t *p_intf = (intf_thread_t*)p_this;
687 playlist_t *p_playlist;
689 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
696 /* Parse commands that require a playlist */
697 if( !strcmp( psz_cmd, "prev" ) )
699 playlist_Prev( p_playlist );
701 else if( !strcmp( psz_cmd, "next" ) )
703 playlist_Next( p_playlist );
705 else if( !strcmp( psz_cmd, "play" ) )
707 playlist_Play( p_playlist );
709 else if( !strcmp( psz_cmd, "stop" ) )
711 playlist_Stop( p_playlist );
713 else if( !strcmp( psz_cmd, "add" ) )
715 printf( _("trying to add %s to playlist\n"), newval.psz_string );
716 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
717 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
719 else if( !strcmp( psz_cmd, "playlist" ) )
722 for ( i = 0; i < p_playlist->i_size; i++ )
724 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
725 p_playlist->pp_items[i]->input.psz_name,
726 p_playlist->pp_items[i]->input.psz_uri );
730 printf( _("| no entries\n") );
738 printf( _("unknown command!\n") );
741 vlc_object_release( p_playlist );
745 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
746 vlc_value_t oldval, vlc_value_t newval, void *p_data )
748 p_this->p_vlc->b_die = VLC_TRUE;
752 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
753 vlc_value_t oldval, vlc_value_t newval, void *p_data )
755 intf_thread_t *p_newintf;
757 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
761 p_newintf->b_block = VLC_FALSE;
762 if( intf_RunThread( p_newintf ) )
764 vlc_object_detach( p_newintf );
765 intf_Destroy( p_newintf );
772 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
773 vlc_value_t oldval, vlc_value_t newval, void *p_data )
775 intf_thread_t *p_intf = (intf_thread_t*)p_this;
778 if ( *newval.psz_string )
781 audio_volume_t i_volume = atoi( newval.psz_string );
782 if ( i_volume > AOUT_VOLUME_MAX )
784 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
786 i_error = VLC_EBADVAR;
788 else i_error = aout_VolumeSet( p_this, i_volume );
793 audio_volume_t i_volume;
794 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
796 i_error = VLC_EGENERIC;
800 printf( _("Volume is %d\n"), i_volume );
801 i_error = VLC_SUCCESS;
808 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
809 vlc_value_t oldval, vlc_value_t newval, void *p_data )
811 intf_thread_t *p_intf = (intf_thread_t*)p_this;
812 audio_volume_t i_volume;
813 int i_nb_steps = atoi(newval.psz_string);
814 int i_error = VLC_SUCCESS;
816 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
821 if ( !strcmp(psz_cmd, "volup") )
823 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
824 i_error = VLC_EGENERIC;
828 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
829 i_error = VLC_EGENERIC;
832 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
836 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
837 vlc_value_t oldval, vlc_value_t newval, void *p_data )
839 intf_thread_t *p_intf = (intf_thread_t*)p_this;
840 aout_instance_t * p_aout;
841 const char * psz_variable;
842 vlc_value_t val_name;
845 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
846 if ( p_aout == NULL ) return VLC_ENOOBJ;
848 if ( !strcmp( psz_cmd, "adev" ) )
850 psz_variable = "audio-device";
854 psz_variable = "audio-channels";
857 /* Get the descriptive name of the variable */
858 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
860 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
862 if ( !*newval.psz_string )
864 /* Retrieve all registered ***. */
865 vlc_value_t val, text;
868 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
870 vlc_object_release( (vlc_object_t *)p_aout );
875 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
876 VLC_VAR_GETLIST, &val, &text ) < 0 )
878 vlc_object_release( (vlc_object_t *)p_aout );
882 printf( "+----[ %s ]\n", val_name.psz_string );
883 for ( i = 0; i < val.p_list->i_count; i++ )
885 if ( i_value == val.p_list->p_values[i].i_int )
886 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
887 text.p_list->p_values[i].psz_string );
889 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
890 text.p_list->p_values[i].psz_string );
892 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
894 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
896 if( val_name.psz_string ) free( val_name.psz_string );
897 i_error = VLC_SUCCESS;
902 val.i_int = atoi( newval.psz_string );
904 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
906 vlc_object_release( (vlc_object_t *)p_aout );
912 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
914 INPUT_RECORD input_record;
917 /* On Win32, select() only works on socket descriptors */
918 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
919 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
921 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
922 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
925 if( input_record.EventType != KEY_EVENT ||
926 !input_record.Event.KeyEvent.bKeyDown ||
927 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
928 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
929 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
930 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
932 /* nothing interesting */
936 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
938 /* Echo out the command */
939 putc( p_buffer[ *pi_size ], stdout );
941 /* Handle special keys */
942 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
944 putc( '\n', stdout );
947 switch( p_buffer[ *pi_size ] )
954 putc( '\b', stdout );
965 if( *pi_size == MAX_LINE_LENGTH ||
966 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
968 p_buffer[ *pi_size ] = 0;
977 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
982 if( p_intf->p_sys->i_socket == -1 )
983 return ReadWin32( p_intf, p_buffer, pi_size );
986 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
987 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
988 STDIN_FILENO : p_intf->p_sys->i_socket,
989 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
991 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
997 /* Connection closed */
1000 p_intf->p_sys->i_socket = -1;
1001 p_buffer[ *pi_size ] = 0;
1005 if( *pi_size == MAX_LINE_LENGTH ||
1006 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1008 p_buffer[ *pi_size ] = 0;