Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

rc.c

00001 /*****************************************************************************
00002  * rc.c : remote control stdin/stdout module for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2004 - 2005 the VideoLAN team
00005  * $Id: rc.c 13127 2005-11-03 20:39:41Z jpsaman $
00006  *
00007  * Author: Peter Surda <[email protected]>
00008  *         Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <string.h>
00030 
00031 #include <errno.h>                                                 /* ENOMEM */
00032 #include <stdio.h>
00033 #include <ctype.h>
00034 #include <signal.h>
00035 
00036 #include <vlc/vlc.h>
00037 #include <vlc/intf.h>
00038 #include <vlc/aout.h>
00039 #include <vlc/vout.h>
00040 #include <vlc_video.h>
00041 #include <vlc_osd.h>
00042 
00043 #ifdef HAVE_UNISTD_H
00044 #    include <unistd.h>
00045 #endif
00046 
00047 #ifdef HAVE_SYS_TIME_H
00048 #    include <sys/time.h>
00049 #endif
00050 #include <sys/types.h>
00051 
00052 #include "vlc_error.h"
00053 #include "network.h"
00054 
00055 #if defined(AF_UNIX) && !defined(AF_LOCAL)
00056 #    define AF_LOCAL AF_UNIX
00057 #endif
00058 
00059 #if defined(AF_LOCAL) && ! defined(WIN32)
00060 #    include <sys/un.h>
00061 #endif
00062 
00063 #define MAX_LINE_LENGTH 256
00064 #define STATUS_CHANGE "status change: "
00065 
00066 /*****************************************************************************
00067  * Local prototypes
00068  *****************************************************************************/
00069 static int  Activate     ( vlc_object_t * );
00070 static void Deactivate   ( vlc_object_t * );
00071 static void Run          ( intf_thread_t * );
00072 
00073 static void Help         ( intf_thread_t *, vlc_bool_t );
00074 static void RegisterCallbacks( intf_thread_t * );
00075 
00076 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
00077 
00078 static playlist_item_t *parse_MRL( intf_thread_t *, char * );
00079 
00080 static int  Input        ( vlc_object_t *, char const *,
00081                            vlc_value_t, vlc_value_t, void * );
00082 static int  Playlist     ( vlc_object_t *, char const *,
00083                            vlc_value_t, vlc_value_t, void * );
00084 static int  Other        ( vlc_object_t *, char const *,
00085                            vlc_value_t, vlc_value_t, void * );
00086 static int  Quit         ( vlc_object_t *, char const *,
00087                            vlc_value_t, vlc_value_t, void * );
00088 static int  Intf         ( vlc_object_t *, char const *,
00089                            vlc_value_t, vlc_value_t, void * );
00090 static int  Volume       ( vlc_object_t *, char const *,
00091                            vlc_value_t, vlc_value_t, void * );
00092 static int  VolumeMove   ( vlc_object_t *, char const *,
00093                            vlc_value_t, vlc_value_t, void * );
00094 static int  AudioConfig  ( vlc_object_t *, char const *,
00095                            vlc_value_t, vlc_value_t, void * );
00096 static int  Menu         ( vlc_object_t *, char const *,
00097                            vlc_value_t, vlc_value_t, void * );
00098 
00099 /* Status Callbacks */
00100 static int TimeOffsetChanged( vlc_object_t *, char const *,
00101                               vlc_value_t, vlc_value_t , void * );
00102 static int VolumeChanged    ( vlc_object_t *, char const *,
00103                               vlc_value_t, vlc_value_t, void * );
00104 static int StateChanged     ( vlc_object_t *, char const *,
00105                               vlc_value_t, vlc_value_t, void * );
00106 static int RateChanged      ( vlc_object_t *, char const *,
00107                               vlc_value_t, vlc_value_t, void * );
00108 
00109 struct intf_sys_t
00110 {
00111     int *pi_socket_listen;
00112     int i_socket;
00113     char *psz_unix_path;
00114 
00115     /* status changes */
00116     vlc_mutex_t       status_lock;
00117     playlist_status_t i_last_state;
00118 
00119 #ifdef WIN32
00120     HANDLE hConsoleIn;
00121     vlc_bool_t b_quiet;
00122 #endif
00123 };
00124 
00125 #ifdef HAVE_VARIADIC_MACROS
00126 #   define msg_rc( psz_format, args... ) \
00127       __msg_rc( p_intf, psz_format, ## args )
00128 #endif
00129 
00130 void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
00131 {
00132     va_list args;
00133     va_start( args, psz_fmt );
00134 
00135     if( p_intf->p_sys->i_socket == -1 )
00136     {
00137         vprintf( psz_fmt, args );
00138         printf( "\r\n" );
00139     }
00140     else
00141     {
00142         net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
00143         net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
00144     }
00145     va_end( args );
00146 }
00147 
00148 /*****************************************************************************
00149  * Module descriptor
00150  *****************************************************************************/
00151 #define POS_TEXT N_("Show stream position")
00152 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
00153                         "stream from time to time." )
00154 
00155 #define TTY_TEXT N_("Fake TTY")
00156 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
00157 
00158 #define UNIX_TEXT N_("UNIX socket command input")
00159 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
00160                          "stdin." )
00161 
00162 #define HOST_TEXT N_("TCP command input")
00163 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
00164             "You can set the address and port the interface will bind to." )
00165 
00166 #ifdef WIN32
00167 #define QUIET_TEXT N_("Do not open a DOS command box interface")
00168 #define QUIET_LONGTEXT N_( \
00169     "By default the rc interface plugin will start a DOS command box. " \
00170     "Enabling the quiet mode will not bring this command box but can also " \
00171     "be pretty annoying when you want to stop VLC and no video window is " \
00172     "open." )
00173 #endif
00174 
00175 vlc_module_begin();
00176     set_shortname( _("RC"));
00177     set_category( CAT_INTERFACE );
00178     set_subcategory( SUBCAT_INTERFACE_GENERAL );
00179     set_description( _("Remote control interface") );
00180     add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
00181 #ifdef HAVE_ISATTY
00182     add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
00183 #endif
00184     add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
00185     add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
00186 
00187 #ifdef WIN32
00188     add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
00189 #endif
00190 
00191     set_capability( "interface", 20 );
00192     set_callbacks( Activate, Deactivate );
00193 vlc_module_end();
00194 
00195 /*****************************************************************************
00196  * Activate: initialize and create stuff
00197  *****************************************************************************/
00198 static int Activate( vlc_object_t *p_this )
00199 {
00200     intf_thread_t *p_intf = (intf_thread_t*)p_this;
00201     playlist_t *p_playlist;
00202     char *psz_host, *psz_unix_path;
00203     int  *pi_socket = NULL;
00204 
00205 #if defined(HAVE_ISATTY) && !defined(WIN32)
00206     /* Check that stdin is a TTY */
00207     if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
00208     {
00209         msg_Warn( p_intf, "fd 0 is not a TTY" );
00210         return VLC_EGENERIC;
00211     }
00212 #endif
00213 
00214     psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
00215     if( psz_unix_path )
00216     {
00217         int i_socket;
00218 
00219 #if !defined(AF_LOCAL) || defined(WIN32)
00220         msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
00221         free( psz_unix_path );
00222         return VLC_EGENERIC;
00223 #else
00224         struct sockaddr_un addr;
00225         int i_ret;
00226 
00227         memset( &addr, 0, sizeof(struct sockaddr_un) );
00228 
00229         msg_Dbg( p_intf, "trying UNIX socket" );
00230 
00231         if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
00232         {
00233             msg_Warn( p_intf, "can't open socket: %s", strerror(errno) );
00234             free( psz_unix_path );
00235             return VLC_EGENERIC;
00236         }
00237 
00238         addr.sun_family = AF_LOCAL;
00239         strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
00240         addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
00241 
00242         if( (i_ret = bind( i_socket, (struct sockaddr*)&addr,
00243                            sizeof(struct sockaddr_un) ) ) < 0 )
00244         {
00245             msg_Warn( p_intf, "couldn't bind socket to address: %s",
00246                       strerror(errno) );
00247             free( psz_unix_path );
00248             net_Close( i_socket );
00249             return VLC_EGENERIC;
00250         }
00251 
00252         if( ( i_ret = listen( i_socket, 1 ) ) < 0 )
00253         {
00254             msg_Warn( p_intf, "can't listen on socket: %s", strerror(errno));
00255             free( psz_unix_path );
00256             net_Close( i_socket );
00257             return VLC_EGENERIC;
00258         }
00259 
00260         /* FIXME: we need a core function to merge listening sockets sets */
00261         pi_socket = calloc( 2, sizeof( int ) );
00262         if( pi_socket == NULL )
00263         {
00264             free( psz_unix_path );
00265             net_Close( i_socket );
00266             return VLC_ENOMEM;
00267         }
00268         pi_socket[0] = i_socket;
00269         pi_socket[1] = -1;
00270 #endif
00271     }
00272 
00273     if( ( pi_socket == NULL ) &&
00274         ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
00275     {
00276         vlc_url_t url;
00277 
00278         vlc_UrlParse( &url, psz_host, 0 );
00279 
00280         msg_Dbg( p_intf, "base %s port %d", url.psz_host, url.i_port );
00281 
00282         pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
00283         if( pi_socket == NULL )
00284         {
00285             msg_Warn( p_intf, "can't listen to %s port %i",
00286                       url.psz_host, url.i_port );
00287             vlc_UrlClean( &url );
00288             free( psz_host );
00289             return VLC_EGENERIC;
00290         }
00291 
00292         vlc_UrlClean( &url );
00293         free( psz_host );
00294     }
00295 
00296     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
00297     if( !p_intf->p_sys )
00298     {
00299         msg_Err( p_intf, "no memory" );
00300         return VLC_ENOMEM;
00301     }
00302 
00303     p_intf->p_sys->pi_socket_listen = pi_socket;
00304     p_intf->p_sys->i_socket = -1;
00305     p_intf->p_sys->psz_unix_path = psz_unix_path;
00306     vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
00307     p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
00308 
00309     /* Non-buffered stdout */
00310     setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
00311 
00312     p_intf->pf_run = Run;
00313 
00314 #ifdef WIN32
00315     p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
00316     if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
00317 #else
00318     CONSOLE_INTRO_MSG;
00319 #endif
00320 
00321     /* Force "no-view" mode */
00322     p_playlist = (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
00323                                                  FIND_ANYWHERE );
00324     if( p_playlist )
00325     {
00326         vlc_mutex_lock( &p_playlist->object_lock );
00327         p_playlist->status.i_view = -1;
00328         vlc_mutex_unlock( &p_playlist->object_lock );
00329         vlc_object_release( p_playlist );
00330     }
00331 
00332     msg_rc( _("Remote control interface initialized, `h' for help") );
00333     return VLC_SUCCESS;
00334 }
00335 
00336 /*****************************************************************************
00337  * Deactivate: uninitialize and cleanup
00338  *****************************************************************************/
00339 static void Deactivate( vlc_object_t *p_this )
00340 {
00341     intf_thread_t *p_intf = (intf_thread_t*)p_this;
00342 
00343     net_ListenClose( p_intf->p_sys->pi_socket_listen );
00344     if( p_intf->p_sys->i_socket != -1 )
00345         net_Close( p_intf->p_sys->i_socket );
00346     if( p_intf->p_sys->psz_unix_path != NULL )
00347     {
00348 #if defined(AF_LOCAL) && !defined(WIN32)
00349         unlink( p_intf->p_sys->psz_unix_path );
00350 #endif
00351         free( p_intf->p_sys->psz_unix_path );
00352     }
00353     vlc_mutex_destroy( &p_intf->p_sys->status_lock );    
00354     free( p_intf->p_sys );
00355 }
00356 
00357 /*****************************************************************************
00358  * RegisterCallbacks: Register callbacks to dynamic variables
00359  *****************************************************************************/
00360 static void RegisterCallbacks( intf_thread_t *p_intf )
00361 {
00362     /* Register commands that will be cleaned up upon object destruction */
00363     var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00364     var_AddCallback( p_intf, "quit", Quit, NULL );
00365     var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00366     var_AddCallback( p_intf, "intf", Intf, NULL );
00367 
00368     var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00369     var_AddCallback( p_intf, "add", Playlist, NULL );
00370     var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00371     var_AddCallback( p_intf, "playlist", Playlist, NULL );
00372     var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00373     var_AddCallback( p_intf, "play", Playlist, NULL );
00374     var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00375     var_AddCallback( p_intf, "stop", Playlist, NULL );
00376     var_Create( p_intf, "clear", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00377     var_AddCallback( p_intf, "clear", Playlist, NULL );
00378     var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00379     var_AddCallback( p_intf, "prev", Playlist, NULL );
00380     var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00381     var_AddCallback( p_intf, "next", Playlist, NULL );
00382     var_Create( p_intf, "goto", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00383     var_AddCallback( p_intf, "goto", Playlist, NULL );
00384     var_Create( p_intf, "status", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00385     var_AddCallback( p_intf, "status", Playlist, NULL );
00386 
00387     /* marquee on the fly items */
00388     var_Create( p_intf, "marq-marquee", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00389     var_AddCallback( p_intf, "marq-marquee", Other, NULL );
00390     var_Create( p_intf, "marq-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00391     var_AddCallback( p_intf, "marq-x", Other, NULL );
00392     var_Create( p_intf, "marq-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00393     var_AddCallback( p_intf, "marq-y", Other, NULL );
00394     var_Create( p_intf, "marq-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00395     var_AddCallback( p_intf, "marq-position", Other, NULL );
00396     var_Create( p_intf, "marq-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00397     var_AddCallback( p_intf, "marq-color", Other, NULL );
00398     var_Create( p_intf, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00399     var_AddCallback( p_intf, "marq-opacity", Other, NULL );
00400     var_Create( p_intf, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00401     var_AddCallback( p_intf, "marq-timeout", Other, NULL );
00402     var_Create( p_intf, "marq-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00403     var_AddCallback( p_intf, "marq-size", Other, NULL );
00404 
00405     var_Create( p_intf, "mosaic-alpha", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00406     var_AddCallback( p_intf, "mosaic-alpha", Other, NULL );
00407     var_Create( p_intf, "mosaic-height", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00408     var_AddCallback( p_intf, "mosaic-height", Other, NULL );
00409     var_Create( p_intf, "mosaic-width", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00410     var_AddCallback( p_intf, "mosaic-width", Other, NULL );
00411     var_Create( p_intf, "mosaic-xoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00412     var_AddCallback( p_intf, "mosaic-xoffset", Other, NULL );
00413     var_Create( p_intf, "mosaic-yoffset", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00414     var_AddCallback( p_intf, "mosaic-yoffset", Other, NULL );
00415     var_Create( p_intf, "mosaic-align", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00416     var_AddCallback( p_intf, "mosaic-align", Other, NULL );
00417     var_Create( p_intf, "mosaic-vborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00418     var_AddCallback( p_intf, "mosaic-vborder", Other, NULL );
00419     var_Create( p_intf, "mosaic-hborder", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00420     var_AddCallback( p_intf, "mosaic-hborder", Other, NULL );
00421     var_Create( p_intf, "mosaic-position",
00422                      VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00423     var_AddCallback( p_intf, "mosaic-position", Other, NULL );
00424     var_Create( p_intf, "mosaic-rows", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00425     var_AddCallback( p_intf, "mosaic-rows", Other, NULL );
00426     var_Create( p_intf, "mosaic-cols", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00427     var_AddCallback( p_intf, "mosaic-cols", Other, NULL );
00428     var_Create( p_intf, "mosaic-keep-aspect-ratio",
00429                      VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00430     var_AddCallback( p_intf, "mosaic-keep-aspect-ratio", Other, NULL );
00431 
00432     /* time on the fly items */
00433     var_Create( p_intf, "time-format", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00434     var_AddCallback( p_intf, "time-format", Other, NULL );
00435     var_Create( p_intf, "time-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00436     var_AddCallback( p_intf, "time-x", Other, NULL );
00437     var_Create( p_intf, "time-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00438     var_AddCallback( p_intf, "time-y", Other, NULL );
00439     var_Create( p_intf, "time-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00440     var_AddCallback( p_intf, "time-position", Other, NULL );
00441     var_Create( p_intf, "time-color", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00442     var_AddCallback( p_intf, "time-color", Other, NULL );
00443     var_Create( p_intf, "time-opacity", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00444     var_AddCallback( p_intf, "time-opacity", Other, NULL );
00445     var_Create( p_intf, "time-size", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00446     var_AddCallback( p_intf, "time-size", Other, NULL );
00447 
00448     /* logo on the fly items */
00449     var_Create( p_intf, "logo-file", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00450     var_AddCallback( p_intf, "logo-file", Other, NULL );
00451     var_Create( p_intf, "logo-x", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00452     var_AddCallback( p_intf, "logo-x", Other, NULL );
00453     var_Create( p_intf, "logo-y", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00454     var_AddCallback( p_intf, "logo-y", Other, NULL );
00455     var_Create( p_intf, "logo-position", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00456     var_AddCallback( p_intf, "logo-position", Other, NULL );
00457     var_Create( p_intf, "logo-transparency", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00458     var_AddCallback( p_intf, "logo-transparency", Other, NULL );
00459 
00460     /* OSD menu commands */
00461     var_Create( p_intf, "menu", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00462     var_AddCallback( p_intf, "menu", Menu, NULL ); 
00463 
00464     /* DVD commands */
00465     var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00466     var_AddCallback( p_intf, "pause", Input, NULL );
00467     var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
00468     var_AddCallback( p_intf, "seek", Input, NULL );
00469     var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00470     var_AddCallback( p_intf, "title", Input, NULL );
00471     var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00472     var_AddCallback( p_intf, "title_n", Input, NULL );
00473     var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00474     var_AddCallback( p_intf, "title_p", Input, NULL );
00475     var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00476     var_AddCallback( p_intf, "chapter", Input, NULL );
00477     var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00478     var_AddCallback( p_intf, "chapter_n", Input, NULL );
00479     var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00480     var_AddCallback( p_intf, "chapter_p", Input, NULL );
00481 
00482     var_Create( p_intf, "fastforward", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00483     var_AddCallback( p_intf, "fastforward", Input, NULL );
00484     var_Create( p_intf, "rewind", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00485     var_AddCallback( p_intf, "rewind", Input, NULL );
00486     var_Create( p_intf, "faster", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00487     var_AddCallback( p_intf, "faster", Input, NULL );
00488     var_Create( p_intf, "slower", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00489     var_AddCallback( p_intf, "slower", Input, NULL );
00490     var_Create( p_intf, "normal", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
00491     var_AddCallback( p_intf, "normal", Input, NULL );
00492 
00493     /* audio commands */
00494     var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00495     var_AddCallback( p_intf, "volume", Volume, NULL );
00496     var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00497     var_AddCallback( p_intf, "volup", VolumeMove, NULL );
00498     var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00499     var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
00500     var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00501     var_AddCallback( p_intf, "adev", AudioConfig, NULL );
00502     var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
00503     var_AddCallback( p_intf, "achan", AudioConfig, NULL );
00504 }
00505 
00506 /*****************************************************************************
00507  * Run: rc thread
00508  *****************************************************************************
00509  * This part of the interface is in a separate thread so that we can call
00510  * exec() from within it without annoying the rest of the program.
00511  *****************************************************************************/
00512 static void Run( intf_thread_t *p_intf )
00513 {
00514     input_thread_t * p_input;
00515     playlist_t *     p_playlist;
00516 
00517     char       p_buffer[ MAX_LINE_LENGTH + 1 ];
00518     vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
00519     vlc_bool_t b_longhelp = VLC_FALSE;
00520 
00521     int        i_size = 0;
00522     int        i_oldpos = 0;
00523     int        i_newpos;
00524 
00525     p_buffer[0] = 0;
00526     p_input = NULL;
00527     p_playlist = NULL;
00528 
00529     /* Register commands that will be cleaned up upon object destruction */
00530     RegisterCallbacks( p_intf );
00531 
00532     /* status callbacks */
00533     /* Listen to audio volume updates */
00534     var_AddCallback( p_intf->p_vlc, "volume-change", VolumeChanged, p_intf );
00535 
00536 #ifdef WIN32
00537     /* Get the file descriptor of the console input */
00538     p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
00539     if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
00540     {
00541         msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" );
00542         p_intf->b_die = VLC_TRUE;
00543     }
00544 #endif
00545 
00546     while( !p_intf->b_die )
00547     {
00548         char *psz_cmd, *psz_arg;
00549         vlc_bool_t b_complete;
00550 
00551         if( p_intf->p_sys->pi_socket_listen != NULL &&
00552             p_intf->p_sys->i_socket == -1 )
00553         {
00554             p_intf->p_sys->i_socket =
00555                 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen, 0 );
00556         }
00557 
00558         b_complete = ReadCommand( p_intf, p_buffer, &i_size );
00559 
00560         /* Manage the input part */
00561         if( p_input == NULL )
00562         {
00563             if( p_playlist )
00564             {
00565                 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
00566                                                        FIND_CHILD );
00567             }
00568             else
00569             {
00570                 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
00571                                                    FIND_ANYWHERE );
00572                 if( p_input )
00573                 {
00574                     p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
00575                                                            FIND_PARENT );
00576                 }
00577             }
00578             /* New input has been registered */
00579             if( p_input )
00580             {
00581                 if( !p_input->b_dead || !p_input->b_die )
00582                 {
00583                     msg_rc( STATUS_CHANGE "( New input: %s )", p_input->input.p_item->psz_uri );
00584                     msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
00585                 }
00586                 var_AddCallback( p_input, "state", StateChanged, p_intf );
00587                 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
00588                 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
00589                 var_AddCallback( p_input, "rate", RateChanged, p_intf );
00590                 var_AddCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
00591             }
00592         }
00593         else if( p_input->b_dead )
00594         {
00595             var_DelCallback( p_input, "state", StateChanged, p_intf );
00596             var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
00597             var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
00598             var_DelCallback( p_input, "rate", RateChanged, p_intf );
00599             var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
00600             vlc_object_release( p_input );
00601             p_input = NULL;
00602 
00603             if( p_playlist )
00604             {
00605                 vlc_mutex_lock( &p_playlist->object_lock );
00606                 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
00607                 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
00608                 vlc_mutex_unlock( &p_playlist->object_lock );
00609             }
00610         }
00611 
00612         if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
00613             (p_playlist != NULL) )
00614         {
00615             vlc_mutex_lock( &p_playlist->object_lock );
00616             if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
00617                 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
00618             {
00619                 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
00620                 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
00621             }
00622             else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
00623                 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
00624             {
00625                 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
00626                 msg_rc( STATUS_CHANGE "( play state: 1 )" );
00627             }
00628             else if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
00629                 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
00630             {
00631                 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
00632                 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
00633             }
00634             vlc_mutex_unlock( &p_playlist->object_lock );
00635         }
00636 
00637         if( p_input && b_showpos )
00638         {
00639             i_newpos = 100 * var_GetFloat( p_input, "position" );
00640             if( i_oldpos != i_newpos )
00641             {
00642                 i_oldpos = i_newpos;
00643                 msg_rc( "pos: %d%%", i_newpos );
00644             }
00645         }
00646 
00647         /* Is there something to do? */
00648         if( !b_complete ) continue;
00649 
00650 
00651         /* Skip heading spaces */
00652         psz_cmd = p_buffer;
00653         while( *psz_cmd == ' ' )
00654         {
00655             psz_cmd++;
00656         }
00657 
00658         /* Split psz_cmd at the first space and make sure that
00659          * psz_arg is valid */
00660         psz_arg = strchr( psz_cmd, ' ' );
00661         if( psz_arg )
00662         {
00663             *psz_arg++ = 0;
00664             while( *psz_arg == ' ' )
00665             {
00666                 psz_arg++;
00667             }
00668         }
00669         else
00670         {
00671             psz_arg = "";
00672         }
00673 
00674         /* If the user typed a registered local command, try it */
00675         if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
00676         {
00677             vlc_value_t val;
00678             int i_ret;
00679 
00680             val.psz_string = psz_arg;
00681             i_ret = var_Set( p_intf, psz_cmd, val );
00682             msg_rc( "%s: returned %i (%s)",
00683                     psz_cmd, i_ret, vlc_error( i_ret ) );
00684         }
00685         /* Or maybe it's a global command */
00686         else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
00687         {
00688             vlc_value_t val;
00689             int i_ret;
00690 
00691             val.psz_string = psz_arg;
00692             /* FIXME: it's a global command, but we should pass the
00693              * local object as an argument, not p_intf->p_libvlc. */
00694             i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
00695             if( i_ret != 0 )
00696             {
00697                 msg_rc( "%s: returned %i (%s)",
00698                          psz_cmd, i_ret, vlc_error( i_ret ) );
00699             }
00700         }
00701         else if( !strcmp( psz_cmd, "logout" ) )
00702         {
00703             /* Close connection */
00704             if( p_intf->p_sys->i_socket != -1 )
00705             {
00706                 net_Close( p_intf->p_sys->i_socket );
00707             }
00708             p_intf->p_sys->i_socket = -1;
00709         }
00710         else if( !strcmp( psz_cmd, "info" ) )
00711         {
00712             if( p_input )
00713             {
00714                 int i, j;
00715                 vlc_mutex_lock( &p_input->input.p_item->lock );
00716                 for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
00717                 {
00718                     info_category_t *p_category =
00719                         p_input->input.p_item->pp_categories[i];
00720 
00721                     msg_rc( "+----[ %s ]", p_category->psz_name );
00722                     msg_rc( "| " );
00723                     for ( j = 0; j < p_category->i_infos; j++ )
00724                     {
00725                         info_t *p_info = p_category->pp_infos[j];
00726                         msg_rc( "| %s: %s", p_info->psz_name,
00727                                 p_info->psz_value );
00728                     }
00729                     msg_rc( "| " );
00730                 }
00731                 msg_rc( "+----[ end of stream info ]" );
00732                 vlc_mutex_unlock( &p_input->input.p_item->lock );
00733             }
00734             else
00735             {
00736                 msg_rc( "no input" );
00737             }
00738         }
00739         else if( !strcmp( psz_cmd, "is_playing" ) )
00740         {
00741             if( ! p_input )
00742             {
00743                 msg_rc( "0" );
00744             }
00745             else
00746             {
00747                 msg_rc( "1" );
00748             }
00749         }
00750         else if( !strcmp( psz_cmd, "get_time" ) )
00751         {
00752             if( ! p_input )
00753             {
00754                 msg_rc("0");
00755             }
00756             else
00757             {
00758                 vlc_value_t time;
00759                 var_Get( p_input, "time", &time );
00760                 msg_rc( "%i", time.i_time / 1000000);
00761             }
00762         }
00763         else if( !strcmp( psz_cmd, "get_length" ) )
00764         {
00765             if( ! p_input )
00766             {
00767                 msg_rc("0");
00768             }
00769             else
00770             {
00771                 vlc_value_t time;
00772                 var_Get( p_input, "length", &time );
00773                 msg_rc( "%i", time.i_time / 1000000);
00774             }
00775         }
00776         else if( !strcmp( psz_cmd, "get_title" ) )
00777         {
00778             if( ! p_input )
00779             {
00780                 msg_rc("");
00781             }
00782             else
00783             {
00784                 msg_rc( "%s", p_input->input.p_item->psz_name );
00785             }
00786         }
00787         else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
00788                  || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
00789         {
00790             if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
00791                  b_longhelp = VLC_TRUE;
00792             else b_longhelp = VLC_FALSE;
00793 
00794             Help( p_intf, b_longhelp );
00795         }
00796         else switch( psz_cmd[0] )
00797         {
00798         case 'f':
00799         case 'F':
00800             if( p_input )
00801             {
00802                 vout_thread_t *p_vout;
00803                 p_vout = vlc_object_find( p_input,
00804                                           VLC_OBJECT_VOUT, FIND_CHILD );
00805 
00806                 if( p_vout )
00807                 {
00808                     vlc_value_t val;
00809                     vlc_bool_t b_update = VLC_FALSE;
00810                     var_Get( p_vout, "fullscreen", &val );
00811                     val.b_bool = !val.b_bool;
00812                     if( !strncmp(psz_arg, "on", 2) && (val.b_bool == VLC_TRUE) )
00813                     {
00814                         b_update = VLC_TRUE;
00815                         val.b_bool = VLC_TRUE;
00816                     }
00817                     else if( !strncmp(psz_arg, "off", 3)  && (val.b_bool == VLC_FALSE) )
00818                     {
00819                         b_update = VLC_TRUE;
00820                         val.b_bool = VLC_FALSE;
00821                     }
00822                     else if( strncmp(psz_arg, "off", 3) && strncmp(psz_arg, "on", 2) )
00823                         b_update = VLC_TRUE;
00824                     if( b_update ) var_Set( p_vout, "fullscreen", val );
00825                     vlc_object_release( p_vout );
00826                 }
00827             }
00828             break;
00829 
00830         case 's':
00831         case 'S':
00832             ;
00833             break;
00834 
00835         case '\0':
00836             /* Ignore empty lines */
00837             break;
00838 
00839         default:
00840             msg_rc(_("unknown command `%s', type `help' for help"), psz_cmd);
00841             break;
00842         }
00843 
00844         /* Command processed */
00845         i_size = 0; p_buffer[0] = 0;
00846     }
00847 
00848     msg_rc( STATUS_CHANGE "( stop state: 0 )" );
00849     msg_rc( STATUS_CHANGE "( quit )" );
00850 
00851     if( p_input )
00852     {
00853         var_DelCallback( p_input, "state", StateChanged, p_intf );
00854         var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
00855         var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
00856         var_DelCallback( p_input, "rate", RateChanged, p_intf );
00857         var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
00858         vlc_object_release( p_input );
00859         p_input = NULL;
00860     }
00861 
00862     if( p_playlist )
00863     {
00864         vlc_object_release( p_playlist );
00865         p_playlist = NULL;
00866     }
00867 
00868     var_DelCallback( p_intf->p_vlc, "volume-change", VolumeChanged, p_intf );
00869 }
00870 
00871 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
00872 {
00873     msg_rc(_("+----[ Remote control commands ]"));
00874     msg_rc(  "| ");
00875     msg_rc(_("| add XYZ  . . . . . . . . . . add XYZ to playlist"));
00876     msg_rc(_("| playlist . . .  show items currently in playlist"));
00877     msg_rc(_("| play . . . . . . . . . . . . . . . . play stream"));
00878     msg_rc(_("| stop . . . . . . . . . . . . . . . . stop stream"));
00879     msg_rc(_("| next . . . . . . . . . . . .  next playlist item"));
00880     msg_rc(_("| prev . . . . . . . . . .  previous playlist item"));
00881     msg_rc(_("| goto . . . . . . . . . . . .  goto item at index"));
00882     msg_rc(_("| clear . . . . . . . . . . .   clear the playlist"));
00883     msg_rc(_("| status . . . . . . . . . current playlist status"));
00884     msg_rc(_("| title [X]  . . . . set/get title in current item"));
00885     msg_rc(_("| title_n  . . . . . .  next title in current item"));
00886     msg_rc(_("| title_p  . . . .  previous title in current item"));
00887     msg_rc(_("| chapter [X]  . . set/get chapter in current item"));
00888     msg_rc(_("| chapter_n  . . . .  next chapter in current item"));
00889     msg_rc(_("| chapter_p  . .  previous chapter in current item"));
00890     msg_rc(  "| ");
00891     msg_rc(_("| seek X . seek in seconds, for instance `seek 12'"));
00892     msg_rc(_("| pause  . . . . . . . . . . . . . .  toggle pause"));
00893     msg_rc(_("| fastforward  . . . . . .  .  set to maximum rate"));
00894     msg_rc(_("| rewind  . . . . . . . . . .  set to minimum rate"));
00895     msg_rc(_("| faster . . . . . . . .  faster playing of stream"));
00896     msg_rc(_("| slower . . . . . . . .  slower playing of stream"));
00897     msg_rc(_("| normal . . . . . . . .  normal playing of stream"));
00898     msg_rc(_("| f [on|off] . . . . . . . . . . toggle fullscreen"));
00899     msg_rc(_("| info . . .  information about the current stream"));
00900     msg_rc(  "| ");
00901     msg_rc(_("| volume [X] . . . . . . . .  set/get audio volume"));
00902     msg_rc(_("| volup [X]  . . . . .  raise audio volume X steps"));
00903     msg_rc(_("| voldown [X]  . . . .  lower audio volume X steps"));
00904     msg_rc(_("| adev [X] . . . . . . . . .  set/get audio device"));
00905     msg_rc(_("| achan [X]. . . . . . . .  set/get audio channels"));
00906     msg_rc(_("| menu [on|off|up|down|left|right|select] use menu"));
00907     msg_rc(  "| ");
00908 
00909     if (b_longhelp)
00910     {
00911         msg_rc(_("| marq-marquee STRING  . . overlay STRING in video"));
00912         msg_rc(_("| marq-x X . . . . . . . . . . . .offset from left"));
00913         msg_rc(_("| marq-y Y . . . . . . . . . . . . offset from top"));
00914         msg_rc(_("| marq-position #. . .  .relative position control"));
00915         msg_rc(_("| marq-color # . . . . . . . . . . font color, RGB"));
00916         msg_rc(_("| marq-opacity # . . . . . . . . . . . . . opacity"));
00917         msg_rc(_("| marq-timeout T. . . . . . . . . . timeout, in ms"));
00918         msg_rc(_("| marq-size # . . . . . . . . font size, in pixels"));
00919         msg_rc(  "| ");
00920         msg_rc(_("| time-format STRING . . . overlay STRING in video"));
00921         msg_rc(_("| time-x X . . . . . . . . . . . .offset from left"));
00922         msg_rc(_("| time-y Y . . . . . . . . . . . . offset from top"));
00923         msg_rc(_("| time-position #. . . . . . . . relative position"));
00924         msg_rc(_("| time-color # . . . . . . . . . . font color, RGB"));
00925         msg_rc(_("| time-opacity # . . . . . . . . . . . . . opacity"));
00926         msg_rc(_("| time-size # . . . . . . . . font size, in pixels"));
00927         msg_rc(  "| ");
00928         msg_rc(_("| logo-file STRING . . . the overlay file path/name"));
00929         msg_rc(_("| logo-x X . . . . . . . . . . . .offset from left"));
00930         msg_rc(_("| logo-y Y . . . . . . . . . . . . offset from top"));
00931         msg_rc(_("| logo-position #. . . . . . . . relative position"));
00932         msg_rc(_("| logo-transparency #. . . . . . . . .transparency"));
00933         msg_rc(  "| ");
00934         msg_rc(_("| mosaic-alpha # . . . . . . . . . . . . . . alpha"));
00935         msg_rc(_("| mosaic-height #. . . . . . . . . . . . . .height"));
00936         msg_rc(_("| mosaic-width # . . . . . . . . . . . . . . width"));
00937         msg_rc(_("| mosaic-xoffset # . . . .top left corner position"));
00938         msg_rc(_("| mosaic-yoffset # . . . .top left corner position"));
00939         msg_rc(_("| mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
00940         msg_rc(_("| mosaic-vborder # . . . . . . . . vertical border"));
00941         msg_rc(_("| mosaic-hborder # . . . . . . . horizontal border"));
00942         msg_rc(_("| mosaic-position {0=auto,1=fixed} . . . .position"));
00943         msg_rc(_("| mosaic-rows #. . . . . . . . . . .number of rows"));
00944         msg_rc(_("| mosaic-cols #. . . . . . . . . . .number of cols"));
00945         msg_rc(_("| mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
00946         msg_rc(  "| ");
00947     }
00948     msg_rc(_("| help . . . . . . . . . . . . . this help message"));
00949     msg_rc(_("| longhelp . . . . . . . . . a longer help message"));
00950     msg_rc(_("| logout . . . . .  exit (if in socket connection)"));
00951     msg_rc(_("| quit . . . . . . . . . . . . . . . . .  quit vlc"));
00952     msg_rc(  "| ");
00953     msg_rc(_("+----[ end of help ]"));
00954 }
00955 
00956 /********************************************************************
00957  * Status callback routines
00958  ********************************************************************/
00959 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
00960     vlc_value_t oldval, vlc_value_t newval, void *p_data )
00961 {
00962     intf_thread_t *p_intf = (intf_thread_t*)p_data;
00963     input_thread_t *p_input = NULL;
00964 
00965     vlc_mutex_lock( &p_intf->p_sys->status_lock );
00966     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
00967     if( p_input )
00968     {
00969         msg_rc( STATUS_CHANGE "( time-offset: %d )", var_GetInteger( p_input, "time-offset" ) );
00970         vlc_object_release( p_input );
00971     }
00972     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
00973     return VLC_SUCCESS;
00974 }
00975 
00976 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
00977     vlc_value_t oldval, vlc_value_t newval, void *p_data )
00978 {
00979     intf_thread_t *p_intf = (intf_thread_t*)p_data;
00980 
00981     vlc_mutex_lock( &p_intf->p_sys->status_lock );
00982     msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_this, "volume") );
00983     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
00984     return VLC_SUCCESS;
00985 }
00986 
00987 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
00988     vlc_value_t oldval, vlc_value_t newval, void *p_data )
00989 {
00990     intf_thread_t *p_intf = (intf_thread_t*)p_data;
00991     playlist_t    *p_playlist = NULL;
00992     input_thread_t *p_input = NULL;
00993 
00994     vlc_mutex_lock( &p_intf->p_sys->status_lock );
00995     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
00996     if( p_input )
00997     {
00998         p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
00999         if( p_playlist )
01000         {
01001             char cmd[5] = "";
01002             switch( p_playlist->status.i_status )
01003             {
01004             case PLAYLIST_STOPPED:
01005                 strncpy( &cmd[0], "stop", 4);
01006                 cmd[4] = '\0';
01007                 break;
01008             case PLAYLIST_RUNNING:
01009                 strncpy( &cmd[0], "play", 4);
01010                 cmd[4] = '\0';
01011                 break;
01012             case PLAYLIST_PAUSED:
01013                 strncpy( &cmd[0], "pause", 5);
01014                 cmd[5] = '\0';
01015                 break;
01016             } /* var_GetInteger( p_input, "state" )  */
01017             msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
01018             vlc_object_release( p_playlist );
01019         }
01020         vlc_object_release( p_input );
01021     }
01022     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
01023     return VLC_SUCCESS;
01024 }
01025 
01026 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
01027     vlc_value_t oldval, vlc_value_t newval, void *p_data )
01028 {
01029     intf_thread_t *p_intf = (intf_thread_t*)p_data;
01030     input_thread_t *p_input = NULL;
01031 
01032     vlc_mutex_lock( &p_intf->p_sys->status_lock );
01033     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
01034     if( p_input )
01035     {
01036         msg_rc( STATUS_CHANGE "( new rate: %d )", var_GetInteger( p_input, "rate" ) );
01037         vlc_object_release( p_input );
01038     }
01039     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
01040     return VLC_SUCCESS;
01041 }
01042 
01043 /********************************************************************
01044  * Command routines
01045  ********************************************************************/
01046 static int Input( vlc_object_t *p_this, char const *psz_cmd,
01047                   vlc_value_t oldval, vlc_value_t newval, void *p_data )
01048 {
01049     intf_thread_t *p_intf = (intf_thread_t*)p_this;
01050     input_thread_t *p_input;
01051     vlc_value_t     val;
01052 
01053     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
01054     if( !p_input ) return VLC_ENOOBJ;
01055 
01056     var_Get( p_input, "state", &val );
01057     if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
01058         ( strcmp( psz_cmd, "pause" ) != 0 ) )
01059     {
01060         msg_rc( _("press menu select or pause to continue") );
01061         vlc_object_release( p_input );
01062         return VLC_EGENERIC;
01063     }
01064 
01065     /* Parse commands that only require an input */
01066     if( !strcmp( psz_cmd, "pause" ) )
01067     {
01068         val.i_int = config_GetInt( p_intf, "key-play-pause" );
01069         var_Set( p_intf->p_vlc, "key-pressed", val );
01070         vlc_object_release( p_input );
01071         return VLC_SUCCESS;
01072     }
01073     else if( !strcmp( psz_cmd, "seek" ) )
01074     {
01075         if( strlen( newval.psz_string ) > 0 &&
01076             newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
01077         {
01078             val.f_float = (float)atoi( newval.psz_string ) / 100.0;
01079             var_Set( p_input, "position", val );
01080         }
01081         else
01082         {
01083             val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
01084             var_Set( p_input, "time", val );
01085         }
01086         vlc_object_release( p_input );
01087         return VLC_SUCCESS;
01088     }
01089     else if ( !strcmp( psz_cmd, "fastforward" ) )
01090     {
01091         val.i_int = config_GetInt( p_intf, "key-jump+3sec" );
01092         var_Set( p_intf->p_vlc, "key-pressed", val );
01093         vlc_object_release( p_input );
01094         return VLC_SUCCESS;
01095     }
01096     else if ( !strcmp( psz_cmd, "rewind" ) )
01097     {
01098         val.i_int = config_GetInt( p_intf, "key-jump-3sec" );
01099         var_Set( p_intf->p_vlc, "key-pressed", val );
01100         vlc_object_release( p_input );
01101         return VLC_SUCCESS;
01102     }
01103     else if ( !strcmp( psz_cmd, "faster" ) )
01104     {
01105         val.b_bool = VLC_TRUE;
01106         var_Set( p_input, "rate-faster", val );
01107         vlc_object_release( p_input );
01108         return VLC_SUCCESS;
01109     }
01110     else if ( !strcmp( psz_cmd, "slower" ) )
01111     {
01112         val.b_bool = VLC_TRUE;
01113         var_Set( p_input, "rate-slower", val );
01114         vlc_object_release( p_input );
01115         return VLC_SUCCESS;
01116     }
01117     else if ( !strcmp( psz_cmd, "normal" ) )
01118     {
01119         val.i_int = INPUT_RATE_DEFAULT;
01120         var_Set( p_input, "rate", val );
01121         vlc_object_release( p_input );
01122         return VLC_SUCCESS;
01123     }
01124     else if( !strcmp( psz_cmd, "chapter" ) ||
01125              !strcmp( psz_cmd, "chapter_n" ) ||
01126              !strcmp( psz_cmd, "chapter_p" ) )
01127     {
01128         if( !strcmp( psz_cmd, "chapter" ) )
01129         {
01130             if ( *newval.psz_string )
01131             {
01132                 /* Set. */
01133                 val.i_int = atoi( newval.psz_string );
01134                 var_Set( p_input, "chapter", val );
01135             }
01136             else
01137             {
01138                 vlc_value_t val_list;
01139 
01140                 /* Get. */
01141                 var_Get( p_input, "chapter", &val );
01142                 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
01143                             &val_list, NULL );
01144                 msg_rc( "Currently playing chapter %d/%d",
01145                         val.i_int, val_list.p_list->i_count );
01146                 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
01147                             &val_list, NULL );
01148             }
01149         }
01150         else if( !strcmp( psz_cmd, "chapter_n" ) )
01151         {
01152             val.b_bool = VLC_TRUE;
01153             var_Set( p_input, "next-chapter", val );
01154         }
01155         else if( !strcmp( psz_cmd, "chapter_p" ) )
01156         {
01157             val.b_bool = VLC_TRUE;
01158             var_Set( p_input, "prev-chapter", val );
01159         }
01160         vlc_object_release( p_input );
01161         return VLC_SUCCESS;
01162     }
01163     else if( !strcmp( psz_cmd, "title" ) ||
01164              !strcmp( psz_cmd, "title_n" ) ||
01165              !strcmp( psz_cmd, "title_p" ) )
01166     {
01167         if( !strcmp( psz_cmd, "title" ) )
01168         {
01169             if ( *newval.psz_string )
01170             {
01171                 /* Set. */
01172                 val.i_int = atoi( newval.psz_string );
01173                 var_Set( p_input, "title", val );
01174             }
01175             else
01176             {
01177                 vlc_value_t val_list;
01178 
01179                 /* Get. */
01180                 var_Get( p_input, "title", &val );
01181                 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
01182                             &val_list, NULL );
01183                 msg_rc( "Currently playing title %d/%d",
01184                         val.i_int, val_list.p_list->i_count );
01185                 var_Change( p_this, "title", VLC_VAR_FREELIST,
01186                             &val_list, NULL );
01187             }
01188         }
01189         else if( !strcmp( psz_cmd, "title_n" ) )
01190         {
01191             val.b_bool = VLC_TRUE;
01192             var_Set( p_input, "next-title", val );
01193         }
01194         else if( !strcmp( psz_cmd, "title_p" ) )
01195         {
01196             val.b_bool = VLC_TRUE;
01197             var_Set( p_input, "prev-title", val );
01198         }
01199 
01200         vlc_object_release( p_input );
01201         return VLC_SUCCESS;
01202     }
01203 
01204     /* Never reached. */
01205     vlc_object_release( p_input );
01206     return VLC_EGENERIC;
01207 }
01208 
01209 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
01210                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
01211 {
01212     vlc_value_t val;
01213     intf_thread_t *p_intf = (intf_thread_t*)p_this;
01214     playlist_t *p_playlist;
01215 
01216     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
01217                                            FIND_ANYWHERE );
01218     if( !p_playlist )
01219     {
01220         return VLC_ENOOBJ;
01221     }
01222 
01223     if( p_playlist->p_input )
01224     {
01225         vlc_value_t val;
01226         var_Get( p_playlist->p_input, "state", &val );
01227         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )        {
01228             msg_rc( _("press menu select or pause to continue") );
01229             vlc_object_release( p_playlist );
01230             return VLC_EGENERIC;
01231         }
01232     }
01233 
01234     /* Parse commands that require a playlist */
01235     if( !strcmp( psz_cmd, "prev" ) )
01236     {
01237         playlist_Prev( p_playlist );
01238     }
01239     else if( !strcmp( psz_cmd, "next" ) )
01240     {
01241         playlist_Next( p_playlist );
01242     }
01243     else if( !strcmp( psz_cmd, "play" ) )
01244     {
01245         if( p_playlist->p_input )
01246         {
01247             vlc_value_t val;
01248  
01249             var_Get( p_playlist->p_input, "rate", &val );
01250             if( val.i_int != INPUT_RATE_DEFAULT )
01251             {
01252                 val.i_int = INPUT_RATE_DEFAULT;
01253                 var_Set( p_playlist->p_input, "rate", val );
01254             }
01255             else
01256             {
01257                 playlist_Play( p_playlist );
01258             }
01259         }
01260     }
01261     else if (!strcmp( psz_cmd, "goto" ) )
01262     {
01263         if( strlen( newval.psz_string ) > 0) 
01264         {
01265             val.i_int = atoi( newval.psz_string );
01266             playlist_Goto( p_playlist, val.i_int); 
01267         }
01268     }
01269     else if( !strcmp( psz_cmd, "stop" ) )
01270     {
01271         playlist_Stop( p_playlist );
01272     }
01273     else if( !strcmp( psz_cmd, "clear" ) )
01274     {
01275         playlist_Stop( p_playlist );
01276         vlc_mutex_lock( &p_playlist->object_lock );
01277         playlist_Clear( p_playlist );
01278         vlc_mutex_unlock( &p_playlist->object_lock );
01279     }
01280     else if( !strcmp( psz_cmd, "add" ) &&
01281              newval.psz_string && *newval.psz_string )
01282     {
01283         playlist_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
01284 
01285         if( p_item )
01286         {
01287             msg_rc( "trying to add %s to playlist", newval.psz_string );
01288             playlist_AddItem( p_playlist, p_item,
01289                               PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
01290         }
01291     }
01292     else if( !strcmp( psz_cmd, "playlist" ) )
01293     {
01294         int i;
01295 
01296         for ( i = 0; i < p_playlist->i_size; i++ )
01297         {
01298             msg_rc( "|%s%s   %s|%s|", i == p_playlist->i_index ? "*" : " ",
01299                     p_playlist->pp_items[i]->input.psz_name,
01300                     p_playlist->pp_items[i]->input.psz_uri,
01301                     p_playlist->pp_items[i]->i_parents > 0 ?
01302                     p_playlist->pp_items[i]->pp_parents[0]->p_parent->input.psz_name : "" );
01303         }
01304         if ( i == 0 )
01305         {
01306             msg_rc( "| no entries" );
01307         }
01308     }
01309     else if( !strcmp( psz_cmd, "status" ) )
01310     {
01311         if( p_playlist->p_input )
01312         {
01313             /* Replay the current state of the system. */
01314             msg_rc( STATUS_CHANGE "( New input: %s )", p_playlist->p_input->input.p_item->psz_uri );
01315             msg_rc( STATUS_CHANGE "( audio volume: %d )", config_GetInt( p_intf, "volume" ));
01316 
01317             vlc_mutex_lock( &p_playlist->object_lock );
01318             switch( p_playlist->status.i_status )
01319             {
01320                 case PLAYLIST_STOPPED:
01321                     msg_rc( STATUS_CHANGE "( stop state: 0 )" );
01322                     break;
01323                 case PLAYLIST_RUNNING:
01324                     msg_rc( STATUS_CHANGE "( play state: 1 )" );
01325                     break;
01326                 case PLAYLIST_PAUSED:
01327                     msg_rc( STATUS_CHANGE "( pause state: 2 )" );
01328                     break;
01329                 default:
01330                     msg_rc( STATUS_CHANGE "( state unknown )" );
01331                     break;
01332             }
01333             vlc_mutex_unlock( &p_playlist->object_lock );
01334         }
01335     }
01336 
01337     /*
01338      * sanity check
01339      */
01340     else
01341     {
01342         msg_rc( "unknown command!" );
01343     }
01344 
01345     vlc_object_release( p_playlist );
01346     return VLC_SUCCESS;
01347 }
01348 
01349 static int Other( vlc_object_t *p_this, char const *psz_cmd,
01350                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
01351 {
01352     intf_thread_t *p_intf = (intf_thread_t*)p_this;
01353     vlc_object_t  *p_playlist;
01354     vlc_value_t    val;
01355     vlc_object_t  *p_input;
01356 
01357     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
01358     if( !p_playlist )
01359     {
01360         return VLC_ENOOBJ;
01361     }
01362 
01363     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
01364     if( !p_input )
01365     {
01366         vlc_object_release( p_playlist );
01367         return VLC_ENOOBJ;
01368     }
01369 
01370     if( p_input )
01371     {
01372         var_Get( p_input, "state", &val );
01373         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
01374         {
01375             msg_rc( _("press pause to continue") );
01376             vlc_object_release( p_playlist );
01377             vlc_object_release( p_input );
01378             return VLC_EGENERIC;
01379         }
01380     }
01381 
01382     /* Parse miscellaneous commands */
01383     if( !strcmp( psz_cmd, "marq-marquee" ) )
01384     {
01385         if( strlen( newval.psz_string ) > 0 )
01386         {
01387             val.psz_string = newval.psz_string;
01388             var_Set( p_input->p_libvlc, "marq-marquee", val );
01389         }
01390         else 
01391         {
01392                 val.psz_string = "";
01393                 var_Set( p_input->p_libvlc, "marq-marquee", val);
01394         }
01395     }
01396     else if( !strcmp( psz_cmd, "marq-x" ) )
01397     {
01398         if( strlen( newval.psz_string ) > 0) 
01399         {
01400             val.i_int = atoi( newval.psz_string );
01401             var_Set( p_input->p_libvlc, "marq-x", val );
01402         }
01403     }
01404     else if( !strcmp( psz_cmd, "marq-y" ) )
01405     {
01406         if( strlen( newval.psz_string ) > 0) 
01407         {
01408             val.i_int = atoi( newval.psz_string );
01409             var_Set( p_input->p_libvlc, "marq-y", val );
01410         }
01411     }
01412     else if( !strcmp( psz_cmd, "marq-position" ) )
01413     {
01414         if( strlen( newval.psz_string ) > 0) 
01415         {
01416             val.i_int = atoi( newval.psz_string );
01417             var_Set( p_input->p_libvlc, "marq-position", val );
01418         }
01419     }
01420     else if( !strcmp( psz_cmd, "marq-color" ) )
01421     {
01422         if( strlen( newval.psz_string ) > 0) 
01423         {
01424             val.i_int = strtol( newval.psz_string, NULL, 0 );
01425             var_Set( p_input->p_libvlc, "marq-color", val );
01426         }
01427     }
01428     else if( !strcmp( psz_cmd, "marq-opacity" ) )
01429     {
01430         if( strlen( newval.psz_string ) > 0) 
01431         {
01432             val.i_int = strtol( newval.psz_string, NULL, 0 );
01433             var_Set( p_input->p_libvlc, "marq-opacity", val );
01434         }
01435     }
01436     else if( !strcmp( psz_cmd, "marq-size" ) )
01437     {
01438         if( strlen( newval.psz_string ) > 0) 
01439         {
01440             val.i_int = atoi( newval.psz_string );
01441             var_Set( p_input->p_libvlc, "marq-size", val );
01442         }
01443     }
01444     else if( !strcmp( psz_cmd, "marq-timeout" ) )
01445     {
01446         if( strlen( newval.psz_string ) > 0) 
01447         {
01448             val.i_int = atoi( newval.psz_string );
01449             var_Set( p_input, "marq-timeout", val );
01450         }
01451     }
01452     else if( !strcmp( psz_cmd, "mosaic-alpha" ) )
01453     {
01454         if( strlen( newval.psz_string ) > 0)
01455         {
01456             val.i_int = atoi( newval.psz_string );
01457             var_Set( p_input->p_libvlc, "mosaic-alpha", val );
01458         }
01459     }
01460     else if( !strcmp( psz_cmd, "mosaic-height" ) )
01461     {
01462         if( strlen( newval.psz_string ) > 0)
01463         {
01464             val.i_int = atoi( newval.psz_string );
01465             var_Set( p_input->p_libvlc, "mosaic-height", val );
01466         }
01467     }
01468     else if( !strcmp( psz_cmd, "mosaic-width" ) )
01469     {
01470         if( strlen( newval.psz_string ) > 0)
01471         {
01472             val.i_int = atoi( newval.psz_string );
01473             var_Set( p_input->p_libvlc, "mosaic-width", val );
01474         }
01475     }
01476     else if( !strcmp( psz_cmd, "mosaic-xoffset" ) )
01477     {
01478         if( strlen( newval.psz_string ) > 0)
01479         {
01480             val.i_int = atoi( newval.psz_string );
01481             var_Set( p_input->p_libvlc, "mosaic-xoffset", val );
01482         }
01483     }
01484     else if( !strcmp( psz_cmd, "mosaic-yoffset" ) )
01485     {
01486         if( strlen( newval.psz_string ) > 0)
01487         {
01488             val.i_int = atoi( newval.psz_string );
01489             var_Set( p_input->p_libvlc, "mosaic-yoffset", val );
01490         }
01491     }
01492     else if( !strcmp( psz_cmd, "mosaic-align" ) )
01493     {
01494         if( strlen( newval.psz_string ) > 0 )
01495         {
01496             val.i_int = atoi( newval.psz_string );
01497             var_Set( p_input->p_libvlc, "mosaic-align", val );
01498         }
01499     }
01500     else if( !strcmp( psz_cmd, "mosaic-vborder" ) )
01501     {
01502         if( strlen( newval.psz_string ) > 0)
01503         {
01504             val.i_int = atoi( newval.psz_string );
01505             var_Set( p_input->p_libvlc, "mosaic-vborder", val );
01506         }
01507     }
01508     else if( !strcmp( psz_cmd, "mosaic-hborder" ) )
01509     {
01510         if( strlen( newval.psz_string ) > 0)
01511         {
01512             val.i_int = atoi( newval.psz_string );
01513             var_Set( p_input->p_libvlc, "mosaic-hborder", val );
01514         }
01515     }
01516     else if( !strcmp( psz_cmd, "mosaic-position" ) )
01517     {
01518         if( strlen( newval.psz_string ) > 0)
01519         {
01520             val.i_int = atoi( newval.psz_string );
01521             var_Set( p_input->p_libvlc, "mosaic-position", val );
01522         }
01523     }
01524     else if( !strcmp( psz_cmd, "mosaic-rows" ) )
01525     {
01526         if( strlen( newval.psz_string ) > 0)
01527         {
01528             val.i_int = atoi( newval.psz_string );
01529             var_Set( p_input->p_libvlc, "mosaic-rows", val );
01530         }
01531     }
01532     else if( !strcmp( psz_cmd, "mosaic-cols" ) )
01533     {
01534         if( strlen( newval.psz_string ) > 0)
01535         {
01536             val.i_int = atoi( newval.psz_string );
01537             var_Set( p_input->p_libvlc, "mosaic-cols", val );
01538         }
01539     }
01540     else if( !strcmp( psz_cmd, "mosaic-keep-aspect-ratio" ) )
01541     {
01542         if( strlen( newval.psz_string ) > 0)
01543         {
01544             val.i_int = atoi( newval.psz_string );
01545             var_Set( p_input->p_libvlc, "mosaic-keep-aspect-ratio", val );
01546         }
01547     }
01548     else if( !strcmp( psz_cmd, "time-format" ) )
01549     {
01550         if( strlen( newval.psz_string ) > 0 )
01551         {
01552             val.psz_string = newval.psz_string;
01553             var_Set( p_input->p_libvlc, "time-format", val );
01554         }
01555         else 
01556         {
01557             val.psz_string = "";
01558             var_Set( p_input->p_libvlc, "time-format", val);
01559         }
01560     }
01561     else if( !strcmp( psz_cmd, "time-x" ) )
01562     {
01563         if( strlen( newval.psz_string ) > 0) 
01564         {
01565             val.i_int = atoi( newval.psz_string );
01566             var_Set( p_input->p_libvlc, "time-x", val );
01567         }
01568     }
01569     else if( !strcmp( psz_cmd, "time-y" ) )
01570     {
01571         if( strlen( newval.psz_string ) > 0) 
01572         {
01573             val.i_int = atoi( newval.psz_string );
01574             var_Set( p_input->p_libvlc, "time-y", val );
01575         }
01576     }
01577     else if( !strcmp( psz_cmd, "time-position" ) )
01578     {
01579         if( strlen( newval.psz_string ) > 0) 
01580         {
01581             val.i_int = atoi( newval.psz_string );
01582             var_Set( p_input->p_libvlc, "time-position", val );
01583         }
01584     }
01585     else if( !strcmp( psz_cmd, "time-color" ) )
01586     {
01587         if( strlen( newval.psz_string ) > 0) 
01588         {
01589             val.i_int = strtol( newval.psz_string, NULL, 0 );
01590             var_Set( p_input->p_libvlc, "time-color", val );
01591         }
01592     }
01593     else if( !strcmp( psz_cmd, "time-opacity" ) )
01594     {
01595         if( strlen( newval.psz_string ) > 0) 
01596         {
01597             val.i_int = strtol( newval.psz_string, NULL, 0 );
01598             var_Set( p_input->p_libvlc, "time-opacity", val );
01599         }
01600     }
01601     else if( !strcmp( psz_cmd, "time-size" ) )
01602     {
01603         if( strlen( newval.psz_string ) > 0) 
01604         {
01605             val.i_int = atoi( newval.psz_string );
01606             var_Set( p_input->p_libvlc, "time-size", val );
01607         }
01608     }
01609     else if( !strcmp( psz_cmd, "logo-file" ) )
01610     {
01611         if( strlen( newval.psz_string ) > 0 )
01612         {
01613             val.psz_string = newval.psz_string;
01614             var_Set( p_input->p_libvlc, "logo-file", val );
01615         }
01616     }
01617     else if( !strcmp( psz_cmd, "logo-x" ) )
01618     {
01619         if( strlen( newval.psz_string ) > 0) 
01620         {
01621             val.i_int = atoi( newval.psz_string );
01622             var_Set( p_input->p_libvlc, "logo-x", val );
01623         }
01624     }
01625     else if( !strcmp( psz_cmd, "logo-y" ) )
01626     {
01627         if( strlen( newval.psz_string ) > 0) 
01628         {
01629             val.i_int = atoi( newval.psz_string );
01630             var_Set( p_input->p_libvlc, "logo-y", val );
01631         }
01632     }
01633     else if( !strcmp( psz_cmd, "logo-position" ) )
01634     {
01635         if( strlen( newval.psz_string ) > 0) 
01636         {
01637             val.i_int = atoi( newval.psz_string );
01638             var_Set( p_input->p_libvlc, "logo-position", val );
01639         }
01640     }
01641     else if( !strcmp( psz_cmd, "logo-transparency" ) )
01642     {
01643         if( strlen( newval.psz_string ) > 0) 
01644         {
01645             val.i_int = strtol( newval.psz_string, NULL, 0 );
01646             var_Set( p_input->p_libvlc, "logo-transparency", val );
01647         }
01648     }
01649 
01650     /*
01651      * sanity check
01652      */
01653     else
01654     {
01655         msg_rc( "unknown command!" );
01656     }
01657 
01658     vlc_object_release( p_playlist );
01659     vlc_object_release( p_input );
01660     return VLC_SUCCESS;
01661 }
01662 
01663 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
01664                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
01665 {
01666     playlist_t *p_playlist;
01667 
01668     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
01669     if( p_playlist )
01670     {
01671         playlist_Stop( p_playlist );
01672         vlc_object_release( p_playlist );
01673     }    
01674     p_this->p_vlc->b_die = VLC_TRUE;
01675     return VLC_SUCCESS;
01676 }
01677 
01678 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
01679                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
01680 {
01681     intf_thread_t *p_newintf = NULL;
01682 
01683     p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
01684     if( p_newintf )
01685     {
01686         p_newintf->b_block = VLC_FALSE;
01687         if( intf_RunThread( p_newintf ) )
01688         {
01689             vlc_object_detach( p_newintf );
01690             intf_Destroy( p_newintf );
01691         }
01692     }
01693 
01694     return VLC_SUCCESS;
01695 }
01696 
01697 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
01698                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
01699 {
01700     intf_thread_t *p_intf = (intf_thread_t*)p_this;
01701     input_thread_t *p_input = NULL;
01702     int i_error = VLC_EGENERIC;
01703 
01704     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
01705     if( !p_input )
01706         return VLC_ENOOBJ;
01707 
01708     if( p_input )
01709     {
01710         vlc_value_t val;
01711 
01712         var_Get( p_input, "state", &val );
01713         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
01714         {
01715             msg_rc( _("press menu select or pause to continue") );
01716             vlc_object_release( p_input );
01717             return VLC_EGENERIC;
01718         }
01719         vlc_object_release( p_input );
01720     }
01721 
01722     if ( *newval.psz_string )
01723     {
01724         /* Set. */
01725         audio_volume_t i_volume = atoi( newval.psz_string );
01726         if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
01727         {
01728             msg_rc( "Volume must be in the range %d-%d", AOUT_VOLUME_MIN,
01729                     AOUT_VOLUME_MAX );
01730             i_error = VLC_EBADVAR;
01731         }
01732         else
01733         {
01734             if( i_volume == AOUT_VOLUME_MIN )
01735             {
01736                 vlc_value_t keyval;
01737 
01738                 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
01739                 var_Set( p_intf->p_vlc, "key-pressed", keyval );
01740             }
01741             i_error = aout_VolumeSet( p_this, i_volume );
01742             osd_Volume( p_this );
01743             msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
01744         }
01745     }
01746     else
01747     {
01748         /* Get. */
01749         audio_volume_t i_volume;
01750         if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
01751         {
01752             i_error = VLC_EGENERIC;
01753         }
01754         else
01755         {
01756             msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
01757             i_error = VLC_SUCCESS;
01758         }
01759     }
01760 
01761     return i_error;
01762 }
01763 
01764 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
01765                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
01766 {
01767     intf_thread_t *p_intf = (intf_thread_t*)p_this;
01768     audio_volume_t i_volume;
01769     input_thread_t *p_input = NULL;
01770     int i_nb_steps = atoi(newval.psz_string);
01771     int i_error = VLC_SUCCESS;
01772     int i_volume_step = 0;
01773 
01774     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
01775     if( !p_input )
01776         return VLC_ENOOBJ;
01777 
01778     if( p_input )
01779     {
01780         vlc_value_t val;
01781 
01782         var_Get( p_input, "state", &val );
01783         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
01784         {
01785             msg_rc( _("press menu select or pause to continue") );
01786             vlc_object_release( p_input );
01787             return VLC_EGENERIC;
01788         }
01789         vlc_object_release( p_input );
01790     }
01791 
01792     i_volume_step = config_GetInt( p_intf->p_vlc, "volume-step" );
01793     if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
01794     {
01795         i_nb_steps = 1;
01796     }
01797 
01798     if ( !strcmp(psz_cmd, "volup") )
01799     {
01800         if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
01801             i_error = VLC_EGENERIC;
01802     }
01803     else
01804     {
01805         if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
01806             i_error = VLC_EGENERIC;
01807     }
01808     osd_Volume( p_this );
01809 
01810     if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
01811     return i_error;
01812 }
01813 
01814 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
01815                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
01816 {
01817     intf_thread_t *p_intf = (intf_thread_t*)p_this;
01818     input_thread_t *p_input = NULL;
01819     aout_instance_t * p_aout;
01820     const char * psz_variable;
01821     vlc_value_t val_name;
01822     int i_error;
01823 
01824     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
01825     if( !p_input )
01826         return VLC_ENOOBJ;
01827 
01828     if( p_input )
01829     {
01830         vlc_value_t val;
01831 
01832         var_Get( p_input, "state", &val );
01833         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )        {
01834             msg_rc( _("press menu select or pause to continue") );
01835             vlc_object_release( p_input );
01836             return VLC_EGENERIC;
01837         }
01838         vlc_object_release( p_input );
01839     }
01840 
01841     p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
01842     if ( p_aout == NULL ) return VLC_ENOOBJ;
01843 
01844     if ( !strcmp( psz_cmd, "adev" ) )
01845     {
01846         psz_variable = "audio-device";
01847     }
01848     else
01849     {
01850         psz_variable = "audio-channels";
01851     }
01852 
01853     /* Get the descriptive name of the variable */
01854     var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
01855                  &val_name, NULL );
01856     if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
01857 
01858     if ( !*newval.psz_string )
01859     {
01860         /* Retrieve all registered ***. */
01861         vlc_value_t val, text;
01862         int i, i_value;
01863 
01864         if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
01865         {
01866             vlc_object_release( (vlc_object_t *)p_aout );
01867             return VLC_EGENERIC;
01868         }
01869         i_value = val.i_int;
01870 
01871         if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
01872                          VLC_VAR_GETLIST, &val, &text ) < 0 )
01873         {
01874             vlc_object_release( (vlc_object_t *)p_aout );
01875             return VLC_EGENERIC;
01876         }
01877 
01878         msg_rc( "+----[ %s ]", val_name.psz_string );
01879         for ( i = 0; i < val.p_list->i_count; i++ )
01880         {
01881             if ( i_value == val.p_list->p_values[i].i_int )
01882                 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
01883                         text.p_list->p_values[i].psz_string );
01884             else
01885                 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
01886                         text.p_list->p_values[i].psz_string );
01887         }
01888         var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
01889                     &val, &text );
01890         msg_rc( "+----[ end of %s ]", val_name.psz_string );
01891 
01892         if( val_name.psz_string ) free( val_name.psz_string );
01893         i_error = VLC_SUCCESS;
01894     }
01895     else
01896     {
01897         vlc_value_t val;
01898         val.i_int = atoi( newval.psz_string );
01899 
01900         i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
01901     }
01902     vlc_object_release( (vlc_object_t *)p_aout );
01903 
01904     return i_error;
01905 }
01906 
01907 /* OSD menu commands */
01908 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
01909     vlc_value_t oldval, vlc_value_t newval, void *p_data )
01910 {
01911     intf_thread_t *p_intf = (intf_thread_t*)p_this;
01912     playlist_t    *p_playlist = NULL;
01913     vlc_value_t val;
01914     int i_error = VLC_EGENERIC;
01915 
01916     if ( !*newval.psz_string )
01917     {
01918         msg_rc( _("please provide one of the following paramaters") );
01919         msg_rc( "[on|off|up|down|left|right|select]" );
01920         return i_error;
01921     }
01922 
01923     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
01924     if( !p_playlist )
01925         return VLC_ENOOBJ;
01926 
01927     if( p_playlist->p_input )
01928     {
01929         var_Get( p_playlist->p_input, "state", &val );
01930         if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
01931             ( strcmp( newval.psz_string, "select" ) != 0 ) )
01932         {
01933             msg_rc( _("press menu select or pause to continue") );
01934             vlc_object_release( p_playlist );
01935             return VLC_EGENERIC;
01936         }
01937     }
01938     vlc_object_release( p_playlist );
01939 
01940     val.psz_string = strdup( newval.psz_string );
01941     if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
01942         osd_MenuShow( p_this );
01943     else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
01944         osd_MenuHide( p_this );
01945     else if( !strcmp( val.psz_string, "up" ) )
01946         osd_MenuUp( p_this );
01947     else if( !strcmp( val.psz_string, "down" ) )
01948         osd_MenuDown( p_this );
01949     else if( !strcmp( val.psz_string, "left" ) )
01950         osd_MenuPrev( p_this );
01951     else if( !strcmp( val.psz_string, "right" ) )
01952         osd_MenuNext( p_this );
01953     else if( !strcmp( val.psz_string, "select" ) )
01954         osd_MenuActivate( p_this );
01955     else
01956     {
01957         msg_rc( _("please provide one of the following paramaters") );
01958         msg_rc( "[on|off|up|down|left|right|select]" );
01959         if( val.psz_string ) free( val.psz_string );
01960             return i_error;
01961     }
01962 
01963     i_error = VLC_SUCCESS;
01964     if( val.psz_string ) free( val.psz_string );
01965     return i_error;
01966 }
01967 
01968 #ifdef WIN32
01969 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
01970 {
01971     INPUT_RECORD input_record;
01972     DWORD i_dw;
01973 
01974     /* On Win32, select() only works on socket descriptors */
01975     while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
01976                                 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
01977     {
01978         while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
01979                ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
01980                                  1, &i_dw ) )
01981         {
01982             if( input_record.EventType != KEY_EVENT ||
01983                 !input_record.Event.KeyEvent.bKeyDown ||
01984                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
01985                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
01986                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
01987                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
01988             {
01989                 /* nothing interesting */
01990                 continue;
01991             }
01992 
01993             p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
01994 
01995             /* Echo out the command */
01996             putc( p_buffer[ *pi_size ], stdout );
01997 
01998             /* Handle special keys */
01999             if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
02000             {
02001                 putc( '\n', stdout );
02002                 break;
02003             }
02004             switch( p_buffer[ *pi_size ] )
02005             {
02006             case '\b':
02007                 if( *pi_size )
02008                 {
02009                     *pi_size -= 2;
02010                     putc( ' ', stdout );
02011                     putc( '\b', stdout );
02012                 }
02013                 break;
02014             case '\r':
02015                 (*pi_size) --;
02016                 break;
02017             }
02018 
02019             (*pi_size)++;
02020         }
02021 
02022         if( *pi_size == MAX_LINE_LENGTH ||
02023             p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
02024         {
02025             p_buffer[ *pi_size ] = 0;
02026             return VLC_TRUE;
02027         }
02028     }
02029 
02030     return VLC_FALSE;
02031 }
02032 #endif
02033 
02034 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
02035 {
02036     int i_read = 0;
02037 
02038 #ifdef WIN32
02039     if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
02040         return ReadWin32( p_intf, p_buffer, pi_size );
02041     else if( p_intf->p_sys->i_socket == -1 )
02042     {
02043         msleep( INTF_IDLE_SLEEP );
02044         return VLC_FALSE;
02045     }
02046 #endif
02047 
02048     while( !p_intf->b_die && *pi_size < MAX_LINE_LENGTH &&
02049            (i_read = net_ReadNonBlock( p_intf, p_intf->p_sys->i_socket == -1 ?
02050                        0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
02051                   (uint8_t *)p_buffer + *pi_size, 1, INTF_IDLE_SLEEP ) ) > 0 )
02052     {
02053         if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
02054             break;
02055 
02056         (*pi_size)++;
02057     }
02058 
02059     /* Connection closed */
02060     if( i_read == -1 )
02061     {
02062         p_intf->p_sys->i_socket = -1;
02063         p_buffer[ *pi_size ] = 0;
02064         return VLC_TRUE;
02065     }
02066 
02067     if( *pi_size == MAX_LINE_LENGTH ||
02068         p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
02069     {
02070         p_buffer[ *pi_size ] = 0;
02071         return VLC_TRUE;
02072     }
02073 
02074     return VLC_FALSE;
02075 }
02076 
02077 /*****************************************************************************
02078  * parse_MRL: build a playlist item from a full mrl
02079  *****************************************************************************
02080  * MRL format: "simplified-mrl [:option-name[=option-value]]"
02081  * We don't check for '"' or '\'', we just assume that a ':' that follows a
02082  * space is a new option. Should be good enough for our purpose.
02083  *****************************************************************************/
02084 static playlist_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
02085 {
02086 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
02087 #define SKIPTRAILINGSPACE( p, d ) \
02088     { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
02089 
02090     playlist_item_t *p_item = NULL;
02091     char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
02092     char **ppsz_options = NULL;
02093     int i, i_options = 0;
02094 
02095     if( !psz_mrl ) return 0;
02096 
02097     psz_mrl = psz_orig = strdup( psz_mrl );
02098     while( *psz_mrl )
02099     {
02100         SKIPSPACE( psz_mrl );
02101         psz_item = psz_mrl;
02102 
02103         for( ; *psz_mrl; psz_mrl++ )
02104         {
02105             if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
02106             {
02107                 /* We have a complete item */
02108                 break;
02109             }
02110             if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
02111                 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
02112             {
02113                 /* We have a complete item */
02114                 break;
02115             }
02116         }
02117 
02118         if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
02119         SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
02120 
02121         /* Remove '"' and '\'' if necessary */
02122         if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
02123         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
02124         if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
02125         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
02126 
02127         if( !psz_item_mrl ) psz_item_mrl = psz_item;
02128         else if( *psz_item )
02129         {
02130             i_options++;
02131             ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
02132             ppsz_options[i_options - 1] = &psz_item[1];
02133         }
02134 
02135         if( *psz_mrl ) SKIPSPACE( psz_mrl );
02136     }
02137 
02138     /* Now create a playlist item */
02139     if( psz_item_mrl )
02140     {
02141         p_item = playlist_ItemNew( p_intf, psz_item_mrl, psz_item_mrl );
02142         for( i = 0; i < i_options; i++ )
02143         {
02144             playlist_ItemAddOption( p_item, ppsz_options[i] );
02145         }
02146     }
02147 
02148     if( i_options ) free( ppsz_options );
02149     free( psz_orig );
02150 
02151     return p_item;
02152 }

Generated on Tue Dec 20 10:14:31 2005 for vlc-0.8.4a by  doxygen 1.4.2