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