Struct Sps

Source
pub struct Sps {
Show 28 fields pub nal_ref_idc: u8, pub nal_unit_type: NALUnitType, pub profile_idc: u8, pub constraint_set0_flag: bool, pub constraint_set1_flag: bool, pub constraint_set2_flag: bool, pub constraint_set3_flag: bool, pub constraint_set4_flag: bool, pub constraint_set5_flag: bool, pub level_idc: u8, pub seq_parameter_set_id: u16, pub ext: Option<SpsExtended>, pub log2_max_frame_num_minus4: u8, pub pic_order_cnt_type: u8, pub log2_max_pic_order_cnt_lsb_minus4: Option<u8>, pub pic_order_cnt_type1: Option<PicOrderCountType1>, pub max_num_ref_frames: u8, pub gaps_in_frame_num_value_allowed_flag: bool, pub pic_width_in_mbs_minus1: u64, pub pic_height_in_map_units_minus1: u64, pub mb_adaptive_frame_field_flag: Option<bool>, pub direct_8x8_inference_flag: bool, pub frame_crop_info: Option<FrameCropInfo>, pub sample_aspect_ratio: Option<SarDimensions>, pub overscan_appropriate_flag: Option<bool>, pub color_config: Option<ColorConfig>, pub chroma_sample_loc: Option<ChromaSampleLoc>, pub timing_info: Option<TimingInfo>,
}
Expand description

The Sequence Parameter Set. ISO/IEC-14496-10-2022 - 7.3.2

Fields§

§nal_ref_idc: u8

The nal_ref_idc is comprised of 2 bits.

A nonzero value means the NAL unit has any of the following: SPS, SPS extension, subset SPS, PPS, slice of a reference picture, slice of a data partition of a reference picture, or a prefix NAL unit preceeding a slice of a reference picture.

0 means that the stream is decoded using the process from Clauses 2-9 (ISO/IEC-14496-10-2022) that the slice or slice data partition is part of a non-reference picture. Additionally, if nal_ref_idc is 0 for a NAL unit with nal_unit_type ranging from [1, 4] then nal_ref_idc must be 0 for all NAL units with nal_unit_type between [1, 4].

If the nal_unit_type is 5, then the nal_ref_idc cannot be 0.

If nal_unit_type is 6, 9, 10, 11, or 12, then the nal_ref_idc must be 0.

ISO/IEC-14496-10-2022 - 7.4.1

§nal_unit_type: NALUnitType

The nal_unit_type is comprised of 5 bits. See the NALUnitType nutype enum for more info.

§profile_idc: u8

The profile_idc of the coded video sequence as a u8.

It is comprised of 8 bits or 1 byte. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§constraint_set0_flag: bool

constraint_set0_flag: 1 if it abides by the constraints in A.2.1, 0 if unsure or otherwise.

If profile_idc is 44, 100, 110, 122, or 244, this is automatically set to false.

It is a single bit. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§constraint_set1_flag: bool

constraint_set1_flag: 1 if it abides by the constraints in A.2.2, 0 if unsure or otherwise.

If profile_idc is 44, 100, 110, 122, or 244, this is automatically set to false.

It is a single bit. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§constraint_set2_flag: bool

constraint_set2_flag: 1 if it abides by the constraints in A.2.3, 0 if unsure or otherwise.

If profile_idc is 44, 100, 110, 122, or 244, this is automatically set to false.

It is a single bit. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§constraint_set3_flag: bool

constraint_set3_flag:

    if (profile_idc == 66, 77, or 88) AND (level_idc == 11):
        1 if it abides by the constraints in Annex A for level 1b
        0 if it abides by the constraints in Annex A for level 1.1
    elif profile_idc == 100 or 110:
        1 if it abides by the constraints for the "High 10 Intra profile"
        0 if unsure or otherwise
    elif profile_idc == 122:
        1 if it abides by the constraints in Annex A for the "High 4:2:2 Intra profile"
        0 if unsure or otherwise
    elif profile_idc == 44:
        1 by default
        0 is not possible.
    elif profile_idc == 244:
        1 if it abides by the constraints in Annex A for the "High 4:4:4 Intra profile"
        0 if unsure or otherwise
    else:
        1 is reserved for future use
        0 otherwise

It is a single bit. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§constraint_set4_flag: bool

constraint_set4_flag:

    if (profile_idc == 77, 88, 100, or 110):
        1 if frame_mbs_only_flag == 1
        0 if unsure or otherwise
    elif (profile_idc == 118, 128, or 134):
        1 if it abides by the constraints in G.6.1.1
        0 if unsure or otherwise
    else:
        1 is reserved for future use
        0 otherwise

It is a single bit. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§constraint_set5_flag: bool

constraint_set5_flag:

    if (profile_idc == 77, 88, or 100):
        1 if there are no B slice types
        0 if unsure or otherwise
    elif profile_idc == 118:
        1 if it abides by the constraints in G.6.1.2
        0 if unsure or otherwise
    else:
        1 is reserved for future use
        0 otherwise

It is a single bit. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§level_idc: u8

The level_idc of the coded video sequence as a u8.

It is comprised of 8 bits or 1 byte. ISO/IEC-14496-10-2022 - 7.4.2.1.1

§seq_parameter_set_id: u16

The seq_parameter_set_id is the id of the SPS referred to by the PPS (picture parameter set).

The value of this ranges from [0, 31].

This is a variable number of bits as it is encoded by an exp golomb (unsigned). The smallest encoding would be for 0 which is encoded as 1, which is a single bit. The largest encoding would be for 31 which is encoded as 000 0010 0000, which is 11 bits. ISO/IEC-14496-10-2022 - 7.4.2.1.1

For more information:

https://en.wikipedia.org/wiki/Exponential-Golomb_coding

§ext: Option<SpsExtended>

An optional SpsExtended. Refer to the SpsExtended struct for more info.

This will be parsed if profile_idc is equal to any of the following values: 44, 83, 86, 100, 110, 118, 122, 128, 134, 135, 138, 139, or 244.

§log2_max_frame_num_minus4: u8

The log2_max_frame_num_minus4 is the value used when deriving MaxFrameNum from the equation: MaxFrameNum = 2^(log2_max_frame_num_minus4 + 4)

The value of this ranges from [0, 12].

This is a variable number of bits as it is encoded by an exp golomb (unsigned). The smallest encoding would be for 0 which is encoded as 1, which is a single bit. The largest encoding would be for 12 which is encoded as 000 1101, which is 7 bits. ISO/IEC-14496-10-2022 - 7.4.2.1.1

For more information:

https://en.wikipedia.org/wiki/Exponential-Golomb_coding

§pic_order_cnt_type: u8

The pic_order_cnt_type specifies how to decode the picture order count in subclause 8.2.1.

The value of this ranges from [0, 2].

This is a variable number of bits as it is encoded by an exp golomb (unsigned). The smallest encoding would be for 0 which is encoded as 1, which is a single bit. The largest encoding would be for 2 which is encoded as 011, which is 3 bits. ISO/IEC-14496-10-2022 - 7.4.2.1.1

For more information:

https://en.wikipedia.org/wiki/Exponential-Golomb_coding

There are a few subsequent fields that are read if pic_order_cnt_type is 0 or 1.

In the case of 0, log2_max_pic_order_cnt_lsb_minus4 is read as an exp golomb (unsigned).

In the case of 1, delta_pic_order_always_zero_flag, offset_for_non_ref_pic, offset_for_top_to_bottom_field, num_ref_frames_in_pic_order_cnt_cycle and offset_for_ref_frame will be read and stored in pic_order_cnt_type1.

Refer to the PicOrderCountType1 struct for more info.

§log2_max_pic_order_cnt_lsb_minus4: Option<u8>

The log2_max_pic_order_cnt_lsb_minus4 is the value used when deriving MaxFrameNum from the equation: MaxPicOrderCntLsb = 2^(log2_max_frame_num_minus4 + 4) from subclause 8.2.1.

This is an Option<u8> because the value is only set if pic_order_cnt_type == 0.

The value of this ranges from [0, 12].

This is a variable number of bits as it is encoded by an exp golomb (unsigned). The smallest encoding would be for 0 which is encoded as 1, which is a single bit. The largest encoding would be for 12 which is encoded as 000 1101, which is 7 bits. ISO/IEC-14496-10-2022 - 7.4.2.1.1

For more information:

https://en.wikipedia.org/wiki/Exponential-Golomb_coding

§pic_order_cnt_type1: Option<PicOrderCountType1>

An optional PicOrderCountType1. This is computed from other fields, and isn’t directly set.

If pic_order_cnt_type == 1, then the PicOrderCountType1 will be computed.

Refer to the PicOrderCountType1 struct for more info.

§max_num_ref_frames: u8

The max_num_ref_frames is the max short-term and long-term reference frames, complementary reference field pairs, and non-paired reference fields that can be used by the decoder for inter-prediction of pictures in the coded video.

The value of this ranges from [0, MaxDpbFrames], which is specified in subclause A.3.1 or A.3.2.

This is a variable number of bits as it is encoded by an exp golomb (unsigned). The smallest encoding would be for 0 which is encoded as 1, which is a single bit. The largest encoding would be for 14 which is encoded as 000 1111, which is 7 bits. ISO/IEC-14496-10-2022 - 7.4.2.1.1

For more information:

https://en.wikipedia.org/wiki/Exponential-Golomb_coding

§gaps_in_frame_num_value_allowed_flag: bool

The gaps_in_frame_num_value_allowed_flag is a single bit.

The value specifies the allowed values of frame_num from subclause 7.4.3 and the decoding process if there is an inferred gap between the values of frame_num from subclause 8.2.5.2.

§pic_width_in_mbs_minus1: u64

The pic_width_in_mbs_minus1 is the width of each decoded picture in macroblocks as a u64.

We then use this (along with the left and right frame crop offsets) to calculate the width as:

width = ((pic_width_in_mbs_minus1 + 1) * 16) - frame_crop_right_offset * 2 - frame_crop_left_offset * 2

This is a variable number of bits as it is encoded by an exp golomb (unsigned). ISO/IEC-14496-10-2022 - 7.4.2.1.1

For more information:

https://en.wikipedia.org/wiki/Exponential-Golomb_coding

§pic_height_in_map_units_minus1: u64

The pic_height_in_map_units_minus1 is the height of each decoded frame in slice group map units as a u64.

We then use this (along with the bottom and top frame crop offsets) to calculate the height as:

height = ((2 - frame_mbs_only_flag as u64) * (pic_height_in_map_units_minus1 + 1) * 16) - frame_crop_bottom_offset * 2 - frame_crop_top_offset * 2

This is a variable number of bits as it is encoded by an exp golomb (unsigned). ISO/IEC-14496-10-2022 - 7.4.2.1.1

For more information:

https://en.wikipedia.org/wiki/Exponential-Golomb_coding

§mb_adaptive_frame_field_flag: Option<bool>

The mb_adaptive_frame_field_flag is a single bit.

If frame_mbs_only_flag is NOT set then this field is read and stored.

0 means there is no switching between frame and field macroblocks in a picture.

1 means the might be switching between frame and field macroblocks in a picture.

ISO/IEC-14496-10-2022 - 7.4.2.1.1

§direct_8x8_inference_flag: bool

The direct_8x8_inference_flag specifies the method used to derive the luma motion vectors for B_Skip, B_Direct_8x8 and B_Direct_16x16 from subclause 8.4.1.2, and is a single bit.

ISO/IEC-14496-10-2022 - 7.4.2.1.1

§frame_crop_info: Option<FrameCropInfo>

An optional frame_crop_info struct. This is computed by other fields, and isn’t directly set.

If the frame_cropping_flag is set, then frame_crop_left_offset, frame_crop_right_offset, frame_crop_top_offset, and frame_crop_bottom_offset will be read and stored.

Refer to the FrameCropInfo struct for more info.

§sample_aspect_ratio: Option<SarDimensions>

An optional SarDimensions struct. This is computed by other fields, and isn’t directly set.

If the aspect_ratio_info_present_flag is set, then the aspect_ratio_idc will be read and stored.

If the aspect_ratio_idc is 255, then the sar_width and sar_height will be read and stored.

Also known as sample_aspect_ratio in the spec.

The default values are set to 0 for the aspect_ratio_idc, sar_width, and sar_height. Therefore, this will always be returned by the parse function. ISO/IEC-14496-10-2022 - E.2.1

Refer to the SarDimensions struct for more info.

§overscan_appropriate_flag: Option<bool>

An optional overscan_appropriate_flag is a single bit.

If the overscan_info_present_flag is set, then this field will be read and stored.

0 means the overscan should not be used. (ex: screensharing or security cameras)

1 means the overscan can be used. (ex: entertainment TV programming or live video conference)

ISO/IEC-14496-10-2022 - E.2.1

§color_config: Option<ColorConfig>

An optional ColorConfig. This is computed from other fields, and isn’t directly set.

If video_signal_type_present_flag is set, then the ColorConfig will be computed, and if the color_description_present_flag is set, then the ColorConfig will be comprised of the video_full_range_flag (1 bit), color_primaries (1 byte as a u8), transfer_characteristics (1 byte as a u8), and matrix_coefficients (1 byte as a u8).

Otherwise, color_primaries, transfer_characteristics, and matrix_coefficients are set to 2 (unspecified) by default.

Refer to the ColorConfig struct for more info.

§chroma_sample_loc: Option<ChromaSampleLoc>

An optional ChromaSampleLoc. This is computed from other fields, and isn’t directly set.

If chrome_loc_info_present_flag is set, then the ChromaSampleLoc will be computed, and is comprised of chroma_sample_loc_type_top_field and chroma_sample_loc_type_bottom_field.

Refer to the ChromaSampleLoc struct for more info.

§timing_info: Option<TimingInfo>

An optional TimingInfo. This is computed from other fields, and isn’t directly set.

If timing_info_present_flag is set, then the TimingInfo will be computed, and is comprised of num_units_in_tick and time_scale.

Refer to the TimingInfo struct for more info.

Implementations§

Source§

impl Sps

Source

pub fn parse(reader: impl Read) -> Result<Self>

Parses an Sps from the input bytes.

Returns an Sps struct.

Source

pub fn build(&self, writer: impl Write) -> Result<()>

Builds the Sps struct into a byte stream. Returns a built byte stream.

Source

pub fn parse_with_emulation_prevention(reader: impl Read) -> Result<Self>

Parses the Sps struct from a reader that may contain emulation prevention bytes. Is the same as calling Self::parse with an [EmulationPreventionIo] wrapper.

Source

pub fn build_with_emulation_prevention(self, writer: impl Write) -> Result<()>

Builds the Sps struct into a byte stream that may contain emulation prevention bytes. Is the same as calling Self::build with an [EmulationPreventionIo] wrapper.

Source

pub fn size(&self) -> u64

Returns the total byte size of the Sps struct.

Source

pub fn height(&self) -> u64

The height as a u64. This is computed from other fields, and isn’t directly set.

height = ((2 - frame_mbs_only_flag as u64) * (pic_height_in_map_units_minus1 + 1) * 16) - frame_crop_bottom_offset * 2 - frame_crop_top_offset * 2

We don’t directly store frame_mbs_only_flag since we can tell if it’s set: If mb_adaptive_frame_field_flag is None, then frame_mbs_only_flag is set (1). Otherwise mb_adaptive_frame_field_flag unset (0).

Source

pub fn width(&self) -> u64

The width as a u64. This is computed from other fields, and isn’t directly set.

width = ((pic_width_in_mbs_minus1 + 1) * 16) - frame_crop_right_offset * 2 - frame_crop_left_offset * 2

Source

pub fn frame_rate(&self) -> Option<f64>

Returns the frame rate as a f64.

If timing_info_present_flag is set, then the frame_rate will be computed, and if num_units_in_tick is nonzero, then the framerate will be: frame_rate = time_scale as f64 / (2.0 * num_units_in_tick as f64)

Trait Implementations§

Source§

impl Clone for Sps

Source§

fn clone(&self) -> Sps

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Sps

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Sps

Source§

fn eq(&self, other: &Sps) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Sps

Auto Trait Implementations§

§

impl Freeze for Sps

§

impl RefUnwindSafe for Sps

§

impl Send for Sps

§

impl Sync for Sps

§

impl Unpin for Sps

§

impl UnwindSafe for Sps

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.