Skip to content

Commit

Permalink
Support max_width/max_height options.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdaede committed Sep 1, 2021
1 parent a6240d6 commit 7d049a9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/api/config/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl EncoderConfig {
// has the property that the scaled distortion of a 2Nx2N block is always
// equal to the sum of the scaled distortions of the NxN sub-blocks it's
// made of, this is a necessary property to be able to do RDO between
// multiple partition sizes properly. Unfortunately, when tx domains
// multiple partition sizes properly. Unfortunately, when tx domain
// distortion is used, distortion is only known at the tx block level which
// might be bigger than 8x8. So temporal RDO is always disabled in that case.
!self.speed_settings.tx_domain_distortion
Expand Down
44 changes: 32 additions & 12 deletions src/api/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ pub use crate::tiling::TilingInfo;
#[non_exhaustive]
pub enum InvalidConfig {
/// The width is invalid.
#[error("invalid width {0} (expected >= 16, <= 65535)")]
InvalidWidth(usize),
#[error("invalid width {actual} (expected >= 16, <= {max})")]
InvalidWidth {
/// The actual value.
actual: usize,
/// The maximal supported value.
max: usize,
},
/// The height is invalid.
#[error("invalid height {0} (expected >= 16, <= 65535)")]
InvalidHeight(usize),
#[error("invalid height {actual} (expected >= 16, <= {max})")]
InvalidHeight {
/// The actual value.
actual: usize,
/// The maximal supported value.
max: usize,
},
/// Aspect ratio numerator is invalid.
#[error("invalid aspect ratio numerator {0} (expected > 0)")]
InvalidAspectRatioNum(usize),
Expand Down Expand Up @@ -285,14 +295,30 @@ impl Config {
if (config.still_picture && config.width < 1)
|| (!config.still_picture && config.width < 16)
|| config.width > u16::max_value() as usize
|| (config.max_width != 0 && config.width > config.max_width)
{
return Err(InvalidWidth(config.width));
return Err(InvalidWidth {
actual: config.width,
max: if config.max_width != 0 {
config.max_width
} else {
u16::max_value() as usize
},
});
}
if (config.still_picture && config.height < 1)
|| (!config.still_picture && config.height < 16)
|| config.height > u16::max_value() as usize
|| (config.max_height != 0 && config.height > config.max_height)
{
return Err(InvalidHeight(config.height));
return Err(InvalidHeight {
actual: config.height,
max: if config.max_height != 0 {
config.max_height
} else {
u16::max_value() as usize
},
});
}

if config.sample_aspect_ratio.num == 0 {
Expand All @@ -313,12 +339,6 @@ impl Config {
if render_height == 0 || render_height > u16::max_value() as usize {
return Err(InvalidRenderHeight(render_height));
}
if config.max_width != 0 && config.width > config.max_width {
return Err(InvalidWidth(config.width));
}
if config.max_height != 0 && config.height > config.max_height {
return Err(InvalidHeight(config.height));
}

if config.rdo_lookahead_frames > MAX_RDO_LOOKAHEAD_FRAMES
|| config.rdo_lookahead_frames < 1
Expand Down
8 changes: 2 additions & 6 deletions src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,8 @@ unsafe fn option_match(
match key {
"width" => enc.width = value.parse().map_err(|_| ())?,
"height" => enc.height = value.parse().map_err(|_| ())?,
"max_width" => {
enc.max_width = value.parse().map_err(|_| ())?
}
"max_height" => {
enc.max_height = value.parse().map_err(|_| ())?
}
"max_width" => enc.max_width = value.parse().map_err(|_| ())?,
"max_height" => enc.max_height = value.parse().map_err(|_| ())?,
"speed" => {
enc.speed_settings =
rav1e::SpeedSettings::from_preset(value.parse().map_err(|_| ())?)
Expand Down
4 changes: 2 additions & 2 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ impl Sequence {
if config.max_width > 0 { config.max_width } else { config.width };
let max_height =
if config.max_height > 0 { config.max_height } else { config.height };
let width_bits = 32 - ((max_width as u32) - 1).leading_zeros();
let height_bits = 32 - ((max_height as u32) - 1).leading_zeros();
let width_bits = 32 - (max_width as u32).leading_zeros();
let height_bits = 32 - (max_height as u32).leading_zeros();
assert!(width_bits <= 16);
assert!(height_bits <= 16);

Expand Down
2 changes: 2 additions & 0 deletions src/fuzzing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ impl Arbitrary for ArbitraryEncoder {
speed_settings: SpeedSettings::from_preset(u.int_in_range(0..=10)?),
width: u.int_in_range(1..=256)?,
height: u.int_in_range(1..=256)?,
max_width: 0,
max_height: 0,
still_picture: Arbitrary::arbitrary(u)?,
time_base: arbitrary_rational(u)?,
min_key_frame_interval: u.int_in_range(0..=3)?,
Expand Down

0 comments on commit 7d049a9

Please sign in to comment.