scuffle_h265/sps/
long_term_ref_pics.rs

1use std::io;
2
3use scuffle_bytes_util::{BitReader, range_check};
4use scuffle_expgolomb::BitReaderExpGolombExt;
5
6/// Directly part of [SPS RBSP](crate::SpsRbsp).
7#[derive(Debug, Clone, PartialEq)]
8pub struct LongTermRefPics {
9    /// Specifies the picture order count modulo `MaxPicOrderCntLsb` of the `i`-th
10    /// candidate long-term reference picture specified in the SPS.
11    pub lt_ref_pic_poc_lsb_sps: Vec<u64>,
12    /// Equal to `false` specifies that the `i`-th candidate long-term reference picture
13    /// specified in the SPS is not used for reference by a picture that includes in its long-term RPS the `i`-th
14    /// candidate long-term reference picture specified in the SPS.
15    pub used_by_curr_pic_lt_sps_flag: Vec<bool>,
16}
17
18impl LongTermRefPics {
19    pub(crate) fn parse<R: io::Read>(
20        bit_reader: &mut BitReader<R>,
21        log2_max_pic_order_cnt_lsb_minus4: u8,
22    ) -> Result<Self, io::Error> {
23        let num_long_term_ref_pics_sps = bit_reader.read_exp_golomb()?;
24        range_check!(num_long_term_ref_pics_sps, 0, 32)?;
25
26        let mut lt_ref_pic_poc_lsb_sps = Vec::with_capacity(num_long_term_ref_pics_sps as usize);
27        let mut used_by_curr_pic_lt_sps_flag = Vec::with_capacity(num_long_term_ref_pics_sps as usize);
28
29        for _ in 0..num_long_term_ref_pics_sps {
30            lt_ref_pic_poc_lsb_sps.push(bit_reader.read_bits(log2_max_pic_order_cnt_lsb_minus4 + 4)?);
31            used_by_curr_pic_lt_sps_flag.push(bit_reader.read_bit()?);
32        }
33
34        Ok(Self {
35            lt_ref_pic_poc_lsb_sps,
36            used_by_curr_pic_lt_sps_flag,
37        })
38    }
39}