scuffle_h265/sps/
long_term_ref_pics.rs

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