Skip to main content

Module pixel_format

Module pixel_format 

Source
Expand description

Pixel-format detection from codec sequence headers.

Given raw bitstream samples (the same Vec<Vec> our decoders consume), parse just enough of the first sequence header to extract chroma subsampling + luma bit depth, then map to our PixelFormat enum.

Why not use the full decoder: our CPU decoders (H.264 openh264, HEVC Rust, VP9 Rust, rav1d AV1) each have their own parser entry points, but none of them expose a “just probe the format” API. NVDEC’s sequence_callback tells us, but only after decode starts. This module gives the pipeline a fast, codec-agnostic probe path that runs before decoder construction.

Structs§

Av1FrameHeader
Parsed AV1 frame header — full §5.9.1 uncompressed_header parse. Provides everything needed to populate StdVideoDecodeAV1PictureInfo
Av1SequenceHeader
Parsed AV1 sequence header fields (from OBU type 1, §5.5.2). Minimum subset needed to build StdVideoAV1SequenceHeader for Vulkan AV1 decode session parameters.
H264PpsInfo
Parsed H.264 PPS fields. Consumers: Vulkan Video decoder (fills StdVideoH264PictureParameterSet), slice-header parser (needs bottom_field_pic_order_in_frame_present_flag + redundant_pic_cnt_present_flag as branching predicates).
H264SliceHeader
Parsed H.264 slice header — just the fields the Vulkan Video decoder + our DPB manager need. See ITU-T H.264 §7.3.3. Full slice header has ref_pic_list_modification, weighted_prediction tables, dec_ref_pic_marking, etc., which we don’t consume (the driver re-derives them from the PPS + StdVideoDecodeH264PictureInfo flags).
H264SpsInfo
Parsed H.264 SPS fields relevant to the pipeline.
H265PpsInfo
Parsed HEVC PPS.
H265SliceHeader
HEVC slice header — subset needed for StdVideoDecodeH265PictureInfo.
H265VpsInfo
Parsed HEVC VPS — minimum fields needed for StdVideoH265VideoParameterSet.
HevcSpsInfo
Parsed HEVC SPS fields relevant to the pipeline.
Mpeg2SeqInfo
Parsed MPEG-2 sequence header + (optional) sequence extension.

Enums§

Av1FrameType
H264SliceType
Slice type name (decoded from slice_type ue(v) value). Per H.264 §7.4.3 Table 7-6, values 0..=4 are one iteration of the slice types; values 5..=9 are the same types but mark “all slices in the current picture have this type” (aka slice_type_all_same). Both halves collapse to the same enum.
H265SliceType

Functions§

av1_frame_header_offset
Locate the byte offset, within sample, of the uncompressed_header payload of the first Frame OBU (obu_type 3 or 6). Returns None if no such OBU is found.
av1_tile_group_offset
Locate the byte offset of the first tile_group_obu payload within the sample buffer, used for VkVideoDecodeAV1PictureInfoKHR::pTileOffsets. Two shapes:
av1_tile_group_offset_fallback
Backwards-compatible shim — uses an empty-ish sequence header default that only works for the fallback path (standalone type-4 OBU). Callers with access to the parsed sequence header should use av1_tile_group_offset (the seq-aware form) instead.
detect
Detect pixel format from the first sequence header in samples. Falls back to Yuv420p on any parse failure — that matches the previous hard-coded behavior so a bad probe doesn’t block the transcode, just the probe payload accuracy.
detect_dims
Public entry point — dispatch by codec and return Some((width, height)) if the sequence header in samples[0] is parseable, None otherwise.
find_av1_obu_with_offset_pub
Public re-export so the Vulkan Video decoder can extract the byte range of an OBU from a demuxed sample.
h264_first_slice_nal_offset
Scan an Annex-B H.264 sample for the first coded-slice NAL (types 1 / 5 / 19) and return its byte offset within data. Parallel to hevc_first_slice_nal_offset.
hevc_first_slice_nal_offset
Scan an Annex-B HEVC sample and return the offset, in bytes from the start of data, where the first coded-slice NAL begins (the byte AFTER the start code). Vulkan slice_segment_offsets wants offsets to NAL-unit first bytes, not to start codes.
parse_av1_frame_header
Parse an AV1 frame_header_obu (or the frame_header part of a frame_obu) from the given sample. Requires the sequence header for branch predicates (order_hint_bits, enable flags).
parse_av1_sequence_header
Parse the AV1 sequence header OBU (obu_type=1). Returns the subset of §5.5.2 fields needed for Vulkan decode-session-params. Partial parse: we stop after color_config + film_grain_params_present (everything Vulkan’s StdVideoAV1SequenceHeader cares about).
parse_h264_pps
Walk an Annex-B sample looking for the first NAL of type 8 (PPS) and decode its syntax elements. Returns None when no PPS is in the sample or the syntax is truncated before redundant_pic_cnt_present_flag (the last required field).
parse_h264_slice_header
Parse the first slice-NAL in sample, using the SPS + PPS for branch predicates. The NAL header’s nal_unit_type gates which slice types we accept: 1 (non-IDR), 5 (IDR), 19 (auxiliary coded slice) all share the same syntax. Returns None when the sample contains no slice NAL or the SPS/PPS didn’t provide the required context (e.g., SPS pic_order_cnt_type was None so we can’t branch into the POC reads).
parse_h264_sps
Full H.264 SPS walker — see §7.3.2.1.1 + §7.4.2.1.1. The parse is greedy: profile_idc + chroma fields are populated first, then we walk the variable-length sections (scaling lists, pic_order_cnt_type branch) to reach pic_width_in_mbs_minus1 etc. If any of those sections hit end-of-buffer the dims come back as None but the early fields are returned.
parse_h265_pps
Parse the HEVC PPS (NAL type 34). Subset needed for Std PPS.
parse_h265_slice_header
Parse the HEVC slice header — subset needed for StdVideoDecodeH265PictureInfo. sps / pps provide context for bit-width of POC lsb and branch predicates.
parse_h265_vps
Parse the HEVC VPS (NAL type 32). Minimum fields for Std VPS.
parse_hevc_sps
Full HEVC SPS walker — see H.265 §7.3.2.2.1 + §7.4.3.2.1. Consumes profile_tier_level via the existing skip_hevc_profile_tier_level helper, then reads pic_width_in_luma_samples + pic_height_in_luma_samples and applies the conformance window crop if present.
parse_mpeg2_sequence_header
MPEG-2 sequence header scan — ISO/IEC 13818-2 §6.2.2.1 (sequence header, start code 00 00 01 B3) + §6.2.2.3 (sequence extension, start code 00 00 01 B5 with extension_start_code_identifier==1).