Coverage Report

Created: 2026-05-21 08:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/demux/mpeg/ps.h
Line
Count
Source
1
/*****************************************************************************
2
 * ps.h: Program Stream demuxer helper
3
 *****************************************************************************
4
 * Copyright (C) 2004-2009 VLC authors and VideoLAN
5
 *
6
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation; either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program; if not, write to the Free Software Foundation,
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21
 *****************************************************************************/
22
23
#include <assert.h>
24
#include <vlc_demux.h>
25
#include "timestamps.h"
26
27
18.3M
#define PS_STREAM_ID_END_STREAM       0xB9
28
143k
#define PS_STREAM_ID_PACK_HEADER      0xBA
29
4.12k
#define PS_STREAM_ID_SYSTEM_HEADER    0xBB
30
31
327k
#define PS_PACKET_ID_MASK_VOB        0xBD00
32
135k
#define PS_PACKET_ID_MASK_AOB        0xA000
33
47.9k
#define PS_PACKET_ID_MASK_EXTENDED   0xFD00
34
35
/* 0xBD20 + 0x00 to 0x1f */
36
0
#define PS_SPU_ID_OFFSET             (PS_PACKET_ID_MASK_VOB | 0x20)
37
38
#define PS_AOB_PACKET_ID_LPCM        (PS_PACKET_ID_MASK_AOB | 0x00)
39
186k
#define PS_AOB_PACKET_ID_MLP         (PS_PACKET_ID_MASK_AOB | 0x01)
40
186k
#define PS_VOB_PACKET_ID_MLP         (PS_PACKET_ID_MASK_VOB | 0xA1)
41
42
enum ps_source {
43
    PS_SOURCE_UNKNOWN, // any PS/PES source
44
    PS_SOURCE_VOB,     // when reading a DVD-Video
45
    PS_SOURCE_AOB,     // when reading a DVD-Audio
46
};
47
48
/* 256-0xC0 for normal stream, 256 for VOB stream, 256 for EVOB stream, 8 for AOB stream */
49
12.6M
#define PS_TK_COUNT (256+256+256+8 - 0xc0)
50
static inline unsigned ps_id_to_tk( unsigned i_id )
51
164k
{
52
164k
    assert(i_id >= 0xc0);
53
164k
    if(unlikely(i_id < 0xc0))
54
0
        return 0;
55
164k
    if( i_id <= 0xff )
56
72.2k
        return i_id - 0xc0;
57
92.4k
    if( (i_id & 0xff00) == PS_PACKET_ID_MASK_VOB )
58
81.5k
        return 256-0xC0 + (i_id & 0xff);
59
10.8k
    if( (i_id & 0xff00) == PS_PACKET_ID_MASK_EXTENDED )
60
1.87k
        return 512-0xc0 + (i_id & 0xff);
61
10.8k
    assert( (i_id & 0xff00) == PS_PACKET_ID_MASK_AOB );
62
9.01k
    return 768-0xc0 + (i_id & 0x07);
63
9.01k
}
ps.c:ps_id_to_tk
Line
Count
Source
51
164k
{
52
164k
    assert(i_id >= 0xc0);
53
164k
    if(unlikely(i_id < 0xc0))
54
0
        return 0;
55
164k
    if( i_id <= 0xff )
56
72.2k
        return i_id - 0xc0;
57
92.4k
    if( (i_id & 0xff00) == PS_PACKET_ID_MASK_VOB )
58
81.5k
        return 256-0xC0 + (i_id & 0xff);
59
10.8k
    if( (i_id & 0xff00) == PS_PACKET_ID_MASK_EXTENDED )
60
1.87k
        return 512-0xc0 + (i_id & 0xff);
61
10.8k
    assert( (i_id & 0xff00) == PS_PACKET_ID_MASK_AOB );
62
9.01k
    return 768-0xc0 + (i_id & 0x07);
63
9.01k
}
Unexecuted instantiation: vobsub.c:ps_id_to_tk
64
65
typedef struct ps_psm_t ps_psm_t;
66
static inline uint8_t ps_id_to_type( const ps_psm_t *, uint16_t );
67
static inline const uint8_t *ps_id_to_lang( const ps_psm_t *, uint16_t );
68
69
typedef struct
70
{
71
    bool        b_configured;
72
    bool        b_updated;
73
    int         i_skip;
74
    int         i_id;
75
    int         i_next_block_flags;
76
    es_out_id_t *es;
77
    es_format_t fmt;
78
    vlc_tick_t  i_first_pts;
79
    vlc_tick_t  i_last_pts;
80
81
} ps_track_t;
82
83
/* Init a set of track */
84
static inline void ps_track_init( ps_track_t tk[PS_TK_COUNT] )
85
1.13k
{
86
1.13k
    int i;
87
662k
    for( i = 0; i < PS_TK_COUNT; i++ )
88
661k
    {
89
661k
        tk[i].b_configured = false;
90
661k
        tk[i].b_updated = false;
91
661k
        tk[i].i_skip = 0;
92
661k
        tk[i].i_id   = 0;
93
661k
        tk[i].i_next_block_flags = 0;
94
661k
        tk[i].es     = NULL;
95
661k
        tk[i].i_first_pts = VLC_TICK_INVALID;
96
661k
        tk[i].i_last_pts = VLC_TICK_INVALID;
97
661k
        es_format_Init( &tk[i].fmt, UNKNOWN_ES, 0 );
98
661k
    }
99
1.13k
}
ps.c:ps_track_init
Line
Count
Source
85
1.13k
{
86
1.13k
    int i;
87
662k
    for( i = 0; i < PS_TK_COUNT; i++ )
88
661k
    {
89
661k
        tk[i].b_configured = false;
90
661k
        tk[i].b_updated = false;
91
661k
        tk[i].i_skip = 0;
92
661k
        tk[i].i_id   = 0;
93
661k
        tk[i].i_next_block_flags = 0;
94
661k
        tk[i].es     = NULL;
95
661k
        tk[i].i_first_pts = VLC_TICK_INVALID;
96
        tk[i].i_last_pts = VLC_TICK_INVALID;
97
661k
        es_format_Init( &tk[i].fmt, UNKNOWN_ES, 0 );
98
661k
    }
99
1.13k
}
Unexecuted instantiation: vobsub.c:ps_track_init
100
101
static inline bool ps_is_H264( const uint8_t *p_data, size_t i_data )
102
12.3k
{
103
12.3k
    const uint8_t startcode[3] = { 0, 0, 1 };
104
12.3k
    int i_flags = 0;
105
106
12.3k
    if( i_data < 9 ||
107
12.3k
       (!memcmp( p_data, startcode, 3 ) &&
108
192
        !memcmp( &p_data[1], startcode, 3 )) )
109
7
        return false;
110
111
    /* Shitty H264 probing. We need a centralized way do to this */
112
546k
    while( i_data > 5 )
113
538k
    {
114
538k
        if( !memcmp( p_data, startcode, 3 ) )
115
5.15k
        {
116
5.15k
            if(p_data[3] == 0x67)
117
217
                i_flags ^= 0x01;
118
4.93k
            else if(p_data[3] == 0x68)
119
206
                i_flags ^= 0x02;
120
4.73k
            else if( p_data[3] & 0x80 )
121
2.81k
                return false;
122
1.91k
            else if( (p_data[3] & 0x1F) > 23 || (p_data[3] & 0x1F) < 1 )
123
786
                return false;
124
1.12k
            else if( (p_data[3] & 0x1F) < 6 )
125
728
                return (i_flags == 0x03);
126
5.15k
        }
127
534k
        p_data++;
128
534k
        i_data--;
129
534k
    }
130
131
8.04k
    return false;
132
12.3k
}
ps.c:ps_is_H264
Line
Count
Source
102
12.3k
{
103
12.3k
    const uint8_t startcode[3] = { 0, 0, 1 };
104
12.3k
    int i_flags = 0;
105
106
12.3k
    if( i_data < 9 ||
107
12.3k
       (!memcmp( p_data, startcode, 3 ) &&
108
192
        !memcmp( &p_data[1], startcode, 3 )) )
109
7
        return false;
110
111
    /* Shitty H264 probing. We need a centralized way do to this */
112
546k
    while( i_data > 5 )
113
538k
    {
114
538k
        if( !memcmp( p_data, startcode, 3 ) )
115
5.15k
        {
116
5.15k
            if(p_data[3] == 0x67)
117
217
                i_flags ^= 0x01;
118
4.93k
            else if(p_data[3] == 0x68)
119
206
                i_flags ^= 0x02;
120
4.73k
            else if( p_data[3] & 0x80 )
121
2.81k
                return false;
122
1.91k
            else if( (p_data[3] & 0x1F) > 23 || (p_data[3] & 0x1F) < 1 )
123
786
                return false;
124
1.12k
            else if( (p_data[3] & 0x1F) < 6 )
125
728
                return (i_flags == 0x03);
126
5.15k
        }
127
534k
        p_data++;
128
534k
        i_data--;
129
534k
    }
130
131
8.04k
    return false;
132
12.3k
}
Unexecuted instantiation: vobsub.c:ps_is_H264
133
134
static inline bool ps_is_EAC3( const uint8_t *p_data, size_t i_data )
135
4.04k
{
136
    /* AC-3 marking, see vlc_a52_header_Parse */
137
4.04k
    if( i_data < 8 || p_data[0] != 0x0b || p_data[1] != 0x77 )
138
3.89k
        return false;
139
146
    int bsid = p_data[5] >> 3;
140
146
    return bsid > 10 && bsid <= 16;
141
4.04k
}
ps.c:ps_is_EAC3
Line
Count
Source
135
4.04k
{
136
    /* AC-3 marking, see vlc_a52_header_Parse */
137
4.04k
    if( i_data < 8 || p_data[0] != 0x0b || p_data[1] != 0x77 )
138
3.89k
        return false;
139
146
    int bsid = p_data[5] >> 3;
140
146
    return bsid > 10 && bsid <= 16;
141
4.04k
}
Unexecuted instantiation: vobsub.c:ps_is_EAC3
142
143
/* From id fill i_skip and es_format_t */
144
static inline int ps_track_fill( ps_track_t *tk, ps_psm_t *p_psm,
145
                                 int i_id,
146
                                 const uint8_t *p_pkt, size_t i_pkt,
147
                                 bool b_mpeg2only )
148
60.1k
{
149
60.1k
    tk->i_skip = 0;
150
60.1k
    tk->i_id = i_id;
151
152
60.1k
    if( ( i_id&0xff00 ) == PS_PACKET_ID_MASK_VOB ) /* 0xBD00 -> 0xBDFF, VOB Private Stream 1 */
153
24.9k
    {
154
24.9k
        if( ( i_id&0xf8 ) == 0x88 || /* 0x88 -> 0x8f - Can be DTS-HD primary audio in evob */
155
24.8k
            ( i_id&0xf8 ) == 0x98 )  /* 0x98 -> 0x9f - Can be DTS-HD secondary audio in evob */
156
468
        {
157
468
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DTS );
158
468
            tk->i_skip = 4;
159
468
        }
160
24.5k
        else if( ( i_id&0xf8 ) == 0x80 || /* 0x80 -> 0x87 */
161
22.1k
                 ( i_id&0xf0 ) == 0xc0 )  /* 0xc0 -> 0xcf AC-3, Can also be DD+/E-AC3 in evob */
162
4.09k
        {
163
4.09k
            bool b_eac3 = false;
164
4.09k
            if( ( i_id&0xf0 ) == 0xc0 )
165
1.73k
            {
166
1.73k
                if( p_pkt == NULL || i_pkt < 9 )
167
0
                    return VLC_EGENERIC;
168
169
1.73k
                unsigned i_start = 9 + p_pkt[8];
170
1.73k
                if( i_start + 9 < i_pkt )
171
1.72k
                    b_eac3 = ps_is_EAC3( &p_pkt[i_start + 4], i_pkt - i_start - 4 );
172
1.73k
            }
173
174
4.09k
            es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 );
175
4.09k
            tk->i_skip = 4;
176
4.09k
        }
177
20.4k
        else if( ( i_id&0xfc ) == 0x00 ) /* 0x00 -> 0x03 */
178
6.10k
        {
179
6.10k
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_CVD );
180
6.10k
        }
181
14.3k
        else if( ( i_id&0xff ) == 0x0b ) /* 0x0b */
182
2.31k
        {
183
2.31k
            bool b_eac3 = i_pkt > 8 && ps_is_EAC3( &p_pkt[9], i_pkt - 9 );
184
2.31k
            es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 );
185
2.31k
        }
186
11.9k
        else if( ( i_id&0xff ) == 0x10 ) /* 0x10 */
187
568
        {
188
568
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_TELETEXT );
189
568
        }
190
11.4k
        else if( ( i_id&0xe0 ) == 0x20 ) /* 0x20 -> 0x3f */
191
4.48k
        {
192
4.48k
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_SPU );
193
4.48k
            tk->i_skip = 1;
194
4.48k
        }
195
6.92k
        else if( ( i_id&0xff ) == 0x70 ) /* 0x70 */
196
905
        {
197
905
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_OGT );
198
905
        }
199
6.02k
        else if( ( i_id&0xf0 ) == 0xa0 ) /* 0xa0 -> 0xaf */
200
622
        {
201
622
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVD_LPCM );
202
622
            tk->i_skip = 1;
203
622
        }
204
5.39k
        else if( ( i_id&0xf0 ) == 0xb0 ) /* 0xb0 -> 0xbf */
205
2.51k
        {
206
2.51k
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_TRUEHD );
207
2.51k
            tk->i_skip = 5;
208
2.51k
        }
209
2.88k
        else
210
2.88k
        {
211
2.88k
            es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
212
2.88k
            return VLC_EGENERIC;
213
2.88k
        }
214
24.9k
    }
215
35.1k
    else if( (i_id&0xff00) == PS_PACKET_ID_MASK_EXTENDED ) /* EVOB: 0xFD00 -> 0xFDFF */
216
1.47k
    {
217
1.47k
        uint8_t i_sub_id = i_id & 0xff;
218
1.47k
        if( ( i_sub_id >= 0x55 && i_sub_id <= 0x5f ) || /* Can be primary VC-1 in evob */
219
1.37k
            ( i_sub_id >= 0x75 && i_sub_id <= 0x7f ) )  /* Secondary VC-1 */
220
979
        {
221
979
            es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_VC1 );
222
979
        }
223
496
        else
224
496
        {
225
496
            es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
226
496
            return VLC_EGENERIC;
227
496
        }
228
1.47k
    }
229
33.7k
    else if( (i_id&0xff00) == PS_PACKET_ID_MASK_AOB ) /* AOB: 0xA000 -> 0xA0FF */
230
3.36k
    {
231
3.36k
        uint8_t i_sub_id = i_id & 0x07;
232
3.36k
        if( i_sub_id == 0 )
233
3.36k
        {
234
3.36k
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVDA_LPCM );
235
3.36k
            tk->i_skip = 1;
236
3.36k
        }
237
0
        else if( i_sub_id == 1 )
238
0
        {
239
0
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MLP );
240
0
            tk->i_skip = -1; /* It's a hack for variable skip value */
241
0
        }
242
0
        else
243
0
        {
244
0
            es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
245
0
            return VLC_EGENERIC;
246
0
        }
247
3.36k
    }
248
30.3k
    else
249
30.3k
    {
250
30.3k
        int i_type = ps_id_to_type( p_psm , i_id );
251
252
30.3k
        es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
253
254
30.3k
        if( (i_id&0xf0) == 0xe0 ) /* 0xe0 -> 0xef */
255
17.2k
        {
256
17.2k
            if( i_type == 0x01 )
257
34
            {
258
34
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV );
259
34
                tk->fmt.i_original_fourcc = VLC_CODEC_MP1V;
260
34
            }
261
17.2k
            else if( i_type == 0x02 )
262
2
            {
263
2
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV );
264
2
            }
265
17.2k
            else if( i_type == 0x10 )
266
1.29k
            {
267
1.29k
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MP4V );
268
1.29k
            }
269
15.9k
            else if( i_type == 0x1b )
270
1
            {
271
1
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 );
272
1
            }
273
15.9k
            else if( i_type == 0x24 )
274
771
            {
275
771
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_HEVC );
276
771
            }
277
15.1k
            else if( i_id == 0xe2 || /* Primary H.264 in evob */
278
14.8k
                     i_id == 0xe3 )  /* Secondary H.264 in evob */
279
2.09k
            {
280
2.09k
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 );
281
2.09k
            }
282
13.0k
            else if( p_pkt && i_type == 0x00 && /* Not from PSM */
283
13.0k
                     i_pkt > 9 + 5 &&
284
12.8k
                     i_pkt > 9U + 5 + p_pkt[8] &&
285
12.3k
                     ps_is_H264( &p_pkt[ 9 + p_pkt[8] ],
286
12.3k
                                  i_pkt - 9 - p_pkt[8] ) )
287
180
            {
288
180
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 );
289
180
            }
290
12.9k
            else if( tk->fmt.i_cat == UNKNOWN_ES &&
291
12.9k
                     ( p_pkt != NULL /* Not system */ || b_mpeg2only ) )
292
12.8k
            {
293
12.8k
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV );
294
12.8k
            }
295
17.2k
        }
296
13.0k
        else if( ( i_id&0xe0 ) == 0xc0 ) /* 0xc0 -> 0xdf */
297
6.15k
        {
298
6.15k
            if( i_type == 0x03 ||
299
6.13k
                i_type == 0x04 )
300
18
            {
301
18
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA );
302
18
            }
303
6.13k
            else if( i_type == 0x0f )
304
15
            {
305
15
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A );
306
15
                tk->fmt.i_original_fourcc = VLC_FOURCC('A','D','T','S');
307
15
            }
308
6.11k
            else if( i_type == 0x11 )
309
1.23k
            {
310
1.23k
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A );
311
1.23k
                tk->fmt.i_original_fourcc = VLC_FOURCC('L','A','T','M');
312
1.23k
            }
313
4.88k
            else if( i_type == 0x2d )
314
404
            {
315
404
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPEGH );
316
404
            }
317
4.48k
            else if( tk->fmt.i_cat == UNKNOWN_ES )
318
4.48k
            {
319
4.48k
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA );
320
4.48k
            }
321
6.15k
        }
322
6.91k
        else if( tk->fmt.i_cat == UNKNOWN_ES ) return VLC_EGENERIC;
323
30.3k
    }
324
325
    /* PES packets usually contain truncated frames */
326
49.8k
    tk->fmt.b_packetized = false;
327
49.8k
    tk->fmt.i_priority = ~i_id & 0x0F;
328
329
49.8k
    if( ps_id_to_lang( p_psm, i_id ) )
330
3.85k
    {
331
3.85k
        tk->fmt.psz_language = malloc( 4 );
332
3.85k
        if( tk->fmt.psz_language )
333
3.85k
        {
334
3.85k
            memcpy( tk->fmt.psz_language, ps_id_to_lang( p_psm , i_id ), 3 );
335
3.85k
            tk->fmt.psz_language[3] = 0;
336
3.85k
        }
337
3.85k
    }
338
339
49.8k
    return (tk->fmt.i_cat != UNKNOWN_ES || p_pkt) ? VLC_SUCCESS : VLC_EGENERIC;
340
60.1k
}
ps.c:ps_track_fill
Line
Count
Source
148
60.1k
{
149
60.1k
    tk->i_skip = 0;
150
60.1k
    tk->i_id = i_id;
151
152
60.1k
    if( ( i_id&0xff00 ) == PS_PACKET_ID_MASK_VOB ) /* 0xBD00 -> 0xBDFF, VOB Private Stream 1 */
153
24.9k
    {
154
24.9k
        if( ( i_id&0xf8 ) == 0x88 || /* 0x88 -> 0x8f - Can be DTS-HD primary audio in evob */
155
24.8k
            ( i_id&0xf8 ) == 0x98 )  /* 0x98 -> 0x9f - Can be DTS-HD secondary audio in evob */
156
468
        {
157
468
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DTS );
158
468
            tk->i_skip = 4;
159
468
        }
160
24.5k
        else if( ( i_id&0xf8 ) == 0x80 || /* 0x80 -> 0x87 */
161
22.1k
                 ( i_id&0xf0 ) == 0xc0 )  /* 0xc0 -> 0xcf AC-3, Can also be DD+/E-AC3 in evob */
162
4.09k
        {
163
4.09k
            bool b_eac3 = false;
164
4.09k
            if( ( i_id&0xf0 ) == 0xc0 )
165
1.73k
            {
166
1.73k
                if( p_pkt == NULL || i_pkt < 9 )
167
0
                    return VLC_EGENERIC;
168
169
1.73k
                unsigned i_start = 9 + p_pkt[8];
170
1.73k
                if( i_start + 9 < i_pkt )
171
1.72k
                    b_eac3 = ps_is_EAC3( &p_pkt[i_start + 4], i_pkt - i_start - 4 );
172
1.73k
            }
173
174
4.09k
            es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 );
175
4.09k
            tk->i_skip = 4;
176
4.09k
        }
177
20.4k
        else if( ( i_id&0xfc ) == 0x00 ) /* 0x00 -> 0x03 */
178
6.10k
        {
179
6.10k
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_CVD );
180
6.10k
        }
181
14.3k
        else if( ( i_id&0xff ) == 0x0b ) /* 0x0b */
182
2.31k
        {
183
2.31k
            bool b_eac3 = i_pkt > 8 && ps_is_EAC3( &p_pkt[9], i_pkt - 9 );
184
2.31k
            es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 );
185
2.31k
        }
186
11.9k
        else if( ( i_id&0xff ) == 0x10 ) /* 0x10 */
187
568
        {
188
568
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_TELETEXT );
189
568
        }
190
11.4k
        else if( ( i_id&0xe0 ) == 0x20 ) /* 0x20 -> 0x3f */
191
4.48k
        {
192
4.48k
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_SPU );
193
4.48k
            tk->i_skip = 1;
194
4.48k
        }
195
6.92k
        else if( ( i_id&0xff ) == 0x70 ) /* 0x70 */
196
905
        {
197
905
            es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_OGT );
198
905
        }
199
6.02k
        else if( ( i_id&0xf0 ) == 0xa0 ) /* 0xa0 -> 0xaf */
200
622
        {
201
622
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVD_LPCM );
202
622
            tk->i_skip = 1;
203
622
        }
204
5.39k
        else if( ( i_id&0xf0 ) == 0xb0 ) /* 0xb0 -> 0xbf */
205
2.51k
        {
206
2.51k
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_TRUEHD );
207
2.51k
            tk->i_skip = 5;
208
2.51k
        }
209
2.88k
        else
210
2.88k
        {
211
2.88k
            es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
212
2.88k
            return VLC_EGENERIC;
213
2.88k
        }
214
24.9k
    }
215
35.1k
    else if( (i_id&0xff00) == PS_PACKET_ID_MASK_EXTENDED ) /* EVOB: 0xFD00 -> 0xFDFF */
216
1.47k
    {
217
1.47k
        uint8_t i_sub_id = i_id & 0xff;
218
1.47k
        if( ( i_sub_id >= 0x55 && i_sub_id <= 0x5f ) || /* Can be primary VC-1 in evob */
219
1.37k
            ( i_sub_id >= 0x75 && i_sub_id <= 0x7f ) )  /* Secondary VC-1 */
220
979
        {
221
979
            es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_VC1 );
222
979
        }
223
496
        else
224
496
        {
225
496
            es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
226
496
            return VLC_EGENERIC;
227
496
        }
228
1.47k
    }
229
33.7k
    else if( (i_id&0xff00) == PS_PACKET_ID_MASK_AOB ) /* AOB: 0xA000 -> 0xA0FF */
230
3.36k
    {
231
3.36k
        uint8_t i_sub_id = i_id & 0x07;
232
3.36k
        if( i_sub_id == 0 )
233
3.36k
        {
234
3.36k
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVDA_LPCM );
235
3.36k
            tk->i_skip = 1;
236
3.36k
        }
237
0
        else if( i_sub_id == 1 )
238
0
        {
239
0
            es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MLP );
240
0
            tk->i_skip = -1; /* It's a hack for variable skip value */
241
0
        }
242
0
        else
243
0
        {
244
0
            es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
245
0
            return VLC_EGENERIC;
246
0
        }
247
3.36k
    }
248
30.3k
    else
249
30.3k
    {
250
30.3k
        int i_type = ps_id_to_type( p_psm , i_id );
251
252
30.3k
        es_format_Change( &tk->fmt, UNKNOWN_ES, 0 );
253
254
30.3k
        if( (i_id&0xf0) == 0xe0 ) /* 0xe0 -> 0xef */
255
17.2k
        {
256
17.2k
            if( i_type == 0x01 )
257
34
            {
258
34
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV );
259
34
                tk->fmt.i_original_fourcc = VLC_CODEC_MP1V;
260
34
            }
261
17.2k
            else if( i_type == 0x02 )
262
2
            {
263
2
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV );
264
2
            }
265
17.2k
            else if( i_type == 0x10 )
266
1.29k
            {
267
1.29k
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MP4V );
268
1.29k
            }
269
15.9k
            else if( i_type == 0x1b )
270
1
            {
271
1
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 );
272
1
            }
273
15.9k
            else if( i_type == 0x24 )
274
771
            {
275
771
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_HEVC );
276
771
            }
277
15.1k
            else if( i_id == 0xe2 || /* Primary H.264 in evob */
278
14.8k
                     i_id == 0xe3 )  /* Secondary H.264 in evob */
279
2.09k
            {
280
2.09k
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 );
281
2.09k
            }
282
13.0k
            else if( p_pkt && i_type == 0x00 && /* Not from PSM */
283
13.0k
                     i_pkt > 9 + 5 &&
284
12.8k
                     i_pkt > 9U + 5 + p_pkt[8] &&
285
12.3k
                     ps_is_H264( &p_pkt[ 9 + p_pkt[8] ],
286
12.3k
                                  i_pkt - 9 - p_pkt[8] ) )
287
180
            {
288
180
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 );
289
180
            }
290
12.9k
            else if( tk->fmt.i_cat == UNKNOWN_ES &&
291
12.9k
                     ( p_pkt != NULL /* Not system */ || b_mpeg2only ) )
292
12.8k
            {
293
12.8k
                es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV );
294
12.8k
            }
295
17.2k
        }
296
13.0k
        else if( ( i_id&0xe0 ) == 0xc0 ) /* 0xc0 -> 0xdf */
297
6.15k
        {
298
6.15k
            if( i_type == 0x03 ||
299
6.13k
                i_type == 0x04 )
300
18
            {
301
18
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA );
302
18
            }
303
6.13k
            else if( i_type == 0x0f )
304
15
            {
305
15
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A );
306
15
                tk->fmt.i_original_fourcc = VLC_FOURCC('A','D','T','S');
307
15
            }
308
6.11k
            else if( i_type == 0x11 )
309
1.23k
            {
310
1.23k
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A );
311
1.23k
                tk->fmt.i_original_fourcc = VLC_FOURCC('L','A','T','M');
312
1.23k
            }
313
4.88k
            else if( i_type == 0x2d )
314
404
            {
315
404
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPEGH );
316
404
            }
317
4.48k
            else if( tk->fmt.i_cat == UNKNOWN_ES )
318
4.48k
            {
319
4.48k
                es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA );
320
4.48k
            }
321
6.15k
        }
322
6.91k
        else if( tk->fmt.i_cat == UNKNOWN_ES ) return VLC_EGENERIC;
323
30.3k
    }
324
325
    /* PES packets usually contain truncated frames */
326
49.8k
    tk->fmt.b_packetized = false;
327
49.8k
    tk->fmt.i_priority = ~i_id & 0x0F;
328
329
49.8k
    if( ps_id_to_lang( p_psm, i_id ) )
330
3.85k
    {
331
3.85k
        tk->fmt.psz_language = malloc( 4 );
332
3.85k
        if( tk->fmt.psz_language )
333
3.85k
        {
334
3.85k
            memcpy( tk->fmt.psz_language, ps_id_to_lang( p_psm , i_id ), 3 );
335
3.85k
            tk->fmt.psz_language[3] = 0;
336
3.85k
        }
337
3.85k
    }
338
339
49.8k
    return (tk->fmt.i_cat != UNKNOWN_ES || p_pkt) ? VLC_SUCCESS : VLC_EGENERIC;
340
60.1k
}
Unexecuted instantiation: vobsub.c:ps_track_fill
341
342
/* return the id of a PES (should be valid) */
343
static inline int ps_pkt_id( const uint8_t *p_pkt, size_t i_pkt, enum ps_source source )
344
181k
{
345
181k
    if(unlikely(i_pkt < 4))
346
0
        return 0;
347
181k
    if( p_pkt[3] == STREAM_ID_PRIVATE_STREAM_1 )
348
90.5k
    {
349
90.5k
        uint8_t i_sub_id = 0;
350
90.5k
        if( i_pkt >= 9 &&
351
90.5k
            i_pkt > 9 + (size_t)p_pkt[8] )
352
81.1k
        {
353
81.1k
            const unsigned i_start = 9 + p_pkt[8];
354
81.1k
            i_sub_id = p_pkt[i_start];
355
356
81.1k
            if( i_sub_id == 0xa0 &&
357
9.15k
                i_pkt >= i_start + 7 &&
358
9.01k
                p_pkt[i_start + 6] != 0x80 )
359
9.01k
            {
360
                /* AOB LPCM extension */
361
9.01k
                return PS_PACKET_ID_MASK_AOB | (i_sub_id & 0x01);
362
9.01k
            }
363
364
72.1k
            if( i_sub_id == 0xa1 &&
365
787
                source == PS_SOURCE_AOB )
366
0
            {
367
                /* AOB MLP extension */
368
0
                return PS_PACKET_ID_MASK_AOB | (i_sub_id & 0x01);
369
0
            }
370
72.1k
        }
371
372
        /* VOB extension */
373
81.5k
        return PS_PACKET_ID_MASK_VOB | i_sub_id;
374
90.5k
    }
375
90.9k
    if( i_pkt >= 9 &&
376
86.1k
             p_pkt[3] == STREAM_ID_EXTENDED_STREAM_ID &&
377
7.25k
             (p_pkt[6]&0xC0) == 0x80 &&   /* mpeg2 */
378
2.18k
             (p_pkt[7]&0x01) == 0x01 )    /* extension_flag */
379
2.17k
    {
380
        /* ISO 13818 amendment 2 and SMPTE RP 227 */
381
2.17k
        const uint8_t i_flags = p_pkt[7];
382
2.17k
        unsigned int i_skip = 9;
383
384
        /* Find PES extension */
385
2.17k
        if( (i_flags & 0x80 ) )
386
2.09k
        {
387
2.09k
            i_skip += 5;        /* pts */
388
2.09k
            if( (i_flags & 0x40) )
389
2.09k
                i_skip += 5;    /* dts */
390
2.09k
        }
391
2.17k
        if( (i_flags & 0x20 ) )
392
2.10k
            i_skip += 6;
393
2.17k
        if( (i_flags & 0x10 ) )
394
2.10k
            i_skip += 3;
395
2.17k
        if( (i_flags & 0x08 ) )
396
2.08k
            i_skip += 1;
397
2.17k
        if( (i_flags & 0x04 ) )
398
2.15k
            i_skip += 1;
399
2.17k
        if( (i_flags & 0x02 ) )
400
2.03k
            i_skip += 2;
401
402
2.17k
        if( i_skip < i_pkt && (p_pkt[i_skip]&0x01) )
403
1.91k
        {
404
1.91k
            const uint8_t i_flags2 = p_pkt[i_skip];
405
406
            /* Find PES extension 2 */
407
1.91k
            i_skip += 1;
408
1.91k
            if( i_flags2 & 0x80 )
409
44
                i_skip += 16;
410
1.91k
            if( (i_flags2 & 0x40) && i_skip < i_pkt )
411
109
                i_skip += 1 + p_pkt[i_skip];
412
1.91k
            if( i_flags2 & 0x20 )
413
157
                i_skip += 2;
414
1.91k
            if( i_flags2 & 0x10 )
415
313
                i_skip += 2;
416
417
1.91k
            if( i_skip + 1 < i_pkt )
418
1.90k
            {
419
1.90k
                const int i_extension_field_length = p_pkt[i_skip]&0x7f;
420
1.90k
                if( i_extension_field_length >=1 )
421
1.89k
                {
422
1.89k
                    int i_stream_id_extension_flag = (p_pkt[i_skip+1] >> 7)&0x1;
423
1.89k
                    if( i_stream_id_extension_flag == 0 )
424
1.86k
                        return PS_PACKET_ID_MASK_EXTENDED | (p_pkt[i_skip+1]&0x7f);
425
1.89k
                }
426
1.90k
            }
427
1.91k
        }
428
2.17k
    }
429
89.0k
    return p_pkt[3];
430
90.9k
}
ps.c:ps_pkt_id
Line
Count
Source
344
181k
{
345
181k
    if(unlikely(i_pkt < 4))
346
0
        return 0;
347
181k
    if( p_pkt[3] == STREAM_ID_PRIVATE_STREAM_1 )
348
90.5k
    {
349
90.5k
        uint8_t i_sub_id = 0;
350
90.5k
        if( i_pkt >= 9 &&
351
90.5k
            i_pkt > 9 + (size_t)p_pkt[8] )
352
81.1k
        {
353
81.1k
            const unsigned i_start = 9 + p_pkt[8];
354
81.1k
            i_sub_id = p_pkt[i_start];
355
356
81.1k
            if( i_sub_id == 0xa0 &&
357
9.15k
                i_pkt >= i_start + 7 &&
358
9.01k
                p_pkt[i_start + 6] != 0x80 )
359
9.01k
            {
360
                /* AOB LPCM extension */
361
9.01k
                return PS_PACKET_ID_MASK_AOB | (i_sub_id & 0x01);
362
9.01k
            }
363
364
72.1k
            if( i_sub_id == 0xa1 &&
365
787
                source == PS_SOURCE_AOB )
366
0
            {
367
                /* AOB MLP extension */
368
0
                return PS_PACKET_ID_MASK_AOB | (i_sub_id & 0x01);
369
0
            }
370
72.1k
        }
371
372
        /* VOB extension */
373
81.5k
        return PS_PACKET_ID_MASK_VOB | i_sub_id;
374
90.5k
    }
375
90.9k
    if( i_pkt >= 9 &&
376
86.1k
             p_pkt[3] == STREAM_ID_EXTENDED_STREAM_ID &&
377
7.25k
             (p_pkt[6]&0xC0) == 0x80 &&   /* mpeg2 */
378
2.18k
             (p_pkt[7]&0x01) == 0x01 )    /* extension_flag */
379
2.17k
    {
380
        /* ISO 13818 amendment 2 and SMPTE RP 227 */
381
2.17k
        const uint8_t i_flags = p_pkt[7];
382
2.17k
        unsigned int i_skip = 9;
383
384
        /* Find PES extension */
385
2.17k
        if( (i_flags & 0x80 ) )
386
2.09k
        {
387
2.09k
            i_skip += 5;        /* pts */
388
2.09k
            if( (i_flags & 0x40) )
389
2.09k
                i_skip += 5;    /* dts */
390
2.09k
        }
391
2.17k
        if( (i_flags & 0x20 ) )
392
2.10k
            i_skip += 6;
393
2.17k
        if( (i_flags & 0x10 ) )
394
2.10k
            i_skip += 3;
395
2.17k
        if( (i_flags & 0x08 ) )
396
2.08k
            i_skip += 1;
397
2.17k
        if( (i_flags & 0x04 ) )
398
2.15k
            i_skip += 1;
399
2.17k
        if( (i_flags & 0x02 ) )
400
2.03k
            i_skip += 2;
401
402
2.17k
        if( i_skip < i_pkt && (p_pkt[i_skip]&0x01) )
403
1.91k
        {
404
1.91k
            const uint8_t i_flags2 = p_pkt[i_skip];
405
406
            /* Find PES extension 2 */
407
1.91k
            i_skip += 1;
408
1.91k
            if( i_flags2 & 0x80 )
409
44
                i_skip += 16;
410
1.91k
            if( (i_flags2 & 0x40) && i_skip < i_pkt )
411
109
                i_skip += 1 + p_pkt[i_skip];
412
1.91k
            if( i_flags2 & 0x20 )
413
157
                i_skip += 2;
414
1.91k
            if( i_flags2 & 0x10 )
415
313
                i_skip += 2;
416
417
1.91k
            if( i_skip + 1 < i_pkt )
418
1.90k
            {
419
1.90k
                const int i_extension_field_length = p_pkt[i_skip]&0x7f;
420
1.90k
                if( i_extension_field_length >=1 )
421
1.89k
                {
422
1.89k
                    int i_stream_id_extension_flag = (p_pkt[i_skip+1] >> 7)&0x1;
423
1.89k
                    if( i_stream_id_extension_flag == 0 )
424
1.86k
                        return PS_PACKET_ID_MASK_EXTENDED | (p_pkt[i_skip+1]&0x7f);
425
1.89k
                }
426
1.90k
            }
427
1.91k
        }
428
2.17k
    }
429
89.0k
    return p_pkt[3];
430
90.9k
}
Unexecuted instantiation: vobsub.c:ps_pkt_id
431
432
/* return the size of the next packet */
433
static inline int ps_pkt_size( const uint8_t *p, int i_peek )
434
207k
{
435
207k
    if( unlikely(i_peek < 4) )
436
0
        return -1;
437
438
207k
    switch( p[3] )
439
207k
    {
440
3.81k
        case PS_STREAM_ID_END_STREAM:
441
3.81k
            return 4;
442
443
4.30k
        case PS_STREAM_ID_PACK_HEADER:
444
4.30k
            if( i_peek > 4 )
445
4.30k
            {
446
4.30k
                if( i_peek >= 14 && (p[4] >> 6) == 0x01 )
447
2.67k
                    return 14 + (p[13]&0x07);
448
1.63k
                if( i_peek >= 12 && (p[4] >> 4) == 0x02 )
449
1.57k
                    return 12;
450
1.63k
            }
451
57
            break;
452
453
2.77k
        case PS_STREAM_ID_SYSTEM_HEADER:
454
33.9k
        case STREAM_ID_PROGRAM_STREAM_MAP:
455
34.4k
        case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
456
199k
        default:
457
199k
            if( i_peek >= 6 )
458
199k
                return 6 + ((p[4]<<8) | p[5] );
459
207k
    }
460
76
    return -1;
461
207k
}
ps.c:ps_pkt_size
Line
Count
Source
434
207k
{
435
207k
    if( unlikely(i_peek < 4) )
436
0
        return -1;
437
438
207k
    switch( p[3] )
439
207k
    {
440
3.81k
        case PS_STREAM_ID_END_STREAM:
441
3.81k
            return 4;
442
443
4.30k
        case PS_STREAM_ID_PACK_HEADER:
444
4.30k
            if( i_peek > 4 )
445
4.30k
            {
446
4.30k
                if( i_peek >= 14 && (p[4] >> 6) == 0x01 )
447
2.67k
                    return 14 + (p[13]&0x07);
448
1.63k
                if( i_peek >= 12 && (p[4] >> 4) == 0x02 )
449
1.57k
                    return 12;
450
1.63k
            }
451
57
            break;
452
453
2.77k
        case PS_STREAM_ID_SYSTEM_HEADER:
454
33.9k
        case STREAM_ID_PROGRAM_STREAM_MAP:
455
34.4k
        case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
456
199k
        default:
457
199k
            if( i_peek >= 6 )
458
199k
                return 6 + ((p[4]<<8) | p[5] );
459
207k
    }
460
76
    return -1;
461
207k
}
Unexecuted instantiation: vobsub.c:ps_pkt_size
462
463
/* parse a PACK PES */
464
static inline int ps_pkt_parse_pack( const uint8_t *p_pkt, size_t i_pkt,
465
                                     vlc_tick_t *pi_scr, int *pi_mux_rate )
466
2.44k
{
467
2.44k
    const uint8_t *p = p_pkt;
468
2.44k
    ts_90khz_t i_scr;
469
2.44k
    if( i_pkt >= 14 && (p[4] >> 6) == 0x01 ) /* 0b01 H.222 MPEG-2 Pack Header */
470
1.48k
    {
471
1.48k
        i_scr = ExtractPackHeaderTimestamp( &p[4] );
472
1.48k
        *pi_mux_rate = ( p[10] << 14 )|( p[11] << 6 )|( p[12] >> 2);
473
1.48k
    }
474
963
    else if( i_pkt >= 12 && (p[4] >> 4) == 0x02 ) /* 0b0010 ISO 11172-1 MPEG-1 Pack Header */
475
963
    {
476
963
        if(!ExtractPESTimestamp( &p[4], 0x02, &i_scr )) /* same bits as PES/PTS */
477
815
            return VLC_EGENERIC;
478
148
        *pi_mux_rate = ( ( p[9]&0x7f )<< 15 )|( p[10] << 7 )|( p[11] >> 1);
479
148
    }
480
0
    else
481
0
    {
482
0
        return VLC_EGENERIC;
483
0
    }
484
1.62k
    *pi_scr = FROM_SCALE( i_scr );
485
1.62k
    return VLC_SUCCESS;
486
2.44k
}
ps.c:ps_pkt_parse_pack
Line
Count
Source
466
2.44k
{
467
2.44k
    const uint8_t *p = p_pkt;
468
2.44k
    ts_90khz_t i_scr;
469
2.44k
    if( i_pkt >= 14 && (p[4] >> 6) == 0x01 ) /* 0b01 H.222 MPEG-2 Pack Header */
470
1.48k
    {
471
1.48k
        i_scr = ExtractPackHeaderTimestamp( &p[4] );
472
1.48k
        *pi_mux_rate = ( p[10] << 14 )|( p[11] << 6 )|( p[12] >> 2);
473
1.48k
    }
474
963
    else if( i_pkt >= 12 && (p[4] >> 4) == 0x02 ) /* 0b0010 ISO 11172-1 MPEG-1 Pack Header */
475
963
    {
476
963
        if(!ExtractPESTimestamp( &p[4], 0x02, &i_scr )) /* same bits as PES/PTS */
477
815
            return VLC_EGENERIC;
478
148
        *pi_mux_rate = ( ( p[9]&0x7f )<< 15 )|( p[10] << 7 )|( p[11] >> 1);
479
148
    }
480
0
    else
481
0
    {
482
0
        return VLC_EGENERIC;
483
0
    }
484
1.62k
    *pi_scr = FROM_SCALE( i_scr );
485
1.62k
    return VLC_SUCCESS;
486
2.44k
}
Unexecuted instantiation: vobsub.c:ps_pkt_parse_pack
487
488
/* Parse a SYSTEM PES */
489
static inline int ps_pkt_parse_system( const uint8_t *p_pkt, size_t i_pkt,
490
                                       ps_psm_t *p_psm,
491
                                       ps_track_t tk[PS_TK_COUNT] )
492
1.34k
{
493
1.34k
    const uint8_t *p = &p_pkt[6 + 3 + 1 + 1 + 1];
494
1.34k
    const uint8_t *p_pktend = &p_pkt[i_pkt];
495
496
    /* System header is not usable if it references private streams (0xBD)
497
     * or 'all audio streams' (0xB8) or 'all video streams' (0xB9) */
498
4.58k
    while( p < p_pktend && (p[0] & 0x80) )
499
3.23k
    {
500
3.23k
        int i_id = p[0];
501
3.23k
        switch( i_id )
502
3.23k
        {
503
13
            case 0xB7:
504
13
                if( p_pktend - p < 6 )
505
1
                    return VLC_EGENERIC;
506
12
                i_id = PS_PACKET_ID_MASK_EXTENDED | (p[2] & 0x7F);
507
12
                p += 6;
508
12
                break;
509
3.22k
            default:
510
3.22k
                if( p_pktend - p < 3 )
511
1
                    return VLC_EGENERIC;
512
3.22k
                p += 3;
513
3.22k
                break;
514
3.23k
        }
515
516
3.23k
        if( i_id < 0xc0 )
517
125
            continue;
518
519
3.11k
        unsigned i_tk = ps_id_to_tk( i_id );
520
3.11k
        if( !tk[i_tk].b_configured )
521
3.06k
            ps_track_fill( &tk[i_tk], p_psm, i_id, NULL, 0, false );
522
3.11k
    }
523
1.34k
    return VLC_SUCCESS;
524
1.34k
}
ps.c:ps_pkt_parse_system
Line
Count
Source
492
1.34k
{
493
1.34k
    const uint8_t *p = &p_pkt[6 + 3 + 1 + 1 + 1];
494
1.34k
    const uint8_t *p_pktend = &p_pkt[i_pkt];
495
496
    /* System header is not usable if it references private streams (0xBD)
497
     * or 'all audio streams' (0xB8) or 'all video streams' (0xB9) */
498
4.58k
    while( p < p_pktend && (p[0] & 0x80) )
499
3.23k
    {
500
3.23k
        int i_id = p[0];
501
3.23k
        switch( i_id )
502
3.23k
        {
503
13
            case 0xB7:
504
13
                if( p_pktend - p < 6 )
505
1
                    return VLC_EGENERIC;
506
12
                i_id = PS_PACKET_ID_MASK_EXTENDED | (p[2] & 0x7F);
507
12
                p += 6;
508
12
                break;
509
3.22k
            default:
510
3.22k
                if( p_pktend - p < 3 )
511
1
                    return VLC_EGENERIC;
512
3.22k
                p += 3;
513
3.22k
                break;
514
3.23k
        }
515
516
3.23k
        if( i_id < 0xc0 )
517
125
            continue;
518
519
3.11k
        unsigned i_tk = ps_id_to_tk( i_id );
520
3.11k
        if( !tk[i_tk].b_configured )
521
3.06k
            ps_track_fill( &tk[i_tk], p_psm, i_id, NULL, 0, false );
522
3.11k
    }
523
1.34k
    return VLC_SUCCESS;
524
1.34k
}
Unexecuted instantiation: vobsub.c:ps_pkt_parse_system
525
526
/* Parse a PES (and skip i_skip_extra in the payload) */
527
static inline int ps_pkt_parse_pes( vlc_object_t *p_object, block_t *p_pes, int i_skip_extra )
528
154k
{
529
154k
    unsigned int i_skip;
530
154k
    ts_pes_header_t pesh;
531
154k
    ts_pes_header_init( &pesh );
532
533
154k
    if( ParsePESHeader( p_object->logger, p_pes->p_buffer, p_pes->i_buffer, &pesh ) != VLC_SUCCESS )
534
36.3k
        return VLC_EGENERIC;
535
536
117k
    i_skip = pesh.i_size;
537
538
117k
    if( pesh.b_scrambling )
539
6.24k
        p_pes->i_flags |= BLOCK_FLAG_SCRAMBLED;
540
541
117k
    if( i_skip_extra >= 0 )
542
117k
        i_skip += i_skip_extra;
543
0
    else if( p_pes->i_buffer > i_skip + 3 &&
544
0
             ( ps_pkt_id( p_pes->p_buffer, p_pes->i_buffer, PS_SOURCE_AOB ) == PS_AOB_PACKET_ID_MLP ||
545
0
               ps_pkt_id( p_pes->p_buffer, p_pes->i_buffer, PS_SOURCE_VOB ) == PS_VOB_PACKET_ID_MLP ) )
546
0
        i_skip += 4 + p_pes->p_buffer[i_skip+3];
547
548
117k
    if( p_pes->i_buffer <= i_skip )
549
3.64k
    {
550
3.64k
        return VLC_EGENERIC;
551
3.64k
    }
552
553
114k
    p_pes->p_buffer += i_skip;
554
114k
    p_pes->i_buffer -= i_skip;
555
556
114k
    if( pesh.i_pts != TS_90KHZ_INVALID )
557
71.4k
    {
558
71.4k
        p_pes->i_pts = FROM_SCALE( pesh.i_pts );
559
71.4k
        if( pesh.i_dts != TS_90KHZ_INVALID )
560
12.4k
            p_pes->i_dts = FROM_SCALE( pesh.i_dts );
561
59.0k
        else /* ISO/IEC 13818-1 2.7.5: if pts and no dts, then dts == pts */
562
59.0k
            p_pes->i_dts = p_pes->i_pts;
563
71.4k
    }
564
565
114k
    return VLC_SUCCESS;
566
117k
}
ps.c:ps_pkt_parse_pes
Line
Count
Source
528
154k
{
529
154k
    unsigned int i_skip;
530
154k
    ts_pes_header_t pesh;
531
154k
    ts_pes_header_init( &pesh );
532
533
154k
    if( ParsePESHeader( p_object->logger, p_pes->p_buffer, p_pes->i_buffer, &pesh ) != VLC_SUCCESS )
534
36.3k
        return VLC_EGENERIC;
535
536
117k
    i_skip = pesh.i_size;
537
538
117k
    if( pesh.b_scrambling )
539
6.24k
        p_pes->i_flags |= BLOCK_FLAG_SCRAMBLED;
540
541
117k
    if( i_skip_extra >= 0 )
542
117k
        i_skip += i_skip_extra;
543
0
    else if( p_pes->i_buffer > i_skip + 3 &&
544
0
             ( ps_pkt_id( p_pes->p_buffer, p_pes->i_buffer, PS_SOURCE_AOB ) == PS_AOB_PACKET_ID_MLP ||
545
0
               ps_pkt_id( p_pes->p_buffer, p_pes->i_buffer, PS_SOURCE_VOB ) == PS_VOB_PACKET_ID_MLP ) )
546
0
        i_skip += 4 + p_pes->p_buffer[i_skip+3];
547
548
117k
    if( p_pes->i_buffer <= i_skip )
549
3.64k
    {
550
3.64k
        return VLC_EGENERIC;
551
3.64k
    }
552
553
114k
    p_pes->p_buffer += i_skip;
554
114k
    p_pes->i_buffer -= i_skip;
555
556
114k
    if( pesh.i_pts != TS_90KHZ_INVALID )
557
71.4k
    {
558
71.4k
        p_pes->i_pts = FROM_SCALE( pesh.i_pts );
559
71.4k
        if( pesh.i_dts != TS_90KHZ_INVALID )
560
12.4k
            p_pes->i_dts = FROM_SCALE( pesh.i_dts );
561
59.0k
        else /* ISO/IEC 13818-1 2.7.5: if pts and no dts, then dts == pts */
562
59.0k
            p_pes->i_dts = p_pes->i_pts;
563
71.4k
    }
564
565
114k
    return VLC_SUCCESS;
566
117k
}
Unexecuted instantiation: vobsub.c:ps_pkt_parse_pes
567
568
typedef struct
569
{
570
    /* Language is iso639-2T */
571
    uint8_t lang[3];
572
} ps_descriptors_t;
573
574
/* Program stream map handling */
575
typedef struct ps_es_t
576
{
577
    uint8_t i_type;
578
    uint16_t i_id;
579
580
    ps_descriptors_t desc;
581
582
} ps_es_t;
583
584
struct ps_psm_t
585
{
586
    uint8_t i_version;
587
588
    size_t  i_es;
589
    ps_es_t *es;
590
591
    ps_descriptors_t uniqueextdesc;
592
};
593
594
static inline uint8_t ps_id_to_type( const ps_psm_t *p_psm, uint16_t i_id )
595
31.9k
{
596
31.9k
    size_t i;
597
74.1k
    for( i = 0; p_psm && i < p_psm->i_es; i++ )
598
46.2k
    {
599
46.2k
        if( p_psm->es[i].i_id == i_id ) return p_psm->es[i].i_type;
600
46.2k
    }
601
27.9k
    return 0;
602
31.9k
}
ps.c:ps_id_to_type
Line
Count
Source
595
31.9k
{
596
31.9k
    size_t i;
597
74.1k
    for( i = 0; p_psm && i < p_psm->i_es; i++ )
598
46.2k
    {
599
46.2k
        if( p_psm->es[i].i_id == i_id ) return p_psm->es[i].i_type;
600
46.2k
    }
601
27.9k
    return 0;
602
31.9k
}
Unexecuted instantiation: vobsub.c:ps_id_to_type
603
604
static inline const uint8_t *ps_id_to_lang( const ps_psm_t *p_psm, uint16_t i_id )
605
53.7k
{
606
53.7k
    size_t i;
607
131k
    for( i = 0; p_psm && i < p_psm->i_es; i++ )
608
85.4k
    {
609
85.4k
        if( p_psm->es[i].i_id == i_id )
610
7.71k
            return p_psm->es[i].desc.lang;
611
85.4k
    }
612
46.0k
    return 0;
613
53.7k
}
ps.c:ps_id_to_lang
Line
Count
Source
605
53.7k
{
606
53.7k
    size_t i;
607
131k
    for( i = 0; p_psm && i < p_psm->i_es; i++ )
608
85.4k
    {
609
85.4k
        if( p_psm->es[i].i_id == i_id )
610
7.71k
            return p_psm->es[i].desc.lang;
611
85.4k
    }
612
46.0k
    return 0;
613
53.7k
}
Unexecuted instantiation: vobsub.c:ps_id_to_lang
614
615
static inline void ps_psm_init( ps_psm_t *p_psm )
616
1.13k
{
617
1.13k
    p_psm->i_version = 0xFF;
618
1.13k
    p_psm->i_es = 0;
619
1.13k
    p_psm->es = 0;
620
1.13k
    memset( &p_psm->uniqueextdesc, 0, 3 );
621
1.13k
}
ps.c:ps_psm_init
Line
Count
Source
616
1.13k
{
617
1.13k
    p_psm->i_version = 0xFF;
618
1.13k
    p_psm->i_es = 0;
619
1.13k
    p_psm->es = 0;
620
1.13k
    memset( &p_psm->uniqueextdesc, 0, 3 );
621
1.13k
}
Unexecuted instantiation: vobsub.c:ps_psm_init
622
623
static inline void ps_psm_destroy( ps_psm_t *p_psm )
624
11.4k
{
625
11.4k
    free( p_psm->es );
626
11.4k
    p_psm->es = NULL;
627
11.4k
    p_psm->i_es = 0;
628
11.4k
}
ps.c:ps_psm_destroy
Line
Count
Source
624
11.4k
{
625
11.4k
    free( p_psm->es );
626
    p_psm->es = NULL;
627
11.4k
    p_psm->i_es = 0;
628
11.4k
}
Unexecuted instantiation: vobsub.c:ps_psm_destroy
629
630
static inline void ps_parse_descriptors( const uint8_t *p_data, size_t i_data,
631
                                        ps_descriptors_t *p_desc )
632
6.13k
{
633
9.98k
    while( i_data > 3 && i_data > 2u + p_data[1] )
634
3.84k
    {
635
3.84k
        switch( p_data[0] )
636
3.84k
        {
637
139
            case 0x0A: /* ISO_639_language_descriptor */
638
139
                if( i_data >= 6 )
639
86
                    memcpy( p_desc->lang, &p_data[2], 3 );
640
139
                break;
641
642
3.70k
            default:
643
3.70k
                break;
644
3.84k
        }
645
3.84k
        uint8_t i_desc_size = p_data[1];
646
3.84k
        p_data += 2 + i_desc_size;
647
3.84k
        i_data -= 2 + i_desc_size;
648
3.84k
    }
649
6.13k
}
ps.c:ps_parse_descriptors
Line
Count
Source
632
6.13k
{
633
9.98k
    while( i_data > 3 && i_data > 2u + p_data[1] )
634
3.84k
    {
635
3.84k
        switch( p_data[0] )
636
3.84k
        {
637
139
            case 0x0A: /* ISO_639_language_descriptor */
638
139
                if( i_data >= 6 )
639
86
                    memcpy( p_desc->lang, &p_data[2], 3 );
640
139
                break;
641
642
3.70k
            default:
643
3.70k
                break;
644
3.84k
        }
645
3.84k
        uint8_t i_desc_size = p_data[1];
646
3.84k
        p_data += 2 + i_desc_size;
647
3.84k
        i_data -= 2 + i_desc_size;
648
3.84k
    }
649
6.13k
}
Unexecuted instantiation: vobsub.c:ps_parse_descriptors
650
651
static inline int ps_psm_fill( ps_psm_t *p_psm,
652
                               const uint8_t *p_buffer, size_t i_pkt,
653
                               ps_track_t tk[PS_TK_COUNT])
654
16.6k
{
655
16.6k
    size_t i_length, i_info_length, i_es_base;
656
16.6k
    uint8_t i_version;
657
16.6k
    bool b_single_extension;
658
659
    // Demux() checks that we have at least 4 bytes, but we need
660
    // at least 10 to read up to the info_length field
661
16.6k
    assert(i_pkt >= 4);
662
16.6k
    if( !p_psm || i_pkt < 10 || p_buffer[3] != STREAM_ID_PROGRAM_STREAM_MAP)
663
4
        return VLC_EGENERIC;
664
665
16.6k
    i_length = GetWBE(&p_buffer[4]) + 6;
666
16.6k
    if( i_length > i_pkt ) return VLC_EGENERIC;
667
668
16.6k
    if((p_buffer[6] & 0x80) == 0) /* current_next_indicator */
669
351
        return VLC_EGENERIC;
670
671
16.3k
    b_single_extension = p_buffer[6] & 0x40;
672
16.3k
    i_version = (p_buffer[6] & 0xf8);
673
674
16.3k
    if( p_psm->i_version == i_version ) return VLC_EGENERIC;
675
676
10.3k
    ps_psm_destroy( p_psm );
677
678
10.3k
    i_info_length = GetWBE(&p_buffer[8]);
679
10.3k
    if( i_info_length + 10 > i_length )
680
2.52k
        return VLC_EGENERIC;
681
682
    /* Elementary stream map */
683
    /* int i_esm_length = (uint16_t)(p_buffer[ 10 + i_info_length ] << 8) +
684
        p_buffer[ 11 + i_info_length]; */
685
7.79k
    i_es_base = 12 + i_info_length;
686
687
13.9k
    while( i_es_base + 4 < i_length )
688
13.0k
    {
689
13.0k
        ps_es_t *tmp_es = realloc( p_psm->es, sizeof(ps_es_t) * (p_psm->i_es+1) );
690
13.0k
        if( tmp_es == NULL )
691
0
            break;
692
13.0k
        p_psm->es = tmp_es;
693
694
13.0k
        ps_es_t *p_es = &p_psm->es[ p_psm->i_es++ ];
695
13.0k
        p_es->i_type = p_buffer[ i_es_base  ];
696
13.0k
        p_es->i_id = p_buffer[ i_es_base + 1 ];
697
698
13.0k
        i_info_length = GetWBE(&p_buffer[ i_es_base + 2 ]);
699
700
13.0k
        if( i_es_base + 4 + i_info_length > i_length )
701
6.88k
            break;
702
703
        /* TODO Add support for VC-1 stream:
704
         *      stream_type=0xea, stream_id=0xfd AND registration
705
         *      descriptor 0x5 with format_identifier == 0x56432D31 (VC-1)
706
         *      (I need a sample that use PSM with VC-1) */
707
708
6.19k
        if( p_es->i_id == STREAM_ID_EXTENDED_STREAM_ID && b_single_extension == 0 )
709
88
        {
710
88
            if( i_info_length < 3 )
711
64
                break;
712
24
            p_es->i_id = (p_es->i_id << 8) | (p_buffer[i_es_base + 6] & 0x7F);
713
24
            ps_parse_descriptors( &p_buffer[i_es_base + 4 + 3],
714
24
                                  i_info_length - 3,
715
24
                                  &p_psm->uniqueextdesc );
716
24
        }
717
6.10k
        else
718
6.10k
        {
719
6.10k
            ps_parse_descriptors( &p_buffer[i_es_base + 4],
720
6.10k
                                  i_info_length, &p_es->desc );
721
6.10k
        }
722
723
6.13k
        i_es_base += 4 + i_info_length;
724
6.13k
    }
725
726
    /* TODO: CRC */
727
728
7.79k
    p_psm->i_version = i_version;
729
730
    /* Check/Modify our existing tracks */
731
4.55M
    for( int i = 0; i < PS_TK_COUNT; i++ )
732
4.54M
    {
733
4.54M
        if( !tk[i].b_configured )
734
4.50M
            continue;
735
736
45.9k
        ps_track_t tk_tmp;
737
45.9k
        es_format_Init( &tk_tmp.fmt, UNKNOWN_ES, 0 );
738
739
45.9k
        if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id,
740
45.9k
                           p_buffer, i_pkt, false ) != VLC_SUCCESS )
741
0
            continue;
742
743
45.9k
        if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec )
744
38.7k
        {
745
38.7k
            es_format_Clean( &tk_tmp.fmt );
746
38.7k
            continue;
747
38.7k
        }
748
749
        /* replace with new version */
750
7.23k
        tk_tmp.b_configured = true;
751
7.23k
        tk_tmp.b_updated = true;
752
7.23k
        tk_tmp.es = tk[i].es;
753
7.23k
        es_format_Clean( &tk[i].fmt );
754
7.23k
        tk[i] = tk_tmp;
755
7.23k
    }
756
757
7.79k
    return VLC_SUCCESS;
758
10.3k
}
ps.c:ps_psm_fill
Line
Count
Source
654
16.6k
{
655
16.6k
    size_t i_length, i_info_length, i_es_base;
656
16.6k
    uint8_t i_version;
657
16.6k
    bool b_single_extension;
658
659
    // Demux() checks that we have at least 4 bytes, but we need
660
    // at least 10 to read up to the info_length field
661
16.6k
    assert(i_pkt >= 4);
662
16.6k
    if( !p_psm || i_pkt < 10 || p_buffer[3] != STREAM_ID_PROGRAM_STREAM_MAP)
663
4
        return VLC_EGENERIC;
664
665
16.6k
    i_length = GetWBE(&p_buffer[4]) + 6;
666
16.6k
    if( i_length > i_pkt ) return VLC_EGENERIC;
667
668
16.6k
    if((p_buffer[6] & 0x80) == 0) /* current_next_indicator */
669
351
        return VLC_EGENERIC;
670
671
16.3k
    b_single_extension = p_buffer[6] & 0x40;
672
16.3k
    i_version = (p_buffer[6] & 0xf8);
673
674
16.3k
    if( p_psm->i_version == i_version ) return VLC_EGENERIC;
675
676
10.3k
    ps_psm_destroy( p_psm );
677
678
10.3k
    i_info_length = GetWBE(&p_buffer[8]);
679
10.3k
    if( i_info_length + 10 > i_length )
680
2.52k
        return VLC_EGENERIC;
681
682
    /* Elementary stream map */
683
    /* int i_esm_length = (uint16_t)(p_buffer[ 10 + i_info_length ] << 8) +
684
        p_buffer[ 11 + i_info_length]; */
685
7.79k
    i_es_base = 12 + i_info_length;
686
687
13.9k
    while( i_es_base + 4 < i_length )
688
13.0k
    {
689
13.0k
        ps_es_t *tmp_es = realloc( p_psm->es, sizeof(ps_es_t) * (p_psm->i_es+1) );
690
13.0k
        if( tmp_es == NULL )
691
0
            break;
692
13.0k
        p_psm->es = tmp_es;
693
694
13.0k
        ps_es_t *p_es = &p_psm->es[ p_psm->i_es++ ];
695
13.0k
        p_es->i_type = p_buffer[ i_es_base  ];
696
13.0k
        p_es->i_id = p_buffer[ i_es_base + 1 ];
697
698
13.0k
        i_info_length = GetWBE(&p_buffer[ i_es_base + 2 ]);
699
700
13.0k
        if( i_es_base + 4 + i_info_length > i_length )
701
6.88k
            break;
702
703
        /* TODO Add support for VC-1 stream:
704
         *      stream_type=0xea, stream_id=0xfd AND registration
705
         *      descriptor 0x5 with format_identifier == 0x56432D31 (VC-1)
706
         *      (I need a sample that use PSM with VC-1) */
707
708
6.19k
        if( p_es->i_id == STREAM_ID_EXTENDED_STREAM_ID && b_single_extension == 0 )
709
88
        {
710
88
            if( i_info_length < 3 )
711
64
                break;
712
24
            p_es->i_id = (p_es->i_id << 8) | (p_buffer[i_es_base + 6] & 0x7F);
713
24
            ps_parse_descriptors( &p_buffer[i_es_base + 4 + 3],
714
24
                                  i_info_length - 3,
715
24
                                  &p_psm->uniqueextdesc );
716
24
        }
717
6.10k
        else
718
6.10k
        {
719
6.10k
            ps_parse_descriptors( &p_buffer[i_es_base + 4],
720
6.10k
                                  i_info_length, &p_es->desc );
721
6.10k
        }
722
723
6.13k
        i_es_base += 4 + i_info_length;
724
6.13k
    }
725
726
    /* TODO: CRC */
727
728
7.79k
    p_psm->i_version = i_version;
729
730
    /* Check/Modify our existing tracks */
731
4.55M
    for( int i = 0; i < PS_TK_COUNT; i++ )
732
4.54M
    {
733
4.54M
        if( !tk[i].b_configured )
734
4.50M
            continue;
735
736
45.9k
        ps_track_t tk_tmp;
737
45.9k
        es_format_Init( &tk_tmp.fmt, UNKNOWN_ES, 0 );
738
739
45.9k
        if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id,
740
45.9k
                           p_buffer, i_pkt, false ) != VLC_SUCCESS )
741
0
            continue;
742
743
45.9k
        if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec )
744
38.7k
        {
745
38.7k
            es_format_Clean( &tk_tmp.fmt );
746
38.7k
            continue;
747
38.7k
        }
748
749
        /* replace with new version */
750
7.23k
        tk_tmp.b_configured = true;
751
7.23k
        tk_tmp.b_updated = true;
752
7.23k
        tk_tmp.es = tk[i].es;
753
7.23k
        es_format_Clean( &tk[i].fmt );
754
7.23k
        tk[i] = tk_tmp;
755
7.23k
    }
756
757
7.79k
    return VLC_SUCCESS;
758
10.3k
}
Unexecuted instantiation: vobsub.c:ps_psm_fill