(packetData: Uint8Array)
| 390 | |
| 391 | /** Builds a HevcDecoderConfigurationRecord from an HEVC packet in Annex B format. */ |
| 392 | export const extractHevcDecoderConfigurationRecord = (packetData: Uint8Array) => { |
| 393 | try { |
| 394 | const nalUnits = findNalUnitsInAnnexB(packetData); |
| 395 | |
| 396 | const vpsUnits = nalUnits.filter(unit => extractNalUnitTypeForHevc(unit) === HevcNalUnitType.VPS_NUT); |
| 397 | const spsUnits = nalUnits.filter(unit => extractNalUnitTypeForHevc(unit) === HevcNalUnitType.SPS_NUT); |
| 398 | const ppsUnits = nalUnits.filter(unit => extractNalUnitTypeForHevc(unit) === HevcNalUnitType.PPS_NUT); |
| 399 | const seiUnits = nalUnits.filter( |
| 400 | unit => extractNalUnitTypeForHevc(unit) === HevcNalUnitType.PREFIX_SEI_NUT |
| 401 | || extractNalUnitTypeForHevc(unit) === HevcNalUnitType.SUFFIX_SEI_NUT, |
| 402 | ); |
| 403 | |
| 404 | if (spsUnits.length === 0 || ppsUnits.length === 0) return null; |
| 405 | |
| 406 | const sps = spsUnits[0]; |
| 407 | const bitstream = new Bitstream(removeEmulationPreventionBytes(sps)); |
| 408 | |
| 409 | bitstream.skipBits(16); // NAL header |
| 410 | |
| 411 | bitstream.readBits(4); // sps_video_parameter_set_id |
| 412 | const sps_max_sub_layers_minus1 = bitstream.readBits(3); |
| 413 | const sps_temporal_id_nesting_flag = bitstream.readBits(1); |
| 414 | |
| 415 | const { |
| 416 | general_profile_space, |
| 417 | general_tier_flag, |
| 418 | general_profile_idc, |
| 419 | general_profile_compatibility_flags, |
| 420 | general_constraint_indicator_flags, |
| 421 | general_level_idc, |
| 422 | } = parseProfileTierLevel(bitstream, sps_max_sub_layers_minus1); |
| 423 | |
| 424 | readExpGolomb(bitstream); // sps_seq_parameter_set_id |
| 425 | |
| 426 | const chroma_format_idc = readExpGolomb(bitstream); |
| 427 | if (chroma_format_idc === 3) bitstream.skipBits(1); // separate_colour_plane_flag |
| 428 | |
| 429 | readExpGolomb(bitstream); // pic_width_in_luma_samples |
| 430 | readExpGolomb(bitstream); // pic_height_in_luma_samples |
| 431 | |
| 432 | if (bitstream.readBits(1)) { // conformance_window_flag |
| 433 | readExpGolomb(bitstream); // conf_win_left_offset |
| 434 | readExpGolomb(bitstream); // conf_win_right_offset |
| 435 | readExpGolomb(bitstream); // conf_win_top_offset |
| 436 | readExpGolomb(bitstream); // conf_win_bottom_offset |
| 437 | } |
| 438 | |
| 439 | const bit_depth_luma_minus8 = readExpGolomb(bitstream); |
| 440 | const bit_depth_chroma_minus8 = readExpGolomb(bitstream); |
| 441 | |
| 442 | readExpGolomb(bitstream); // log2_max_pic_order_cnt_lsb_minus4 |
| 443 | |
| 444 | const sps_sub_layer_ordering_info_present_flag = bitstream.readBits(1); |
| 445 | const maxNum = sps_sub_layer_ordering_info_present_flag ? 0 : sps_max_sub_layers_minus1; |
| 446 | for (let i = maxNum; i <= sps_max_sub_layers_minus1; i++) { |
| 447 | readExpGolomb(bitstream); // sps_max_dec_pic_buffering_minus1[i] |
| 448 | readExpGolomb(bitstream); // sps_max_num_reorder_pics[i] |
| 449 | readExpGolomb(bitstream); // sps_max_latency_increase_plus1[i] |
no test coverage detected