]> git.sesse.net Git - vlc/blob - modules/control/rc/rc.c
4d2530a000560ed3c51cad013ef06709de8a85c5
[vlc] / modules / control / rc / rc.c
1 /*****************************************************************************
2  * rc.c : remote control stdin/stdout plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: rc.c,v 1.37 2003/07/28 07:16:50 fenrir Exp $
6  *
7  * Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <errno.h>                                                 /* ENOMEM */
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <signal.h>
34
35 #include <vlc/vlc.h>
36 #include <vlc/intf.h>
37 #include <vlc/aout.h>
38 #include <vlc/vout.h>
39
40 #ifdef HAVE_UNISTD_H
41 #    include <unistd.h>
42 #endif
43
44 #ifdef HAVE_SYS_TIME_H
45 #    include <sys/time.h>
46 #endif
47 #include <sys/types.h>
48
49 #include "vlc_error.h"
50
51 #define MAX_LINE_LENGTH 256
52
53 /*****************************************************************************
54  * Local prototypes
55  *****************************************************************************/
56 static int  Activate     ( vlc_object_t * );
57 static void Run          ( intf_thread_t *p_intf );
58
59 static int  Input        ( vlc_object_t *, char const *,
60                            vlc_value_t, vlc_value_t, void * );
61 static int  Playlist     ( vlc_object_t *, char const *,
62                            vlc_value_t, vlc_value_t, void * );
63 static int  Quit         ( vlc_object_t *, char const *,
64                            vlc_value_t, vlc_value_t, void * );
65 static int  Intf         ( vlc_object_t *, char const *,
66                            vlc_value_t, vlc_value_t, void * );
67 static int  Volume       ( vlc_object_t *, char const *,
68                            vlc_value_t, vlc_value_t, void * );
69 static int  VolumeMove   ( vlc_object_t *, char const *,
70                            vlc_value_t, vlc_value_t, void * );
71 static int  AudioConfig  ( vlc_object_t *, char const *,
72                            vlc_value_t, vlc_value_t, void * );
73
74 /*****************************************************************************
75  * Module descriptor
76  *****************************************************************************/
77 #define POS_TEXT N_("Show stream position")
78 #define POS_LONGTEXT N_("Show the current position in seconds within the stream from time to time.")
79
80 #define TTY_TEXT N_("Fake TTY")
81 #define TTY_LONGTEXT N_("Force the rc plugin to use stdin as if it was a TTY.")
82
83 vlc_module_begin();
84     add_category_hint( N_("Remote control"), NULL, VLC_TRUE );
85     add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
86 #ifdef HAVE_ISATTY
87     add_bool( "fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT, VLC_TRUE );
88 #endif
89     set_description( _("remote control interface") );
90     set_capability( "interface", 20 );
91     set_callbacks( Activate, NULL );
92 vlc_module_end();
93
94 /*****************************************************************************
95  * Activate: initialize and create stuff
96  *****************************************************************************/
97 static int Activate( vlc_object_t *p_this )
98 {
99     intf_thread_t *p_intf = (intf_thread_t*)p_this;
100
101 #if defined(HAVE_ISATTY) && !defined(WIN32)
102     /* Check that stdin is a TTY */
103     if( !config_GetInt( p_intf, "fake-tty" ) && !isatty( 0 ) )
104     {
105         msg_Warn( p_intf, "fd 0 is not a TTY" );
106         return VLC_EGENERIC;
107     }
108 #endif
109
110     /* Non-buffered stdout */
111     setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
112
113     p_intf->pf_run = Run;
114
115     CONSOLE_INTRO_MSG;
116
117     printf( "remote control interface initialized, `h' for help\n" );
118     return VLC_SUCCESS;
119 }
120
121 /*****************************************************************************
122  * Run: rc thread
123  *****************************************************************************
124  * This part of the interface is in a separate thread so that we can call
125  * exec() from within it without annoying the rest of the program.
126  *****************************************************************************/
127 static void Run( intf_thread_t *p_intf )
128 {
129     input_thread_t * p_input;
130     playlist_t *     p_playlist;
131
132     char       p_buffer[ MAX_LINE_LENGTH + 1 ];
133     vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
134     input_info_category_t * p_category;
135     input_info_t * p_info;
136
137     int        i_dummy;
138     off_t      i_oldpos = 0;
139     off_t      i_newpos;
140
141     double     f_ratio = 1.0;
142
143 #ifdef WIN32
144     HANDLE hConsoleIn;
145     INPUT_RECORD input_record;
146     DWORD i_dummy2;
147 #endif
148
149     p_input = NULL;
150     p_playlist = NULL;
151
152     /* Register commands that will be cleaned up upon object destruction */
153     var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
154     var_AddCallback( p_intf, "quit", Quit, NULL );
155     var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
156     var_AddCallback( p_intf, "intf", Intf, NULL );
157
158     var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
159     var_AddCallback( p_intf, "add", Playlist, NULL );
160     var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
161     var_AddCallback( p_intf, "playlist", Playlist, NULL );
162     var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
163     var_AddCallback( p_intf, "play", Playlist, NULL );
164     var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
165     var_AddCallback( p_intf, "stop", Playlist, NULL );
166     var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
167     var_AddCallback( p_intf, "prev", Playlist, NULL );
168     var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
169     var_AddCallback( p_intf, "next", Playlist, NULL );
170
171     var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
172     var_AddCallback( p_intf, "pause", Input, NULL );
173     var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
174     var_AddCallback( p_intf, "seek", Input, NULL );
175     var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
176     var_AddCallback( p_intf, "title", Input, NULL );
177     var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
178     var_AddCallback( p_intf, "title_n", Input, NULL );
179     var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
180     var_AddCallback( p_intf, "title_p", Input, NULL );
181     var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
182     var_AddCallback( p_intf, "chapter", Input, NULL );
183     var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
184     var_AddCallback( p_intf, "chapter_n", Input, NULL );
185     var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
186     var_AddCallback( p_intf, "chapter_p", Input, NULL );
187
188     var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
189     var_AddCallback( p_intf, "volume", Volume, NULL );
190     var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
191     var_AddCallback( p_intf, "volup", VolumeMove, NULL );
192     var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
193     var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
194     var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
195     var_AddCallback( p_intf, "adev", AudioConfig, NULL );
196     var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
197     var_AddCallback( p_intf, "achan", AudioConfig, NULL );
198
199 #ifdef WIN32
200     /* Get the file descriptor of the console input */
201     hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
202     if( hConsoleIn == INVALID_HANDLE_VALUE )
203     {
204         msg_Err( p_intf, "Couldn't open STD_INPUT_HANDLE" ); 
205         p_intf->b_die = VLC_TRUE;
206     }
207 #endif
208
209     while( !p_intf->b_die )
210     {
211         vlc_bool_t     b_complete = VLC_FALSE;
212
213 #ifndef WIN32
214         fd_set         fds;
215         struct timeval tv;
216
217         /* Check stdin */
218         tv.tv_sec = 0;
219         tv.tv_usec = (long)INTF_IDLE_SLEEP;
220         FD_ZERO( &fds );
221         FD_SET( STDIN_FILENO, &fds );
222
223         i_dummy = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
224 #else
225         /* On Win32, select() only works on socket descriptors */
226         i_dummy = ( WaitForSingleObject( hConsoleIn, INTF_IDLE_SLEEP/1000 )
227                     == WAIT_OBJECT_0 );
228 #endif
229         if( i_dummy > 0 )
230         {
231             int i_size = 0;
232
233             while( !p_intf->b_die
234                     && i_size < MAX_LINE_LENGTH
235 #ifndef WIN32
236                     && read( STDIN_FILENO, p_buffer + i_size, 1 ) > 0
237 #else
238                     && ReadConsoleInput( hConsoleIn, &input_record, 1,
239                                          &i_dummy2 )
240 #endif
241                    )
242             {
243 #ifdef WIN32
244                 if( input_record.EventType != KEY_EVENT ||
245                     !input_record.Event.KeyEvent.bKeyDown ||
246                     input_record.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
247                     input_record.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL||
248                     input_record.Event.KeyEvent.wVirtualKeyCode == VK_MENU ||
249                     input_record.Event.KeyEvent.wVirtualKeyCode == VK_CAPITAL )
250                 {
251                     /* nothing interesting */
252                     continue;
253                 }
254
255                 p_buffer[ i_size ] =
256                     input_record.Event.KeyEvent.uChar.AsciiChar;
257
258                 /* Echo out the command */
259                 putc( p_buffer[ i_size ], stdout );
260
261                 /* Handle special keys */
262                 if( p_buffer[ i_size ] == '\r' || p_buffer[ i_size ] == '\n' )
263                 {
264                     putc( '\n', stdout );
265                     break;
266                 }
267                 switch( p_buffer[ i_size ] )
268                 {
269                 case '\b':
270                     if( i_size )
271                     {
272                         i_size -= 2;
273                         putc( ' ', stdout );
274                         putc( '\b', stdout );
275                     }
276                     break;
277                 case '\r':
278                     i_size --;
279                     break;
280                 }
281
282                 i_size++;
283 #else
284
285                 if( p_buffer[ i_size ] == '\r' || p_buffer[ i_size ] == '\n' )
286                 {
287                     break;
288                 }
289
290                 i_size++;
291 #endif
292             }
293
294             if( i_size == MAX_LINE_LENGTH
295                  || p_buffer[ i_size ] == '\r'
296                  || p_buffer[ i_size ] == '\n' )
297             {
298                 p_buffer[ i_size ] = 0;
299                 b_complete = VLC_TRUE;
300             }
301         }
302
303         /* Manage the input part */
304         if( p_input == NULL )
305         {
306             if( p_playlist )
307             {
308                 p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
309                                                        FIND_CHILD );
310             }
311             else
312             {
313                 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
314                                                    FIND_ANYWHERE );
315                 if( p_input )
316                 {
317                     p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
318                                                            FIND_PARENT );
319                 }
320             }
321         }
322         else if( p_input->b_dead )
323         {
324             vlc_object_release( p_input );
325             p_input = NULL;
326         }
327
328         if( p_input && b_showpos )
329         {
330             /* Get position */
331             vlc_mutex_lock( &p_input->stream.stream_lock );
332             if( !p_input->b_die && p_input->stream.i_mux_rate )
333             {
334 #define A p_input->stream.p_selected_area
335                 f_ratio = 1.0 / ( 50 * p_input->stream.i_mux_rate );
336                 i_newpos = A->i_tell * f_ratio;
337
338                 if( i_oldpos != i_newpos )
339                 {
340                     i_oldpos = i_newpos;
341                     printf( "pos: %li s / %li s\n", (long int)i_newpos,
342                             (long int)(f_ratio * A->i_size) );
343                 }
344 #undef S
345             }
346             vlc_mutex_unlock( &p_input->stream.stream_lock );
347         }
348
349         /* Is there something to do? */
350         if( b_complete )
351         {
352             char *psz_cmd, *psz_arg;
353
354             /* Skip heading spaces */
355             psz_cmd = p_buffer;
356             while( *psz_cmd == ' ' )
357             {
358                 psz_cmd++;
359             }
360
361             /* Split psz_cmd at the first space and make sure that
362              * psz_arg is valid */
363             psz_arg = strchr( psz_cmd, ' ' );
364             if( psz_arg )
365             {
366                 *psz_arg++ = 0;
367                 while( *psz_arg == ' ' )
368                 {
369                     psz_arg++;
370                 }
371             }
372             else
373             {
374                 psz_arg = "";
375             }
376
377             /* If the user typed a registered local command, try it */
378             if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
379             {
380                 vlc_value_t val;
381                 int i_ret;
382
383                 val.psz_string = psz_arg;
384                 i_ret = var_Set( p_intf, psz_cmd, val );
385                 printf( "%s: returned %i (%s)\n",
386                         psz_cmd, i_ret, vlc_error( i_ret ) );
387             }
388             /* Or maybe it's a global command */
389             else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
390             {
391                 vlc_value_t val;
392                 int i_ret;
393
394                 val.psz_string = psz_arg;
395                 /* FIXME: it's a global command, but we should pass the
396                  * local object as an argument, not p_intf->p_libvlc. */
397                 i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
398                 printf( "%s: returned %i (%s)\n",
399                         psz_cmd, i_ret, vlc_error( i_ret ) );
400             }
401             else if( !strcmp( psz_cmd, "info" ) )
402             {
403                 if ( p_input )
404                 {
405                     vlc_mutex_lock( &p_input->stream.stream_lock );
406                     p_category = p_input->stream.p_info;
407                     while ( p_category )
408                     {
409                         printf( "+----[ %s ]\n", p_category->psz_name );
410                         printf( "| \n" );
411                         p_info = p_category->p_info;
412                         while ( p_info )
413                         {
414                             printf( "| %s: %s\n", p_info->psz_name,
415                                     p_info->psz_value );
416                             p_info = p_info->p_next;
417                         }
418                         p_category = p_category->p_next;
419                         printf( "| \n" );
420                     }
421                     printf( "+----[ end of stream info ]\n" );
422                     vlc_mutex_unlock( &p_input->stream.stream_lock );
423                 }
424                 else
425                 {
426                     printf( "no input\n" );
427                 }
428             }
429             else switch( psz_cmd[0] )
430             {
431             case 'f':
432             case 'F':
433                 if( p_input )
434                 {
435                     vout_thread_t *p_vout;
436                     p_vout = vlc_object_find( p_input,
437                                               VLC_OBJECT_VOUT, FIND_CHILD );
438
439                     if( p_vout )
440                     {
441                         p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
442                         vlc_object_release( p_vout );
443                     }
444                 }
445                 break;
446
447             case 's':
448             case 'S':
449                 ;
450                 break;
451
452             case '?':
453             case 'h':
454             case 'H':
455                 printf("+----[ remote control commands ]\n");
456                 printf("| \n");
457                 printf("| add XYZ  . . . . . . . . . . add XYZ to playlist\n");
458                 printf("| playlist . . .  show items currently in playlist\n");
459                 printf("| play . . . . . . . . . . . . . . . . play stream\n");
460                 printf("| stop . . . . . . . . . . . . . . . . stop stream\n");
461                 printf("| next . . . . . . . . . . . .  next playlist item\n");
462                 printf("| prev . . . . . . . . . .  previous playlist item\n");
463                 printf("| title [X]  . . . . set/get title in current item\n");
464                 printf("| title_n  . . . . . .  next title in current item\n");
465                 printf("| title_p  . . . .  previous title in current item\n");
466                 printf("| chapter [X]  . . set/get chapter in current item\n");
467                 printf("| chapter_n  . . . .  next chapter in current item\n");
468                 printf("| chapter_p  . .  previous chapter in current item\n");
469                 printf("| \n");
470                 printf("| seek X . seek in seconds, for instance `seek 12'\n");
471                 printf("| pause  . . . . . . . . . . . . . .  toggle pause\n");
472                 printf("| f  . . . . . . . . . . . . . . toggle fullscreen\n");
473                 printf("| info . . .  information about the current stream\n");
474                 printf("| \n");
475                 printf("| volume [X] . . . . . . . .  set/get audio volume\n");
476                 printf("| volup [X]  . . . . .  raise audio volume X steps\n");
477                 printf("| voldown [X]  . . . .  lower audio volume X steps\n");
478                 printf("| adev [X] . . . . . . . . .  set/get audio device\n");
479                 printf("| achan [X]. . . . . . . .  set/get audio channels\n");
480                 printf("| \n");
481                 printf("| help . . . . . . . . . . . . . this help message\n");
482                 printf("| quit . . . . . . . . . . . . . . . . .  quit vlc\n");
483                 printf("| \n");
484                 printf("+----[ end of help ]\n");
485                 break;
486             case '\0':
487                 /* Ignore empty lines */
488                 break;
489             default:
490                 printf( "unknown command `%s', type `help' for help\n", psz_cmd );
491                 break;
492             }
493         }
494     }
495
496     if( p_input )
497     {
498         vlc_object_release( p_input );
499         p_input = NULL;
500     }
501
502     if( p_playlist )
503     {
504         vlc_object_release( p_playlist );
505         p_playlist = NULL;
506     }
507 }
508
509 static int Input( vlc_object_t *p_this, char const *psz_cmd,
510                   vlc_value_t oldval, vlc_value_t newval, void *p_data )
511 {
512     input_thread_t * p_input;
513
514     p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );
515
516     if( !p_input )
517     {
518         return VLC_ENOOBJ;
519     }
520
521     /* Parse commands that only require an input */
522     if( !strcmp( psz_cmd, "pause" ) )
523     {
524         input_SetStatus( p_input, INPUT_STATUS_PAUSE );
525         vlc_object_release( p_input );
526         return VLC_SUCCESS;
527     }
528     else if( !strcmp( psz_cmd, "seek" ) )
529     {
530         if( strlen( newval.psz_string ) > 0 &&
531             newval.psz_string[strlen( newval.psz_string ) - 1] == '%' )
532         {
533             input_Seek( p_input, atoi( newval.psz_string ),
534                         INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
535         }
536         else
537         {
538             input_Seek( p_input, atoi( newval.psz_string ),
539                         INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
540         }
541         vlc_object_release( p_input );
542         return VLC_SUCCESS;
543     }
544     else if( !strcmp( psz_cmd, "chapter" ) ||
545              !strcmp( psz_cmd, "chapter_n" ) ||
546              !strcmp( psz_cmd, "chapter_p" ) )
547     {
548         unsigned int i_chapter = 0;
549
550         if( !strcmp( psz_cmd, "chapter" ) )
551         {
552             if ( *newval.psz_string )
553             {
554                 /* Set. */
555                 i_chapter = atoi( newval.psz_string );
556             }
557             else
558             {
559                 /* Get. */
560                 vlc_mutex_lock( &p_input->stream.stream_lock );
561                 printf( "Currently playing chapter %d/%d\n",
562                         p_input->stream.p_selected_area->i_part,
563                         p_input->stream.p_selected_area->i_part_nb - 1 );
564                 vlc_mutex_unlock( &p_input->stream.stream_lock );
565
566                 vlc_object_release( p_input );
567                 return VLC_SUCCESS;
568             }
569         }
570         else if( !strcmp( psz_cmd, "chapter_n" ) )
571         {
572             vlc_mutex_lock( &p_input->stream.stream_lock );
573             i_chapter = p_input->stream.p_selected_area->i_part + 1;
574             vlc_mutex_unlock( &p_input->stream.stream_lock );
575         }
576         else if( !strcmp( psz_cmd, "chapter_p" ) )
577         {
578             vlc_mutex_lock( &p_input->stream.stream_lock );
579             i_chapter = p_input->stream.p_selected_area->i_part - 1;
580             vlc_mutex_unlock( &p_input->stream.stream_lock );
581         }
582
583         vlc_mutex_lock( &p_input->stream.stream_lock );
584         if( ( i_chapter > 0 ) && ( i_chapter <
585             p_input->stream.p_selected_area->i_part_nb ) )
586         {
587             input_area_t *p_area = p_input->stream.p_selected_area;
588             p_input->stream.p_selected_area->i_part = i_chapter;
589             vlc_mutex_unlock( &p_input->stream.stream_lock );
590             input_ChangeArea( p_input, p_area );
591             input_SetStatus( p_input, INPUT_STATUS_PLAY );
592             vlc_mutex_lock( &p_input->stream.stream_lock );
593         }
594         vlc_mutex_unlock( &p_input->stream.stream_lock );
595
596         vlc_object_release( p_input );
597         return VLC_SUCCESS;
598     }
599     else if( !strcmp( psz_cmd, "title" ) ||
600              !strcmp( psz_cmd, "title_n" ) ||
601              !strcmp( psz_cmd, "title_p" ) )
602     {
603         unsigned int i_title = 0;
604
605         if( !strcmp( psz_cmd, "title" ) )
606         {
607             if ( *newval.psz_string )
608             {
609                 /* Set. */
610                 i_title = atoi( newval.psz_string );
611             }
612             else
613             {
614                 /* Get. */
615                 vlc_mutex_lock( &p_input->stream.stream_lock );
616                 printf( "Currently playing title %d/%d\n",
617                         p_input->stream.p_selected_area->i_id,
618                         p_input->stream.i_area_nb - 1 );
619                 vlc_mutex_unlock( &p_input->stream.stream_lock );
620
621                 vlc_object_release( p_input );
622                 return VLC_SUCCESS;
623             }
624         }
625         else if( !strcmp( psz_cmd, "title_n" ) )
626         {
627             vlc_mutex_lock( &p_input->stream.stream_lock );
628             i_title = p_input->stream.p_selected_area->i_id + 1;
629             vlc_mutex_unlock( &p_input->stream.stream_lock );
630         }
631         else if( !strcmp( psz_cmd, "title_p" ) )
632         {
633             vlc_mutex_lock( &p_input->stream.stream_lock );
634             i_title = p_input->stream.p_selected_area->i_id - 1;
635             vlc_mutex_unlock( &p_input->stream.stream_lock );
636         }
637
638         vlc_mutex_lock( &p_input->stream.stream_lock );
639         if( ( i_title > 0 ) && ( i_title < p_input->stream.i_area_nb ) )
640         {
641             input_area_t *p_area = p_input->stream.pp_areas[i_title];
642             vlc_mutex_unlock( &p_input->stream.stream_lock );
643             input_ChangeArea( p_input, p_area );
644             input_SetStatus( p_input, INPUT_STATUS_PLAY );
645             vlc_mutex_lock( &p_input->stream.stream_lock );
646         }
647         vlc_mutex_unlock( &p_input->stream.stream_lock );
648
649         vlc_object_release( p_input );
650         return VLC_SUCCESS;
651     }
652
653     /* Never reached. */
654     return VLC_EGENERIC;
655 }
656
657 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
658                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
659 {
660     playlist_t *     p_playlist;
661
662     p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
663                                            FIND_ANYWHERE );
664     if( !p_playlist )
665     {
666         return VLC_ENOOBJ;
667     }
668
669     /* Parse commands that require a playlist */
670     if( !strcmp( psz_cmd, "prev" ) )
671     {
672         playlist_Prev( p_playlist );
673     }
674     else if( !strcmp( psz_cmd, "next" ) )
675     {
676         playlist_Next( p_playlist );
677     }
678     else if( !strcmp( psz_cmd, "play" ) )
679     {
680         playlist_Play( p_playlist );
681     }
682     else if( !strcmp( psz_cmd, "stop" ) )
683     {
684         playlist_Stop( p_playlist );
685     }
686     else if( !strcmp( psz_cmd, "add" ) )
687     {
688         printf( "trying to add %s to playlist\n", newval.psz_string );
689         playlist_Add( p_playlist, newval.psz_string, NULL, 0,
690                       PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
691     }
692     else if( !strcmp( psz_cmd, "playlist" ) )
693     {
694         int i;
695         for ( i = 0; i < p_playlist->i_size; i++ )
696         {
697             printf( "|%s%s   %s|\n", i == p_playlist->i_index?"*":" ",
698                     p_playlist->pp_items[i]->psz_name,
699                     p_playlist->pp_items[i]->psz_uri );
700         }
701         if ( i == 0 )
702         {
703             printf( "| no entries\n" );
704         }
705     }
706     /*
707      * sanity check
708      */
709     else
710     {
711         printf( "unknown command!\n" );
712     }
713
714     vlc_object_release( p_playlist );
715     return VLC_SUCCESS;
716 }
717
718 static int Quit( vlc_object_t *p_this, char const *psz_cmd,
719                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
720 {
721     p_this->p_vlc->b_die = VLC_TRUE;
722     return VLC_SUCCESS;
723 }
724
725 static int Intf( vlc_object_t *p_this, char const *psz_cmd,
726                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
727 {
728     intf_thread_t *p_newintf;
729
730     p_newintf = intf_Create( p_this->p_vlc, newval.psz_string );
731
732     if( p_newintf )
733     {
734         p_newintf->b_block = VLC_FALSE;
735         if( intf_RunThread( p_newintf ) )
736         {
737             vlc_object_detach( p_newintf );
738             intf_Destroy( p_newintf );
739         }
740     }
741
742     return VLC_SUCCESS;
743 }
744
745 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
746                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
747 {
748     int i_error;
749
750     if ( *newval.psz_string )
751     {
752         /* Set. */
753         audio_volume_t i_volume = atoi( newval.psz_string );
754         if ( i_volume > AOUT_VOLUME_MAX )
755         {
756             printf( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
757                     AOUT_VOLUME_MAX );
758             i_error = VLC_EBADVAR;
759         }
760         else i_error = aout_VolumeSet( p_this, i_volume );
761     }
762     else
763     {
764         /* Get. */
765         audio_volume_t i_volume;
766         if ( aout_VolumeGet( p_this, &i_volume ) < 0 )
767         {
768             i_error = VLC_EGENERIC;
769         }
770         else
771         {
772             printf( "Volume is %d\n", i_volume );
773             i_error = VLC_SUCCESS;
774         }
775     }
776
777     return i_error;
778 }
779
780 static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
781                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
782 {
783     audio_volume_t i_volume;
784     int i_nb_steps = atoi(newval.psz_string);
785     int i_error = VLC_SUCCESS;
786
787     if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
788     {
789         i_nb_steps = 1;
790     }
791
792     if ( !strcmp(psz_cmd, "volup") )
793     {
794         if ( aout_VolumeUp( p_this, i_nb_steps, &i_volume ) < 0 )
795             i_error = VLC_EGENERIC;
796     }
797     else
798     {
799         if ( aout_VolumeDown( p_this, i_nb_steps, &i_volume ) < 0 )
800             i_error = VLC_EGENERIC;
801     }
802
803     if ( !i_error ) printf( "Volume is %d\n", i_volume );
804     return i_error;
805 }
806
807 static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
808                         vlc_value_t oldval, vlc_value_t newval, void *p_data )
809 {
810     aout_instance_t * p_aout;
811     const char * psz_variable;
812     vlc_value_t val_name;
813     int i_error;
814
815     p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
816     if ( p_aout == NULL ) return VLC_ENOOBJ;
817
818     if ( !strcmp( psz_cmd, "adev" ) )
819     {
820         psz_variable = "audio-device";
821     }
822     else
823     {
824         psz_variable = "audio-channels";
825     }
826
827     /* Get the descriptive name of the variable */
828     var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_GETTEXT,
829                  &val_name, NULL );
830     if( !val_name.psz_string ) val_name.psz_string = strdup(psz_variable);
831
832     if ( !*newval.psz_string )
833     {
834         /* Retrieve all registered ***. */
835         vlc_value_t val, text;
836         int i, i_value;
837
838         if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
839         {
840             vlc_object_release( (vlc_object_t *)p_aout );
841             return VLC_EGENERIC;
842         }
843         i_value = val.i_int;
844
845         if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
846                          VLC_VAR_GETLIST, &val, &text ) < 0 )
847         {
848             vlc_object_release( (vlc_object_t *)p_aout );
849             return VLC_EGENERIC;
850         }
851
852         printf( "+----[ %s ]\n", val_name.psz_string );
853         for ( i = 0; i < val.p_list->i_count; i++ )
854         {
855             if ( i_value == val.p_list->p_values[i].i_int )
856                 printf( "| %i - %s *\n", val.p_list->p_values[i].i_int,
857                         text.p_list->p_values[i].psz_string );
858             else
859                 printf( "| %i - %s\n", val.p_list->p_values[i].i_int,
860                         text.p_list->p_values[i].psz_string );
861         }
862         var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
863                     &val, &text );
864         printf( "+----[ end of %s ]\n", val_name.psz_string );
865
866         if( val_name.psz_string ) free( val_name.psz_string );
867         i_error = VLC_SUCCESS;
868     }
869     else
870     {
871         vlc_value_t val;
872         val.i_int = atoi( newval.psz_string );
873
874         i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
875     }
876     vlc_object_release( (vlc_object_t *)p_aout );
877
878     return i_error;
879 }