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 Other ( vlc_object_t *, char const *,
79 vlc_value_t, vlc_value_t, void * );
80 static int Quit ( vlc_object_t *, char const *,
81 vlc_value_t, vlc_value_t, void * );
82 static int Intf ( vlc_object_t *, char const *,
83 vlc_value_t, vlc_value_t, void * );
84 static int Volume ( vlc_object_t *, char const *,
85 vlc_value_t, vlc_value_t, void * );
86 static int VolumeMove ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
88 static int AudioConfig ( vlc_object_t *, char const *,
89 vlc_value_t, vlc_value_t, void * );
104 #ifdef HAVE_VARIADIC_MACROS
105 # define printf( psz_format, args... ) \
106 Printf( p_intf, psz_format, ## args )
109 void Printf( intf_thread_t *p_intf, const char *psz_fmt, ... )
112 va_start( args, psz_fmt );
113 if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
114 else net_vaPrintf( p_intf, p_intf->p_sys->i_socket, psz_fmt, args );
118 /*****************************************************************************
120 *****************************************************************************/
121 #define POS_TEXT N_("Show stream position")
122 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
123 "stream from time to time." )
125 #define TTY_TEXT N_("Fake TTY")
126 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
128 #define UNIX_TEXT N_("UNIX socket command input")
129 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
132 #define HOST_TEXT N_("TCP command input")
133 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
134 "You can set the address and port the interface will bind to." )
135 #define EXTEND_TEXT N_("Extended help")
136 #define EXTEND_LONGTEXT N_("List additional commands.")
140 #define QUIET_TEXT N_("Do not open a DOS command box interface")
141 #define QUIET_LONGTEXT N_( \
142 "By default the rc interface plugin will start a DOS command box. " \
143 "Enabling the quiet mode will not bring this command box but can also " \
144 "be pretty annoying when you want to stop VLC and no video window is " \
149 set_description( _("Remote control interface") );
150 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
152 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
154 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
155 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
158 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
160 add_bool( "rc-extend", 0, NULL, EXTEND_TEXT, EXTEND_LONGTEXT, VLC_FALSE );
162 set_capability( "interface", 20 );
163 set_callbacks( Activate, Deactivate );
166 /*****************************************************************************
167 * Activate: initialize and create stuff
168 *****************************************************************************/
169 static int Activate( vlc_object_t *p_this )
171 intf_thread_t *p_intf = (intf_thread_t*)p_this;
172 char *psz_host, *psz_unix_path;
175 #if defined(HAVE_ISATTY) && !defined(WIN32)
176 /* Check that stdin is a TTY */
177 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
179 msg_Warn( p_intf, "fd 0 is not a TTY" );
184 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
188 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
189 free( psz_unix_path );
192 struct sockaddr_un addr;
195 memset( &addr, 0, sizeof(struct sockaddr_un) );
197 msg_Dbg( p_intf, "trying UNIX socket" );
199 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
201 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
202 free( psz_unix_path );
206 addr.sun_family = AF_LOCAL;
207 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
208 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
210 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
211 sizeof(struct sockaddr_un) ) ) < 0 )
213 msg_Warn( p_intf, "couldn't bind socket to address: %s",
215 free( psz_unix_path );
216 net_Close( i_socket );
220 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
222 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
223 free( psz_unix_path );
224 net_Close( i_socket );
230 if( ( i_socket == -1) &&
231 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
235 vlc_UrlParse( &url, psz_host, 0 );
237 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
239 if( (i_socket = net_ListenTCP(p_this, url.psz_host, url.i_port)) == -1)
241 msg_Warn( p_intf, "can't listen to %s port %i",
242 url.psz_host, url.i_port );
243 vlc_UrlClean( &url );
248 vlc_UrlClean( &url );
252 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
255 msg_Err( p_intf, "no memory" );
259 p_intf->p_sys->i_socket_listen = i_socket;
260 p_intf->p_sys->i_socket = -1;
261 p_intf->p_sys->psz_unix_path = psz_unix_path;
263 /* Non-buffered stdout */
264 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
266 p_intf->pf_run = Run;
269 p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
270 if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
275 printf( _("Remote control interface initialized, `h' for help\n") );
279 /*****************************************************************************
280 * Deactivate: uninitialize and cleanup
281 *****************************************************************************/
282 static void Deactivate( vlc_object_t *p_this )
284 intf_thread_t *p_intf = (intf_thread_t*)p_this;
286 if( p_intf->p_sys->i_socket_listen != -1 )
287 net_Close( p_intf->p_sys->i_socket_listen );
288 if( p_intf->p_sys->i_socket != -1 )
289 net_Close( p_intf->p_sys->i_socket );
290 if( p_intf->p_sys->psz_unix_path != NULL )
293 unlink( p_intf->p_sys->psz_unix_path );
295 free( p_intf->p_sys->psz_unix_path );
297 free( p_intf->p_sys );
300 /*****************************************************************************
302 *****************************************************************************
303 * This part of the interface is in a separate thread so that we can call
304 * exec() from within it without annoying the rest of the program.
305 *****************************************************************************/
306 static void Run( intf_thread_t *p_intf )
308 input_thread_t * p_input;
309 playlist_t * p_playlist;
311 char p_buffer[ MAX_LINE_LENGTH + 1 ];
312 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
322 p_intf->p_sys->b_extend = config_GetInt( p_intf, "rc-extend" );
323 /* Register commands that will be cleaned up upon object destruction */
324 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
325 var_AddCallback( p_intf, "quit", Quit, NULL );
326 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
327 var_AddCallback( p_intf, "intf", Intf, NULL );
329 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
330 var_AddCallback( p_intf, "add", Playlist, NULL );
331 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
332 var_AddCallback( p_intf, "playlist", Playlist, NULL );
333 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
334 var_AddCallback( p_intf, "play", Playlist, NULL );
335 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
336 var_AddCallback( p_intf, "stop", Playlist, NULL );
337 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
338 var_AddCallback( p_intf, "prev", Playlist, NULL );
339 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
340 var_AddCallback( p_intf, "next", Playlist, NULL );
342 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
343 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
344 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
345 var_AddCallback( p_intf, "marq-x", Other, NULL );
346 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
347 var_AddCallback( p_intf, "marq-y", Other, NULL );
348 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
349 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
351 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
352 var_AddCallback( p_intf, "pause", Input, NULL );
353 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
354 var_AddCallback( p_intf, "seek", Input, NULL );
355 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
356 var_AddCallback( p_intf, "title", Input, NULL );
357 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
358 var_AddCallback( p_intf, "title_n", Input, NULL );
359 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
360 var_AddCallback( p_intf, "title_p", Input, NULL );
361 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
362 var_AddCallback( p_intf, "chapter", Input, NULL );
363 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
364 var_AddCallback( p_intf, "chapter_n", Input, NULL );
365 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
366 var_AddCallback( p_intf, "chapter_p", Input, NULL );
368 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
369 var_AddCallback( p_intf, "volume", Volume, NULL );
370 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
371 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
372 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
373 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
374 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
375 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
376 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
377 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
380 /* Get the file descriptor of the console input */
381 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
382 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
384 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
385 p_intf->b_die = VLC_TRUE;
389 while( !p_intf->b_die )
391 char *psz_cmd, *psz_arg;
392 vlc_bool_t b_complete;
394 if( p_intf->p_sys->i_socket_listen != - 1 &&
395 p_intf->p_sys->i_socket == -1 )
397 p_intf->p_sys->i_socket =
398 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
401 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
403 /* Manage the input part */
404 if( p_input == NULL )
408 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
413 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
417 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
422 else if( p_input->b_dead )
424 vlc_object_release( p_input );
428 if( p_input && b_showpos )
430 i_newpos = 100 * var_GetFloat( p_input, "position" );
431 if( i_oldpos != i_newpos )
434 printf( "pos: %d%%\n", i_newpos );
438 /* Is there something to do? */
439 if( !b_complete ) continue;
442 /* Skip heading spaces */
444 while( *psz_cmd == ' ' )
449 /* Split psz_cmd at the first space and make sure that
450 * psz_arg is valid */
451 psz_arg = strchr( psz_cmd, ' ' );
455 while( *psz_arg == ' ' )
465 /* If the user typed a registered local command, try it */
466 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
471 val.psz_string = psz_arg;
472 i_ret = var_Set( p_intf, psz_cmd, val );
473 printf( _("%s: returned %i (%s)\n"),
474 psz_cmd, i_ret, vlc_error( i_ret ) );
476 /* Or maybe it's a global command */
477 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
482 val.psz_string = psz_arg;
483 /* FIXME: it's a global command, but we should pass the
484 * local object as an argument, not p_intf->p_libvlc. */
485 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
488 printf( _("%s: returned %i (%s)\n"),
489 psz_cmd, i_ret, vlc_error( i_ret ) );
492 else if( !strcmp( psz_cmd, "logout" ) )
494 /* Close connection */
495 if( p_intf->p_sys->i_socket != -1 )
497 net_Close( p_intf->p_sys->i_socket );
499 p_intf->p_sys->i_socket = -1;
501 else if( !strcmp( psz_cmd, "info" ) )
506 vlc_mutex_lock( &p_input->input.p_item->lock );
507 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
509 info_category_t *p_category =
510 p_input->input.p_item->pp_categories[i];
512 printf( "+----[ %s ]\n", p_category->psz_name );
514 for ( j = 0; j < p_category->i_infos; j++ )
516 info_t *p_info = p_category->pp_infos[j];
517 printf( "| %s: %s\n", p_info->psz_name,
522 printf( _("+----[ end of stream info ]\n") );
523 vlc_mutex_unlock( &p_input->input.p_item->lock );
527 printf( _("no input\n") );
530 else if( !strcmp( psz_cmd, "is_playing" ) )
541 else if( !strcmp( psz_cmd, "get_time" ) )
550 var_Get( p_input, "time", &time );
551 printf( "%i\n", time.i_time / 1000000);
554 else if( !strcmp( psz_cmd, "get_length" ) )
563 var_Get( p_input, "length", &time );
564 printf( "%i\n", time.i_time / 1000000);
567 else if( !strcmp( psz_cmd, "get_title" ) )
575 printf( "%s\n", p_input->input.p_item->psz_name );
578 else switch( psz_cmd[0] )
584 vout_thread_t *p_vout;
585 p_vout = vlc_object_find( p_input,
586 VLC_OBJECT_VOUT, FIND_CHILD );
590 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
591 vlc_object_release( p_vout );
604 printf(_("+----[ Remote control commands ]\n"));
606 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
607 printf(_("| playlist . . . show items currently in playlist\n"));
608 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
609 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
610 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
611 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
612 printf(_("| title [X] . . . . set/get title in current item\n"));
613 printf(_("| title_n . . . . . . next title in current item\n"));
614 printf(_("| title_p . . . . previous title in current item\n"));
615 printf(_("| chapter [X] . . set/get chapter in current item\n"));
616 printf(_("| chapter_n . . . . next chapter in current item\n"));
617 printf(_("| chapter_p . . previous chapter in current item\n"));
619 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
620 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
621 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
622 printf(_("| info . . . information about the current stream\n"));
624 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
625 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
626 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
627 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
628 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
630 if (p_intf->p_sys->b_extend)
632 printf(_("| marq-marquee STRING . . overlay STRING in video\n"));
633 printf(_("| marq-x X . . . . . .offset of marquee, from left\n"));
634 printf(_("| marq-y Y . . . . . . offset of marquee, from top\n"));
635 printf(_("| marq-timeout T. . . . .timeout of marquee, in ms\n"));
638 printf(_("| help . . . . . . . . . . . . . this help message\n"));
639 printf(_("| logout . . . . . .exit (if in socket connection)\n"));
640 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
642 printf(_("+----[ end of help ]\n"));
646 /* Ignore empty lines */
650 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
654 /* Command processed */
655 i_size = 0; p_buffer[0] = 0;
660 vlc_object_release( p_input );
666 vlc_object_release( p_playlist );
671 static int Input( vlc_object_t *p_this, char const *psz_cmd,
672 vlc_value_t oldval, vlc_value_t newval, void *p_data )
674 intf_thread_t *p_intf = (intf_thread_t*)p_this;
675 input_thread_t *p_input;
678 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
679 if( !p_input ) return VLC_ENOOBJ;
681 /* Parse commands that only require an input */
682 if( !strcmp( psz_cmd, "pause" ) )
686 var_Set( p_input, "state", val );
687 vlc_object_release( p_input );
690 else if( !strcmp( psz_cmd, "seek" ) )
692 if( strlen( newval.psz_string ) > 0 &&
693 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
695 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
696 var_Set( p_input, "position", val );
700 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
701 var_Set( p_input, "time", val );
703 vlc_object_release( p_input );
707 else if( !strcmp( psz_cmd, "chapter" ) ||
708 !strcmp( psz_cmd, "chapter_n" ) ||
709 !strcmp( psz_cmd, "chapter_p" ) )
711 if( !strcmp( psz_cmd, "chapter" ) )
713 if ( *newval.psz_string )
716 val.i_int = atoi( newval.psz_string );
717 var_Set( p_input, "chapter", val );
721 vlc_value_t val_list;
724 var_Get( p_input, "chapter", &val );
725 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
727 printf( _("Currently playing chapter %d/%d\n"),
728 val.i_int, val_list.p_list->i_count );
729 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
733 else if( !strcmp( psz_cmd, "chapter_n" ) )
735 val.b_bool = VLC_TRUE;
736 var_Set( p_input, "next-chapter", val );
738 else if( !strcmp( psz_cmd, "chapter_p" ) )
740 val.b_bool = VLC_TRUE;
741 var_Set( p_input, "prev-chapter", val );
744 vlc_object_release( p_input );
747 else if( !strcmp( psz_cmd, "title" ) ||
748 !strcmp( psz_cmd, "title_n" ) ||
749 !strcmp( psz_cmd, "title_p" ) )
751 if( !strcmp( psz_cmd, "title" ) )
753 if ( *newval.psz_string )
756 val.i_int = atoi( newval.psz_string );
757 var_Set( p_input, "title", val );
761 vlc_value_t val_list;
764 var_Get( p_input, "title", &val );
765 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
767 printf( _("Currently playing title %d/%d\n"),
768 val.i_int, val_list.p_list->i_count );
769 var_Change( p_this, "title", VLC_VAR_FREELIST,
773 else if( !strcmp( psz_cmd, "title_n" ) )
775 val.b_bool = VLC_TRUE;
776 var_Set( p_input, "next-title", val );
778 else if( !strcmp( psz_cmd, "title_p" ) )
780 val.b_bool = VLC_TRUE;
781 var_Set( p_input, "prev-title", val );
784 vlc_object_release( p_input );
792 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
793 vlc_value_t oldval, vlc_value_t newval, void *p_data )
795 intf_thread_t *p_intf = (intf_thread_t*)p_this;
796 playlist_t *p_playlist;
798 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
805 /* Parse commands that require a playlist */
806 if( !strcmp( psz_cmd, "prev" ) )
808 playlist_Prev( p_playlist );
810 else if( !strcmp( psz_cmd, "next" ) )
812 playlist_Next( p_playlist );
814 else if( !strcmp( psz_cmd, "play" ) )
816 playlist_Play( p_playlist );
818 else if( !strcmp( psz_cmd, "stop" ) )
820 playlist_Stop( p_playlist );
822 else if( !strcmp( psz_cmd, "add" ) )
824 printf( _("trying to add %s to playlist\n"), newval.psz_string );
825 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
826 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
828 else if( !strcmp( psz_cmd, "playlist" ) )
831 for ( i = 0; i < p_playlist->i_size; i++ )
833 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
834 p_playlist->pp_items[i]->input.psz_name,
835 p_playlist->pp_items[i]->input.psz_uri );
839 printf( _("| no entries\n") );
848 printf( _("unknown command!\n") );
851 vlc_object_release( p_playlist );
855 static int Other( vlc_object_t *p_this, char const *psz_cmd,
856 vlc_value_t oldval, vlc_value_t newval, void *p_data )
858 intf_thread_t *p_intf = (intf_thread_t*)p_this;
862 p_pl = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
869 /* Parse miscellaneous commands */
870 if( !strcmp( psz_cmd, "marq-marquee" ) )
872 if( strlen( newval.psz_string ) > 0 )
874 val.psz_string = newval.psz_string;
875 var_Set( p_pl, "marq-marquee", val );
880 var_Set( p_pl, "marq-marquee", val);
883 else if( !strcmp( psz_cmd, "marq-x" ) )
885 if( strlen( newval.psz_string ) > 0)
887 val.i_int = atoi( newval.psz_string );
888 var_Set( p_pl, "marq-x", val );
891 else if( !strcmp( psz_cmd, "marq-y" ) )
893 if( strlen( newval.psz_string ) > 0)
895 val.i_int = atoi( newval.psz_string );
896 var_Set( p_pl, "marq-y", val );
899 else if( !strcmp( psz_cmd, "marq-timeout" ) )
901 if( strlen( newval.psz_string ) > 0)
903 val.i_int = atoi( newval.psz_string );
904 var_Set( p_pl, "marq-timeout", val );
913 printf( _("unknown command!\n") );
916 vlc_object_release( p_pl );
920 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
921 vlc_value_t oldval, vlc_value_t newval, void *p_data )
923 p_this->p_vlc->b_die = VLC_TRUE;
927 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
928 vlc_value_t oldval, vlc_value_t newval, void *p_data )
930 intf_thread_t *p_newintf;
932 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
936 p_newintf->b_block = VLC_FALSE;
937 if( intf_RunThread( p_newintf ) )
939 vlc_object_detach( p_newintf );
940 intf_Destroy( p_newintf );
947 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
948 vlc_value_t oldval, vlc_value_t newval, void *p_data )
950 intf_thread_t *p_intf = (intf_thread_t*)p_this;
953 if ( *newval.psz_string )
956 audio_volume_t i_volume = atoi( newval.psz_string );
957 if ( i_volume > AOUT_VOLUME_MAX )
959 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
961 i_error = VLC_EBADVAR;
963 else i_error = aout_VolumeSet( p_this, i_volume );
968 audio_volume_t i_volume;
969 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
971 i_error = VLC_EGENERIC;
975 printf( _("Volume is %d\n"), i_volume );
976 i_error = VLC_SUCCESS;
983 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
984 vlc_value_t oldval, vlc_value_t newval, void *p_data )
986 intf_thread_t *p_intf = (intf_thread_t*)p_this;
987 audio_volume_t i_volume;
988 int i_nb_steps = atoi(newval.psz_string);
989 int i_error = VLC_SUCCESS;
991 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
996 if ( !strcmp(psz_cmd, "volup") )
998 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
999 i_error = VLC_EGENERIC;
1003 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1004 i_error = VLC_EGENERIC;
1007 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
1011 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1012 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1014 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1015 aout_instance_t * p_aout;
1016 const char * psz_variable;
1017 vlc_value_t val_name;
1020 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1021 if ( p_aout == NULL ) return VLC_ENOOBJ;
1023 if ( !strcmp( psz_cmd, "adev" ) )
1025 psz_variable = "audio-device";
1029 psz_variable = "audio-channels";
1032 /* Get the descriptive name of the variable */
1033 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1035 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1037 if ( !*newval.psz_string )
1039 /* Retrieve all registered ***. */
1040 vlc_value_t val, text;
1043 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1045 vlc_object_release( (vlc_object_t *)p_aout );
1046 return VLC_EGENERIC;
1048 i_value = val.i_int;
1050 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1051 VLC_VAR_GETLIST, &val, &text ) < 0 )
1053 vlc_object_release( (vlc_object_t *)p_aout );
1054 return VLC_EGENERIC;
1057 printf( "+----[ %s ]\n", val_name.psz_string );
1058 for ( i = 0; i < val.p_list->i_count; i++ )
1060 if ( i_value == val.p_list->p_values[i].i_int )
1061 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1062 text.p_list->p_values[i].psz_string );
1064 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
1065 text.p_list->p_values[i].psz_string );
1067 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1069 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
1071 if( val_name.psz_string ) free( val_name.psz_string );
1072 i_error = VLC_SUCCESS;
1077 val.i_int = atoi( newval.psz_string );
1079 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1081 vlc_object_release( (vlc_object_t *)p_aout );
1087 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1089 INPUT_RECORD input_record;
1092 /* On Win32, select() only works on socket descriptors */
1093 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1094 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1096 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1097 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1100 if( input_record.EventType != KEY_EVENT ||
1101 !input_record.Event.KeyEvent.bKeyDown ||
1102 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1103 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1104 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1105 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1107 /* nothing interesting */
1111 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1113 /* Echo out the command */
1114 putc( p_buffer[ *pi_size ], stdout );
1116 /* Handle special keys */
1117 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1119 putc( '\n', stdout );
1122 switch( p_buffer[ *pi_size ] )
1128 putc( ' ', stdout );
1129 putc( '\b', stdout );
1140 if( *pi_size == MAX_LINE_LENGTH ||
1141 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1143 p_buffer[ *pi_size ] = 0;
1152 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1157 if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1158 return ReadWin32( p_intf, p_buffer, pi_size );
1159 else if( p_intf->p_sys->i_socket == -1 )
1161 msleep( INTF_IDLE_SLEEP );
1166 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1167 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1168 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket,
1169 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1171 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1177 /* Connection closed */
1180 p_intf->p_sys->i_socket = -1;
1181 p_buffer[ *pi_size ] = 0;
1185 if( *pi_size == MAX_LINE_LENGTH ||
1186 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1188 p_buffer[ *pi_size ] = 0;