lesavka: keep inline preview geometry honest
This commit is contained in:
parent
545bda5a96
commit
d7277070f0
@ -4,7 +4,7 @@ path = "src/main.rs"
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "lesavka_client"
|
name = "lesavka_client"
|
||||||
version = "0.11.6"
|
version = "0.11.7"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -1342,20 +1342,17 @@ fn adapt_inline_preview_request(
|
|||||||
max_bitrate_kbit: u32,
|
max_bitrate_kbit: u32,
|
||||||
prefer_reencode: bool,
|
prefer_reencode: bool,
|
||||||
) -> (i32, i32, u32, u32, bool) {
|
) -> (i32, i32, u32, u32, bool) {
|
||||||
let bounded_width = requested_width.max(2).min(preview_dimension(
|
let inline_width = requested_width.max(2);
|
||||||
"LESAVKA_PREVIEW_REQUEST_WIDTH",
|
let inline_height = requested_height.max(2);
|
||||||
INLINE_PREVIEW_REQUEST_WIDTH,
|
if !prefer_reencode {
|
||||||
));
|
return (
|
||||||
let bounded_height = requested_height.max(2).min(preview_dimension(
|
inline_width,
|
||||||
"LESAVKA_PREVIEW_REQUEST_HEIGHT",
|
inline_height,
|
||||||
INLINE_PREVIEW_REQUEST_HEIGHT,
|
requested_fps.max(1),
|
||||||
));
|
max_bitrate_kbit.max(800),
|
||||||
let (inline_width, inline_height) = fit_preview_within_bounds(
|
false,
|
||||||
requested_width.max(2),
|
);
|
||||||
requested_height.max(2),
|
}
|
||||||
bounded_width,
|
|
||||||
bounded_height,
|
|
||||||
);
|
|
||||||
let inline_fps = requested_fps.max(1).min(preview_bitrate(
|
let inline_fps = requested_fps.max(1).min(preview_bitrate(
|
||||||
"LESAVKA_PREVIEW_REQUEST_FPS",
|
"LESAVKA_PREVIEW_REQUEST_FPS",
|
||||||
INLINE_PREVIEW_REQUEST_FPS,
|
INLINE_PREVIEW_REQUEST_FPS,
|
||||||
@ -1364,10 +1361,7 @@ fn adapt_inline_preview_request(
|
|||||||
"LESAVKA_PREVIEW_MAX_KBIT",
|
"LESAVKA_PREVIEW_MAX_KBIT",
|
||||||
INLINE_PREVIEW_MAX_KBIT,
|
INLINE_PREVIEW_MAX_KBIT,
|
||||||
));
|
));
|
||||||
let adapted = inline_width != requested_width.max(2)
|
let adapted = inline_fps != requested_fps.max(1) || inline_bitrate != max_bitrate_kbit.max(800);
|
||||||
|| inline_height != requested_height.max(2)
|
|
||||||
|| inline_fps != requested_fps.max(1)
|
|
||||||
|| inline_bitrate != max_bitrate_kbit.max(800);
|
|
||||||
(
|
(
|
||||||
inline_width,
|
inline_width,
|
||||||
inline_height,
|
inline_height,
|
||||||
@ -1378,36 +1372,6 @@ fn adapt_inline_preview_request(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(coverage))]
|
#[cfg(not(coverage))]
|
||||||
fn fit_preview_within_bounds(
|
|
||||||
requested_width: i32,
|
|
||||||
requested_height: i32,
|
|
||||||
max_width: i32,
|
|
||||||
max_height: i32,
|
|
||||||
) -> (i32, i32) {
|
|
||||||
let requested_width = round_down_even_i32(requested_width.max(2));
|
|
||||||
let requested_height = round_down_even_i32(requested_height.max(2));
|
|
||||||
let max_width = round_down_even_i32(max_width.max(2));
|
|
||||||
let max_height = round_down_even_i32(max_height.max(2));
|
|
||||||
if requested_width <= max_width && requested_height <= max_height {
|
|
||||||
return (requested_width, requested_height);
|
|
||||||
}
|
|
||||||
let width_limited_height =
|
|
||||||
round_down_even_i32((requested_height * max_width) / requested_width);
|
|
||||||
if width_limited_height <= max_height {
|
|
||||||
(max_width, width_limited_height.max(2))
|
|
||||||
} else {
|
|
||||||
let height_limited_width =
|
|
||||||
round_down_even_i32((requested_width * max_height) / requested_height);
|
|
||||||
(height_limited_width.max(2), max_height)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(coverage))]
|
|
||||||
fn round_down_even_i32(value: i32) -> i32 {
|
|
||||||
let value = value.max(2);
|
|
||||||
value - (value & 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(coverage))]
|
#[cfg(not(coverage))]
|
||||||
fn events_per_second(events: &VecDeque<Instant>, now: Instant) -> f32 {
|
fn events_per_second(events: &VecDeque<Instant>, now: Instant) -> f32 {
|
||||||
let Some(oldest) = events.front().copied() else {
|
let Some(oldest) = events.front().copied() else {
|
||||||
@ -1494,8 +1458,14 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn inline_preview_request_caps_large_full_quality_streams() {
|
fn inline_preview_request_caps_large_full_quality_streams() {
|
||||||
|
let adapted = adapt_inline_preview_request(1920, 1080, 30, 12_000, true);
|
||||||
|
assert_eq!(adapted, (1920, 1080, 24, 4_000, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inline_preview_request_keeps_source_stream_honest() {
|
||||||
let adapted = adapt_inline_preview_request(1920, 1080, 30, 12_000, false);
|
let adapted = adapt_inline_preview_request(1920, 1080, 30, 12_000, false);
|
||||||
assert_eq!(adapted, (960, 540, 24, 4_000, true));
|
assert_eq!(adapted, (1920, 1080, 30, 12_000, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lesavka_common"
|
name = "lesavka_common"
|
||||||
version = "0.11.6"
|
version = "0.11.7"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,6 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn banner_includes_version() {
|
fn banner_includes_version() {
|
||||||
assert_eq!(banner("0.11.6"), "lesavka-common CLI (v0.11.6)");
|
assert_eq!(banner("0.11.7"), "lesavka-common CLI (v0.11.7)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ bench = false
|
|||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "lesavka_server"
|
name = "lesavka_server"
|
||||||
version = "0.11.6"
|
version = "0.11.7"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
autobins = false
|
autobins = false
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user