input.c 40.3 KB
Newer Older
1 2
/*****************************************************************************
 * input.c: input thread
Michel Kaempf's avatar
Michel Kaempf committed
3 4
 * Read an MPEG2 stream, demultiplex and parse it before sending it to
 * decoders.
5
 *****************************************************************************
6
 * Copyright (C) 1998-2002 VideoLAN
Laurent Aimar's avatar
Laurent Aimar committed
7
 * $Id: input.c,v 1.241 2003/09/15 18:05:13 fenrir Exp $
8
 *
9
 * Authors: Christophe Massiot <massiot@via.ecp.fr>
10 11 12 13 14
 *
 * 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.
15
 *
16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
20
 *
21 22 23
 * 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.
24
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
25

26
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
27
 * Preamble
28
 *****************************************************************************/
29
#include <stdlib.h>
30

31
#include <vlc/vlc.h>
32 33
#include <vlc/input.h>
#include <vlc/vout.h>
34

35 36
#ifdef HAVE_SYS_TIMES_H
#   include <sys/times.h>
37
#endif
38

39
#include "vlc_playlist.h"
40

41 42
#include "stream_output.h"

43
#include "vlc_interface.h"
44 45
#include "codecs.h"
#include "modules/demux/util/sub.h"
46

47
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
48
 * Local prototypes
49
 *****************************************************************************/
50 51 52 53 54 55 56
struct input_thread_sys_t
{
    /* subtitles */
    int              i_sub;
    subtitle_demux_t **sub;
};

57
static  int RunThread       ( input_thread_t *p_input );
58 59 60
static  int InitThread      ( input_thread_t *p_input );
static void ErrorThread     ( input_thread_t *p_input );
static void EndThread       ( input_thread_t *p_input );
Michel Kaempf's avatar
Michel Kaempf committed
61

62 63
static void ParseOption     ( input_thread_t *p_input,
                              const char *psz_option );
64 65 66 67

static es_out_t *EsOutCreate ( input_thread_t * );
static void      EsOutRelease( es_out_t * );

68 69 70 71 72 73 74 75 76 77 78
/*****************************************************************************
 * Callbacks
 *****************************************************************************/
static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data );
static int TimeCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data );
static int StateCallback   ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data );
static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data );
79

80
/*****************************************************************************
81
 * input_CreateThread: creates a new input thread
82
 *****************************************************************************
83 84
 * This function creates a new input, and returns a pointer
 * to its description. On error, it returns NULL.
85
 *****************************************************************************/
86
input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
87
                                      playlist_item_t *p_item )
Michel Kaempf's avatar
Michel Kaempf committed
88
{
89
    input_thread_t *    p_input;                        /* thread descriptor */
90
    input_info_category_t * p_info;
91
    vlc_value_t val;
92
    int i;
93

94
    /* Allocate descriptor */
95
    p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
96
    if( p_input == NULL )
Michel Kaempf's avatar
Michel Kaempf committed
97
    {
98
        msg_Err( p_parent, "out of memory" );
99
        return NULL;
Michel Kaempf's avatar
Michel Kaempf committed
100
    }
101

102 103 104 105 106 107
    /* Parse input options */
    for( i = 0; i < p_item->i_options; i++ )
    {
        ParseOption( p_input, p_item->ppsz_options[i] );
    }

108 109 110 111 112 113 114 115 116
    /* Create a few object variables we'll need later on */
    var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Create( p_input, "audio-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
    var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );

    var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
    var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
    var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    var_Create( p_input, "sout-keep",  VLC_VAR_BOOL | VLC_VAR_DOINHERIT );

    /* play status */

    /* position variable */
    var_Create( p_input, "position",  VLC_VAR_FLOAT );  /* position 0.0 -> 1.0 */
    val.f_float = 0.0;
    var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "position", PositionCallback, NULL );

    /* time variable */
    var_Create( p_input, "time",  VLC_VAR_TIME );
    val.i_time = 0;
    var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "time", TimeCallback, NULL );

    /* length variable */
    var_Create( p_input, "length",  VLC_VAR_TIME );
    val.i_time = 0;
    var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );

    /* rate variable */
    var_Create( p_input, "rate", VLC_VAR_INTEGER );
    var_Create( p_input, "rate-slower", VLC_VAR_VOID );
    var_Create( p_input, "rate-faster", VLC_VAR_VOID );
    val.i_int = DEFAULT_RATE;
    var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "rate", RateCallback, NULL );
    var_AddCallback( p_input, "rate-slower", RateCallback, NULL );
    var_AddCallback( p_input, "rate-faster", RateCallback, NULL );

    /* state variable */
    var_Create( p_input, "state", VLC_VAR_INTEGER );
    val.i_int = INIT_S;
    var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
    var_AddCallback( p_input, "state", StateCallback, NULL );

154

155
    /* Initialize thread properties */
156
    p_input->b_eof      = 0;
157
    p_input->p_sys      = NULL;
158 159

    /* Set target */
160
    p_input->psz_source = strdup( p_item->psz_uri );
161

162 163 164
    /* Stream */
    p_input->s = NULL;

165 166 167
    /* es out */
    p_input->p_es_out = NULL;

168
    /* Demux */
169 170 171 172
    p_input->p_demux   = NULL;
    p_input->pf_demux  = NULL;
    p_input->pf_rewind = NULL;
    p_input->pf_demux_control = NULL;
173 174

    /* Access */
175
    p_input->p_access = NULL;
176

177 178
    p_input->i_bufsize = 0;
    p_input->i_mtu = 0;
179
    p_input->i_pts_delay = DEFAULT_PTS_DELAY;
180

181 182 183 184 185 186
    /* Initialize statistics */
    p_input->c_loops                    = 0;
    p_input->stream.c_packets_read      = 0;
    p_input->stream.c_packets_trashed   = 0;

    /* Set locks. */
187
    vlc_mutex_init( p_input, &p_input->stream.stream_lock );
188
    vlc_cond_init( p_input, &p_input->stream.stream_wait );
189
    vlc_mutex_init( p_input, &p_input->stream.control.control_lock );
Michel Kaempf's avatar
Michel Kaempf committed
190

191
    /* Initialize stream description */
192
    p_input->stream.b_changed = 0;
193 194
    p_input->stream.i_es_number = 0;
    p_input->stream.i_selected_es_number = 0;
195
    p_input->stream.i_pgrm_number = 0;
196
    p_input->stream.i_new_status = p_input->stream.i_new_rate = 0;
197
    p_input->stream.b_new_mute = MUTE_NO_CHANGE;
Christophe Massiot's avatar
Christophe Massiot committed
198
    p_input->stream.i_mux_rate = 0;
199
    p_input->stream.b_seekable = 0;
200
    p_input->stream.p_sout = NULL;
Michel Kaempf's avatar
Michel Kaempf committed
201

202 203 204
    /* no stream, no program, no area, no es */
    p_input->stream.p_new_program = NULL;

205 206
    p_input->stream.i_area_nb = 0;
    p_input->stream.pp_areas = NULL;
207
    p_input->stream.p_selected_area = NULL;
208
    p_input->stream.p_new_area = NULL;
209

210 211 212 213
    p_input->stream.pp_selected_es = NULL;
    p_input->stream.p_removed_es = NULL;
    p_input->stream.p_newly_selected_es = NULL;

214
    /* By default there is one area in a stream */
215
    input_AddArea( p_input, 0, 1 );
216
    p_input->stream.p_selected_area = p_input->stream.pp_areas[0];
217

218
    /* Initialize stream control properties. */
219
    p_input->stream.control.i_status = INIT_S;
220 221
    p_input->stream.control.i_rate = DEFAULT_RATE;
    p_input->stream.control.b_mute = 0;
222 223
    p_input->stream.control.b_grayscale = config_GetInt( p_input, "grayscale" );

224 225 226 227 228 229 230 231 232 233 234
    /* Initialize input info */
    p_input->stream.p_info = malloc( sizeof( input_info_category_t ) );
    if( !p_input->stream.p_info )
    {
        msg_Err( p_input, "No memory!" );
        return NULL;
    }
    p_input->stream.p_info->psz_name = strdup("General") ;
    p_input->stream.p_info->p_info = NULL;
    p_input->stream.p_info->p_next = NULL;

235
    msg_Info( p_input, "playlist item `%s'", p_input->psz_source );
Michel Kaempf's avatar
Michel Kaempf committed
236

237 238
    p_info = input_InfoCategory( p_input, _("General") );
    input_AddInfo( p_info, _("Playlist Item"), p_input->psz_source );
239
    vlc_object_attach( p_input, p_parent );
240

Sam Hocevar's avatar
Sam Hocevar committed
241
    /* Create thread and wait for its readiness. */
242 243
    if( vlc_thread_create( p_input, "input", RunThread,
                           VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
Michel Kaempf's avatar
Michel Kaempf committed
244
    {
245
        msg_Err( p_input, "cannot create input thread" );
Michel Kaempf's avatar
Michel Kaempf committed
246
        free( p_input );
247
        return NULL;
Michel Kaempf's avatar
Michel Kaempf committed
248
    }
249

250
    return p_input;
Michel Kaempf's avatar
Michel Kaempf committed
251 252
}

253
/*****************************************************************************
254
 * input_StopThread: mark an input thread as zombie
255
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
256
 * This function should not return until the thread is effectively cancelled.
257
 *****************************************************************************/
Sam Hocevar's avatar
Sam Hocevar committed
258
void input_StopThread( input_thread_t *p_input )
Michel Kaempf's avatar
Michel Kaempf committed
259
{
260 261
    /* Make the thread exit from a possible vlc_cond_wait() */
    vlc_mutex_lock( &p_input->stream.stream_lock );
262 263
    /* Request thread destruction */
    p_input->b_die = 1;
Michel Kaempf's avatar
Michel Kaempf committed
264

265 266
    vlc_cond_signal( &p_input->stream.stream_wait );
    vlc_mutex_unlock( &p_input->stream.stream_lock );
267 268 269 270 271 272 273 274 275 276
}

/*****************************************************************************
 * input_DestroyThread: mark an input thread as zombie
 *****************************************************************************
 * This function should not return until the thread is effectively cancelled.
 *****************************************************************************/
void input_DestroyThread( input_thread_t *p_input )
{
    /* Join the thread */
277
    vlc_thread_join( p_input );
278 279 280

    /* Destroy Mutex locks */
    vlc_mutex_destroy( &p_input->stream.control.control_lock );
281
    vlc_cond_destroy( &p_input->stream.stream_wait );
282
    vlc_mutex_destroy( &p_input->stream.stream_lock );
Michel Kaempf's avatar
Michel Kaempf committed
283 284
}

285
/*****************************************************************************
286
 * RunThread: main thread loop
287
 *****************************************************************************
288
 * Thread in charge of processing the network packets and demultiplexing.
289
 *****************************************************************************/
290
static int RunThread( input_thread_t *p_input )
Michel Kaempf's avatar
Michel Kaempf committed
291
{
292 293 294
    vlc_value_t  val;
    mtime_t      i_update_next = -1;

Sam Hocevar's avatar
Sam Hocevar committed
295 296 297
    /* Signal right now, otherwise we'll get stuck in a peek */
    vlc_thread_ready( p_input );

298 299 300 301 302
    if( InitThread( p_input ) )
    {
        /* If we failed, wait before we are killed, and exit */
        p_input->b_error = 1;
        ErrorThread( p_input );
Sam Hocevar's avatar
Sam Hocevar committed
303
        p_input->b_dead = 1;
304
        return 0;
305
    }
Michel Kaempf's avatar
Michel Kaempf committed
306

307
    /* initialization is complete */
308
    vlc_mutex_lock( &p_input->stream.stream_lock );
309 310
    p_input->stream.b_changed        = 1;
    p_input->stream.control.i_status = PLAYING_S;
311 312
    vlc_mutex_unlock( &p_input->stream.stream_lock );

313 314 315
    val.i_int = PLAYING_S;
    var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );

316 317
    while( !p_input->b_die && !p_input->b_error && !p_input->b_eof )
    {
318
        unsigned int i, i_count;
319

320
        p_input->c_loops++;
321

322
        vlc_mutex_lock( &p_input->stream.stream_lock );
323

324 325 326 327 328
        if( p_input->stream.p_new_program )
        {
            if( p_input->pf_set_program != NULL )
            {

329 330
                /* Reinitialize buffer manager. */
                input_AccessReinit( p_input );
331 332

                p_input->pf_set_program( p_input,
333
                                         p_input->stream.p_new_program );
334

335 336 337 338
                /* Escape all decoders for the stream discontinuity they
                 * will encounter. */
                input_EscapeDiscontinuity( p_input );

339 340 341 342 343 344 345 346 347 348 349
                for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
                {
                    pgrm_descriptor_t * p_pgrm
                                            = p_input->stream.pp_programs[i];

                    /* Reinitialize synchro. */
                    p_pgrm->i_synchro_state = SYNCHRO_REINIT;
                }
            }
            p_input->stream.p_new_program = NULL;
        }
350

351 352
        if( p_input->stream.p_new_area )
        {
353 354
            if( p_input->stream.b_seekable && p_input->pf_set_area != NULL )
            {
355
                input_AccessReinit( p_input );
356 357 358

                p_input->pf_set_area( p_input, p_input->stream.p_new_area );

359 360 361 362
                /* Escape all decoders for the stream discontinuity they
                 * will encounter. */
                input_EscapeDiscontinuity( p_input );

363 364 365 366 367 368 369 370 371
                for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
                {
                    pgrm_descriptor_t * p_pgrm
                                            = p_input->stream.pp_programs[i];

                    /* Reinitialize synchro. */
                    p_pgrm->i_synchro_state = SYNCHRO_REINIT;
                }
            }
372 373 374
            p_input->stream.p_new_area = NULL;
        }

375
        if( p_input->stream.p_selected_area->i_seek != NO_SEEK )
376
        {
377
            if( p_input->stream.p_selected_area->i_size > 0 )
378
            {
379
                unsigned int i;
380
                mtime_t      i_time;
381 382
                double f = (double)p_input->stream.p_selected_area->i_seek /
                           (double)p_input->stream.p_selected_area->i_size;
383

Christophe Massiot's avatar
Christophe Massiot committed
384
                vlc_mutex_unlock( &p_input->stream.stream_lock );
385
                demux_Control( p_input, DEMUX_SET_POSITION, f );
Christophe Massiot's avatar
Christophe Massiot committed
386
                vlc_mutex_lock( &p_input->stream.stream_lock );
387

388 389 390 391
                /* Escape all decoders for the stream discontinuity they
                 * will encounter. */
                input_EscapeDiscontinuity( p_input );

392 393
                for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
                {
394
                    pgrm_descriptor_t * p_pgrm=p_input->stream.pp_programs[i];
395 396 397 398

                    /* Reinitialize synchro. */
                    p_pgrm->i_synchro_state = SYNCHRO_REINIT;
                }
399

Laurent Aimar's avatar
Laurent Aimar committed
400
                vlc_mutex_unlock( &p_input->stream.stream_lock );
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
                if( !demux_Control( p_input, DEMUX_GET_TIME, &i_time ) )
                {
                    int i;
                    vlc_value_t val;

                    /* Help in bar display */
                    val.i_time = i_time;
                    var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );

                    /* Seek subs */
                    for( i = 0; i < p_input->p_sys->i_sub; i++ )
                    {
                        subtitle_Seek( p_input->p_sys->sub[i], i_time );
                    }
                }
Laurent Aimar's avatar
Laurent Aimar committed
416
                vlc_mutex_lock( &p_input->stream.stream_lock );
417
            }
418
            p_input->stream.p_selected_area->i_seek = NO_SEEK;
419
        }
420

421 422 423 424 425 426 427 428 429 430 431 432
        if( p_input->stream.p_removed_es )
        {
            input_UnselectES( p_input, p_input->stream.p_removed_es );
            p_input->stream.p_removed_es = NULL;
        }

        if( p_input->stream.p_newly_selected_es )
        {
            input_SelectES( p_input, p_input->stream.p_newly_selected_es );
            p_input->stream.p_newly_selected_es = NULL;
        }

433 434 435 436 437 438 439 440 441 442 443 444 445 446
        if( p_input->stream.b_new_mute != MUTE_NO_CHANGE )
        {
            if( p_input->stream.b_new_mute )
            {
                input_EscapeAudioDiscontinuity( p_input );
            }

            vlc_mutex_lock( &p_input->stream.control.control_lock );
            p_input->stream.control.b_mute = p_input->stream.b_new_mute;
            vlc_mutex_unlock( &p_input->stream.control.control_lock );

            p_input->stream.b_new_mute = MUTE_NO_CHANGE;
        }

447
        vlc_mutex_unlock( &p_input->stream.stream_lock );
448

Christophe Massiot's avatar
Christophe Massiot committed
449 450
        /* Read and demultiplex some data. */
        i_count = p_input->pf_demux( p_input );
451

452
        if( i_count == 0 )
453
        {
454
            /* End of file - we do not set b_die because only the
455
             * playlist is allowed to do so. */
456
            msg_Info( p_input, "EOF reached" );
457 458 459 460 461
            p_input->b_eof = 1;
        }
        else if( i_count < 0 )
        {
            p_input->b_error = 1;
462
        }
463 464 465

        if( !p_input->b_error && !p_input->b_eof && i_update_next < mdate() )
        {
466 467 468 469
            int i;
            mtime_t i_time;
            mtime_t i_length;
            double  d_pos;
470 471

            /* update input status variables */
472
            if( !demux_Control( p_input, DEMUX_GET_POSITION, &d_pos ) )
473
            {
474
                val.f_float = (float)d_pos;
475 476
                var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
            }
477
            if( !demux_Control( p_input, DEMUX_GET_TIME, &i_time ) )
478
            {
479
                val.i_time = i_time;
480 481
                var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
            }
482
            if( !demux_Control( p_input, DEMUX_GET_LENGTH, &i_length ) )
483
            {
484
                val.i_time = i_length;
485 486 487
                var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
            }

488 489 490 491 492 493 494
            /* update subs */
            for( i = 0; i < p_input->p_sys->i_sub; i++ )
            {
                subtitle_Demux( p_input->p_sys->sub[i], i_time );
            }

            i_update_next = mdate() + 150000LL;
495
        }
496 497
    }

498
    if( p_input->b_error || p_input->b_eof )
499 500 501
    {
        ErrorThread( p_input );
    }
502

503
    EndThread( p_input );
504

505
    return 0;
506 507
}

508
/*****************************************************************************
509
 * InitThread: init the input Thread
510
 *****************************************************************************/
511
static int InitThread( input_thread_t * p_input )
Michel Kaempf's avatar
Michel Kaempf committed
512
{
513
    float f_fps;
Christophe Massiot's avatar
Christophe Massiot committed
514
    /* Parse source string. Syntax : [[<access>][/<demux>]:][<source>] */
515
    char * psz_parser = p_input->psz_dupsource = strdup(p_input->psz_source);
516
    vlc_value_t val;
517 518
    subtitle_demux_t *p_sub;
    int64_t i_microsecondperframe;
519

Christophe Massiot's avatar
Christophe Massiot committed
520 521 522 523 524
    /* Skip the plug-in names */
    while( *psz_parser && *psz_parser != ':' )
    {
        psz_parser++;
    }
525
#if defined( WIN32 ) || defined( UNDER_CE )
Christophe Massiot's avatar
Christophe Massiot committed
526
    if( psz_parser - p_input->psz_dupsource == 1 )
527
    {
528
        msg_Warn( p_input, "drive letter %c: found in source string",
Christophe Massiot's avatar
Christophe Massiot committed
529
                           p_input->psz_dupsource[0] ) ;
530
        psz_parser = "";
531 532
    }
#endif
533

Christophe Massiot's avatar
Christophe Massiot committed
534
    if( !*psz_parser )
535
    {
536
        p_input->psz_access = p_input->psz_demux = "";
Christophe Massiot's avatar
Christophe Massiot committed
537
        p_input->psz_name = p_input->psz_source;
Christophe Massiot's avatar
Christophe Massiot committed
538
        free( p_input->psz_dupsource );
539
        p_input->psz_dupsource = NULL;
Michel Kaempf's avatar
Michel Kaempf committed
540
    }
Christophe Massiot's avatar
Christophe Massiot committed
541 542 543
    else
    {
        *psz_parser++ = '\0';
544

545 546 547 548
        /* let's skip '//' */
        if( psz_parser[0] == '/' && psz_parser[1] == '/' )
        {
            psz_parser += 2 ;
549
        }
550 551

        p_input->psz_name = psz_parser ;
552

Christophe Massiot's avatar
Christophe Massiot committed
553
        /* Come back to parse the access and demux plug-ins */
Christophe Massiot's avatar
Christophe Massiot committed
554
        psz_parser = p_input->psz_dupsource;
555

556
        if( !*psz_parser )
Christophe Massiot's avatar
Christophe Massiot committed
557 558
        {
            /* No access */
559
            p_input->psz_access = "";
Christophe Massiot's avatar
Christophe Massiot committed
560 561 562 563
        }
        else if( *psz_parser == '/' )
        {
            /* No access */
564
            p_input->psz_access = "";
Christophe Massiot's avatar
Christophe Massiot committed
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
            psz_parser++;
        }
        else
        {
            p_input->psz_access = psz_parser;

            while( *psz_parser && *psz_parser != '/' )
            {
                psz_parser++;
            }

            if( *psz_parser == '/' )
            {
                *psz_parser++ = '\0';
            }
        }
581

Christophe Massiot's avatar
Christophe Massiot committed
582 583 584
        if( !*psz_parser )
        {
            /* No demux */
585
            p_input->psz_demux = "";
Christophe Massiot's avatar
Christophe Massiot committed
586 587 588 589 590
        }
        else
        {
            p_input->psz_demux = psz_parser;
        }
Sam Hocevar's avatar
Sam Hocevar committed
591
    }
Christophe Massiot's avatar
Christophe Massiot committed
592

593 594
    msg_Dbg( p_input, "access `%s', demux `%s', name `%s'",
             p_input->psz_access, p_input->psz_demux, p_input->psz_name );
Christophe Massiot's avatar
Christophe Massiot committed
595 596

    if( input_AccessInit( p_input ) == -1 )
597
    {
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
        return VLC_EGENERIC;
    }

    /* Initialize optional stream output. (before demuxer)*/
    var_Get( p_input, "sout", &val );
    if( val.psz_string != NULL )
    {
        if ( *val.psz_string && (p_input->stream.p_sout =
             sout_NewInstance( p_input, val.psz_string )) == NULL )
        {
            msg_Err( p_input, "cannot start stream output instance, aborting" );
            free( val.psz_string );
            return VLC_EGENERIC;
        }
        free( val.psz_string );
613
    }
Christophe Massiot's avatar
Christophe Massiot committed
614

615 616
    p_input->p_es_out = EsOutCreate( p_input );

617
    /* Find and open appropriate access module */
618 619
    p_input->p_access = module_Need( p_input, "access",
                                     p_input->psz_access );
Christophe Massiot's avatar
Christophe Massiot committed
620

621 622 623 624 625 626 627 628 629 630 631 632 633 634
    if ( p_input->p_access == NULL
          && (*p_input->psz_demux || *p_input->psz_access) )
    {
        /* Maybe we got something like :
         * /Volumes/toto:titi/gabu.mpg */
        p_input->psz_access = p_input->psz_demux = "";
        p_input->psz_name = p_input->psz_source;
        free( p_input->psz_dupsource);
        p_input->psz_dupsource = NULL;

        p_input->p_access = module_Need( p_input, "access",
                                         p_input->psz_access );
    }

635
    if( p_input->p_access == NULL )
636
    {
637
        msg_Err( p_input, "no suitable access module for `%s/%s://%s'",
638
                 p_input->psz_access, p_input->psz_demux, p_input->psz_name );
639 640 641 642 643
        if ( p_input->stream.p_sout != NULL )
        {
            sout_DeleteInstance( p_input->stream.p_sout );
        }
        return VLC_EGENERIC;
644
    }
Christophe Massiot's avatar
Christophe Massiot committed
645 646 647

    /* Waiting for stream. */
    if( p_input->i_mtu )
Christophe Massiot's avatar
Christophe Massiot committed
648
    {
Christophe Massiot's avatar
Christophe Massiot committed
649
        p_input->i_bufsize = p_input->i_mtu;
Christophe Massiot's avatar
Christophe Massiot committed
650
    }
651 652
    else
    {
Christophe Massiot's avatar
Christophe Massiot committed
653
        p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
654
    }
655

656 657 658 659 660
    /* If the desynchronisation requested by the user is < 0, we need to
     * cache more data. */
    if( p_input->p_vlc->i_desync < 0 )
        p_input->i_pts_delay -= p_input->p_vlc->i_desync;

661
    if( p_input->p_current_data == NULL && p_input->pf_read != NULL )
662
    {
Christophe Massiot's avatar
Christophe Massiot committed
663 664
        while( !input_FillBuffer( p_input ) )
        {
665
            if( p_input->b_die || p_input->b_error || p_input->b_eof )
Christophe Massiot's avatar
Christophe Massiot committed
666
            {
667
                module_Unneed( p_input, p_input->p_access );
668 669 670 671 672
                if ( p_input->stream.p_sout != NULL )
                {
                    sout_DeleteInstance( p_input->stream.p_sout );
                }
                return VLC_EGENERIC;
Christophe Massiot's avatar
Christophe Massiot committed
673 674
            }
        }
675
    }
676

677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
    /* Create the stream_t facilities */
    p_input->s = stream_OpenInput( p_input );
    if( p_input->s == NULL )
    {
        /* should nver occur yet */

        msg_Err( p_input, "cannot create stream_t !" );
        module_Unneed( p_input, p_input->p_access );
        if ( p_input->stream.p_sout != NULL )
        {
            sout_DeleteInstance( p_input->stream.p_sout );
        }
        return VLC_EGENERIC;
    }

692
    /* Find and open appropriate demux module */
693 694
    p_input->p_demux = module_Need( p_input, "demux",
                                    p_input->psz_demux );
695

696
    if( p_input->p_demux == NULL )
697
    {
698
        msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
699
                 p_input->psz_access, p_input->psz_demux, p_input->psz_name );
700
        stream_Release( p_input->s );
701
        module_Unneed( p_input, p_input->p_access );
702
        if ( p_input->stream.p_sout != NULL )
703
        {
704
            sout_DeleteInstance( p_input->stream.p_sout );
705
        }
706
        return VLC_EGENERIC;
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
    /* Init input_thread_sys_t */
    p_input->p_sys = malloc( sizeof( input_thread_sys_t ) );
    p_input->p_sys->i_sub = 0;
    p_input->p_sys->sub   = NULL;

    /* get fps */
    if( demux_Control( p_input, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
    {
        i_microsecondperframe = 0;
    }
    else
    {
        i_microsecondperframe = (int64_t)( (double)1000000.0 / (double)f_fps );
    }

    /* Now add subtitles (for now only one) */
    if( ( p_sub = subtitle_New( p_input, NULL, i_microsecondperframe ) ) )
    {
        TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub, p_sub );

        /* see if it should be selected */
        var_Get( p_sub, "sub-file", &val );
        if( val.psz_string && *val.psz_string )
        {
            subtitle_Select( p_sub );
        }
    }

737
    return VLC_SUCCESS;
Michel Kaempf's avatar
Michel Kaempf committed
738 739
}

740
/*****************************************************************************
741
 * ErrorThread: RunThread() error loop
742
 *****************************************************************************
743
 * This function is called when an error occured during thread main's loop.
744
 *****************************************************************************/
745
static void ErrorThread( input_thread_t *p_input )
Michel Kaempf's avatar
Michel Kaempf committed
746
{
747
    while( !p_input->b_die )
Michel Kaempf's avatar
Michel Kaempf committed
748
    {
749 750
        /* Sleep a while */
        msleep( INPUT_IDLE_SLEEP );
Michel Kaempf's avatar
Michel Kaempf committed
751 752 753
    }
}

754
/*****************************************************************************
755
 * EndThread: end the input thread
756
 *****************************************************************************/
757
static void EndThread( input_thread_t * p_input )
758
{
759
    int i;
760
#ifdef HAVE_SYS_TIMES_H
761 762 763
    /* Display statistics */
    struct tms  cpu_usage;
    times( &cpu_usage );
764

765
    msg_Dbg( p_input, "%ld loops consuming user: %ld, system: %ld",
766
             p_input->c_loops, cpu_usage.tms_utime, cpu_usage.tms_stime );
767
#else
768
    msg_Dbg( p_input, "%ld loops", p_input->c_loops );
769
#endif
770

771 772
    input_DumpStream( p_input );

773 774 775
    /* Free all ES and destroy all decoder threads */
    input_EndStream( p_input );

776 777 778
    /* Close optional stream output instance */
    if ( p_input->stream.p_sout != NULL )
    {
779 780
        vlc_object_t *p_pl =
            vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
        vlc_value_t keep;

        if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
        {
            /* attach sout to the playlist */
            msg_Warn( p_input, "keeping sout" );
            vlc_object_detach( p_input->stream.p_sout );
            vlc_object_attach( p_input->stream.p_sout, p_pl );
        }
        else
        {
            msg_Warn( p_input, "destroying sout" );
            sout_DeleteInstance( p_input->stream.p_sout );
        }
        if( p_pl )
        {
            vlc_object_release( p_pl );
        }
799 800
    }

801 802 803 804 805 806 807 808 809 810 811 812 813
    /* Destroy subtitles demuxers */
    for( i = 0; i < p_input->p_sys->i_sub; i++ )
    {
        subtitle_Close( p_input->p_sys->sub[i] );
    }
    if( p_input->p_sys->i_sub > 0 )
    {
        free( p_input->p_sys->sub );
    }

    /* Free input_thread_sys_t */
    free( p_input->p_sys );

814
    /* Free demultiplexer's data */
815
    module_Unneed( p_input, p_input->p_demux );
816

817 818 819
    /* Destroy the stream_t facilities */
    stream_Release( p_input->s );

820 821 822
    /* Destroy es out */
    EsOutRelease( p_input->p_es_out );

823
    /* Close the access plug-in */
824
    module_Unneed( p_input, p_input->p_access );
825

Christophe Massiot's avatar
Christophe Massiot committed
826 827
    input_AccessEnd( p_input );

828 829 830 831
    /* Free info structures XXX destroy es before 'cause vorbis */
    msg_Dbg( p_input, "freeing info structures...");
    input_DelInfo( p_input );

Christophe Massiot's avatar
Christophe Massiot committed
832
    free( p_input->psz_source );
833
    if ( p_input->psz_dupsource != NULL ) free( p_input->psz_dupsource );
834 835 836

    /* Tell we're dead */
    p_input->b_dead = 1;
837 838
}

839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
/*****************************************************************************
 * ParseOption: parses the options for the input
 *****************************************************************************
 * This function parses the input (config) options and creates their associated
 * object variables.
 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
 * bar is the value of the option.
 *****************************************************************************/
static void ParseOption( input_thread_t *p_input, const char *psz_option )
{
    char *psz_name = (char *)psz_option;
    char *psz_value = strchr( psz_option, '=' );
    int  i_name_len, i_type;
    vlc_bool_t b_isno = VLC_FALSE;
    vlc_value_t val;

    if( psz_value ) i_name_len = psz_value - psz_option;
    else i_name_len = strlen( psz_option );

    /* It's too much of an hassle to remove the ':' when we parse
     * the cmd line :) */
    if( i_name_len && *psz_name == ':' )
    {
        psz_name++;
        i_name_len--;
    }

    if( i_name_len == 0 ) return;

    psz_name = strndup( psz_name, i_name_len );
    if( psz_value ) psz_value++;

    i_type = config_GetType( p_input, psz_name );

    if( !i_type && !psz_value )
    {
        /* check for "no-foo" or "nofoo" */
        if( !strncmp( psz_name, "no-", 3 ) )
        {
            memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
        }
        else if( !strncmp( psz_name, "no", 2 ) )
        {
            memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
        }
        else goto cleanup;           /* Option doesn't exist */

        b_isno = VLC_TRUE;
        i_type = config_GetType( p_input, psz_name );

        if( !i_type ) goto cleanup;  /* Option doesn't exist */
    }
    else if( !i_type ) goto cleanup; /* Option doesn't exist */

    if( ( i_type != VLC_VAR_BOOL ) &&
        ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */

    /* Create the variable in the input object.
     * Children of the input object will be able to retreive this value
     * thanks to the inheritance property of the object variables. */
    var_Create( p_input, psz_name, i_type );

    switch( i_type )
    {
    case VLC_VAR_BOOL:
        val.b_bool = !b_isno;
        break;

    case VLC_VAR_INTEGER:
        val.i_int = atoi( psz_value );
        break;

    case VLC_VAR_FLOAT:
        val.f_float = atof( psz_value );
        break;

    case VLC_VAR_STRING:
    case VLC_VAR_FILE:
    case VLC_VAR_DIRECTORY:
        val.psz_string = psz_value;
        break;

    default:
        goto cleanup;
        break;
    }

    var_Set( p_input, psz_name, val );

    msg_Dbg( p_input, "set input option: %s to %s", psz_name, psz_value );

  cleanup:
    if( psz_name ) free( psz_name );
    return;
}
934

935 936 937 938 939 940 941 942 943
/*****************************************************************************
 * es_out_t input handler
 *****************************************************************************/
struct es_out_sys_t
{
    input_thread_t *p_input;

    int         i_id;
    es_out_id_t **id;
944 945 946

    vlc_bool_t  i_audio;
    vlc_bool_t  i_video;
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
};
struct es_out_id_t
{
    es_descriptor_t *p_es;
};

static es_out_id_t *EsOutAdd    ( es_out_t *, es_format_t * );
static int          EsOutSend   ( es_out_t *, es_out_id_t *, pes_packet_t * );
static void         EsOutDel    ( es_out_t *, es_out_id_t * );
static int          EsOutControl( es_out_t *, int i_query, va_list );

static es_out_t *EsOutCreate( input_thread_t *p_input )
{
    es_out_t *out = malloc( sizeof( es_out_t ) );

    out->pf_add     = EsOutAdd;
    out->pf_send    = EsOutSend;
    out->pf_del     = EsOutDel;
    out->pf_control = EsOutControl;

    out->p_sys = malloc( sizeof( es_out_sys_t ) );
    out->p_sys->p_input = p_input;
    out->p_sys->i_id    = 0;
    out->p_sys->id      = NULL;
971 972
    out->p_sys->i_audio = -1;
    out->p_sys->i_video = -1;
973 974 975 976
    return out;
}
static void      EsOutRelease( es_out_t *out )
{
977 978 979 980 981 982 983 984 985 986 987 988
    es_out_sys_t *p_sys = out->p_sys;
    int i;

    for( i = 0; i < p_sys->i_id; i++ )
    {
        free( p_sys->id[i] );
    }
    if( p_sys->id )
    {
        free( p_sys->id );
    }
    free( p_sys );
989 990 991 992 993
    free( out );
}

static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
{
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
    es_out_sys_t      *p_sys = out->p_sys;
    input_thread_t    *p_input = p_sys->p_input;
    es_out_id_t       *id = malloc( sizeof( es_out_id_t ) );
    pgrm_descriptor_t *p_prgm = NULL;

    vlc_mutex_lock( &p_input->stream.stream_lock );
    if( fmt->i_group >= 0 )
    {
        /* search program */
        p_prgm = input_FindProgram( p_input, fmt->i_group );

        if( p_prgm == NULL )
        {
            /* create it */
            p_prgm = input_AddProgram( p_input, fmt->i_group, 0 );

            /* Select the first by default */
            if( p_input->stream.p_selected_program == NULL )
            {
                p_input->stream.p_selected_program = p_prgm;
            }
        }
    }

    id->p_es = input_AddES( p_input,
                            p_prgm,
                            1 + out->p_sys->i_id,
                            fmt->i_cat,
                            fmt->psz_description, 0 );
    id->p_es->i_stream_id = 1 + out->p_sys->i_id;
    id->p_es->i_fourcc = fmt->i_codec;

    switch( fmt->i_cat )
    {
        case AUDIO_ES:
        {
            WAVEFORMATEX *p_wf = malloc( sizeof( WAVEFORMATEX ) + fmt->i_extra);

            p_wf->wFormatTag        = WAVE_FORMAT_UNKNOWN;
            p_wf->nChannels         = fmt->audio.i_channels;
            p_wf->nSamplesPerSec    = fmt->audio.i_samplerate;
            p_wf->nAvgBytesPerSec   = fmt->audio.i_bitrate / 8;
            p_wf->nBlockAlign       = fmt->audio.i_blockalign;
            p_wf->wBitsPerSample    = fmt->audio.i_bitspersample;
            p_wf->cbSize            = fmt->i_extra;
            if( fmt->i_extra > 0 )
            {
                if( fmt->i_extra_type != ES_EXTRA_TYPE_WAVEFORMATEX )
                {
                    msg_Warn( p_input, "extra type != WAVEFORMATEX for audio" );
                }
                memcpy( &p_wf[1], fmt->p_extra, fmt->i_extra );
            }
            id->p_es->p_waveformatex = p_wf;
            break;
        }
        case VIDEO_ES:
        {
            BITMAPINFOHEADER *p_bih = malloc( sizeof( BITMAPINFOHEADER ) +
                                              fmt->i_extra );
            p_bih->biSize           = sizeof(BITMAPINFOHEADER) + fmt->i_extra;
            p_bih->biWidth          = fmt->video.i_width;
            p_bih->biHeight         = fmt->video.i_height;
            p_bih->biPlanes         = 1;
            p_bih->biBitCount       = 24;
            p_bih->biCompression    = fmt->i_codec;
            p_bih->biSizeImage      = fmt->video.i_width * fmt->video.i_height;
            p_bih->biXPelsPerMeter  = 0;
            p_bih->biYPelsPerMeter  = 0;
            p_bih->biClrUsed        = 0;
            p_bih->biClrImportant   = 0;

            if( fmt->i_extra > 0 )
            {
                if( fmt->i_extra_type != ES_EXTRA_TYPE_BITMAPINFOHEADER )
                {
                    msg_Warn( p_input,
                              "extra type != BITMAPINFOHEADER for video" );
                }
                memcpy( &p_bih[1], fmt->p_extra, fmt->i_extra );
            }
            id->p_es->p_bitmapinfoheader = p_bih;
            break;
        }
        default:
            break;
    }

    if( fmt->i_cat == AUDIO_ES && fmt->i_priority > out->p_sys->i_audio )
    {
        if( out->p_sys->i_audio >= 0 )
        {
            msg_Err( p_input, "FIXME unselect es in es_out_Add" );
        }
        input_SelectES( p_input, id->p_es );
        if( id->p_es->p_decoder_fifo )
        {
            out->p_sys->i_audio = fmt->i_priority;
        }
    }
    else if( fmt->i_cat == VIDEO_ES && fmt->i_priority > out->p_sys->i_video )
    {
        if( out->p_sys->i_video >= 0 )
        {
            msg_Err( p_input, "FIXME unselect es in es_out_Add" );
        }
        input_SelectES( p_input, id->p_es );
        if( id->p_es->p_decoder_fifo )
        {
            out->p_sys->i_video = fmt->i_priority;
        }
    }
    vlc_mutex_unlock( &p_input->stream.stream_lock );


    TAB_APPEND( out->p_sys->i_id, out->p_sys->id, id );
1110 1111 1112 1113 1114

    return id;
}
static int EsOutSend( es_out_t *out, es_out_id_t *id, pes_packet_t *p_pes )
{
1115 1116 1117 1118 1119 1120 1121 1122
    if( id->p_es->p_decoder_fifo )
    {
        input_DecodePES( id->p_es->p_decoder_fifo, p_pes );
    }
    else
    {
        input_DeletePES( out->p_sys->p_input->p_method_data, p_pes );
    }
1123 1124 1125 1126
    return VLC_SUCCESS;
}
static void EsOutDel( es_out_t *out, es_out_id_t *id )
{
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
    es_out_sys_t *p_sys = out->p_sys;

    TAB_REMOVE( p_sys->i_id, p_sys->id, id );

    vlc_mutex_lock( &p_sys->p_input->stream.stream_lock );
    if( id->p_es->p_decoder_fifo )
    {
        input_UnselectES( p_sys->p_input, id->p_es );
    }
    if( id->p_es->p_waveformatex )
    {
        free( id->p_es->p_waveformatex );
        id->p_es->p_waveformatex = NULL;
    }
    if( id->p_es->p_bitmapinfoheader )
    {
        free( id->p_es->p_bitmapinfoheader );
        id->p_es->p_bitmapinfoheader = NULL;
    }
    input_DelES( p_sys->p_input, id->p_es );
    vlc_mutex_unlock( &p_sys->p_input->stream.stream_lock );

1149 1150 1151 1152
    free( id );
}
static int EsOutControl( es_out_t *out, int i_query, va_list args )
{
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
    es_out_sys_t *p_sys = out->p_sys;
    vlc_bool_t  b, *pb;
    es_out_id_t *id;
    switch( i_query )
    {
        case ES_OUT_SET_SELECT:
            id = (es_out_id_t*) va_arg( args, es_out_id_t * );
            b = (vlc_bool_t) va_arg( args, vlc_bool_t );
            if( b && id->p_es->p_decoder_fifo == NULL )
            {
                input_SelectES( p_sys->p_input, id->p_es );
                return id->p_es->p_decoder_fifo ? VLC_SUCCESS : VLC_EGENERIC;
            }
            else if( !b && id->p_es->p_decoder_fifo )
            {
                input_UnselectES( p_sys->p_input, id->p_es );
            }
            return VLC_SUCCESS;

        case ES_OUT_GET_SELECT:
            id = (es_out_id_t*) va_arg( args, es_out_id_t * );
            pb = (vlc_bool_t*) va_arg( args, vlc_bool_t * );

            *pb = id->p_es->p_decoder_fifo ? VLC_TRUE : VLC_FALSE;
            return VLC_SUCCESS;

        default:
            msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
            return VLC_EGENERIC;
    }
1183 1184
}

1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
/*****************************************************************************
 * Callbacks  (position, time, state, rate )
 *****************************************************************************/
static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    input_thread_t *p_input = (input_thread_t *)p_this;

    msg_Warn( p_input, "cmd=%s old=%f new=%f",
              psz_cmd,
              oldval.f_float, newval.f_float );

    vlc_mutex_lock( &p_input->stream.stream_lock );
    p_input->stream.p_selected_area->i_seek =
        (int64_t)( newval.f_float * (double)p_input->stream.p_selected_area->i_size );
    vlc_mutex_unlock( &p_input->stream.stream_lock );

    return VLC_SUCCESS;
}

static int TimeCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    input_thread_t *p_input = (input_thread_t *)p_this;

    /* FIXME TODO FIXME */
    msg_Warn( p_input, "cmd=%s old=%lld new=%lld",
              psz_cmd,
              oldval.i_time, newval.i_time );

    vlc_mutex_lock( &p_input->stream.stream_lock );
    p_input->stream.p_selected_area->i_seek =
        newval.i_time / 1000000 * 50 * p_input->stream.i_mux_rate;
    vlc_mutex_unlock( &p_input->stream.stream_lock );

    return VLC_SUCCESS;
}

static int StateCallback   ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    input_thread_t *p_input = (input_thread_t *)p_this;
    msg_Warn( p_input, "cmd=%s old=%d new=%d",
              psz_cmd, oldval.i_int, newval.i_int );

    switch( newval.i_int )
    {
        case PLAYING_S:
            input_SetStatus( p_input, INPUT_STATUS_PLAY );
            return VLC_SUCCESS;
        case PAUSE_S:
            input_SetStatus( p_input, INPUT_STATUS_PAUSE );
            return VLC_SUCCESS;
        case END_S:
            input_SetStatus( p_input, INPUT_STATUS_END );
            return VLC_SUCCESS;
        default:
            msg_Err( p_input, "cannot set new state (invalid)" );
            return VLC_EGENERIC;
    }
}

static int RateCallback    ( vlc_object_t *p_this, char const *psz_cmd,
                             vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
    input_thread_t *p_input = (input_thread_t *)p_this;

    if( !strcmp( psz_cmd, "rate-slower" ) )
    {
        input_SetStatus( p_input, INPUT_STATUS_SLOWER );
    }
    else if( !strcmp( psz_cmd, "rate-faster" ) )
    {
        input_SetStatus( p_input, INPUT_STATUS_FASTER );
    }
    else
    {
        msg_Warn( p_input, "cmd=%s old=%d new=%d",
                  psz_cmd, oldval.i_int, newval.i_int );
        input_SetRate( p_input, newval.i_int );
    }
    return VLC_SUCCESS;
}