Skip to content

Commit

Permalink
codec/av1/parser: switch buffer_removal_time_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 63e16df commit 111bb26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/codec/av1/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub struct DecoderModelInfo {
pub num_units_in_decoding_tick: u32,
/// Plus 1 specifies the length of the buffer_removal_time syntax element,
/// in bits.
pub buffer_removal_time_length_minus_1: u32,
pub buffer_removal_time_length_minus_1: u8,
/// Plus 1 specifies the length of the frame_presentation_time syntax
/// element, in bits.
pub frame_presentation_time_length_minus_1: u32,
Expand Down Expand Up @@ -1691,7 +1691,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)? as u8;
dmi.num_units_in_decoding_tick = r.read_bits(32)?;
dmi.buffer_removal_time_length_minus_1 = r.read_bits(5)?;
dmi.buffer_removal_time_length_minus_1 = r.read_bits(5)? as u8;
dmi.frame_presentation_time_length_minus_1 = r.read_bits(5)?;
Ok(())
}
Expand Down Expand Up @@ -3297,7 +3297,7 @@ impl Parser {

if op_pt_idc == 0 || (in_temporal_layer && in_spatial_layer) {
let n = buffer_removal_time_length_minus_1 + 1;
fh.buffer_removal_time[op_num] = r.read_bits(n.try_into().unwrap())?;
fh.buffer_removal_time[op_num] = r.read_bits(n)?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/codec/av1/synthesizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,12 @@ where
(op.idc >> (self.obu.obu_header.spatial_id + 8)) & 1 != 0;

if op.idc == 0 || (in_temporal_layer && in_spatial_layer) {
let n = usize::try_from(
let n = usize::from(
sequence
.decoder_model_info
.buffer_removal_time_length_minus_1
+ 1,
)?;
);

self.f(n, op.decoder_buffer_delay)?;
}
Expand Down

0 comments on commit 111bb26

Please sign in to comment.