test(lesavka): cover live media control choices

This commit is contained in:
Brad Stein 2026-05-19 10:43:49 -03:00
parent 679a744ec8
commit d73d86f0da
2 changed files with 88 additions and 0 deletions

View File

@ -148,6 +148,45 @@ use super::*;
assert!(!disables_upstream_epoch_auto_heal("yes"));
}
#[test]
/// Keeps live camera codec override behavior explicit because the launcher can switch transport without restarting the whole app.
fn live_camera_codec_override_updates_capture_config_aliases() {
use crate::input::camera::{CameraCodec, CameraConfig};
use crate::live_media_control::MediaCameraCodecChoice;
let cfg = CameraConfig {
codec: CameraCodec::Mjpeg,
width: 1280,
height: 720,
fps: 30,
};
assert_eq!(camera_codec_id(CameraCodec::Mjpeg), "mjpeg");
assert_eq!(camera_codec_id(CameraCodec::Hevc), "hevc");
assert_eq!(camera_codec_id(CameraCodec::H264), "h264");
assert_eq!(parse_live_camera_codec("jpeg"), Some(CameraCodec::Mjpeg));
assert_eq!(parse_live_camera_codec("h.265"), Some(CameraCodec::Hevc));
assert_eq!(parse_live_camera_codec("h264"), Some(CameraCodec::H264));
assert_eq!(parse_live_camera_codec("vp9"), None);
assert_eq!(
camera_config_with_live_codec(Some(cfg), &MediaCameraCodecChoice::Inherit)
.expect("inherited config")
.codec,
CameraCodec::Mjpeg
);
assert_eq!(
camera_config_with_live_codec(
Some(cfg),
&MediaCameraCodecChoice::selected(Some("hevc".to_string())),
)
.expect("overridden config")
.codec,
CameraCodec::Hevc
);
assert!(camera_config_with_live_codec(None, &MediaCameraCodecChoice::Inherit).is_none());
}
#[test]
/// Keeps HEVC recovery explicit because freshness drops can otherwise resume from predictive frames.
fn hevc_keyframe_detection_recognizes_irap_access_units() {

View File

@ -41,6 +41,30 @@ fn device_choices_resolve_inherit_auto_and_selected() {
);
}
#[test]
fn codec_and_noise_choices_resolve_inherit_and_selected_values() {
assert_eq!(
MediaCameraCodecChoice::selected(Some(" HeVc ".to_string())).resolve(Some("mjpeg")),
Some("hevc".to_string())
);
assert_eq!(
MediaCameraCodecChoice::selected(Some(" ".to_string())).resolve(Some("mjpeg")),
Some("mjpeg".to_string())
);
assert_eq!(
MediaAudioCodecChoice::Inherit.resolve(UpstreamAudioCodec::PcmS16le),
UpstreamAudioCodec::PcmS16le
);
assert_eq!(
MediaAudioCodecChoice::selected(UpstreamAudioCodec::Opus)
.resolve(UpstreamAudioCodec::PcmS16le),
UpstreamAudioCodec::Opus
);
assert!(MediaNoiseSuppressionChoice::Enabled.resolve(false));
assert!(!MediaNoiseSuppressionChoice::Disabled.resolve(true));
assert!(MediaNoiseSuppressionChoice::Inherit.resolve(true));
}
#[test]
/// Keeps `live_media_controls_refresh_after_file_changes` explicit because it sits on this module contract, where hidden behavior would make regressions difficult to diagnose.
/// Inputs are the typed parameters; output is the return value or side effect.
@ -87,6 +111,31 @@ fn parser_tolerates_unknown_tokens_and_rejects_invalid_flags() {
);
}
#[test]
fn parser_round_trips_codec_aliases_noise_and_encoded_choices() {
let raw = "camera=1 mic=1 speaker=0 camera_source_b64=b64:TG9naXRlY2ggQlJJTw== camera_quality=720p mic_source=auto speaker_sink=inherit webcam_transport=h265 uplink_audio_codec=pcm mic_noise_suppression=yes";
let state = parse_media_control_state(raw).expect("state");
assert_eq!(
state.camera_source.resolve(None).as_deref(),
Some("Logitech BRIO")
);
assert_eq!(state.camera_profile.resolve(None).as_deref(), Some("720p"));
assert_eq!(state.microphone_source, MediaDeviceChoice::Auto);
assert_eq!(state.audio_sink, MediaDeviceChoice::Inherit);
assert_eq!(state.camera_codec.resolve(None).as_deref(), Some("hevc"));
assert_eq!(
state.audio_codec.resolve(UpstreamAudioCodec::Opus),
UpstreamAudioCodec::PcmS16le
);
assert!(state.noise_suppression.resolve(false));
assert_eq!(parse_choice("b64:not-base64"), None);
assert_eq!(parse_camera_codec_choice("vp9"), None);
assert_eq!(parse_audio_codec_choice("flac"), None);
assert_eq!(parse_noise_suppression_choice("maybe"), None);
}
#[test]
/// Keeps `refresh_falls_back_to_all_enabled_if_lock_is_poisoned` explicit because it sits on this module contract, where hidden behavior would make regressions difficult to diagnose.
/// Inputs are the typed parameters; output is the return value or side effect.