Skip to content

Commit d2e0838

Browse files
committed
Support max_width/max_height options.
1 parent a6240d6 commit d2e0838

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

src/api/config/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl EncoderConfig {
221221
// has the property that the scaled distortion of a 2Nx2N block is always
222222
// equal to the sum of the scaled distortions of the NxN sub-blocks it's
223223
// made of, this is a necessary property to be able to do RDO between
224-
// multiple partition sizes properly. Unfortunately, when tx domains
224+
// multiple partition sizes properly. Unfortunately, when tx domain
225225
// distortion is used, distortion is only known at the tx block level which
226226
// might be bigger than 8x8. So temporal RDO is always disabled in that case.
227227
!self.speed_settings.tx_domain_distortion

src/api/config/mod.rs

+32-12
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,21 @@ pub use crate::tiling::TilingInfo;
3232
#[non_exhaustive]
3333
pub enum InvalidConfig {
3434
/// The width is invalid.
35-
#[error("invalid width {0} (expected >= 16, <= 65535)")]
36-
InvalidWidth(usize),
35+
#[error("invalid width {actual} (expected >= 16, <= {max})")]
36+
InvalidWidth {
37+
/// The actual value.
38+
actual: usize,
39+
/// The maximal supported value.
40+
max: usize,
41+
},
3742
/// The height is invalid.
38-
#[error("invalid height {0} (expected >= 16, <= 65535)")]
39-
InvalidHeight(usize),
43+
#[error("invalid height {actual} (expected >= 16, <= {max})")]
44+
InvalidHeight {
45+
/// The actual value.
46+
actual: usize,
47+
/// The maximal supported value.
48+
max: usize,
49+
},
4050
/// Aspect ratio numerator is invalid.
4151
#[error("invalid aspect ratio numerator {0} (expected > 0)")]
4252
InvalidAspectRatioNum(usize),
@@ -285,14 +295,30 @@ impl Config {
285295
if (config.still_picture && config.width < 1)
286296
|| (!config.still_picture && config.width < 16)
287297
|| config.width > u16::max_value() as usize
298+
|| (config.max_width != 0 && config.width > config.max_width)
288299
{
289-
return Err(InvalidWidth(config.width));
300+
return Err(InvalidWidth {
301+
actual: config.width,
302+
max: if config.max_width != 0 {
303+
config.max_width
304+
} else {
305+
u16::max_value() as usize
306+
},
307+
});
290308
}
291309
if (config.still_picture && config.height < 1)
292310
|| (!config.still_picture && config.height < 16)
293311
|| config.height > u16::max_value() as usize
312+
|| (config.max_height != 0 && config.height > config.max_height)
294313
{
295-
return Err(InvalidHeight(config.height));
314+
return Err(InvalidHeight {
315+
actual: config.height,
316+
max: if config.max_height != 0 {
317+
config.max_height
318+
} else {
319+
u16::max_value() as usize
320+
},
321+
});
296322
}
297323

298324
if config.sample_aspect_ratio.num == 0 {
@@ -313,12 +339,6 @@ impl Config {
313339
if render_height == 0 || render_height > u16::max_value() as usize {
314340
return Err(InvalidRenderHeight(render_height));
315341
}
316-
if config.max_width != 0 && config.width > config.max_width {
317-
return Err(InvalidWidth(config.width));
318-
}
319-
if config.max_height != 0 && config.height > config.max_height {
320-
return Err(InvalidHeight(config.height));
321-
}
322342

323343
if config.rdo_lookahead_frames > MAX_RDO_LOOKAHEAD_FRAMES
324344
|| config.rdo_lookahead_frames < 1

src/capi.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,8 @@ unsafe fn option_match(
609609
match key {
610610
"width" => enc.width = value.parse().map_err(|_| ())?,
611611
"height" => enc.height = value.parse().map_err(|_| ())?,
612-
"max_width" => {
613-
enc.max_width = value.parse().map_err(|_| ())?
614-
}
615-
"max_height" => {
616-
enc.max_height = value.parse().map_err(|_| ())?
617-
}
612+
"max_width" => enc.max_width = value.parse().map_err(|_| ())?,
613+
"max_height" => enc.max_height = value.parse().map_err(|_| ())?,
618614
"speed" => {
619615
enc.speed_settings =
620616
rav1e::SpeedSettings::from_preset(value.parse().map_err(|_| ())?)

src/fuzzing.rs

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ impl Arbitrary for ArbitraryEncoder {
221221
speed_settings: SpeedSettings::from_preset(u.int_in_range(0..=10)?),
222222
width: u.int_in_range(1..=256)?,
223223
height: u.int_in_range(1..=256)?,
224+
max_width: 0,
225+
max_height: 0,
224226
still_picture: Arbitrary::arbitrary(u)?,
225227
time_base: arbitrary_rational(u)?,
226228
min_key_frame_interval: u.int_in_range(0..=3)?,

0 commit comments

Comments
 (0)