diff --git a/src/api/config/encoder.rs b/src/api/config/encoder.rs index ef8ba5725a..85992cf263 100644 --- a/src/api/config/encoder.rs +++ b/src/api/config/encoder.rs @@ -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 diff --git a/src/api/config/mod.rs b/src/api/config/mod.rs index b0527eed32..d915d21ec1 100644 --- a/src/api/config/mod.rs +++ b/src/api/config/mod.rs @@ -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 {0} (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 {0} (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), @@ -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 { @@ -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 diff --git a/src/capi.rs b/src/capi.rs index 99cb874944..4edcf2b68c 100644 --- a/src/capi.rs +++ b/src/capi.rs @@ -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(|_| ())?)