rc.c 27.9 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * rc.c : remote control stdin/stdout plugin for vlc
 *****************************************************************************
 * Copyright (C) 2001 VideoLAN
gbazin's avatar
   
gbazin committed
5
 * $Id: rc.c,v 1.23 2003/01/23 10:25:40 gbazin Exp $
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 *
 * Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>

#include <errno.h>                                                 /* ENOMEM */
#include <stdio.h>
#include <ctype.h>
33
#include <signal.h>
34
35
36

#include <vlc/vlc.h>
#include <vlc/intf.h>
37
#include <vlc/aout.h>
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <vlc/vout.h>

#ifdef HAVE_UNISTD_H
#    include <unistd.h>
#endif

#ifdef HAVE_SYS_TIME_H
#    include <sys/time.h>
#endif
#include <sys/types.h>

#if defined( WIN32 )
#include <winsock2.h>                                            /* select() */
#endif

53
54
#include "error.h"

55
56
57
58
59
60
61
62
#define MAX_LINE_LENGTH 256

/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
static int  Activate     ( vlc_object_t * );
static void Run          ( intf_thread_t *p_intf );

63
64
static int  Input        ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
gbazin's avatar
   
gbazin committed
65
66
67
68
69
70
71
72
73
74
75
76
static int  Playlist     ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
static int  Quit         ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
static int  Intf         ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
static int  Volume       ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
static int  VolumeMove   ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
static int  AudioConfig  ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );
77

78
79
80
/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
81
82
83
#define POS_TEXT N_("show stream position")
#define POS_LONGTEXT N_("Show the current position in seconds within the stream from time to time.")

84
85
86
#define TTY_TEXT N_("fake TTY")
#define TTY_LONGTEXT N_("Force the rc plugin to use stdin as if it was a TTY.")

87
vlc_module_begin();
88
89
    add_category_hint( N_("Remote control"), NULL );
    add_bool( "rc-show-pos", 0, NULL, POS_TEXT, POS_LONGTEXT );
Sam Hocevar's avatar
Sam Hocevar committed
90
#ifdef HAVE_ISATTY
91
    add_bool( "fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT );
Sam Hocevar's avatar
Sam Hocevar committed
92
#endif
93
94
95
96
97
98
99
100
101
102
103
104
    set_description( _("remote control interface module") );
    set_capability( "interface", 20 );
    set_callbacks( Activate, NULL );
vlc_module_end();

/*****************************************************************************
 * Activate: initialize and create stuff
 *****************************************************************************/
static int Activate( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t*)p_this;

gbazin's avatar
   
gbazin committed
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
113
114
115
116
117
118
    }
#endif

    /* Non-buffered stdout */
    setvbuf( stdout, (char *)NULL, _IOLBF, 0 );

    p_intf->pf_run = Run;

gbazin's avatar
   
gbazin committed
119
    CONSOLE_INTRO_MSG;
120
121

    printf( "remote control interface initialized, `h' for help\n" );
122
    return VLC_SUCCESS;
123
124
125
126
127
128
129
130
131
132
133
}

/*****************************************************************************
 * Run: rc thread
 *****************************************************************************
 * This part of the interface is in a separate thread so that we can call
 * exec() from within it without annoying the rest of the program.
 *****************************************************************************/
static void Run( intf_thread_t *p_intf )
{
    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
139
140
141
142
143
144
    input_info_category_t * p_category;
    input_info_t * p_info;

    int        i_dummy;
    off_t      i_oldpos = 0;
    off_t      i_newpos;

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 */
gbazin's avatar
   
gbazin committed
151
152
153
154
155
    var_Create( p_intf, "quit", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "quit", Quit, NULL );
    var_Create( p_intf, "intf", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "intf", Intf, NULL );

156
157
158
159
    var_Create( p_intf, "add", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "add", Playlist, NULL );
    var_Create( p_intf, "playlist", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "playlist", Playlist, NULL );
gbazin's avatar
   
gbazin committed
160
161
162
163
164
165
166
167
168
    var_Create( p_intf, "play", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "play", Playlist, NULL );
    var_Create( p_intf, "stop", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "stop", Playlist, NULL );
    var_Create( p_intf, "prev", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "prev", Playlist, NULL );
    var_Create( p_intf, "next", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "next", Playlist, NULL );

169
170
171
172
    var_Create( p_intf, "pause", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "pause", Input, NULL );
    var_Create( p_intf, "seek", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "seek", Input, NULL );
gbazin's avatar
   
gbazin committed
173
    var_Create( p_intf, "title", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
174
    var_AddCallback( p_intf, "title", Input, NULL );
gbazin's avatar
   
gbazin committed
175
    var_Create( p_intf, "title_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
176
    var_AddCallback( p_intf, "title_n", Input, NULL );
gbazin's avatar
   
gbazin committed
177
    var_Create( p_intf, "title_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
178
    var_AddCallback( p_intf, "title_p", Input, NULL );
gbazin's avatar
   
gbazin committed
179
    var_Create( p_intf, "chapter", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
180
    var_AddCallback( p_intf, "chapter", Input, NULL );
gbazin's avatar
   
gbazin committed
181
    var_Create( p_intf, "chapter_n", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
182
    var_AddCallback( p_intf, "chapter_n", Input, NULL );
gbazin's avatar
   
gbazin committed
183
    var_Create( p_intf, "chapter_p", VLC_VAR_VOID | VLC_VAR_ISCOMMAND );
184
    var_AddCallback( p_intf, "chapter_p", Input, NULL );
gbazin's avatar
   
gbazin committed
185
186
187
188
189
190
191
192
193
194
195

    var_Create( p_intf, "volume", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "volume", Volume, NULL );
    var_Create( p_intf, "volup", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "volup", VolumeMove, NULL );
    var_Create( p_intf, "voldown", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "voldown", VolumeMove, NULL );
    var_Create( p_intf, "adev", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "adev", AudioConfig, NULL );
    var_Create( p_intf, "achan", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
    var_AddCallback( p_intf, "achan", AudioConfig, NULL );
196

gbazin's avatar
   
gbazin committed
197
198
199
200
201
202
203
204
205
#ifdef WIN32
    /* Get the file descriptor of the console input */
    i_dummy = _open( "CONIN$", 0 );
    if( i_dummy == -1 )
    {
        msg_Err( p_intf, "Couldn't open CONIN$" ); 
    }
#endif

206
207
    while( !p_intf->b_die )
    {
gbazin's avatar
   
gbazin committed
208
209
210
211
212
        vlc_bool_t     b_complete = VLC_FALSE;

#ifndef WIN32
        /* On Win32, select() only works on socket descriptors */

213
214
        fd_set         fds;
        struct timeval tv;
215
216
217
218
219

        /* Check stdin */
        tv.tv_sec = 0;
        tv.tv_usec = 50000;
        FD_ZERO( &fds );
gbazin's avatar
   
gbazin committed
220
        FD_SET( STDIN_FILENO, &fds );
221

gbazin's avatar
   
gbazin committed
222
        i_dummy = select( STDIN_FILENO + 1, &fds, NULL, NULL, &tv );
223
        if( i_dummy > 0 )
gbazin's avatar
   
gbazin committed
224
#endif
225
226
227
228
229
        {
            int i_size = 0;

            while( !p_intf->b_die
                    && i_size < MAX_LINE_LENGTH
gbazin's avatar
   
gbazin committed
230
231
232
#ifdef WIN32
                    && read( i_dummy, p_buffer + i_size, 1 ) > 0
#else
233
                    && read( STDIN_FILENO, p_buffer + i_size, 1 ) > 0
gbazin's avatar
   
gbazin committed
234
#endif
235
236
237
238
239
240
241
242
243
244
245
                    && p_buffer[ i_size ] != '\r'
                    && p_buffer[ i_size ] != '\n' )
            {
                i_size++;
            }

            if( i_size == MAX_LINE_LENGTH
                 || p_buffer[ i_size ] == '\r'
                 || p_buffer[ i_size ] == '\n' )
            {
                p_buffer[ i_size ] = 0;
246
                b_complete = VLC_TRUE;
247
248
249
250
251
252
            }
        }

        /* Manage the input part */
        if( p_input == NULL )
        {
253
254
255
256
257
258
259
260
261
            if( p_playlist )
            {
                p_input = vlc_object_find( p_playlist, VLC_OBJECT_INPUT,
                                                       FIND_CHILD );
            }
            else
            {
                p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
                                                   FIND_ANYWHERE );
262
                if( p_input )
263
264
265
266
267
                {
                    p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
                                                           FIND_PARENT );
                }
            }
268
269
270
271
272
273
274
        }
        else if( p_input->b_dead )
        {
            vlc_object_release( p_input );
            p_input = NULL;
        }

275
        if( p_input && b_showpos )
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
        {
            /* Get position */
            vlc_mutex_lock( &p_input->stream.stream_lock );
            if( !p_input->b_die && p_input->stream.i_mux_rate )
            {
#define A p_input->stream.p_selected_area
                f_ratio = 1.0 / ( 50 * p_input->stream.i_mux_rate );
                i_newpos = A->i_tell * f_ratio;

                if( i_oldpos != i_newpos )
                {
                    i_oldpos = i_newpos;
                    printf( "pos: %li s / %li s\n", (long int)i_newpos,
                            (long int)(f_ratio * A->i_size) );
                }
#undef S
            }
            vlc_mutex_unlock( &p_input->stream.stream_lock );
        }

        /* Is there something to do? */
297
        if( b_complete )
298
        {
299
            char *psz_cmd, *psz_arg;
300

301
302
303
            /* Skip heading spaces */
            psz_cmd = p_buffer;
            while( *psz_cmd == ' ' )
304
            {
305
                psz_cmd++;
306
            }
307
308
309
310
311

            /* Split psz_cmd at the first space and make sure that
             * psz_arg is valid */
            psz_arg = strchr( psz_cmd, ' ' );
            if( psz_arg )
312
            {
313
314
315
316
317
                *psz_arg++ = 0;
                while( *psz_arg == ' ' )
                {
                    psz_arg++;
                }
318
            }
319
            else
320
            {
321
                psz_arg = "";
Sam Hocevar's avatar
Sam Hocevar committed
322
            }
323
324

            /* If the user typed a registered local command, try it */
gbazin's avatar
   
gbazin committed
325
            if( var_Type( p_intf, psz_cmd ) & VLC_VAR_ISCOMMAND )
Sam Hocevar's avatar
Sam Hocevar committed
326
            {
327
328
329
330
                vlc_value_t val;
                int i_ret;

                val.psz_string = psz_arg;
gbazin's avatar
   
gbazin committed
331
                i_ret = var_Set( p_intf, psz_cmd, val );
332
333
                printf( "%s: returned %i (%s)\n",
                        psz_cmd, i_ret, vlc_error( i_ret ) );
334
            }
335
            /* Or maybe it's a global command */
gbazin's avatar
   
gbazin committed
336
            else if( var_Type( p_intf->p_libvlc, psz_cmd ) & VLC_VAR_ISCOMMAND )
337
            {
338
339
340
341
342
343
                vlc_value_t val;
                int i_ret;

                val.psz_string = psz_arg;
                /* FIXME: it's a global command, but we should pass the
                 * local object as an argument, not p_intf->p_libvlc. */
gbazin's avatar
   
gbazin committed
344
                i_ret = var_Set( p_intf->p_libvlc, psz_cmd, val );
345
346
                printf( "%s: returned %i (%s)\n",
                        psz_cmd, i_ret, vlc_error( i_ret ) );
347
            }
348
            else if( !strcmp( psz_cmd, "info" ) )
349
350
            {
                if ( p_input )
351
                {
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
                    vlc_mutex_lock( &p_input->stream.stream_lock );
                    p_category = p_input->stream.p_info;
                    while ( p_category )
                    {
                        printf( "+----[ %s ]\n", p_category->psz_name );
                        printf( "| \n" );
                        p_info = p_category->p_info;
                        while ( p_info )
                        {
                            printf( "| %s: %s\n", p_info->psz_name,
                                    p_info->psz_value );
                            p_info = p_info->p_next;
                        }
                        p_category = p_category->p_next;
                        printf( "| \n" );
                    }
                    printf( "+----[ end of stream info ]\n" );
                    vlc_mutex_unlock( &p_input->stream.stream_lock );
                }
                else
                {
                    printf( "no input\n" );
                }
            }
376
            else switch( psz_cmd[0] )
377
            {
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
            case 'f':
            case 'F':
                if( p_input )
                {
                    vout_thread_t *p_vout;
                    p_vout = vlc_object_find( p_input,
                                              VLC_OBJECT_VOUT, FIND_CHILD );

                    if( p_vout )
                    {
                        p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
                        vlc_object_release( p_vout );
                    }
                }
                break;

            case 's':
            case 'S':
                ;
                break;

            case '?':
            case 'h':
            case 'H':
402
403
                printf("+----[ remote control commands ]\n");
                printf("| \n");
404
405
                printf("| add XYZ  . . . . . . . . . . add XYZ to playlist\n");
                printf("| playlist . . .  show items currently in playlist\n");
406
407
408
409
                printf("| play . . . . . . . . . . . . . . . . play stream\n");
                printf("| stop . . . . . . . . . . . . . . . . stop stream\n");
                printf("| next . . . . . . . . . . . .  next playlist item\n");
                printf("| prev . . . . . . . . . .  previous playlist item\n");
gbazin's avatar
   
gbazin committed
410
411
412
413
414
415
                printf("| title [X]  . . . . set/get title in current item\n");
                printf("| title_n  . . . . . .  next title in current item\n");
                printf("| title_p  . . . .  previous title in current item\n");
                printf("| chapter [X]  . . set/get chapter in current item\n");
                printf("| chapter_n  . . . .  next chapter in current item\n");
                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
419
420
421
                printf("| pause  . . . . . . . . . . . . . .  toggle pause\n");
                printf("| f  . . . . . . . . . . . . . . toggle fullscreen\n");
                printf("| info . . .  information about the current stream\n");
                printf("| \n");
422
423
424
425
426
427
                printf("| volume [X] . . . . . . . .  set/get audio volume\n");
                printf("| volup [X]  . . . . .  raise audio volume X steps\n");
                printf("| voldown [X]  . . . .  lower audio volume X steps\n");
                printf("| adev [X] . . . . . . . . .  set/get audio device\n");
                printf("| achan [X]. . . . . . . .  set/get audio channels\n");
                printf("| \n");
428
429
430
431
                printf("| help . . . . . . . . . . . . . this help message\n");
                printf("| quit . . . . . . . . . . . . . . . . .  quit vlc\n");
                printf("| \n");
                printf("+----[ end of help ]\n");
432
433
434
435
436
                break;
            case '\0':
                /* Ignore empty lines */
                break;
            default:
437
                printf( "unknown command `%s', type `help' for help\n", psz_cmd );
438
439
440
441
442
443
444
445
446
                break;
            }
        }
    }

    if( p_input )
    {
        vlc_object_release( p_input );
        p_input = NULL;
447
    }
448

449
450
451
452
    if( p_playlist )
    {
        vlc_object_release( p_playlist );
        p_playlist = NULL;
453
    }
454
455
}

456
457
static int Input( vlc_object_t *p_this, char const *psz_cmd,
                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
{
    input_thread_t * p_input;

    p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_ANYWHERE );

    if( !p_input )
    {
        return VLC_ENOOBJ;
    }

    /* Parse commands that only require an input */
    if( !strcmp( psz_cmd, "pause" ) )
    {
        input_SetStatus( p_input, INPUT_STATUS_PAUSE );
        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }
475
476
    else if( !strcmp( psz_cmd, "seek" ) )
    {
gbazin's avatar
   
gbazin committed
477
        input_Seek( p_input, atoi( newval.psz_string ),
478
479
                    INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
    }
gbazin's avatar
   
gbazin committed
480
481
482
483
    else if( !strcmp( psz_cmd, "chapter" ) ||
             !strcmp( psz_cmd, "chapter_n" ) ||
             !strcmp( psz_cmd, "chapter_p" ) )
    {
484
        unsigned int i_chapter = 0;
gbazin's avatar
   
gbazin committed
485
486
487

        if( !strcmp( psz_cmd, "chapter" ) )
        {
gbazin's avatar
   
gbazin committed
488
            if ( *newval.psz_string )
gbazin's avatar
   
gbazin committed
489
490
            {
                /* Set. */
gbazin's avatar
   
gbazin committed
491
                i_chapter = atoi( newval.psz_string );
gbazin's avatar
   
gbazin committed
492
493
494
495
496
            }
            else
            {
                /* Get. */
                vlc_mutex_lock( &p_input->stream.stream_lock );
497
498
499
                printf( "Currently playing chapter %d/%d\n",
                        p_input->stream.p_selected_area->i_part,
                        p_input->stream.p_selected_area->i_part_nb - 1 );
gbazin's avatar
   
gbazin committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
                vlc_mutex_unlock( &p_input->stream.stream_lock );

                vlc_object_release( p_input );
                return VLC_SUCCESS;
            }
        }
        else if( !strcmp( psz_cmd, "chapter_n" ) )
        {
            vlc_mutex_lock( &p_input->stream.stream_lock );
            i_chapter = p_input->stream.p_selected_area->i_part + 1;
            vlc_mutex_unlock( &p_input->stream.stream_lock );
        }
        else if( !strcmp( psz_cmd, "chapter_p" ) )
        {
            vlc_mutex_lock( &p_input->stream.stream_lock );
            i_chapter = p_input->stream.p_selected_area->i_part - 1;
            vlc_mutex_unlock( &p_input->stream.stream_lock );
        }

        vlc_mutex_lock( &p_input->stream.stream_lock );
520
        if( ( i_chapter > 0 ) && ( i_chapter <
gbazin's avatar
   
gbazin committed
521
522
            p_input->stream.p_selected_area->i_part_nb ) )
        {
523
524
525
526
527
528
            input_area_t *p_area = p_input->stream.p_selected_area;
            p_input->stream.p_selected_area->i_part = i_chapter;
            vlc_mutex_unlock( &p_input->stream.stream_lock );
            input_ChangeArea( p_input, p_area );
            input_SetStatus( p_input, INPUT_STATUS_PLAY );
            vlc_mutex_lock( &p_input->stream.stream_lock );
gbazin's avatar
   
gbazin committed
529
530
531
532
533
534
535
536
537
538
        }
        vlc_mutex_unlock( &p_input->stream.stream_lock );

        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }
    else if( !strcmp( psz_cmd, "title" ) ||
             !strcmp( psz_cmd, "title_n" ) ||
             !strcmp( psz_cmd, "title_p" ) )
    {
539
        unsigned int i_title = 0;
gbazin's avatar
   
gbazin committed
540
541
542

        if( !strcmp( psz_cmd, "title" ) )
        {
gbazin's avatar
   
gbazin committed
543
            if ( *newval.psz_string )
gbazin's avatar
   
gbazin committed
544
545
            {
                /* Set. */
gbazin's avatar
   
gbazin committed
546
                i_title = atoi( newval.psz_string );
gbazin's avatar
   
gbazin committed
547
548
549
550
551
            }
            else
            {
                /* Get. */
                vlc_mutex_lock( &p_input->stream.stream_lock );
552
553
554
                printf( "Currently playing title %d/%d\n",
                        p_input->stream.p_selected_area->i_id,
                        p_input->stream.i_area_nb - 1 );
gbazin's avatar
   
gbazin committed
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
                vlc_mutex_unlock( &p_input->stream.stream_lock );

                vlc_object_release( p_input );
                return VLC_SUCCESS;
            }
        }
        else if( !strcmp( psz_cmd, "title_n" ) )
        {
            vlc_mutex_lock( &p_input->stream.stream_lock );
            i_title = p_input->stream.p_selected_area->i_id + 1;
            vlc_mutex_unlock( &p_input->stream.stream_lock );
        }
        else if( !strcmp( psz_cmd, "title_p" ) )
        {
            vlc_mutex_lock( &p_input->stream.stream_lock );
            i_title = p_input->stream.p_selected_area->i_id - 1;
            vlc_mutex_unlock( &p_input->stream.stream_lock );
        }

        vlc_mutex_lock( &p_input->stream.stream_lock );
575
        if( ( i_title > 0 ) && ( i_title < p_input->stream.i_area_nb ) )
gbazin's avatar
   
gbazin committed
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
581
            input_SetStatus( p_input, INPUT_STATUS_PLAY );
            vlc_mutex_lock( &p_input->stream.stream_lock );
gbazin's avatar
   
gbazin committed
582
583
584
585
586
587
588
        }
        vlc_mutex_unlock( &p_input->stream.stream_lock );

        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }

589
590
    /* Never reached. */
    return VLC_EGENERIC;
591
}
592

593
594
595
596
static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
                     vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    playlist_t *     p_playlist;
597

598
599
    p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
                                           FIND_ANYWHERE );
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
    if( !p_playlist )
    {
        return VLC_ENOOBJ;
    }

    /* Parse commands that require a playlist */
    if( !strcmp( psz_cmd, "prev" ) )
    {
        playlist_Prev( p_playlist );
    }
    else if( !strcmp( psz_cmd, "next" ) )
    {
        playlist_Next( p_playlist );
    }
    else if( !strcmp( psz_cmd, "play" ) )
    {
        playlist_Play( p_playlist );
    }
    else if( !strcmp( psz_cmd, "stop" ) )
    {
        playlist_Stop( p_playlist );
    }
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
    else if( !strcmp( psz_cmd, "add" ) )
    {
        printf( "trying to add %s to playlist\n", newval.psz_string );
        playlist_Add( p_playlist, newval.psz_string,
                      PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
    }
    else if( !strcmp( psz_cmd, "playlist" ) )
    {
        int i;
        for ( i = 0; i < p_playlist->i_size; i++ )
        {
            printf( "|%s%s   %s|\n", i == p_playlist->i_index?"*":" ",
                    p_playlist->pp_items[i]->psz_name,
                    p_playlist->pp_items[i]->psz_uri );
        }
        if ( i == 0 )
        {
Loïc Minier's avatar
Loïc Minier committed
639
            printf( "| no entries\n" );
640
641
642
643
644
645
646
647
648
        }
    }
    /*
     * sanity check
     */
    else
    {
        printf( "unknown command!\n" );
    }
649

gbazin's avatar
   
gbazin committed
650
    vlc_object_release( p_playlist );
651
652
653
    return VLC_SUCCESS;
}

gbazin's avatar
   
gbazin committed
654
655
static int Quit( vlc_object_t *p_this, char const *psz_cmd,
                 vlc_value_t oldval, vlc_value_t newval, void *p_data )
656
657
658
659
660
{
    p_this->p_vlc->b_die = VLC_TRUE;
    return VLC_SUCCESS;
}

gbazin's avatar
   
gbazin committed
661
662
static int Intf( vlc_object_t *p_this, char const *psz_cmd,
                 vlc_value_t oldval, vlc_value_t newval, void *p_data )
663
664
665
666
{
    intf_thread_t *p_newintf;
    char *psz_oldmodule = config_GetPsz( p_this->p_vlc, "intf" );

gbazin's avatar
   
gbazin committed
667
    config_PutPsz( p_this->p_vlc, "intf", newval.psz_string );
668
669
670
671
672
673
674
    p_newintf = intf_Create( p_this->p_vlc );
    config_PutPsz( p_this->p_vlc, "intf", psz_oldmodule );

    if( psz_oldmodule )
    {
        free( psz_oldmodule );
    }
Sam Hocevar's avatar
Sam Hocevar committed
675

676
677
678
679
680
681
682
683
684
685
686
    if( p_newintf )
    {
        p_newintf->b_block = VLC_FALSE;
        if( intf_RunThread( p_newintf ) )
        {
            vlc_object_detach( p_newintf );
            intf_Destroy( p_newintf );
        }
    }

    return VLC_SUCCESS;
687
688
}

gbazin's avatar
   
gbazin committed
689
690
static int Volume( vlc_object_t *p_this, char const *psz_cmd,
                   vlc_value_t oldval, vlc_value_t newval, void *p_data )
691
692
693
694
695
696
{
    aout_instance_t * p_aout;
    int i_error;
    p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
    if ( p_aout == NULL ) return VLC_ENOOBJ;

gbazin's avatar
   
gbazin committed
697
    if ( *newval.psz_string )
698
699
    {
        /* Set. */
gbazin's avatar
   
gbazin committed
700
        audio_volume_t i_volume = atoi( newval.psz_string );
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
        if ( i_volume > AOUT_VOLUME_MAX )
        {
            printf( "Volume must be in the range %d-%d\n", AOUT_VOLUME_MIN,
                    AOUT_VOLUME_MAX );
            i_error = VLC_EBADVAR;
        }
        else i_error = aout_VolumeSet( p_aout, i_volume );
    }
    else
    {
        /* Get. */
        audio_volume_t i_volume;
        if ( aout_VolumeGet( p_aout, &i_volume ) < 0 )
        {
            i_error = VLC_EGENERIC;
        }
        else
        {
            printf( "Volume is %d\n", i_volume );
            i_error = VLC_SUCCESS;
        }
    }
    vlc_object_release( (vlc_object_t *)p_aout );

    return i_error;
}

gbazin's avatar
   
gbazin committed
728
729
static int VolumeMove( vlc_object_t *p_this, char const *psz_cmd,
                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
730
731
732
{
    aout_instance_t * p_aout;
    audio_volume_t i_volume;
gbazin's avatar
   
gbazin committed
733
    int i_nb_steps = atoi(newval.psz_string);
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
    int i_error = VLC_SUCCESS;

    if ( i_nb_steps <= 0 || i_nb_steps > (AOUT_VOLUME_MAX/AOUT_VOLUME_STEP) )
    {
        i_nb_steps = 1;
    }

    p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
    if ( p_aout == NULL ) return VLC_ENOOBJ;

    if ( !strcmp(psz_cmd, "volup") )
    {
        if ( aout_VolumeUp( p_aout, i_nb_steps, &i_volume ) < 0 )
            i_error = VLC_EGENERIC;
    }
    else
    {
        if ( aout_VolumeDown( p_aout, i_nb_steps, &i_volume ) < 0 )
            i_error = VLC_EGENERIC;
    }
    vlc_object_release( (vlc_object_t *)p_aout );

    if ( !i_error ) printf( "Volume is %d\n", i_volume );
    return i_error;
}

gbazin's avatar
   
gbazin committed
760
761
static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
{
    aout_instance_t * p_aout;
    const char * psz_variable;
    const char * psz_name;
    int i_error;

    p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, FIND_ANYWHERE );
    if ( p_aout == NULL ) return VLC_ENOOBJ;

    if ( !strcmp( psz_cmd, "adev" ) )
    {
        psz_variable = "audio-device";
        psz_name = "audio devices";
    }
    else
    {
        psz_variable = "audio-channels";
        psz_name = "audio channels";
    }

gbazin's avatar
   
gbazin committed
782
    if ( !*newval.psz_string )
783
784
785
    {
        /* Retrieve all registered ***. */
        vlc_value_t val;
gbazin's avatar
   
gbazin committed
786
787
        int i;
        char * psz_value;
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804

        if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
        {
            vlc_object_release( (vlc_object_t *)p_aout );
            return VLC_EGENERIC;
        }
        psz_value = val.psz_string;

        if ( var_Change( (vlc_object_t *)p_aout, psz_variable,
                         VLC_VAR_GETLIST, &val ) < 0 )
        {
            free( psz_value );
            vlc_object_release( (vlc_object_t *)p_aout );
            return VLC_EGENERIC;
        }

        printf( "+----[ %s ]\n", psz_name );
gbazin's avatar
   
gbazin committed
805
        for ( i = 0; i < val.p_list->i_count; i++ )
806
        {
gbazin's avatar
   
gbazin committed
807
808
            if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
                printf( "| %s *\n", val.p_list->p_values[i].psz_string );
809
            else
gbazin's avatar
   
gbazin committed
810
                printf( "| %s\n", val.p_list->p_values[i].psz_string );
811
812
813
814
815
816
817
818
819
820
821
        }
        var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
                    &val );
        printf( "+----[ end of %s ]\n", psz_name );

        free( psz_value );
        i_error = VLC_SUCCESS;
    }
    else
    {
        vlc_value_t val;
gbazin's avatar
   
gbazin committed
822
        val.psz_string = newval.psz_string;
823
824
825
826
827
828
829

        i_error = var_Set( (vlc_object_t *)p_aout, psz_variable, val );
    }
    vlc_object_release( (vlc_object_t *)p_aout );

    return i_error;
}