54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
|
|
use std::time::Duration;
|
||
|
|
use tokio::time::Instant;
|
||
|
|
|
||
|
|
use super::UpstreamMediaKind;
|
||
|
|
|
||
|
|
pub(super) fn upstream_timing_trace_enabled() -> bool {
|
||
|
|
std::env::var("LESAVKA_UPSTREAM_TIMING_TRACE")
|
||
|
|
.ok()
|
||
|
|
.map(|value| {
|
||
|
|
let trimmed = value.trim();
|
||
|
|
!(trimmed.eq_ignore_ascii_case("0")
|
||
|
|
|| trimmed.eq_ignore_ascii_case("false")
|
||
|
|
|| trimmed.eq_ignore_ascii_case("no")
|
||
|
|
|| trimmed.eq_ignore_ascii_case("off"))
|
||
|
|
})
|
||
|
|
.unwrap_or(false)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub(super) fn upstream_playout_delay() -> Duration {
|
||
|
|
let delay_ms = std::env::var("LESAVKA_UPSTREAM_PLAYOUT_DELAY_MS")
|
||
|
|
.ok()
|
||
|
|
.and_then(|value| value.trim().parse::<u64>().ok())
|
||
|
|
.unwrap_or(1_000);
|
||
|
|
Duration::from_millis(delay_ms)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub(super) fn upstream_playout_offset_us(kind: UpstreamMediaKind) -> i64 {
|
||
|
|
let name = match kind {
|
||
|
|
UpstreamMediaKind::Camera => "LESAVKA_UPSTREAM_VIDEO_PLAYOUT_OFFSET_US",
|
||
|
|
UpstreamMediaKind::Microphone => "LESAVKA_UPSTREAM_AUDIO_PLAYOUT_OFFSET_US",
|
||
|
|
};
|
||
|
|
std::env::var(name)
|
||
|
|
.ok()
|
||
|
|
.and_then(|value| value.trim().parse::<i64>().ok())
|
||
|
|
.unwrap_or(0)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub(super) fn upstream_pairing_master_slack() -> Duration {
|
||
|
|
let slack_us = std::env::var("LESAVKA_UPSTREAM_PAIR_SLACK_US")
|
||
|
|
.ok()
|
||
|
|
.and_then(|value| value.trim().parse::<u64>().ok())
|
||
|
|
.unwrap_or(20_000);
|
||
|
|
Duration::from_micros(slack_us)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub(super) fn apply_playout_offset(base: Instant, offset_us: i64) -> Instant {
|
||
|
|
if offset_us >= 0 {
|
||
|
|
base + Duration::from_micros(offset_us as u64)
|
||
|
|
} else {
|
||
|
|
base.checked_sub(Duration::from_micros(offset_us.unsigned_abs()))
|
||
|
|
.unwrap_or(base)
|
||
|
|
}
|
||
|
|
}
|