From 63e16df012225d8850f80b4b57e0c5af3fdba5be Mon Sep 17 00:00:00 2001 From: Alexandre Courbot Date: Wed, 26 Jun 2024 12:32:12 +0900 Subject: [PATCH] codec/av1/parser: switch buffer_delay_length_minus_1 to u8 This member is read from 5 bits. This removes the need for potentially-failing type conversions. --- src/codec/av1/parser.rs | 8 ++++---- src/codec/av1/synthesizer.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/codec/av1/parser.rs b/src/codec/av1/parser.rs index 554e568f..19cded1b 100644 --- a/src/codec/av1/parser.rs +++ b/src/codec/av1/parser.rs @@ -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, @@ -1679,9 +1679,9 @@ 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()?; @@ -1689,7 +1689,7 @@ impl Parser { } 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)?; diff --git a/src/codec/av1/synthesizer.rs b/src/codec/av1/synthesizer.rs index 0c50a083..5bd04a60 100644 --- a/src/codec/av1/synthesizer.rs +++ b/src/codec/av1/synthesizer.rs @@ -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)?;