rc.c 25.5 KB
Newer Older
1
2
3
4
/*****************************************************************************
 * rc.c : remote control stdin/stdout plugin for vlc
 *****************************************************************************
 * Copyright (C) 2001 VideoLAN
5
 * $Id: rc.c,v 1.12 2002/11/23 20:37:10 sam 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#include <vlc/vlc.h>
#include <vlc/intf.h>
#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

#define MAX_LINE_LENGTH 256

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

60
61
62
static int  Playlist     ( vlc_object_t *, char *, char * );
static int  Quit         ( vlc_object_t *, char *, char * );
static int  Intf         ( vlc_object_t *, char *, char * );
63
64
65
static int  Volume       ( vlc_object_t *, char *, char * );
static int  VolumeMove   ( vlc_object_t *, char *, char * );
static int  AudioConfig  ( vlc_object_t *, char *, char * );
66

67
68
69
/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
70
71
72
#define POS_TEXT N_("show stream position")
#define POS_LONGTEXT N_("Show the current position in seconds within the stream from time to time.")

73
74
75
#define TTY_TEXT N_("fake TTY")
#define TTY_LONGTEXT N_("Force the rc plugin to use stdin as if it was a TTY.")

76
vlc_module_begin();
77
78
    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
79
#ifdef HAVE_ISATTY
80
    add_bool( "fake-tty", 0, NULL, TTY_TEXT, TTY_LONGTEXT );
Sam Hocevar's avatar
Sam Hocevar committed
81
#endif
82
83
84
85
86
87
88
89
90
91
92
93
94
95
    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;

#ifdef HAVE_ISATTY
    /* Check that stdin is a TTY */
96
    if( !config_GetInt( p_intf, "fake-tty" ) && !isatty( 0 ) )
97
98
    {
        msg_Warn( p_intf, "fd 0 is not a TTY" );
99
        return VLC_EGENERIC;
100
101
102
103
104
105
106
107
    }
#endif

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

    p_intf->pf_run = Run;

gbazin's avatar
   
gbazin committed
108
    CONSOLE_INTRO_MSG;
109
110

    printf( "remote control interface initialized, `h' for help\n" );
111
    return VLC_SUCCESS;
112
113
114
115
116
117
118
119
120
121
122
}

/*****************************************************************************
 * 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;
123
    playlist_t *     p_playlist;
124
125

    char       p_buffer[ MAX_LINE_LENGTH + 1 ];
126
    vlc_bool_t b_showpos = config_GetInt( p_intf, "rc-show-pos" );
127
128
129
130
131
132
133
    input_info_category_t * p_category;
    input_info_t * p_info;

    int        i_dummy;
    off_t      i_oldpos = 0;
    off_t      i_newpos;

134
    double     f_ratio = 1.0;
135
136

    p_input = NULL;
137
    p_playlist = NULL;
138

139
140
141
142
143
144
145
146
147
148
149
150
    /* Register commands that will be cleaned up upon object destruction */
    var_Create( p_intf, "quit", VLC_VAR_COMMAND );
    var_Set( p_intf, "quit", (vlc_value_t)(void*)Quit );
    var_Create( p_intf, "intf", VLC_VAR_COMMAND );
    var_Set( p_intf, "intf", (vlc_value_t)(void*)Intf );

    var_Create( p_intf, "play", VLC_VAR_COMMAND );
    var_Set( p_intf, "play", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "stop", VLC_VAR_COMMAND );
    var_Set( p_intf, "stop", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "pause", VLC_VAR_COMMAND );
    var_Set( p_intf, "pause", (vlc_value_t)(void*)Playlist );
151
152
    var_Create( p_intf, "seek", VLC_VAR_COMMAND );
    var_Set( p_intf, "seek", (vlc_value_t)(void*)Playlist );
153
154
155
156
    var_Create( p_intf, "prev", VLC_VAR_COMMAND );
    var_Set( p_intf, "prev", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "next", VLC_VAR_COMMAND );
    var_Set( p_intf, "next", (vlc_value_t)(void*)Playlist );
Sam Hocevar's avatar
Sam Hocevar committed
157

gbazin's avatar
   
gbazin committed
158
159
160
161
162
163
164
165
166
167
168
169
170
    var_Create( p_intf, "title", VLC_VAR_COMMAND );
    var_Set( p_intf, "title", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "title_n", VLC_VAR_COMMAND );
    var_Set( p_intf, "title_n", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "title_p", VLC_VAR_COMMAND );
    var_Set( p_intf, "title_p", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "chapter", VLC_VAR_COMMAND );
    var_Set( p_intf, "chapter", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "chapter_n", VLC_VAR_COMMAND );
    var_Set( p_intf, "chapter_n", (vlc_value_t)(void*)Playlist );
    var_Create( p_intf, "chapter_p", VLC_VAR_COMMAND );
    var_Set( p_intf, "chapter_p", (vlc_value_t)(void*)Playlist );

171
172
173
174
175
176
177
178
179
180
181
    var_Create( p_intf, "volume", VLC_VAR_COMMAND );
    var_Set( p_intf, "volume", (vlc_value_t)(void*)Volume );
    var_Create( p_intf, "volup", VLC_VAR_COMMAND );
    var_Set( p_intf, "volup", (vlc_value_t)(void*)VolumeMove );
    var_Create( p_intf, "voldown", VLC_VAR_COMMAND );
    var_Set( p_intf, "voldown", (vlc_value_t)(void*)VolumeMove );
    var_Create( p_intf, "adev", VLC_VAR_COMMAND );
    var_Set( p_intf, "adev", (vlc_value_t)(void*)AudioConfig );
    var_Create( p_intf, "achan", VLC_VAR_COMMAND );
    var_Set( p_intf, "achan", (vlc_value_t)(void*)AudioConfig );

182
183
    while( !p_intf->b_die )
    {
184
185
186
        fd_set         fds;
        struct timeval tv;
        vlc_bool_t     b_complete = VLC_FALSE;
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

        /* Check stdin */
        tv.tv_sec = 0;
        tv.tv_usec = 50000;
        FD_ZERO( &fds );
        FD_SET( STDIN_FILENO, &fds );

        i_dummy = select( 32, &fds, NULL, NULL, &tv );
        if( i_dummy > 0 )
        {
            int i_size = 0;

            while( !p_intf->b_die
                    && i_size < MAX_LINE_LENGTH
                    && read( STDIN_FILENO, p_buffer + i_size, 1 ) > 0
                    && 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;
213
                b_complete = VLC_TRUE;
214
215
216
217
218
219
            }
        }

        /* Manage the input part */
        if( p_input == NULL )
        {
220
221
222
223
224
225
226
227
228
            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 );
229
                if( p_input )
230
231
232
233
234
                {
                    p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
                                                           FIND_PARENT );
                }
            }
235
236
237
238
239
240
241
        }
        else if( p_input->b_dead )
        {
            vlc_object_release( p_input );
            p_input = NULL;
        }

242
        if( p_input && b_showpos )
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
        {
            /* 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? */
264
        if( b_complete )
265
        {
266
            char *psz_cmd, *psz_arg;
267

268
269
270
            /* Skip heading spaces */
            psz_cmd = p_buffer;
            while( *psz_cmd == ' ' )
271
            {
272
                psz_cmd++;
273
            }
274
275
276
277
278

            /* Split psz_cmd at the first space and make sure that
             * psz_arg is valid */
            psz_arg = strchr( psz_cmd, ' ' );
            if( psz_arg )
279
            {
280
281
282
283
284
                *psz_arg++ = 0;
                while( *psz_arg == ' ' )
                {
                    psz_arg++;
                }
285
            }
286
            else
287
            {
288
                psz_arg = "";
Sam Hocevar's avatar
Sam Hocevar committed
289
            }
290
291
292

            /* If the user typed a registered local command, try it */
            if( var_Type( p_intf, psz_cmd ) == VLC_VAR_COMMAND )
Sam Hocevar's avatar
Sam Hocevar committed
293
            {
294
295
296
297
298
299
300
                vlc_value_t val;
                int i_ret;

                val.psz_string = psz_arg;
                i_ret = var_Get( p_intf, psz_cmd, &val );
                printf( "%s: returned %i (%s)\n",
                        psz_cmd, i_ret, vlc_error( i_ret ) );
301
            }
302
303
            /* Or maybe it's a global command */
            else if( var_Type( p_intf->p_libvlc, psz_cmd ) == VLC_VAR_COMMAND )
304
            {
305
306
307
308
309
310
311
312
313
                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. */
                i_ret = var_Get( p_intf->p_libvlc, psz_cmd, &val );
                printf( "%s: returned %i (%s)\n",
                        psz_cmd, i_ret, vlc_error( i_ret ) );
314
            }
315
            else if( !strcmp( psz_cmd, "info" ) )
316
317
            {
                if ( p_input )
318
                {
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
                    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" );
                }
            }
343
            else switch( psz_cmd[0] )
344
345
346
            {
            case 'a':
            case 'A':
347
                if( psz_cmd[1] == ' ' && p_playlist )
348
                {
349
                    playlist_Add( p_playlist, psz_cmd + 2,
350
                                  PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
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
376
377
                }
                break;

            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':
378
379
380
381
382
383
384
                printf("+----[ remote control commands ]\n");
                printf("| \n");
                printf("| a XYZ  . . . . . . . . . . . add XYZ to playlist\n");
                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
385
386
387
388
389
390
                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");
391
                printf("| \n");
392
                printf("| seek X . seek in seconds, for instance `seek 12'\n");
393
394
395
396
                printf("| pause  . . . . . . . . . . . . . .  toggle pause\n");
                printf("| f  . . . . . . . . . . . . . . toggle fullscreen\n");
                printf("| info . . .  information about the current stream\n");
                printf("| \n");
397
398
399
400
401
402
                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");
403
404
405
406
                printf("| help . . . . . . . . . . . . . this help message\n");
                printf("| quit . . . . . . . . . . . . . . . . .  quit vlc\n");
                printf("| \n");
                printf("+----[ end of help ]\n");
407
408
409
410
411
                break;
            case '\0':
                /* Ignore empty lines */
                break;
            default:
412
                printf( "unknown command `%s', type `help' for help\n", psz_cmd );
413
414
415
416
417
418
419
420
421
                break;
            }
        }
    }

    if( p_input )
    {
        vlc_object_release( p_input );
        p_input = NULL;
422
    }
423

424
425
426
427
    if( p_playlist )
    {
        vlc_object_release( p_playlist );
        p_playlist = NULL;
428
    }
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
}

static int Playlist( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
{
    input_thread_t * p_input;
    playlist_t *     p_playlist;

    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;
    }
450
451
452
453
454
    else if( !strcmp( psz_cmd, "seek" ) )
    {
        input_Seek( p_input, atoi( psz_arg ),
                    INPUT_SEEK_SECONDS | INPUT_SEEK_SET );
    }
gbazin's avatar
   
gbazin committed
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
    else if( !strcmp( psz_cmd, "chapter" ) ||
             !strcmp( psz_cmd, "chapter_n" ) ||
             !strcmp( psz_cmd, "chapter_p" ) )
    {
        int i_chapter = 0;

        if( !strcmp( psz_cmd, "chapter" ) )
        {
            if ( *psz_arg )
            {
                /* Set. */
                i_chapter = atoi( psz_arg );
            }
            else
            {
                /* Get. */
                vlc_mutex_lock( &p_input->stream.stream_lock );
                printf( "Currently playing chapter %d\n",
                        p_input->stream.p_selected_area->i_part );
                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 );
        if( ( i_chapter > 0 ) && ( i_chapter <=
            p_input->stream.p_selected_area->i_part_nb ) )
        {
          p_input->stream.p_selected_area->i_part = i_chapter;
          vlc_mutex_unlock( &p_input->stream.stream_lock );
          input_ChangeArea( p_input,
                            (input_area_t*)p_input->stream.p_selected_area );
          input_SetStatus( p_input, INPUT_STATUS_PLAY );
          vlc_mutex_lock( &p_input->stream.stream_lock );
        }
        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" ) )
    {
        int i_title = 0;

        if( !strcmp( psz_cmd, "title" ) )
        {
            if ( *psz_arg )
            {
                /* Set. */
                i_title = atoi( psz_arg );
            }
            else
            {
                /* Get. */
                vlc_mutex_lock( &p_input->stream.stream_lock );
                printf( "Currently playing title %d\n",
                        p_input->stream.p_selected_area->i_id );
                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 );
        if( ( i_title > 0 ) && ( i_title <=
            p_input->stream.p_selected_area->i_part_nb ) )
        {
          p_input->stream.p_selected_area->i_part = i_title;
          vlc_mutex_unlock( &p_input->stream.stream_lock );
          input_ChangeArea( p_input,
                            (input_area_t*)p_input->stream.pp_areas[i_title] );
          input_SetStatus( p_input, INPUT_STATUS_PLAY );
          vlc_mutex_lock( &p_input->stream.stream_lock );
        }
        vlc_mutex_unlock( &p_input->stream.stream_lock );

        vlc_object_release( p_input );
        return VLC_SUCCESS;
    }

564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591

    p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
                                           FIND_PARENT );
    vlc_object_release( p_input );

    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 );
    }

gbazin's avatar
   
gbazin committed
592
    vlc_object_release( p_playlist );
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
    return VLC_SUCCESS;
}

static int Quit( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
{
    p_this->p_vlc->b_die = VLC_TRUE;
    return VLC_SUCCESS;
}

static int Intf( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
{
    intf_thread_t *p_newintf;
    char *psz_oldmodule = config_GetPsz( p_this->p_vlc, "intf" );

    config_PutPsz( p_this->p_vlc, "intf", psz_arg );
    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
615

616
617
618
619
620
621
622
623
624
625
626
    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;
627
628
}

629
630
631
632
633
634
static int Signal( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
{
    raise( atoi(psz_arg) );
    return VLC_SUCCESS;
}

635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
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
728
729
730
731
732
733
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
static int Volume( vlc_object_t *p_this, char *psz_cmd, char *psz_arg )
{
    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;

    if ( *psz_arg )
    {
        /* Set. */
        audio_volume_t i_volume = atoi( psz_arg );
        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;
}

static int VolumeMove( vlc_object_t * p_this, char * psz_cmd, char * psz_arg )
{
    aout_instance_t * p_aout;
    audio_volume_t i_volume;
    int i_nb_steps = atoi(psz_arg);
    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;
}

static int AudioConfig( vlc_object_t * p_this, char * psz_cmd, char * psz_arg )
{
    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";
    }

    if ( !*psz_arg )
    {
        /* Retrieve all registered ***. */
        vlc_value_t val;
        int i, i_vals;
        vlc_value_t * p_vals;
        char * psz_value;

        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 );
        i_vals = ((vlc_value_t *)val.p_address)[0].i_int;
        p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */
        for ( i = 0; i < i_vals; i++ )
        {
            if ( !strcmp( psz_value, p_vals[i].psz_string ) )
                printf( "| %s *\n", p_vals[i].psz_string );
            else
                printf( "| %s\n", p_vals[i].psz_string );
        }
        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;
        val.psz_string = psz_arg;

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

    return i_error;
}
776