Coverage Report

Created: 2026-06-30 07:56

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
65.5k
#define STREAM_ID_PROGRAM_STREAM_MAP         0xBC
26
265k
#define STREAM_ID_PRIVATE_STREAM_1           0xBD
27
3.39k
#define STREAM_ID_PADDING                    0xBE
28
1.12k
#define STREAM_ID_PRIVATE_STREAM_2           0xBF
29
#define STREAM_ID_AUDIO_STREAM_0             0xC0
30
#define STREAM_ID_VIDEO_STREAM_0             0xE0
31
1.99k
#define STREAM_ID_ECM                        0xF0
32
2.69k
#define STREAM_ID_EMM                        0xF1
33
6.94k
#define STREAM_ID_DSM_CC                     0xF2
34
7.64k
#define STREAM_ID_H222_1_TYPE_E              0xF8
35
#define STREAM_ID_METADATA_STREAM            0xFC
36
280k
#define STREAM_ID_EXTENDED_STREAM_ID         0xFD
37
39.3k
#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
1.64M
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
1.64M
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
1.64M
             (ts_90khz_t)(p_data[1] << 22)|
45
1.64M
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
1.64M
             (ts_90khz_t)(p_data[3] << 7)|
47
1.64M
             (ts_90khz_t)(p_data[4] >> 1);
48
1.64M
}
ps.c:GetPESTimestamp
Line
Count
Source
41
83.6k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
83.6k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
83.6k
             (ts_90khz_t)(p_data[1] << 22)|
45
83.6k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
83.6k
             (ts_90khz_t)(p_data[3] << 7)|
47
83.6k
             (ts_90khz_t)(p_data[4] >> 1);
48
83.6k
}
pva.c:GetPESTimestamp
Line
Count
Source
41
1.36M
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
1.36M
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
1.36M
             (ts_90khz_t)(p_data[1] << 22)|
45
1.36M
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
1.36M
             (ts_90khz_t)(p_data[3] << 7)|
47
1.36M
             (ts_90khz_t)(p_data[4] >> 1);
48
1.36M
}
Unexecuted instantiation: ty.c:GetPESTimestamp
Unexecuted instantiation: vobsub.c:GetPESTimestamp
ts.c:GetPESTimestamp
Line
Count
Source
41
190k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
190k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
190k
             (ts_90khz_t)(p_data[1] << 22)|
45
190k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
190k
             (ts_90khz_t)(p_data[3] << 7)|
47
190k
             (ts_90khz_t)(p_data[4] >> 1);
48
190k
}
ts_hotfixes.c:GetPESTimestamp
Line
Count
Source
41
11.6k
{
42
    /* prefixed by 4 bits 0010 or 0011 */
43
11.6k
    return  ((ts_90khz_t)(p_data[ 0]&0x0e ) << 29)|
44
11.6k
             (ts_90khz_t)(p_data[1] << 22)|
45
11.6k
            ((ts_90khz_t)(p_data[2]&0xfe) << 14)|
46
11.6k
             (ts_90khz_t)(p_data[3] << 7)|
47
11.6k
             (ts_90khz_t)(p_data[4] >> 1);
48
11.6k
}
49
50
static inline bool ExtractPESTimestamp( const uint8_t *p_data, uint8_t i_flags, ts_90khz_t *ret )
51
519k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
519k
    if((p_data[0] & 0xC1) != 0x01 ||
55
385k
       (p_data[2] & 0x01) != 0x01 ||
56
318k
       (p_data[4] & 0x01) != 0x01 ||
57
288k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
286k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
233k
        return false;
60
61
62
286k
    *ret =  GetPESTimestamp( p_data );
63
286k
    return true;
64
519k
}
ps.c:ExtractPESTimestamp
Line
Count
Source
51
170k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
170k
    if((p_data[0] & 0xC1) != 0x01 ||
55
111k
       (p_data[2] & 0x01) != 0x01 ||
56
99.0k
       (p_data[4] & 0x01) != 0x01 ||
57
85.7k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
83.6k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
86.7k
        return false;
60
61
62
83.6k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
170k
}
Unexecuted instantiation: pva.c:ExtractPESTimestamp
Unexecuted instantiation: ty.c:ExtractPESTimestamp
Unexecuted instantiation: vobsub.c:ExtractPESTimestamp
ts.c:ExtractPESTimestamp
Line
Count
Source
51
326k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
326k
    if((p_data[0] & 0xC1) != 0x01 ||
55
257k
       (p_data[2] & 0x01) != 0x01 ||
56
206k
       (p_data[4] & 0x01) != 0x01 ||
57
190k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
190k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
135k
        return false;
60
61
62
190k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
326k
}
ts_hotfixes.c:ExtractPESTimestamp
Line
Count
Source
51
22.3k
{
52
    /* !warn broken muxers set incorrect flags. see #17773 and #19140 */
53
    /* check marker bits, and i_flags = b 0010, 0011 or 0001 */
54
22.3k
    if((p_data[0] & 0xC1) != 0x01 ||
55
15.1k
       (p_data[2] & 0x01) != 0x01 ||
56
12.6k
       (p_data[4] & 0x01) != 0x01 ||
57
11.9k
       (p_data[0] & 0x30) == 0 || /* at least needs one bit */
58
11.6k
       (p_data[0] >> 5) > i_flags ) /* needs flags 1x => 1x or flags 01 => 01 */
59
10.6k
        return false;
60
61
62
11.6k
    *ret =  GetPESTimestamp( p_data );
63
    return true;
64
22.3k
}
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
1.38k
{
69
    /* prefixed by 2 bits 01 */
70
1.38k
    return  ((ts_90khz_t)(p_data[0]&0x38 ) << 27)|
71
1.38k
            ((ts_90khz_t)(p_data[0]&0x03 ) << 28)|
72
1.38k
             (ts_90khz_t)(p_data[1] << 20)|
73
1.38k
            ((ts_90khz_t)(p_data[2]&0xf8 ) << 12)|
74
1.38k
            ((ts_90khz_t)(p_data[2]&0x03 ) << 13)|
75
1.38k
             (ts_90khz_t)(p_data[3] << 5) |
76
1.38k
             (ts_90khz_t)(p_data[4] >> 3);
77
1.38k
}
ps.c:ExtractPackHeaderTimestamp
Line
Count
Source
68
1.38k
{
69
    /* prefixed by 2 bits 01 */
70
1.38k
    return  ((ts_90khz_t)(p_data[0]&0x38 ) << 27)|
71
1.38k
            ((ts_90khz_t)(p_data[0]&0x03 ) << 28)|
72
1.38k
             (ts_90khz_t)(p_data[1] << 20)|
73
1.38k
            ((ts_90khz_t)(p_data[2]&0xf8 ) << 12)|
74
1.38k
            ((ts_90khz_t)(p_data[2]&0x03 ) << 13)|
75
1.38k
             (ts_90khz_t)(p_data[3] << 5) |
76
1.38k
             (ts_90khz_t)(p_data[4] >> 3);
77
1.38k
}
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
1.19M
{
90
1.19M
    h->i_dts = TS_90KHZ_INVALID;
91
1.19M
    h->i_pts = TS_90KHZ_INVALID;
92
1.19M
    h->i_stream_id = 0;
93
1.19M
    h->b_scrambling = false;
94
1.19M
    h->i_size = 0;
95
1.19M
}
ps.c:ts_pes_header_init
Line
Count
Source
89
151k
{
90
151k
    h->i_dts = TS_90KHZ_INVALID;
91
151k
    h->i_pts = TS_90KHZ_INVALID;
92
151k
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
151k
    h->i_size = 0;
95
151k
}
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
984k
{
90
984k
    h->i_dts = TS_90KHZ_INVALID;
91
984k
    h->i_pts = TS_90KHZ_INVALID;
92
984k
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
984k
    h->i_size = 0;
95
984k
}
ts_hotfixes.c:ts_pes_header_init
Line
Count
Source
89
54.2k
{
90
54.2k
    h->i_dts = TS_90KHZ_INVALID;
91
54.2k
    h->i_pts = TS_90KHZ_INVALID;
92
54.2k
    h->i_stream_id = 0;
93
    h->b_scrambling = false;
94
54.2k
    h->i_size = 0;
95
54.2k
}
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
1.19M
{
101
1.19M
    unsigned i_skip;
102
103
1.19M
    if ( i_header < 9 )
104
5.86k
        return VLC_EGENERIC;
105
106
1.18M
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
18.8k
        return VLC_EGENERIC;
108
109
1.16M
    h->i_stream_id = p_header[3];
110
111
1.16M
    switch( p_header[3] )
112
1.16M
    {
113
453
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
890
    case STREAM_ID_PADDING:
115
1.12k
    case STREAM_ID_PRIVATE_STREAM_2:
116
1.99k
    case STREAM_ID_ECM:
117
2.69k
    case STREAM_ID_EMM:
118
5.48k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
6.94k
    case STREAM_ID_DSM_CC:
120
7.64k
    case STREAM_ID_H222_1_TYPE_E:
121
7.64k
        i_skip = 6;
122
7.64k
        h->b_scrambling = false;
123
7.64k
        break;
124
1.15M
    default:
125
1.15M
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
938k
        {
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
938k
            i_skip = p_header[8] + 9;
131
132
938k
            h->b_scrambling = p_header[6]&0x30;
133
134
938k
            if( p_header[7]&0x80 )    /* has pts */
135
197k
            {
136
197k
                if( i_header >= 9 + 5 )
137
197k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
197k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
23.0k
                    i_header >= 14 + 5 )
141
22.9k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
197k
            }
143
938k
        }
144
218k
        else
145
218k
        {
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
218k
            i_skip = 6;
151
152
218k
            h->b_scrambling = false;
153
154
410k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
193k
            {
156
193k
                i_skip++;
157
193k
                if( i_header < i_skip + 1 )
158
1.70k
                    return VLC_EGENERIC;
159
193k
            }
160
217k
            if( i_skip == 23 )
161
4.40k
            {
162
4.40k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
4.40k
                return VLC_EGENERIC;
164
4.40k
            }
165
            /* Skip STD buffer size */
166
212k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
24.2k
            {
168
24.2k
                i_skip += 2;
169
24.2k
            }
170
171
212k
            if( i_header < i_skip + 1 )
172
175
                return VLC_EGENERIC;
173
174
212k
            if(  p_header[i_skip]&0x20 )
175
170k
            {
176
170k
                if( i_header >= i_skip + 5 )
177
169k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
170k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
132k
                    i_header >= i_skip + 10 )
181
128k
                {
182
128k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
128k
                    i_skip += 10;
184
128k
                }
185
41.7k
                else
186
41.7k
                {
187
41.7k
                    i_skip += 5;
188
41.7k
                }
189
170k
            }
190
42.3k
            else
191
42.3k
            {
192
42.3k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
40.8k
                    return VLC_EGENERIC;
194
1.58k
                i_skip += 1;
195
1.58k
            }
196
212k
        }
197
1.11M
        break;
198
1.16M
    }
199
200
1.11M
    h->i_size = i_skip;
201
1.11M
    return VLC_SUCCESS;
202
1.16M
}
ps.c:ParsePESHeader
Line
Count
Source
100
151k
{
101
151k
    unsigned i_skip;
102
103
151k
    if ( i_header < 9 )
104
3.35k
        return VLC_EGENERIC;
105
106
148k
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
0
        return VLC_EGENERIC;
108
109
148k
    h->i_stream_id = p_header[3];
110
111
148k
    switch( p_header[3] )
112
148k
    {
113
0
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
0
    case STREAM_ID_PADDING:
115
0
    case STREAM_ID_PRIVATE_STREAM_2:
116
65
    case STREAM_ID_ECM:
117
65
    case STREAM_ID_EMM:
118
296
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
297
    case STREAM_ID_DSM_CC:
120
641
    case STREAM_ID_H222_1_TYPE_E:
121
641
        i_skip = 6;
122
641
        h->b_scrambling = false;
123
641
        break;
124
147k
    default:
125
147k
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
29.5k
        {
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
29.5k
            i_skip = p_header[8] + 9;
131
132
29.5k
            h->b_scrambling = p_header[6]&0x30;
133
134
29.5k
            if( p_header[7]&0x80 )    /* has pts */
135
24.3k
            {
136
24.3k
                if( i_header >= 9 + 5 )
137
24.2k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
24.3k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
1.99k
                    i_header >= 14 + 5 )
141
1.94k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
24.3k
            }
143
29.5k
        }
144
118k
        else
145
118k
        {
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
118k
            i_skip = 6;
151
152
118k
            h->b_scrambling = false;
153
154
191k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
74.9k
            {
156
74.9k
                i_skip++;
157
74.9k
                if( i_header < i_skip + 1 )
158
1.24k
                    return VLC_EGENERIC;
159
74.9k
            }
160
117k
            if( i_skip == 23 )
161
1.51k
            {
162
1.51k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
1.51k
                return VLC_EGENERIC;
164
1.51k
            }
165
            /* Skip STD buffer size */
166
115k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
10.5k
            {
168
10.5k
                i_skip += 2;
169
10.5k
            }
170
171
115k
            if( i_header < i_skip + 1 )
172
54
                return VLC_EGENERIC;
173
174
115k
            if(  p_header[i_skip]&0x20 )
175
86.0k
            {
176
86.0k
                if( i_header >= i_skip + 5 )
177
85.7k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
86.0k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
60.4k
                    i_header >= i_skip + 10 )
181
57.4k
                {
182
57.4k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
57.4k
                    i_skip += 10;
184
57.4k
                }
185
28.5k
                else
186
28.5k
                {
187
28.5k
                    i_skip += 5;
188
28.5k
                }
189
86.0k
            }
190
29.3k
            else
191
29.3k
            {
192
29.3k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
29.2k
                    return VLC_EGENERIC;
194
72
                i_skip += 1;
195
72
            }
196
115k
        }
197
115k
        break;
198
148k
    }
199
200
116k
    h->i_size = i_skip;
201
116k
    return VLC_SUCCESS;
202
148k
}
Unexecuted instantiation: pva.c:ParsePESHeader
Unexecuted instantiation: ty.c:ParsePESHeader
Unexecuted instantiation: vobsub.c:ParsePESHeader
ts.c:ParsePESHeader
Line
Count
Source
100
984k
{
101
984k
    unsigned i_skip;
102
103
984k
    if ( i_header < 9 )
104
1.80k
        return VLC_EGENERIC;
105
106
982k
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
5.82k
        return VLC_EGENERIC;
108
109
976k
    h->i_stream_id = p_header[3];
110
111
976k
    switch( p_header[3] )
112
976k
    {
113
316
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
645
    case STREAM_ID_PADDING:
115
778
    case STREAM_ID_PRIVATE_STREAM_2:
116
1.54k
    case STREAM_ID_ECM:
117
2.16k
    case STREAM_ID_EMM:
118
3.80k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
4.88k
    case STREAM_ID_DSM_CC:
120
5.17k
    case STREAM_ID_H222_1_TYPE_E:
121
5.17k
        i_skip = 6;
122
5.17k
        h->b_scrambling = false;
123
5.17k
        break;
124
971k
    default:
125
971k
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
882k
        {
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
882k
            i_skip = p_header[8] + 9;
131
132
882k
            h->b_scrambling = p_header[6]&0x30;
133
134
882k
            if( p_header[7]&0x80 )    /* has pts */
135
168k
            {
136
168k
                if( i_header >= 9 + 5 )
137
168k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
168k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
18.4k
                    i_header >= 14 + 5 )
141
18.3k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
168k
            }
143
882k
        }
144
88.8k
        else
145
88.8k
        {
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
88.8k
            i_skip = 6;
151
152
88.8k
            h->b_scrambling = false;
153
154
174k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
86.2k
            {
156
86.2k
                i_skip++;
157
86.2k
                if( i_header < i_skip + 1 )
158
233
                    return VLC_EGENERIC;
159
86.2k
            }
160
88.6k
            if( i_skip == 23 )
161
1.66k
            {
162
1.66k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
1.66k
                return VLC_EGENERIC;
164
1.66k
            }
165
            /* Skip STD buffer size */
166
87.0k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
12.2k
            {
168
12.2k
                i_skip += 2;
169
12.2k
            }
170
171
87.0k
            if( i_header < i_skip + 1 )
172
101
                return VLC_EGENERIC;
173
174
86.9k
            if(  p_header[i_skip]&0x20 )
175
75.6k
            {
176
75.6k
                if( i_header >= i_skip + 5 )
177
75.0k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
75.6k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
65.4k
                    i_header >= i_skip + 10 )
181
64.7k
                {
182
64.7k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
64.7k
                    i_skip += 10;
184
64.7k
                }
185
10.9k
                else
186
10.9k
                {
187
10.9k
                    i_skip += 5;
188
10.9k
                }
189
75.6k
            }
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.1k
                    return VLC_EGENERIC;
194
1.02k
                i_skip += 1;
195
1.02k
            }
196
86.9k
        }
197
959k
        break;
198
976k
    }
199
200
964k
    h->i_size = i_skip;
201
964k
    return VLC_SUCCESS;
202
976k
}
ts_hotfixes.c:ParsePESHeader
Line
Count
Source
100
54.2k
{
101
54.2k
    unsigned i_skip;
102
103
54.2k
    if ( i_header < 9 )
104
711
        return VLC_EGENERIC;
105
106
53.5k
    if( p_header[0] != 0 || p_header[1] != 0 || p_header[2] != 1 )
107
13.0k
        return VLC_EGENERIC;
108
109
40.4k
    h->i_stream_id = p_header[3];
110
111
40.4k
    switch( p_header[3] )
112
40.4k
    {
113
137
    case STREAM_ID_PROGRAM_STREAM_MAP:
114
245
    case STREAM_ID_PADDING:
115
342
    case STREAM_ID_PRIVATE_STREAM_2:
116
385
    case STREAM_ID_ECM:
117
459
    case STREAM_ID_EMM:
118
1.38k
    case STREAM_ID_PROGRAM_STREAM_DIRECTORY:
119
1.76k
    case STREAM_ID_DSM_CC:
120
1.83k
    case STREAM_ID_H222_1_TYPE_E:
121
1.83k
        i_skip = 6;
122
1.83k
        h->b_scrambling = false;
123
1.83k
        break;
124
38.6k
    default:
125
38.6k
        if( ( p_header[6]&0xC0 ) == 0x80 )
126
26.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
26.7k
            i_skip = p_header[8] + 9;
131
132
26.7k
            h->b_scrambling = p_header[6]&0x30;
133
134
26.7k
            if( p_header[7]&0x80 )    /* has pts */
135
5.08k
            {
136
5.08k
                if( i_header >= 9 + 5 )
137
5.07k
                   (void) ExtractPESTimestamp( &p_header[9], p_header[7] >> 6, &h->i_pts );
138
139
5.08k
                if( ( p_header[7]&0x40 ) &&    /* has dts */
140
2.63k
                    i_header >= 14 + 5 )
141
2.62k
                   (void) ExtractPESTimestamp( &p_header[14], 0x01, &h->i_dts );
142
5.08k
            }
143
26.7k
        }
144
11.8k
        else
145
11.8k
        {
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
11.8k
            i_skip = 6;
151
152
11.8k
            h->b_scrambling = false;
153
154
43.7k
            while( i_skip < 23 && p_header[i_skip] == 0xff )
155
32.1k
            {
156
32.1k
                i_skip++;
157
32.1k
                if( i_header < i_skip + 1 )
158
228
                    return VLC_EGENERIC;
159
32.1k
            }
160
11.6k
            if( i_skip == 23 )
161
1.22k
            {
162
1.22k
                vlc_error( p_logger, "too much MPEG-1 stuffing" );
163
1.22k
                return VLC_EGENERIC;
164
1.22k
            }
165
            /* Skip STD buffer size */
166
10.4k
            if( ( p_header[i_skip] & 0xC0 ) == 0x40 )
167
1.44k
            {
168
1.44k
                i_skip += 2;
169
1.44k
            }
170
171
10.4k
            if( i_header < i_skip + 1 )
172
20
                return VLC_EGENERIC;
173
174
10.3k
            if(  p_header[i_skip]&0x20 )
175
8.56k
            {
176
8.56k
                if( i_header >= i_skip + 5 )
177
8.24k
                    (void) ExtractPESTimestamp( &p_header[i_skip], p_header[i_skip] >> 4, &h->i_pts );
178
179
8.56k
                if( ( p_header[i_skip]&0x10 ) &&     /* has dts */
180
6.71k
                    i_header >= i_skip + 10 )
181
6.38k
                {
182
6.38k
                    (void) ExtractPESTimestamp( &p_header[i_skip+5], 0x01, &h->i_dts );
183
6.38k
                    i_skip += 10;
184
6.38k
                }
185
2.17k
                else
186
2.17k
                {
187
2.17k
                    i_skip += 5;
188
2.17k
                }
189
8.56k
            }
190
1.82k
            else
191
1.82k
            {
192
1.82k
                if( (p_header[i_skip] & 0xFF) != 0x0F ) /* No pts/dts, lowest bits set to 0x0F */
193
1.33k
                    return VLC_EGENERIC;
194
490
                i_skip += 1;
195
490
            }
196
10.3k
        }
197
35.8k
        break;
198
40.4k
    }
199
200
37.6k
    h->i_size = i_skip;
201
37.6k
    return VLC_SUCCESS;
202
40.4k
}
203
204
#endif