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, "marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
315 var_AddCallback( p_intf, "marquee", Input, NULL );
316 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
317 var_AddCallback( p_intf, "marq-x", Input, NULL );
318 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
319 var_AddCallback( p_intf, "marq-y", Input, NULL );
321 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
322 var_AddCallback( p_intf, "pause", Input, NULL );
323 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
324 var_AddCallback( p_intf, "seek", Input, NULL );
325 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
326 var_AddCallback( p_intf, "title", Input, NULL );
327 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
328 var_AddCallback( p_intf, "title_n", Input, NULL );
329 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
330 var_AddCallback( p_intf, "title_p", Input, NULL );
331 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
332 var_AddCallback( p_intf, "chapter", Input, NULL );
333 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
334 var_AddCallback( p_intf, "chapter_n", Input, NULL );
335 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
336 var_AddCallback( p_intf, "chapter_p", Input, NULL );
338 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
339 var_AddCallback( p_intf, "volume", Volume, NULL );
340 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
341 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
342 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
343 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
344 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
345 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
346 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
347 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
350 /* Get the file descriptor of the console input */
351 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
352 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
354 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
355 p_intf->b_die = VLC_TRUE;
359 while( !p_intf->b_die )
361 char *psz_cmd, *psz_arg;
362 vlc_bool_t b_complete;
364 if( p_intf->p_sys->i_socket_listen != - 1 &&
365 p_intf->p_sys->i_socket == -1 )
367 p_intf->p_sys->i_socket =
368 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
371 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
373 /* Manage the input part */
374 if( p_input == NULL )
378 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
383 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
387 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
392 else if( p_input->b_dead )
394 vlc_object_release( p_input );
398 if( p_input && b_showpos )
400 i_newpos = 100 * var_GetFloat( p_input, "position" );
401 if( i_oldpos != i_newpos )
404 printf( "pos: %d%%\n", i_newpos );
408 /* Is there something to do? */
409 if( !b_complete ) continue;
412 /* Skip heading spaces */
414 while( *psz_cmd == ' ' )
419 /* Split psz_cmd at the first space and make sure that
420 * psz_arg is valid */
421 psz_arg = strchr( psz_cmd, ' ' );
425 while( *psz_arg == ' ' )
435 /* If the user typed a registered local command, try it */
436 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
441 val.psz_string = psz_arg;
442 i_ret = var_Set( p_intf, psz_cmd, val );
443 printf( _("%s: returned %i (%s)\n"),
444 psz_cmd, i_ret, vlc_error( i_ret ) );
446 /* Or maybe it's a global command */
447 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
452 val.psz_string = psz_arg;
453 /* FIXME: it's a global command, but we should pass the
454 * local object as an argument, not p_intf->p_libvlc. */
455 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
458 printf( _("%s: returned %i (%s)\n"),
459 psz_cmd, i_ret, vlc_error( i_ret ) );
462 else if( !strcmp( psz_cmd, "info" ) )
467 vlc_mutex_lock( &p_input->input.p_item->lock );
468 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
470 info_category_t *p_category =
471 p_input->input.p_item->pp_categories[i];
473 printf( "+----[ %s ]\n", p_category->psz_name );
475 for ( j = 0; j < p_category->i_infos; j++ )
477 info_t *p_info = p_category->pp_infos[j];
478 printf( "| %s: %s\n", p_info->psz_name,
483 printf( _("+----[ end of stream info ]\n") );
484 vlc_mutex_unlock( &p_input->input.p_item->lock );
488 printf( _("no input\n") );
491 else if( !strcmp( psz_cmd, "is_playing" ) )
502 else if( !strcmp( psz_cmd, "get_time" ) )
511 var_Get( p_input, "time", &time );
512 printf( "%i\n", time.i_time / 1000000);
515 else if( !strcmp( psz_cmd, "get_length" ) )
524 var_Get( p_input, "length", &time );
525 printf( "%i\n", time.i_time / 1000000);
528 else if( !strcmp( psz_cmd, "get_title" ) )
536 printf( "%s\n", p_input->input.p_item->psz_name );
539 else switch( psz_cmd[0] )
545 vout_thread_t *p_vout;
546 p_vout = vlc_object_find( p_input,
547 VLC_OBJECT_VOUT, FIND_CHILD );
551 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
552 vlc_object_release( p_vout );
565 printf(_("+----[ Remote control commands ]\n"));
567 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
568 printf(_("| playlist . . . show items currently in playlist\n"));
569 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
570 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
571 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
572 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
573 printf(_("| title [X] . . . . set/get title in current item\n"));
574 printf(_("| title_n . . . . . . next title in current item\n"));
575 printf(_("| title_p . . . . previous title in current item\n"));
576 printf(_("| chapter [X] . . set/get chapter in current item\n"));
577 printf(_("| chapter_n . . . . next chapter in current item\n"));
578 printf(_("| chapter_p . . previous chapter in current item\n"));
580 printf(_("| marquee STRING . . . . . overlay STRING in video\n"));
581 printf(_("| marq-x X . . . . . .offset of marquee, from left\n"));
582 printf(_("| marq-y Y . . . . . . offset of marquee, from top\n"));
584 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
585 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
586 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
587 printf(_("| info . . . information about the current stream\n"));
589 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
590 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
591 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
592 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
593 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
595 printf(_("| help . . . . . . . . . . . . . this help message\n"));
596 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
598 printf(_("+----[ end of help ]\n"));
602 /* Ignore empty lines */
606 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
610 /* Command processed */
611 i_size = 0; p_buffer[0] = 0;
616 vlc_object_release( p_input );
622 vlc_object_release( p_playlist );
627 static int Input( vlc_object_t *p_this, char const *psz_cmd,
628 vlc_value_t oldval, vlc_value_t newval, void *p_data )
630 intf_thread_t *p_intf = (intf_thread_t*)p_this;
631 input_thread_t *p_input;
634 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
635 if( !p_input ) return VLC_ENOOBJ;
637 /* Parse commands that only require an input */
638 if( !strcmp( psz_cmd, "pause" ) )
642 var_Set( p_input, "state", val );
643 vlc_object_release( p_input );
646 else if( !strcmp( psz_cmd, "seek" ) )
648 if( strlen( newval.psz_string ) > 0 &&
649 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
651 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
652 var_Set( p_input, "position", val );
656 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
657 var_Set( p_input, "time", val );
659 vlc_object_release( p_input );
662 else if( !strcmp( psz_cmd, "marquee" ) )
664 if( strlen( newval.psz_string ) > 0 )
666 val.psz_string = newval.psz_string;
667 /* check for the playlist structure */
669 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
674 var_Set( p_pl, "marquee", val );
675 vlc_object_release( p_pl );
677 vlc_object_release( p_input );
680 else if( !strcmp( psz_cmd, "marq-x" ) )
682 if( strlen( newval.psz_string ) > 0)
685 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
690 val.i_int = atoi( newval.psz_string );
691 var_Set( p_pl, "marq-x", val );
692 vlc_object_release( p_pl );
694 vlc_object_release( p_input );
697 else if( !strcmp( psz_cmd, "marq-y" ) )
699 if( strlen( newval.psz_string ) > 0)
702 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
707 val.i_int = atoi( newval.psz_string );
708 var_Set( p_pl, "marq-y", val );
709 vlc_object_release( p_pl );
711 vlc_object_release( p_input );
715 else if( !strcmp( psz_cmd, "chapter" ) ||
716 !strcmp( psz_cmd, "chapter_n" ) ||
717 !strcmp( psz_cmd, "chapter_p" ) )
719 if( !strcmp( psz_cmd, "chapter" ) )
721 if ( *newval.psz_string )
724 val.i_int = atoi( newval.psz_string );
725 var_Set( p_input, "chapter", val );
729 vlc_value_t val_list;
732 var_Get( p_input, "chapter", &val );
733 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
735 printf( _("Currently playing chapter %d/%d\n"),
736 val.i_int, val_list.p_list->i_count );
737 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
741 else if( !strcmp( psz_cmd, "chapter_n" ) )
743 val.b_bool = VLC_TRUE;
744 var_Set( p_input, "next-chapter", val );
746 else if( !strcmp( psz_cmd, "chapter_p" ) )
748 val.b_bool = VLC_TRUE;
749 var_Set( p_input, "prev-chapter", val );
752 vlc_object_release( p_input );
755 else if( !strcmp( psz_cmd, "title" ) ||
756 !strcmp( psz_cmd, "title_n" ) ||
757 !strcmp( psz_cmd, "title_p" ) )
759 if( !strcmp( psz_cmd, "title" ) )
761 if ( *newval.psz_string )
764 val.i_int = atoi( newval.psz_string );
765 var_Set( p_input, "title", val );
769 vlc_value_t val_list;
772 var_Get( p_input, "title", &val );
773 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
775 printf( _("Currently playing title %d/%d\n"),
776 val.i_int, val_list.p_list->i_count );
777 var_Change( p_this, "title", VLC_VAR_FREELIST,
781 else if( !strcmp( psz_cmd, "title_n" ) )
783 val.b_bool = VLC_TRUE;
784 var_Set( p_input, "next-title", val );
786 else if( !strcmp( psz_cmd, "title_p" ) )
788 val.b_bool = VLC_TRUE;
789 var_Set( p_input, "prev-title", val );
792 vlc_object_release( p_input );
800 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
801 vlc_value_t oldval, vlc_value_t newval, void *p_data )
803 intf_thread_t *p_intf = (intf_thread_t*)p_this;
804 playlist_t *p_playlist;
806 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
813 /* Parse commands that require a playlist */
814 if( !strcmp( psz_cmd, "prev" ) )
816 playlist_Prev( p_playlist );
818 else if( !strcmp( psz_cmd, "next" ) )
820 playlist_Next( p_playlist );
822 else if( !strcmp( psz_cmd, "play" ) )
824 playlist_Play( p_playlist );
826 else if( !strcmp( psz_cmd, "stop" ) )
828 playlist_Stop( p_playlist );
830 else if( !strcmp( psz_cmd, "add" ) )
832 printf( _("trying to add %s to playlist\n"), newval.psz_string );
833 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
834 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
836 else if( !strcmp( psz_cmd, "playlist" ) )
839 for ( i = 0; i < p_playlist->i_size; i++ )
841 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
842 p_playlist->pp_items[i]->input.psz_name,
843 p_playlist->pp_items[i]->input.psz_uri );
847 printf( _("| no entries\n") );
855 printf( _("unknown command!\n") );
858 vlc_object_release( p_playlist );
862 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
863 vlc_value_t oldval, vlc_value_t newval, void *p_data )
865 p_this->p_vlc->b_die = VLC_TRUE;
869 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
870 vlc_value_t oldval, vlc_value_t newval, void *p_data )
872 intf_thread_t *p_newintf;
874 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
878 p_newintf->b_block = VLC_FALSE;
879 if( intf_RunThread( p_newintf ) )
881 vlc_object_detach( p_newintf );
882 intf_Destroy( p_newintf );
889 static int Volume( 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;
895 if ( *newval.psz_string )
898 audio_volume_t i_volume = atoi( newval.psz_string );
899 if ( i_volume > AOUT_VOLUME_MAX )
901 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
903 i_error = VLC_EBADVAR;
905 else i_error = aout_VolumeSet( p_this, i_volume );
910 audio_volume_t i_volume;
911 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
913 i_error = VLC_EGENERIC;
917 printf( _("Volume is %d\n"), i_volume );
918 i_error = VLC_SUCCESS;
925 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
926 vlc_value_t oldval, vlc_value_t newval, void *p_data )
928 intf_thread_t *p_intf = (intf_thread_t*)p_this;
929 audio_volume_t i_volume;
930 int i_nb_steps = atoi(newval.psz_string);
931 int i_error = VLC_SUCCESS;
933 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
938 if ( !strcmp(psz_cmd, "volup") )
940 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
941 i_error = VLC_EGENERIC;
945 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
946 i_error = VLC_EGENERIC;
949 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
953 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
954 vlc_value_t oldval, vlc_value_t newval, void *p_data )
956 intf_thread_t *p_intf = (intf_thread_t*)p_this;
957 aout_instance_t * p_aout;
958 const char * psz_variable;
959 vlc_value_t val_name;
962 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
963 if ( p_aout == NULL ) return VLC_ENOOBJ;
965 if ( !strcmp( psz_cmd, "adev" ) )
967 psz_variable = "audio-device";
971 psz_variable = "audio-channels";
974 /* Get the descriptive name of the variable */
975 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
977 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
979 if ( !*newval.psz_string )
981 /* Retrieve all registered ***. */
982 vlc_value_t val, text;
985 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
987 vlc_object_release( (vlc_object_t *)p_aout );
992 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
993 VLC_VAR_GETLIST, &val, &text ) < 0 )
995 vlc_object_release( (vlc_object_t *)p_aout );
999 printf( "+----[ %s ]\n", val_name.psz_string );
1000 for ( i = 0; i < val.p_list->i_count; i++ )
1002 if ( i_value == val.p_list->p_values[i].i_int )
1003 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1004 text.p_list->p_values[i].psz_string );
1006 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
1007 text.p_list->p_values[i].psz_string );
1009 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1011 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
1013 if( val_name.psz_string ) free( val_name.psz_string );
1014 i_error = VLC_SUCCESS;
1019 val.i_int = atoi( newval.psz_string );
1021 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1023 vlc_object_release( (vlc_object_t *)p_aout );
1029 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1031 INPUT_RECORD input_record;
1034 /* On Win32, select() only works on socket descriptors */
1035 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1036 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1038 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1039 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1042 if( input_record.EventType != KEY_EVENT ||
1043 !input_record.Event.KeyEvent.bKeyDown ||
1044 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1045 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1046 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1047 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1049 /* nothing interesting */
1053 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1055 /* Echo out the command */
1056 putc( p_buffer[ *pi_size ], stdout );
1058 /* Handle special keys */
1059 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1061 putc( '\n', stdout );
1064 switch( p_buffer[ *pi_size ] )
1070 putc( ' ', stdout );
1071 putc( '\b', stdout );
1082 if( *pi_size == MAX_LINE_LENGTH ||
1083 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1085 p_buffer[ *pi_size ] = 0;
1094 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1099 if( p_intf->p_sys->i_socket == -1 )
1100 return ReadWin32( p_intf, p_buffer, pi_size );
1103 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1104 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1105 STDIN_FILENO : p_intf->p_sys->i_socket,
1106 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1108 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1114 /* Connection closed */
1117 p_intf->p_sys->i_socket = -1;
1118 p_buffer[ *pi_size ] = 0;
1122 if( *pi_size == MAX_LINE_LENGTH ||
1123 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1125 p_buffer[ *pi_size ] = 0;