1 /*****************************************************************************
2 * rtci.c : real time control interface stdin/stdout module for vlc
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
5 * $Id: rc.c 8847 2004-09-29 11:36:37Z markfm $
7 * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /******************************************************************************
26 * Module purpose -- provide a socket based interface to control various
27 * VLC parameters and obtain status information on the fly. Output
28 * will be purposely less verbose than on some interfaces -- this
29 * interface is intended more for comms with an external program than a human
30 *****************************************************************************/
32 /*****************************************************************************
34 *****************************************************************************/
35 #include <stdlib.h> /* malloc(), free() */
38 #include <errno.h> /* ENOMEM */
52 #ifdef HAVE_SYS_TIME_H
53 # include <sys/time.h>
55 #include <sys/types.h>
57 #include "vlc_error.h"
60 #if defined(PF_UNIX) && !defined(PF_LOCAL)
61 # define PF_LOCAL PF_UNIX
63 #if defined(AF_UNIX) && !defined(AF_LOCAL)
64 # define AF_LOCAL AF_UNIX
71 #define MAX_LINE_LENGTH 256
73 /*****************************************************************************
75 *****************************************************************************/
76 static int Activate ( vlc_object_t * );
77 static void Deactivate ( vlc_object_t * );
78 static void Run ( intf_thread_t * );
80 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
82 static int Input ( vlc_object_t *, char const *,
83 vlc_value_t, vlc_value_t, void * );
84 static int Playlist ( vlc_object_t *, char const *,
85 vlc_value_t, vlc_value_t, void * );
86 static int Other ( vlc_object_t *, char const *,
87 vlc_value_t, vlc_value_t, void * );
88 static int Quit ( vlc_object_t *, char const *,
89 vlc_value_t, vlc_value_t, void * );
90 static int Intf ( vlc_object_t *, char const *,
91 vlc_value_t, vlc_value_t, void * );
92 static int Volume ( vlc_object_t *, char const *,
93 vlc_value_t, vlc_value_t, void * );
94 static int VolumeMove ( vlc_object_t *, char const *,
95 vlc_value_t, vlc_value_t, void * );
96 static int AudioConfig ( vlc_object_t *, char const *,
97 vlc_value_t, vlc_value_t, void * );
111 #ifdef HAVE_VARIADIC_MACROS
112 # define msg_rtci( psz_format, args... ) \
113 __msg_rtci( p_intf, psz_format, ## args )
116 static void __msg_rtci( intf_thread_t *p_intf, const char *psz_fmt, ... )
119 va_start( args, psz_fmt );
120 if( p_intf->p_sys->i_socket == -1 ) vprintf( psz_fmt, args );
121 else net_vaPrintf( p_intf, p_intf->p_sys->i_socket, psz_fmt, args );
125 /*****************************************************************************
127 *****************************************************************************/
128 #define POS_TEXT N_("Show stream position")
129 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
130 "stream from time to time." )
132 #define TTY_TEXT N_("Fake TTY")
133 #define TTY_LONGTEXT N_("Force the rtci module to use stdin as if it was a TTY.")
135 #define UNIX_TEXT N_("UNIX socket command input")
136 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
139 #define HOST_TEXT N_("TCP command input")
140 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
141 "You can set the address and port the interface will bind to." )
142 #define EXTEND_TEXT N_("Extended help")
143 #define EXTEND_LONGTEXT N_("List additional commands.")
146 #define QUIET_TEXT N_("Do not open a DOS command box interface")
147 #define QUIET_LONGTEXT N_( \
148 "By default the rtci interface plugin will start a DOS command box. " \
149 "Enabling the quiet mode will not launch this command box." )
153 set_description( _("Real time control interface") );
154 set_category( CAT_INTERFACE );
155 set_subcategory( SUBCAT_INTERFACE_GENERAL );
156 add_bool( "rtci-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
158 add_bool( "rtci-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
160 add_string( "rtci-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
161 add_string( "rtci-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
164 add_bool( "rtci-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
166 add_bool( "rtci-extend", 0, NULL, EXTEND_TEXT, EXTEND_LONGTEXT, VLC_FALSE );
168 set_capability( "interface", 20 );
169 set_callbacks( Activate, Deactivate );
172 /*****************************************************************************
173 * Activate: initialize and create stuff
174 *****************************************************************************/
175 static int Activate( vlc_object_t *p_this )
177 intf_thread_t *p_intf = (intf_thread_t*)p_this;
178 char *psz_host, *psz_unix_path;
181 #if defined(HAVE_ISATTY) && !defined(WIN32)
182 /* Check that stdin is a TTY */
183 if( !config_GetInt( p_intf, "rtci-fake-tty" ) && !isatty( 0 ) )
185 msg_Warn( p_intf, "fd 0 is not a TTY" );
190 psz_unix_path = config_GetPsz( p_intf, "rtci-unix" );
194 msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
195 free( psz_unix_path );
198 struct sockaddr_un addr;
201 memset( &addr, 0, sizeof(struct sockaddr_un) );
203 msg_Dbg( p_intf, "trying UNIX socket" );
205 if( (i_socket = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
207 msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
208 free( psz_unix_path );
212 addr.sun_family = AF_LOCAL;
213 strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
214 addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
216 if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
217 sizeof(struct sockaddr_un) ) ) < 0 )
219 msg_Warn( p_intf, "couldn't bind socket to address: %s",
221 free( psz_unix_path );
222 net_Close( i_socket );
226 if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
228 msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
229 free( psz_unix_path );
230 net_Close( i_socket );
236 if( ( i_socket == -1) &&
237 ( psz_host = config_GetPsz( p_intf, "rtci-host" ) ) != NULL )
241 vlc_UrlParse( &url, psz_host, 0 );
243 msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
245 if( (i_socket = net_ListenTCP(p_this, url.psz_host, url.i_port)) == -1)
247 msg_Warn( p_intf, "can't listen to %s port %i",
248 url.psz_host, url.i_port );
249 vlc_UrlClean( &url );
254 vlc_UrlClean( &url );
258 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
261 msg_Err( p_intf, "no memory" );
265 p_intf->p_sys->i_socket_listen = i_socket;
266 p_intf->p_sys->i_socket = -1;
267 p_intf->p_sys->psz_unix_path = psz_unix_path;
269 /* Non-buffered stdout */
270 setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
272 p_intf->pf_run = Run;
275 if( !config_GetInt( p_intf, "rtci-quiet" ) ) { CONSOLE_INTRO_MSG; }
280 msg_rtci( _("Real time control interface initialized, `h' for help\n") );
284 /*****************************************************************************
285 * Deactivate: uninitialize and cleanup
286 *****************************************************************************/
287 static void Deactivate( vlc_object_t *p_this )
289 intf_thread_t *p_intf = (intf_thread_t*)p_this;
291 if( p_intf->p_sys->i_socket_listen != -1 )
292 net_Close( p_intf->p_sys->i_socket_listen );
293 if( p_intf->p_sys->i_socket != -1 )
294 net_Close( p_intf->p_sys->i_socket );
295 if( p_intf->p_sys->psz_unix_path != NULL )
298 unlink( p_intf->p_sys->psz_unix_path );
300 free( p_intf->p_sys->psz_unix_path );
302 free( p_intf->p_sys );
305 /*****************************************************************************
307 *****************************************************************************
308 * This part of the interface is in a separate thread so that we can call
309 * exec() from within it without annoying the rest of the program.
310 *****************************************************************************/
311 static void Run( intf_thread_t *p_intf )
313 input_thread_t * p_input;
314 playlist_t * p_playlist;
316 char p_buffer[ MAX_LINE_LENGTH + 1 ];
317 vlc_bool_t b_showpos = config_GetInt( p_intf, "rtci-show-pos" );
327 p_intf->p_sys->b_extend = config_GetInt( p_intf, "rtci-extend" );
328 /* Register commands that will be cleaned up upon object destruction */
329 var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
330 var_AddCallback( p_intf, "quit", Quit, NULL );
331 var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
332 var_AddCallback( p_intf, "intf", Intf, NULL );
334 var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
335 var_AddCallback( p_intf, "add", Playlist, NULL );
336 var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
337 var_AddCallback( p_intf, "playlist", Playlist, NULL );
338 var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
339 var_AddCallback( p_intf, "play", Playlist, NULL );
340 var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
341 var_AddCallback( p_intf, "stop", Playlist, NULL );
342 var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
343 var_AddCallback( p_intf, "prev", Playlist, NULL );
344 var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
345 var_AddCallback( p_intf, "next", Playlist, NULL );
346 var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
347 var_AddCallback( p_intf, "goto", Playlist, NULL );
349 var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
350 var_AddCallback( p_intf, "marq-marquee", Other, NULL );
351 var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
352 var_AddCallback( p_intf, "marq-x", Other, NULL );
353 var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
354 var_AddCallback( p_intf, "marq-y", Other, NULL );
355 var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
356 var_AddCallback( p_intf, "marq-timeout", Other, NULL );
358 var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
359 var_AddCallback( p_intf, "pause", Input, NULL );
360 var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
361 var_AddCallback( p_intf, "seek", Input, NULL );
362 var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
363 var_AddCallback( p_intf, "title", Input, NULL );
364 var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
365 var_AddCallback( p_intf, "title_n", Input, NULL );
366 var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
367 var_AddCallback( p_intf, "title_p", Input, NULL );
368 var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
369 var_AddCallback( p_intf, "chapter", Input, NULL );
370 var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
371 var_AddCallback( p_intf, "chapter_n", Input, NULL );
372 var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
373 var_AddCallback( p_intf, "chapter_p", Input, NULL );
375 var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
376 var_AddCallback( p_intf, "fastforward", Input, NULL );
377 var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
378 var_AddCallback( p_intf, "rewind", Input, NULL );
380 var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
381 var_AddCallback( p_intf, "volume", Volume, NULL );
382 var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
383 var_AddCallback( p_intf, "volup", VolumeMove, NULL );
384 var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
385 var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
386 var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
387 var_AddCallback( p_intf, "adev", AudioConfig, NULL );
388 var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
389 var_AddCallback( p_intf, "achan", AudioConfig, NULL );
392 /* Get the file descriptor of the console input */
393 p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
394 if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
396 msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
397 p_intf->b_die = VLC_TRUE;
401 while( !p_intf->b_die )
403 char *psz_cmd, *psz_arg;
404 vlc_bool_t b_complete;
406 if( p_intf->p_sys->i_socket_listen != - 1 &&
407 p_intf->p_sys->i_socket == -1 )
409 p_intf->p_sys->i_socket =
410 net_Accept( p_intf, p_intf->p_sys->i_socket_listen, 0 );
413 b_complete = ReadCommand( p_intf, p_buffer, &i_size );
415 /* Manage the input part */
416 if( p_input == NULL )
420 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
425 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
429 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
434 else if( p_input->b_dead )
436 vlc_object_release( p_input );
440 if( p_input && b_showpos )
442 i_newpos = 100 * var_GetFloat( p_input, "position" );
443 if( i_oldpos != i_newpos )
446 msg_rtci( "pos: %d%%\n", i_newpos );
450 /* Is there something to do? */
451 if( !b_complete ) continue;
454 /* Skip heading spaces */
456 while( *psz_cmd == ' ' )
461 /* Split psz_cmd at the first space and make sure that
462 * psz_arg is valid */
463 psz_arg = strchr( psz_cmd, ' ' );
467 while( *psz_arg == ' ' )
477 /* If the user typed a registered local command, try it */
478 if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
483 val.psz_string = psz_arg;
484 i_ret = var_Set( p_intf, psz_cmd, val );
485 msg_rtci( "%s: returned %i (%s)\n",
486 psz_cmd, i_ret, vlc_error( i_ret ) );
488 /* Or maybe it's a global command */
489 else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
494 val.psz_string = psz_arg;
495 /* FIXME: it's a global command, but we should pass the
496 * local object as an argument, not p_intf->p_libvlc. */
497 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
500 msg_rtci( "%s: returned %i (%s)\n",
501 psz_cmd, i_ret, vlc_error( i_ret ) );
504 else if( !strcmp( psz_cmd, "logout" ) )
506 /* Close connection */
507 if( p_intf->p_sys->i_socket != -1 )
509 net_Close( p_intf->p_sys->i_socket );
511 p_intf->p_sys->i_socket = -1;
513 else if( !strcmp( psz_cmd, "info" ) )
518 vlc_mutex_lock( &p_input->input.p_item->lock );
519 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
521 info_category_t *p_category =
522 p_input->input.p_item->pp_categories[i];
524 msg_rtci( "+----[ %s ]\n", p_category->psz_name );
526 for ( j = 0; j < p_category->i_infos; j++ )
528 info_t *p_info = p_category->pp_infos[j];
529 msg_rtci( "| %s: %s\n", p_info->psz_name,
534 msg_rtci( "+----[ end of stream info ]\n" );
535 vlc_mutex_unlock( &p_input->input.p_item->lock );
539 msg_rtci( "no input\n" );
542 else if( !strcmp( psz_cmd, "is_playing" ) )
553 else if( !strcmp( psz_cmd, "get_time" ) )
562 var_Get( p_input, "time", &time );
563 msg_rtci( "%i\n", time.i_time / 1000000);
566 else if( !strcmp( psz_cmd, "get_length" ) )
575 var_Get( p_input, "length", &time );
576 msg_rtci( "%i\n", time.i_time / 1000000);
579 else if( !strcmp( psz_cmd, "get_title" ) )
587 msg_rtci( "%s\n", p_input->input.p_item->psz_name );
590 else switch( psz_cmd[0] )
596 vout_thread_t *p_vout;
597 p_vout = vlc_object_find( p_input,
598 VLC_OBJECT_VOUT, FIND_CHILD );
602 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
603 vlc_object_release( p_vout );
616 msg_rtci(_("+----[ Remote control commands ]\n"));
618 msg_rtci(_("| add XYZ . . . . . . . . . . add XYZ to playlist\n"));
619 msg_rtci(_("| playlist . . . show items currently in playlist\n"));
620 msg_rtci(_("| play . . . . . . . . . . . . . . . . play stream\n"));
621 msg_rtci(_("| stop . . . . . . . . . . . . . . . . stop stream\n"));
622 msg_rtci(_("| next . . . . . . . . . . . . next playlist item\n"));
623 msg_rtci(_("| prev . . . . . . . . . . previous playlist item\n"));
624 msg_rtci(_("| goto . . . . . . . . . . . . goto item at index\n"));
625 msg_rtci(_("| title [X] . . . . set/get title in current item\n"));
626 msg_rtci(_("| title_n . . . . . . next title in current item\n"));
627 msg_rtci(_("| title_p . . . . previous title in current item\n"));
628 msg_rtci(_("| chapter [X] . . set/get chapter in current item\n"));
629 msg_rtci(_("| chapter_n . . . . next chapter in current item\n"));
630 msg_rtci(_("| chapter_p . . previous chapter in current item\n"));
632 msg_rtci(_("| seek X . seek in seconds, for instance `seek 12'\n"));
633 msg_rtci(_("| pause . . . . . . . . . . . . . . toggle pause\n"));
634 msg_rtci(_("| fastforward . . . . . . . set to maximum rate\n"));
635 msg_rtci(_("| rewind . . . . . . . . . . set to minimum rate\n"));
636 msg_rtci(_("| f . . . . . . . . . . . . . . toggle fullscreen\n"));
637 msg_rtci(_("| info . . . information about the current stream\n"));
639 msg_rtci(_("| volume [X] . . . . . . . . set/get audio volume\n"));
640 msg_rtci(_("| volup [X] . . . . . raise audio volume X steps\n"));
641 msg_rtci(_("| voldown [X] . . . . lower audio volume X steps\n"));
642 msg_rtci(_("| adev [X] . . . . . . . . . set/get audio device\n"));
643 msg_rtci(_("| achan [X]. . . . . . . . set/get audio channels\n"));
646 if (p_intf->p_sys->b_extend)
648 msg_rtci(_("| marq-marquee STRING . . overlay STRING in video\n"));
649 msg_rtci(_("| marq-x X . . . . . .offset of marquee, from left\n"));
650 msg_rtci(_("| marq-y Y . . . . . . offset of marquee, from top\n"));
651 msg_rtci(_("| marq-timeout T. . . . .timeout of marquee, in ms\n"));
654 msg_rtci(_("| help . . . . . . . . . . . . . this help message\n"));
655 msg_rtci(_("| logout . . . . . .exit (if in socket connection)\n"));
656 msg_rtci(_("| quit . . . . . . . . . . . . . . . . . quit vlc\n"));
658 msg_rtci(_("+----[ end of help ]\n"));
662 /* Ignore empty lines */
666 msg_rtci(_("unknown command `%s', type `help' for help\n"), psz_cmd);
670 /* Command processed */
671 i_size = 0; p_buffer[0] = 0;
676 vlc_object_release( p_input );
682 vlc_object_release( p_playlist );
687 static int Input( vlc_object_t *p_this, char const *psz_cmd,
688 vlc_value_t oldval, vlc_value_t newval, void *p_data )
690 intf_thread_t *p_intf = (intf_thread_t*)p_this;
691 input_thread_t *p_input;
694 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
695 if( !p_input ) return VLC_ENOOBJ;
697 /* Parse commands that only require an input */
698 if( !strcmp( psz_cmd, "pause" ) )
702 var_Set( p_input, "state", val );
703 vlc_object_release( p_input );
706 else if( !strcmp( psz_cmd, "seek" ) )
708 if( strlen( newval.psz_string ) > 0 &&
709 newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
711 val.f_float = (float)atoi( newval.psz_string ) / 100.0;
712 var_Set( p_input, "position", val );
716 val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
717 var_Set( p_input, "time", val );
719 vlc_object_release( p_input );
722 else if ( !strcmp( psz_cmd, "fastforward" ) )
724 val.i_int = INPUT_RATE_MAX;
726 var_Set( p_input, "rate", val );
727 vlc_object_release( p_input );
730 else if ( !strcmp( psz_cmd, "rewind" ) )
732 val.i_int = INPUT_RATE_MIN;
734 var_Set( p_input, "rate", val );
735 vlc_object_release( p_input );
738 else if( !strcmp( psz_cmd, "chapter" ) ||
739 !strcmp( psz_cmd, "chapter_n" ) ||
740 !strcmp( psz_cmd, "chapter_p" ) )
742 if( !strcmp( psz_cmd, "chapter" ) )
744 if ( *newval.psz_string )
747 val.i_int = atoi( newval.psz_string );
748 var_Set( p_input, "chapter", val );
752 vlc_value_t val_list;
755 var_Get( p_input, "chapter", &val );
756 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
758 msg_rtci( "Currently playing chapter %d/%d\n",
759 val.i_int, val_list.p_list->i_count );
760 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
764 else if( !strcmp( psz_cmd, "chapter_n" ) )
766 val.b_bool = VLC_TRUE;
767 var_Set( p_input, "next-chapter", val );
769 else if( !strcmp( psz_cmd, "chapter_p" ) )
771 val.b_bool = VLC_TRUE;
772 var_Set( p_input, "prev-chapter", val );
775 vlc_object_release( p_input );
778 else if( !strcmp( psz_cmd, "title" ) ||
779 !strcmp( psz_cmd, "title_n" ) ||
780 !strcmp( psz_cmd, "title_p" ) )
782 if( !strcmp( psz_cmd, "title" ) )
784 if ( *newval.psz_string )
787 val.i_int = atoi( newval.psz_string );
788 var_Set( p_input, "title", val );
792 vlc_value_t val_list;
795 var_Get( p_input, "title", &val );
796 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
798 msg_rtci( "Currently playing title %d/%d\n",
799 val.i_int, val_list.p_list->i_count );
800 var_Change( p_this, "title", VLC_VAR_FREELIST,
804 else if( !strcmp( psz_cmd, "title_n" ) )
806 val.b_bool = VLC_TRUE;
807 var_Set( p_input, "next-title", val );
809 else if( !strcmp( psz_cmd, "title_p" ) )
811 val.b_bool = VLC_TRUE;
812 var_Set( p_input, "prev-title", val );
815 vlc_object_release( p_input );
823 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
824 vlc_value_t oldval, vlc_value_t newval, void *p_data )
826 intf_thread_t *p_intf = (intf_thread_t*)p_this;
827 playlist_t *p_playlist;
829 p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
836 /* Parse commands that require a playlist */
837 if( !strcmp( psz_cmd, "prev" ) )
839 playlist_Prev( p_playlist );
841 else if( !strcmp( psz_cmd, "next" ) )
843 playlist_Next( p_playlist );
845 else if( !strcmp( psz_cmd, "play" ) )
847 playlist_Play( p_playlist );
849 else if (!strcmp( psz_cmd, "goto" ) )
851 if( strlen( newval.psz_string ) > 0)
853 val.i_int = atoi( newval.psz_string );
854 playlist_Goto( p_playlist, val.i_int);
857 else if( !strcmp( psz_cmd, "stop" ) )
859 playlist_Stop( p_playlist );
861 else if( !strcmp( psz_cmd, "add" ) )
863 msg_rtci( "trying to add %s to playlist\n", newval.psz_string );
864 playlist_Add( p_playlist, newval.psz_string, newval.psz_string,
865 PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
867 else if( !strcmp( psz_cmd, "playlist" ) )
870 for ( i = 0; i < p_playlist->i_size; i++ )
872 msg_rtci( "|%s%s %s|\n", i == p_playlist->i_index ? "*" : " ",
873 p_playlist->pp_items[i]->input.psz_name,
874 p_playlist->pp_items[i]->input.psz_uri,
875 p_playlist->pp_items[i]->i_parents > 0 ?
876 p_playlist->pp_items[i]->pp_parents[0]->p_parent->input.psz_name : "" );
880 msg_rtci( "| no entries\n" );
889 msg_rtci( "unknown command!\n" );
892 vlc_object_release( p_playlist );
896 static int Other( vlc_object_t *p_this, char const *psz_cmd,
897 vlc_value_t oldval, vlc_value_t newval, void *p_data )
899 intf_thread_t *p_intf = (intf_thread_t*)p_this;
903 p_pl = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
910 /* Parse miscellaneous commands */
911 if( !strcmp( psz_cmd, "marq-marquee" ) )
913 if( strlen( newval.psz_string ) > 0 )
915 val.psz_string = newval.psz_string;
916 var_Set( p_pl, "marq-marquee", val );
921 var_Set( p_pl, "marq-marquee", val);
924 else if( !strcmp( psz_cmd, "marq-x" ) )
926 if( strlen( newval.psz_string ) > 0)
928 val.i_int = atoi( newval.psz_string );
929 var_Set( p_pl, "marq-x", val );
932 else if( !strcmp( psz_cmd, "marq-y" ) )
934 if( strlen( newval.psz_string ) > 0)
936 val.i_int = atoi( newval.psz_string );
937 var_Set( p_pl, "marq-y", val );
940 else if( !strcmp( psz_cmd, "marq-timeout" ) )
942 if( strlen( newval.psz_string ) > 0)
944 val.i_int = atoi( newval.psz_string );
945 var_Set( p_pl, "marq-timeout", val );
954 msg_rtci( "unknown command!\n" );
957 vlc_object_release( p_pl );
961 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
962 vlc_value_t oldval, vlc_value_t newval, void *p_data )
964 p_this->p_vlc->b_die = VLC_TRUE;
968 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
969 vlc_value_t oldval, vlc_value_t newval, void *p_data )
971 intf_thread_t *p_newintf;
973 p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
977 p_newintf->b_block = VLC_FALSE;
978 if( intf_RunThread( p_newintf ) )
980 vlc_object_detach( p_newintf );
981 intf_Destroy( p_newintf );
988 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
989 vlc_value_t oldval, vlc_value_t newval, void *p_data )
991 intf_thread_t *p_intf = (intf_thread_t*)p_this;
994 if ( *newval.psz_string )
997 audio_volume_t i_volume = atoi( newval.psz_string );
998 if ( i_volume > AOUT_VOLUME_MAX )
1000 msg_rtci( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
1002 i_error = VLC_EBADVAR;
1004 else i_error = aout_VolumeSet( p_this, i_volume );
1009 audio_volume_t i_volume;
1010 if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1012 i_error = VLC_EGENERIC;
1016 msg_rtci( "Volume is %d\n", i_volume );
1017 i_error = VLC_SUCCESS;
1024 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1025 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1027 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1028 audio_volume_t i_volume;
1029 int i_nb_steps = atoi(newval.psz_string);
1030 int i_error = VLC_SUCCESS;
1032 if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
1037 if ( !strcmp(psz_cmd, "volup") )
1039 if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1040 i_error = VLC_EGENERIC;
1044 if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1045 i_error = VLC_EGENERIC;
1048 if ( !i_error ) msg_rtci( "Volume is %d\n", i_volume );
1052 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1053 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1055 intf_thread_t *p_intf = (intf_thread_t*)p_this;
1056 aout_instance_t * p_aout;
1057 const char * psz_variable;
1058 vlc_value_t val_name;
1061 p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1062 if ( p_aout == NULL ) return VLC_ENOOBJ;
1064 if ( !strcmp( psz_cmd, "adev" ) )
1066 psz_variable = "audio-device";
1070 psz_variable = "audio-channels";
1073 /* Get the descriptive name of the variable */
1074 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1076 if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1078 if ( !*newval.psz_string )
1080 /* Retrieve all registered ***. */
1081 vlc_value_t val, text;
1084 if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1086 vlc_object_release( (vlc_object_t *)p_aout );
1087 return VLC_EGENERIC;
1089 i_value = val.i_int;
1091 if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1092 VLC_VAR_GETLIST, &val, &text ) < 0 )
1094 vlc_object_release( (vlc_object_t *)p_aout );
1095 return VLC_EGENERIC;
1098 msg_rtci( "+----[ %s ]\n", val_name.psz_string );
1099 for ( i = 0; i < val.p_list->i_count; i++ )
1101 if ( i_value == val.p_list->p_values[i].i_int )
1102 msg_rtci( "| %i - %s *\n", val.p_list->p_values[i].i_int,
1103 text.p_list->p_values[i].psz_string );
1105 msg_rtci( "| %i - %s\n", val.p_list->p_values[i].i_int,
1106 text.p_list->p_values[i].psz_string );
1108 var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1110 msg_rtci( "+----[ end of %s ]\n", val_name.psz_string );
1112 if( val_name.psz_string ) free( val_name.psz_string );
1113 i_error = VLC_SUCCESS;
1118 val.i_int = atoi( newval.psz_string );
1120 i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1122 vlc_object_release( (vlc_object_t *)p_aout );
1128 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1130 INPUT_RECORD input_record;
1133 /* On Win32, select() only works on socket descriptors */
1134 while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1135 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1137 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1138 ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1141 if( input_record.EventType != KEY_EVENT ||
1142 !input_record.Event.KeyEvent.bKeyDown ||
1143 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1144 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1145 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1146 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1148 /* nothing interesting */
1152 p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1154 /* Echo out the command */
1155 putc( p_buffer[ *pi_size ], stdout );
1157 /* Handle special keys */
1158 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1160 putc( '\n', stdout );
1163 switch( p_buffer[ *pi_size ] )
1169 putc( ' ', stdout );
1170 putc( '\b', stdout );
1181 if( *pi_size == MAX_LINE_LENGTH ||
1182 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1184 p_buffer[ *pi_size ] = 0;
1193 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1198 if( p_intf->p_sys->i_socket == -1 )
1199 return ReadWin32( p_intf, p_buffer, pi_size );
1202 while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
1203 (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
1204 STDIN_FILENO : p_intf->p_sys->i_socket,
1205 p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
1207 if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1213 /* Connection closed */
1216 p_intf->p_sys->i_socket = -1;
1217 p_buffer[ *pi_size ] = 0;
1221 if( *pi_size == MAX_LINE_LENGTH ||
1222 p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1224 p_buffer[ *pi_size ] = 0;