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 #define QUIET_TEXT N_("Do not open a DOS command box interface")
134 #define QUIET_LONGTEXT N_( \
135 "By default the rc interface plugin will start a DOS command box. " \
136 "Enabling the quiet mode will not bring this command box but can also " \
137 "be pretty annoying when you want to stop VLC and no video window is " \
142 set_description( _("Remote control interface") );
143 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
145 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
147 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
148 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
151 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
154 set_capability( "interface", 20 );
155 set_callbacks( Activate, Deactivate );
158 /*****************************************************************************
159 * Activate: initialize and create stuff
160 *****************************************************************************/
161 static int Activate( vlc_object_t *p_this )
163 intf_thread_t *p_intf = (intf_thread_t*)p_this;
164 char *psz_host, *psz_unix_path;
167 #if defined(HAVE_ISATTY) && !defined(WIN32)
168 /* Check that stdin is a TTY */
169 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
171 msg_Warn( p_intf, "fd 0 is not a TTY" );
176 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
180 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
181 free( psz_unix_path );
184 struct sockaddr_un addr;
187 memset( &addr, 0, sizeof(struct sockaddr_un) );
189 msg_Dbg( p_intf, "trying UNIX socket" );
191 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
193 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
194 free( psz_unix_path );
198 addr.sun_family = AF_LOCAL;
199 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
200 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
202 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
203 sizeof(struct sockaddr_un) ) ) < 0 )
205 msg_Warn( p_intf, "couldn't bind socket to address: %s",
207 free( psz_unix_path );
208 net_Close( i_socket );
212 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
214 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
215 free( psz_unix_path );
216 net_Close( i_socket );
222 if( ( i_socket == -1) &&
223 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
227 vlc_UrlParse( &url, psz_host, 0 );
229 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
231 if( (i_socket = net_ListenTCP(p_this, url.psz_host, url.i_port)) == -1)
233 msg_Warn( p_intf, "can't listen to %s port %i",
234 url.psz_host, url.i_port );
235 vlc_UrlClean( &url );
240 vlc_UrlClean( &url );
244 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
247 msg_Err( p_intf, "no memory" );
251 p_intf->p_sys->i_socket_listen = i_socket;
252 p_intf->p_sys->i_socket = -1;
253 p_intf->p_sys->psz_unix_path = psz_unix_path;
255 /* Non-buffered stdout */
256 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
258 p_intf->pf_run = Run;
261 if( !config_GetInt( p_intf, "rc-quiet" ) ) { CONSOLE_INTRO_MSG; }
266 printf( _("Remote control interface initialized, `h' for help\n") );
270 /*****************************************************************************
271 * Deactivate: uninitialize and cleanup
272 *****************************************************************************/
273 static void Deactivate( vlc_object_t *p_this )
275 intf_thread_t *p_intf = (intf_thread_t*)p_this;
277 if( p_intf->p_sys->i_socket_listen != -1 )
278 net_Close( p_intf->p_sys->i_socket_listen );
279 if( p_intf->p_sys->i_socket != -1 )
280 net_Close( p_intf->p_sys->i_socket );
281 if( p_intf->p_sys->psz_unix_path != NULL )
284 unlink( p_intf->p_sys->psz_unix_path );
286 free( p_intf->p_sys->psz_unix_path );
288 free( p_intf->p_sys );
291 /*****************************************************************************
293 *****************************************************************************
294 * This part of the interface is in a separate thread so that we can call
295 * exec() from within it without annoying the rest of the program.
296 *****************************************************************************/
297 static void Run( intf_thread_t *p_intf )
299 input_thread_t * p_input;
300 playlist_t * p_playlist;
302 char p_buffer[ MAX_LINE_LENGTH + 1 ];
303 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
313 /* Register commands that will be cleaned up upon object destruction */
314 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
315 var_AddCallback( p_intf, "quit", Quit, NULL );
316 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
317 var_AddCallback( p_intf, "intf", Intf, NULL );
319 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
320 var_AddCallback( p_intf, "add", Playlist, NULL );
321 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
322 var_AddCallback( p_intf, "playlist", Playlist, NULL );
323 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
324 var_AddCallback( p_intf, "play", Playlist, NULL );
325 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
326 var_AddCallback( p_intf, "stop", Playlist, NULL );
327 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
328 var_AddCallback( p_intf, "prev", Playlist, NULL );
329 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
330 var_AddCallback( p_intf, "next", Playlist, NULL );
332 var_Create( p_intf, "marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
333 var_AddCallback( p_intf, "marquee", Input, NULL );
334 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
335 var_AddCallback( p_intf, "marq-x", Input, NULL );
336 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
337 var_AddCallback( p_intf, "marq-y", Input, NULL );
338 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
339 var_AddCallback( p_intf, "marq-timeout", Input, NULL );
341 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
342 var_AddCallback( p_intf, "pause", Input, NULL );
343 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
344 var_AddCallback( p_intf, "seek", Input, NULL );
345 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
346 var_AddCallback( p_intf, "title", Input, NULL );
347 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
348 var_AddCallback( p_intf, "title_n", Input, NULL );
349 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
350 var_AddCallback( p_intf, "title_p", Input, NULL );
351 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
352 var_AddCallback( p_intf, "chapter", Input, NULL );
353 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
354 var_AddCallback( p_intf, "chapter_n", Input, NULL );
355 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
356 var_AddCallback( p_intf, "chapter_p", Input, NULL );
358 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
359 var_AddCallback( p_intf, "volume", Volume, NULL );
360 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
361 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
362 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
363 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
364 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
365 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
366 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
367 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
370 /* Get the file descriptor of the console input */
371 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
372 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
374 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
375 p_intf->b_die = VLC_TRUE;
379 while( !p_intf->b_die )
381 char *psz_cmd, *psz_arg;
382 vlc_bool_t b_complete;
384 if( p_intf->p_sys->i_socket_listen != - 1 &&
385 p_intf->p_sys->i_socket == -1 )
387 p_intf->p_sys->i_socket =
388 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
391 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
393 /* Manage the input part */
394 if( p_input == NULL )
398 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
403 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
407 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
412 else if( p_input->b_dead )
414 vlc_object_release( p_input );
418 if( p_input && b_showpos )
420 i_newpos = 100 * var_GetFloat( p_input, "position" );
421 if( i_oldpos != i_newpos )
424 printf( "pos: %d%%\n", i_newpos );
428 /* Is there something to do? */
429 if( !b_complete ) continue;
432 /* Skip heading spaces */
434 while( *psz_cmd == ' ' )
439 /* Split psz_cmd at the first space and make sure that
440 * psz_arg is valid */
441 psz_arg = strchr( psz_cmd, ' ' );
445 while( *psz_arg == ' ' )
455 /* If the user typed a registered local command, try it */
456 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
461 val.psz_string = psz_arg;
462 i_ret = var_Set( p_intf, psz_cmd, val );
463 printf( _("%s: returned %i (%s)\n"),
464 psz_cmd, i_ret, vlc_error( i_ret ) );
466 /* Or maybe it's a global command */
467 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
472 val.psz_string = psz_arg;
473 /* FIXME: it's a global command, but we should pass the
474 * local object as an argument, not p_intf->p_libvlc. */
475 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
478 printf( _("%s: returned %i (%s)\n"),
479 psz_cmd, i_ret, vlc_error( i_ret ) );
482 else if( !strcmp( psz_cmd, "logout" ) )
484 /* Close connection */
485 if( p_intf->p_sys->i_socket != -1 )
487 net_Close( p_intf->p_sys->i_socket );
489 p_intf->p_sys->i_socket = -1;
491 else if( !strcmp( psz_cmd, "info" ) )
496 vlc_mutex_lock( &p_input->input.p_item->lock );
497 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
499 info_category_t *p_category =
500 p_input->input.p_item->pp_categories[i];
502 printf( "+----[ %s ]\n", p_category->psz_name );
504 for ( j = 0; j < p_category->i_infos; j++ )
506 info_t *p_info = p_category->pp_infos[j];
507 printf( "| %s: %s\n", p_info->psz_name,
512 printf( _("+----[ end of stream info ]\n") );
513 vlc_mutex_unlock( &p_input->input.p_item->lock );
517 printf( _("no input\n") );
520 else if( !strcmp( psz_cmd, "is_playing" ) )
531 else if( !strcmp( psz_cmd, "get_time" ) )
540 var_Get( p_input, "time", &time );
541 printf( "%i\n", time.i_time / 1000000);
544 else if( !strcmp( psz_cmd, "get_length" ) )
553 var_Get( p_input, "length", &time );
554 printf( "%i\n", time.i_time / 1000000);
557 else if( !strcmp( psz_cmd, "get_title" ) )
565 printf( "%s\n", p_input->input.p_item->psz_name );
568 else switch( psz_cmd[0] )
574 vout_thread_t *p_vout;
575 p_vout = vlc_object_find( p_input,
576 VLC_OBJECT_VOUT, FIND_CHILD );
580 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
581 vlc_object_release( p_vout );
594 printf(_("+----[ Remote control commands ]\n"));
596 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
597 printf(_("| playlist . . . show items currently in playlist\n"));
598 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
599 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
600 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
601 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
602 printf(_("| title [X] . . . . set/get title in current item\n"));
603 printf(_("| title_n . . . . . . next title in current item\n"));
604 printf(_("| title_p . . . . previous title in current item\n"));
605 printf(_("| chapter [X] . . set/get chapter in current item\n"));
606 printf(_("| chapter_n . . . . next chapter in current item\n"));
607 printf(_("| chapter_p . . previous chapter in current item\n"));
609 printf(_("| marquee STRING . . . . . overlay STRING in video\n"));
610 printf(_("| marq-x X . . . . . .offset of marquee, from left\n"));
611 printf(_("| marq-y Y . . . . . . offset of marquee, from top\n"));
612 printf(_("| marq-timeout T. . . . .timeout of marquee, in ms\n"));
614 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
615 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
616 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
617 printf(_("| info . . . information about the current stream\n"));
619 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
620 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
621 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
622 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
623 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
625 printf(_("| help . . . . . . . . . . . . . this help message\n"));
626 printf(_("| logout . . . . . .exit (if in socket connection)\n"));
627 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
629 printf(_("+----[ end of help ]\n"));
633 /* Ignore empty lines */
637 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
641 /* Command processed */
642 i_size = 0; p_buffer[0] = 0;
647 vlc_object_release( p_input );
653 vlc_object_release( p_playlist );
658 static int Input( vlc_object_t *p_this, char const *psz_cmd,
659 vlc_value_t oldval, vlc_value_t newval, void *p_data )
661 intf_thread_t *p_intf = (intf_thread_t*)p_this;
662 input_thread_t *p_input;
665 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
666 if( !p_input ) return VLC_ENOOBJ;
668 /* Parse commands that only require an input */
669 if( !strcmp( psz_cmd, "pause" ) )
673 var_Set( p_input, "state", val );
674 vlc_object_release( p_input );
677 else if( !strcmp( psz_cmd, "seek" ) )
679 if( strlen( newval.psz_string ) > 0 &&
680 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
682 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
683 var_Set( p_input, "position", val );
687 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
688 var_Set( p_input, "time", val );
690 vlc_object_release( p_input );
693 else if( !strcmp( psz_cmd, "marquee" ) )
695 if( strlen( newval.psz_string ) > 0 )
697 val.psz_string = newval.psz_string;
698 /* check for the playlist structure */
700 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
705 var_Set( p_pl, "marquee", val );
706 vlc_object_release( p_pl );
708 vlc_object_release( p_input );
711 else if( !strcmp( psz_cmd, "marq-x" ) )
713 if( strlen( newval.psz_string ) > 0)
716 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
721 val.i_int = atoi( newval.psz_string );
722 var_Set( p_pl, "marq-x", val );
723 vlc_object_release( p_pl );
725 vlc_object_release( p_input );
728 else if( !strcmp( psz_cmd, "marq-y" ) )
730 if( strlen( newval.psz_string ) > 0)
733 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
738 val.i_int = atoi( newval.psz_string );
739 var_Set( p_pl, "marq-y", val );
740 vlc_object_release( p_pl );
742 vlc_object_release( p_input );
745 else if( !strcmp( psz_cmd, "marq-timeout" ) )
747 if( strlen( newval.psz_string ) > 0)
750 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
755 val.i_int = atoi( newval.psz_string );
756 var_Set( p_pl, "marq-timeout", val );
757 vlc_object_release( p_pl );
759 vlc_object_release( p_input );
763 else if( !strcmp( psz_cmd, "chapter" ) ||
764 !strcmp( psz_cmd, "chapter_n" ) ||
765 !strcmp( psz_cmd, "chapter_p" ) )
767 if( !strcmp( psz_cmd, "chapter" ) )
769 if ( *newval.psz_string )
772 val.i_int = atoi( newval.psz_string );
773 var_Set( p_input, "chapter", val );
777 vlc_value_t val_list;
780 var_Get( p_input, "chapter", &val );
781 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
783 printf( _("Currently playing chapter %d/%d\n"),
784 val.i_int, val_list.p_list->i_count );
785 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
789 else if( !strcmp( psz_cmd, "chapter_n" ) )
791 val.b_bool = VLC_TRUE;
792 var_Set( p_input, "next-chapter", val );
794 else if( !strcmp( psz_cmd, "chapter_p" ) )
796 val.b_bool = VLC_TRUE;
797 var_Set( p_input, "prev-chapter", val );
800 vlc_object_release( p_input );
803 else if( !strcmp( psz_cmd, "title" ) ||
804 !strcmp( psz_cmd, "title_n" ) ||
805 !strcmp( psz_cmd, "title_p" ) )
807 if( !strcmp( psz_cmd, "title" ) )
809 if ( *newval.psz_string )
812 val.i_int = atoi( newval.psz_string );
813 var_Set( p_input, "title", val );
817 vlc_value_t val_list;
820 var_Get( p_input, "title", &val );
821 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
823 printf( _("Currently playing title %d/%d\n"),
824 val.i_int, val_list.p_list->i_count );
825 var_Change( p_this, "title", VLC_VAR_FREELIST,
829 else if( !strcmp( psz_cmd, "title_n" ) )
831 val.b_bool = VLC_TRUE;
832 var_Set( p_input, "next-title", val );
834 else if( !strcmp( psz_cmd, "title_p" ) )
836 val.b_bool = VLC_TRUE;
837 var_Set( p_input, "prev-title", val );
840 vlc_object_release( p_input );
848 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
849 vlc_value_t oldval, vlc_value_t newval, void *p_data )
851 intf_thread_t *p_intf = (intf_thread_t*)p_this;
852 playlist_t *p_playlist;
854 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
861 /* Parse commands that require a playlist */
862 if( !strcmp( psz_cmd, "prev" ) )
864 playlist_Prev( p_playlist );
866 else if( !strcmp( psz_cmd, "next" ) )
868 playlist_Next( p_playlist );
870 else if( !strcmp( psz_cmd, "play" ) )
872 playlist_Play( p_playlist );
874 else if( !strcmp( psz_cmd, "stop" ) )
876 playlist_Stop( p_playlist );
878 else if( !strcmp( psz_cmd, "add" ) )
880 printf( _("trying to add %s to playlist\n"), newval.psz_string );
881 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
882 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
884 else if( !strcmp( psz_cmd, "playlist" ) )
887 for ( i = 0; i < p_playlist->i_size; i++ )
889 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
890 p_playlist->pp_items[i]->input.psz_name,
891 p_playlist->pp_items[i]->input.psz_uri );
895 printf( _("| no entries\n") );
903 printf( _("unknown command!\n") );
906 vlc_object_release( p_playlist );
910 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
911 vlc_value_t oldval, vlc_value_t newval, void *p_data )
913 p_this->p_vlc->b_die = VLC_TRUE;
917 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
918 vlc_value_t oldval, vlc_value_t newval, void *p_data )
920 intf_thread_t *p_newintf;
922 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
926 p_newintf->b_block = VLC_FALSE;
927 if( intf_RunThread( p_newintf ) )
929 vlc_object_detach( p_newintf );
930 intf_Destroy( p_newintf );
937 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
938 vlc_value_t oldval, vlc_value_t newval, void *p_data )
940 intf_thread_t *p_intf = (intf_thread_t*)p_this;
943 if ( *newval.psz_string )
946 audio_volume_t i_volume = atoi( newval.psz_string );
947 if ( i_volume > AOUT_VOLUME_MAX )
949 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
951 i_error = VLC_EBADVAR;
953 else i_error = aout_VolumeSet( p_this, i_volume );
958 audio_volume_t i_volume;
959 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
961 i_error = VLC_EGENERIC;
965 printf( _("Volume is %d\n"), i_volume );
966 i_error = VLC_SUCCESS;
973 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
974 vlc_value_t oldval, vlc_value_t newval, void *p_data )
976 intf_thread_t *p_intf = (intf_thread_t*)p_this;
977 audio_volume_t i_volume;
978 int i_nb_steps = atoi(newval.psz_string);
979 int i_error = VLC_SUCCESS;
981 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
986 if ( !strcmp(psz_cmd, "volup") )
988 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
989 i_error = VLC_EGENERIC;
993 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
994 i_error = VLC_EGENERIC;
997 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
1001 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1002 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1004 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1005 aout_instance_t * p_aout;
1006 const char * psz_variable;
1007 vlc_value_t val_name;
1010 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1011 if ( p_aout == NULL ) return VLC_ENOOBJ;
1013 if ( !strcmp( psz_cmd, "adev" ) )
1015 psz_variable = "audio-device";
1019 psz_variable = "audio-channels";
1022 /* Get the descriptive name of the variable */
1023 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1025 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1027 if ( !*newval.psz_string )
1029 /* Retrieve all registered ***. */
1030 vlc_value_t val, text;
1033 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1035 vlc_object_release( (vlc_object_t *)p_aout );
1036 return VLC_EGENERIC;
1038 i_value = val.i_int;
1040 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1041 VLC_VAR_GETLIST, &val, &text ) < 0 )
1043 vlc_object_release( (vlc_object_t *)p_aout );
1044 return VLC_EGENERIC;
1047 printf( "+----[ %s ]\n", val_name.psz_string );
1048 for ( i = 0; i < val.p_list->i_count; i++ )
1050 if ( i_value == val.p_list->p_values[i].i_int )
1051 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1052 text.p_list->p_values[i].psz_string );
1054 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
1055 text.p_list->p_values[i].psz_string );
1057 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1059 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
1061 if( val_name.psz_string ) free( val_name.psz_string );
1062 i_error = VLC_SUCCESS;
1067 val.i_int = atoi( newval.psz_string );
1069 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1071 vlc_object_release( (vlc_object_t *)p_aout );
1077 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1079 INPUT_RECORD input_record;
1082 /* On Win32, select() only works on socket descriptors */
1083 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1084 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1086 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1087 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1090 if( input_record.EventType != KEY_EVENT ||
1091 !input_record.Event.KeyEvent.bKeyDown ||
1092 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1093 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1094 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1095 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1097 /* nothing interesting */
1101 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1103 /* Echo out the command */
1104 putc( p_buffer[ *pi_size ], stdout );
1106 /* Handle special keys */
1107 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1109 putc( '\n', stdout );
1112 switch( p_buffer[ *pi_size ] )
1118 putc( ' ', stdout );
1119 putc( '\b', stdout );
1130 if( *pi_size == MAX_LINE_LENGTH ||
1131 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1133 p_buffer[ *pi_size ] = 0;
1142 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1147 if( p_intf->p_sys->i_socket == -1 )
1148 return ReadWin32( p_intf, p_buffer, pi_size );
1151 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1152 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1153 STDIN_FILENO : p_intf->p_sys->i_socket,
1154 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1156 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1162 /* Connection closed */
1165 p_intf->p_sys->i_socket = -1;
1166 p_buffer[ *pi_size ] = 0;
1170 if( *pi_size == MAX_LINE_LENGTH ||
1171 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1173 p_buffer[ *pi_size ] = 0;