return values instead of wrapping them in needless results
This commit is contained in:
@@ -78,14 +78,17 @@ pub(crate) fn start(output_path: PathBuf) -> Result<AudioSession> {
|
||||
}
|
||||
|
||||
impl AudioSession {
|
||||
pub fn stop(self) -> Result<PathBuf> {
|
||||
/// 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,
|
||||
|
||||
@@ -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<u32> {
|
||||
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<CaptureRect>,
|
||||
pub pipe_fps: u32,
|
||||
pub encode_width_limit: Option<u32>,
|
||||
pub encode_width_limit: u32,
|
||||
pub frame_counter: Arc<std::sync::atomic::AtomicU64>,
|
||||
}
|
||||
|
||||
@@ -453,15 +453,12 @@ 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 {
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
filter_parts.push("scale=trunc(iw/2)*2:trunc(ih/2)*2".to_string());
|
||||
}
|
||||
let filter = filter_parts.join(",");
|
||||
|
||||
tracing::info!(
|
||||
@@ -716,7 +713,7 @@ fn compute_output_dims(
|
||||
monitor_w: u32,
|
||||
monitor_h: u32,
|
||||
crop: Option<CaptureRect>,
|
||||
width_limit: Option<u32>,
|
||||
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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<clicks::Click> = 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<RecordedCl
|
||||
|
||||
let live_audio = lock(&state.audio).take();
|
||||
if let Some(a) = live_audio {
|
||||
if let Ok(p) = a.stop() {
|
||||
ss.audio_segments.push(p);
|
||||
}
|
||||
ss.audio_segments.push(a.stop());
|
||||
}
|
||||
|
||||
let live_clicks = lock(&state.click_recorder)
|
||||
|
||||
Reference in New Issue
Block a user