Returns the length of the header
| 3305 | |
| 3306 | // Returns the length of the header |
| 3307 | static int hb_parse_ps( |
| 3308 | hb_stream_t *stream, |
| 3309 | uint8_t *buf, |
| 3310 | int len, |
| 3311 | hb_pes_info_t *pes_info ) |
| 3312 | { |
| 3313 | memset( pes_info, 0, sizeof( hb_pes_info_t ) ); |
| 3314 | pes_info->pts = AV_NOPTS_VALUE; |
| 3315 | pes_info->dts = AV_NOPTS_VALUE; |
| 3316 | |
| 3317 | bitbuf_t bb, cc; |
| 3318 | bits_init(&bb, buf, len, 0); |
| 3319 | bits_clone(&cc, &bb, len); |
| 3320 | |
| 3321 | if ( bits_bytes_left(&bb) < 4 ) |
| 3322 | return 0; |
| 3323 | |
| 3324 | // Validate start code |
| 3325 | if ( bits_get(&bb, 8 * 3) != 0x000001 ) |
| 3326 | { |
| 3327 | return 0; |
| 3328 | } |
| 3329 | |
| 3330 | pes_info->stream_id = bits_get(&bb, 8); |
| 3331 | if ( pes_info->stream_id == 0xb9 ) |
| 3332 | { |
| 3333 | // Program stream end code |
| 3334 | return 1; |
| 3335 | } |
| 3336 | else if ( pes_info->stream_id == 0xba ) |
| 3337 | { |
| 3338 | return parse_pack_header( stream, &cc, pes_info ); |
| 3339 | } |
| 3340 | else if ( pes_info->stream_id >= 0xbd && |
| 3341 | pes_info->stream_id != 0xbe && |
| 3342 | pes_info->stream_id != 0xbf && |
| 3343 | pes_info->stream_id != 0xf0 && |
| 3344 | pes_info->stream_id != 0xf1 && |
| 3345 | pes_info->stream_id != 0xf2 && |
| 3346 | pes_info->stream_id != 0xf8 && |
| 3347 | pes_info->stream_id != 0xff ) |
| 3348 | { |
| 3349 | return parse_pes_header( stream, &cc, pes_info ); |
| 3350 | } |
| 3351 | else |
| 3352 | { |
| 3353 | if ( bits_bytes_left(&bb) < 2 ) |
| 3354 | { |
| 3355 | return 0; |
| 3356 | } |
| 3357 | pes_info->packet_len = bits_get(&bb, 16); |
| 3358 | if ( pes_info->stream_id == 0xbe ) |
| 3359 | { |
| 3360 | // Skip all stuffing |
| 3361 | pes_info->header_len = 6 + pes_info->packet_len; |
| 3362 | } |
| 3363 | else |
| 3364 | { |
no test coverage detected