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