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 * );
103 #ifdef HAVE_VARIADIC_MACROS
104 # define printf( psz_format, args... ) \
105 Printf( p_intf, psz_format, ## args )
108 void Printf( intf_thread_t *p_intf, const char *psz_fmt, ... )
111 va_start( args, psz_fmt );
112 if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
113 else net_vaPrintf( p_intf, p_intf->p_sys->i_socket, psz_fmt, args );
117 /*****************************************************************************
119 *****************************************************************************/
120 #define POS_TEXT N_("Show stream position")
121 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
122 "stream from time to time." )
124 #define TTY_TEXT N_("Fake TTY")
125 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
127 #define UNIX_TEXT N_("UNIX socket command input")
128 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
131 #define HOST_TEXT N_("TCP command input")
132 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
133 "You can set the address and port the interface will bind to." )
134 #define EXTEND_TEXT N_("Extended help")
135 #define EXTEND_LONGTEXT N_("List additional commands.")
139 #define QUIET_TEXT N_("Do not open a DOS command box interface")
140 #define QUIET_LONGTEXT N_( \
141 "By default the rc interface plugin will start a DOS command box. " \
142 "Enabling the quiet mode will not bring this command box but can also " \
143 "be pretty annoying when you want to stop VLC and no video window is " \
148 set_description( _("Remote control interface") );
149 add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
151 add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
153 add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
154 add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
157 add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
159 add_bool( "rc-extend", 0, NULL, EXTEND_TEXT, EXTEND_LONGTEXT, VLC_FALSE );
161 set_capability( "interface", 20 );
162 set_callbacks( Activate, Deactivate );
165 /*****************************************************************************
166 * Activate: initialize and create stuff
167 *****************************************************************************/
168 static int Activate( vlc_object_t *p_this )
170 intf_thread_t *p_intf = (intf_thread_t*)p_this;
171 char *psz_host, *psz_unix_path;
174 #if defined(HAVE_ISATTY) && !defined(WIN32)
175 /* Check that stdin is a TTY */
176 if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
178 msg_Warn( p_intf, "fd 0 is not a TTY" );
183 psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
187 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
188 free( psz_unix_path );
191 struct sockaddr_un addr;
194 memset( &addr, 0, sizeof(struct sockaddr_un) );
196 msg_Dbg( p_intf, "trying UNIX socket" );
198 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
200 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
201 free( psz_unix_path );
205 addr.sun_family = AF_LOCAL;
206 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
207 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
209 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
210 sizeof(struct sockaddr_un) ) ) < 0 )
212 msg_Warn( p_intf, "couldn't bind socket to address: %s",
214 free( psz_unix_path );
215 net_Close( i_socket );
219 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
221 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
222 free( psz_unix_path );
223 net_Close( i_socket );
229 if( ( i_socket == -1) &&
230 ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
234 vlc_UrlParse( &url, psz_host, 0 );
236 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
238 if( (i_socket = net_ListenTCP(p_this, url.psz_host, url.i_port)) == -1)
240 msg_Warn( p_intf, "can't listen to %s port %i",
241 url.psz_host, url.i_port );
242 vlc_UrlClean( &url );
247 vlc_UrlClean( &url );
251 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
254 msg_Err( p_intf, "no memory" );
258 p_intf->p_sys->i_socket_listen = i_socket;
259 p_intf->p_sys->i_socket = -1;
260 p_intf->p_sys->psz_unix_path = psz_unix_path;
262 /* Non-buffered stdout */
263 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
265 p_intf->pf_run = Run;
268 if( !config_GetInt( p_intf, "rc-quiet" ) ) { CONSOLE_INTRO_MSG; }
273 printf( _("Remote control interface initialized, `h' for help\n") );
277 /*****************************************************************************
278 * Deactivate: uninitialize and cleanup
279 *****************************************************************************/
280 static void Deactivate( vlc_object_t *p_this )
282 intf_thread_t *p_intf = (intf_thread_t*)p_this;
284 if( p_intf->p_sys->i_socket_listen != -1 )
285 net_Close( p_intf->p_sys->i_socket_listen );
286 if( p_intf->p_sys->i_socket != -1 )
287 net_Close( p_intf->p_sys->i_socket );
288 if( p_intf->p_sys->psz_unix_path != NULL )
291 unlink( p_intf->p_sys->psz_unix_path );
293 free( p_intf->p_sys->psz_unix_path );
295 free( p_intf->p_sys );
298 /*****************************************************************************
300 *****************************************************************************
301 * This part of the interface is in a separate thread so that we can call
302 * exec() from within it without annoying the rest of the program.
303 *****************************************************************************/
304 static void Run( intf_thread_t *p_intf )
306 input_thread_t * p_input;
307 playlist_t * p_playlist;
309 char p_buffer[ MAX_LINE_LENGTH + 1 ];
310 vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
320 p_intf->p_sys->b_extend = config_GetInt( p_intf, "rc-extend" );
321 /* Register commands that will be cleaned up upon object destruction */
322 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
323 var_AddCallback( p_intf, "quit", Quit, NULL );
324 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
325 var_AddCallback( p_intf, "intf", Intf, NULL );
327 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
328 var_AddCallback( p_intf, "add", Playlist, NULL );
329 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
330 var_AddCallback( p_intf, "playlist", Playlist, NULL );
331 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
332 var_AddCallback( p_intf, "play", Playlist, NULL );
333 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
334 var_AddCallback( p_intf, "stop", Playlist, NULL );
335 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
336 var_AddCallback( p_intf, "prev", Playlist, NULL );
337 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
338 var_AddCallback( p_intf, "next", Playlist, NULL );
340 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
341 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
342 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
343 var_AddCallback( p_intf, "marq-x", Other, NULL );
344 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
345 var_AddCallback( p_intf, "marq-y", Other, NULL );
346 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
347 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
349 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
350 var_AddCallback( p_intf, "pause", Input, NULL );
351 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
352 var_AddCallback( p_intf, "seek", Input, NULL );
353 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
354 var_AddCallback( p_intf, "title", Input, NULL );
355 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
356 var_AddCallback( p_intf, "title_n", Input, NULL );
357 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
358 var_AddCallback( p_intf, "title_p", Input, NULL );
359 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
360 var_AddCallback( p_intf, "chapter", Input, NULL );
361 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
362 var_AddCallback( p_intf, "chapter_n", Input, NULL );
363 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
364 var_AddCallback( p_intf, "chapter_p", Input, NULL );
366 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
367 var_AddCallback( p_intf, "volume", Volume, NULL );
368 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
369 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
370 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
371 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
372 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
373 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
374 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
375 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
378 /* Get the file descriptor of the console input */
379 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
380 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
382 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
383 p_intf->b_die = VLC_TRUE;
387 while( !p_intf->b_die )
389 char *psz_cmd, *psz_arg;
390 vlc_bool_t b_complete;
392 if( p_intf->p_sys->i_socket_listen != - 1 &&
393 p_intf->p_sys->i_socket == -1 )
395 p_intf->p_sys->i_socket =
396 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
399 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
401 /* Manage the input part */
402 if( p_input == NULL )
406 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
411 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
415 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
420 else if( p_input->b_dead )
422 vlc_object_release( p_input );
426 if( p_input && b_showpos )
428 i_newpos = 100 * var_GetFloat( p_input, "position" );
429 if( i_oldpos != i_newpos )
432 printf( "pos: %d%%\n", i_newpos );
436 /* Is there something to do? */
437 if( !b_complete ) continue;
440 /* Skip heading spaces */
442 while( *psz_cmd == ' ' )
447 /* Split psz_cmd at the first space and make sure that
448 * psz_arg is valid */
449 psz_arg = strchr( psz_cmd, ' ' );
453 while( *psz_arg == ' ' )
463 /* If the user typed a registered local command, try it */
464 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
469 val.psz_string = psz_arg;
470 i_ret = var_Set( p_intf, psz_cmd, val );
471 printf( _("%s: returned %i (%s)\n"),
472 psz_cmd, i_ret, vlc_error( i_ret ) );
474 /* Or maybe it's a global command */
475 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
480 val.psz_string = psz_arg;
481 /* FIXME: it's a global command, but we should pass the
482 * local object as an argument, not p_intf->p_libvlc. */
483 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
486 printf( _("%s: returned %i (%s)\n"),
487 psz_cmd, i_ret, vlc_error( i_ret ) );
490 else if( !strcmp( psz_cmd, "logout" ) )
492 /* Close connection */
493 if( p_intf->p_sys->i_socket != -1 )
495 net_Close( p_intf->p_sys->i_socket );
497 p_intf->p_sys->i_socket = -1;
499 else if( !strcmp( psz_cmd, "info" ) )
504 vlc_mutex_lock( &p_input->input.p_item->lock );
505 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
507 info_category_t *p_category =
508 p_input->input.p_item->pp_categories[i];
510 printf( "+----[ %s ]\n", p_category->psz_name );
512 for ( j = 0; j < p_category->i_infos; j++ )
514 info_t *p_info = p_category->pp_infos[j];
515 printf( "| %s: %s\n", p_info->psz_name,
520 printf( _("+----[ end of stream info ]\n") );
521 vlc_mutex_unlock( &p_input->input.p_item->lock );
525 printf( _("no input\n") );
528 else if( !strcmp( psz_cmd, "is_playing" ) )
539 else if( !strcmp( psz_cmd, "get_time" ) )
548 var_Get( p_input, "time", &time );
549 printf( "%i\n", time.i_time / 1000000);
552 else if( !strcmp( psz_cmd, "get_length" ) )
561 var_Get( p_input, "length", &time );
562 printf( "%i\n", time.i_time / 1000000);
565 else if( !strcmp( psz_cmd, "get_title" ) )
573 printf( "%s\n", p_input->input.p_item->psz_name );
576 else switch( psz_cmd[0] )
582 vout_thread_t *p_vout;
583 p_vout = vlc_object_find( p_input,
584 VLC_OBJECT_VOUT, FIND_CHILD );
588 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
589 vlc_object_release( p_vout );
602 printf(_("+----[ Remote control commands ]\n"));
604 printf(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
605 printf(_("| playlist . . . show items currently in playlist\n"));
606 printf(_("| play . . . . . . . . . . . . . . . . play stream\n"));
607 printf(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
608 printf(_("| next . . . . . . . . . . . . next playlist item\n"));
609 printf(_("| prev . . . . . . . . . . previous playlist item\n"));
610 printf(_("| title [X] . . . . set/get title in current item\n"));
611 printf(_("| title_n . . . . . . next title in current item\n"));
612 printf(_("| title_p . . . . previous title in current item\n"));
613 printf(_("| chapter [X] . . set/get chapter in current item\n"));
614 printf(_("| chapter_n . . . . next chapter in current item\n"));
615 printf(_("| chapter_p . . previous chapter in current item\n"));
617 printf(_("| seek X . seek in seconds, for instance `seek 12'\n"));
618 printf(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
619 printf(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
620 printf(_("| info . . . information about the current stream\n"));
622 printf(_("| volume [X] . . . . . . . . set/get audio volume\n"));
623 printf(_("| volup [X] . . . . . raise audio volume X steps\n"));
624 printf(_("| voldown [X] . . . . lower audio volume X steps\n"));
625 printf(_("| adev [X] . . . . . . . . . set/get audio device\n"));
626 printf(_("| achan [X]. . . . . . . . set/get audio channels\n"));
628 if (p_intf->p_sys->b_extend)
630 printf(_("| marq-marquee STRING . . overlay STRING in video\n"));
631 printf(_("| marq-x X . . . . . .offset of marquee, from left\n"));
632 printf(_("| marq-y Y . . . . . . offset of marquee, from top\n"));
633 printf(_("| marq-timeout T. . . . .timeout of marquee, in ms\n"));
636 printf(_("| help . . . . . . . . . . . . . this help message\n"));
637 printf(_("| logout . . . . . .exit (if in socket connection)\n"));
638 printf(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
640 printf(_("+----[ end of help ]\n"));
644 /* Ignore empty lines */
648 printf(_("unknown command `%s', type `help' for help\n"), psz_cmd);
652 /* Command processed */
653 i_size = 0; p_buffer[0] = 0;
658 vlc_object_release( p_input );
664 vlc_object_release( p_playlist );
669 static int Input( vlc_object_t *p_this, char const *psz_cmd,
670 vlc_value_t oldval, vlc_value_t newval, void *p_data )
672 intf_thread_t *p_intf = (intf_thread_t*)p_this;
673 input_thread_t *p_input;
676 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
677 if( !p_input ) return VLC_ENOOBJ;
679 /* Parse commands that only require an input */
680 if( !strcmp( psz_cmd, "pause" ) )
684 var_Set( p_input, "state", val );
685 vlc_object_release( p_input );
688 else if( !strcmp( psz_cmd, "seek" ) )
690 if( strlen( newval.psz_string ) > 0 &&
691 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
693 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
694 var_Set( p_input, "position", val );
698 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
699 var_Set( p_input, "time", val );
701 vlc_object_release( p_input );
705 else if( !strcmp( psz_cmd, "chapter" ) ||
706 !strcmp( psz_cmd, "chapter_n" ) ||
707 !strcmp( psz_cmd, "chapter_p" ) )
709 if( !strcmp( psz_cmd, "chapter" ) )
711 if ( *newval.psz_string )
714 val.i_int = atoi( newval.psz_string );
715 var_Set( p_input, "chapter", val );
719 vlc_value_t val_list;
722 var_Get( p_input, "chapter", &val );
723 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
725 printf( _("Currently playing chapter %d/%d\n"),
726 val.i_int, val_list.p_list->i_count );
727 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
731 else if( !strcmp( psz_cmd, "chapter_n" ) )
733 val.b_bool = VLC_TRUE;
734 var_Set( p_input, "next-chapter", val );
736 else if( !strcmp( psz_cmd, "chapter_p" ) )
738 val.b_bool = VLC_TRUE;
739 var_Set( p_input, "prev-chapter", val );
742 vlc_object_release( p_input );
745 else if( !strcmp( psz_cmd, "title" ) ||
746 !strcmp( psz_cmd, "title_n" ) ||
747 !strcmp( psz_cmd, "title_p" ) )
749 if( !strcmp( psz_cmd, "title" ) )
751 if ( *newval.psz_string )
754 val.i_int = atoi( newval.psz_string );
755 var_Set( p_input, "title", val );
759 vlc_value_t val_list;
762 var_Get( p_input, "title", &val );
763 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
765 printf( _("Currently playing title %d/%d\n"),
766 val.i_int, val_list.p_list->i_count );
767 var_Change( p_this, "title", VLC_VAR_FREELIST,
771 else if( !strcmp( psz_cmd, "title_n" ) )
773 val.b_bool = VLC_TRUE;
774 var_Set( p_input, "next-title", val );
776 else if( !strcmp( psz_cmd, "title_p" ) )
778 val.b_bool = VLC_TRUE;
779 var_Set( p_input, "prev-title", val );
782 vlc_object_release( p_input );
790 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
791 vlc_value_t oldval, vlc_value_t newval, void *p_data )
793 intf_thread_t *p_intf = (intf_thread_t*)p_this;
794 playlist_t *p_playlist;
796 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
803 /* Parse commands that require a playlist */
804 if( !strcmp( psz_cmd, "prev" ) )
806 playlist_Prev( p_playlist );
808 else if( !strcmp( psz_cmd, "next" ) )
810 playlist_Next( p_playlist );
812 else if( !strcmp( psz_cmd, "play" ) )
814 playlist_Play( p_playlist );
816 else if( !strcmp( psz_cmd, "stop" ) )
818 playlist_Stop( p_playlist );
820 else if( !strcmp( psz_cmd, "add" ) )
822 printf( _("trying to add %s to playlist\n"), newval.psz_string );
823 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
824 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
826 else if( !strcmp( psz_cmd, "playlist" ) )
829 for ( i = 0; i < p_playlist->i_size; i++ )
831 printf( "|%s%s %s|\n", i == p_playlist->i_index?"*":" ",
832 p_playlist->pp_items[i]->input.psz_name,
833 p_playlist->pp_items[i]->input.psz_uri );
837 printf( _("| no entries\n") );
846 printf( _("unknown command!\n") );
849 vlc_object_release( p_playlist );
853 static int Other( vlc_object_t *p_this, char const *psz_cmd,
854 vlc_value_t oldval, vlc_value_t newval, void *p_data )
856 intf_thread_t *p_intf = (intf_thread_t*)p_this;
860 p_pl = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
867 /* Parse miscellaneous commands */
868 if( !strcmp( psz_cmd, "marq-marquee" ) )
870 if( strlen( newval.psz_string ) > 0 )
872 val.psz_string = newval.psz_string;
873 var_Set( p_pl, "marq-marquee", val );
878 var_Set( p_pl, "marq-marquee", val);
881 else if( !strcmp( psz_cmd, "marq-x" ) )
883 if( strlen( newval.psz_string ) > 0)
885 val.i_int = atoi( newval.psz_string );
886 var_Set( p_pl, "marq-x", val );
889 else if( !strcmp( psz_cmd, "marq-y" ) )
891 if( strlen( newval.psz_string ) > 0)
893 val.i_int = atoi( newval.psz_string );
894 var_Set( p_pl, "marq-y", val );
897 else if( !strcmp( psz_cmd, "marq-timeout" ) )
899 if( strlen( newval.psz_string ) > 0)
901 val.i_int = atoi( newval.psz_string );
902 var_Set( p_pl, "marq-timeout", val );
911 printf( _("unknown command!\n") );
914 vlc_object_release( p_pl );
918 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
919 vlc_value_t oldval, vlc_value_t newval, void *p_data )
921 p_this->p_vlc->b_die = VLC_TRUE;
925 static int Intf( 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_newintf;
930 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
934 p_newintf->b_block = VLC_FALSE;
935 if( intf_RunThread( p_newintf ) )
937 vlc_object_detach( p_newintf );
938 intf_Destroy( p_newintf );
945 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
946 vlc_value_t oldval, vlc_value_t newval, void *p_data )
948 intf_thread_t *p_intf = (intf_thread_t*)p_this;
951 if ( *newval.psz_string )
954 audio_volume_t i_volume = atoi( newval.psz_string );
955 if ( i_volume > AOUT_VOLUME_MAX )
957 printf( _("Volume must be in the range %d-%d\n"), AOUT_VOLUME_MIN,
959 i_error = VLC_EBADVAR;
961 else i_error = aout_VolumeSet( p_this, i_volume );
966 audio_volume_t i_volume;
967 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
969 i_error = VLC_EGENERIC;
973 printf( _("Volume is %d\n"), i_volume );
974 i_error = VLC_SUCCESS;
981 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
982 vlc_value_t oldval, vlc_value_t newval, void *p_data )
984 intf_thread_t *p_intf = (intf_thread_t*)p_this;
985 audio_volume_t i_volume;
986 int i_nb_steps = atoi(newval.psz_string);
987 int i_error = VLC_SUCCESS;
989 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
994 if ( !strcmp(psz_cmd, "volup") )
996 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
997 i_error = VLC_EGENERIC;
1001 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1002 i_error = VLC_EGENERIC;
1005 if ( !i_error ) printf( _("Volume is %d\n"), i_volume );
1009 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1010 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1012 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1013 aout_instance_t * p_aout;
1014 const char * psz_variable;
1015 vlc_value_t val_name;
1018 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1019 if ( p_aout == NULL ) return VLC_ENOOBJ;
1021 if ( !strcmp( psz_cmd, "adev" ) )
1023 psz_variable = "audio-device";
1027 psz_variable = "audio-channels";
1030 /* Get the descriptive name of the variable */
1031 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1033 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1035 if ( !*newval.psz_string )
1037 /* Retrieve all registered ***. */
1038 vlc_value_t val, text;
1041 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1043 vlc_object_release( (vlc_object_t *)p_aout );
1044 return VLC_EGENERIC;
1046 i_value = val.i_int;
1048 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1049 VLC_VAR_GETLIST, &val, &text ) < 0 )
1051 vlc_object_release( (vlc_object_t *)p_aout );
1052 return VLC_EGENERIC;
1055 printf( "+----[ %s ]\n", val_name.psz_string );
1056 for ( i = 0; i < val.p_list->i_count; i++ )
1058 if ( i_value == val.p_list->p_values[i].i_int )
1059 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1060 text.p_list->p_values[i].psz_string );
1062 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
1063 text.p_list->p_values[i].psz_string );
1065 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1067 printf( _("+----[ end of %s ]\n"), val_name.psz_string );
1069 if( val_name.psz_string ) free( val_name.psz_string );
1070 i_error = VLC_SUCCESS;
1075 val.i_int = atoi( newval.psz_string );
1077 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1079 vlc_object_release( (vlc_object_t *)p_aout );
1085 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1087 INPUT_RECORD input_record;
1090 /* On Win32, select() only works on socket descriptors */
1091 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1092 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1094 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1095 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1098 if( input_record.EventType != KEY_EVENT ||
1099 !input_record.Event.KeyEvent.bKeyDown ||
1100 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1101 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1102 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1103 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1105 /* nothing interesting */
1109 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1111 /* Echo out the command */
1112 putc( p_buffer[ *pi_size ], stdout );
1114 /* Handle special keys */
1115 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1117 putc( '\n', stdout );
1120 switch( p_buffer[ *pi_size ] )
1126 putc( ' ', stdout );
1127 putc( '\b', stdout );
1138 if( *pi_size == MAX_LINE_LENGTH ||
1139 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1141 p_buffer[ *pi_size ] = 0;
1150 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1155 if( p_intf->p_sys->i_socket == -1 )
1156 return ReadWin32( p_intf, p_buffer, pi_size );
1159 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1160 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1161 0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket,
1162 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1164 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1170 /* Connection closed */
1173 p_intf->p_sys->i_socket = -1;
1174 p_buffer[ *pi_size ] = 0;
1178 if( *pi_size == MAX_LINE_LENGTH ||
1179 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1181 p_buffer[ *pi_size ] = 0;