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 memset( &url, 0, sizeof(vlc_url_t) );
213 /* If it doesn't include a :, it's a port number rather than an URL */
214 if( strchr( psz_host, ':' ) ) vlc_UrlParse( &url, psz_host, 0 );
215 else url.i_port = atoi( psz_host );
217 /* By default, we listen on localhost only for security reasons.
218 * If you need to listen on all IP addresses, specify 0.0.0.0
220 if( url.psz_host != NULL )
222 psz_addr = url.psz_host;
226 /* Default to IPv4 for now.
227 * FIXME: should try both IPv4 and IPv6.
231 var_Create( p_this, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
232 var_Get( p_this, "ipv6", &val );
233 psz_addr = val.b_bool ? "::1" : "127.0.0.1";
236 msg_Dbg( p_intf, "base %s port %d", psz_addr, url.i_port );
238 if( (i_socket = net_ListenTCP( p_this, psz_addr, url.i_port )) == -1 )
240 msg_Warn( p_intf, "can't listen to %s port %i", psz_addr,
242 vlc_UrlClean( &url );
247 vlc_UrlClean( &url );
251 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
254 msg_Err( p_intf, "no memory" );
258 p_intf->p_sys->i_socket_listen = i_socket;
259 p_intf->p_sys->i_socket = -1;
260 p_intf->p_sys->psz_unix_path = psz_unix_path;
262 /* Non-buffered stdout */
263 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
265 p_intf->pf_run = Run;
269 printf( _("Remote control interface initialized, `h' for help\n") );
273 /*****************************************************************************
274 * Deactivate: uninitialize and cleanup
275 *****************************************************************************/
276 static void Deactivate( vlc_object_t *p_this )
278 intf_thread_t *p_intf = (intf_thread_t*)p_this;
280 if( p_intf->p_sys->i_socket_listen != -1 )
281 net_Close( p_intf->p_sys->i_socket_listen );
282 if( p_intf->p_sys->i_socket != -1 )
283 net_Close( p_intf->p_sys->i_socket );
284 if( p_intf->p_sys->psz_unix_path != NULL )
287 unlink( p_intf->p_sys->psz_unix_path );
289 free( p_intf->p_sys->psz_unix_path );
291 free( p_intf->p_sys );
294 /*****************************************************************************
296 *****************************************************************************
297 * This part of the interface is in a separate thread so that we can call
298 * exec() from within it without annoying the rest of the program.
299 *****************************************************************************/
300 static void Run( intf_thread_t *p_intf )
302 input_thread_t * p_input;
303 playlist_t * p_playlist;
305 char p_buffer[ MAX_LINE_LENGTH + 1 ];
306 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
316 /* Register commands that will be cleaned up upon object destruction */
317 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
318 var_AddCallback( p_intf, "quit", Quit, NULL );
319 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
320 var_AddCallback( p_intf, "intf", Intf, NULL );
322 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
323 var_AddCallback( p_intf, "add", Playlist, NULL );
324 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
325 var_AddCallback( p_intf, "playlist", Playlist, NULL );
326 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
327 var_AddCallback( p_intf, "play", Playlist, NULL );
328 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
329 var_AddCallback( p_intf, "stop", Playlist, NULL );
330 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
331 var_AddCallback( p_intf, "prev", Playlist, NULL );
332 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
333 var_AddCallback( p_intf, "next", Playlist, NULL );
335 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
336 var_AddCallback( p_intf, "pause", Input, NULL );
337 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
338 var_AddCallback( p_intf, "seek", Input, NULL );
339 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
340 var_AddCallback( p_intf, "title", Input, NULL );
341 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
342 var_AddCallback( p_intf, "title_n", Input, NULL );
343 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
344 var_AddCallback( p_intf, "title_p", Input, NULL );
345 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
346 var_AddCallback( p_intf, "chapter", Input, NULL );
347 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
348 var_AddCallback( p_intf, "chapter_n", Input, NULL );
349 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
350 var_AddCallback( p_intf, "chapter_p", Input, NULL );
352 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
353 var_AddCallback( p_intf, "volume", Volume, NULL );
354 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
355 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
356 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
357 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
358 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
359 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
360 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
361 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
364 /* Get the file descriptor of the console input */
365 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
366 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
368 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
369 p_intf->b_die = VLC_TRUE;
373 while( !p_intf->b_die )
375 char *psz_cmd, *psz_arg;
376 vlc_bool_t b_complete;
378 if( p_intf->p_sys->i_socket_listen != - 1 &&
379 p_intf->p_sys->i_socket == -1 )
381 p_intf->p_sys->i_socket =
382 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
385 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
387 /* Manage the input part */
388 if( p_input == NULL )
392 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
397 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
401 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
406 else if( p_input->b_dead )
408 vlc_object_release( p_input );
412 if( p_input && b_showpos )
414 i_newpos = 100 * var_GetFloat( p_input, "position" );
415 if( i_oldpos != i_newpos )
418 printf( "pos: %d%%\n", i_newpos );
422 /* Is there something to do? */
423 if( !b_complete ) continue;
426 /* Skip heading spaces */
428 while( *psz_cmd == ' ' )
433 /* Split psz_cmd at the first space and make sure that
434 * psz_arg is valid */
435 psz_arg = strchr( psz_cmd, ' ' );
439 while( *psz_arg == ' ' )
449 /* If the user typed a registered local command, try it */
450 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
455 val.psz_string = psz_arg;
456 i_ret = var_Set( p_intf, psz_cmd, val );
457 printf( _("%s: returned %i (%s)\n"),
458 psz_cmd, i_ret, vlc_error( i_ret ) );
460 /* Or maybe it's a global command */
461 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
466 val.psz_string = psz_arg;
467 /* FIXME: it's a global command, but we should pass the
468 * local object as an argument, not p_intf->p_libvlc. */
469 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
470 printf( _("%s: returned %i (%s)\n"),
471 psz_cmd, i_ret, vlc_error( i_ret ) );
473 else if( !strcmp( psz_cmd, "info" ) )
478 vlc_mutex_lock( &p_input->input.p_item->lock );
479 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
481 info_category_t *p_category =
482 p_input->input.p_item->pp_categories[i];
484 printf( "+----[ %s ]\n", p_category->psz_name );
486 for ( j = 0; j < p_category->i_infos; j++ )
488 info_t *p_info = p_category->pp_infos[j];
489 printf( "| %s: %s\n", p_info->psz_name,
494 printf( _("+----[ end of stream info ]\n") );
495 vlc_mutex_unlock( &p_input->input.p_item->lock );
499 printf( _("no input\n") );
502 else switch( psz_cmd[0] )
508 vout_thread_t *p_vout;
509 p_vout = vlc_object_find( p_input,
510 VLC_OBJECT_VOUT, FIND_CHILD );
514 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
515 vlc_object_release( p_vout );
528 printf(_("+----[ Remote control commands ]\n"));
530 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
531 printf(_("| playlist . . . show items currently in playlist\n"));
532 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
533 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
534 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
535 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
536 printf(_("| title [X] . . . . set/get title in current item\n"));
537 printf(_("| title_n . . . . . . next title in current item\n"));
538 printf(_("| title_p . . . . previous title in current item\n"));
539 printf(_("| chapter [X] . . set/get chapter in current item\n"));
540 printf(_("| chapter_n . . . . next chapter in current item\n"));
541 printf(_("| chapter_p . . previous chapter in current item\n"));
543 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
544 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
545 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
546 printf(_("| info . . . information about the current stream\n"));
548 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
549 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
550 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
551 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
552 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
554 printf(_("| help . . . . . . . . . . . . . this help message\n"));
555 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
557 printf(_("+----[ end of help ]\n"));
561 /* Ignore empty lines */
565 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
569 /* Command processed */
570 i_size = 0; p_buffer[0] = 0;
575 vlc_object_release( p_input );
581 vlc_object_release( p_playlist );
586 static int Input( vlc_object_t *p_this, char const *psz_cmd,
587 vlc_value_t oldval, vlc_value_t newval, void *p_data )
589 intf_thread_t *p_intf = (intf_thread_t*)p_this;
590 input_thread_t *p_input;
593 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
594 if( !p_input ) return VLC_ENOOBJ;
596 /* Parse commands that only require an input */
597 if( !strcmp( psz_cmd, "pause" ) )
601 var_Set( p_input, "state", val );
602 vlc_object_release( p_input );
605 else if( !strcmp( psz_cmd, "seek" ) )
607 if( strlen( newval.psz_string ) > 0 &&
608 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
610 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
611 var_Set( p_input, "position", val );
615 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
616 var_Set( p_input, "time", val );
618 vlc_object_release( p_input );
621 else if( !strcmp( psz_cmd, "chapter" ) ||
622 !strcmp( psz_cmd, "chapter_n" ) ||
623 !strcmp( psz_cmd, "chapter_p" ) )
625 if( !strcmp( psz_cmd, "chapter" ) )
627 if ( *newval.psz_string )
630 val.i_int = atoi( newval.psz_string );
631 var_Set( p_input, "chapter", val );
635 vlc_value_t val_list;
638 var_Get( p_input, "chapter", &val );
639 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
641 printf( _("Currently playing chapter %d/%d\n"),
642 val.i_int, val_list.p_list->i_count );
643 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
647 else if( !strcmp( psz_cmd, "chapter_n" ) )
649 val.b_bool = VLC_TRUE;
650 var_Set( p_input, "next-chapter", val );
652 else if( !strcmp( psz_cmd, "chapter_p" ) )
654 val.b_bool = VLC_TRUE;
655 var_Set( p_input, "prev-chapter", val );
658 vlc_object_release( p_input );
661 else if( !strcmp( psz_cmd, "title" ) ||
662 !strcmp( psz_cmd, "title_n" ) ||
663 !strcmp( psz_cmd, "title_p" ) )
665 if( !strcmp( psz_cmd, "title" ) )
667 if ( *newval.psz_string )
670 val.i_int = atoi( newval.psz_string );
671 var_Set( p_input, "title", val );
675 vlc_value_t val_list;
678 var_Get( p_input, "title", &val );
679 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
681 printf( _("Currently playing title %d/%d\n"),
682 val.i_int, val_list.p_list->i_count );
683 var_Change( p_this, "title", VLC_VAR_FREELIST,
687 else if( !strcmp( psz_cmd, "title_n" ) )
689 val.b_bool = VLC_TRUE;
690 var_Set( p_input, "next-title", val );
692 else if( !strcmp( psz_cmd, "title_p" ) )
694 val.b_bool = VLC_TRUE;
695 var_Set( p_input, "prev-title", val );
698 vlc_object_release( p_input );
706 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
707 vlc_value_t oldval, vlc_value_t newval, void *p_data )
709 intf_thread_t *p_intf = (intf_thread_t*)p_this;
710 playlist_t *p_playlist;
712 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
719 /* Parse commands that require a playlist */
720 if( !strcmp( psz_cmd, "prev" ) )
722 playlist_Prev( p_playlist );
724 else if( !strcmp( psz_cmd, "next" ) )
726 playlist_Next( p_playlist );
728 else if( !strcmp( psz_cmd, "play" ) )
730 playlist_Play( p_playlist );
732 else if( !strcmp( psz_cmd, "stop" ) )
734 playlist_Stop( p_playlist );
736 else if( !strcmp( psz_cmd, "add" ) )
738 printf( _("trying to add %s to playlist\n"), newval.psz_string );
739 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
740 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
742 else if( !strcmp( psz_cmd, "playlist" ) )
745 for ( i = 0; i < p_playlist->i_size; i++ )
747 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
748 p_playlist->pp_items[i]->input.psz_name,
749 p_playlist->pp_items[i]->input.psz_uri );
753 printf( _("| no entries\n") );
761 printf( _("unknown command!\n") );
764 vlc_object_release( p_playlist );
768 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
769 vlc_value_t oldval, vlc_value_t newval, void *p_data )
771 p_this->p_vlc->b_die = VLC_TRUE;
775 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
776 vlc_value_t oldval, vlc_value_t newval, void *p_data )
778 intf_thread_t *p_newintf;
780 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
784 p_newintf->b_block = VLC_FALSE;
785 if( intf_RunThread( p_newintf ) )
787 vlc_object_detach( p_newintf );
788 intf_Destroy( p_newintf );
795 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
796 vlc_value_t oldval, vlc_value_t newval, void *p_data )
798 intf_thread_t *p_intf = (intf_thread_t*)p_this;
801 if ( *newval.psz_string )
804 audio_volume_t i_volume = atoi( newval.psz_string );
805 if ( i_volume > AOUT_VOLUME_MAX )
807 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
809 i_error = VLC_EBADVAR;
811 else i_error = aout_VolumeSet( p_this, i_volume );
816 audio_volume_t i_volume;
817 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
819 i_error = VLC_EGENERIC;
823 printf( _("Volume is %d\n"), i_volume );
824 i_error = VLC_SUCCESS;
831 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
832 vlc_value_t oldval, vlc_value_t newval, void *p_data )
834 intf_thread_t *p_intf = (intf_thread_t*)p_this;
835 audio_volume_t i_volume;
836 int i_nb_steps = atoi(newval.psz_string);
837 int i_error = VLC_SUCCESS;
839 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
844 if ( !strcmp(psz_cmd, "volup") )
846 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
847 i_error = VLC_EGENERIC;
851 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
852 i_error = VLC_EGENERIC;
855 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
859 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
860 vlc_value_t oldval, vlc_value_t newval, void *p_data )
862 intf_thread_t *p_intf = (intf_thread_t*)p_this;
863 aout_instance_t * p_aout;
864 const char * psz_variable;
865 vlc_value_t val_name;
868 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
869 if ( p_aout == NULL ) return VLC_ENOOBJ;
871 if ( !strcmp( psz_cmd, "adev" ) )
873 psz_variable = "audio-device";
877 psz_variable = "audio-channels";
880 /* Get the descriptive name of the variable */
881 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
883 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
885 if ( !*newval.psz_string )
887 /* Retrieve all registered ***. */
888 vlc_value_t val, text;
891 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
893 vlc_object_release( (vlc_object_t *)p_aout );
898 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
899 VLC_VAR_GETLIST, &val, &text ) < 0 )
901 vlc_object_release( (vlc_object_t *)p_aout );
905 printf( "+----[ %s ]\n", val_name.psz_string );
906 for ( i = 0; i < val.p_list->i_count; i++ )
908 if ( i_value == val.p_list->p_values[i].i_int )
909 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
910 text.p_list->p_values[i].psz_string );
912 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
913 text.p_list->p_values[i].psz_string );
915 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
917 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
919 if( val_name.psz_string ) free( val_name.psz_string );
920 i_error = VLC_SUCCESS;
925 val.i_int = atoi( newval.psz_string );
927 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
929 vlc_object_release( (vlc_object_t *)p_aout );
935 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
937 INPUT_RECORD input_record;
940 /* On Win32, select() only works on socket descriptors */
941 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
942 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
944 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
945 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
948 if( input_record.EventType != KEY_EVENT ||
949 !input_record.Event.KeyEvent.bKeyDown ||
950 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
951 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
952 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
953 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
955 /* nothing interesting */
959 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
961 /* Echo out the command */
962 putc( p_buffer[ *pi_size ], stdout );
964 /* Handle special keys */
965 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
967 putc( '\n', stdout );
970 switch( p_buffer[ *pi_size ] )
977 putc( '\b', stdout );
988 if( *pi_size == MAX_LINE_LENGTH ||
989 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
991 p_buffer[ *pi_size ] = 0;
1000 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1005 if( p_intf->p_sys->i_socket == -1 )
1006 return ReadWin32( p_intf, p_buffer, pi_size );
1009 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1010 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1011 STDIN_FILENO : p_intf->p_sys->i_socket,
1012 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1014 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1020 /* Connection closed */
1023 p_intf->p_sys->i_socket = -1;
1024 p_buffer[ *pi_size ] = 0;
1028 if( *pi_size == MAX_LINE_LENGTH ||
1029 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1031 p_buffer[ *pi_size ] = 0;