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 " \
119 "stream from time to time." )
121 #define TTY_TEXT N_("Fake TTY")
122 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
124 #define UNIX_TEXT N_("UNIX socket command input")
125 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
128 #define HOST_TEXT N_("TCP command input")
129 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
130 "You can set the address and port the interface will bind to." )
133 set_description( _("Remote control interface") );
134 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
136 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
138 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
139 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
140 set_capability( "interface", 20 );
141 set_callbacks( Activate, Deactivate );
144 /*****************************************************************************
145 * Activate: initialize and create stuff
146 *****************************************************************************/
147 static int Activate( vlc_object_t *p_this )
149 intf_thread_t *p_intf = (intf_thread_t*)p_this;
150 char *psz_host, *psz_unix_path;
153 #if defined(HAVE_ISATTY) && !defined(WIN32)
154 /* Check that stdin is a TTY */
155 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
157 msg_Warn( p_intf, "fd 0 is not a TTY" );
162 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
166 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
167 free( psz_unix_path );
170 struct sockaddr_un addr;
173 memset( &addr, 0, sizeof(struct sockaddr_un) );
175 msg_Dbg( p_intf, "trying UNIX socket" );
177 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
179 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
180 free( psz_unix_path );
184 addr.sun_family = AF_LOCAL;
185 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
186 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
188 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
189 sizeof(struct sockaddr_un) ) ) < 0 )
191 msg_Warn( p_intf, "couldn't bind socket to address: %s",
193 free( psz_unix_path );
194 net_Close( i_socket );
198 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
200 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
201 free( psz_unix_path );
202 net_Close( i_socket );
208 if( ( i_socket == -1) &&
209 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
213 vlc_UrlParse( &url, psz_host, 0 );
215 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
217 if( (i_socket = net_ListenTCP(p_this, url.psz_host, url.i_port)) == -1)
219 msg_Warn( p_intf, "can't listen to %s port %i",
220 url.psz_host, url.i_port );
221 vlc_UrlClean( &url );
226 vlc_UrlClean( &url );
230 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
233 msg_Err( p_intf, "no memory" );
237 p_intf->p_sys->i_socket_listen = i_socket;
238 p_intf->p_sys->i_socket = -1;
239 p_intf->p_sys->psz_unix_path = psz_unix_path;
241 /* Non-buffered stdout */
242 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
244 p_intf->pf_run = Run;
248 printf( _("Remote control interface initialized, `h' for help\n") );
252 /*****************************************************************************
253 * Deactivate: uninitialize and cleanup
254 *****************************************************************************/
255 static void Deactivate( vlc_object_t *p_this )
257 intf_thread_t *p_intf = (intf_thread_t*)p_this;
259 if( p_intf->p_sys->i_socket_listen != -1 )
260 net_Close( p_intf->p_sys->i_socket_listen );
261 if( p_intf->p_sys->i_socket != -1 )
262 net_Close( p_intf->p_sys->i_socket );
263 if( p_intf->p_sys->psz_unix_path != NULL )
266 unlink( p_intf->p_sys->psz_unix_path );
268 free( p_intf->p_sys->psz_unix_path );
270 free( p_intf->p_sys );
273 /*****************************************************************************
275 *****************************************************************************
276 * This part of the interface is in a separate thread so that we can call
277 * exec() from within it without annoying the rest of the program.
278 *****************************************************************************/
279 static void Run( intf_thread_t *p_intf )
281 input_thread_t * p_input;
282 playlist_t * p_playlist;
284 char p_buffer[ MAX_LINE_LENGTH + 1 ];
285 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
295 /* Register commands that will be cleaned up upon object destruction */
296 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
297 var_AddCallback( p_intf, "quit", Quit, NULL );
298 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
299 var_AddCallback( p_intf, "intf", Intf, NULL );
301 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
302 var_AddCallback( p_intf, "add", Playlist, NULL );
303 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
304 var_AddCallback( p_intf, "playlist", Playlist, NULL );
305 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
306 var_AddCallback( p_intf, "play", Playlist, NULL );
307 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
308 var_AddCallback( p_intf, "stop", Playlist, NULL );
309 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
310 var_AddCallback( p_intf, "prev", Playlist, NULL );
311 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
312 var_AddCallback( p_intf, "next", Playlist, NULL );
314 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
315 var_AddCallback( p_intf, "pause", Input, NULL );
316 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
317 var_AddCallback( p_intf, "seek", Input, NULL );
318 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
319 var_AddCallback( p_intf, "title", Input, NULL );
320 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
321 var_AddCallback( p_intf, "title_n", Input, NULL );
322 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
323 var_AddCallback( p_intf, "title_p", Input, NULL );
324 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
325 var_AddCallback( p_intf, "chapter", Input, NULL );
326 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
327 var_AddCallback( p_intf, "chapter_n", Input, NULL );
328 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
329 var_AddCallback( p_intf, "chapter_p", Input, NULL );
331 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
332 var_AddCallback( p_intf, "volume", Volume, NULL );
333 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
334 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
335 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
336 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
337 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
338 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
339 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
340 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
343 /* Get the file descriptor of the console input */
344 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
345 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
347 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
348 p_intf->b_die = VLC_TRUE;
352 while( !p_intf->b_die )
354 char *psz_cmd, *psz_arg;
355 vlc_bool_t b_complete;
357 if( p_intf->p_sys->i_socket_listen != - 1 &&
358 p_intf->p_sys->i_socket == -1 )
360 p_intf->p_sys->i_socket =
361 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
364 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
366 /* Manage the input part */
367 if( p_input == NULL )
371 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
376 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
380 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
385 else if( p_input->b_dead )
387 vlc_object_release( p_input );
391 if( p_input && b_showpos )
393 i_newpos = 100 * var_GetFloat( p_input, "position" );
394 if( i_oldpos != i_newpos )
397 printf( "pos: %d%%\n", i_newpos );
401 /* Is there something to do? */
402 if( !b_complete ) continue;
405 /* Skip heading spaces */
407 while( *psz_cmd == ' ' )
412 /* Split psz_cmd at the first space and make sure that
413 * psz_arg is valid */
414 psz_arg = strchr( psz_cmd, ' ' );
418 while( *psz_arg == ' ' )
428 /* If the user typed a registered local command, try it */
429 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
434 val.psz_string = psz_arg;
435 i_ret = var_Set( p_intf, psz_cmd, val );
436 printf( _("%s: returned %i (%s)\n"),
437 psz_cmd, i_ret, vlc_error( i_ret ) );
439 /* Or maybe it's a global command */
440 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
445 val.psz_string = psz_arg;
446 /* FIXME: it's a global command, but we should pass the
447 * local object as an argument, not p_intf->p_libvlc. */
448 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
451 printf( _("%s: returned %i (%s)\n"),
452 psz_cmd, i_ret, vlc_error( i_ret ) );
455 else if( !strcmp( psz_cmd, "info" ) )
460 vlc_mutex_lock( &p_input->input.p_item->lock );
461 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
463 info_category_t *p_category =
464 p_input->input.p_item->pp_categories[i];
466 printf( "+----[ %s ]\n", p_category->psz_name );
468 for ( j = 0; j < p_category->i_infos; j++ )
470 info_t *p_info = p_category->pp_infos[j];
471 printf( "| %s: %s\n", p_info->psz_name,
476 printf( _("+----[ end of stream info ]\n") );
477 vlc_mutex_unlock( &p_input->input.p_item->lock );
481 printf( _("no input\n") );
484 else if( !strcmp( psz_cmd, "is_playing" ) )
495 else if( !strcmp( psz_cmd, "get_time" ) )
504 var_Get( p_input, "time", &time );
505 printf( "%i\n", time.i_time / 1000000);
508 else if( !strcmp( psz_cmd, "get_length" ) )
517 var_Get( p_input, "length", &time );
518 printf( "%i\n", time.i_time / 1000000);
521 else if( !strcmp( psz_cmd, "get_title" ) )
529 printf( "%s\n", p_input->input.p_item->psz_name );
532 else switch( psz_cmd[0] )
538 vout_thread_t *p_vout;
539 p_vout = vlc_object_find( p_input,
540 VLC_OBJECT_VOUT, FIND_CHILD );
544 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
545 vlc_object_release( p_vout );
558 printf(_("+----[ Remote control commands ]\n"));
560 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
561 printf(_("| playlist . . . show items currently in playlist\n"));
562 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
563 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
564 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
565 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
566 printf(_("| title [X] . . . . set/get title in current item\n"));
567 printf(_("| title_n . . . . . . next title in current item\n"));
568 printf(_("| title_p . . . . previous title in current item\n"));
569 printf(_("| chapter [X] . . set/get chapter in current item\n"));
570 printf(_("| chapter_n . . . . next chapter in current item\n"));
571 printf(_("| chapter_p . . previous chapter in current item\n"));
573 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
574 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
575 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
576 printf(_("| info . . . information about the current stream\n"));
578 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
579 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
580 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
581 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
582 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
584 printf(_("| help . . . . . . . . . . . . . this help message\n"));
585 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
587 printf(_("+----[ end of help ]\n"));
591 /* Ignore empty lines */
595 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
599 /* Command processed */
600 i_size = 0; p_buffer[0] = 0;
605 vlc_object_release( p_input );
611 vlc_object_release( p_playlist );
616 static int Input( vlc_object_t *p_this, char const *psz_cmd,
617 vlc_value_t oldval, vlc_value_t newval, void *p_data )
619 intf_thread_t *p_intf = (intf_thread_t*)p_this;
620 input_thread_t *p_input;
623 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
624 if( !p_input ) return VLC_ENOOBJ;
626 /* Parse commands that only require an input */
627 if( !strcmp( psz_cmd, "pause" ) )
631 var_Set( p_input, "state", val );
632 vlc_object_release( p_input );
635 else if( !strcmp( psz_cmd, "seek" ) )
637 if( strlen( newval.psz_string ) > 0 &&
638 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
640 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
641 var_Set( p_input, "position", val );
645 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
646 var_Set( p_input, "time", val );
648 vlc_object_release( p_input );
651 else if( !strcmp( psz_cmd, "chapter" ) ||
652 !strcmp( psz_cmd, "chapter_n" ) ||
653 !strcmp( psz_cmd, "chapter_p" ) )
655 if( !strcmp( psz_cmd, "chapter" ) )
657 if ( *newval.psz_string )
660 val.i_int = atoi( newval.psz_string );
661 var_Set( p_input, "chapter", val );
665 vlc_value_t val_list;
668 var_Get( p_input, "chapter", &val );
669 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
671 printf( _("Currently playing chapter %d/%d\n"),
672 val.i_int, val_list.p_list->i_count );
673 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
677 else if( !strcmp( psz_cmd, "chapter_n" ) )
679 val.b_bool = VLC_TRUE;
680 var_Set( p_input, "next-chapter", val );
682 else if( !strcmp( psz_cmd, "chapter_p" ) )
684 val.b_bool = VLC_TRUE;
685 var_Set( p_input, "prev-chapter", val );
688 vlc_object_release( p_input );
691 else if( !strcmp( psz_cmd, "title" ) ||
692 !strcmp( psz_cmd, "title_n" ) ||
693 !strcmp( psz_cmd, "title_p" ) )
695 if( !strcmp( psz_cmd, "title" ) )
697 if ( *newval.psz_string )
700 val.i_int = atoi( newval.psz_string );
701 var_Set( p_input, "title", val );
705 vlc_value_t val_list;
708 var_Get( p_input, "title", &val );
709 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
711 printf( _("Currently playing title %d/%d\n"),
712 val.i_int, val_list.p_list->i_count );
713 var_Change( p_this, "title", VLC_VAR_FREELIST,
717 else if( !strcmp( psz_cmd, "title_n" ) )
719 val.b_bool = VLC_TRUE;
720 var_Set( p_input, "next-title", val );
722 else if( !strcmp( psz_cmd, "title_p" ) )
724 val.b_bool = VLC_TRUE;
725 var_Set( p_input, "prev-title", val );
728 vlc_object_release( p_input );
736 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
737 vlc_value_t oldval, vlc_value_t newval, void *p_data )
739 intf_thread_t *p_intf = (intf_thread_t*)p_this;
740 playlist_t *p_playlist;
742 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
749 /* Parse commands that require a playlist */
750 if( !strcmp( psz_cmd, "prev" ) )
752 playlist_Prev( p_playlist );
754 else if( !strcmp( psz_cmd, "next" ) )
756 playlist_Next( p_playlist );
758 else if( !strcmp( psz_cmd, "play" ) )
760 playlist_Play( p_playlist );
762 else if( !strcmp( psz_cmd, "stop" ) )
764 playlist_Stop( p_playlist );
766 else if( !strcmp( psz_cmd, "add" ) )
768 printf( _("trying to add %s to playlist\n"), newval.psz_string );
769 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
770 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
772 else if( !strcmp( psz_cmd, "playlist" ) )
775 for ( i = 0; i < p_playlist->i_size; i++ )
777 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
778 p_playlist->pp_items[i]->input.psz_name,
779 p_playlist->pp_items[i]->input.psz_uri );
783 printf( _("| no entries\n") );
791 printf( _("unknown command!\n") );
794 vlc_object_release( p_playlist );
798 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
799 vlc_value_t oldval, vlc_value_t newval, void *p_data )
801 p_this->p_vlc->b_die = VLC_TRUE;
805 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
806 vlc_value_t oldval, vlc_value_t newval, void *p_data )
808 intf_thread_t *p_newintf;
810 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
814 p_newintf->b_block = VLC_FALSE;
815 if( intf_RunThread( p_newintf ) )
817 vlc_object_detach( p_newintf );
818 intf_Destroy( p_newintf );
825 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
826 vlc_value_t oldval, vlc_value_t newval, void *p_data )
828 intf_thread_t *p_intf = (intf_thread_t*)p_this;
831 if ( *newval.psz_string )
834 audio_volume_t i_volume = atoi( newval.psz_string );
835 if ( i_volume > AOUT_VOLUME_MAX )
837 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
839 i_error = VLC_EBADVAR;
841 else i_error = aout_VolumeSet( p_this, i_volume );
846 audio_volume_t i_volume;
847 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
849 i_error = VLC_EGENERIC;
853 printf( _("Volume is %d\n"), i_volume );
854 i_error = VLC_SUCCESS;
861 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
862 vlc_value_t oldval, vlc_value_t newval, void *p_data )
864 intf_thread_t *p_intf = (intf_thread_t*)p_this;
865 audio_volume_t i_volume;
866 int i_nb_steps = atoi(newval.psz_string);
867 int i_error = VLC_SUCCESS;
869 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
874 if ( !strcmp(psz_cmd, "volup") )
876 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
877 i_error = VLC_EGENERIC;
881 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
882 i_error = VLC_EGENERIC;
885 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
889 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
890 vlc_value_t oldval, vlc_value_t newval, void *p_data )
892 intf_thread_t *p_intf = (intf_thread_t*)p_this;
893 aout_instance_t * p_aout;
894 const char * psz_variable;
895 vlc_value_t val_name;
898 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
899 if ( p_aout == NULL ) return VLC_ENOOBJ;
901 if ( !strcmp( psz_cmd, "adev" ) )
903 psz_variable = "audio-device";
907 psz_variable = "audio-channels";
910 /* Get the descriptive name of the variable */
911 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
913 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
915 if ( !*newval.psz_string )
917 /* Retrieve all registered ***. */
918 vlc_value_t val, text;
921 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
923 vlc_object_release( (vlc_object_t *)p_aout );
928 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
929 VLC_VAR_GETLIST, &val, &text ) < 0 )
931 vlc_object_release( (vlc_object_t *)p_aout );
935 printf( "+----[ %s ]\n", val_name.psz_string );
936 for ( i = 0; i < val.p_list->i_count; i++ )
938 if ( i_value == val.p_list->p_values[i].i_int )
939 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
940 text.p_list->p_values[i].psz_string );
942 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
943 text.p_list->p_values[i].psz_string );
945 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
947 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
949 if( val_name.psz_string ) free( val_name.psz_string );
950 i_error = VLC_SUCCESS;
955 val.i_int = atoi( newval.psz_string );
957 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
959 vlc_object_release( (vlc_object_t *)p_aout );
965 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
967 INPUT_RECORD input_record;
970 /* On Win32, select() only works on socket descriptors */
971 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
972 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
974 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
975 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
978 if( input_record.EventType != KEY_EVENT ||
979 !input_record.Event.KeyEvent.bKeyDown ||
980 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
981 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
982 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
983 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
985 /* nothing interesting */
989 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
991 /* Echo out the command */
992 putc( p_buffer[ *pi_size ], stdout );
994 /* Handle special keys */
995 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
997 putc( '\n', stdout );
1000 switch( p_buffer[ *pi_size ] )
1006 putc( ' ', stdout );
1007 putc( '\b', stdout );
1018 if( *pi_size == MAX_LINE_LENGTH ||
1019 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1021 p_buffer[ *pi_size ] = 0;
1030 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1035 if( p_intf->p_sys->i_socket == -1 )
1036 return ReadWin32( p_intf, p_buffer, pi_size );
1039 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1040 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1041 STDIN_FILENO : p_intf->p_sys->i_socket,
1042 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1044 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1050 /* Connection closed */
1053 p_intf->p_sys->i_socket = -1;
1054 p_buffer[ *pi_size ] = 0;
1058 if( *pi_size == MAX_LINE_LENGTH ||
1059 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1061 p_buffer[ *pi_size ] = 0;