diff --git a/src-tauri/src/audio.rs b/src-tauri/src/audio.rs index 7a9a0c4..93b599a 100644 --- a/src-tauri/src/audio.rs +++ b/src-tauri/src/audio.rs @@ -78,14 +78,17 @@ pub(crate) fn start(output_path: PathBuf) -> Result { } impl AudioSession { - pub fn stop(self) -> Result { + /// Stop the capture thread and hand back the PCM file it wrote. Joining can + /// only fail if the thread panicked, which is logged rather than returned - + /// the recorded audio is still usable either way. + pub fn stop(self) -> PathBuf { self.running.store(false, Ordering::Relaxed); if let Some(t) = self.thread { if let Ok(Err(ref e)) = t.join() { tracing::warn!("audio capture thread reported error on stop: {e:#}"); } } - Ok(self.output_path) + self.output_path } /// True if the capture thread flagged an abnormal exit (endpoint lost, diff --git a/src-tauri/src/capture.rs b/src-tauri/src/capture.rs index 546608a..7788bd0 100644 --- a/src-tauri/src/capture.rs +++ b/src-tauri/src/capture.rs @@ -45,13 +45,13 @@ const MAX_ENCODE_WIDTH: u32 = 3840; const AUTO_ENCODE_WIDTH: u32 = 1920; const FALLBACK_REFRESH_HZ: u32 = 60; -/// Returns the cap to apply to the encode width, or None for native res. +/// The cap to apply to the encode width in pixels. /// Auto keeps the historic 1920 cap so nothing changes for existing users; /// Full records at native res up to `MAX_ENCODE_WIDTH` (3840). -fn encode_width_limit(quality: CaptureQuality) -> Option { +fn encode_width_limit(quality: CaptureQuality) -> u32 { match quality { - CaptureQuality::Auto => Some(AUTO_ENCODE_WIDTH), - CaptureQuality::Full => Some(MAX_ENCODE_WIDTH), + CaptureQuality::Auto => AUTO_ENCODE_WIDTH, + CaptureQuality::Full => MAX_ENCODE_WIDTH, } } @@ -63,7 +63,7 @@ pub(crate) struct CaptureSetup { pub height: u32, pub crop: Option, pub pipe_fps: u32, - pub encode_width_limit: Option, + pub encode_width_limit: u32, pub frame_counter: Arc, } @@ -453,12 +453,9 @@ impl GraphicsCaptureApiHandler for CaptureHandler { let h = c.height.min(setup.height.saturating_sub(y.cast_unsigned())); filter_parts.push(format!("crop={w}:{h}:{x}:{y}")); } - if let Some(limit) = setup.encode_width_limit { - if setup.width > limit { - filter_parts.push(format!("scale={limit}:-2")); - } else { - filter_parts.push("scale=trunc(iw/2)*2:trunc(ih/2)*2".to_string()); - } + let limit = setup.encode_width_limit; + if setup.width > limit { + filter_parts.push(format!("scale={limit}:-2")); } else { filter_parts.push("scale=trunc(iw/2)*2:trunc(ih/2)*2".to_string()); } @@ -716,7 +713,7 @@ fn compute_output_dims( monitor_w: u32, monitor_h: u32, crop: Option, - width_limit: Option, + width_limit: u32, ) -> (u32, u32) { let (raw_w, raw_h) = match crop { Some(c) => { @@ -729,7 +726,7 @@ fn compute_output_dims( } None => (monitor_w, monitor_h), }; - let cap = width_limit.unwrap_or(u32::MAX); + let cap = width_limit; if raw_w > cap { let scale = f64::from(cap) / f64::from(raw_w); let nh = crate::encode::round_u32(f64::from(raw_h) * scale); diff --git a/src-tauri/src/encode.rs b/src-tauri/src/encode.rs index cea5610..fb4a780 100644 --- a/src-tauri/src/encode.rs +++ b/src-tauri/src/encode.rs @@ -29,6 +29,10 @@ pub(crate) fn round_u32(v: f64) -> u32 { clippy::cast_possible_truncation, reason = "value is clamped into u32 range on the line above the cast" )] + #[allow( + clippy::cast_sign_loss, + reason = "value is clamped to 0.0 or above on the line above the cast" + )] let out = v.round().clamp(0.0, f64::from(u32::MAX)) as u32; out } @@ -40,6 +44,10 @@ pub(crate) fn round_u64(v: f64) -> u64 { clippy::cast_possible_truncation, reason = "value is clamped into u64 range on the line above the cast" )] + #[allow( + clippy::cast_sign_loss, + reason = "value is clamped to 0.0 or above on the line above the cast" + )] let out = v.round().clamp(0.0, 18_446_744_073_709_551_615.0) as u64; out } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 852b16a..fed4a09 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -602,9 +602,7 @@ fn pause_capture(state: State<'_, AppState>) -> Result<(), String> { .map_err(|e| format!("fixing fps: {e:#}"))?; let path = if fixed_path.exists() { fixed_path } else { raw_path }; - let audio_path = lock(&state.audio) - .take() - .and_then(|a| a.stop().ok()); + let audio_path = lock(&state.audio).take().map(|a| a.stop()); let new_clicks: Vec = lock(&state.click_recorder) .take() @@ -701,9 +699,7 @@ fn restart_audio_capture( let mut ss = lock(&state.session); let ss = ss.as_mut().ok_or_else(|| "no session in progress".to_string())?; if let Some(a) = lock(&state.audio).take() { - if let Ok(p) = a.stop() { - ss.audio_segments.push(p); - } + ss.audio_segments.push(a.stop()); } ss.audio_segments.len() + 1 }; @@ -747,9 +743,7 @@ fn stop_capture(app: AppHandle, state: State<'_, AppState>) -> Result