]> git.sesse.net Git - vlc/blob - modules/control/rc.c
Modify the update system : I will add more functionnality but this is the beginning
[vlc] / modules / control / rc.c
1 /*****************************************************************************
2  * rc.c : remote control stdin/stdout module for vlc
3  *****************************************************************************
4  * Copyright (C) 2004-2007 the VideoLAN team
5  * $Id$
6  *
7  * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
8  *         Jean-Paul Saman <jpsaman #_at_# m2x _replaceWith#dot_ nl>
9  *
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.
14  *
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.
19  *
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29
30
31 #include <errno.h>                                                 /* ENOMEM */
32 #include <ctype.h>
33 #include <signal.h>
34
35 #include <vlc_interface.h>
36 #include <vlc_aout.h>
37 #include <vlc_vout.h>
38 #include <vlc_osd.h>
39 #include <vlc_playlist.h>
40 #include <vlc_update.h>
41
42 #ifdef HAVE_UNISTD_H
43 #    include <unistd.h>
44 #endif
45
46 #ifdef HAVE_SYS_TIME_H
47 #    include <sys/time.h>
48 #endif
49 #include <sys/types.h>
50
51 #include <vlc_network.h>
52 #include "vlc_url.h"
53
54 #include <vlc_charset.h>
55
56 #if defined(AF_UNIX) && !defined(AF_LOCAL)
57 #    define AF_LOCAL AF_UNIX
58 #endif
59
60 #if defined(AF_LOCAL) && ! defined(WIN32)
61 #    include <sys/un.h>
62 #endif
63
64 #define MAX_LINE_LENGTH 256
65 #define STATUS_CHANGE "status change: "
66
67 /*****************************************************************************
68  * Local prototypes
69  *****************************************************************************/
70 static int  Activate     ( vlc_object_t * );
71 static void Deactivate   ( vlc_object_t * );
72 static void Run          ( intf_thread_t * );
73
74 static void Help         ( intf_thread_t *, vlc_bool_t );
75 static void RegisterCallbacks( intf_thread_t * );
76
77 static vlc_bool_t ReadCommand( intf_thread_t *, char *, int * );
78
79 static input_item_t *parse_MRL( intf_thread_t *, char * );
80
81 static int  Input        ( vlc_object_t *, char const *,
82                            vlc_value_t, vlc_value_t, void * );
83 static int  Playlist     ( vlc_object_t *, char const *,
84                            vlc_value_t, vlc_value_t, void * );
85 static int  Quit         ( vlc_object_t *, char const *,
86                            vlc_value_t, vlc_value_t, void * );
87 static int  Intf         ( vlc_object_t *, char const *,
88                            vlc_value_t, vlc_value_t, void * );
89 static int  Volume       ( vlc_object_t *, char const *,
90                            vlc_value_t, vlc_value_t, void * );
91 static int  VolumeMove   ( vlc_object_t *, char const *,
92                            vlc_value_t, vlc_value_t, void * );
93 static int  VideoConfig  ( vlc_object_t *, char const *,
94                            vlc_value_t, vlc_value_t, void * );
95 static int  AudioConfig  ( vlc_object_t *, char const *,
96                            vlc_value_t, vlc_value_t, void * );
97 static int  Menu         ( vlc_object_t *, char const *,
98                            vlc_value_t, vlc_value_t, void * );
99 static void checkUpdates( intf_thread_t *p_intf );
100
101 /* Status Callbacks */
102 static int TimeOffsetChanged( vlc_object_t *, char const *,
103                               vlc_value_t, vlc_value_t , void * );
104 static int VolumeChanged    ( vlc_object_t *, char const *,
105                               vlc_value_t, vlc_value_t, void * );
106 static int StateChanged     ( vlc_object_t *, char const *,
107                               vlc_value_t, vlc_value_t, void * );
108 static int RateChanged      ( vlc_object_t *, char const *,
109                               vlc_value_t, vlc_value_t, void * );
110
111 struct intf_sys_t
112 {
113     int *pi_socket_listen;
114     int i_socket;
115     char *psz_unix_path;
116
117     /* status changes */
118     vlc_mutex_t       status_lock;
119     playlist_status_t i_last_state;
120
121 #ifdef WIN32
122     HANDLE hConsoleIn;
123     vlc_bool_t b_quiet;
124 #endif
125 };
126
127 #ifdef HAVE_VARIADIC_MACROS
128 #   define msg_rc( psz_format, args... ) \
129       __msg_rc( p_intf, psz_format, ## args )
130 #endif
131
132 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
133 {
134     va_list args;
135     va_start( args, psz_fmt );
136
137     if( p_intf->p_sys->i_socket == -1 )
138     {
139         utf8_vfprintf( stdout, psz_fmt, args );
140         printf( "\r\n" );
141     }
142     else
143     {
144         net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
145         net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
146     }
147     va_end( args );
148 }
149
150 /*****************************************************************************
151  * Module descriptor
152  *****************************************************************************/
153 #define POS_TEXT N_("Show stream position")
154 #define POS_LONGTEXT N_("Show the current position in seconds within the " \
155                         "stream from time to time." )
156
157 #define TTY_TEXT N_("Fake TTY")
158 #define TTY_LONGTEXT N_("Force the rc module to use stdin as if it was a TTY.")
159
160 #define UNIX_TEXT N_("UNIX socket command input")
161 #define UNIX_LONGTEXT N_("Accept commands over a Unix socket rather than " \
162                          "stdin." )
163
164 #define HOST_TEXT N_("TCP command input")
165 #define HOST_LONGTEXT N_("Accept commands over a socket rather than stdin. " \
166             "You can set the address and port the interface will bind to." )
167
168 #ifdef WIN32
169 #define QUIET_TEXT N_("Do not open a DOS command box interface")
170 #define QUIET_LONGTEXT N_( \
171     "By default the rc interface plugin will start a DOS command box. " \
172     "Enabling the quiet mode will not bring this command box but can also " \
173     "be pretty annoying when you want to stop VLC and no video window is " \
174     "open." )
175 #endif
176
177 vlc_module_begin();
178     set_shortname( _("RC"));
179     set_category( CAT_INTERFACE );
180     set_subcategory( SUBCAT_INTERFACE_MAIN );
181     set_description( _("Remote control interface") );
182     add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
183
184 #ifdef WIN32
185     add_bool( "rc-quiet", 0, NULL, QUIET_TEXT, QUIET_LONGTEXT, VLC_FALSE );
186 #else
187 #if defined (HAVE_ISATTY)
188     add_bool( "rc-fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
189 #endif
190     add_string( "rc-unix", 0, NULL, UNIX_TEXT, UNIX_LONGTEXT, VLC_TRUE );
191 #endif
192     add_string( "rc-host", 0, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
193
194     set_capability( "interface", 20 );
195
196     set_callbacks( Activate, Deactivate );
197 vlc_module_end();
198
199 /*****************************************************************************
200  * Activate: initialize and create stuff
201  *****************************************************************************/
202 static int Activate( vlc_object_t *p_this )
203 {
204     intf_thread_t *p_intf = (intf_thread_t*)p_this;
205     char *psz_host, *psz_unix_path;
206     int  *pi_socket = NULL;
207
208 #ifndef WIN32
209 #if defined(HAVE_ISATTY)
210     /* Check that stdin is a TTY */
211     if( !config_GetInt( p_intf, "rc-fake-tty" ) && !isatty( 0 ) )
212     {
213         msg_Warn( p_intf, "fd 0 is not a TTY" );
214         return VLC_EGENERIC;
215     }
216 #endif
217
218     psz_unix_path = config_GetPsz( p_intf, "rc-unix" );
219     if( psz_unix_path )
220     {
221         int i_socket;
222
223 #ifndef AF_LOCAL
224         msg_Warn( p_intf, "your OS doesn't support filesystem sockets" );
225         free( psz_unix_path );
226         return VLC_EGENERIC;
227 #else
228         struct sockaddr_un addr;
229
230         memset( &addr, 0, sizeof(struct sockaddr_un) );
231
232         msg_Dbg( p_intf, "trying UNIX socket" );
233
234         if( (i_socket = socket( AF_LOCAL, SOCK_STREAM, 0 ) ) < 0 )
235         {
236             msg_Warn( p_intf, "can't open socket: %m" );
237             free( psz_unix_path );
238             return VLC_EGENERIC;
239         }
240
241         addr.sun_family = AF_LOCAL;
242         strncpy( addr.sun_path, psz_unix_path, sizeof( addr.sun_path ) );
243         addr.sun_path[sizeof( addr.sun_path ) - 1] = '\0';
244
245         if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr))
246          && (errno == EADDRINUSE)
247          && connect (i_socket, (struct sockaddr *)&addr, sizeof (addr))
248          && (errno == ECONNREFUSED))
249         {
250             msg_Info (p_intf, "Removing dead UNIX socket: %s", psz_unix_path);
251             unlink (psz_unix_path);
252
253             if (bind (i_socket, (struct sockaddr *)&addr, sizeof (addr)))
254             {
255                 msg_Err (p_intf, "cannot bind UNIX socket at %s: %m",
256                          psz_unix_path);
257                 free (psz_unix_path);
258                 net_Close (i_socket);
259                 return VLC_EGENERIC;
260             }
261         }
262
263         if( listen( i_socket, 1 ) )
264         {
265             msg_Warn( p_intf, "can't listen on socket: %m");
266             free( psz_unix_path );
267             net_Close( i_socket );
268             return VLC_EGENERIC;
269         }
270
271         /* FIXME: we need a core function to merge listening sockets sets */
272         pi_socket = calloc( 2, sizeof( int ) );
273         if( pi_socket == NULL )
274         {
275             free( psz_unix_path );
276             net_Close( i_socket );
277             return VLC_ENOMEM;
278         }
279         pi_socket[0] = i_socket;
280         pi_socket[1] = -1;
281 #endif /* AF_LOCAL */
282     }
283 #endif /* !WIN32 */
284
285     if( ( pi_socket == NULL ) &&
286         ( psz_host = config_GetPsz( p_intf, "rc-host" ) ) != NULL )
287     {
288         vlc_url_t url;
289
290         vlc_UrlParse( &url, psz_host, 0 );
291
292         msg_Dbg( p_intf, "base: %s, port: %d", url.psz_host, url.i_port );
293
294         pi_socket = net_ListenTCP(p_this, url.psz_host, url.i_port);
295         if( pi_socket == NULL )
296         {
297             msg_Warn( p_intf, "can't listen to %s port %i",
298                       url.psz_host, url.i_port );
299             vlc_UrlClean( &url );
300             free( psz_host );
301             return VLC_EGENERIC;
302         }
303
304         vlc_UrlClean( &url );
305         free( psz_host );
306     }
307
308     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
309     if( !p_intf->p_sys )
310     {
311         msg_Err( p_intf, "no memory" );
312         return VLC_ENOMEM;
313     }
314
315     p_intf->p_sys->pi_socket_listen = pi_socket;
316     p_intf->p_sys->i_socket = -1;
317     p_intf->p_sys->psz_unix_path = psz_unix_path;
318     vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
319     p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
320
321     /* Non-buffered stdout */
322     setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
323
324     p_intf->pf_run = Run;
325
326 #ifdef WIN32
327     p_intf->p_sys->b_quiet = config_GetInt( p_intf, "rc-quiet" );
328     if( !p_intf->p_sys->b_quiet ) { CONSOLE_INTRO_MSG; }
329 #else
330     CONSOLE_INTRO_MSG;
331 #endif
332
333     msg_rc( _("Remote control interface initialized. Type `help' for help.") );
334     return VLC_SUCCESS;
335 }
336
337 /*****************************************************************************
338  * Deactivate: uninitialize and cleanup
339  *****************************************************************************/
340 static void Deactivate( vlc_object_t *p_this )
341 {
342     intf_thread_t *p_intf = (intf_thread_t*)p_this;
343
344     net_ListenClose( p_intf->p_sys->pi_socket_listen );
345     if( p_intf->p_sys->i_socket != -1 )
346         net_Close( p_intf->p_sys->i_socket );
347     if( p_intf->p_sys->psz_unix_path != NULL )
348     {
349 #if defined(AF_LOCAL) && !defined(WIN32)
350         unlink( p_intf->p_sys->psz_unix_path );
351 #endif
352         free( p_intf->p_sys->psz_unix_path );
353     }
354     vlc_mutex_destroy( &p_intf->p_sys->status_lock );
355     free( p_intf->p_sys );
356 }
357
358 /*****************************************************************************
359  * RegisterCallbacks: Register callbacks to dynamic variables
360  *****************************************************************************/
361 static void RegisterCallbacks( intf_thread_t *p_intf )
362 {
363     /* Register commands that will be cleaned up upon object destruction */
364 #define ADD( name, type, target )                                   \
365     var_Create( p_intf, name, VLC_VAR_ ## type | VLC_VAR_ISCOMMAND ); \
366     var_AddCallback( p_intf, name, target, NULL );
367     ADD( "quit", VOID, Quit )
368     ADD( "intf", STRING, Intf )
369
370     ADD( "add", STRING, Playlist )
371     ADD( "repeat", STRING, Playlist )
372     ADD( "loop", STRING, Playlist )
373     ADD( "random", STRING, Playlist )
374     ADD( "enqueue", STRING, Playlist )
375     ADD( "playlist", VOID, Playlist )
376     ADD( "sort", VOID, Playlist )
377     ADD( "play", VOID, Playlist )
378     ADD( "stop", VOID, Playlist )
379     ADD( "clear", VOID, Playlist )
380     ADD( "prev", VOID, Playlist )
381     ADD( "next", VOID, Playlist )
382     ADD( "goto", INTEGER, Playlist )
383     ADD( "status", INTEGER, Playlist )
384
385     /* OSD menu commands */
386     ADD(  "menu", STRING, Menu )
387
388     /* DVD commands */
389     ADD( "pause", VOID, Input )
390     ADD( "seek", INTEGER, Input )
391     ADD( "title", STRING, Input )
392     ADD( "title_n", VOID, Input )
393     ADD( "title_p", VOID, Input )
394     ADD( "chapter", STRING, Input )
395     ADD( "chapter_n", VOID, Input )
396     ADD( "chapter_p", VOID, Input )
397
398     ADD( "fastforward", VOID, Input )
399     ADD( "rewind", VOID, Input )
400     ADD( "faster", VOID, Input )
401     ADD( "slower", VOID, Input )
402     ADD( "normal", VOID, Input )
403
404     ADD( "atrack", STRING, Input )
405     ADD( "vtrack", STRING, Input )
406     ADD( "strack", STRING, Input )
407
408     /* video commands */
409     ADD( "vratio", STRING, VideoConfig )
410     ADD( "vcrop", STRING, VideoConfig )
411     ADD( "vzoom", STRING, VideoConfig )
412     ADD( "snapshot", VOID, VideoConfig )
413
414     /* audio commands */
415     ADD( "volume", STRING, Volume )
416     ADD( "volup", STRING, VolumeMove )
417     ADD( "voldown", STRING, VolumeMove )
418     ADD( "adev", STRING, AudioConfig )
419     ADD( "achan", STRING, AudioConfig )
420
421 #undef ADD
422 }
423
424 /*****************************************************************************
425  * Run: rc thread
426  *****************************************************************************
427  * This part of the interface is in a separate thread so that we can call
428  * exec() from within it without annoying the rest of the program.
429  *****************************************************************************/
430 static void Run( intf_thread_t *p_intf )
431 {
432     input_thread_t * p_input;
433     playlist_t *     p_playlist;
434
435     char       p_buffer[ MAX_LINE_LENGTH + 1 ];
436     vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
437     vlc_bool_t b_longhelp = VLC_FALSE;
438
439     int        i_size = 0;
440     int        i_oldpos = 0;
441     int        i_newpos;
442
443     p_buffer[0] = 0;
444     p_input = NULL;
445     p_playlist = NULL;
446
447     /* Register commands that will be cleaned up upon object destruction */
448     RegisterCallbacks( p_intf );
449
450     /* status callbacks */
451     /* Listen to audio volume updates */
452     var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
453
454 #ifdef WIN32
455     /* Get the file descriptor of the console input */
456     p_intf->p_sys->hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
457     if( p_intf->p_sys->hConsoleIn == INVALID_HANDLE_VALUE )
458     {
459         msg_Err( p_intf, "couldn't find user input handle" );
460         vlc_object_kill( p_intf );
461     }
462 #endif
463
464     while( !intf_ShouldDie( p_intf ) )
465     {
466         char *psz_cmd, *psz_arg;
467         vlc_bool_t b_complete;
468
469         if( p_intf->p_sys->pi_socket_listen != NULL &&
470             p_intf->p_sys->i_socket == -1 )
471         {
472             p_intf->p_sys->i_socket =
473                 net_Accept( p_intf, p_intf->p_sys->pi_socket_listen,
474                             INTF_IDLE_SLEEP );
475             if( p_intf->p_sys->i_socket == -1 ) continue;
476         }
477
478         b_complete = ReadCommand( p_intf, p_buffer, &i_size );
479
480         /* Manage the input part */
481         if( p_input == NULL )
482         {
483             if( p_playlist )
484             {
485                 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
486                                                        FIND_CHILD );
487             }
488             else
489             {
490                 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
491                                                    FIND_ANYWHERE );
492                 if( p_input )
493                 {
494                     p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
495                                                            FIND_PARENT );
496                 }
497             }
498             /* New input has been registered */
499             if( p_input )
500             {
501                 if( !p_input->b_dead || !p_input->b_die )
502                 {
503                     char *psz_uri =
504                             input_item_GetURI( input_GetItem( p_input ) );
505                     msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
506                     free( psz_uri );
507                     msg_rc( STATUS_CHANGE "( audio volume: %d )",
508                             config_GetInt( p_intf, "volume" ));
509                 }
510                 var_AddCallback( p_input, "state", StateChanged, p_intf );
511                 var_AddCallback( p_input, "rate-faster", RateChanged, p_intf );
512                 var_AddCallback( p_input, "rate-slower", RateChanged, p_intf );
513                 var_AddCallback( p_input, "rate", RateChanged, p_intf );
514                 var_AddCallback( p_input, "time-offset", TimeOffsetChanged,
515                                  p_intf );
516             }
517         }
518         else if( p_input->b_dead )
519         {
520             var_DelCallback( p_input, "state", StateChanged, p_intf );
521             var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
522             var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
523             var_DelCallback( p_input, "rate", RateChanged, p_intf );
524             var_DelCallback( p_input, "time-offset", TimeOffsetChanged,
525                              p_intf );
526             vlc_object_release( p_input );
527             p_input = NULL;
528
529             if( p_playlist )
530             {
531                 vlc_mutex_lock( &p_playlist->object_lock );
532                 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
533                 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
534                 vlc_mutex_unlock( &p_playlist->object_lock );
535             }
536         }
537
538         if( (p_input != NULL) && !p_input->b_dead && !p_input->b_die &&
539             (p_playlist != NULL) )
540         {
541             vlc_mutex_lock( &p_playlist->object_lock );
542             if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
543                 (p_playlist->status.i_status == PLAYLIST_STOPPED) )
544             {
545                 p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
546                 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
547             }
548             else if(
549                 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
550                 (p_playlist->status.i_status == PLAYLIST_RUNNING) )
551             {
552                 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
553                 msg_rc( STATUS_CHANGE "( play state: 1 )" );
554             }
555             else if(
556                 (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
557                 (p_playlist->status.i_status == PLAYLIST_PAUSED) )
558             {
559                 p_intf->p_sys->i_last_state = p_playlist->status.i_status;
560                 msg_rc( STATUS_CHANGE "( pause state: 2 )" );
561             }
562             vlc_mutex_unlock( &p_playlist->object_lock );
563         }
564
565         if( p_input && b_showpos )
566         {
567             i_newpos = 100 * var_GetFloat( p_input, "position" );
568             if( i_oldpos != i_newpos )
569             {
570                 i_oldpos = i_newpos;
571                 msg_rc( "pos: %d%%", i_newpos );
572             }
573         }
574
575         /* Is there something to do? */
576         if( !b_complete ) continue;
577
578
579         /* Skip heading spaces */
580         psz_cmd = p_buffer;
581         while( *psz_cmd == ' ' )
582         {
583             psz_cmd++;
584         }
585
586         /* Split psz_cmd at the first space and make sure that
587          * psz_arg is valid */
588         psz_arg = strchr( psz_cmd, ' ' );
589         if( psz_arg )
590         {
591             *psz_arg++ = 0;
592             while( *psz_arg == ' ' )
593             {
594                 psz_arg++;
595             }
596         }
597         else
598         {
599             psz_arg = "";
600         }
601
602         /* module specfic commands: @<module name> <command> <args...> */
603         if( *psz_cmd == '@' && *psz_arg )
604         {
605             /* Parse miscellaneous commands */
606             char *psz_alias = psz_cmd + 1;
607             char *psz_mycmd = strdup( psz_arg );
608             char *psz_myarg = strchr( psz_mycmd, ' ' );
609             char *psz_msg;
610
611             if( !psz_myarg )
612             {
613                 msg_rc( "Not enough parameters." );
614             }
615             else
616             {
617                 *psz_myarg = '\0';
618                 psz_myarg ++;
619
620                 var_Command( p_intf, psz_alias, psz_mycmd, psz_myarg,
621                              &psz_msg );
622
623                 if( psz_msg )
624                 {
625                     msg_rc( psz_msg );
626                     free( psz_msg );
627                 }
628             }
629             free( psz_mycmd );
630         }
631         /* If the user typed a registered local command, try it */
632         else if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
633         {
634             vlc_value_t val;
635             int i_ret;
636
637             val.psz_string = psz_arg;
638             i_ret = var_Set( p_intf, psz_cmd, val );
639             msg_rc( "%s: returned %i (%s)",
640                     psz_cmd, i_ret, vlc_error( i_ret ) );
641         }
642         /* Or maybe it's a global command */
643         else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
644         {
645             vlc_value_t val;
646             int i_ret;
647
648             val.psz_string = psz_arg;
649             /* FIXME: it's a global command, but we should pass the
650              * local object as an argument, not p_intf->p_libvlc. */
651             i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
652             if( i_ret != 0 )
653             {
654                 msg_rc( "%s: returned %i (%s)",
655                          psz_cmd, i_ret, vlc_error( i_ret ) );
656             }
657         }
658         else if( !strcmp( psz_cmd, "logout" ) )
659         {
660             /* Close connection */
661             if( p_intf->p_sys->i_socket != -1 )
662             {
663                 net_Close( p_intf->p_sys->i_socket );
664             }
665             p_intf->p_sys->i_socket = -1;
666         }
667         else if( !strcmp( psz_cmd, "info" ) )
668         {
669             if( p_input )
670             {
671                 int i, j;
672                 vlc_mutex_lock( &input_GetItem(p_input)->lock );
673                 for ( i = 0; i < input_GetItem(p_input)->i_categories; i++ )
674                 {
675                     info_category_t *p_category = input_GetItem(p_input)
676                                                         ->pp_categories[i];
677
678                     msg_rc( "+----[ %s ]", p_category->psz_name );
679                     msg_rc( "| " );
680                     for ( j = 0; j < p_category->i_infos; j++ )
681                     {
682                         info_t *p_info = p_category->pp_infos[j];
683                         msg_rc( "| %s: %s", p_info->psz_name,
684                                 p_info->psz_value );
685                     }
686                     msg_rc( "| " );
687                 }
688                 msg_rc( "+----[ end of stream info ]" );
689                 vlc_mutex_unlock( &input_GetItem(p_input)->lock );
690             }
691             else
692             {
693                 msg_rc( "no input" );
694             }
695         }
696         else if( !strcmp( psz_cmd, "is_playing" ) )
697         {
698             if( ! p_input )
699             {
700                 msg_rc( "0" );
701             }
702             else
703             {
704                 msg_rc( "1" );
705             }
706         }
707         else if( !strcmp( psz_cmd, "get_time" ) )
708         {
709             if( ! p_input )
710             {
711                 msg_rc("0");
712             }
713             else
714             {
715                 vlc_value_t time;
716                 var_Get( p_input, "time", &time );
717                 msg_rc( "%i", time.i_time / 1000000);
718             }
719         }
720         else if( !strcmp( psz_cmd, "get_length" ) )
721         {
722             if( ! p_input )
723             {
724                 msg_rc("0");
725             }
726             else
727             {
728                 vlc_value_t time;
729                 var_Get( p_input, "length", &time );
730                 msg_rc( "%i", time.i_time / 1000000);
731             }
732         }
733         else if( !strcmp( psz_cmd, "get_title" ) )
734         {
735             if( ! p_input )
736             {
737                 msg_rc("");
738             }
739             else
740             {
741                 msg_rc( "%s", input_GetItem(p_input)->psz_name );
742             }
743         }
744         else if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "h", 1 )
745                  || !strncmp( psz_cmd, "H", 1 ) || !strncmp( psz_cmd, "?", 1 ) )
746         {
747             if( !strcmp( psz_cmd, "longhelp" ) || !strncmp( psz_cmd, "H", 1 ) )
748                  b_longhelp = VLC_TRUE;
749             else b_longhelp = VLC_FALSE;
750
751             Help( p_intf, b_longhelp );
752         }
753         else if( !strcmp( psz_cmd, "check-updates" ) )
754         {
755             checkUpdates( p_intf );
756         }
757         else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
758         {
759             var_SetInteger( p_intf->p_libvlc, "key-pressed",
760                             config_GetInt( p_intf, psz_arg ) );
761         }
762         else switch( psz_cmd[0] )
763         {
764         case 'f':
765         case 'F':
766             if( p_input )
767             {
768                 vout_thread_t *p_vout;
769                 p_vout = vlc_object_find( p_input,
770                                           VLC_OBJECT_VOUT, FIND_CHILD );
771
772                 if( p_vout )
773                 {
774                     vlc_value_t val;
775                     vlc_bool_t b_update = VLC_FALSE;
776                     var_Get( p_vout, "fullscreen", &val );
777                     val.b_bool = !val.b_bool;
778                     if( !strncmp( psz_arg, "on", 2 )
779                         && ( val.b_bool == VLC_TRUE ) )
780                     {
781                         b_update = VLC_TRUE;
782                         val.b_bool = VLC_TRUE;
783                     }
784                     else if( !strncmp( psz_arg, "off", 3 )
785                              && ( val.b_bool == VLC_FALSE ) )
786                     {
787                         b_update = VLC_TRUE;
788                         val.b_bool = VLC_FALSE;
789                     }
790                     else if( strncmp( psz_arg, "off", 3 )
791                              && strncmp( psz_arg, "on", 2 ) )
792                         b_update = VLC_TRUE;
793                     if( b_update ) var_Set( p_vout, "fullscreen", val );
794                     vlc_object_release( p_vout );
795                 }
796             }
797             break;
798
799         case 's':
800         case 'S':
801             ;
802             break;
803
804         case '\0':
805             /* Ignore empty lines */
806             break;
807
808         default:
809             msg_rc(_("Unknown command `%s'. Type `help' for help."), psz_cmd);
810             break;
811         }
812
813         /* Command processed */
814         i_size = 0; p_buffer[0] = 0;
815     }
816
817     msg_rc( STATUS_CHANGE "( stop state: 0 )" );
818     msg_rc( STATUS_CHANGE "( quit )" );
819
820     if( p_input )
821     {
822         var_DelCallback( p_input, "state", StateChanged, p_intf );
823         var_DelCallback( p_input, "rate-faster", RateChanged, p_intf );
824         var_DelCallback( p_input, "rate-slower", RateChanged, p_intf );
825         var_DelCallback( p_input, "rate", RateChanged, p_intf );
826         var_DelCallback( p_input, "time-offset", TimeOffsetChanged, p_intf );
827         vlc_object_release( p_input );
828         p_input = NULL;
829     }
830
831     if( p_playlist )
832     {
833         vlc_object_release( p_playlist );
834         p_playlist = NULL;
835     }
836
837     var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
838 }
839
840 static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
841 {
842     msg_rc(_("+----[ Remote control commands ]"));
843     msg_rc(  "| ");
844     msg_rc(_("| add XYZ  . . . . . . . . . . . . add XYZ to playlist"));
845     msg_rc(_("| enqueue XYZ  . . . . . . . . . queue XYZ to playlist"));
846     msg_rc(_("| playlist . . . . .  show items currently in playlist"));
847     msg_rc(_("| play . . . . . . . . . . . . . . . . . . play stream"));
848     msg_rc(_("| stop . . . . . . . . . . . . . . . . . . stop stream"));
849     msg_rc(_("| next . . . . . . . . . . . . . .  next playlist item"));
850     msg_rc(_("| prev . . . . . . . . . . . .  previous playlist item"));
851     msg_rc(_("| goto . . . . . . . . . . . . . .  goto item at index"));
852     msg_rc(_("| repeat [on|off] . . . .  toggle playlist item repeat"));
853     msg_rc(_("| loop [on|off] . . . . . . . . . toggle playlist loop"));
854     msg_rc(_("| random [on|off] . . . . . . .  toggle random jumping"));
855     msg_rc(_("| clear . . . . . . . . . . . . . . clear the playlist"));
856     msg_rc(_("| status . . . . . . . . . . . current playlist status"));
857     msg_rc(_("| title [X]  . . . . . . set/get title in current item"));
858     msg_rc(_("| title_n  . . . . . . . .  next title in current item"));
859     msg_rc(_("| title_p  . . . . . .  previous title in current item"));
860     msg_rc(_("| chapter [X]  . . . . set/get chapter in current item"));
861     msg_rc(_("| chapter_n  . . . . . .  next chapter in current item"));
862     msg_rc(_("| chapter_p  . . . .  previous chapter in current item"));
863     msg_rc(  "| ");
864     msg_rc(_("| seek X . . . seek in seconds, for instance `seek 12'"));
865     msg_rc(_("| pause  . . . . . . . . . . . . . . . .  toggle pause"));
866     msg_rc(_("| fastforward  . . . . . . . .  .  set to maximum rate"));
867     msg_rc(_("| rewind  . . . . . . . . . . . .  set to minimum rate"));
868     msg_rc(_("| faster . . . . . . . . . .  faster playing of stream"));
869     msg_rc(_("| slower . . . . . . . . . .  slower playing of stream"));
870     msg_rc(_("| normal . . . . . . . . . .  normal playing of stream"));
871     msg_rc(_("| f [on|off] . . . . . . . . . . . . toggle fullscreen"));
872     msg_rc(_("| info . . . . .  information about the current stream"));
873     msg_rc(_("| get_time . . seconds elapsed since stream's beginning"));
874     msg_rc(_("| is_playing . . . .  1 if a stream plays, 0 otherwise"));
875     msg_rc(_("| get_title . . . . .  the title of the current stream"));
876     msg_rc(_("| get_length . . . .  the length of the current stream"));
877     msg_rc(  "| ");
878     msg_rc(_("| volume [X] . . . . . . . . . .  set/get audio volume"));
879     msg_rc(_("| volup [X]  . . . . . . .  raise audio volume X steps"));
880     msg_rc(_("| voldown [X]  . . . . . .  lower audio volume X steps"));
881     msg_rc(_("| adev [X] . . . . . . . . . . .  set/get audio device"));
882     msg_rc(_("| achan [X]. . . . . . . . . .  set/get audio channels"));
883     msg_rc(_("| atrack [X] . . . . . . . . . . . set/get audio track"));
884     msg_rc(_("| vtrack [X] . . . . . . . . . . . set/get video track"));
885     msg_rc(_("| vratio [X]  . . . . . . . set/get video aspect ratio"));
886     msg_rc(_("| vcrop [X]  . . . . . . . . . . .  set/get video crop"));
887     msg_rc(_("| vzoom [X]  . . . . . . . . . . .  set/get video zoom"));
888     msg_rc(_("| snapshot . . . . . . . . . . . . take video snapshot"));
889     msg_rc(_("| strack [X] . . . . . . . . . set/get subtitles track"));
890     msg_rc(_("| key [hotkey name] . . . . . .  simulate hotkey press"));
891     msg_rc(_("| menu . . [on|off|up|down|left|right|select] use menu"));
892     msg_rc(  "| ");
893
894     if (b_longhelp)
895     {
896         msg_rc(_("| @name marq-marquee  STRING  . . overlay STRING in video"));
897         msg_rc(_("| @name marq-x X . . . . . . . . . . . .offset from left"));
898         msg_rc(_("| @name marq-y Y . . . . . . . . . . . . offset from top"));
899         msg_rc(_("| @name marq-position #. . .  .relative position control"));
900         msg_rc(_("| @name marq-color # . . . . . . . . . . font color, RGB"));
901         msg_rc(_("| @name marq-opacity # . . . . . . . . . . . . . opacity"));
902         msg_rc(_("| @name marq-timeout T. . . . . . . . . . timeout, in ms"));
903         msg_rc(_("| @name marq-size # . . . . . . . . font size, in pixels"));
904         msg_rc(  "| ");
905         msg_rc(_("| @name logo-file STRING . . .the overlay file path/name"));
906         msg_rc(_("| @name logo-x X . . . . . . . . . . . .offset from left"));
907         msg_rc(_("| @name logo-y Y . . . . . . . . . . . . offset from top"));
908         msg_rc(_("| @name logo-position #. . . . . . . . relative position"));
909         msg_rc(_("| @name logo-transparency #. . . . . . . . .transparency"));
910         msg_rc(  "| ");
911         msg_rc(_("| @name mosaic-alpha # . . . . . . . . . . . . . . alpha"));
912         msg_rc(_("| @name mosaic-height #. . . . . . . . . . . . . .height"));
913         msg_rc(_("| @name mosaic-width # . . . . . . . . . . . . . . width"));
914         msg_rc(_("| @name mosaic-xoffset # . . . .top left corner position"));
915         msg_rc(_("| @name mosaic-yoffset # . . . .top left corner position"));
916         msg_rc(_("| @name mosaic-offsets x,y(,x,y)*. . . . list of offsets"));
917         msg_rc(_("| @name mosaic-align 0..2,4..6,8..10. . .mosaic alignment"));
918         msg_rc(_("| @name mosaic-vborder # . . . . . . . . vertical border"));
919         msg_rc(_("| @name mosaic-hborder # . . . . . . . horizontal border"));
920         msg_rc(_("| @name mosaic-position {0=auto,1=fixed} . . . .position"));
921         msg_rc(_("| @name mosaic-rows #. . . . . . . . . . .number of rows"));
922         msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
923         msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
924         msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
925         msg_rc(  "| ");
926         msg_rc(_("| check-updates [newer] [equal] [older]\n"
927                  "|               [undef] [info] [source] [binary] [plugin]"));
928         msg_rc(  "| ");
929     }
930     msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
931     msg_rc(_("| longhelp . . . . . . . . . . . a longer help message"));
932     msg_rc(_("| logout . . . . . . .  exit (if in socket connection)"));
933     msg_rc(_("| quit . . . . . . . . . . . . . . . . . . .  quit vlc"));
934     msg_rc(  "| ");
935     msg_rc(_("+----[ end of help ]"));
936 }
937
938 /********************************************************************
939  * Status callback routines
940  ********************************************************************/
941 static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
942     vlc_value_t oldval, vlc_value_t newval, void *p_data )
943 {
944     intf_thread_t *p_intf = (intf_thread_t*)p_data;
945     input_thread_t *p_input = NULL;
946
947     vlc_mutex_lock( &p_intf->p_sys->status_lock );
948     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
949     if( p_input )
950     {
951         msg_rc( STATUS_CHANGE "( time-offset: %d )",
952                 var_GetInteger( p_input, "time-offset" ) );
953         vlc_object_release( p_input );
954     }
955     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
956     return VLC_SUCCESS;
957 }
958
959 static int VolumeChanged( vlc_object_t *p_this, char const *psz_cmd,
960     vlc_value_t oldval, vlc_value_t newval, void *p_data )
961 {
962     intf_thread_t *p_intf = (intf_thread_t*)p_data;
963
964     vlc_mutex_lock( &p_intf->p_sys->status_lock );
965     msg_rc( STATUS_CHANGE "( audio volume: %d )",
966             config_GetInt( p_this, "volume") );
967     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
968     return VLC_SUCCESS;
969 }
970
971 static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
972     vlc_value_t oldval, vlc_value_t newval, void *p_data )
973 {
974     intf_thread_t *p_intf = (intf_thread_t*)p_data;
975     playlist_t    *p_playlist = NULL;
976     input_thread_t *p_input = NULL;
977
978     vlc_mutex_lock( &p_intf->p_sys->status_lock );
979     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
980     if( p_input )
981     {
982         p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
983         if( p_playlist )
984         {
985             char cmd[5] = "";
986             switch( p_playlist->status.i_status )
987             {
988             case PLAYLIST_STOPPED:
989                 strncpy( &cmd[0], "stop", 4);
990                 cmd[4] = '\0';
991                 break;
992             case PLAYLIST_RUNNING:
993                 strncpy( &cmd[0], "play", 4);
994                 cmd[4] = '\0';
995                 break;
996             case PLAYLIST_PAUSED:
997                 strncpy( &cmd[0], "pause", 5);
998                 cmd[5] = '\0';
999                 break;
1000             } /* var_GetInteger( p_input, "state" )  */
1001             msg_rc( STATUS_CHANGE "( %s state: %d )", &cmd[0], newval.i_int );
1002             vlc_object_release( p_playlist );
1003         }
1004         vlc_object_release( p_input );
1005     }
1006     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1007     return VLC_SUCCESS;
1008 }
1009
1010 static int RateChanged( vlc_object_t *p_this, char const *psz_cmd,
1011     vlc_value_t oldval, vlc_value_t newval, void *p_data )
1012 {
1013     intf_thread_t *p_intf = (intf_thread_t*)p_data;
1014     input_thread_t *p_input = NULL;
1015
1016     vlc_mutex_lock( &p_intf->p_sys->status_lock );
1017     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1018     if( p_input )
1019     {
1020         msg_rc( STATUS_CHANGE "( new rate: %d )",
1021                 var_GetInteger( p_input, "rate" ) );
1022         vlc_object_release( p_input );
1023     }
1024     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
1025     return VLC_SUCCESS;
1026 }
1027
1028 /********************************************************************
1029  * Command routines
1030  ********************************************************************/
1031 static int Input( vlc_object_t *p_this, char const *psz_cmd,
1032                   vlc_value_t oldval, vlc_value_t newval, void *p_data )
1033 {
1034     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1035     input_thread_t *p_input;
1036     vlc_value_t     val;
1037
1038     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1039     if( !p_input ) return VLC_ENOOBJ;
1040
1041     var_Get( p_input, "state", &val );
1042     if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1043         ( strcmp( psz_cmd, "pause" ) != 0 ) )
1044     {
1045         msg_rc( _("Press menu select or pause to continue.") );
1046         vlc_object_release( p_input );
1047         return VLC_EGENERIC;
1048     }
1049
1050     /* Parse commands that only require an input */
1051     if( !strcmp( psz_cmd, "pause" ) )
1052     {
1053         val.i_int = config_GetInt( p_intf, "key-play-pause" );
1054         var_Set( p_intf->p_libvlc, "key-pressed", val );
1055         vlc_object_release( p_input );
1056         return VLC_SUCCESS;
1057     }
1058     else if( !strcmp( psz_cmd, "seek" ) )
1059     {
1060         if( strlen( newval.psz_string ) > 0 &&
1061             newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
1062         {
1063             val.f_float = (float)atof( newval.psz_string ) / 100.0;
1064             var_Set( p_input, "position", val );
1065         }
1066         else
1067         {
1068             val.i_time = ((int64_t)atoi( newval.psz_string )) * 1000000;
1069             var_Set( p_input, "time", val );
1070         }
1071         vlc_object_release( p_input );
1072         return VLC_SUCCESS;
1073     }
1074     else if ( !strcmp( psz_cmd, "fastforward" ) )
1075     {
1076         val.i_int = config_GetInt( p_intf, "key-jump+extrashort" );
1077         var_Set( p_intf->p_libvlc, "key-pressed", val );
1078         vlc_object_release( p_input );
1079         return VLC_SUCCESS;
1080     }
1081     else if ( !strcmp( psz_cmd, "rewind" ) )
1082     {
1083         val.i_int = config_GetInt( p_intf, "key-jump-extrashort" );
1084         var_Set( p_intf->p_libvlc, "key-pressed", val );
1085         vlc_object_release( p_input );
1086         return VLC_SUCCESS;
1087     }
1088     else if ( !strcmp( psz_cmd, "faster" ) )
1089     {
1090         var_Set( p_input, "rate-faster", val );
1091         vlc_object_release( p_input );
1092         return VLC_SUCCESS;
1093     }
1094     else if ( !strcmp( psz_cmd, "slower" ) )
1095     {
1096         var_Set( p_input, "rate-slower", val );
1097         vlc_object_release( p_input );
1098         return VLC_SUCCESS;
1099     }
1100     else if ( !strcmp( psz_cmd, "normal" ) )
1101     {
1102         val.i_int = INPUT_RATE_DEFAULT;
1103         var_Set( p_input, "rate", val );
1104         vlc_object_release( p_input );
1105         return VLC_SUCCESS;
1106     }
1107     else if( !strcmp( psz_cmd, "chapter" ) ||
1108              !strcmp( psz_cmd, "chapter_n" ) ||
1109              !strcmp( psz_cmd, "chapter_p" ) )
1110     {
1111         if( !strcmp( psz_cmd, "chapter" ) )
1112         {
1113             if ( *newval.psz_string )
1114             {
1115                 /* Set. */
1116                 val.i_int = atoi( newval.psz_string );
1117                 var_Set( p_input, "chapter", val );
1118             }
1119             else
1120             {
1121                 vlc_value_t val_list;
1122
1123                 /* Get. */
1124                 var_Get( p_input, "chapter", &val );
1125                 var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
1126                             &val_list, NULL );
1127                 msg_rc( "Currently playing chapter %d/%d.",
1128                         val.i_int, val_list.p_list->i_count );
1129                 var_Change( p_this, "chapter", VLC_VAR_FREELIST,
1130                             &val_list, NULL );
1131             }
1132         }
1133         else if( !strcmp( psz_cmd, "chapter_n" ) )
1134         {
1135             val.b_bool = VLC_TRUE;
1136             var_Set( p_input, "next-chapter", val );
1137         }
1138         else if( !strcmp( psz_cmd, "chapter_p" ) )
1139         {
1140             val.b_bool = VLC_TRUE;
1141             var_Set( p_input, "prev-chapter", val );
1142         }
1143         vlc_object_release( p_input );
1144         return VLC_SUCCESS;
1145     }
1146     else if( !strcmp( psz_cmd, "title" ) ||
1147              !strcmp( psz_cmd, "title_n" ) ||
1148              !strcmp( psz_cmd, "title_p" ) )
1149     {
1150         if( !strcmp( psz_cmd, "title" ) )
1151         {
1152             if ( *newval.psz_string )
1153             {
1154                 /* Set. */
1155                 val.i_int = atoi( newval.psz_string );
1156                 var_Set( p_input, "title", val );
1157             }
1158             else
1159             {
1160                 vlc_value_t val_list;
1161
1162                 /* Get. */
1163                 var_Get( p_input, "title", &val );
1164                 var_Change( p_input, "title", VLC_VAR_GETCHOICES,
1165                             &val_list, NULL );
1166                 msg_rc( "Currently playing title %d/%d.",
1167                         val.i_int, val_list.p_list->i_count );
1168                 var_Change( p_this, "title", VLC_VAR_FREELIST,
1169                             &val_list, NULL );
1170             }
1171         }
1172         else if( !strcmp( psz_cmd, "title_n" ) )
1173         {
1174             val.b_bool = VLC_TRUE;
1175             var_Set( p_input, "next-title", val );
1176         }
1177         else if( !strcmp( psz_cmd, "title_p" ) )
1178         {
1179             val.b_bool = VLC_TRUE;
1180             var_Set( p_input, "prev-title", val );
1181         }
1182
1183         vlc_object_release( p_input );
1184         return VLC_SUCCESS;
1185     }
1186     else if(    !strcmp( psz_cmd, "atrack" )
1187              || !strcmp( psz_cmd, "vtrack" )
1188              || !strcmp( psz_cmd, "strack" ) )
1189     {
1190         const char *psz_variable;
1191         vlc_value_t val_name;
1192         int i_error;
1193
1194         if( !strcmp( psz_cmd, "atrack" ) )
1195         {
1196             psz_variable = "audio-es";
1197         }
1198         else if( !strcmp( psz_cmd, "vtrack" ) )
1199         {
1200             psz_variable = "video-es";
1201         }
1202         else
1203         {
1204             psz_variable = "spu-es";
1205         }
1206
1207         /* Get the descriptive name of the variable */
1208         var_Change( p_input, psz_variable, VLC_VAR_GETTEXT,
1209                      &val_name, NULL );
1210         if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1211
1212         if( newval.psz_string && *newval.psz_string )
1213         {
1214             /* set */
1215             vlc_value_t val;
1216             val.i_int = atoi( newval.psz_string );
1217
1218             i_error = var_Set( p_input, psz_variable, val );
1219         }
1220         else
1221         {
1222             /* get */
1223             vlc_value_t val, text;
1224             int i, i_value;
1225
1226             if ( var_Get( p_input, psz_variable, &val ) < 0 )
1227             {
1228                 vlc_object_release( p_input );
1229                 return VLC_EGENERIC;
1230             }
1231             i_value = val.i_int;
1232
1233             if ( var_Change( p_input, psz_variable,
1234                              VLC_VAR_GETLIST, &val, &text ) < 0 )
1235             {
1236                 vlc_object_release( p_input );
1237                 return VLC_EGENERIC;
1238             }
1239
1240             msg_rc( "+----[ %s ]", val_name.psz_string );
1241             for ( i = 0; i < val.p_list->i_count; i++ )
1242             {
1243                 if ( i_value == val.p_list->p_values[i].i_int )
1244                     msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1245                             text.p_list->p_values[i].psz_string );
1246                 else
1247                     msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1248                             text.p_list->p_values[i].psz_string );
1249             }
1250             var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
1251                         &val, &text );
1252             msg_rc( "+----[ end of %s ]", val_name.psz_string );
1253
1254             if( val_name.psz_string ) free( val_name.psz_string );
1255
1256             i_error = VLC_SUCCESS;
1257         }
1258         vlc_object_release( p_input );
1259         return i_error;
1260     }
1261
1262     /* Never reached. */
1263     vlc_object_release( p_input );
1264     return VLC_EGENERIC;
1265 }
1266
1267 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
1268                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
1269 {
1270     vlc_value_t val;
1271
1272     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1273     playlist_t *p_playlist = pl_Yield( p_this );
1274
1275     PL_LOCK;
1276     if( p_playlist->p_input )
1277     {
1278         var_Get( p_playlist->p_input, "state", &val );
1279         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1280         {
1281             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1282             vlc_object_release( p_playlist );
1283             PL_UNLOCK;
1284             return VLC_EGENERIC;
1285         }
1286     }
1287     PL_UNLOCK;
1288
1289     /* Parse commands that require a playlist */
1290     if( !strcmp( psz_cmd, "prev" ) )
1291     {
1292         playlist_Prev( p_playlist );
1293     }
1294     else if( !strcmp( psz_cmd, "next" ) )
1295     {
1296         playlist_Next( p_playlist );
1297     }
1298     else if( !strcmp( psz_cmd, "play" ) )
1299     {
1300         msg_Warn( p_playlist, "play" );
1301         playlist_Play( p_playlist );
1302     }
1303     else if( !strcmp( psz_cmd, "repeat" ) )
1304     {
1305         vlc_bool_t b_update = VLC_TRUE;
1306
1307         var_Get( p_playlist, "repeat", &val );
1308
1309         if( strlen( newval.psz_string ) > 0 )
1310         {
1311             if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1312                  ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1313             {
1314                 b_update = VLC_FALSE;
1315             }
1316         }
1317
1318         if ( b_update )
1319         {
1320             val.b_bool = !val.b_bool;
1321             var_Set( p_playlist, "repeat", val );
1322         }
1323         msg_rc( "Setting repeat to %d", val.b_bool );
1324     }
1325     else if( !strcmp( psz_cmd, "loop" ) )
1326     {
1327         vlc_bool_t b_update = VLC_TRUE;
1328
1329         var_Get( p_playlist, "loop", &val );
1330
1331         if( strlen( newval.psz_string ) > 0 )
1332         {
1333             if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1334                  ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1335             {
1336                 b_update = VLC_FALSE;
1337             }
1338         }
1339
1340         if ( b_update )
1341         {
1342             val.b_bool = !val.b_bool;
1343             var_Set( p_playlist, "loop", val );
1344         }
1345         msg_rc( "Setting loop to %d", val.b_bool );
1346     }
1347     else if( !strcmp( psz_cmd, "random" ) )
1348     {
1349         vlc_bool_t b_update = VLC_TRUE;
1350
1351         var_Get( p_playlist, "random", &val );
1352
1353         if( strlen( newval.psz_string ) > 0 )
1354         {
1355             if ( ( !strncmp( newval.psz_string, "on", 2 ) && ( val.b_bool == VLC_TRUE ) ) ||
1356                  ( !strncmp( newval.psz_string, "off", 3 ) && ( val.b_bool == VLC_FALSE ) ) )
1357             {
1358                 b_update = VLC_FALSE;
1359             }
1360         }
1361
1362         if ( b_update )
1363         {
1364             val.b_bool = !val.b_bool;
1365             var_Set( p_playlist, "random", val );
1366         }
1367         msg_rc( "Setting random to %d", val.b_bool );
1368     }
1369     else if (!strcmp( psz_cmd, "goto" ) )
1370     {
1371         int i_pos = atoi( newval.psz_string );
1372         /* The playlist stores 2 times the same item: onelevel & category */
1373         int i_size = p_playlist->items.i_size / 2;
1374
1375         if( i_pos <= 0 )
1376             msg_rc( _("Error: `goto' needs an argument greater than zero.") );
1377         else if( i_pos <= i_size )
1378         {
1379             playlist_item_t *p_item, *p_parent;
1380             p_item = p_parent = p_playlist->items.p_elems[i_pos*2-1];
1381             while( p_parent->p_parent )
1382                 p_parent = p_parent->p_parent;
1383             playlist_Control( p_playlist, PLAYLIST_VIEWPLAY, VLC_TRUE,
1384                     p_parent, p_item );
1385         }
1386         else
1387             msg_rc( _("Playlist has only %d elements"), i_size );
1388     }
1389     else if( !strcmp( psz_cmd, "stop" ) )
1390     {
1391         playlist_Stop( p_playlist );
1392     }
1393     else if( !strcmp( psz_cmd, "clear" ) )
1394     {
1395         playlist_Stop( p_playlist );
1396         playlist_Clear( p_playlist, VLC_FALSE );
1397     }
1398     else if( !strcmp( psz_cmd, "add" ) &&
1399              newval.psz_string && *newval.psz_string )
1400     {
1401         input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1402
1403         if( p_item )
1404         {
1405             msg_rc( "Trying to add %s to playlist.", newval.psz_string );
1406             playlist_AddInput( p_playlist, p_item,
1407                      PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1408                      VLC_FALSE );
1409         }
1410     }
1411     else if( !strcmp( psz_cmd, "enqueue" ) &&
1412              newval.psz_string && *newval.psz_string )
1413     {
1414         input_item_t *p_item = parse_MRL( p_intf, newval.psz_string );
1415
1416         if( p_item )
1417         {
1418             msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
1419             playlist_AddInput( p_playlist, p_item,
1420                                PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
1421                                VLC_FALSE);
1422         }
1423     }
1424     else if( !strcmp( psz_cmd, "playlist" ) )
1425     {
1426         msg_Dbg( p_playlist, "Dumping category" );
1427         playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
1428         msg_Dbg( p_playlist, "Dumping Onelevel" );
1429         playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
1430     }
1431     else if( !strcmp( psz_cmd, "sort" ))
1432     {
1433         playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
1434                                     SORT_ARTIST, ORDER_NORMAL );
1435     }
1436     else if( !strcmp( psz_cmd, "status" ) )
1437     {
1438         if( p_playlist->p_input )
1439         {
1440             /* Replay the current state of the system. */
1441             char *psz_uri =
1442                     input_item_GetURI( input_GetItem( p_playlist->p_input ) );
1443             msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
1444             free( psz_uri );
1445             msg_rc( STATUS_CHANGE "( audio volume: %d )",
1446                     config_GetInt( p_intf, "volume" ));
1447
1448             vlc_mutex_lock( &p_playlist->object_lock );
1449             switch( p_playlist->status.i_status )
1450             {
1451                 case PLAYLIST_STOPPED:
1452                     msg_rc( STATUS_CHANGE "( stop state: 0 )" );
1453                     break;
1454                 case PLAYLIST_RUNNING:
1455                     msg_rc( STATUS_CHANGE "( play state: 1 )" );
1456                     break;
1457                 case PLAYLIST_PAUSED:
1458                     msg_rc( STATUS_CHANGE "( pause state: 2 )" );
1459                     break;
1460                 default:
1461                     msg_rc( STATUS_CHANGE "( state unknown )" );
1462                     break;
1463             }
1464             vlc_mutex_unlock( &p_playlist->object_lock );
1465         }
1466     }
1467
1468     /*
1469      * sanity check
1470      */
1471     else
1472     {
1473         msg_rc( "unknown command!" );
1474     }
1475
1476     vlc_object_release( p_playlist );
1477     return VLC_SUCCESS;
1478 }
1479
1480 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
1481                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
1482 {
1483     playlist_t *p_playlist;
1484
1485     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1486     if( p_playlist )
1487     {
1488         playlist_Stop( p_playlist );
1489         vlc_object_release( p_playlist );
1490     }
1491     vlc_object_kill( p_this->p_libvlc );
1492     return VLC_SUCCESS;
1493 }
1494
1495 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
1496                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
1497 {
1498     intf_thread_t *p_newintf = NULL;
1499
1500     p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string, 0, NULL );
1501     if( p_newintf )
1502     {
1503         if( intf_RunThread( p_newintf ) )
1504         {
1505             vlc_object_detach( p_newintf );
1506             intf_Destroy( p_newintf );
1507         }
1508     }
1509
1510     return VLC_SUCCESS;
1511 }
1512
1513 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
1514                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
1515 {
1516     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1517     input_thread_t *p_input = NULL;
1518     int i_error = VLC_EGENERIC;
1519
1520     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1521     if( !p_input )
1522         return VLC_ENOOBJ;
1523
1524     if( p_input )
1525     {
1526         vlc_value_t val;
1527
1528         var_Get( p_input, "state", &val );
1529         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1530         {
1531             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1532             vlc_object_release( p_input );
1533             return VLC_EGENERIC;
1534         }
1535         vlc_object_release( p_input );
1536     }
1537
1538     if ( *newval.psz_string )
1539     {
1540         /* Set. */
1541         audio_volume_t i_volume = atoi( newval.psz_string );
1542         if ( (i_volume > (audio_volume_t)AOUT_VOLUME_MAX) )
1543         {
1544             msg_rc( "Volume must be in the range %d-%d.", AOUT_VOLUME_MIN,
1545                     AOUT_VOLUME_MAX );
1546             i_error = VLC_EBADVAR;
1547         }
1548         else
1549         {
1550             if( i_volume == AOUT_VOLUME_MIN )
1551             {
1552                 vlc_value_t keyval;
1553
1554                 keyval.i_int = config_GetInt( p_intf, "key-vol-mute" );
1555                 var_Set( p_intf->p_libvlc, "key-pressed", keyval );
1556             }
1557             i_error = aout_VolumeSet( p_this, i_volume );
1558             osd_Volume( p_this );
1559             msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1560         }
1561     }
1562     else
1563     {
1564         /* Get. */
1565         audio_volume_t i_volume;
1566         if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
1567         {
1568             i_error = VLC_EGENERIC;
1569         }
1570         else
1571         {
1572             msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1573             i_error = VLC_SUCCESS;
1574         }
1575     }
1576
1577     return i_error;
1578 }
1579
1580 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
1581                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
1582 {
1583     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1584     audio_volume_t i_volume;
1585     input_thread_t *p_input = NULL;
1586     int i_nb_steps = atoi(newval.psz_string);
1587     int i_error = VLC_SUCCESS;
1588     int i_volume_step = 0;
1589
1590     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1591     if( !p_input )
1592         return VLC_ENOOBJ;
1593
1594     if( p_input )
1595     {
1596         vlc_value_t val;
1597
1598         var_Get( p_input, "state", &val );
1599         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
1600         {
1601             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1602             vlc_object_release( p_input );
1603             return VLC_EGENERIC;
1604         }
1605         vlc_object_release( p_input );
1606     }
1607
1608     i_volume_step = config_GetInt( p_intf->p_libvlc, "volume-step" );
1609     if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/i_volume_step) )
1610     {
1611         i_nb_steps = 1;
1612     }
1613
1614     if ( !strcmp(psz_cmd, "volup") )
1615     {
1616         if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
1617             i_error = VLC_EGENERIC;
1618     }
1619     else
1620     {
1621         if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
1622             i_error = VLC_EGENERIC;
1623     }
1624     osd_Volume( p_this );
1625
1626     if ( !i_error ) msg_rc( STATUS_CHANGE "( audio volume: %d )", i_volume );
1627     return i_error;
1628 }
1629
1630
1631 static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
1632                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
1633 {
1634     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1635     input_thread_t *p_input = NULL;
1636     vout_thread_t * p_vout;
1637     const char * psz_variable;
1638     int i_error;
1639
1640     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1641     if( !p_input )
1642         return VLC_ENOOBJ;
1643
1644     p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
1645     vlc_object_release( p_input );
1646     if( !p_vout )
1647         return VLC_ENOOBJ;
1648
1649     if( !strcmp( psz_cmd, "vcrop" ) )
1650     {
1651         psz_variable = "crop";
1652     }
1653     else if( !strcmp( psz_cmd, "vratio" ) )
1654     {
1655         psz_variable = "aspect-ratio";
1656     }
1657     else if( !strcmp( psz_cmd, "vzoom" ) )
1658     {
1659         psz_variable = "zoom";
1660     }
1661     else if( !strcmp( psz_cmd, "snapshot" ) )
1662     {
1663         psz_variable = "video-snapshot";
1664     }
1665
1666     if( newval.psz_string && *newval.psz_string )
1667     {
1668         /* set */
1669         if( !strcmp( psz_variable, "zoom" ) )
1670         {
1671             vlc_value_t val;
1672             val.f_float = atof( newval.psz_string );
1673             i_error = var_Set( p_vout, psz_variable, val );
1674         }
1675         else
1676         {
1677             i_error = var_Set( p_vout, psz_variable, newval );
1678         }
1679     }
1680     else  if( !strcmp( psz_cmd, "snapshot" ) )
1681     {
1682         i_error = var_Set( p_vout, psz_variable, newval );
1683     }
1684     else
1685     {
1686         /* get */
1687         vlc_value_t val_name;
1688         vlc_value_t val, text;
1689         int i;
1690         float f_value = 0.;
1691         char *psz_value = NULL;
1692
1693         if ( var_Get( p_vout, psz_variable, &val ) < 0 )
1694         {
1695             vlc_object_release( p_vout );
1696             return VLC_EGENERIC;
1697         }
1698         if( !strcmp( psz_variable, "zoom" ) )
1699         {
1700             f_value = val.f_float;
1701         }
1702         else
1703         {
1704             psz_value = strdup( val.psz_string );
1705         }
1706
1707         if ( var_Change( p_vout, psz_variable,
1708                          VLC_VAR_GETLIST, &val, &text ) < 0 )
1709         {
1710             vlc_object_release( p_vout );
1711             return VLC_EGENERIC;
1712         }
1713
1714         /* Get the descriptive name of the variable */
1715         var_Change( p_vout, psz_variable, VLC_VAR_GETTEXT,
1716                     &val_name, NULL );
1717         if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1718
1719         msg_rc( "+----[ %s ]", val_name.psz_string );
1720         if( !strcmp( psz_variable, "zoom" ) )
1721         {
1722             for ( i = 0; i < val.p_list->i_count; i++ )
1723             {
1724                 if ( f_value == val.p_list->p_values[i].f_float )
1725                     msg_rc( "| %f - %s *", val.p_list->p_values[i].f_float,
1726                             text.p_list->p_values[i].psz_string );
1727                 else
1728                     msg_rc( "| %f - %s", val.p_list->p_values[i].f_float,
1729                             text.p_list->p_values[i].psz_string );
1730             }
1731         }
1732         else
1733         {
1734             for ( i = 0; i < val.p_list->i_count; i++ )
1735             {
1736                 if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
1737                     msg_rc( "| %s - %s *", val.p_list->p_values[i].psz_string,
1738                             text.p_list->p_values[i].psz_string );
1739                 else
1740                     msg_rc( "| %s - %s", val.p_list->p_values[i].psz_string,
1741                             text.p_list->p_values[i].psz_string );
1742             }
1743             free( psz_value );
1744         }
1745         var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
1746                     &val, &text );
1747         msg_rc( "+----[ end of %s ]", val_name.psz_string );
1748
1749         if( val_name.psz_string ) free( val_name.psz_string );
1750
1751         i_error = VLC_SUCCESS;
1752     }
1753     vlc_object_release( p_vout );
1754     return i_error;
1755 }
1756
1757 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
1758                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
1759 {
1760     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1761     input_thread_t *p_input = NULL;
1762     aout_instance_t * p_aout;
1763     const char * psz_variable;
1764     vlc_value_t val_name;
1765     int i_error;
1766
1767     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
1768     if( !p_input )
1769         return VLC_ENOOBJ;
1770
1771     if( p_input )
1772     {
1773         vlc_value_t val;
1774
1775         var_Get( p_input, "state", &val );
1776         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )        {
1777             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1778             vlc_object_release( p_input );
1779             return VLC_EGENERIC;
1780         }
1781         vlc_object_release( p_input );
1782     }
1783
1784     p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1785     if ( p_aout == NULL ) return VLC_ENOOBJ;
1786
1787     if ( !strcmp( psz_cmd, "adev" ) )
1788     {
1789         psz_variable = "audio-device";
1790     }
1791     else
1792     {
1793         psz_variable = "audio-channels";
1794     }
1795
1796     /* Get the descriptive name of the variable */
1797     var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
1798                  &val_name, NULL );
1799     if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
1800
1801     if ( !*newval.psz_string )
1802     {
1803         /* Retrieve all registered ***. */
1804         vlc_value_t val, text;
1805         int i, i_value;
1806
1807         if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
1808         {
1809             vlc_object_release( (vlc_object_t *)p_aout );
1810             return VLC_EGENERIC;
1811         }
1812         i_value = val.i_int;
1813
1814         if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
1815                          VLC_VAR_GETLIST, &val, &text ) < 0 )
1816         {
1817             vlc_object_release( (vlc_object_t *)p_aout );
1818             return VLC_EGENERIC;
1819         }
1820
1821         msg_rc( "+----[ %s ]", val_name.psz_string );
1822         for ( i = 0; i < val.p_list->i_count; i++ )
1823         {
1824             if ( i_value == val.p_list->p_values[i].i_int )
1825                 msg_rc( "| %i - %s *", val.p_list->p_values[i].i_int,
1826                         text.p_list->p_values[i].psz_string );
1827             else
1828                 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
1829                         text.p_list->p_values[i].psz_string );
1830         }
1831         var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
1832                     &val, &text );
1833         msg_rc( "+----[ end of %s ]", val_name.psz_string );
1834
1835         if( val_name.psz_string ) free( val_name.psz_string );
1836         i_error = VLC_SUCCESS;
1837     }
1838     else
1839     {
1840         vlc_value_t val;
1841         val.i_int = atoi( newval.psz_string );
1842
1843         i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
1844     }
1845     vlc_object_release( (vlc_object_t *)p_aout );
1846
1847     return i_error;
1848 }
1849
1850 /* OSD menu commands */
1851 static int Menu( vlc_object_t *p_this, char const *psz_cmd,
1852     vlc_value_t oldval, vlc_value_t newval, void *p_data )
1853 {
1854     intf_thread_t *p_intf = (intf_thread_t*)p_this;
1855     playlist_t    *p_playlist = NULL;
1856     vlc_value_t val;
1857     int i_error = VLC_EGENERIC;
1858
1859     if ( !*newval.psz_string )
1860     {
1861         msg_rc( _("Please provide one of the following parameters:") );
1862         msg_rc( "[on|off|up|down|left|right|select]" );
1863         return i_error;
1864     }
1865
1866     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1867     if( !p_playlist )
1868         return VLC_ENOOBJ;
1869
1870     if( p_playlist->p_input )
1871     {
1872         var_Get( p_playlist->p_input, "state", &val );
1873         if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
1874             ( strcmp( newval.psz_string, "select" ) != 0 ) )
1875         {
1876             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
1877             vlc_object_release( p_playlist );
1878             return VLC_EGENERIC;
1879         }
1880     }
1881     vlc_object_release( p_playlist );
1882
1883     val.psz_string = strdup( newval.psz_string );
1884     if( !strcmp( val.psz_string, "on" ) || !strcmp( val.psz_string, "show" ))
1885         osd_MenuShow( p_this );
1886     else if( !strcmp( val.psz_string, "off" ) || !strcmp( val.psz_string, "hide" ) )
1887         osd_MenuHide( p_this );
1888     else if( !strcmp( val.psz_string, "up" ) )
1889         osd_MenuUp( p_this );
1890     else if( !strcmp( val.psz_string, "down" ) )
1891         osd_MenuDown( p_this );
1892     else if( !strcmp( val.psz_string, "left" ) )
1893         osd_MenuPrev( p_this );
1894     else if( !strcmp( val.psz_string, "right" ) )
1895         osd_MenuNext( p_this );
1896     else if( !strcmp( val.psz_string, "select" ) )
1897         osd_MenuActivate( p_this );
1898     else
1899     {
1900         msg_rc( _("Please provide one of the following parameters:") );
1901         msg_rc( "[on|off|up|down|left|right|select]" );
1902         if( val.psz_string ) free( val.psz_string );
1903             return i_error;
1904     }
1905
1906     i_error = VLC_SUCCESS;
1907     if( val.psz_string ) free( val.psz_string );
1908     return i_error;
1909 }
1910
1911 #ifdef WIN32
1912 vlc_bool_t ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1913 {
1914     INPUT_RECORD input_record;
1915     DWORD i_dw;
1916
1917     /* On Win32, select() only works on socket descriptors */
1918     while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
1919                                 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
1920     {
1921         while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1922                ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
1923                                  1, &i_dw ) )
1924         {
1925             if( input_record.EventType != KEY_EVENT ||
1926                 !input_record.Event.KeyEvent.bKeyDown ||
1927                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
1928                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
1929                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
1930                 input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
1931             {
1932                 /* nothing interesting */
1933                 continue;
1934             }
1935
1936             p_buffer[ *pi_size ] = input_record.Event.KeyEvent.uChar.AsciiChar;
1937
1938             /* Echo out the command */
1939             putc( p_buffer[ *pi_size ], stdout );
1940
1941             /* Handle special keys */
1942             if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1943             {
1944                 putc( '\n', stdout );
1945                 break;
1946             }
1947             switch( p_buffer[ *pi_size ] )
1948             {
1949             case '\b':
1950                 if( *pi_size )
1951                 {
1952                     *pi_size -= 2;
1953                     putc( ' ', stdout );
1954                     putc( '\b', stdout );
1955                 }
1956                 break;
1957             case '\r':
1958                 (*pi_size) --;
1959                 break;
1960             }
1961
1962             (*pi_size)++;
1963         }
1964
1965         if( *pi_size == MAX_LINE_LENGTH ||
1966             p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1967         {
1968             p_buffer[ *pi_size ] = 0;
1969             return VLC_TRUE;
1970         }
1971     }
1972
1973     return VLC_FALSE;
1974 }
1975 #endif
1976
1977 vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
1978 {
1979     int i_read = 0;
1980
1981 #ifdef WIN32
1982     if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet )
1983         return ReadWin32( p_intf, p_buffer, pi_size );
1984     else if( p_intf->p_sys->i_socket == -1 )
1985     {
1986         msleep( INTF_IDLE_SLEEP );
1987         return VLC_FALSE;
1988     }
1989 #endif
1990
1991     while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
1992            (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
1993                        0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
1994                   (uint8_t *)p_buffer + *pi_size, 1, VLC_FALSE ) ) > 0 )
1995     {
1996         if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
1997             break;
1998
1999         (*pi_size)++;
2000     }
2001
2002     /* Connection closed */
2003     if( i_read <= 0 )
2004     {
2005         if( p_intf->p_sys->i_socket != -1 )
2006         {
2007             net_Close( p_intf->p_sys->i_socket );
2008             p_intf->p_sys->i_socket = -1;
2009         }
2010         else
2011             /* Standard input closed: exit */
2012             vlc_object_kill( p_intf );
2013
2014         p_buffer[ *pi_size ] = 0;
2015         return VLC_TRUE;
2016     }
2017
2018     if( *pi_size == MAX_LINE_LENGTH ||
2019         p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' )
2020     {
2021         p_buffer[ *pi_size ] = 0;
2022         return VLC_TRUE;
2023     }
2024
2025     return VLC_FALSE;
2026 }
2027
2028 /*****************************************************************************
2029  * parse_MRL: build a input item from a full mrl
2030  *****************************************************************************
2031  * MRL format: "simplified-mrl [:option-name[=option-value]]"
2032  * We don't check for '"' or '\'', we just assume that a ':' that follows a
2033  * space is a new option. Should be good enough for our purpose.
2034  *****************************************************************************/
2035 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
2036 {
2037 #define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
2038 #define SKIPTRAILINGSPACE( p, d ) \
2039     { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
2040
2041     input_item_t *p_item = NULL;
2042     char *psz_item = NULL, *psz_item_mrl = NULL, *psz_orig;
2043     char **ppsz_options = NULL;
2044     int i, i_options = 0;
2045
2046     if( !psz_mrl ) return 0;
2047
2048     psz_mrl = psz_orig = strdup( psz_mrl );
2049     while( *psz_mrl )
2050     {
2051         SKIPSPACE( psz_mrl );
2052         psz_item = psz_mrl;
2053
2054         for( ; *psz_mrl; psz_mrl++ )
2055         {
2056             if( (*psz_mrl == ' ' || *psz_mrl == '\t') && psz_mrl[1] == ':' )
2057             {
2058                 /* We have a complete item */
2059                 break;
2060             }
2061             if( (*psz_mrl == ' ' || *psz_mrl == '\t') &&
2062                 (psz_mrl[1] == '"' || psz_mrl[1] == '\'') && psz_mrl[2] == ':')
2063             {
2064                 /* We have a complete item */
2065                 break;
2066             }
2067         }
2068
2069         if( *psz_mrl ) { *psz_mrl = 0; psz_mrl++; }
2070         SKIPTRAILINGSPACE( psz_item, psz_item + strlen( psz_item ) );
2071
2072         /* Remove '"' and '\'' if necessary */
2073         if( *psz_item == '"' && psz_item[strlen(psz_item)-1] == '"' )
2074         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2075         if( *psz_item == '\'' && psz_item[strlen(psz_item)-1] == '\'' )
2076         { psz_item++; psz_item[strlen(psz_item)-1] = 0; }
2077
2078         if( !psz_item_mrl ) psz_item_mrl = psz_item;
2079         else if( *psz_item )
2080         {
2081             i_options++;
2082             ppsz_options = realloc( ppsz_options, i_options * sizeof(char *) );
2083             ppsz_options[i_options - 1] = &psz_item[1];
2084         }
2085
2086         if( *psz_mrl ) SKIPSPACE( psz_mrl );
2087     }
2088
2089     /* Now create a playlist item */
2090     if( psz_item_mrl )
2091     {
2092         p_item = input_ItemNew( p_intf, psz_item_mrl, NULL );
2093         for( i = 0; i < i_options; i++ )
2094         {
2095             input_ItemAddOption( p_item, ppsz_options[i] );
2096         }
2097     }
2098
2099     if( i_options ) free( ppsz_options );
2100     free( psz_orig );
2101
2102     return p_item;
2103 }
2104
2105 /*****************************************************************************
2106  * checkUpdates : check for updates
2107  ****************************************************************************/
2108 static void checkUpdates( intf_thread_t *p_intf )
2109 {
2110     update_t *p_u = update_New( p_intf );
2111     if( p_u == NULL ) return;
2112
2113     update_Check( p_u );
2114     msg_rc( "\nChecking for updates" );
2115
2116     if( update_CompareReleaseToCurrent( p_u ) == UpdateReleaseStatusNewer )
2117         msg_rc( "\n+----[ VLC %i.%i.%i%s ] ", p_u->release.i_major,
2118                                               p_u->release.i_minor,
2119                                               p_u->release.i_revision,
2120                                               p_u->release.psz_extra );
2121     else
2122         msg_rc( "\n+----Last version" );
2123     update_Delete( p_u );
2124 }