Skip to content

Commit ae34408

Browse files
committed
codec/av1/parser: turn max_frame_height_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 10586b3 commit ae34408

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
@@ -401,7 +401,7 @@ pub struct SequenceHeaderObu {
401401
pub max_frame_width_minus_1: u16,
402402
/// Specifies the maximum frame height minus 1 for the frames represented by
403403
/// this sequence header.
404-
pub max_frame_height_minus_1: u32,
404+
pub max_frame_height_minus_1: u16,
405405
/// Specifies whether frame id numbers are present in the coded video
406406
/// sequence.
407407
pub frame_id_numbers_present_flag: bool,
@@ -1394,7 +1394,7 @@ impl Parser {
13941394
fh.frame_height = r.read_bits(n)? + 1;
13951395
} else {
13961396
fh.frame_width = seq.max_frame_width_minus_1 as u32 + 1;
1397-
fh.frame_height = seq.max_frame_height_minus_1 + 1;
1397+
fh.frame_height = seq.max_frame_height_minus_1 as u32 + 1;
13981398
}
13991399

14001400
Self::parse_superres_params(fh, r, seq)?;
@@ -1825,7 +1825,8 @@ impl Parser {
18251825
s.frame_height_bits_minus_1 = r.read_bits(4)? as u8;
18261826
// frame_width_bits_minus_1 has been read from 4 bits, meaning we can read 16 bits at most.
18271827
s.max_frame_width_minus_1 = r.read_bits(s.frame_width_bits_minus_1 + 1)? as u16;
1828-
s.max_frame_height_minus_1 = r.read_bits(s.frame_height_bits_minus_1 + 1)?;
1828+
// frame_height_bits_minus_1 has been read from 4 bits, meaning we can read 16 bits at most.
1829+
s.max_frame_height_minus_1 = r.read_bits(s.frame_height_bits_minus_1 + 1)? as u16;
18291830
if s.reduced_still_picture_header {
18301831
s.frame_id_numbers_present_flag = false;
18311832
} else {

src/codec/av1/synthesizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ where
966966
if self.obu.frame_width != sequence.max_frame_width_minus_1 as u32 + 1 {
967967
self.invalid_element_value("FrameWidth")?;
968968
}
969-
if self.obu.frame_height != sequence.max_frame_height_minus_1 + 1 {
969+
if self.obu.frame_height != sequence.max_frame_height_minus_1 as u32 + 1 {
970970
self.invalid_element_value("FrameHeight")?;
971971
}
972972

@@ -1711,7 +1711,7 @@ mod tests {
17111711
frame_width_bits_minus_1: 16 - 1,
17121712
frame_height_bits_minus_1: 16 - 1,
17131713
max_frame_width_minus_1: (WIDTH - 1) as u16,
1714-
max_frame_height_minus_1: HEIGHT - 1,
1714+
max_frame_height_minus_1: (HEIGHT - 1) as u16,
17151715

17161716
seq_force_integer_mv: SELECT_INTEGER_MV as u32,
17171717

src/decoder/stateless/av1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ where
437437
"Found new sequence, resolution: {:?}, profile: {:?}, bit depth: {:?}",
438438
Resolution::from((
439439
sequence.max_frame_width_minus_1 as u32 + 1,
440-
sequence.max_frame_height_minus_1 + 1
440+
sequence.max_frame_height_minus_1 as u32 + 1
441441
)),
442442
sequence.seq_profile,
443443
sequence.bit_depth

src/decoder/stateless/av1/vaapi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl VaStreamInfo for &Rc<SequenceHeaderObu> {
9494
fn coded_size(&self) -> (u32, u32) {
9595
(
9696
self.max_frame_width_minus_1 as u32 + 1,
97-
self.max_frame_height_minus_1 + 1,
97+
self.max_frame_height_minus_1 as u32 + 1,
9898
)
9999
}
100100

@@ -514,7 +514,7 @@ impl<M: SurfaceMemoryDescriptor + 'static> StatelessAV1DecoderBackend for VaapiB
514514
* accomodate the other case. See 6.7.5 in the spec */
515515
let layers = (0..=highest_layer).map(|layer| Resolution {
516516
width: (sequence.max_frame_width_minus_1 as u32 + 1) / (layer + 1),
517-
height: (sequence.max_frame_height_minus_1 + 1) / (layer + 1),
517+
height: (sequence.max_frame_height_minus_1 as u32 + 1) / (layer + 1),
518518
});
519519

520520
PoolCreationMode::Layers(layers.collect())

src/encoder/stateless/av1/predictor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<Picture, Reference> LowDelayAV1<Picture, Reference> {
9393

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

9898
seq_force_integer_mv: SELECT_INTEGER_MV as u32,
9999

src/encoder/stateless/av1/vaapi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ mod tests {
717717
frame_width_bits_minus_1: 16 - 1,
718718
frame_height_bits_minus_1: 16 - 1,
719719
max_frame_width_minus_1: (WIDTH - 1) as u16,
720-
max_frame_height_minus_1: HEIGHT - 1,
720+
max_frame_height_minus_1: (HEIGHT - 1) as u16,
721721

722722
enable_order_hint: true,
723723
order_hint_bits: 8,

0 commit comments

Comments
 (0)