Coverage Report

Created: 2026-10-17 07:46

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
257k
#define STREAM_ID_PROGRAM_STREAM_MAP         0xBC
26
2.11M
#define STREAM_ID_PRIVATE_STREAM_1           0xBD
27
4.58k
#define STREAM_ID_PADDING                    0xBE
28
3.40k
#define STREAM_ID_PRIVATE_STREAM_2           0xBF
29
#define STREAM_ID_AUDIO_STREAM_0             0xC0
30
#define STREAM_ID_VIDEO_STREAM_0             0xE0
31
4.18k
#define STREAM_ID_ECM                        0xF0
32
4.75k
#define STREAM_ID_EMM                        0xF1
33
12.2k
#define STREAM_ID_DSM_CC                     0xF2
34
13.6k
#define STREAM_ID_H222_1_TYPE_E              0xF8
35
#define STREAM_ID_METADATA_STREAM            0xFC
36
2.31M
#define STREAM_ID_EXTENDED_STREAM_ID         0xFD
37
129k
#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.40M
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
2.40M
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
2.40M
             (ts_90khz_t)(p_data[1] << 22)|
45
2.40M
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
2.40M
             (ts_90khz_t)(p_data[3] << 7)|
47
2.40M
             (ts_90khz_t)(p_data[4] >> 1);
48
2.40M
}
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.50M
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
1.50M
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
1.50M
             (ts_90khz_t)(p_data[1] << 22)|
45
1.50M
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
1.50M
             (ts_90khz_t)(p_data[3] << 7)|
47
1.50M
             (ts_90khz_t)(p_data[4] >> 1);
48
1.50M
}
Unexecuted instantiation: ty.c:GetPESTimestamp
Unexecuted instantiation: vobsub.c:GetPESTimestamp
ts.c:GetPESTimestamp
Line
Count
Source
41
202k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
202k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
202k
             (ts_90khz_t)(p_data[1] << 22)|
45
202k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
202k
             (ts_90khz_t)(p_data[3] << 7)|
47
202k
             (ts_90khz_t)(p_data[4] >> 1);
48
202k
}
ts_hotfixes.c:GetPESTimestamp
Line
Count
Source
41
9.43k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
9.43k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
9.43k
             (ts_90khz_t)(p_data[1] << 22)|
45
9.43k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
9.43k
             (ts_90khz_t)(p_data[3] << 7)|
47
9.43k
             (ts_90khz_t)(p_data[4] >> 1);
48
9.43k
}
49
50
static inline bool ExtractPESTimestamp( const uint8_t *p_data, uint8_t i_flags, ts_90khz_t *ret )
51
1.66M
{
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.66M
    if((p_data[0] & 0xC1) != 0x01 ||
55
1.18M
       (p_data[2] & 0x01) != 0x01 ||
56
1.04M
       (p_data[4] & 0x01) != 0x01 ||
57
903k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
901k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
758k
        return false;
60
61
62
901k
    *ret =  GetPESTimestamp( p_data );
63
901k
    return true;
64
1.66M
}
ps.c:ExtractPESTimestamp
Line
Count
Source
51
1.26M
{
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.26M
    if((p_data[0] & 0xC1) != 0x01 ||
55
879k
       (p_data[2] & 0x01) != 0x01 ||
56
793k
       (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
579k
        return false;
60
61
62
689k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
1.26M
}
Unexecuted instantiation: pva.c:ExtractPESTimestamp
Unexecuted instantiation: ty.c:ExtractPESTimestamp
Unexecuted instantiation: vobsub.c:ExtractPESTimestamp
ts.c:ExtractPESTimestamp
Line
Count
Source
51
372k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
372k
    if((p_data[0] & 0xC1) != 0x01 ||
55
295k
       (p_data[2] & 0x01) != 0x01 ||
56
239k
       (p_data[4] & 0x01) != 0x01 ||
57
202k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
202k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
169k
        return false;
60
61
62
202k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
372k
}
ts_hotfixes.c:ExtractPESTimestamp
Line
Count
Source
51
19.2k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
19.2k
    if((p_data[0] & 0xC1) != 0x01 ||
55
12.4k
       (p_data[2] & 0x01) != 0x01 ||
56
10.6k
       (p_data[4] & 0x01) != 0x01 ||
57
9.74k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
9.43k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
9.86k
        return false;
60
61
62
9.43k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
19.2k
}
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
35.3k
{
69
    /* prefixed by 2 bits 01 */
70
35.3k
    return  ((ts_90khz_t)(p_data[0]&0x38 ) << 27)|
71
35.3k
            ((ts_90khz_t)(p_data[0]&0x03 ) << 28)|
72
35.3k
             (ts_90khz_t)(p_data[1] << 20)|
73
35.3k
            ((ts_90khz_t)(p_data[2]&0xf8 ) << 12)|
74
35.3k
            ((ts_90khz_t)(p_data[2]&0x03 ) << 13)|
75
35.3k
             (ts_90khz_t)(p_data[3] << 5) |
76
35.3k
             (ts_90khz_t)(p_data[4] >> 3);
77
35.3k
}
ps.c:ExtractPackHeaderTimestamp
Line
Count
Source
68
35.3k
{
69
    /* prefixed by 2 bits 01 */
70
35.3k
    return  ((ts_90khz_t)(p_data[0]&0x38 ) << 27)|
71
35.3k
            ((ts_90khz_t)(p_data[0]&0x03 ) << 28)|
72
35.3k
             (ts_90khz_t)(p_data[1] << 20)|
73
35.3k
            ((ts_90khz_t)(p_data[2]&0xf8 ) << 12)|
74
35.3k
            ((ts_90khz_t)(p_data[2]&0x03 ) << 13)|
75
35.3k
             (ts_90khz_t)(p_data[3] << 5) |
76
35.3k
             (ts_90khz_t)(p_data[4] >> 3);
77
35.3k
}
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.32M
{
90
2.32M
    h->i_dts = TS_90KHZ_INVALID;
91
2.32M
    h->i_pts = TS_90KHZ_INVALID;
92
2.32M
    h->i_stream_id = 0;
93
2.32M
    h->b_scrambling = false;
94
2.32M
    h->i_size = 0;
95
2.32M
}
ps.c:ts_pes_header_init
Line
Count
Source
89
1.23M
{
90
1.23M
    h->i_dts = TS_90KHZ_INVALID;
91
1.23M
    h->i_pts = TS_90KHZ_INVALID;
92
1.23M
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
1.23M
    h->i_size = 0;
95
1.23M
}
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.03M
{
90
1.03M
    h->i_dts = TS_90KHZ_INVALID;
91
1.03M
    h->i_pts = TS_90KHZ_INVALID;
92
1.03M
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
1.03M
    h->i_size = 0;
95
1.03M
}
ts_hotfixes.c:ts_pes_header_init
Line
Count
Source
89
50.3k
{
90
50.3k
    h->i_dts = TS_90KHZ_INVALID;
91
50.3k
    h->i_pts = TS_90KHZ_INVALID;
92
50.3k
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
50.3k
    h->i_size = 0;
95
50.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.32M
{
101
2.32M
    unsigned i_skip;
102
103
2.32M
    if ( i_header < 9 )
104
10.7k
        return VLC_EGENERIC;
105
106
2.30M
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
16.5k
        return VLC_EGENERIC;
108
109
2.29M
    h->i_stream_id = p_header[3];
110
111
2.29M
    switch( p_header[3] )
112
2.29M
    {
113
401
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
982
    case STREAM_ID_PADDING:
115
3.40k
    case STREAM_ID_PRIVATE_STREAM_2:
116
4.18k
    case STREAM_ID_ECM:
117
4.75k
    case STREAM_ID_EMM:
118
10.2k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
12.2k
    case STREAM_ID_DSM_CC:
120
13.6k
    case STREAM_ID_H222_1_TYPE_E:
121
13.6k
        i_skip = 6;
122
13.6k
        h->b_scrambling = false;
123
13.6k
        break;
124
2.27M
    default:
125
2.27M
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
1.30M
        {
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.30M
            i_skip = p_header[8] + 9;
131
132
1.30M
            h->b_scrambling = p_header[6]&0x30;
133
134
1.30M
            if( p_header[7]&0x80 )    /* has pts */
135
465k
            {
136
465k
                if( i_header >= 9 + 5 )
137
457k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
465k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
52.1k
                    i_header >= 14 + 5 )
141
43.2k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
465k
            }
143
1.30M
        }
144
978k
        else
145
978k
        {
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
978k
            i_skip = 6;
151
152
978k
            h->b_scrambling = false;
153
154
1.96M
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
1.02M
            {
156
1.02M
                i_skip++;
157
1.02M
                if( i_header < i_skip + 1 )
158
39.1k
                    return VLC_EGENERIC;
159
1.02M
            }
160
939k
            if( i_skip == 23 )
161
3.06k
            {
162
3.06k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
3.06k
                return VLC_EGENERIC;
164
3.06k
            }
165
            /* Skip STD buffer size */
166
936k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
48.3k
            {
168
48.3k
                i_skip += 2;
169
48.3k
            }
170
171
936k
            if( i_header < i_skip + 1 )
172
378
                return VLC_EGENERIC;
173
174
935k
            if(  p_header[i_skip]&0x20 )
175
764k
            {
176
764k
                if( i_header >= i_skip + 5 )
177
756k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
764k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
431k
                    i_header >= i_skip + 10 )
181
401k
                {
182
401k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
401k
                    i_skip += 10;
184
401k
                }
185
363k
                else
186
363k
                {
187
363k
                    i_skip += 5;
188
363k
                }
189
764k
            }
190
170k
            else
191
170k
            {
192
170k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
169k
                    return VLC_EGENERIC;
194
1.87k
                i_skip += 1;
195
1.87k
            }
196
935k
        }
197
2.06M
        break;
198
2.29M
    }
199
200
2.08M
    h->i_size = i_skip;
201
2.08M
    return VLC_SUCCESS;
202
2.29M
}
ps.c:ParsePESHeader
Line
Count
Source
100
1.23M
{
101
1.23M
    unsigned i_skip;
102
103
1.23M
    if ( i_header < 9 )
104
7.74k
        return VLC_EGENERIC;
105
106
1.22M
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
0
        return VLC_EGENERIC;
108
109
1.22M
    h->i_stream_id = p_header[3];
110
111
1.22M
    switch( p_header[3] )
112
1.22M
    {
113
0
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
0
    case STREAM_ID_PADDING:
115
0
    case STREAM_ID_PRIVATE_STREAM_2:
116
61
    case STREAM_ID_ECM:
117
130
    case STREAM_ID_EMM:
118
611
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
1.32k
    case STREAM_ID_DSM_CC:
120
1.85k
    case STREAM_ID_H222_1_TYPE_E:
121
1.85k
        i_skip = 6;
122
1.85k
        h->b_scrambling = false;
123
1.85k
        break;
124
1.22M
    default:
125
1.22M
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
367k
        {
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
367k
            i_skip = p_header[8] + 9;
131
132
367k
            h->b_scrambling = p_header[6]&0x30;
133
134
367k
            if( p_header[7]&0x80 )    /* has pts */
135
287k
            {
136
287k
                if( i_header >= 9 + 5 )
137
280k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
287k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
30.7k
                    i_header >= 14 + 5 )
141
21.9k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
287k
            }
143
367k
        }
144
859k
        else
145
859k
        {
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
859k
            i_skip = 6;
151
152
859k
            h->b_scrambling = false;
153
154
1.73M
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
913k
            {
156
913k
                i_skip++;
157
913k
                if( i_header < i_skip + 1 )
158
38.6k
                    return VLC_EGENERIC;
159
913k
            }
160
820k
            if( i_skip == 23 )
161
413
            {
162
413
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
413
                return VLC_EGENERIC;
164
413
            }
165
            /* Skip STD buffer size */
166
820k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
34.4k
            {
168
34.4k
                i_skip += 2;
169
34.4k
            }
170
171
820k
            if( i_header < i_skip + 1 )
172
234
                return VLC_EGENERIC;
173
174
819k
            if(  p_header[i_skip]&0x20 )
175
661k
            {
176
661k
                if( i_header >= i_skip + 5 )
177
653k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
661k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
340k
                    i_header >= i_skip + 10 )
181
310k
                {
182
310k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
310k
                    i_skip += 10;
184
310k
                }
185
350k
                else
186
350k
                {
187
350k
                    i_skip += 5;
188
350k
                }
189
661k
            }
190
158k
            else
191
158k
            {
192
158k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
157k
                    return VLC_EGENERIC;
194
387
                i_skip += 1;
195
387
            }
196
819k
        }
197
1.02M
        break;
198
1.22M
    }
199
200
1.03M
    h->i_size = i_skip;
201
1.03M
    return VLC_SUCCESS;
202
1.22M
}
Unexecuted instantiation: pva.c:ParsePESHeader
Unexecuted instantiation: ty.c:ParsePESHeader
Unexecuted instantiation: vobsub.c:ParsePESHeader
ts.c:ParsePESHeader
Line
Count
Source
100
1.03M
{
101
1.03M
    unsigned i_skip;
102
103
1.03M
    if ( i_header < 9 )
104
2.35k
        return VLC_EGENERIC;
105
106
1.03M
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
5.97k
        return VLC_EGENERIC;
108
109
1.02M
    h->i_stream_id = p_header[3];
110
111
1.02M
    switch( p_header[3] )
112
1.02M
    {
113
282
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
762
    case STREAM_ID_PADDING:
115
895
    case STREAM_ID_PRIVATE_STREAM_2:
116
1.56k
    case STREAM_ID_ECM:
117
1.99k
    case STREAM_ID_EMM:
118
6.07k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
7.13k
    case STREAM_ID_DSM_CC:
120
7.90k
    case STREAM_ID_H222_1_TYPE_E:
121
7.90k
        i_skip = 6;
122
7.90k
        h->b_scrambling = false;
123
7.90k
        break;
124
1.01M
    default:
125
1.01M
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
908k
        {
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
908k
            i_skip = p_header[8] + 9;
131
132
908k
            h->b_scrambling = p_header[6]&0x30;
133
134
908k
            if( p_header[7]&0x80 )    /* has pts */
135
172k
            {
136
172k
                if( i_header >= 9 + 5 )
137
172k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
172k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
18.5k
                    i_header >= 14 + 5 )
141
18.5k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
172k
            }
143
908k
        }
144
109k
        else
145
109k
        {
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
109k
            i_skip = 6;
151
152
109k
            h->b_scrambling = false;
153
154
192k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
83.1k
            {
156
83.1k
                i_skip++;
157
83.1k
                if( i_header < i_skip + 1 )
158
212
                    return VLC_EGENERIC;
159
83.1k
            }
160
109k
            if( i_skip == 23 )
161
1.60k
            {
162
1.60k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
1.60k
                return VLC_EGENERIC;
164
1.60k
            }
165
            /* Skip STD buffer size */
166
107k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
12.5k
            {
168
12.5k
                i_skip += 2;
169
12.5k
            }
170
171
107k
            if( i_header < i_skip + 1 )
172
124
                return VLC_EGENERIC;
173
174
107k
            if(  p_header[i_skip]&0x20 )
175
96.2k
            {
176
96.2k
                if( i_header >= i_skip + 5 )
177
95.6k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
96.2k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
86.3k
                    i_header >= i_skip + 10 )
181
85.7k
                {
182
85.7k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
85.7k
                    i_skip += 10;
184
85.7k
                }
185
10.5k
                else
186
10.5k
                {
187
10.5k
                    i_skip += 5;
188
10.5k
                }
189
96.2k
            }
190
11.0k
            else
191
11.0k
            {
192
11.0k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
10.0k
                    return VLC_EGENERIC;
194
1.00k
                i_skip += 1;
195
1.00k
            }
196
107k
        }
197
1.00M
        break;
198
1.02M
    }
199
200
1.01M
    h->i_size = i_skip;
201
1.01M
    return VLC_SUCCESS;
202
1.02M
}
ts_hotfixes.c:ParsePESHeader
Line
Count
Source
100
50.3k
{
101
50.3k
    unsigned i_skip;
102
103
50.3k
    if ( i_header < 9 )
104
672
        return VLC_EGENERIC;
105
106
49.6k
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
10.5k
        return VLC_EGENERIC;
108
109
39.0k
    h->i_stream_id = p_header[3];
110
111
39.0k
    switch( p_header[3] )
112
39.0k
    {
113
119
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
220
    case STREAM_ID_PADDING:
115
2.51k
    case STREAM_ID_PRIVATE_STREAM_2:
116
2.55k
    case STREAM_ID_ECM:
117
2.63k
    case STREAM_ID_EMM:
118
3.53k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
3.83k
    case STREAM_ID_DSM_CC:
120
3.90k
    case STREAM_ID_H222_1_TYPE_E:
121
3.90k
        i_skip = 6;
122
3.90k
        h->b_scrambling = false;
123
3.90k
        break;
124
35.1k
    default:
125
35.1k
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
25.0k
        {
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
25.0k
            i_skip = p_header[8] + 9;
131
132
25.0k
            h->b_scrambling = p_header[6]&0x30;
133
134
25.0k
            if( p_header[7]&0x80 )    /* has pts */
135
4.88k
            {
136
4.88k
                if( i_header >= 9 + 5 )
137
4.86k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
4.88k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
2.73k
                    i_header >= 14 + 5 )
141
2.72k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
4.88k
            }
143
25.0k
        }
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
39.1k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
29.1k
            {
156
29.1k
                i_skip++;
157
29.1k
                if( i_header < i_skip + 1 )
158
228
                    return VLC_EGENERIC;
159
29.1k
            }
160
9.90k
            if( i_skip == 23 )
161
1.05k
            {
162
1.05k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
1.05k
                return VLC_EGENERIC;
164
1.05k
            }
165
            /* Skip STD buffer size */
166
8.85k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
1.36k
            {
168
1.36k
                i_skip += 2;
169
1.36k
            }
170
171
8.85k
            if( i_header < i_skip + 1 )
172
20
                return VLC_EGENERIC;
173
174
8.83k
            if(  p_header[i_skip]&0x20 )
175
7.07k
            {
176
7.07k
                if( i_header >= i_skip + 5 )
177
6.75k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
7.07k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
5.28k
                    i_header >= i_skip + 10 )
181
4.96k
                {
182
4.96k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
4.96k
                    i_skip += 10;
184
4.96k
                }
185
2.11k
                else
186
2.11k
                {
187
2.11k
                    i_skip += 5;
188
2.11k
                }
189
7.07k
            }
190
1.76k
            else
191
1.76k
            {
192
1.76k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
1.28k
                    return VLC_EGENERIC;
194
478
                i_skip += 1;
195
478
            }
196
8.83k
        }
197
32.6k
        break;
198
39.0k
    }
199
200
36.5k
    h->i_size = i_skip;
201
36.5k
    return VLC_SUCCESS;
202
39.0k
}
203
204
#endif