Skip to content

Commit

Permalink
codec/av1/parser: switch buffer_delay_length_minus_1 to u8
Browse files Browse the repository at this point in the history
This member is read from 5 bits. This removes the need for
potentially-failing type conversions.
  • Loading branch information
Gnurou committed Jul 1, 2024
1 parent a27e8e9 commit 63e16df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/codec/av1/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub struct TimingInfo {
pub struct DecoderModelInfo {
/// Plus 1 specifies the length of the decoder_buffer_delay and the
/// encoder_buffer_delay syntax elements, in bits.
pub buffer_delay_length_minus_1: u32,
pub buffer_delay_length_minus_1: u8,
/// The number of time units of a decoding clock operating at the frequency
/// time_scale Hz that corresponds to one increment of a clock tick counter:
pub num_units_in_decoding_tick: u32,
Expand Down Expand Up @@ -1679,17 +1679,17 @@ impl Parser {
fn parse_operating_parameters_info(
opi: &mut OperatingPoint,
r: &mut Reader,
buffer_delay_length_minus_1: u32,
buffer_delay_length_minus_1: u8,
) -> anyhow::Result<()> {
let n = u8::try_from(buffer_delay_length_minus_1 + 1).unwrap();
let n = buffer_delay_length_minus_1 + 1;
opi.decoder_buffer_delay = r.read_bits(n)?;
opi.encoder_buffer_delay = r.read_bits(n)?;
opi.low_delay_mode_flag = r.read_bit()?;
Ok(())
}

fn parse_decoder_model_info(dmi: &mut DecoderModelInfo, r: &mut Reader) -> anyhow::Result<()> {
dmi.buffer_delay_length_minus_1 = r.read_bits(5)?;
dmi.buffer_delay_length_minus_1 = r.read_bits(5)? as u8;
dmi.num_units_in_decoding_tick = r.read_bits(32)?;
dmi.buffer_removal_time_length_minus_1 = r.read_bits(5)?;
dmi.frame_presentation_time_length_minus_1 = r.read_bits(5)?;
Expand Down
2 changes: 1 addition & 1 deletion src/codec/av1/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ where
fn operating_parameters_info(&mut self, i: usize) -> SynthesizerResult<()> {
let op = &self.obu.operating_points[i];

let n = usize::try_from(self.obu.decoder_model_info.buffer_delay_length_minus_1)? + 1;
let n = usize::from(self.obu.decoder_model_info.buffer_delay_length_minus_1) + 1;
self.f(n, op.decoder_buffer_delay)?;
self.f(n, op.encoder_buffer_delay)?;
self.f(1, op.low_delay_mode_flag)?;
Expand Down

0 comments on commit 63e16df

Please sign in to comment.