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 );
339 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
340 var_AddCallback( p_intf, "pause", Input, NULL );
341 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
342 var_AddCallback( p_intf, "seek", Input, NULL );
343 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
344 var_AddCallback( p_intf, "title", Input, NULL );
345 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
346 var_AddCallback( p_intf, "title_n", Input, NULL );
347 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
348 var_AddCallback( p_intf, "title_p", Input, NULL );
349 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
350 var_AddCallback( p_intf, "chapter", Input, NULL );
351 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
352 var_AddCallback( p_intf, "chapter_n", Input, NULL );
353 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
354 var_AddCallback( p_intf, "chapter_p", Input, NULL );
356 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
357 var_AddCallback( p_intf, "volume", Volume, NULL );
358 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
359 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
360 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
361 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
362 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
363 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
364 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
365 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
368 /* Get the file descriptor of the console input */
369 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
370 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
372 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
373 p_intf->b_die = VLC_TRUE;
377 while( !p_intf->b_die )
379 char *psz_cmd, *psz_arg;
380 vlc_bool_t b_complete;
382 if( p_intf->p_sys->i_socket_listen != - 1 &&
383 p_intf->p_sys->i_socket == -1 )
385 p_intf->p_sys->i_socket =
386 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
389 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
391 /* Manage the input part */
392 if( p_input == NULL )
396 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
401 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
405 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
410 else if( p_input->b_dead )
412 vlc_object_release( p_input );
416 if( p_input && b_showpos )
418 i_newpos = 100 * var_GetFloat( p_input, "position" );
419 if( i_oldpos != i_newpos )
422 printf( "pos: %d%%\n", i_newpos );
426 /* Is there something to do? */
427 if( !b_complete ) continue;
430 /* Skip heading spaces */
432 while( *psz_cmd == ' ' )
437 /* Split psz_cmd at the first space and make sure that
438 * psz_arg is valid */
439 psz_arg = strchr( psz_cmd, ' ' );
443 while( *psz_arg == ' ' )
453 /* If the user typed a registered local command, try it */
454 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
459 val.psz_string = psz_arg;
460 i_ret = var_Set( p_intf, psz_cmd, val );
461 printf( _("%s: returned %i (%s)\n"),
462 psz_cmd, i_ret, vlc_error( i_ret ) );
464 /* Or maybe it's a global command */
465 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
470 val.psz_string = psz_arg;
471 /* FIXME: it's a global command, but we should pass the
472 * local object as an argument, not p_intf->p_libvlc. */
473 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
476 printf( _("%s: returned %i (%s)\n"),
477 psz_cmd, i_ret, vlc_error( i_ret ) );
480 else if( !strcmp( psz_cmd, "info" ) )
485 vlc_mutex_lock( &p_input->input.p_item->lock );
486 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
488 info_category_t *p_category =
489 p_input->input.p_item->pp_categories[i];
491 printf( "+----[ %s ]\n", p_category->psz_name );
493 for ( j = 0; j < p_category->i_infos; j++ )
495 info_t *p_info = p_category->pp_infos[j];
496 printf( "| %s: %s\n", p_info->psz_name,
501 printf( _("+----[ end of stream info ]\n") );
502 vlc_mutex_unlock( &p_input->input.p_item->lock );
506 printf( _("no input\n") );
509 else if( !strcmp( psz_cmd, "is_playing" ) )
520 else if( !strcmp( psz_cmd, "get_time" ) )
529 var_Get( p_input, "time", &time );
530 printf( "%i\n", time.i_time / 1000000);
533 else if( !strcmp( psz_cmd, "get_length" ) )
542 var_Get( p_input, "length", &time );
543 printf( "%i\n", time.i_time / 1000000);
546 else if( !strcmp( psz_cmd, "get_title" ) )
554 printf( "%s\n", p_input->input.p_item->psz_name );
557 else switch( psz_cmd[0] )
563 vout_thread_t *p_vout;
564 p_vout = vlc_object_find( p_input,
565 VLC_OBJECT_VOUT, FIND_CHILD );
569 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
570 vlc_object_release( p_vout );
583 printf(_("+----[ Remote control commands ]\n"));
585 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
586 printf(_("| playlist . . . show items currently in playlist\n"));
587 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
588 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
589 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
590 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
591 printf(_("| title [X] . . . . set/get title in current item\n"));
592 printf(_("| title_n . . . . . . next title in current item\n"));
593 printf(_("| title_p . . . . previous title in current item\n"));
594 printf(_("| chapter [X] . . set/get chapter in current item\n"));
595 printf(_("| chapter_n . . . . next chapter in current item\n"));
596 printf(_("| chapter_p . . previous chapter in current item\n"));
598 printf(_("| marquee STRING . . . . . overlay STRING in video\n"));
599 printf(_("| marq-x X . . . . . .offset of marquee, from left\n"));
600 printf(_("| marq-y Y . . . . . . offset of marquee, from top\n"));
602 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
603 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
604 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
605 printf(_("| info . . . information about the current stream\n"));
607 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
608 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
609 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
610 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
611 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
613 printf(_("| help . . . . . . . . . . . . . this help message\n"));
614 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
616 printf(_("+----[ end of help ]\n"));
620 /* Ignore empty lines */
624 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
628 /* Command processed */
629 i_size = 0; p_buffer[0] = 0;
634 vlc_object_release( p_input );
640 vlc_object_release( p_playlist );
645 static int Input( vlc_object_t *p_this, char const *psz_cmd,
646 vlc_value_t oldval, vlc_value_t newval, void *p_data )
648 intf_thread_t *p_intf = (intf_thread_t*)p_this;
649 input_thread_t *p_input;
652 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
653 if( !p_input ) return VLC_ENOOBJ;
655 /* Parse commands that only require an input */
656 if( !strcmp( psz_cmd, "pause" ) )
660 var_Set( p_input, "state", val );
661 vlc_object_release( p_input );
664 else if( !strcmp( psz_cmd, "seek" ) )
666 if( strlen( newval.psz_string ) > 0 &&
667 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
669 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
670 var_Set( p_input, "position", val );
674 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
675 var_Set( p_input, "time", val );
677 vlc_object_release( p_input );
680 else if( !strcmp( psz_cmd, "marquee" ) )
682 if( strlen( newval.psz_string ) > 0 )
684 val.psz_string = newval.psz_string;
685 /* check for the playlist structure */
687 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
692 var_Set( p_pl, "marquee", val );
693 vlc_object_release( p_pl );
695 vlc_object_release( p_input );
698 else if( !strcmp( psz_cmd, "marq-x" ) )
700 if( strlen( newval.psz_string ) > 0)
703 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
708 val.i_int = atoi( newval.psz_string );
709 var_Set( p_pl, "marq-x", val );
710 vlc_object_release( p_pl );
712 vlc_object_release( p_input );
715 else if( !strcmp( psz_cmd, "marq-y" ) )
717 if( strlen( newval.psz_string ) > 0)
720 vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
725 val.i_int = atoi( newval.psz_string );
726 var_Set( p_pl, "marq-y", val );
727 vlc_object_release( p_pl );
729 vlc_object_release( p_input );
733 else if( !strcmp( psz_cmd, "chapter" ) ||
734 !strcmp( psz_cmd, "chapter_n" ) ||
735 !strcmp( psz_cmd, "chapter_p" ) )
737 if( !strcmp( psz_cmd, "chapter" ) )
739 if ( *newval.psz_string )
742 val.i_int = atoi( newval.psz_string );
743 var_Set( p_input, "chapter", val );
747 vlc_value_t val_list;
750 var_Get( p_input, "chapter", &val );
751 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
753 printf( _("Currently playing chapter %d/%d\n"),
754 val.i_int, val_list.p_list->i_count );
755 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
759 else if( !strcmp( psz_cmd, "chapter_n" ) )
761 val.b_bool = VLC_TRUE;
762 var_Set( p_input, "next-chapter", val );
764 else if( !strcmp( psz_cmd, "chapter_p" ) )
766 val.b_bool = VLC_TRUE;
767 var_Set( p_input, "prev-chapter", val );
770 vlc_object_release( p_input );
773 else if( !strcmp( psz_cmd, "title" ) ||
774 !strcmp( psz_cmd, "title_n" ) ||
775 !strcmp( psz_cmd, "title_p" ) )
777 if( !strcmp( psz_cmd, "title" ) )
779 if ( *newval.psz_string )
782 val.i_int = atoi( newval.psz_string );
783 var_Set( p_input, "title", val );
787 vlc_value_t val_list;
790 var_Get( p_input, "title", &val );
791 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
793 printf( _("Currently playing title %d/%d\n"),
794 val.i_int, val_list.p_list->i_count );
795 var_Change( p_this, "title", VLC_VAR_FREELIST,
799 else if( !strcmp( psz_cmd, "title_n" ) )
801 val.b_bool = VLC_TRUE;
802 var_Set( p_input, "next-title", val );
804 else if( !strcmp( psz_cmd, "title_p" ) )
806 val.b_bool = VLC_TRUE;
807 var_Set( p_input, "prev-title", val );
810 vlc_object_release( p_input );
818 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
819 vlc_value_t oldval, vlc_value_t newval, void *p_data )
821 intf_thread_t *p_intf = (intf_thread_t*)p_this;
822 playlist_t *p_playlist;
824 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
831 /* Parse commands that require a playlist */
832 if( !strcmp( psz_cmd, "prev" ) )
834 playlist_Prev( p_playlist );
836 else if( !strcmp( psz_cmd, "next" ) )
838 playlist_Next( p_playlist );
840 else if( !strcmp( psz_cmd, "play" ) )
842 playlist_Play( p_playlist );
844 else if( !strcmp( psz_cmd, "stop" ) )
846 playlist_Stop( p_playlist );
848 else if( !strcmp( psz_cmd, "add" ) )
850 printf( _("trying to add %s to playlist\n"), newval.psz_string );
851 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
852 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
854 else if( !strcmp( psz_cmd, "playlist" ) )
857 for ( i = 0; i < p_playlist->i_size; i++ )
859 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
860 p_playlist->pp_items[i]->input.psz_name,
861 p_playlist->pp_items[i]->input.psz_uri );
865 printf( _("| no entries\n") );
873 printf( _("unknown command!\n") );
876 vlc_object_release( p_playlist );
880 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
881 vlc_value_t oldval, vlc_value_t newval, void *p_data )
883 p_this->p_vlc->b_die = VLC_TRUE;
887 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
888 vlc_value_t oldval, vlc_value_t newval, void *p_data )
890 intf_thread_t *p_newintf;
892 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
896 p_newintf->b_block = VLC_FALSE;
897 if( intf_RunThread( p_newintf ) )
899 vlc_object_detach( p_newintf );
900 intf_Destroy( p_newintf );
907 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
908 vlc_value_t oldval, vlc_value_t newval, void *p_data )
910 intf_thread_t *p_intf = (intf_thread_t*)p_this;
913 if ( *newval.psz_string )
916 audio_volume_t i_volume = atoi( newval.psz_string );
917 if ( i_volume > AOUT_VOLUME_MAX )
919 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
921 i_error = VLC_EBADVAR;
923 else i_error = aout_VolumeSet( p_this, i_volume );
928 audio_volume_t i_volume;
929 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
931 i_error = VLC_EGENERIC;
935 printf( _("Volume is %d\n"), i_volume );
936 i_error = VLC_SUCCESS;
943 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
944 vlc_value_t oldval, vlc_value_t newval, void *p_data )
946 intf_thread_t *p_intf = (intf_thread_t*)p_this;
947 audio_volume_t i_volume;
948 int i_nb_steps = atoi(newval.psz_string);
949 int i_error = VLC_SUCCESS;
951 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
956 if ( !strcmp(psz_cmd, "volup") )
958 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
959 i_error = VLC_EGENERIC;
963 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
964 i_error = VLC_EGENERIC;
967 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
971 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
972 vlc_value_t oldval, vlc_value_t newval, void *p_data )
974 intf_thread_t *p_intf = (intf_thread_t*)p_this;
975 aout_instance_t * p_aout;
976 const char * psz_variable;
977 vlc_value_t val_name;
980 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
981 if ( p_aout == NULL ) return VLC_ENOOBJ;
983 if ( !strcmp( psz_cmd, "adev" ) )
985 psz_variable = "audio-device";
989 psz_variable = "audio-channels";
992 /* Get the descriptive name of the variable */
993 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
995 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
997 if ( !*newval.psz_string )
999 /* Retrieve all registered ***. */
1000 vlc_value_t val, text;
1003 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1005 vlc_object_release( (vlc_object_t *)p_aout );
1006 return VLC_EGENERIC;
1008 i_value = val.i_int;
1010 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1011 VLC_VAR_GETLIST, &val, &text ) < 0 )
1013 vlc_object_release( (vlc_object_t *)p_aout );
1014 return VLC_EGENERIC;
1017 printf( "+----[ %s ]\n", val_name.psz_string );
1018 for ( i = 0; i < val.p_list->i_count; i++ )
1020 if ( i_value == val.p_list->p_values[i].i_int )
1021 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1022 text.p_list->p_values[i].psz_string );
1024 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
1025 text.p_list->p_values[i].psz_string );
1027 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1029 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
1031 if( val_name.psz_string ) free( val_name.psz_string );
1032 i_error = VLC_SUCCESS;
1037 val.i_int = atoi( newval.psz_string );
1039 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1041 vlc_object_release( (vlc_object_t *)p_aout );
1047 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1049 INPUT_RECORD input_record;
1052 /* On Win32, select() only works on socket descriptors */
1053 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1054 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1056 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1057 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1060 if( input_record.EventType != KEY_EVENT ||
1061 !input_record.Event.KeyEvent.bKeyDown ||
1062 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1063 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1064 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1065 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1067 /* nothing interesting */
1071 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1073 /* Echo out the command */
1074 putc( p_buffer[ *pi_size ], stdout );
1076 /* Handle special keys */
1077 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1079 putc( '\n', stdout );
1082 switch( p_buffer[ *pi_size ] )
1088 putc( ' ', stdout );
1089 putc( '\b', stdout );
1100 if( *pi_size == MAX_LINE_LENGTH ||
1101 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1103 p_buffer[ *pi_size ] = 0;
1112 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1117 if( p_intf->p_sys->i_socket == -1 )
1118 return ReadWin32( p_intf, p_buffer, pi_size );
1121 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1122 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1123 STDIN_FILENO : p_intf->p_sys->i_socket,
1124 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1126 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1132 /* Connection closed */
1135 p_intf->p_sys->i_socket = -1;
1136 p_buffer[ *pi_size ] = 0;
1140 if( *pi_size == MAX_LINE_LENGTH ||
1141 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1143 p_buffer[ *pi_size ] = 0;