Coverage Report

Created: 2026-12-01 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/demux/mpeg/pes.h
Line
Count
Source
1
/*****************************************************************************
2
 * pes.h: PES Packet helpers
3
 *****************************************************************************
4
 * Copyright (C) 2004-2015 VLC authors and VideoLAN
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
#ifndef VLC_MPEG_PES_H
21
#define VLC_MPEG_PES_H
22
23
#include "timestamps.h"
24
25
283k
#define STREAM_ID_PROGRAM_STREAM_MAP         0xBC
26
2.16M
#define STREAM_ID_PRIVATE_STREAM_1           0xBD
27
4.12k
#define STREAM_ID_PADDING                    0xBE
28
3.11k
#define STREAM_ID_PRIVATE_STREAM_2           0xBF
29
#define STREAM_ID_AUDIO_STREAM_0             0xC0
30
#define STREAM_ID_VIDEO_STREAM_0             0xE0
31
3.91k
#define STREAM_ID_ECM                        0xF0
32
4.43k
#define STREAM_ID_EMM                        0xF1
33
10.9k
#define STREAM_ID_DSM_CC                     0xF2
34
12.2k
#define STREAM_ID_H222_1_TYPE_E              0xF8
35
#define STREAM_ID_METADATA_STREAM            0xFC
36
2.42M
#define STREAM_ID_EXTENDED_STREAM_ID         0xFD
37
139k
#define STREAM_ID_PROGRAM_STREAM_DIRECTORY   0xFF
38
39
/* MPEG-2 PTS/DTS */
40
static inline ts_90khz_t GetPESTimestamp( const uint8_t *p_data )
41
2.36M
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
2.36M
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
2.36M
             (ts_90khz_t)(p_data[1] << 22)|
45
2.36M
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
2.36M
             (ts_90khz_t)(p_data[3] << 7)|
47
2.36M
             (ts_90khz_t)(p_data[4] >> 1);
48
2.36M
}
ps.c:GetPESTimestamp
Line
Count
Source
41
689k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
689k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
689k
             (ts_90khz_t)(p_data[1] << 22)|
45
689k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
689k
             (ts_90khz_t)(p_data[3] << 7)|
47
689k
             (ts_90khz_t)(p_data[4] >> 1);
48
689k
}
pva.c:GetPESTimestamp
Line
Count
Source
41
1.38M
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
1.38M
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
1.38M
             (ts_90khz_t)(p_data[1] << 22)|
45
1.38M
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
1.38M
             (ts_90khz_t)(p_data[3] << 7)|
47
1.38M
             (ts_90khz_t)(p_data[4] >> 1);
48
1.38M
}
Unexecuted instantiation: ty.c:GetPESTimestamp
Unexecuted instantiation: vobsub.c:GetPESTimestamp
ts.c:GetPESTimestamp
Line
Count
Source
41
283k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
283k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
283k
             (ts_90khz_t)(p_data[1] << 22)|
45
283k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
283k
             (ts_90khz_t)(p_data[3] << 7)|
47
283k
             (ts_90khz_t)(p_data[4] >> 1);
48
283k
}
ts_hotfixes.c:GetPESTimestamp
Line
Count
Source
41
10.5k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
10.5k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
10.5k
             (ts_90khz_t)(p_data[1] << 22)|
45
10.5k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
10.5k
             (ts_90khz_t)(p_data[3] << 7)|
47
10.5k
             (ts_90khz_t)(p_data[4] >> 1);
48
10.5k
}
49
50
static inline bool ExtractPESTimestamp( const uint8_t *p_data, uint8_t i_flags, ts_90khz_t *ret )
51
1.79M
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
1.79M
    if((p_data[0] & 0xC1) != 0x01 ||
55
1.29M
       (p_data[2] & 0x01) != 0x01 ||
56
1.14M
       (p_data[4] & 0x01) != 0x01 ||
57
985k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
983k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
809k
        return false;
60
61
62
983k
    *ret =  GetPESTimestamp( p_data );
63
983k
    return true;
64
1.79M
}
ps.c:ExtractPESTimestamp
Line
Count
Source
51
1.29M
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
1.29M
    if((p_data[0] & 0xC1) != 0x01 ||
55
897k
       (p_data[2] & 0x01) != 0x01 ||
56
797k
       (p_data[4] & 0x01) != 0x01 ||
57
690k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
689k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
602k
        return false;
60
61
62
689k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
1.29M
}
Unexecuted instantiation: pva.c:ExtractPESTimestamp
Unexecuted instantiation: ty.c:ExtractPESTimestamp
Unexecuted instantiation: vobsub.c:ExtractPESTimestamp
ts.c:ExtractPESTimestamp
Line
Count
Source
51
479k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
479k
    if((p_data[0] & 0xC1) != 0x01 ||
55
385k
       (p_data[2] & 0x01) != 0x01 ||
56
332k
       (p_data[4] & 0x01) != 0x01 ||
57
283k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
283k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
196k
        return false;
60
61
62
283k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
479k
}
ts_hotfixes.c:ExtractPESTimestamp
Line
Count
Source
51
20.5k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
20.5k
    if((p_data[0] & 0xC1) != 0x01 ||
55
13.5k
       (p_data[2] & 0x01) != 0x01 ||
56
11.8k
       (p_data[4] & 0x01) != 0x01 ||
57
10.8k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
10.5k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
9.91k
        return false;
60
61
62
10.5k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
20.5k
}
65
66
/* PS SCR timestamp as defined in H222 2.5.3.2 */
67
static inline ts_90khz_t ExtractPackHeaderTimestamp( const uint8_t *p_data )
68
36.6k
{
69
    /* prefixed by 2 bits 01 */
70
36.6k
    return  ((ts_90khz_t)(p_data[0]&0x38 ) << 27)|
71
36.6k
            ((ts_90khz_t)(p_data[0]&0x03 ) << 28)|
72
36.6k
             (ts_90khz_t)(p_data[1] << 20)|
73
36.6k
            ((ts_90khz_t)(p_data[2]&0xf8 ) << 12)|
74
36.6k
            ((ts_90khz_t)(p_data[2]&0x03 ) << 13)|
75
36.6k
             (ts_90khz_t)(p_data[3] << 5) |
76
36.6k
             (ts_90khz_t)(p_data[4] >> 3);
77
36.6k
}
ps.c:ExtractPackHeaderTimestamp
Line
Count
Source
68
36.6k
{
69
    /* prefixed by 2 bits 01 */
70
36.6k
    return  ((ts_90khz_t)(p_data[0]&0x38 ) << 27)|
71
36.6k
            ((ts_90khz_t)(p_data[0]&0x03 ) << 28)|
72
36.6k
             (ts_90khz_t)(p_data[1] << 20)|
73
36.6k
            ((ts_90khz_t)(p_data[2]&0xf8 ) << 12)|
74
36.6k
            ((ts_90khz_t)(p_data[2]&0x03 ) << 13)|
75
36.6k
             (ts_90khz_t)(p_data[3] << 5) |
76
36.6k
             (ts_90khz_t)(p_data[4] >> 3);
77
36.6k
}
Unexecuted instantiation: pva.c:ExtractPackHeaderTimestamp
Unexecuted instantiation: ty.c:ExtractPackHeaderTimestamp
Unexecuted instantiation: vobsub.c:ExtractPackHeaderTimestamp
Unexecuted instantiation: ts.c:ExtractPackHeaderTimestamp
Unexecuted instantiation: ts_hotfixes.c:ExtractPackHeaderTimestamp
78
79
typedef struct
80
{
81
    ts_90khz_t i_dts;
82
    ts_90khz_t i_pts;
83
    uint8_t i_stream_id;
84
    bool b_scrambling;
85
    unsigned i_size;
86
} ts_pes_header_t;
87
88
static inline void ts_pes_header_init(ts_pes_header_t *h)
89
2.40M
{
90
2.40M
    h->i_dts = TS_90KHZ_INVALID;
91
2.40M
    h->i_pts = TS_90KHZ_INVALID;
92
2.40M
    h->i_stream_id = 0;
93
2.40M
    h->b_scrambling = false;
94
2.40M
    h->i_size = 0;
95
2.40M
}
ps.c:ts_pes_header_init
Line
Count
Source
89
1.26M
{
90
1.26M
    h->i_dts = TS_90KHZ_INVALID;
91
1.26M
    h->i_pts = TS_90KHZ_INVALID;
92
1.26M
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
1.26M
    h->i_size = 0;
95
1.26M
}
Unexecuted instantiation: pva.c:ts_pes_header_init
Unexecuted instantiation: ty.c:ts_pes_header_init
Unexecuted instantiation: vobsub.c:ts_pes_header_init
ts.c:ts_pes_header_init
Line
Count
Source
89
1.09M
{
90
1.09M
    h->i_dts = TS_90KHZ_INVALID;
91
1.09M
    h->i_pts = TS_90KHZ_INVALID;
92
1.09M
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
1.09M
    h->i_size = 0;
95
1.09M
}
ts_hotfixes.c:ts_pes_header_init
Line
Count
Source
89
49.3k
{
90
49.3k
    h->i_dts = TS_90KHZ_INVALID;
91
49.3k
    h->i_pts = TS_90KHZ_INVALID;
92
49.3k
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
49.3k
    h->i_size = 0;
95
49.3k
}
96
97
inline
98
static int ParsePESHeader( struct vlc_logger *p_logger, const uint8_t *p_header, size_t i_header,
99
                           ts_pes_header_t *h )
100
2.40M
{
101
2.40M
    unsigned i_skip;
102
103
2.40M
    if ( i_header < 9 )
104
11.3k
        return VLC_EGENERIC;
105
106
2.39M
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
17.5k
        return VLC_EGENERIC;
108
109
2.37M
    h->i_stream_id = p_header[3];
110
111
2.37M
    switch( p_header[3] )
112
2.37M
    {
113
442
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
891
    case STREAM_ID_PADDING:
115
3.11k
    case STREAM_ID_PRIVATE_STREAM_2:
116
3.91k
    case STREAM_ID_ECM:
117
4.43k
    case STREAM_ID_EMM:
118
8.98k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
10.9k
    case STREAM_ID_DSM_CC:
120
12.2k
    case STREAM_ID_H222_1_TYPE_E:
121
12.2k
        i_skip = 6;
122
12.2k
        h->b_scrambling = false;
123
12.2k
        break;
124
2.36M
    default:
125
2.36M
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
1.33M
        {
127
            /* mpeg2 PES */
128
            // 9 = syncword(3), stream ID(1), length(2), MPEG2 PES(1), flags(1), header_len(1)
129
            // p_header[8] = header_len(1)
130
1.33M
            i_skip = p_header[8] + 9;
131
132
1.33M
            h->b_scrambling = p_header[6]&0x30;
133
134
1.33M
            if( p_header[7]&0x80 )    /* has pts */
135
504k
            {
136
504k
                if( i_header >= 9 + 5 )
137
497k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
504k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
66.9k
                    i_header >= 14 + 5 )
141
58.7k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
504k
            }
143
1.33M
        }
144
1.02M
        else
145
1.02M
        {
146
            /* FIXME?: WTH do we have undocumented MPEG1 packet stuff here ?
147
               This code path should not be valid, but seems some ppl did
148
               put MPEG1 packets into PS or TS.
149
               Non spec reference for packet format on http://andrewduncan.net/mpeg/mpeg-1.html */
150
1.02M
            i_skip = 6;
151
152
1.02M
            h->b_scrambling = false;
153
154
2.06M
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
1.07M
            {
156
1.07M
                i_skip++;
157
1.07M
                if( i_header < i_skip + 1 )
158
41.1k
                    return VLC_EGENERIC;
159
1.07M
            }
160
988k
            if( i_skip == 23 )
161
3.37k
            {
162
3.37k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
3.37k
                return VLC_EGENERIC;
164
3.37k
            }
165
            /* Skip STD buffer size */
166
984k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
49.8k
            {
168
49.8k
                i_skip += 2;
169
49.8k
            }
170
171
984k
            if( i_header < i_skip + 1 )
172
384
                return VLC_EGENERIC;
173
174
984k
            if(  p_header[i_skip]&0x20 )
175
811k
            {
176
811k
                if( i_header >= i_skip + 5 )
177
802k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
811k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
460k
                    i_header >= i_skip + 10 )
181
430k
                {
182
430k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
430k
                    i_skip += 10;
184
430k
                }
185
380k
                else
186
380k
                {
187
380k
                    i_skip += 5;
188
380k
                }
189
811k
            }
190
173k
            else
191
173k
            {
192
173k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
171k
                    return VLC_EGENERIC;
194
1.81k
                i_skip += 1;
195
1.81k
            }
196
984k
        }
197
2.15M
        break;
198
2.37M
    }
199
200
2.16M
    h->i_size = i_skip;
201
2.16M
    return VLC_SUCCESS;
202
2.37M
}
ps.c:ParsePESHeader
Line
Count
Source
100
1.26M
{
101
1.26M
    unsigned i_skip;
102
103
1.26M
    if ( i_header < 9 )
104
8.52k
        return VLC_EGENERIC;
105
106
1.25M
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
0
        return VLC_EGENERIC;
108
109
1.25M
    h->i_stream_id = p_header[3];
110
111
1.25M
    switch( p_header[3] )
112
1.25M
    {
113
0
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
0
    case STREAM_ID_PADDING:
115
0
    case STREAM_ID_PRIVATE_STREAM_2:
116
60
    case STREAM_ID_ECM:
117
127
    case STREAM_ID_EMM:
118
839
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
1.53k
    case STREAM_ID_DSM_CC:
120
2.02k
    case STREAM_ID_H222_1_TYPE_E:
121
2.02k
        i_skip = 6;
122
2.02k
        h->b_scrambling = false;
123
2.02k
        break;
124
1.25M
    default:
125
1.25M
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
368k
        {
127
            /* mpeg2 PES */
128
            // 9 = syncword(3), stream ID(1), length(2), MPEG2 PES(1), flags(1), header_len(1)
129
            // p_header[8] = header_len(1)
130
368k
            i_skip = p_header[8] + 9;
131
132
368k
            h->b_scrambling = p_header[6]&0x30;
133
134
368k
            if( p_header[7]&0x80 )    /* has pts */
135
286k
            {
136
286k
                if( i_header >= 9 + 5 )
137
279k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
286k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
29.7k
                    i_header >= 14 + 5 )
141
21.5k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
286k
            }
143
368k
        }
144
883k
        else
145
883k
        {
146
            /* FIXME?: WTH do we have undocumented MPEG1 packet stuff here ?
147
               This code path should not be valid, but seems some ppl did
148
               put MPEG1 packets into PS or TS.
149
               Non spec reference for packet format on http://andrewduncan.net/mpeg/mpeg-1.html */
150
883k
            i_skip = 6;
151
152
883k
            h->b_scrambling = false;
153
154
1.78M
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
944k
            {
156
944k
                i_skip++;
157
944k
                if( i_header < i_skip + 1 )
158
40.2k
                    return VLC_EGENERIC;
159
944k
            }
160
843k
            if( i_skip == 23 )
161
588
            {
162
588
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
588
                return VLC_EGENERIC;
164
588
            }
165
            /* Skip STD buffer size */
166
842k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
33.9k
            {
168
33.9k
                i_skip += 2;
169
33.9k
            }
170
171
842k
            if( i_header < i_skip + 1 )
172
214
                return VLC_EGENERIC;
173
174
842k
            if(  p_header[i_skip]&0x20 )
175
682k
            {
176
682k
                if( i_header >= i_skip + 5 )
177
674k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
682k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
343k
                    i_header >= i_skip + 10 )
181
314k
                {
182
314k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
314k
                    i_skip += 10;
184
314k
                }
185
367k
                else
186
367k
                {
187
367k
                    i_skip += 5;
188
367k
                }
189
682k
            }
190
160k
            else
191
160k
            {
192
160k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
159k
                    return VLC_EGENERIC;
194
367
                i_skip += 1;
195
367
            }
196
842k
        }
197
1.05M
        break;
198
1.25M
    }
199
200
1.05M
    h->i_size = i_skip;
201
1.05M
    return VLC_SUCCESS;
202
1.25M
}
Unexecuted instantiation: pva.c:ParsePESHeader
Unexecuted instantiation: ty.c:ParsePESHeader
Unexecuted instantiation: vobsub.c:ParsePESHeader
ts.c:ParsePESHeader
Line
Count
Source
100
1.09M
{
101
1.09M
    unsigned i_skip;
102
103
1.09M
    if ( i_header < 9 )
104
2.19k
        return VLC_EGENERIC;
105
106
1.09M
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
7.55k
        return VLC_EGENERIC;
108
109
1.08M
    h->i_stream_id = p_header[3];
110
111
1.08M
    switch( p_header[3] )
112
1.08M
    {
113
334
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
671
    case STREAM_ID_PADDING:
115
1.04k
    case STREAM_ID_PRIVATE_STREAM_2:
116
1.71k
    case STREAM_ID_ECM:
117
2.08k
    case STREAM_ID_EMM:
118
4.75k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
5.72k
    case STREAM_ID_DSM_CC:
120
6.44k
    case STREAM_ID_H222_1_TYPE_E:
121
6.44k
        i_skip = 6;
122
6.44k
        h->b_scrambling = false;
123
6.44k
        break;
124
1.08M
    default:
125
1.08M
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
944k
        {
127
            /* mpeg2 PES */
128
            // 9 = syncword(3), stream ID(1), length(2), MPEG2 PES(1), flags(1), header_len(1)
129
            // p_header[8] = header_len(1)
130
944k
            i_skip = p_header[8] + 9;
131
132
944k
            h->b_scrambling = p_header[6]&0x30;
133
134
944k
            if( p_header[7]&0x80 )    /* has pts */
135
212k
            {
136
212k
                if( i_header >= 9 + 5 )
137
212k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
212k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
34.3k
                    i_header >= 14 + 5 )
141
34.3k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
212k
            }
143
944k
        }
144
135k
        else
145
135k
        {
146
            /* FIXME?: WTH do we have undocumented MPEG1 packet stuff here ?
147
               This code path should not be valid, but seems some ppl did
148
               put MPEG1 packets into PS or TS.
149
               Non spec reference for packet format on http://andrewduncan.net/mpeg/mpeg-1.html */
150
135k
            i_skip = 6;
151
152
135k
            h->b_scrambling = false;
153
154
238k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
102k
            {
156
102k
                i_skip++;
157
102k
                if( i_header < i_skip + 1 )
158
730
                    return VLC_EGENERIC;
159
102k
            }
160
135k
            if( i_skip == 23 )
161
1.98k
            {
162
1.98k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
1.98k
                return VLC_EGENERIC;
164
1.98k
            }
165
            /* Skip STD buffer size */
166
133k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
14.4k
            {
168
14.4k
                i_skip += 2;
169
14.4k
            }
170
171
133k
            if( i_header < i_skip + 1 )
172
150
                return VLC_EGENERIC;
173
174
133k
            if(  p_header[i_skip]&0x20 )
175
121k
            {
176
121k
                if( i_header >= i_skip + 5 )
177
121k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
121k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
111k
                    i_header >= i_skip + 10 )
181
111k
                {
182
111k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
111k
                    i_skip += 10;
184
111k
                }
185
10.6k
                else
186
10.6k
                {
187
10.6k
                    i_skip += 5;
188
10.6k
                }
189
121k
            }
190
11.2k
            else
191
11.2k
            {
192
11.2k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
10.2k
                    return VLC_EGENERIC;
194
965
                i_skip += 1;
195
965
            }
196
133k
        }
197
1.06M
        break;
198
1.08M
    }
199
200
1.07M
    h->i_size = i_skip;
201
1.07M
    return VLC_SUCCESS;
202
1.08M
}
ts_hotfixes.c:ParsePESHeader
Line
Count
Source
100
49.3k
{
101
49.3k
    unsigned i_skip;
102
103
49.3k
    if ( i_header < 9 )
104
643
        return VLC_EGENERIC;
105
106
48.6k
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
9.97k
        return VLC_EGENERIC;
108
109
38.6k
    h->i_stream_id = p_header[3];
110
111
38.6k
    switch( p_header[3] )
112
38.6k
    {
113
108
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
220
    case STREAM_ID_PADDING:
115
2.06k
    case STREAM_ID_PRIVATE_STREAM_2:
116
2.14k
    case STREAM_ID_ECM:
117
2.22k
    case STREAM_ID_EMM:
118
3.39k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
3.68k
    case STREAM_ID_DSM_CC:
120
3.75k
    case STREAM_ID_H222_1_TYPE_E:
121
3.75k
        i_skip = 6;
122
3.75k
        h->b_scrambling = false;
123
3.75k
        break;
124
34.9k
    default:
125
34.9k
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
24.7k
        {
127
            /* mpeg2 PES */
128
            // 9 = syncword(3), stream ID(1), length(2), MPEG2 PES(1), flags(1), header_len(1)
129
            // p_header[8] = header_len(1)
130
24.7k
            i_skip = p_header[8] + 9;
131
132
24.7k
            h->b_scrambling = p_header[6]&0x30;
133
134
24.7k
            if( p_header[7]&0x80 )    /* has pts */
135
5.40k
            {
136
5.40k
                if( i_header >= 9 + 5 )
137
5.38k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
5.40k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
2.87k
                    i_header >= 14 + 5 )
141
2.85k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
5.40k
            }
143
24.7k
        }
144
10.1k
        else
145
10.1k
        {
146
            /* FIXME?: WTH do we have undocumented MPEG1 packet stuff here ?
147
               This code path should not be valid, but seems some ppl did
148
               put MPEG1 packets into PS or TS.
149
               Non spec reference for packet format on http://andrewduncan.net/mpeg/mpeg-1.html */
150
10.1k
            i_skip = 6;
151
152
10.1k
            h->b_scrambling = false;
153
154
34.8k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
24.9k
            {
156
24.9k
                i_skip++;
157
24.9k
                if( i_header < i_skip + 1 )
158
256
                    return VLC_EGENERIC;
159
24.9k
            }
160
9.89k
            if( i_skip == 23 )
161
802
            {
162
802
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
802
                return VLC_EGENERIC;
164
802
            }
165
            /* Skip STD buffer size */
166
9.09k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
1.37k
            {
168
1.37k
                i_skip += 2;
169
1.37k
            }
170
171
9.09k
            if( i_header < i_skip + 1 )
172
20
                return VLC_EGENERIC;
173
174
9.07k
            if(  p_header[i_skip]&0x20 )
175
7.37k
            {
176
7.37k
                if( i_header >= i_skip + 5 )
177
7.11k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
7.37k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
5.42k
                    i_header >= i_skip + 10 )
181
5.15k
                {
182
5.15k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
5.15k
                    i_skip += 10;
184
5.15k
                }
185
2.22k
                else
186
2.22k
                {
187
2.22k
                    i_skip += 5;
188
2.22k
                }
189
7.37k
            }
190
1.69k
            else
191
1.69k
            {
192
1.69k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
1.21k
                    return VLC_EGENERIC;
194
481
                i_skip += 1;
195
481
            }
196
9.07k
        }
197
32.6k
        break;
198
38.6k
    }
199
200
36.4k
    h->i_size = i_skip;
201
36.4k
    return VLC_SUCCESS;
202
38.6k
}
203
204
#endif