intf_ctrl.c 23.3 KB
Newer Older
1
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * intf_ctrl.c: interface commands access to control functions
 * Library of functions common to all interfaces, allowing access to various
 * structures and settings. Interfaces should only use those functions
 * to read or write informations from other threads.
 * A control function must be declared in the `local prototypes' section (it's
 * type is fixed), and copied into the control_command array. Functions should
 * be listed in alphabetical order, so when `help' is called they are also
 * displayed in this order.
 * A control function can use any function of the program, but should respect
 * two points: first, it should not block, since if it does so, the whole
 * interface thread will hang and in particular miscelannous interface events
 * won't be handled. Secondly, it should send it's output messages exclusively
 * with intf_IntfMsg() function, except particularly critical messages which
 * can use over intf_*Msg() functions.
 * Control functions should return 0 (INTF_NO_ERROR) on success, or one of the
 * error codes defined in command.h. Custom error codes are allowed, but should
 * be positive.
 * More informations about parameters stand in `list of commands' section.
20 21 22 23 24 25 26 27 28
 *****************************************************************************
 * Copyright (C) 1999, 2000 VideoLAN
 *
 * Authors:
 *
 * 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.
29
 * 
30 31
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
34
 *
35 36 37
 * 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.
38
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
39

40
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
41
 * Preamble
42
 *****************************************************************************/
43 44
#include "defs.h"

45 46 47 48 49 50 51
#include <sys/types.h>                        /* on BSD, uio.h needs types.h */
#include <sys/stat.h>                        /* on BSD, fstat() needs stat.h */
#include <sys/uio.h>                                            /* "input.h" */
#include <stdio.h>                                              /* fprintf() */
#include <stdlib.h>                                      /* malloc(), free() */
#include <unistd.h>                                       /* close(), read() */
#include <fcntl.h>                                                 /* open() */
Michel Lespinasse's avatar
Yop,  
Michel Lespinasse committed
52 53 54 55

/* Common headers */
#include "config.h"
#include "common.h"
56
#include "threads.h"
Michel Lespinasse's avatar
Yop,  
Michel Lespinasse committed
57 58
#include "mtime.h"
#include "debug.h"
59
#include "plugins.h"
Michel Lespinasse's avatar
Yop,  
Michel Lespinasse committed
60 61
#include "intf_msg.h"

62 63
#include "stream_control.h"
#include "input_ext-intf.h"
Michel Lespinasse's avatar
Yop,  
Michel Lespinasse committed
64 65 66 67
#include "audio_output.h"
#include "intf_cmd.h"
#include "interface.h"
#include "main.h"
Michel Kaempf's avatar
Michel Kaempf committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

/*
 * Local prototypes
 */
static int Demo                 ( int i_argc, intf_arg_t *p_argv );
static int DisplayImage         ( int i_argc, intf_arg_t *p_argv );
static int Exec                 ( int i_argc, intf_arg_t *p_argv );
static int Help                 ( int i_argc, intf_arg_t *p_argv );
static int PlayAudio            ( int i_argc, intf_arg_t *p_argv );
static int PlayVideo            ( int i_argc, intf_arg_t *p_argv );
static int Quit                 ( int i_argc, intf_arg_t *p_argv );
static int SelectPID            ( int i_argc, intf_arg_t *p_argv );
static int SpawnInput           ( int i_argc, intf_arg_t *p_argv );
#ifdef DEBUG
static int Test                 ( int i_argc, intf_arg_t *p_argv );
#endif
static int Vlan                 ( int i_argc, intf_arg_t *p_argv );
static int Psi                  ( int i_argc, intf_arg_t *p_argv );

/*
 * List of commands.
 * This list is used by intf_ExecCommand function to find functions to
90
 * execute and prepare its arguments. It is terminated by an element  which name
Michel Kaempf's avatar
Michel Kaempf committed
91 92 93 94 95 96 97 98
 * is a null pointer. intf_command_t is defined in command.h.
 *
 * Here is a description of a command description elements:
 *  name is the name of the function, as it should be typed on command line,
 *  function is a pointer to the control function,
 *  format is an argument descriptor (see below),
 *  summary is a text string displayed in regard of the command name when `help'
 *      is called without parameters, and whith usage on syntax error,
99
 *  usage is a short syntax indicator displayed with summary when the command
Michel Kaempf's avatar
Michel Kaempf committed
100 101 102 103
 *      causes a syntax error,
 *  help is a complete help about the command, displayed when `help' is called with
 *      the command name as parameter.
 *
104
 * Format string is a list of ' ' separated strings, which have following
Michel Kaempf's avatar
Michel Kaempf committed
105 106 107 108 109 110 111
 * meanings:
 *  s       string argument
 *  i       integer argument
 *  f       float argument
 *  ?       optionnal argument
 *  *       argument can be repeated
 *  name=   named argument
112
 * Example: "channel=i? s*? i " means that any number of string arguments,
Michel Kaempf's avatar
Michel Kaempf committed
113 114 115 116 117
 * followed by a single mandatory integer argument are waited. A named argument,
 * which name is `channel' and must have an integer value can be optionnaly
 * specified at beginning. The last space is mandatory if there is at least one
 * element, since it acts as an item terminator.
 * Named arguments MUST be at the beginning of the format string, and in
118
 * alphabetic order, but their order on command line has no importance.
Michel Kaempf's avatar
Michel Kaempf committed
119 120 121 122
 * The format string can't have more than INTF_MAX_ARGS elements.
 */
const intf_command_t control_command[] =
{
123 124 125 126
  { "demo", Demo,                                                    /* demo */
    /* format: */   "",
    /* summary: */  "program demonstration",
    /* usage: */    "demo",
Michel Kaempf's avatar
Michel Kaempf committed
127
    /* help: */     "Start program capabilities demonstration." },
128
  { "display", DisplayImage,                                      /* display */
Michel Kaempf's avatar
Michel Kaempf committed
129 130 131
    /* format: */   "s ",
    /* summary: */  "load and display an image",
    /* usage: */    "display <file>",
132
    /* help: */     "Load and display an image. Image format is automatically "\
Michel Kaempf's avatar
Michel Kaempf committed
133
    "identified from file name extension." },
134
  { "exec", Exec,                                                    /* exec */
Michel Kaempf's avatar
Michel Kaempf committed
135 136 137
    /* format: */   "s ",
    /* summary: */  "execute a script file",
    /* usage: */    "exec <file>",
138 139
    /* help: */     "Load an execute a script." },
  { "exit", Quit,                                       /* exit (quit alias) */
Michel Kaempf's avatar
Michel Kaempf committed
140 141 142 143
    /* format: */   "",
    /* summary: */  "quit program",
    /* usage: */    "exit",
    /* help: */     "see `quit'." },
144 145 146 147
  { "help", Help,                                                    /* help */
    /* format: */   "s? ",
    /* summary: */  "list all functions or print help about a specific function",
    /* usage: */    "help [command]",
Michel Kaempf's avatar
Michel Kaempf committed
148
    /* help: */     "If called without argument, list all available " \
149
    " functions.\nIf a command name is provided as argument, displays a short "\
Michel Kaempf's avatar
Michel Kaempf committed
150
    "inline help about the command.\n" },
151
  { "play-audio", PlayAudio,                                   /* play-audio */
152
    /* format: */   "channels=i? rate=i? s ",
Michel Kaempf's avatar
Michel Kaempf committed
153
    /* summary: */  "play an audio file",
154
    /* usage: */    "play-audio [channels=1/2] [rate=r] <file>",
Michel Kaempf's avatar
Michel Kaempf committed
155 156
    /* help: */     "Load and play an audio file." },
  { "play-video", PlayVideo,                                      /* play-video */
157
    /* format: */   "s ",
Michel Kaempf's avatar
Michel Kaempf committed
158 159 160
    /* summary: */  "play a video (.vlp) file",
    /* usage: */    "play-video <file>",
    /* help: */     "Load and play a video file." },
161
  { "quit", Quit,                                                    /* quit */
Michel Kaempf's avatar
Michel Kaempf committed
162 163 164
    /* format: */   "",
    /* summary: */  "quit program",
    /* usage: */    "quit",
165
    /* help: */     "Terminates the program execution... There is not much to"\
Michel Kaempf's avatar
Michel Kaempf committed
166
    " say about it !" },
167
  { "select-pid", SelectPID,                                   /* select-pid */
Michel Kaempf's avatar
Michel Kaempf committed
168 169 170 171 172
    /* format: */   "i i ",
    /* summary: */  "spawn a decoder thread for a specified PID",
    /* summary: */  "select-pid <input> <pid>",
    /* help: */     "Spawn a decoder thread for <pid>. The stream will be" \
    " received by <input>." },
173
  { "spawn-input", SpawnInput,                                /* spawn-input */
Michel Kaempf's avatar
Michel Kaempf committed
174 175 176 177 178 179 180 181
    /* format: */   "method=i? filename=s? hostname=s? ip=s? port=i? vlan=i?",
    /* summary: */  "spawn an input thread",
    /* summary: */  "spawn-input [method=<method>]\n" \
    "[filename=<file>|hostname=<hostname>|ip=<ip>]\n" \
    "[port=<port>] [vlan=<vlan>]",
    /* help: */     "Spawn an input thread. Method is 10, 20, 21, 22, 32, "\
    "hostname is the fully-qualified domain name, ip is a dotted-decimal address." },
#ifdef DEBUG
182
  { "test", Test,                                                    /* test */
Michel Kaempf's avatar
Michel Kaempf committed
183 184 185 186
    /* format: */   "i? ",
    /* summary: */  "crazy developper's test",
    /* usage: */    "depends on the last coder :-)",
    /* help: */     "`test' works only in DEBUG mode, and is provide for " \
187
    "developpers as an easy way to test part of their code. If you don't know "\
Michel Kaempf's avatar
Michel Kaempf committed
188 189 190 191 192 193 194 195
    "what it should do, just try !" },
#endif
  { "vlan", Vlan,
    /* format: */   "intf=s? s i? ",
    /* summary: */  "vlan operations",
    /* usage: */    "vlan synchro\n" \
    "vlan [intf=<interface>] request\n" \
    "vlan [intf=<interface>] join <vlan>\n" \
Michel Kaempf's avatar
Michel Kaempf committed
196
    "vlan [intf=<interface>] leave",
Michel Kaempf's avatar
Michel Kaempf committed
197
    /* help: */     "Perform various operations on vlans. 'synchro' resynchronize " \
198
    "with the server. 'request' ask which is the current vlan (for the default "\
Michel Kaempf's avatar
Michel Kaempf committed
199 200 201 202 203 204 205
    "interface or for a given one). 'join' and 'leave' try to change vlan." },
  { "psi", Psi,
    /* format: */   "i ",
    /* summary: */  "Dump PSI tables",
    /* usage: */    "psi <input thread index>",
    /* help: */     "Display the PSI tables on the console. Warning: this is debug" \
    "command, it can leads to pb since locks are not taken yet" },
206
  { 0, 0, 0, 0, 0 }                                      /* array terminator */
Michel Kaempf's avatar
Michel Kaempf committed
207 208 209 210
};

/* following functions are local */

211
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
212
 * Demo: demo
213 214 215
 *****************************************************************************
 * This function is provided to display a demo of program possibilities.
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
216 217 218 219 220 221 222
static int Demo( int i_argc, intf_arg_t *p_argv )
{
    intf_IntfMsg( COPYRIGHT_MESSAGE );

    return( INTF_NO_ERROR );
}

223
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
224
 * Exec: execute a script
225
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
226
 * This function load and execute a script.
227
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
228 229
static int Exec( int i_argc, intf_arg_t *p_argv )
{
230 231
    int i_err;                                                 /* error code */

Michel Kaempf's avatar
Michel Kaempf committed
232
    i_err = intf_ExecScript( p_argv[1].psz_str );
233
    return( i_err ? INTF_OTHER_ERROR : INTF_NO_ERROR );
Michel Kaempf's avatar
Michel Kaempf committed
234 235
}

236
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
237
 * DisplayImage: load and display an image                               (ok ?)
238
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
239 240
 * Try to load an image identified by it's filename and displays it as a still
 * image using interface video heap.
241
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
242 243
static int DisplayImage( int i_argc, intf_arg_t *p_argv )
{
244
    /* XXX?? */
Michel Kaempf's avatar
Michel Kaempf committed
245 246 247
    return( INTF_NO_ERROR );
}

248
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
249
 * Help: list all available commands                                     (ok ?)
250
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
251
 * This function print a list of available commands
252
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
253 254
static int Help( int i_argc, intf_arg_t *p_argv )
{
255
    int     i_index;                                        /* command index */
Michel Kaempf's avatar
Michel Kaempf committed
256

257
   /* If called with an argument: look for the command and display it's help */
Michel Kaempf's avatar
Michel Kaempf committed
258 259
    if( i_argc == 2 )
    {
Michel Kaempf's avatar
Michel Kaempf committed
260
fprintf( stderr, "maxx debug: coin\n" );
261
        for( i_index = 0; control_command[i_index].psz_name
Michel Kaempf's avatar
Michel Kaempf committed
262 263 264 265 266
                 && strcmp( control_command[i_index].psz_name, p_argv[1].psz_str );
             i_index++ )
        {
            ;
        }
Michel Kaempf's avatar
Michel Kaempf committed
267
fprintf( stderr, "maxx debug: meuh\n" );
Michel Kaempf's avatar
Michel Kaempf committed
268 269 270
        /* Command has been found in list */
        if( control_command[i_index].psz_name )
        {
Michel Kaempf's avatar
Michel Kaempf committed
271
fprintf( stderr, "maxx debug: meow\n" );
Michel Kaempf's avatar
Michel Kaempf committed
272
            intf_IntfMsg( control_command[i_index].psz_usage );
Michel Kaempf's avatar
Michel Kaempf committed
273
fprintf( stderr, "maxx debug: blah\n" );
Michel Kaempf's avatar
Michel Kaempf committed
274
            intf_IntfMsg( control_command[i_index].psz_help );
Michel Kaempf's avatar
Michel Kaempf committed
275
fprintf( stderr, "maxx debug: blih\n" );
Michel Kaempf's avatar
Michel Kaempf committed
276 277 278 279 280 281 282 283 284 285 286 287 288
        }
        /* Command is unknown */
        else
        {
            intf_IntfMsg("help: don't know command `%s'", p_argv[1].psz_str);
            return( INTF_OTHER_ERROR );
        }
    }
    /* If called without argument: print all commands help field */
    else
    {
        for( i_index = 0; control_command[i_index].psz_name; i_index++ )
        {
289
            intf_IntfMsg( "%s: %s",  control_command[i_index].psz_name,
Michel Kaempf's avatar
Michel Kaempf committed
290 291 292 293 294 295 296
                          control_command[i_index].psz_summary );
        }
    }

    return( INTF_NO_ERROR );
}

297
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
298
 * PlayAudio: play an audio file                                         (ok ?)
299
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
300
 * Play a raw audio file from a file, at a given rate.
301
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
302 303
static int PlayAudio( int i_argc, intf_arg_t *p_argv )
{
304 305 306 307 308
    char * psz_file = NULL;              /* name of the audio raw file (s16) */
    int i_fd;      /* file descriptor of the audio file that is to be loaded */
    aout_fifo_t fifo;         /* fifo stores the informations about the file */
    struct stat stat_buffer;      /* needed to find out the size of psz_file */
    int i_arg;                                             /* argument index */
Michel Kaempf's avatar
Michel Kaempf committed
309

Vincent Seguin's avatar
Vincent Seguin committed
310
    if ( !p_main->b_audio )                  /* audio is disabled */
Michel Kaempf's avatar
Michel Kaempf committed
311 312 313 314 315 316
    {
        intf_IntfMsg("play-audio error: audio is disabled");
        return( INTF_NO_ERROR );
    }

    /* Set default configuration */
317 318
    fifo.i_channels = 1 + ( fifo.b_stereo = AOUT_STEREO_DEFAULT );
    fifo.l_rate = AOUT_RATE_DEFAULT;
Michel Kaempf's avatar
Michel Kaempf committed
319

320
    /* The channels and rate parameters are essential ! */
Michel Kaempf's avatar
Michel Kaempf committed
321 322 323 324 325
    /* Parse parameters - see command list above */
    for ( i_arg = 1; i_arg < i_argc; i_arg++ )
    {
        switch( p_argv[i_arg].i_index )
        {
326 327
        case 0:                                                  /* channels */
            fifo.i_channels = p_argv[i_arg].i_num;
Michel Kaempf's avatar
Michel Kaempf committed
328
            break;
329
        case 1:                                                      /* rate */
Michel Kaempf's avatar
Michel Kaempf committed
330 331
            fifo.l_rate = p_argv[i_arg].i_num;
            break;
332
        case 2:                                                  /* filename */
Michel Kaempf's avatar
Michel Kaempf committed
333 334 335 336 337 338
            psz_file = p_argv[i_arg].psz_str;
            break;
        }
    }

    /* Setting up the type of the fifo */
339
    switch ( fifo.i_channels )
Michel Kaempf's avatar
Michel Kaempf committed
340
    {
341
        case 1:
Michel Kaempf's avatar
Michel Kaempf committed
342 343 344
            fifo.i_type = AOUT_INTF_MONO_FIFO;
            break;

345
        case 2:
Michel Kaempf's avatar
Michel Kaempf committed
346 347 348 349
            fifo.i_type = AOUT_INTF_STEREO_FIFO;
            break;

        default:
350
            intf_IntfMsg("play-audio error: channels must be 1 or 2");
Michel Kaempf's avatar
Michel Kaempf committed
351 352 353 354 355
            return( INTF_OTHER_ERROR );
    }

    /* Open file */
    i_fd =  open( psz_file, O_RDONLY );
356
    if ( i_fd < 0 )                                                 /* error */
Michel Kaempf's avatar
Michel Kaempf committed
357 358 359 360 361 362 363
    {
        intf_IntfMsg("play-audio error: can't open `%s'", psz_file);
        return( INTF_OTHER_ERROR );
    }

    /* Get file size to calculate number of audio units */
    fstat( i_fd, &stat_buffer );
364
    fifo.l_units = ( long )( stat_buffer.st_size / (sizeof(s16) << fifo.b_stereo) );
Michel Kaempf's avatar
Michel Kaempf committed
365 366

    /* Allocate memory, read file and close it */
367
    if ( (fifo.buffer = malloc(sizeof(s16)*(fifo.l_units << fifo.b_stereo))) == NULL ) /* !! */
Michel Kaempf's avatar
Michel Kaempf committed
368 369
    {
        intf_IntfMsg("play-audio error: not enough memory to read `%s'", psz_file );
370
        close( i_fd );                                         /* close file */
Michel Kaempf's avatar
Michel Kaempf committed
371 372
        return( INTF_OTHER_ERROR );
    }
373 374
    if ( read(i_fd, fifo.buffer, sizeof(s16)*(fifo.l_units << fifo.b_stereo))
        != sizeof(s16)*(fifo.l_units << fifo.b_stereo) )
Michel Kaempf's avatar
Michel Kaempf committed
375 376 377 378 379 380 381 382
    {
        intf_IntfMsg("play-audio error: can't read %s", psz_file);
        free( fifo.buffer );
        close( i_fd );
        return( INTF_OTHER_ERROR );
    }
    close( i_fd );

383
   /* Now we can work out how many output units we can compute with the fifo */
384
    fifo.l_units = (long)(((s64)fifo.l_units*(s64)p_main->p_aout->l_rate)/(s64)fifo.l_rate);
Michel Kaempf's avatar
Michel Kaempf committed
385 386

    /* Create the fifo */
Vincent Seguin's avatar
Vincent Seguin committed
387
    if ( aout_CreateFifo(p_main->p_aout, &fifo) == NULL )
Michel Kaempf's avatar
Michel Kaempf committed
388 389 390 391 392 393 394 395 396
    {
        intf_IntfMsg("play-audio error: can't create audio fifo");
        free( fifo.buffer );
        return( INTF_OTHER_ERROR );
    }

    return( INTF_NO_ERROR );
}

397
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
398
 * PlayVideo: play a video sequence from a file
399
 *****************************************************************************
400
 * XXX??
401
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
402 403
static int PlayVideo( int i_argc, intf_arg_t *p_argv )
{
404
    /* XXX?? */
405
    return( INTF_NO_ERROR );
Michel Kaempf's avatar
Michel Kaempf committed
406 407
}

408
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
409
 * Quit: quit program                                                    (ok ?)
410
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
411
 * This function set `die' flag of interface, asking the program to terminate.
412
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
413 414
static int Quit( int i_argc, intf_arg_t *p_argv )
{
Vincent Seguin's avatar
Vincent Seguin committed
415
    p_main->p_intf->b_die = 1;
Michel Kaempf's avatar
Michel Kaempf committed
416 417 418 419
    return( INTF_NO_ERROR );
}


420
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
421
 *
422
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
423
 *
424
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
425 426
static int SelectPID( int i_argc, intf_arg_t *p_argv )
{
Michel Kaempf's avatar
Michel Kaempf committed
427
    int i_input = -1, i_pid = -1;
Michel Kaempf's avatar
Michel Kaempf committed
428
    int i_arg;
429

Michel Kaempf's avatar
Michel Kaempf committed
430 431 432 433 434 435
    /* Parse parameters - see command list above */
    for ( i_arg = 1; i_arg < i_argc; i_arg++ )
    {
      switch( p_argv[i_arg].i_index )
      {
      case 0:
436
          /* FIXME: useless ?? */
Michel Kaempf's avatar
Michel Kaempf committed
437 438 439 440 441 442 443 444 445 446
          i_input = p_argv[i_arg].i_num;
          break;
      case 1:
         i_pid = p_argv[i_arg].i_num;
        break;
      }
    }


    /* Find to which input this command is destinated */
Vincent Seguin's avatar
Vincent Seguin committed
447
    intf_IntfMsg( "Adding PID %d to input %d\n", i_pid, i_input );
448 449
    //XXX?? input_AddPgrmElem( p_main->p_intf->p_x11->p_input,
    //XXX??                    i_pid );
Vincent Seguin's avatar
Vincent Seguin committed
450
    return( INTF_NO_ERROR );
Michel Kaempf's avatar
Michel Kaempf committed
451 452 453
}


454
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
455
 * SpawnInput: spawn an input thread                                     (ok ?)
456
 *****************************************************************************
457
 * Spawn an input thread
458
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
459 460
static int SpawnInput( int i_argc, intf_arg_t *p_argv )
{
Benoit Steiner's avatar
 
Benoit Steiner committed
461 462 463
    /* FIXME */
#if 0

Michel Kaempf's avatar
Michel Kaempf committed
464
    int                 i_arg;
465
    int                 i_method = 0;                    /* method parameter */
466
    char *              p_source = NULL;                 /* source parameter */
467
    int                 i_port = 0;                        /* port parameter */
Renaud Dartus's avatar
Renaud Dartus committed
468
    int                 i_vlan_id = 0;                  /* vlan id parameter */
Michel Kaempf's avatar
Michel Kaempf committed
469 470 471 472 473 474

    /* Parse parameters - see command list above */
    for ( i_arg = 1; i_arg < i_argc; i_arg++ )
    {
        switch( p_argv[i_arg].i_index )
        {
475
        case 0:                                                    /* method */
476
            i_method = p_argv[i_arg].i_num;
Michel Kaempf's avatar
Michel Kaempf committed
477
            break;
478
        case 1:                                    /* filename, hostname, ip */
479
        case 2:
480
        case 3:
481
            p_source = p_argv[i_arg].psz_str;
Michel Kaempf's avatar
Michel Kaempf committed
482
            break;
483
        case 4:                                                      /* port */
484
            i_port = p_argv[i_arg].i_num;
Michel Kaempf's avatar
Michel Kaempf committed
485
            break;
Renaud Dartus's avatar
Renaud Dartus committed
486 487
        case 5:                                                   /* VLAN id */
            i_vlan_id = p_argv[i_arg].i_num;
Michel Kaempf's avatar
Michel Kaempf committed
488 489 490 491
            break;
        }
    }

492
    /* Destroy current input, if any */
493
    if( p_main->p_intf->p_input != NULL )
494
    {
495
        input_DestroyThread( p_main->p_intf->p_input, NULL );
Michel Kaempf's avatar
Michel Kaempf committed
496 497
    }

Renaud Dartus's avatar
Renaud Dartus committed
498
    p_main->p_intf->p_input = input_CreateThread( i_method, p_source, i_port, i_vlan_id,
499
                                                  p_main->p_intf->p_vout, p_main->p_aout,
500
                                                  NULL );
Michel Kaempf's avatar
Michel Kaempf committed
501
    return( INTF_NO_ERROR );
502
#endif
Michel Kaempf's avatar
Michel Kaempf committed
503 504
}

505
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
506
 * Test: test function
507
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
508
 * This function is provided to test new functions in the program. Fell free
509
 * to modify !
Michel Kaempf's avatar
Michel Kaempf committed
510
 * This function is only defined in DEBUG mode.
511
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
512 513 514
#ifdef DEBUG
static int Test( int i_argc, intf_arg_t *p_argv )
{
515
    int i_thread;
Michel Kaempf's avatar
Michel Kaempf committed
516

517
/*XXX??    if( i_argc == 1 )
Michel Kaempf's avatar
Michel Kaempf committed
518
    {
Vincent Seguin's avatar
Vincent Seguin committed
519
        i_thread = intf_CreateVoutThread( &p_main->intf_thread, NULL, -1, -1);
520
        intf_IntfMsg("return value: %d", i_thread );
Michel Kaempf's avatar
Michel Kaempf committed
521
    }
Vincent Seguin's avatar
Vincent Seguin committed
522
    else*/
Michel Kaempf's avatar
Michel Kaempf committed
523
    {
524
        i_thread = p_argv[1].i_num;
525
    //XXX??    intf_DestroyVoutThread( &p_main->intf_thread, i_thread );
526
    }
Michel Kaempf's avatar
Michel Kaempf committed
527 528 529 530 531

    return( INTF_NO_ERROR );
}
#endif

532
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
533
 * Vlan: vlan operations
534
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
535
 * This function performs various vlan operations.
536
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
537 538
static int Vlan( int i_argc, intf_arg_t *p_argv  )
{
539
    int i_command;                                /* command argument number */
Michel Kaempf's avatar
Michel Kaempf committed
540

541
    /* Do not try anything if vlans are deactivated */
Vincent Seguin's avatar
Vincent Seguin committed
542
    if( !p_main->b_vlans )
Michel Kaempf's avatar
Michel Kaempf committed
543
    {
544
        intf_IntfMsg("vlans are deactivated");
Michel Kaempf's avatar
Michel Kaempf committed
545 546
        return( INTF_OTHER_ERROR );
    }
547

Michel Kaempf's avatar
Michel Kaempf committed
548 549 550 551
    /* Look for command in list of arguments - this argument is mandatory and
     * imposed by the calling function */
    for( i_command = 1; p_argv[i_command].i_index == 1; i_command++ )
    {
552
        ;
Michel Kaempf's avatar
Michel Kaempf committed
553
    }
554

Michel Kaempf's avatar
Michel Kaempf committed
555
    /* Command is 'join' */
556
    if( !strcmp(p_argv[i_command].psz_str, "join") )
Michel Kaempf's avatar
Michel Kaempf committed
557
    {
558
        /* XXX?? */
559
    }
Michel Kaempf's avatar
Michel Kaempf committed
560 561 562
    /* Command is 'leave' */
    else if( !strcmp(p_argv[i_command].psz_str, "leave") )
    {
563
        /* XXX?? */
Michel Kaempf's avatar
Michel Kaempf committed
564 565 566 567 568
    }
    /* Command is unknown */
    else
    {
        intf_IntfMsg("vlan error: unknown command %s", p_argv[i_command].psz_str );
569
        return( INTF_USAGE_ERROR );
Michel Kaempf's avatar
Michel Kaempf committed
570
    }
571

Michel Kaempf's avatar
Michel Kaempf committed
572 573 574 575
    return( INTF_NO_ERROR );
}


576
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
577
 * Psi
578 579 580
 *****************************************************************************
 * This function is provided to display PSI tables.
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
581 582 583
static int Psi( int i_argc, intf_arg_t *p_argv )
{
    int i_index = p_argv[1].i_num;
584

Vincent Seguin's avatar
Vincent Seguin committed
585
    intf_IntfMsg("Reading PSI table for input %d\n", i_index);
586
    //XXX?? input_PsiRead(p_main->p_intf->p_x11->p_input );
Vincent Seguin's avatar
Vincent Seguin committed
587
    return( INTF_NO_ERROR );
Michel Kaempf's avatar
Michel Kaempf committed
588
}