Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: address camera preview PR feedback

Richie McIlroyef3a82aba6ad
diff --git a/apps/desktop/src-tauri/src/camera.rs b/apps/desktop/src-tauri/src/camera.rs
index ed3a441e0..221e189de 100644
--- a/apps/desktop/src-tauri/src/camera.rs
+++ b/apps/desktop/src-tauri/src/camera.rs
@@ -18,7 +18,6 @@ use kameo::actor::ActorRef;
use serde::{Deserialize, Serialize};
use specta::Type;
use std::{
- mem::ManuallyDrop,
sync::{
Arc,
atomic::{AtomicU64, Ordering},
@@ -415,13 +414,11 @@ impl CameraPreviewManager {
);
let (drop_tx, drop_rx) = oneshot::channel();
- let renderer = ManuallyDrop::new(renderer);
- window
- .run_on_main_thread(move || {
- drop(ManuallyDrop::into_inner(renderer));
- let _ = drop_tx.send(());
- })
- .ok();
+ let renderer = Box::new(renderer);
+ let _ = window.run_on_main_thread(move || {
+ drop(renderer);
+ let _ = drop_tx.send(());
+ });
wait_for_shutdown_signal(&rt, drop_rx, Duration::from_millis(250));
@@ -1202,11 +1199,14 @@ impl Renderer {
});
if blurred {
- let blur_output = self
+ let Some(blur_output) = self
.blur_processor
.as_mut()
.and_then(|p| p.process_returning_output())
- .expect("blurred flag guarantees output");
+ else {
+ prepared.render(surface, frame_data, frame_stride);
+ return true;
+ };
let mut encoder = self
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
@@ -1477,14 +1477,12 @@ impl Renderer {
drop(std::mem::take(&mut self.texture));
self.aspect_ratio = Cached::default();
- let surface = ManuallyDrop::new(self.surface.take());
+ let surface = self.surface.take();
let (drop_tx, drop_rx) = oneshot::channel();
- window
- .run_on_main_thread(move || {
- drop(ManuallyDrop::into_inner(surface));
- let _ = drop_tx.send(());
- })
- .ok();
+ let _ = window.run_on_main_thread(move || {
+ drop(surface);
+ let _ = drop_tx.send(());
+ });
let _ = tokio::time::timeout(Duration::from_millis(250), drop_rx).await;
self.device.destroy();
diff --git a/apps/desktop/src-tauri/src/camera_native.rs b/apps/desktop/src-tauri/src/camera_native.rs
index 44a1a7820..9d3988451 100644
--- a/apps/desktop/src-tauri/src/camera_native.rs
+++ b/apps/desktop/src-tauri/src/camera_native.rs
@@ -123,7 +123,8 @@ pub fn classify_frame(frame: &NativeCameraFrame) -> Result<NativeFrameKind, Nati
.sample_buf
.format_desc()
.ok_or(NativeFrameError::NoFormatDesc)?;
- match cidre::four_cc_to_str(&mut format_desc.media_sub_type().to_be_bytes()) {
+ let mut fourcc = format_desc.media_sub_type().to_be_bytes();
+ match cidre::four_cc_to_str(&mut fourcc) {
"420v" => Ok(NativeFrameKind::Nv12 { full_range: false }),
"420f" => Ok(NativeFrameKind::Nv12 { full_range: true }),
"BGRA" => Ok(NativeFrameKind::Bgra),
diff --git a/apps/desktop/src/utils/socket.ts b/apps/desktop/src/utils/socket.ts
index 37b8d2516..46af09bbe 100644
--- a/apps/desktop/src/utils/socket.ts
+++ b/apps/desktop/src/utils/socket.ts
@@ -748,8 +748,6 @@ export function createImageDataWS(
if (!mainThreadWebGPUInitializing && !mainThreadWebGPU) {
mainThreadWebGPUInitializing = true;
- // initWebGPU's catch covers the no-adapter case, so a separate
- // isWebGPUSupported probe would just request the adapter twice.
const maybeSupported =
typeof navigator !== "undefined" && !!navigator.gpu;
if (maybeSupported && directCanvas) {
diff --git a/crates/recording/src/feeds/camera.rs b/crates/recording/src/feeds/camera.rs
index 2f9a79548..67528cd2d 100644
--- a/crates/recording/src/feeds/camera.rs
+++ b/crates/recording/src/feeds/camera.rs
@@ -522,11 +522,14 @@ fn release_camera_thread(handle: std::thread::JoinHandle<()>) {
let _ = handle.join();
} else {
warn!("Camera setup thread is still running after cancellation");
- let _ = std::thread::Builder::new()
+ if let Err(err) = std::thread::Builder::new()
.name("camera-setup-reaper".to_string())
.spawn(move || {
let _ = handle.join();
- });
+ })
+ {
+ warn!(?err, "Failed to spawn camera-setup-reaper thread");
+ }
}
}
@@ -801,7 +804,7 @@ async fn setup_camera(
// converted to derive VideoInfo; afterwards skip the full-frame
// copy entirely when nothing consumes ffmpeg frames.
if ready_signal.is_none()
- && ffmpeg_sender_count.load(std::sync::atomic::Ordering::Relaxed) == 0
+ && ffmpeg_sender_count.load(std::sync::atomic::Ordering::Acquire) == 0
{
return;
}
@@ -916,7 +919,7 @@ async fn setup_camera(
// converted to derive VideoInfo; afterwards skip the full-frame
// copy entirely when nothing consumes ffmpeg frames.
if ready_signal.is_none()
- && ffmpeg_sender_count.load(std::sync::atomic::Ordering::Relaxed) == 0
+ && ffmpeg_sender_count.load(std::sync::atomic::Ordering::Acquire) == 0
{
return;
}