Skip to content

Commit 10586b3

Browse files
committed
codec/av1/parser: turn max_frame_width_minus_1 into u16
This member is read from 16 bits max. Doing so allows us to avoid some type conversions and optimize the code.
1 parent fdc9e4e commit 10586b3

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

src/codec/av1/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub struct SequenceHeaderObu {
398398
pub frame_height_bits_minus_1: u8,
399399
/// Specifies the maximum frame width minus 1 for the frames represented by
400400
/// this sequence header.
401-
pub max_frame_width_minus_1: u32,
401+
pub max_frame_width_minus_1: u16,
402402
/// Specifies the maximum frame height minus 1 for the frames represented by
403403
/// this sequence header.
404404
pub max_frame_height_minus_1: u32,
@@ -1393,7 +1393,7 @@ impl Parser {
13931393
let n = seq.frame_height_bits_minus_1 + 1;
13941394
fh.frame_height = r.read_bits(n)? + 1;
13951395
} else {
1396-
fh.frame_width = seq.max_frame_width_minus_1 + 1;
1396+
fh.frame_width = seq.max_frame_width_minus_1 as u32 + 1;
13971397
fh.frame_height = seq.max_frame_height_minus_1 + 1;
13981398
}
13991399

@@ -1823,7 +1823,8 @@ impl Parser {
18231823

18241824
s.frame_width_bits_minus_1 = r.read_bits(4)? as u8;
18251825
s.frame_height_bits_minus_1 = r.read_bits(4)? as u8;
1826-
s.max_frame_width_minus_1 = r.read_bits(s.frame_width_bits_minus_1 + 1)?;
1826+
// frame_width_bits_minus_1 has been read from 4 bits, meaning we can read 16 bits at most.
1827+
s.max_frame_width_minus_1 = r.read_bits(s.frame_width_bits_minus_1 + 1)? as u16;
18271828
s.max_frame_height_minus_1 = r.read_bits(s.frame_height_bits_minus_1 + 1)?;
18281829
if s.reduced_still_picture_header {
18291830
s.frame_id_numbers_present_flag = false;

src/codec/av1/synthesizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ where
963963
let n = sequence.frame_height_bits_minus_1 as usize + 1;
964964
self.f(n, self.obu.frame_height - 1)?;
965965
} else {
966-
if self.obu.frame_width != sequence.max_frame_width_minus_1 + 1 {
966+
if self.obu.frame_width != sequence.max_frame_width_minus_1 as u32 + 1 {
967967
self.invalid_element_value("FrameWidth")?;
968968
}
969969
if self.obu.frame_height != sequence.max_frame_height_minus_1 + 1 {
@@ -1710,7 +1710,7 @@ mod tests {
17101710

17111711
frame_width_bits_minus_1: 16 - 1,
17121712
frame_height_bits_minus_1: 16 - 1,
1713-
max_frame_width_minus_1: WIDTH - 1,
1713+
max_frame_width_minus_1: (WIDTH - 1) as u16,
17141714
max_frame_height_minus_1: HEIGHT - 1,
17151715

17161716
seq_force_integer_mv: SELECT_INTEGER_MV as u32,

src/decoder/stateless/av1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ where
436436
log::debug!(
437437
"Found new sequence, resolution: {:?}, profile: {:?}, bit depth: {:?}",
438438
Resolution::from((
439-
sequence.max_frame_width_minus_1 + 1,
439+
sequence.max_frame_width_minus_1 as u32 + 1,
440440
sequence.max_frame_height_minus_1 + 1
441441
)),
442442
sequence.seq_profile,

src/decoder/stateless/av1/vaapi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl VaStreamInfo for &Rc<SequenceHeaderObu> {
9393

9494
fn coded_size(&self) -> (u32, u32) {
9595
(
96-
self.max_frame_width_minus_1 + 1,
96+
self.max_frame_width_minus_1 as u32 + 1,
9797
self.max_frame_height_minus_1 + 1,
9898
)
9999
}
@@ -513,7 +513,7 @@ impl<M: SurfaceMemoryDescriptor + 'static> StatelessAV1DecoderBackend for VaapiB
513513
/* The spec mandates a 2:1 or 1.5:1 ratio, let's go with 2:1 to
514514
* accomodate the other case. See 6.7.5 in the spec */
515515
let layers = (0..=highest_layer).map(|layer| Resolution {
516-
width: (sequence.max_frame_width_minus_1 + 1) / (layer + 1),
516+
width: (sequence.max_frame_width_minus_1 as u32 + 1) / (layer + 1),
517517
height: (sequence.max_frame_height_minus_1 + 1) / (layer + 1),
518518
});
519519

src/encoder/stateless/av1/predictor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<Picture, Reference> LowDelayAV1<Picture, Reference> {
9292
frame_height_bits_minus_1: (1 << 4) - 1,
9393

9494
// Current resolution is the maximum resolution
95-
max_frame_width_minus_1: width - 1,
95+
max_frame_width_minus_1: (width - 1) as u16,
9696
max_frame_height_minus_1: height - 1,
9797

9898
seq_force_integer_mv: SELECT_INTEGER_MV as u32,

src/encoder/stateless/av1/vaapi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ mod tests {
716716

717717
frame_width_bits_minus_1: 16 - 1,
718718
frame_height_bits_minus_1: 16 - 1,
719-
max_frame_width_minus_1: WIDTH - 1,
719+
max_frame_width_minus_1: (WIDTH - 1) as u16,
720720
max_frame_height_minus_1: HEIGHT - 1,
721721

722722
enable_order_hint: true,

0 commit comments

Comments
 (0)