~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/demux/ps.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * ps.c: Program Stream demux module for VLC.
3
3
 *****************************************************************************
4
4
 * Copyright (C) 2004 the VideoLAN team
5
 
 * $Id: 5abacc54974b475c8ab6764a1dbeb21f3ff289cd $
 
5
 * $Id$
6
6
 *
7
7
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8
8
 *
24
24
/*****************************************************************************
25
25
 * Preamble
26
26
 *****************************************************************************/
27
 
#include <stdlib.h>                                      /* malloc(), free() */
28
 
 
29
 
#include <vlc/vlc.h>
30
 
#include <vlc/input.h>
 
27
 
 
28
#ifdef HAVE_CONFIG_H
 
29
# include "config.h"
 
30
#endif
 
31
 
 
32
#include <vlc_common.h>
 
33
#include <vlc_plugin.h>
 
34
#include <vlc_demux.h>
31
35
 
32
36
#include "ps.h"
33
37
 
44
48
/*****************************************************************************
45
49
 * Module descriptor
46
50
 *****************************************************************************/
 
51
static int  OpenForce( vlc_object_t * );
47
52
static int  Open   ( vlc_object_t * );
48
 
static int  OpenAlt( vlc_object_t * );
49
53
static void Close  ( vlc_object_t * );
50
54
 
51
55
vlc_module_begin();
52
 
    set_description( _("MPEG-PS demuxer") );
 
56
    set_description( N_("MPEG-PS demuxer") );
53
57
    set_category( CAT_INPUT );
54
58
    set_subcategory( SUBCAT_INPUT_DEMUX );
55
 
    set_capability( "demux2", 1 );
56
 
    set_callbacks( Open, Close );
 
59
    set_capability( "demux", 1 );
 
60
    set_callbacks( OpenForce, Close );
57
61
    add_shortcut( "ps" );
58
62
 
59
 
    add_bool( "ps-trust-timestamps", VLC_TRUE, NULL, TIME_TEXT,
60
 
                 TIME_LONGTEXT, VLC_TRUE );
 
63
    add_bool( "ps-trust-timestamps", true, NULL, TIME_TEXT,
 
64
                 TIME_LONGTEXT, true );
61
65
 
62
66
    add_submodule();
63
 
    set_description( _("MPEG-PS demuxer") );
64
 
    set_capability( "demux2", 9 );
65
 
    set_callbacks( OpenAlt, Close );
 
67
    set_description( N_("MPEG-PS demuxer") );
 
68
    set_capability( "demux", 8 );
 
69
    set_callbacks( Open, Close );
66
70
vlc_module_end();
67
71
 
68
72
/*****************************************************************************
80
84
    int         i_time_track;
81
85
    int64_t     i_current_pts;
82
86
 
83
 
    vlc_bool_t  b_lost_sync;
84
 
    vlc_bool_t  b_have_pack;
85
 
    vlc_bool_t  b_seekable;
 
87
    bool  b_lost_sync;
 
88
    bool  b_have_pack;
 
89
    bool  b_seekable;
86
90
};
87
91
 
88
92
static int Demux  ( demux_t *p_demux );
94
98
/*****************************************************************************
95
99
 * Open
96
100
 *****************************************************************************/
97
 
static int Open( vlc_object_t *p_this )
 
101
static int OpenCommon( vlc_object_t *p_this, bool b_force )
98
102
{
99
103
    demux_t     *p_demux = (demux_t*)p_this;
100
104
    demux_sys_t *p_sys;
101
105
 
102
 
    uint8_t     *p_peek;
 
106
    const uint8_t *p_peek;
103
107
 
104
108
    if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
105
109
    {
107
111
        return VLC_EGENERIC;
108
112
    }
109
113
 
110
 
    if( p_peek[0] != 0 || p_peek[1] != 0 ||
111
 
        p_peek[2] != 1 || p_peek[3] < 0xb9 )
 
114
    if( memcmp( p_peek, "\x00\x00\x01", 3 ) || ( p_peek[3] < 0xb9 ) )
112
115
    {
 
116
        if( !b_force )
 
117
            return VLC_EGENERIC;
 
118
 
113
119
        msg_Warn( p_demux, "this does not look like an MPEG PS stream, "
114
120
                  "continuing anyway" );
115
121
    }
118
124
    p_demux->pf_demux = Demux;
119
125
    p_demux->pf_control = Control;
120
126
    p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
 
127
    if( !p_sys ) return VLC_ENOMEM;
121
128
 
122
129
    /* Init p_sys */
123
130
    p_sys->i_mux_rate = 0;
125
132
    p_sys->i_length   = -1;
126
133
    p_sys->i_current_pts = (mtime_t) 0;
127
134
    p_sys->i_time_track = -1;
128
 
    
129
 
    p_sys->b_lost_sync = VLC_FALSE;
130
 
    p_sys->b_have_pack = VLC_FALSE;
131
 
    p_sys->b_seekable  = VLC_FALSE;
 
135
 
 
136
    p_sys->b_lost_sync = false;
 
137
    p_sys->b_have_pack = false;
 
138
    p_sys->b_seekable  = false;
132
139
 
133
140
    stream_Control( p_demux->s, STREAM_CAN_SEEK, &p_sys->b_seekable );
134
141
 
140
147
    return VLC_SUCCESS;
141
148
}
142
149
 
143
 
static int OpenAlt( vlc_object_t *p_this )
144
 
{
145
 
    demux_t *p_demux = (demux_t*)p_this;
146
 
    uint8_t *p_peek;
147
 
 
148
 
    if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
149
 
    {
150
 
        msg_Err( p_demux, "cannot peek" );
151
 
        return VLC_EGENERIC;
152
 
    }
153
 
 
154
 
    if( p_peek[0] != 0 || p_peek[1] != 0 ||
155
 
        p_peek[2] != 1 || p_peek[3] < 0xb9 )
156
 
    {
157
 
        if( !p_demux->b_force ) return VLC_EGENERIC;
158
 
    }
159
 
 
160
 
    return Open( p_this );
 
150
static int OpenForce( vlc_object_t *p_this )
 
151
{
 
152
    return OpenCommon( p_this, true );
 
153
}
 
154
 
 
155
static int Open( vlc_object_t *p_this )
 
156
{
 
157
    return OpenCommon( p_this, ((demux_t *)p_this)->b_force );
161
158
}
162
159
 
163
160
/*****************************************************************************
184
181
    free( p_sys );
185
182
}
186
183
 
187
 
static int Demux2( demux_t *p_demux, vlc_bool_t b_end )
 
184
static int Demux2( demux_t *p_demux, bool b_end )
188
185
{
189
186
    demux_sys_t *p_sys = p_demux->p_sys;
190
187
    int i_ret, i_id;
201
198
        if( !p_sys->b_lost_sync )
202
199
            msg_Warn( p_demux, "garbage at input, trying to resync..." );
203
200
 
204
 
        p_sys->b_lost_sync = VLC_TRUE;
 
201
        p_sys->b_lost_sync = true;
205
202
        return 1;
206
203
    }
207
204
 
208
205
    if( p_sys->b_lost_sync ) msg_Warn( p_demux, "found sync code" );
209
 
    p_sys->b_lost_sync = VLC_FALSE;
 
206
    p_sys->b_lost_sync = false;
210
207
 
211
208
    if( ( p_pkt = ps_pkt_read( p_demux->s, i_code ) ) == NULL )
212
209
    {
246
243
        /* Check beginning */
247
244
        i = 0;
248
245
        i_current_pos = stream_Tell( p_demux->s );
249
 
        while( !p_demux->b_die && i < 40 && Demux2( p_demux, VLC_FALSE ) > 0 ) i++;
 
246
        while( vlc_object_alive (p_demux) && i < 40 && Demux2( p_demux, false ) > 0 ) i++;
250
247
 
251
248
        /* Check end */
252
249
        i_size = stream_Size( p_demux->s );
253
250
        i_end = __MAX( 0, __MIN( 200000, i_size ) );
254
251
        stream_Seek( p_demux->s, i_size - i_end );
255
 
    
256
 
        while( !p_demux->b_die && Demux2( p_demux, VLC_TRUE ) > 0 );
 
252
 
 
253
        while( vlc_object_alive (p_demux) && Demux2( p_demux, true ) > 0 );
257
254
        if( i_current_pos >= 0 ) stream_Seek( p_demux->s, i_current_pos );
258
255
    }
259
256
 
268
265
                {
269
266
                    p_sys->i_length = i_length;
270
267
                    p_sys->i_time_track = i;
271
 
                    msg_Dbg( p_demux, "we found a length of: %lld", p_sys->i_length );
 
268
                    msg_Dbg( p_demux, "we found a length of: %"PRId64, p_sys->i_length );
272
269
                }
273
270
            }
274
271
    }
294
291
        if( !p_sys->b_lost_sync )
295
292
            msg_Warn( p_demux, "garbage at input, trying to resync..." );
296
293
 
297
 
        p_sys->b_lost_sync = VLC_TRUE;
 
294
        p_sys->b_lost_sync = true;
298
295
        return 1;
299
296
    }
300
297
 
301
298
    if( p_sys->b_lost_sync ) msg_Warn( p_demux, "found sync code" );
302
 
    p_sys->b_lost_sync = VLC_FALSE;
 
299
    p_sys->b_lost_sync = false;
303
300
 
304
301
    if( p_sys->i_length < 0 && p_sys->b_seekable )
305
302
        FindLength( p_demux );
318
315
    case 0x1ba:
319
316
        if( !ps_pkt_parse_pack( p_pkt, &p_sys->i_scr, &i_mux_rate ) )
320
317
        {
321
 
            if( !p_sys->b_have_pack ) p_sys->b_have_pack = VLC_TRUE;
 
318
            if( !p_sys->b_have_pack ) p_sys->b_have_pack = true;
322
319
            /* done later on to work around bad vcd/svcd streams */
323
320
            /* es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_scr ); */
324
321
            if( i_mux_rate > 0 ) p_sys->i_mux_rate = i_mux_rate;
354
351
    default:
355
352
        if( (i_id = ps_pkt_id( p_pkt )) >= 0xc0 )
356
353
        {
357
 
            vlc_bool_t b_new = VLC_FALSE;
 
354
            bool b_new = false;
358
355
            ps_track_t *tk = &p_sys->tk[PS_ID_TO_TK(i_id)];
359
356
 
360
357
            if( !tk->b_seen )
362
359
                if( !ps_track_fill( tk, &p_sys->psm, i_id ) )
363
360
                {
364
361
                    tk->es = es_out_Add( p_demux->out, &tk->fmt );
365
 
                    b_new = VLC_TRUE;
 
362
                    b_new = true;
366
363
                }
367
364
                else
368
365
                {
369
366
                    msg_Dbg( p_demux, "es id=0x%x format unknown", i_id );
370
367
                }
371
 
                tk->b_seen = VLC_TRUE;
 
368
                tk->b_seen = true;
372
369
            }
373
370
 
374
371
            /* The popular VCD/SVCD subtitling WinSubMux does not
386
383
            p_sys->i_scr = -1;
387
384
 
388
385
            if( tk->b_seen && tk->es &&
389
 
                !ps_pkt_parse_pes( p_pkt, tk->i_skip ) )
 
386
                (
 
387
#ifdef ZVBI_COMPILED /* FIXME!! */
 
388
                tk->fmt.i_codec == VLC_FOURCC('t','e','l','x') ||
 
389
#endif
 
390
                !ps_pkt_parse_pes( p_pkt, tk->i_skip ) ) )
390
391
            {
391
 
                if( !b_new && !p_sys->b_have_pack && tk->fmt.i_cat == AUDIO_ES && p_pkt->i_pts > 0 )
 
392
                if( !b_new && !p_sys->b_have_pack &&
 
393
                    (tk->fmt.i_cat == AUDIO_ES) &&
 
394
                    (p_pkt->i_pts > 0) )
392
395
                {
393
396
                    /* A hack to sync the A/V on PES files. */
394
 
                    msg_Dbg( p_demux, "force SCR: %lld", p_pkt->i_pts );
 
397
                    msg_Dbg( p_demux, "force SCR: %"PRId64, p_pkt->i_pts );
395
398
                    es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_pkt->i_pts );
396
399
                }
397
400
 
505
508
 * Divers:
506
509
 *****************************************************************************/
507
510
 
508
 
/* PSResynch: resynch on a system starcode
 
511
/* PSResynch: resynch on a system startcode
509
512
 *  It doesn't skip more than 512 bytes
510
513
 *  -1 -> error, 0 -> not synch, 1 -> ok
511
514
 */
512
515
static int ps_pkt_resynch( stream_t *s, uint32_t *pi_code )
513
516
{
514
 
    uint8_t *p_peek;
 
517
    const uint8_t *p_peek;
515
518
    int     i_peek;
516
519
    int     i_skip;
517
520
 
554
557
 
555
558
static block_t *ps_pkt_read( stream_t *s, uint32_t i_code )
556
559
{
557
 
    uint8_t *p_peek;
 
560
    const uint8_t *p_peek;
558
561
    int      i_peek = stream_Peek( s, &p_peek, 14 );
559
562
    int      i_size = ps_pkt_size( p_peek, i_peek );
 
563
    VLC_UNUSED(i_code);
560
564
 
561
565
    if( i_size <= 6 && p_peek[3] > 0xba )
562
566
    {