/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 | 21.3M | #define PS_STREAM_ID_END_STREAM 0xB9 |
28 | 249k | #define PS_STREAM_ID_PACK_HEADER 0xBA |
29 | 10.9k | #define PS_STREAM_ID_SYSTEM_HEADER 0xBB |
30 | | |
31 | 657k | #define PS_PACKET_ID_MASK_VOB 0xBD00 |
32 | 230k | #define PS_PACKET_ID_MASK_AOB 0xA000 |
33 | 80.8k | #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 | 308k | #define PS_AOB_PACKET_ID_MLP (PS_PACKET_ID_MASK_AOB | 0x01) |
40 | 308k | #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 | 18.4M | #define PS_TK_COUNT (256+256+256+8 - 0xc0) |
50 | | static inline unsigned ps_id_to_tk( unsigned i_id ) |
51 | 248k | { |
52 | 248k | assert(i_id >= 0xc0); |
53 | 248k | if(unlikely(i_id < 0xc0)) |
54 | 0 | return 0; |
55 | 248k | if( i_id <= 0xff ) |
56 | 60.3k | return i_id - 0xc0; |
57 | 188k | if( (i_id & 0xff00) == PS_PACKET_ID_MASK_VOB ) |
58 | 181k | return 256-0xC0 + (i_id & 0xff); |
59 | 6.20k | if( (i_id & 0xff00) == PS_PACKET_ID_MASK_EXTENDED ) |
60 | 1.34k | return 512-0xc0 + (i_id & 0xff); |
61 | 6.20k | assert( (i_id & 0xff00) == PS_PACKET_ID_MASK_AOB ); |
62 | 4.85k | return 768-0xc0 + (i_id & 0x07); |
63 | 4.85k | } Line | Count | Source | 51 | 248k | { | 52 | 248k | assert(i_id >= 0xc0); | 53 | 248k | if(unlikely(i_id < 0xc0)) | 54 | 0 | return 0; | 55 | 248k | if( i_id <= 0xff ) | 56 | 60.3k | return i_id - 0xc0; | 57 | 188k | if( (i_id & 0xff00) == PS_PACKET_ID_MASK_VOB ) | 58 | 181k | return 256-0xC0 + (i_id & 0xff); | 59 | 6.20k | if( (i_id & 0xff00) == PS_PACKET_ID_MASK_EXTENDED ) | 60 | 1.34k | return 512-0xc0 + (i_id & 0xff); | 61 | 6.20k | assert( (i_id & 0xff00) == PS_PACKET_ID_MASK_AOB ); | 62 | 4.85k | return 768-0xc0 + (i_id & 0x07); | 63 | 4.85k | } |
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 | 572 | { |
86 | 572 | int i; |
87 | 334k | for( i = 0; i < PS_TK_COUNT; i++ ) |
88 | 334k | { |
89 | 334k | tk[i].b_configured = false; |
90 | 334k | tk[i].b_updated = false; |
91 | 334k | tk[i].i_skip = 0; |
92 | 334k | tk[i].i_id = 0; |
93 | 334k | tk[i].i_next_block_flags = 0; |
94 | 334k | tk[i].es = NULL; |
95 | 334k | tk[i].i_first_pts = VLC_TICK_INVALID; |
96 | 334k | tk[i].i_last_pts = VLC_TICK_INVALID; |
97 | 334k | es_format_Init( &tk[i].fmt, UNKNOWN_ES, 0 ); |
98 | 334k | } |
99 | 572 | } Line | Count | Source | 85 | 572 | { | 86 | 572 | int i; | 87 | 334k | for( i = 0; i < PS_TK_COUNT; i++ ) | 88 | 334k | { | 89 | 334k | tk[i].b_configured = false; | 90 | 334k | tk[i].b_updated = false; | 91 | 334k | tk[i].i_skip = 0; | 92 | 334k | tk[i].i_id = 0; | 93 | 334k | tk[i].i_next_block_flags = 0; | 94 | 334k | tk[i].es = NULL; | 95 | 334k | tk[i].i_first_pts = VLC_TICK_INVALID; | 96 | | tk[i].i_last_pts = VLC_TICK_INVALID; | 97 | 334k | es_format_Init( &tk[i].fmt, UNKNOWN_ES, 0 ); | 98 | 334k | } | 99 | 572 | } |
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 | 30.3k | { |
103 | 30.3k | const uint8_t startcode[3] = { 0, 0, 1 }; |
104 | 30.3k | int i_flags = 0; |
105 | | |
106 | 30.3k | if( i_data < 9 || |
107 | 30.3k | (!memcmp( p_data, startcode, 3 ) && |
108 | 275 | !memcmp( &p_data[1], startcode, 3 )) ) |
109 | 15 | return false; |
110 | | |
111 | | /* Shitty H264 probing. We need a centralized way do to this */ |
112 | 675k | while( i_data > 5 ) |
113 | 655k | { |
114 | 655k | if( !memcmp( p_data, startcode, 3 ) ) |
115 | 11.3k | { |
116 | 11.3k | if(p_data[3] == 0x67) |
117 | 57 | i_flags ^= 0x01; |
118 | 11.2k | else if(p_data[3] == 0x68) |
119 | 57 | i_flags ^= 0x02; |
120 | 11.2k | else if( p_data[3] & 0x80 ) |
121 | 6.84k | return false; |
122 | 4.36k | else if( (p_data[3] & 0x1F) > 23 || (p_data[3] & 0x1F) < 1 ) |
123 | 2.91k | return false; |
124 | 1.45k | else if( (p_data[3] & 0x1F) < 6 ) |
125 | 672 | return (i_flags == 0x03); |
126 | 11.3k | } |
127 | 645k | p_data++; |
128 | 645k | i_data--; |
129 | 645k | } |
130 | | |
131 | 19.8k | return false; |
132 | 30.3k | } Line | Count | Source | 102 | 30.3k | { | 103 | 30.3k | const uint8_t startcode[3] = { 0, 0, 1 }; | 104 | 30.3k | int i_flags = 0; | 105 | | | 106 | 30.3k | if( i_data < 9 || | 107 | 30.3k | (!memcmp( p_data, startcode, 3 ) && | 108 | 275 | !memcmp( &p_data[1], startcode, 3 )) ) | 109 | 15 | return false; | 110 | | | 111 | | /* Shitty H264 probing. We need a centralized way do to this */ | 112 | 675k | while( i_data > 5 ) | 113 | 655k | { | 114 | 655k | if( !memcmp( p_data, startcode, 3 ) ) | 115 | 11.3k | { | 116 | 11.3k | if(p_data[3] == 0x67) | 117 | 57 | i_flags ^= 0x01; | 118 | 11.2k | else if(p_data[3] == 0x68) | 119 | 57 | i_flags ^= 0x02; | 120 | 11.2k | else if( p_data[3] & 0x80 ) | 121 | 6.84k | return false; | 122 | 4.36k | else if( (p_data[3] & 0x1F) > 23 || (p_data[3] & 0x1F) < 1 ) | 123 | 2.91k | return false; | 124 | 1.45k | else if( (p_data[3] & 0x1F) < 6 ) | 125 | 672 | return (i_flags == 0x03); | 126 | 11.3k | } | 127 | 645k | p_data++; | 128 | 645k | i_data--; | 129 | 645k | } | 130 | | | 131 | 19.8k | return false; | 132 | 30.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 | 2.75k | { |
136 | | /* AC-3 marking, see vlc_a52_header_Parse */ |
137 | 2.75k | if( i_data < 8 || p_data[0] != 0x0b || p_data[1] != 0x77 ) |
138 | 2.63k | return false; |
139 | 119 | int bsid = p_data[5] >> 3; |
140 | 119 | return bsid > 10 && bsid <= 16; |
141 | 2.75k | } Line | Count | Source | 135 | 2.75k | { | 136 | | /* AC-3 marking, see vlc_a52_header_Parse */ | 137 | 2.75k | if( i_data < 8 || p_data[0] != 0x0b || p_data[1] != 0x77 ) | 138 | 2.63k | return false; | 139 | 119 | int bsid = p_data[5] >> 3; | 140 | 119 | return bsid > 10 && bsid <= 16; | 141 | 2.75k | } |
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 | 133k | { |
149 | 133k | tk->i_skip = 0; |
150 | 133k | tk->i_id = i_id; |
151 | | |
152 | 133k | if( ( i_id&0xff00 ) == PS_PACKET_ID_MASK_VOB ) /* 0xBD00 -> 0xBDFF, VOB Private Stream 1 */ |
153 | 59.9k | { |
154 | 59.9k | if( ( i_id&0xf8 ) == 0x88 || /* 0x88 -> 0x8f - Can be DTS-HD primary audio in evob */ |
155 | 52.3k | ( i_id&0xf8 ) == 0x98 ) /* 0x98 -> 0x9f - Can be DTS-HD secondary audio in evob */ |
156 | 7.71k | { |
157 | 7.71k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DTS ); |
158 | 7.71k | tk->i_skip = 4; |
159 | 7.71k | } |
160 | 52.2k | else if( ( i_id&0xf8 ) == 0x80 || /* 0x80 -> 0x87 */ |
161 | 51.4k | ( i_id&0xf0 ) == 0xc0 ) /* 0xc0 -> 0xcf AC-3, Can also be DD+/E-AC3 in evob */ |
162 | 2.17k | { |
163 | 2.17k | bool b_eac3 = false; |
164 | 2.17k | if( ( i_id&0xf0 ) == 0xc0 ) |
165 | 1.38k | { |
166 | 1.38k | if( p_pkt == NULL || i_pkt < 9 ) |
167 | 0 | return VLC_EGENERIC; |
168 | | |
169 | 1.38k | unsigned i_start = 9 + p_pkt[8]; |
170 | 1.38k | if( i_start + 9 < i_pkt ) |
171 | 1.29k | b_eac3 = ps_is_EAC3( &p_pkt[i_start + 4], i_pkt - i_start - 4 ); |
172 | 1.38k | } |
173 | | |
174 | 2.17k | es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 ); |
175 | 2.17k | tk->i_skip = 4; |
176 | 2.17k | } |
177 | 50.1k | else if( ( i_id&0xfc ) == 0x00 ) /* 0x00 -> 0x03 */ |
178 | 10.5k | { |
179 | 10.5k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_CVD ); |
180 | 10.5k | } |
181 | 39.5k | else if( ( i_id&0xff ) == 0x0b ) /* 0x0b */ |
182 | 1.45k | { |
183 | 1.45k | bool b_eac3 = i_pkt > 8 && ps_is_EAC3( &p_pkt[9], i_pkt - 9 ); |
184 | 1.45k | es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 ); |
185 | 1.45k | } |
186 | 38.0k | else if( ( i_id&0xff ) == 0x10 ) /* 0x10 */ |
187 | 1.09k | { |
188 | 1.09k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_TELETEXT ); |
189 | 1.09k | } |
190 | 37.0k | else if( ( i_id&0xe0 ) == 0x20 ) /* 0x20 -> 0x3f */ |
191 | 17.9k | { |
192 | 17.9k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_SPU ); |
193 | 17.9k | tk->i_skip = 1; |
194 | 17.9k | } |
195 | 19.0k | else if( ( i_id&0xff ) == 0x70 ) /* 0x70 */ |
196 | 10.1k | { |
197 | 10.1k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_OGT ); |
198 | 10.1k | } |
199 | 8.92k | else if( ( i_id&0xf0 ) == 0xa0 ) /* 0xa0 -> 0xaf */ |
200 | 2.20k | { |
201 | 2.20k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVD_LPCM ); |
202 | 2.20k | tk->i_skip = 1; |
203 | 2.20k | } |
204 | 6.71k | else if( ( i_id&0xf0 ) == 0xb0 ) /* 0xb0 -> 0xbf */ |
205 | 1.80k | { |
206 | 1.80k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_TRUEHD ); |
207 | 1.80k | tk->i_skip = 5; |
208 | 1.80k | } |
209 | 4.91k | else |
210 | 4.91k | { |
211 | 4.91k | es_format_Change( &tk->fmt, UNKNOWN_ES, 0 ); |
212 | 4.91k | return VLC_EGENERIC; |
213 | 4.91k | } |
214 | 59.9k | } |
215 | 73.2k | else if( (i_id&0xff00) == PS_PACKET_ID_MASK_EXTENDED ) /* EVOB: 0xFD00 -> 0xFDFF */ |
216 | 1.91k | { |
217 | 1.91k | uint8_t i_sub_id = i_id & 0xff; |
218 | 1.91k | if( ( i_sub_id >= 0x55 && i_sub_id <= 0x5f ) || /* Can be primary VC-1 in evob */ |
219 | 1.75k | ( i_sub_id >= 0x75 && i_sub_id <= 0x7f ) ) /* Secondary VC-1 */ |
220 | 1.17k | { |
221 | 1.17k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_VC1 ); |
222 | 1.17k | } |
223 | 743 | else |
224 | 743 | { |
225 | 743 | es_format_Change( &tk->fmt, UNKNOWN_ES, 0 ); |
226 | 743 | return VLC_EGENERIC; |
227 | 743 | } |
228 | 1.91k | } |
229 | 71.3k | else if( (i_id&0xff00) == PS_PACKET_ID_MASK_AOB ) /* AOB: 0xA000 -> 0xA0FF */ |
230 | 8.23k | { |
231 | 8.23k | uint8_t i_sub_id = i_id & 0x07; |
232 | 8.23k | if( i_sub_id == 0 ) |
233 | 8.23k | { |
234 | 8.23k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVDA_LPCM ); |
235 | 8.23k | tk->i_skip = 1; |
236 | 8.23k | } |
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 | 8.23k | } |
248 | 63.1k | else |
249 | 63.1k | { |
250 | 63.1k | int i_type = ps_id_to_type( p_psm , i_id ); |
251 | | |
252 | 63.1k | es_format_Change( &tk->fmt, UNKNOWN_ES, 0 ); |
253 | | |
254 | 63.1k | if( (i_id&0xf0) == 0xe0 ) /* 0xe0 -> 0xef */ |
255 | 45.0k | { |
256 | 45.0k | if( i_type == 0x01 ) |
257 | 1.37k | { |
258 | 1.37k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV ); |
259 | 1.37k | tk->fmt.i_original_fourcc = VLC_CODEC_MP1V; |
260 | 1.37k | } |
261 | 43.6k | else if( i_type == 0x02 ) |
262 | 0 | { |
263 | 0 | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV ); |
264 | 0 | } |
265 | 43.6k | else if( i_type == 0x10 ) |
266 | 1.03k | { |
267 | 1.03k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MP4V ); |
268 | 1.03k | } |
269 | 42.6k | else if( i_type == 0x1b ) |
270 | 238 | { |
271 | 238 | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); |
272 | 238 | } |
273 | 42.4k | else if( i_type == 0x24 ) |
274 | 1.22k | { |
275 | 1.22k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_HEVC ); |
276 | 1.22k | } |
277 | 41.1k | else if( i_id == 0xe2 || /* Primary H.264 in evob */ |
278 | 33.9k | i_id == 0xe3 ) /* Secondary H.264 in evob */ |
279 | 8.23k | { |
280 | 8.23k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); |
281 | 8.23k | } |
282 | 32.9k | else if( p_pkt && i_type == 0x00 && /* Not from PSM */ |
283 | 32.6k | i_pkt > 9 + 5 && |
284 | 30.5k | i_pkt > 9U + 5 + p_pkt[8] && |
285 | 30.3k | ps_is_H264( &p_pkt[ 9 + p_pkt[8] ], |
286 | 30.3k | i_pkt - 9 - p_pkt[8] ) ) |
287 | 45 | { |
288 | 45 | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); |
289 | 45 | } |
290 | 32.8k | else if( tk->fmt.i_cat == UNKNOWN_ES && |
291 | 32.8k | ( p_pkt != NULL /* Not system */ || b_mpeg2only ) ) |
292 | 32.7k | { |
293 | 32.7k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV ); |
294 | 32.7k | } |
295 | 45.0k | } |
296 | 18.0k | else if( ( i_id&0xe0 ) == 0xc0 ) /* 0xc0 -> 0xdf */ |
297 | 10.7k | { |
298 | 10.7k | if( i_type == 0x03 || |
299 | 10.7k | i_type == 0x04 ) |
300 | 0 | { |
301 | 0 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA ); |
302 | 0 | } |
303 | 10.7k | else if( i_type == 0x0f ) |
304 | 222 | { |
305 | 222 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A ); |
306 | 222 | tk->fmt.i_original_fourcc = VLC_FOURCC('A','D','T','S'); |
307 | 222 | } |
308 | 10.5k | else if( i_type == 0x11 ) |
309 | 698 | { |
310 | 698 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A ); |
311 | 698 | tk->fmt.i_original_fourcc = VLC_FOURCC('L','A','T','M'); |
312 | 698 | } |
313 | 9.87k | else if( i_type == 0x2d ) |
314 | 457 | { |
315 | 457 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPEGH ); |
316 | 457 | } |
317 | 9.41k | else if( tk->fmt.i_cat == UNKNOWN_ES ) |
318 | 9.41k | { |
319 | 9.41k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA ); |
320 | 9.41k | } |
321 | 10.7k | } |
322 | 7.27k | else if( tk->fmt.i_cat == UNKNOWN_ES ) return VLC_EGENERIC; |
323 | 63.1k | } |
324 | | |
325 | | /* PES packets usually contain truncated frames */ |
326 | 120k | tk->fmt.b_packetized = false; |
327 | 120k | tk->fmt.i_priority = ~i_id & 0x0F; |
328 | | |
329 | 120k | if( ps_id_to_lang( p_psm, i_id ) ) |
330 | 5.38k | { |
331 | 5.38k | tk->fmt.psz_language = malloc( 4 ); |
332 | 5.38k | if( tk->fmt.psz_language ) |
333 | 5.38k | { |
334 | 5.38k | memcpy( tk->fmt.psz_language, ps_id_to_lang( p_psm , i_id ), 3 ); |
335 | 5.38k | tk->fmt.psz_language[3] = 0; |
336 | 5.38k | } |
337 | 5.38k | } |
338 | | |
339 | 120k | return (tk->fmt.i_cat != UNKNOWN_ES || p_pkt) ? VLC_SUCCESS : VLC_EGENERIC; |
340 | 133k | } Line | Count | Source | 148 | 133k | { | 149 | 133k | tk->i_skip = 0; | 150 | 133k | tk->i_id = i_id; | 151 | | | 152 | 133k | if( ( i_id&0xff00 ) == PS_PACKET_ID_MASK_VOB ) /* 0xBD00 -> 0xBDFF, VOB Private Stream 1 */ | 153 | 59.9k | { | 154 | 59.9k | if( ( i_id&0xf8 ) == 0x88 || /* 0x88 -> 0x8f - Can be DTS-HD primary audio in evob */ | 155 | 52.3k | ( i_id&0xf8 ) == 0x98 ) /* 0x98 -> 0x9f - Can be DTS-HD secondary audio in evob */ | 156 | 7.71k | { | 157 | 7.71k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DTS ); | 158 | 7.71k | tk->i_skip = 4; | 159 | 7.71k | } | 160 | 52.2k | else if( ( i_id&0xf8 ) == 0x80 || /* 0x80 -> 0x87 */ | 161 | 51.4k | ( i_id&0xf0 ) == 0xc0 ) /* 0xc0 -> 0xcf AC-3, Can also be DD+/E-AC3 in evob */ | 162 | 2.17k | { | 163 | 2.17k | bool b_eac3 = false; | 164 | 2.17k | if( ( i_id&0xf0 ) == 0xc0 ) | 165 | 1.38k | { | 166 | 1.38k | if( p_pkt == NULL || i_pkt < 9 ) | 167 | 0 | return VLC_EGENERIC; | 168 | | | 169 | 1.38k | unsigned i_start = 9 + p_pkt[8]; | 170 | 1.38k | if( i_start + 9 < i_pkt ) | 171 | 1.29k | b_eac3 = ps_is_EAC3( &p_pkt[i_start + 4], i_pkt - i_start - 4 ); | 172 | 1.38k | } | 173 | | | 174 | 2.17k | es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 ); | 175 | 2.17k | tk->i_skip = 4; | 176 | 2.17k | } | 177 | 50.1k | else if( ( i_id&0xfc ) == 0x00 ) /* 0x00 -> 0x03 */ | 178 | 10.5k | { | 179 | 10.5k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_CVD ); | 180 | 10.5k | } | 181 | 39.5k | else if( ( i_id&0xff ) == 0x0b ) /* 0x0b */ | 182 | 1.45k | { | 183 | 1.45k | bool b_eac3 = i_pkt > 8 && ps_is_EAC3( &p_pkt[9], i_pkt - 9 ); | 184 | 1.45k | es_format_Change( &tk->fmt, AUDIO_ES, b_eac3 ? VLC_CODEC_EAC3 : VLC_CODEC_A52 ); | 185 | 1.45k | } | 186 | 38.0k | else if( ( i_id&0xff ) == 0x10 ) /* 0x10 */ | 187 | 1.09k | { | 188 | 1.09k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_TELETEXT ); | 189 | 1.09k | } | 190 | 37.0k | else if( ( i_id&0xe0 ) == 0x20 ) /* 0x20 -> 0x3f */ | 191 | 17.9k | { | 192 | 17.9k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_SPU ); | 193 | 17.9k | tk->i_skip = 1; | 194 | 17.9k | } | 195 | 19.0k | else if( ( i_id&0xff ) == 0x70 ) /* 0x70 */ | 196 | 10.1k | { | 197 | 10.1k | es_format_Change( &tk->fmt, SPU_ES, VLC_CODEC_OGT ); | 198 | 10.1k | } | 199 | 8.92k | else if( ( i_id&0xf0 ) == 0xa0 ) /* 0xa0 -> 0xaf */ | 200 | 2.20k | { | 201 | 2.20k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVD_LPCM ); | 202 | 2.20k | tk->i_skip = 1; | 203 | 2.20k | } | 204 | 6.71k | else if( ( i_id&0xf0 ) == 0xb0 ) /* 0xb0 -> 0xbf */ | 205 | 1.80k | { | 206 | 1.80k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_TRUEHD ); | 207 | 1.80k | tk->i_skip = 5; | 208 | 1.80k | } | 209 | 4.91k | else | 210 | 4.91k | { | 211 | 4.91k | es_format_Change( &tk->fmt, UNKNOWN_ES, 0 ); | 212 | 4.91k | return VLC_EGENERIC; | 213 | 4.91k | } | 214 | 59.9k | } | 215 | 73.2k | else if( (i_id&0xff00) == PS_PACKET_ID_MASK_EXTENDED ) /* EVOB: 0xFD00 -> 0xFDFF */ | 216 | 1.91k | { | 217 | 1.91k | uint8_t i_sub_id = i_id & 0xff; | 218 | 1.91k | if( ( i_sub_id >= 0x55 && i_sub_id <= 0x5f ) || /* Can be primary VC-1 in evob */ | 219 | 1.75k | ( i_sub_id >= 0x75 && i_sub_id <= 0x7f ) ) /* Secondary VC-1 */ | 220 | 1.17k | { | 221 | 1.17k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_VC1 ); | 222 | 1.17k | } | 223 | 743 | else | 224 | 743 | { | 225 | 743 | es_format_Change( &tk->fmt, UNKNOWN_ES, 0 ); | 226 | 743 | return VLC_EGENERIC; | 227 | 743 | } | 228 | 1.91k | } | 229 | 71.3k | else if( (i_id&0xff00) == PS_PACKET_ID_MASK_AOB ) /* AOB: 0xA000 -> 0xA0FF */ | 230 | 8.23k | { | 231 | 8.23k | uint8_t i_sub_id = i_id & 0x07; | 232 | 8.23k | if( i_sub_id == 0 ) | 233 | 8.23k | { | 234 | 8.23k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_DVDA_LPCM ); | 235 | 8.23k | tk->i_skip = 1; | 236 | 8.23k | } | 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 | 8.23k | } | 248 | 63.1k | else | 249 | 63.1k | { | 250 | 63.1k | int i_type = ps_id_to_type( p_psm , i_id ); | 251 | | | 252 | 63.1k | es_format_Change( &tk->fmt, UNKNOWN_ES, 0 ); | 253 | | | 254 | 63.1k | if( (i_id&0xf0) == 0xe0 ) /* 0xe0 -> 0xef */ | 255 | 45.0k | { | 256 | 45.0k | if( i_type == 0x01 ) | 257 | 1.37k | { | 258 | 1.37k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV ); | 259 | 1.37k | tk->fmt.i_original_fourcc = VLC_CODEC_MP1V; | 260 | 1.37k | } | 261 | 43.6k | else if( i_type == 0x02 ) | 262 | 0 | { | 263 | 0 | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV ); | 264 | 0 | } | 265 | 43.6k | else if( i_type == 0x10 ) | 266 | 1.03k | { | 267 | 1.03k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MP4V ); | 268 | 1.03k | } | 269 | 42.6k | else if( i_type == 0x1b ) | 270 | 238 | { | 271 | 238 | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); | 272 | 238 | } | 273 | 42.4k | else if( i_type == 0x24 ) | 274 | 1.22k | { | 275 | 1.22k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_HEVC ); | 276 | 1.22k | } | 277 | 41.1k | else if( i_id == 0xe2 || /* Primary H.264 in evob */ | 278 | 33.9k | i_id == 0xe3 ) /* Secondary H.264 in evob */ | 279 | 8.23k | { | 280 | 8.23k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); | 281 | 8.23k | } | 282 | 32.9k | else if( p_pkt && i_type == 0x00 && /* Not from PSM */ | 283 | 32.6k | i_pkt > 9 + 5 && | 284 | 30.5k | i_pkt > 9U + 5 + p_pkt[8] && | 285 | 30.3k | ps_is_H264( &p_pkt[ 9 + p_pkt[8] ], | 286 | 30.3k | i_pkt - 9 - p_pkt[8] ) ) | 287 | 45 | { | 288 | 45 | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_H264 ); | 289 | 45 | } | 290 | 32.8k | else if( tk->fmt.i_cat == UNKNOWN_ES && | 291 | 32.8k | ( p_pkt != NULL /* Not system */ || b_mpeg2only ) ) | 292 | 32.7k | { | 293 | 32.7k | es_format_Change( &tk->fmt, VIDEO_ES, VLC_CODEC_MPGV ); | 294 | 32.7k | } | 295 | 45.0k | } | 296 | 18.0k | else if( ( i_id&0xe0 ) == 0xc0 ) /* 0xc0 -> 0xdf */ | 297 | 10.7k | { | 298 | 10.7k | if( i_type == 0x03 || | 299 | 10.7k | i_type == 0x04 ) | 300 | 0 | { | 301 | 0 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA ); | 302 | 0 | } | 303 | 10.7k | else if( i_type == 0x0f ) | 304 | 222 | { | 305 | 222 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A ); | 306 | 222 | tk->fmt.i_original_fourcc = VLC_FOURCC('A','D','T','S'); | 307 | 222 | } | 308 | 10.5k | else if( i_type == 0x11 ) | 309 | 698 | { | 310 | 698 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MP4A ); | 311 | 698 | tk->fmt.i_original_fourcc = VLC_FOURCC('L','A','T','M'); | 312 | 698 | } | 313 | 9.87k | else if( i_type == 0x2d ) | 314 | 457 | { | 315 | 457 | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPEGH ); | 316 | 457 | } | 317 | 9.41k | else if( tk->fmt.i_cat == UNKNOWN_ES ) | 318 | 9.41k | { | 319 | 9.41k | es_format_Change( &tk->fmt, AUDIO_ES, VLC_CODEC_MPGA ); | 320 | 9.41k | } | 321 | 10.7k | } | 322 | 7.27k | else if( tk->fmt.i_cat == UNKNOWN_ES ) return VLC_EGENERIC; | 323 | 63.1k | } | 324 | | | 325 | | /* PES packets usually contain truncated frames */ | 326 | 120k | tk->fmt.b_packetized = false; | 327 | 120k | tk->fmt.i_priority = ~i_id & 0x0F; | 328 | | | 329 | 120k | if( ps_id_to_lang( p_psm, i_id ) ) | 330 | 5.38k | { | 331 | 5.38k | tk->fmt.psz_language = malloc( 4 ); | 332 | 5.38k | if( tk->fmt.psz_language ) | 333 | 5.38k | { | 334 | 5.38k | memcpy( tk->fmt.psz_language, ps_id_to_lang( p_psm , i_id ), 3 ); | 335 | 5.38k | tk->fmt.psz_language[3] = 0; | 336 | 5.38k | } | 337 | 5.38k | } | 338 | | | 339 | 120k | return (tk->fmt.i_cat != UNKNOWN_ES || p_pkt) ? VLC_SUCCESS : VLC_EGENERIC; | 340 | 133k | } |
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 | 262k | { |
345 | 262k | if(unlikely(i_pkt < 4)) |
346 | 0 | return 0; |
347 | 262k | if( p_pkt[3] == STREAM_ID_PRIVATE_STREAM_1 ) |
348 | 186k | { |
349 | 186k | uint8_t i_sub_id = 0; |
350 | 186k | if( i_pkt >= 9 && |
351 | 180k | i_pkt > 9 + (size_t)p_pkt[8] ) |
352 | 160k | { |
353 | 160k | const unsigned i_start = 9 + p_pkt[8]; |
354 | 160k | i_sub_id = p_pkt[i_start]; |
355 | | |
356 | 160k | if( i_sub_id == 0xa0 && |
357 | 4.93k | i_pkt >= i_start + 7 && |
358 | 4.86k | p_pkt[i_start + 6] != 0x80 ) |
359 | 4.85k | { |
360 | | /* AOB LPCM extension */ |
361 | 4.85k | return PS_PACKET_ID_MASK_AOB | (i_sub_id & 0x01); |
362 | 4.85k | } |
363 | | |
364 | 155k | if( i_sub_id == 0xa1 && |
365 | 961 | 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 | 155k | } |
371 | | |
372 | | /* VOB extension */ |
373 | 181k | return PS_PACKET_ID_MASK_VOB | i_sub_id; |
374 | 186k | } |
375 | 75.6k | if( i_pkt >= 9 && |
376 | 72.5k | p_pkt[3] == STREAM_ID_EXTENDED_STREAM_ID && |
377 | 5.63k | (p_pkt[6]&0xC0) == 0x80 && /* mpeg2 */ |
378 | 3.35k | (p_pkt[7]&0x01) == 0x01 ) /* extension_flag */ |
379 | 2.83k | { |
380 | | /* ISO 13818 amendment 2 and SMPTE RP 227 */ |
381 | 2.83k | const uint8_t i_flags = p_pkt[7]; |
382 | 2.83k | unsigned int i_skip = 9; |
383 | | |
384 | | /* Find PES extension */ |
385 | 2.83k | if( (i_flags & 0x80 ) ) |
386 | 1.66k | { |
387 | 1.66k | i_skip += 5; /* pts */ |
388 | 1.66k | if( (i_flags & 0x40) ) |
389 | 1.65k | i_skip += 5; /* dts */ |
390 | 1.66k | } |
391 | 2.83k | if( (i_flags & 0x20 ) ) |
392 | 2.17k | i_skip += 6; |
393 | 2.83k | if( (i_flags & 0x10 ) ) |
394 | 1.73k | i_skip += 3; |
395 | 2.83k | if( (i_flags & 0x08 ) ) |
396 | 2.61k | i_skip += 1; |
397 | 2.83k | if( (i_flags & 0x04 ) ) |
398 | 1.83k | i_skip += 1; |
399 | 2.83k | if( (i_flags & 0x02 ) ) |
400 | 1.66k | i_skip += 2; |
401 | | |
402 | 2.83k | if( i_skip < i_pkt && (p_pkt[i_skip]&0x01) ) |
403 | 1.74k | { |
404 | 1.74k | const uint8_t i_flags2 = p_pkt[i_skip]; |
405 | | |
406 | | /* Find PES extension 2 */ |
407 | 1.74k | i_skip += 1; |
408 | 1.74k | if( i_flags2 & 0x80 ) |
409 | 181 | i_skip += 16; |
410 | 1.74k | if( (i_flags2 & 0x40) && i_skip < i_pkt ) |
411 | 672 | i_skip += 1 + p_pkt[i_skip]; |
412 | 1.74k | if( i_flags2 & 0x20 ) |
413 | 640 | i_skip += 2; |
414 | 1.74k | if( i_flags2 & 0x10 ) |
415 | 594 | i_skip += 2; |
416 | | |
417 | 1.74k | if( i_skip + 1 < i_pkt ) |
418 | 1.22k | { |
419 | 1.22k | const int i_extension_field_length = p_pkt[i_skip]&0x7f; |
420 | 1.22k | if( i_extension_field_length >=1 ) |
421 | 1.10k | { |
422 | 1.10k | int i_stream_id_extension_flag = (p_pkt[i_skip+1] >> 7)&0x1; |
423 | 1.10k | if( i_stream_id_extension_flag == 0 ) |
424 | 1.05k | return PS_PACKET_ID_MASK_EXTENDED | (p_pkt[i_skip+1]&0x7f); |
425 | 1.10k | } |
426 | 1.22k | } |
427 | 1.74k | } |
428 | 2.83k | } |
429 | 74.5k | return p_pkt[3]; |
430 | 75.6k | } Line | Count | Source | 344 | 262k | { | 345 | 262k | if(unlikely(i_pkt < 4)) | 346 | 0 | return 0; | 347 | 262k | if( p_pkt[3] == STREAM_ID_PRIVATE_STREAM_1 ) | 348 | 186k | { | 349 | 186k | uint8_t i_sub_id = 0; | 350 | 186k | if( i_pkt >= 9 && | 351 | 180k | i_pkt > 9 + (size_t)p_pkt[8] ) | 352 | 160k | { | 353 | 160k | const unsigned i_start = 9 + p_pkt[8]; | 354 | 160k | i_sub_id = p_pkt[i_start]; | 355 | | | 356 | 160k | if( i_sub_id == 0xa0 && | 357 | 4.93k | i_pkt >= i_start + 7 && | 358 | 4.86k | p_pkt[i_start + 6] != 0x80 ) | 359 | 4.85k | { | 360 | | /* AOB LPCM extension */ | 361 | 4.85k | return PS_PACKET_ID_MASK_AOB | (i_sub_id & 0x01); | 362 | 4.85k | } | 363 | | | 364 | 155k | if( i_sub_id == 0xa1 && | 365 | 961 | 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 | 155k | } | 371 | | | 372 | | /* VOB extension */ | 373 | 181k | return PS_PACKET_ID_MASK_VOB | i_sub_id; | 374 | 186k | } | 375 | 75.6k | if( i_pkt >= 9 && | 376 | 72.5k | p_pkt[3] == STREAM_ID_EXTENDED_STREAM_ID && | 377 | 5.63k | (p_pkt[6]&0xC0) == 0x80 && /* mpeg2 */ | 378 | 3.35k | (p_pkt[7]&0x01) == 0x01 ) /* extension_flag */ | 379 | 2.83k | { | 380 | | /* ISO 13818 amendment 2 and SMPTE RP 227 */ | 381 | 2.83k | const uint8_t i_flags = p_pkt[7]; | 382 | 2.83k | unsigned int i_skip = 9; | 383 | | | 384 | | /* Find PES extension */ | 385 | 2.83k | if( (i_flags & 0x80 ) ) | 386 | 1.66k | { | 387 | 1.66k | i_skip += 5; /* pts */ | 388 | 1.66k | if( (i_flags & 0x40) ) | 389 | 1.65k | i_skip += 5; /* dts */ | 390 | 1.66k | } | 391 | 2.83k | if( (i_flags & 0x20 ) ) | 392 | 2.17k | i_skip += 6; | 393 | 2.83k | if( (i_flags & 0x10 ) ) | 394 | 1.73k | i_skip += 3; | 395 | 2.83k | if( (i_flags & 0x08 ) ) | 396 | 2.61k | i_skip += 1; | 397 | 2.83k | if( (i_flags & 0x04 ) ) | 398 | 1.83k | i_skip += 1; | 399 | 2.83k | if( (i_flags & 0x02 ) ) | 400 | 1.66k | i_skip += 2; | 401 | | | 402 | 2.83k | if( i_skip < i_pkt && (p_pkt[i_skip]&0x01) ) | 403 | 1.74k | { | 404 | 1.74k | const uint8_t i_flags2 = p_pkt[i_skip]; | 405 | | | 406 | | /* Find PES extension 2 */ | 407 | 1.74k | i_skip += 1; | 408 | 1.74k | if( i_flags2 & 0x80 ) | 409 | 181 | i_skip += 16; | 410 | 1.74k | if( (i_flags2 & 0x40) && i_skip < i_pkt ) | 411 | 672 | i_skip += 1 + p_pkt[i_skip]; | 412 | 1.74k | if( i_flags2 & 0x20 ) | 413 | 640 | i_skip += 2; | 414 | 1.74k | if( i_flags2 & 0x10 ) | 415 | 594 | i_skip += 2; | 416 | | | 417 | 1.74k | if( i_skip + 1 < i_pkt ) | 418 | 1.22k | { | 419 | 1.22k | const int i_extension_field_length = p_pkt[i_skip]&0x7f; | 420 | 1.22k | if( i_extension_field_length >=1 ) | 421 | 1.10k | { | 422 | 1.10k | int i_stream_id_extension_flag = (p_pkt[i_skip+1] >> 7)&0x1; | 423 | 1.10k | if( i_stream_id_extension_flag == 0 ) | 424 | 1.05k | return PS_PACKET_ID_MASK_EXTENDED | (p_pkt[i_skip+1]&0x7f); | 425 | 1.10k | } | 426 | 1.22k | } | 427 | 1.74k | } | 428 | 2.83k | } | 429 | 74.5k | return p_pkt[3]; | 430 | 75.6k | } |
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 | 303k | { |
435 | 303k | if( unlikely(i_peek < 4) ) |
436 | 0 | return -1; |
437 | | |
438 | 303k | switch( p[3] ) |
439 | 303k | { |
440 | 8.81k | case PS_STREAM_ID_END_STREAM: |
441 | 8.81k | return 4; |
442 | | |
443 | 1.38k | case PS_STREAM_ID_PACK_HEADER: |
444 | 1.38k | if( i_peek > 4 ) |
445 | 1.38k | { |
446 | 1.38k | if( i_peek >= 14 && (p[4] >> 6) == 0x01 ) |
447 | 181 | return 14 + (p[13]&0x07); |
448 | 1.20k | if( i_peek >= 12 && (p[4] >> 4) == 0x02 ) |
449 | 1.20k | return 12; |
450 | 1.20k | } |
451 | 7 | break; |
452 | | |
453 | 6.47k | case PS_STREAM_ID_SYSTEM_HEADER: |
454 | 47.8k | case STREAM_ID_PROGRAM_STREAM_MAP: |
455 | 48.1k | case STREAM_ID_PROGRAM_STREAM_DIRECTORY: |
456 | 292k | default: |
457 | 292k | if( i_peek >= 6 ) |
458 | 292k | return 6 + ((p[4]<<8) | p[5] ); |
459 | 303k | } |
460 | 15 | return -1; |
461 | 303k | } Line | Count | Source | 434 | 303k | { | 435 | 303k | if( unlikely(i_peek < 4) ) | 436 | 0 | return -1; | 437 | | | 438 | 303k | switch( p[3] ) | 439 | 303k | { | 440 | 8.81k | case PS_STREAM_ID_END_STREAM: | 441 | 8.81k | return 4; | 442 | | | 443 | 1.38k | case PS_STREAM_ID_PACK_HEADER: | 444 | 1.38k | if( i_peek > 4 ) | 445 | 1.38k | { | 446 | 1.38k | if( i_peek >= 14 && (p[4] >> 6) == 0x01 ) | 447 | 181 | return 14 + (p[13]&0x07); | 448 | 1.20k | if( i_peek >= 12 && (p[4] >> 4) == 0x02 ) | 449 | 1.20k | return 12; | 450 | 1.20k | } | 451 | 7 | break; | 452 | | | 453 | 6.47k | case PS_STREAM_ID_SYSTEM_HEADER: | 454 | 47.8k | case STREAM_ID_PROGRAM_STREAM_MAP: | 455 | 48.1k | case STREAM_ID_PROGRAM_STREAM_DIRECTORY: | 456 | 292k | default: | 457 | 292k | if( i_peek >= 6 ) | 458 | 292k | return 6 + ((p[4]<<8) | p[5] ); | 459 | 303k | } | 460 | 15 | return -1; | 461 | 303k | } |
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 | 783 | { |
467 | 783 | const uint8_t *p = p_pkt; |
468 | 783 | ts_90khz_t i_scr; |
469 | 783 | if( i_pkt >= 14 && (p[4] >> 6) == 0x01 ) /* 0b01 H.222 MPEG-2 Pack Header */ |
470 | 112 | { |
471 | 112 | i_scr = ExtractPackHeaderTimestamp( &p[4] ); |
472 | 112 | *pi_mux_rate = ( p[10] << 14 )|( p[11] << 6 )|( p[12] >> 2); |
473 | 112 | } |
474 | 671 | else if( i_pkt >= 12 && (p[4] >> 4) == 0x02 ) /* 0b0010 ISO 11172-1 MPEG-1 Pack Header */ |
475 | 671 | { |
476 | 671 | if(!ExtractPESTimestamp( &p[4], 0x02, &i_scr )) /* same bits as PES/PTS */ |
477 | 116 | return VLC_EGENERIC; |
478 | 555 | *pi_mux_rate = ( ( p[9]&0x7f )<< 15 )|( p[10] << 7 )|( p[11] >> 1); |
479 | 555 | } |
480 | 0 | else |
481 | 0 | { |
482 | 0 | return VLC_EGENERIC; |
483 | 0 | } |
484 | 667 | *pi_scr = FROM_SCALE( i_scr ); |
485 | 667 | return VLC_SUCCESS; |
486 | 783 | } Line | Count | Source | 466 | 783 | { | 467 | 783 | const uint8_t *p = p_pkt; | 468 | 783 | ts_90khz_t i_scr; | 469 | 783 | if( i_pkt >= 14 && (p[4] >> 6) == 0x01 ) /* 0b01 H.222 MPEG-2 Pack Header */ | 470 | 112 | { | 471 | 112 | i_scr = ExtractPackHeaderTimestamp( &p[4] ); | 472 | 112 | *pi_mux_rate = ( p[10] << 14 )|( p[11] << 6 )|( p[12] >> 2); | 473 | 112 | } | 474 | 671 | else if( i_pkt >= 12 && (p[4] >> 4) == 0x02 ) /* 0b0010 ISO 11172-1 MPEG-1 Pack Header */ | 475 | 671 | { | 476 | 671 | if(!ExtractPESTimestamp( &p[4], 0x02, &i_scr )) /* same bits as PES/PTS */ | 477 | 116 | return VLC_EGENERIC; | 478 | 555 | *pi_mux_rate = ( ( p[9]&0x7f )<< 15 )|( p[10] << 7 )|( p[11] >> 1); | 479 | 555 | } | 480 | 0 | else | 481 | 0 | { | 482 | 0 | return VLC_EGENERIC; | 483 | 0 | } | 484 | 667 | *pi_scr = FROM_SCALE( i_scr ); | 485 | 667 | return VLC_SUCCESS; | 486 | 783 | } |
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 | 4.51k | { |
493 | 4.51k | const uint8_t *p = &p_pkt[6 + 3 + 1 + 1 + 1]; |
494 | 4.51k | 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 | 12.0k | while( p < p_pktend && (p[0] & 0x80) ) |
499 | 7.66k | { |
500 | 7.66k | int i_id = p[0]; |
501 | 7.66k | switch( i_id ) |
502 | 7.66k | { |
503 | 291 | case 0xB7: |
504 | 291 | if( p_pktend - p < 6 ) |
505 | 0 | return VLC_EGENERIC; |
506 | 291 | i_id = PS_PACKET_ID_MASK_EXTENDED | (p[2] & 0x7F); |
507 | 291 | p += 6; |
508 | 291 | break; |
509 | 7.37k | default: |
510 | 7.37k | if( p_pktend - p < 3 ) |
511 | 141 | return VLC_EGENERIC; |
512 | 7.23k | p += 3; |
513 | 7.23k | break; |
514 | 7.66k | } |
515 | | |
516 | 7.52k | if( i_id < 0xc0 ) |
517 | 1.88k | continue; |
518 | | |
519 | 5.63k | unsigned i_tk = ps_id_to_tk( i_id ); |
520 | 5.63k | if( !tk[i_tk].b_configured ) |
521 | 5.39k | ps_track_fill( &tk[i_tk], p_psm, i_id, NULL, 0, false ); |
522 | 5.63k | } |
523 | 4.37k | return VLC_SUCCESS; |
524 | 4.51k | } Line | Count | Source | 492 | 4.51k | { | 493 | 4.51k | const uint8_t *p = &p_pkt[6 + 3 + 1 + 1 + 1]; | 494 | 4.51k | 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 | 12.0k | while( p < p_pktend && (p[0] & 0x80) ) | 499 | 7.66k | { | 500 | 7.66k | int i_id = p[0]; | 501 | 7.66k | switch( i_id ) | 502 | 7.66k | { | 503 | 291 | case 0xB7: | 504 | 291 | if( p_pktend - p < 6 ) | 505 | 0 | return VLC_EGENERIC; | 506 | 291 | i_id = PS_PACKET_ID_MASK_EXTENDED | (p[2] & 0x7F); | 507 | 291 | p += 6; | 508 | 291 | break; | 509 | 7.37k | default: | 510 | 7.37k | if( p_pktend - p < 3 ) | 511 | 141 | return VLC_EGENERIC; | 512 | 7.23k | p += 3; | 513 | 7.23k | break; | 514 | 7.66k | } | 515 | | | 516 | 7.52k | if( i_id < 0xc0 ) | 517 | 1.88k | continue; | 518 | | | 519 | 5.63k | unsigned i_tk = ps_id_to_tk( i_id ); | 520 | 5.63k | if( !tk[i_tk].b_configured ) | 521 | 5.39k | ps_track_fill( &tk[i_tk], p_psm, i_id, NULL, 0, false ); | 522 | 5.63k | } | 523 | 4.37k | return VLC_SUCCESS; | 524 | 4.51k | } |
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 | 234k | { |
529 | 234k | unsigned int i_skip; |
530 | 234k | ts_pes_header_t pesh; |
531 | 234k | ts_pes_header_init( &pesh ); |
532 | | |
533 | 234k | if( ParsePESHeader( p_object->logger, p_pes->p_buffer, p_pes->i_buffer, &pesh ) != VLC_SUCCESS ) |
534 | 45.3k | return VLC_EGENERIC; |
535 | | |
536 | 189k | i_skip = pesh.i_size; |
537 | | |
538 | 189k | if( pesh.b_scrambling ) |
539 | 7.07k | p_pes->i_flags |= BLOCK_FLAG_SCRAMBLED; |
540 | | |
541 | 189k | if( i_skip_extra >= 0 ) |
542 | 189k | 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 | 189k | if( p_pes->i_buffer <= i_skip ) |
549 | 10.7k | { |
550 | 10.7k | return VLC_EGENERIC; |
551 | 10.7k | } |
552 | | |
553 | 178k | p_pes->p_buffer += i_skip; |
554 | 178k | p_pes->i_buffer -= i_skip; |
555 | | |
556 | 178k | if( pesh.i_pts != TS_90KHZ_INVALID ) |
557 | 125k | { |
558 | 125k | p_pes->i_pts = FROM_SCALE( pesh.i_pts ); |
559 | 125k | if( pesh.i_dts != TS_90KHZ_INVALID ) |
560 | 20.7k | p_pes->i_dts = FROM_SCALE( pesh.i_dts ); |
561 | 105k | else /* ISO/IEC 13818-1 2.7.5: if pts and no dts, then dts == pts */ |
562 | 105k | p_pes->i_dts = p_pes->i_pts; |
563 | 125k | } |
564 | | |
565 | 178k | return VLC_SUCCESS; |
566 | 189k | } Line | Count | Source | 528 | 234k | { | 529 | 234k | unsigned int i_skip; | 530 | 234k | ts_pes_header_t pesh; | 531 | 234k | ts_pes_header_init( &pesh ); | 532 | | | 533 | 234k | if( ParsePESHeader( p_object->logger, p_pes->p_buffer, p_pes->i_buffer, &pesh ) != VLC_SUCCESS ) | 534 | 45.3k | return VLC_EGENERIC; | 535 | | | 536 | 189k | i_skip = pesh.i_size; | 537 | | | 538 | 189k | if( pesh.b_scrambling ) | 539 | 7.07k | p_pes->i_flags |= BLOCK_FLAG_SCRAMBLED; | 540 | | | 541 | 189k | if( i_skip_extra >= 0 ) | 542 | 189k | 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 | 189k | if( p_pes->i_buffer <= i_skip ) | 549 | 10.7k | { | 550 | 10.7k | return VLC_EGENERIC; | 551 | 10.7k | } | 552 | | | 553 | 178k | p_pes->p_buffer += i_skip; | 554 | 178k | p_pes->i_buffer -= i_skip; | 555 | | | 556 | 178k | if( pesh.i_pts != TS_90KHZ_INVALID ) | 557 | 125k | { | 558 | 125k | p_pes->i_pts = FROM_SCALE( pesh.i_pts ); | 559 | 125k | if( pesh.i_dts != TS_90KHZ_INVALID ) | 560 | 20.7k | p_pes->i_dts = FROM_SCALE( pesh.i_dts ); | 561 | 105k | else /* ISO/IEC 13818-1 2.7.5: if pts and no dts, then dts == pts */ | 562 | 105k | p_pes->i_dts = p_pes->i_pts; | 563 | 125k | } | 564 | | | 565 | 178k | return VLC_SUCCESS; | 566 | 189k | } |
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 | 63.1k | { |
596 | 63.1k | size_t i; |
597 | 139k | for( i = 0; p_psm && i < p_psm->i_es; i++ ) |
598 | 82.5k | { |
599 | 82.5k | if( p_psm->es[i].i_id == i_id ) return p_psm->es[i].i_type; |
600 | 82.5k | } |
601 | 57.2k | return 0; |
602 | 63.1k | } Line | Count | Source | 595 | 63.1k | { | 596 | 63.1k | size_t i; | 597 | 139k | for( i = 0; p_psm && i < p_psm->i_es; i++ ) | 598 | 82.5k | { | 599 | 82.5k | if( p_psm->es[i].i_id == i_id ) return p_psm->es[i].i_type; | 600 | 82.5k | } | 601 | 57.2k | return 0; | 602 | 63.1k | } |
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 | 125k | { |
606 | 125k | size_t i; |
607 | 296k | for( i = 0; p_psm && i < p_psm->i_es; i++ ) |
608 | 181k | { |
609 | 181k | if( p_psm->es[i].i_id == i_id ) |
610 | 10.7k | return p_psm->es[i].desc.lang; |
611 | 181k | } |
612 | 114k | return 0; |
613 | 125k | } Line | Count | Source | 605 | 125k | { | 606 | 125k | size_t i; | 607 | 296k | for( i = 0; p_psm && i < p_psm->i_es; i++ ) | 608 | 181k | { | 609 | 181k | if( p_psm->es[i].i_id == i_id ) | 610 | 10.7k | return p_psm->es[i].desc.lang; | 611 | 181k | } | 612 | 114k | return 0; | 613 | 125k | } |
Unexecuted instantiation: vobsub.c:ps_id_to_lang |
614 | | |
615 | | static inline void ps_psm_init( ps_psm_t *p_psm ) |
616 | 572 | { |
617 | 572 | p_psm->i_version = 0xFF; |
618 | 572 | p_psm->i_es = 0; |
619 | 572 | p_psm->es = 0; |
620 | 572 | memset( &p_psm->uniqueextdesc, 0, 3 ); |
621 | 572 | } Line | Count | Source | 616 | 572 | { | 617 | 572 | p_psm->i_version = 0xFF; | 618 | 572 | p_psm->i_es = 0; | 619 | 572 | p_psm->es = 0; | 620 | 572 | memset( &p_psm->uniqueextdesc, 0, 3 ); | 621 | 572 | } |
Unexecuted instantiation: vobsub.c:ps_psm_init |
622 | | |
623 | | static inline void ps_psm_destroy( ps_psm_t *p_psm ) |
624 | 19.1k | { |
625 | 19.1k | free( p_psm->es ); |
626 | 19.1k | p_psm->es = NULL; |
627 | 19.1k | p_psm->i_es = 0; |
628 | 19.1k | } Line | Count | Source | 624 | 19.1k | { | 625 | 19.1k | free( p_psm->es ); | 626 | | p_psm->es = NULL; | 627 | 19.1k | p_psm->i_es = 0; | 628 | 19.1k | } |
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 | 13.6k | { |
633 | 24.0k | while( i_data > 3 && i_data > 2u + p_data[1] ) |
634 | 10.3k | { |
635 | 10.3k | switch( p_data[0] ) |
636 | 10.3k | { |
637 | 453 | case 0x0A: /* ISO_639_language_descriptor */ |
638 | 453 | if( i_data >= 6 ) |
639 | 441 | memcpy( p_desc->lang, &p_data[2], 3 ); |
640 | 453 | break; |
641 | | |
642 | 9.92k | default: |
643 | 9.92k | break; |
644 | 10.3k | } |
645 | 10.3k | uint8_t i_desc_size = p_data[1]; |
646 | 10.3k | p_data += 2 + i_desc_size; |
647 | 10.3k | i_data -= 2 + i_desc_size; |
648 | 10.3k | } |
649 | 13.6k | } ps.c:ps_parse_descriptors Line | Count | Source | 632 | 13.6k | { | 633 | 24.0k | while( i_data > 3 && i_data > 2u + p_data[1] ) | 634 | 10.3k | { | 635 | 10.3k | switch( p_data[0] ) | 636 | 10.3k | { | 637 | 453 | case 0x0A: /* ISO_639_language_descriptor */ | 638 | 453 | if( i_data >= 6 ) | 639 | 441 | memcpy( p_desc->lang, &p_data[2], 3 ); | 640 | 453 | break; | 641 | | | 642 | 9.92k | default: | 643 | 9.92k | break; | 644 | 10.3k | } | 645 | 10.3k | uint8_t i_desc_size = p_data[1]; | 646 | 10.3k | p_data += 2 + i_desc_size; | 647 | 10.3k | i_data -= 2 + i_desc_size; | 648 | 10.3k | } | 649 | 13.6k | } |
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 | 26.5k | { |
655 | 26.5k | size_t i_length, i_info_length, i_es_base; |
656 | 26.5k | uint8_t i_version; |
657 | 26.5k | 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 | 26.5k | assert(i_pkt >= 4); |
662 | 26.5k | if( !p_psm || i_pkt < 10 || p_buffer[3] != STREAM_ID_PROGRAM_STREAM_MAP) |
663 | 35 | return VLC_EGENERIC; |
664 | | |
665 | 26.5k | i_length = GetWBE(&p_buffer[4]) + 6; |
666 | 26.5k | if( i_length > i_pkt ) return VLC_EGENERIC; |
667 | | |
668 | 26.5k | if((p_buffer[6] & 0x80) == 0) /* current_next_indicator */ |
669 | 874 | return VLC_EGENERIC; |
670 | | |
671 | 25.6k | b_single_extension = p_buffer[6] & 0x40; |
672 | 25.6k | i_version = (p_buffer[6] & 0xf8); |
673 | | |
674 | 25.6k | if( p_psm->i_version == i_version ) return VLC_EGENERIC; |
675 | | |
676 | 18.6k | ps_psm_destroy( p_psm ); |
677 | | |
678 | 18.6k | i_info_length = GetWBE(&p_buffer[8]); |
679 | 18.6k | if( i_info_length + 10 > i_length ) |
680 | 867 | 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 | 17.7k | i_es_base = 12 + i_info_length; |
686 | | |
687 | 31.4k | while( i_es_base + 4 < i_length ) |
688 | 26.3k | { |
689 | 26.3k | ps_es_t *tmp_es = realloc( p_psm->es, sizeof(ps_es_t) * (p_psm->i_es+1) ); |
690 | 26.3k | if( tmp_es == NULL ) |
691 | 0 | break; |
692 | 26.3k | p_psm->es = tmp_es; |
693 | | |
694 | 26.3k | ps_es_t *p_es = &p_psm->es[ p_psm->i_es++ ]; |
695 | 26.3k | p_es->i_type = p_buffer[ i_es_base ]; |
696 | 26.3k | p_es->i_id = p_buffer[ i_es_base + 1 ]; |
697 | | |
698 | 26.3k | i_info_length = GetWBE(&p_buffer[ i_es_base + 2 ]); |
699 | | |
700 | 26.3k | if( i_es_base + 4 + i_info_length > i_length ) |
701 | 12.1k | 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 | 14.2k | if( p_es->i_id == STREAM_ID_EXTENDED_STREAM_ID && b_single_extension == 0 ) |
709 | 2.99k | { |
710 | 2.99k | if( i_info_length < 3 ) |
711 | 551 | break; |
712 | 2.44k | p_es->i_id = (p_es->i_id << 8) | (p_buffer[i_es_base + 6] & 0x7F); |
713 | 2.44k | ps_parse_descriptors( &p_buffer[i_es_base + 4 + 3], |
714 | 2.44k | i_info_length - 3, |
715 | 2.44k | &p_psm->uniqueextdesc ); |
716 | 2.44k | } |
717 | 11.2k | else |
718 | 11.2k | { |
719 | 11.2k | ps_parse_descriptors( &p_buffer[i_es_base + 4], |
720 | 11.2k | i_info_length, &p_es->desc ); |
721 | 11.2k | } |
722 | | |
723 | 13.6k | i_es_base += 4 + i_info_length; |
724 | 13.6k | } |
725 | | |
726 | | /* TODO: CRC */ |
727 | | |
728 | 17.7k | p_psm->i_version = i_version; |
729 | | |
730 | | /* Check/Modify our existing tracks */ |
731 | 10.3M | for( int i = 0; i < PS_TK_COUNT; i++ ) |
732 | 10.3M | { |
733 | 10.3M | if( !tk[i].b_configured ) |
734 | 10.2M | continue; |
735 | | |
736 | 116k | ps_track_t tk_tmp; |
737 | 116k | es_format_Init( &tk_tmp.fmt, UNKNOWN_ES, 0 ); |
738 | | |
739 | 116k | if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id, |
740 | 116k | p_buffer, i_pkt, false ) != VLC_SUCCESS ) |
741 | 0 | continue; |
742 | | |
743 | 116k | if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec ) |
744 | 106k | { |
745 | 106k | es_format_Clean( &tk_tmp.fmt ); |
746 | 106k | continue; |
747 | 106k | } |
748 | | |
749 | | /* replace with new version */ |
750 | 10.4k | tk_tmp.b_configured = true; |
751 | 10.4k | tk_tmp.b_updated = true; |
752 | 10.4k | tk_tmp.es = tk[i].es; |
753 | 10.4k | es_format_Clean( &tk[i].fmt ); |
754 | 10.4k | tk[i] = tk_tmp; |
755 | 10.4k | } |
756 | | |
757 | 17.7k | return VLC_SUCCESS; |
758 | 18.6k | } Line | Count | Source | 654 | 26.5k | { | 655 | 26.5k | size_t i_length, i_info_length, i_es_base; | 656 | 26.5k | uint8_t i_version; | 657 | 26.5k | 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 | 26.5k | assert(i_pkt >= 4); | 662 | 26.5k | if( !p_psm || i_pkt < 10 || p_buffer[3] != STREAM_ID_PROGRAM_STREAM_MAP) | 663 | 35 | return VLC_EGENERIC; | 664 | | | 665 | 26.5k | i_length = GetWBE(&p_buffer[4]) + 6; | 666 | 26.5k | if( i_length > i_pkt ) return VLC_EGENERIC; | 667 | | | 668 | 26.5k | if((p_buffer[6] & 0x80) == 0) /* current_next_indicator */ | 669 | 874 | return VLC_EGENERIC; | 670 | | | 671 | 25.6k | b_single_extension = p_buffer[6] & 0x40; | 672 | 25.6k | i_version = (p_buffer[6] & 0xf8); | 673 | | | 674 | 25.6k | if( p_psm->i_version == i_version ) return VLC_EGENERIC; | 675 | | | 676 | 18.6k | ps_psm_destroy( p_psm ); | 677 | | | 678 | 18.6k | i_info_length = GetWBE(&p_buffer[8]); | 679 | 18.6k | if( i_info_length + 10 > i_length ) | 680 | 867 | 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 | 17.7k | i_es_base = 12 + i_info_length; | 686 | | | 687 | 31.4k | while( i_es_base + 4 < i_length ) | 688 | 26.3k | { | 689 | 26.3k | ps_es_t *tmp_es = realloc( p_psm->es, sizeof(ps_es_t) * (p_psm->i_es+1) ); | 690 | 26.3k | if( tmp_es == NULL ) | 691 | 0 | break; | 692 | 26.3k | p_psm->es = tmp_es; | 693 | | | 694 | 26.3k | ps_es_t *p_es = &p_psm->es[ p_psm->i_es++ ]; | 695 | 26.3k | p_es->i_type = p_buffer[ i_es_base ]; | 696 | 26.3k | p_es->i_id = p_buffer[ i_es_base + 1 ]; | 697 | | | 698 | 26.3k | i_info_length = GetWBE(&p_buffer[ i_es_base + 2 ]); | 699 | | | 700 | 26.3k | if( i_es_base + 4 + i_info_length > i_length ) | 701 | 12.1k | 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 | 14.2k | if( p_es->i_id == STREAM_ID_EXTENDED_STREAM_ID && b_single_extension == 0 ) | 709 | 2.99k | { | 710 | 2.99k | if( i_info_length < 3 ) | 711 | 551 | break; | 712 | 2.44k | p_es->i_id = (p_es->i_id << 8) | (p_buffer[i_es_base + 6] & 0x7F); | 713 | 2.44k | ps_parse_descriptors( &p_buffer[i_es_base + 4 + 3], | 714 | 2.44k | i_info_length - 3, | 715 | 2.44k | &p_psm->uniqueextdesc ); | 716 | 2.44k | } | 717 | 11.2k | else | 718 | 11.2k | { | 719 | 11.2k | ps_parse_descriptors( &p_buffer[i_es_base + 4], | 720 | 11.2k | i_info_length, &p_es->desc ); | 721 | 11.2k | } | 722 | | | 723 | 13.6k | i_es_base += 4 + i_info_length; | 724 | 13.6k | } | 725 | | | 726 | | /* TODO: CRC */ | 727 | | | 728 | 17.7k | p_psm->i_version = i_version; | 729 | | | 730 | | /* Check/Modify our existing tracks */ | 731 | 10.3M | for( int i = 0; i < PS_TK_COUNT; i++ ) | 732 | 10.3M | { | 733 | 10.3M | if( !tk[i].b_configured ) | 734 | 10.2M | continue; | 735 | | | 736 | 116k | ps_track_t tk_tmp; | 737 | 116k | es_format_Init( &tk_tmp.fmt, UNKNOWN_ES, 0 ); | 738 | | | 739 | 116k | if( ps_track_fill( &tk_tmp, p_psm, tk[i].i_id, | 740 | 116k | p_buffer, i_pkt, false ) != VLC_SUCCESS ) | 741 | 0 | continue; | 742 | | | 743 | 116k | if( tk_tmp.fmt.i_codec == tk[i].fmt.i_codec ) | 744 | 106k | { | 745 | 106k | es_format_Clean( &tk_tmp.fmt ); | 746 | 106k | continue; | 747 | 106k | } | 748 | | | 749 | | /* replace with new version */ | 750 | 10.4k | tk_tmp.b_configured = true; | 751 | 10.4k | tk_tmp.b_updated = true; | 752 | 10.4k | tk_tmp.es = tk[i].es; | 753 | 10.4k | es_format_Clean( &tk[i].fmt ); | 754 | 10.4k | tk[i] = tk_tmp; | 755 | 10.4k | } | 756 | | | 757 | 17.7k | return VLC_SUCCESS; | 758 | 18.6k | } |
Unexecuted instantiation: vobsub.c:ps_psm_fill |