Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: handle RGBA fallback correctly in GPU NV12 conversion path

Richie McIlroy8ec07ac0c132
diff --git a/apps/desktop/src-tauri/src/editor_window.rs b/apps/desktop/src-tauri/src/editor_window.rs
index 35da7c3c4..d8042a925 100644
--- a/apps/desktop/src-tauri/src/editor_window.rs
+++ b/apps/desktop/src-tauri/src/editor_window.rs
@@ -29,16 +29,29 @@ async fn do_prewarm(app: AppHandle, path: PathBuf) -> PendingResult {
path,
Box::new(move |output| {
let ws_frame = match output {
- cap_editor::editor::EditorFrameOutput::Nv12(frame) => WSFrame {
- data: frame.data,
- width: frame.width,
- height: frame.height,
- stride: frame.y_stride,
- frame_number: frame.frame_number,
- target_time_ns: frame.target_time_ns,
- format: WSFrameFormat::Nv12,
- created_at: Instant::now(),
- },
+ cap_editor::editor::EditorFrameOutput::Nv12(frame) => {
+ if frame.format == cap_rendering::GpuOutputFormat::Nv12 {
+ WSFrame {
+ data: frame.data,
+ width: frame.width,
+ height: frame.height,
+ stride: frame.y_stride,
+ frame_number: frame.frame_number,
+ target_time_ns: frame.target_time_ns,
+ format: WSFrameFormat::Nv12,
+ created_at: Instant::now(),
+ }
+ } else {
+ WSFrame::from_rendered_frame_nv12(
+ frame.data,
+ frame.width,
+ frame.height,
+ frame.y_stride,
+ frame.frame_number,
+ frame.target_time_ns,
+ )
+ }
+ }
cap_editor::editor::EditorFrameOutput::Rgba(frame) => {
WSFrame::from_rendered_frame_nv12(
frame.data,
@@ -234,16 +247,29 @@ impl EditorInstances {
path,
Box::new(move |output| {
let ws_frame = match output {
- cap_editor::editor::EditorFrameOutput::Nv12(frame) => WSFrame {
- data: frame.data,
- width: frame.width,
- height: frame.height,
- stride: frame.y_stride,
- frame_number: frame.frame_number,
- target_time_ns: frame.target_time_ns,
- format: WSFrameFormat::Nv12,
- created_at: Instant::now(),
- },
+ cap_editor::editor::EditorFrameOutput::Nv12(frame) => {
+ if frame.format == cap_rendering::GpuOutputFormat::Nv12 {
+ WSFrame {
+ data: frame.data,
+ width: frame.width,
+ height: frame.height,
+ stride: frame.y_stride,
+ frame_number: frame.frame_number,
+ target_time_ns: frame.target_time_ns,
+ format: WSFrameFormat::Nv12,
+ created_at: Instant::now(),
+ }
+ } else {
+ WSFrame::from_rendered_frame_nv12(
+ frame.data,
+ frame.width,
+ frame.height,
+ frame.y_stride,
+ frame.frame_number,
+ frame.target_time_ns,
+ )
+ }
+ }
cap_editor::editor::EditorFrameOutput::Rgba(frame) => {
WSFrame::from_rendered_frame_nv12(
frame.data,
diff --git a/crates/rendering/src/frame_pipeline.rs b/crates/rendering/src/frame_pipeline.rs
index c49d9ba24..5b9e207ee 100644
--- a/crates/rendering/src/frame_pipeline.rs
+++ b/crates/rendering/src/frame_pipeline.rs
@@ -315,10 +315,17 @@ impl PendingNv12Readback {
y_stride: self.y_stride,
frame_number: self.frame_number,
target_time_ns,
+ format: GpuOutputFormat::Nv12,
})
}
}
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub enum GpuOutputFormat {
+ Nv12,
+ Rgba,
+}
+
pub struct Nv12RenderedFrame {
pub data: Vec<u8>,
pub width: u32,
@@ -326,6 +333,7 @@ pub struct Nv12RenderedFrame {
pub y_stride: u32,
pub frame_number: u32,
pub target_time_ns: u64,
+ pub format: GpuOutputFormat,
}
pub struct PendingReadback {
@@ -841,6 +849,7 @@ pub async fn finish_encoder_nv12(
y_stride: rgba_frame.padded_bytes_per_row,
frame_number: rgba_frame.frame_number,
target_time_ns: rgba_frame.target_time_ns,
+ format: GpuOutputFormat::Rgba,
})
}
}
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index d74f53b7d..092465e03 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -42,7 +42,7 @@ pub mod zoom_focus_interpolation;
pub use coord::*;
pub use decoder::{DecodedFrame, DecoderStatus, DecoderType, PixelFormat};
-pub use frame_pipeline::{Nv12RenderedFrame, RenderedFrame};
+pub use frame_pipeline::{GpuOutputFormat, Nv12RenderedFrame, RenderedFrame};
pub use project_recordings::{ProjectRecordingsMeta, SegmentRecordings, Video};
use mask::interpolate_masks;