Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Enhance GPU diagnostics and optimize UYVY to YUYV conversion

Richie McIlroy1784fb37a778
diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts
index 1afc1a010..f78bc7845 100644
--- a/apps/desktop/src/utils/tauri.ts
+++ b/apps/desktop/src/utils/tauri.ts
@@ -358,6 +358,7 @@ uploadProgressEvent: "upload-progress-event"
/** user-defined types **/
+export type AllGpusInfo = { gpus: GpuInfoDiag[]; primaryGpuIndex: number | null; isMultiGpuSystem: boolean; hasDiscreteGpu: boolean }
export type Annotation = { id: string; type: AnnotationType; x: number; y: number; width: number; height: number; strokeColor: string; strokeWidth: number; fillColor: string; opacity: number; rotation: number; text: string | null; maskType?: MaskType | null; maskLevel?: number | null }
export type AnnotationType = "arrow" | "circle" | "rectangle" | "text" | "mask"
export type AppTheme = "system" | "light" | "dark"
@@ -423,7 +424,7 @@ quality: number | null;
* Whether to prioritize speed over quality (default: false)
*/
fast: boolean | null }
-export type GpuInfoDiag = { vendor: string; description: string; dedicatedVideoMemoryMb: number }
+export type GpuInfoDiag = { vendor: string; description: string; dedicatedVideoMemoryMb: number; adapterIndex: number; isSoftwareAdapter: boolean; isBasicRenderDriver: boolean; supportsHardwareEncoding: boolean }
export type HapticPattern = "alignment" | "levelChange" | "generic"
export type HapticPerformanceTime = "default" | "now" | "drawCompleted"
export type Hotkey = { code: string; meta: boolean; ctrl: boolean; alt: boolean; shift: boolean }
@@ -478,6 +479,7 @@ export type RecordingStatus = "pending" | "recording"
export type RecordingStopped = null
export type RecordingTargetMode = "display" | "window" | "area"
export type RenderFrameEvent = { frame_number: number; fps: number; resolution_base: XY<number> }
+export type RenderingStatus = { isUsingSoftwareRendering: boolean; isUsingBasicRenderDriver: boolean; hardwareEncodingAvailable: boolean; warningMessage: string | null }
export type RequestOpenRecordingPicker = { target_mode: RecordingTargetMode | null }
export type RequestOpenSettings = { page: string }
export type RequestScreenCapturePrewarm = { force?: boolean }
@@ -498,7 +500,7 @@ export type StartRecordingInputs = { capture_target: ScreenCaptureTarget; captur
export type StereoMode = "stereo" | "monoL" | "monoR"
export type StudioRecordingMeta = { segment: SingleSegment } | { inner: MultipleSegments }
export type StudioRecordingStatus = { status: "InProgress" } | { status: "NeedsRemux" } | { status: "Failed"; error: string } | { status: "Complete" }
-export type SystemDiagnostics = { windowsVersion: WindowsVersionInfo | null; gpuInfo: GpuInfoDiag | null; availableEncoders: string[]; graphicsCaptureSupported: boolean; d3D11VideoProcessorAvailable: boolean }
+export type SystemDiagnostics = { windowsVersion: WindowsVersionInfo | null; gpuInfo: GpuInfoDiag | null; allGpus: AllGpusInfo | null; renderingStatus: RenderingStatus; availableEncoders: string[]; graphicsCaptureSupported: boolean; d3D11VideoProcessorAvailable: boolean }
export type TargetUnderCursor = { display_id: DisplayId | null; window: WindowUnderCursor | null }
export type TextSegment = { start: number; end: number; enabled?: boolean; content?: string; center?: XY<number>; size?: XY<number>; fontFamily?: string; fontSize?: number; fontWeight?: number; italic?: boolean; color?: string; fadeDuration?: number }
export type TimelineConfiguration = { segments: TimelineSegment[]; zoomSegments: ZoomSegment[]; sceneSegments?: SceneSegment[]; maskSegments?: MaskSegment[]; textSegments?: TextSegment[] }
diff --git a/crates/camera-windows/src/lib.rs b/crates/camera-windows/src/lib.rs
index 58aa97349..e3fac3c88 100644
--- a/crates/camera-windows/src/lib.rs
+++ b/crates/camera-windows/src/lib.rs
@@ -21,12 +21,148 @@ const MF_VIDEO_FORMAT_P010: GUID = GUID::from_u128(0x30313050_0000_0010_8000_00a
const MEDIASUBTYPE_Y800: GUID = GUID::from_u128(0x30303859_0000_0010_8000_00aa00389b71);
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum DeviceCategory {
+ Physical,
+ Virtual,
+ CaptureCard,
+}
+
+impl DeviceCategory {
+ pub fn is_virtual(&self) -> bool {
+ matches!(self, DeviceCategory::Virtual)
+ }
+
+ pub fn is_capture_card(&self) -> bool {
+ matches!(self, DeviceCategory::CaptureCard)
+ }
+}
+
+const VIRTUAL_CAMERA_PATTERNS: &[&str] = &[
+ "obs",
+ "virtual",
+ "snap camera",
+ "manycam",
+ "xsplit",
+ "streamlabs",
+ "droidcam",
+ "iriun",
+ "epoccam",
+ "ndi",
+ "newtek",
+ "camtwist",
+ "mmhmm",
+ "chromacam",
+ "vtuber",
+ "prism live",
+ "camo",
+ "avatarify",
+ "facerig",
+];
+
+const CAPTURE_CARD_PATTERNS: &[&str] = &[
+ "elgato",
+ "avermedia",
+ "magewell",
+ "blackmagic",
+ "decklink",
+ "intensity",
+ "ultrastudio",
+ "atomos",
+ "hauppauge",
+ "startech",
+ "j5create",
+ "razer ripsaw",
+ "pengo",
+ "evga xr1",
+ "nzxt signal",
+ "genki shadowcast",
+ "cam link",
+ "live gamer",
+ "game capture",
+];
+
+fn detect_device_category(name: &OsStr, model_id: Option<&str>) -> DeviceCategory {
+ let name_lower = name.to_string_lossy().to_lowercase();
+ let model_lower = model_id.map(|m| m.to_lowercase());
+
+ let matches_pattern = |patterns: &[&str]| {
+ patterns.iter().any(|pattern| {
+ name_lower.contains(pattern)
+ || model_lower.as_ref().is_some_and(|m| m.contains(pattern))
+ })
+ };
+
+ if matches_pattern(CAPTURE_CARD_PATTERNS) {
+ DeviceCategory::CaptureCard
+ } else if matches_pattern(VIRTUAL_CAMERA_PATTERNS) {
+ DeviceCategory::Virtual
+ } else {
+ DeviceCategory::Physical
+ }
+}
+
+#[derive(Debug, Clone)]
+pub struct FormatPreference {
+ pub width: u32,
+ pub height: u32,
+ pub frame_rate: f32,
+ pub format_priority: Vec<PixelFormat>,
+}
+
+impl FormatPreference {
+ pub fn new(width: u32, height: u32, frame_rate: f32) -> Self {
+ Self {
+ width,
+ height,
+ frame_rate,
+ format_priority: vec![
+ PixelFormat::NV12,
+ PixelFormat::YUYV422,
+ PixelFormat::UYVY422,
+ PixelFormat::YUV420P,
+ PixelFormat::MJPEG,
+ PixelFormat::RGB32,
+ ],
+ }
+ }
+
+ pub fn with_format_priority(mut self, priority: Vec<PixelFormat>) -> Self {
+ self.format_priority = priority;
+ self
+ }
+
+ pub fn for_hardware_encoding() -> Self {
+ Self::new(1920, 1080, 30.0).with_format_priority(vec![
+ PixelFormat::NV12,
+ PixelFormat::YUYV422,
+ PixelFormat::UYVY422,
+ PixelFormat::YUV420P,
+ ])
+ }
+
+ pub fn for_capture_card() -> Self {
+ Self::new(1920, 1080, 60.0).with_format_priority(vec![
+ PixelFormat::NV12,
+ PixelFormat::YUYV422,
+ PixelFormat::UYVY422,
+ PixelFormat::P010,
+ ])
+ }
+}
+
+impl Default for FormatPreference {
+ fn default() -> Self {
+ Self::new(1920, 1080, 30.0)
+ }
+}
+
#[derive(Clone)]
pub struct VideoDeviceInfo {
id: OsString,
name: OsString,
model_id: Option<String>,
- // formats: Vec<VideoFormat>,
+ category: DeviceCategory,
inner: VideoDeviceInfoInner,
}
@@ -67,6 +203,104 @@ impl VideoDeviceInfo {
self.model_id.as_deref()
}
+ pub fn category(&self) -> DeviceCategory {
+ self.category
+ }
+
+ pub fn is_virtual_camera(&self) -> bool {
+ self.category.is_virtual()
+ }
+
+ pub fn is_capture_card(&self) -> bool {
+ self.category.is_capture_card()
+ }
+
+ pub fn is_high_bandwidth(&self) -> bool {
+ if !self.is_capture_card() {
+ return false;
+ }
+ self.formats().iter().any(|f| {
+ let pixels = f.width() as u64 * f.height() as u64;
+ let fps = f.frame_rate() as u64;
+ pixels >= 3840 * 2160 && fps >= 30
+ })
+ }
+
+ pub fn max_resolution(&self) -> Option<(u32, u32)> {
+ self.formats()
+ .iter()
+ .map(|f| (f.width(), f.height()))
+ .max_by_key(|(w, h)| (*w as u64) * (*h as u64))
+ }
+
+ pub fn find_best_format(&self, preference: &FormatPreference) -> Option<VideoFormat> {
+ let formats = self.formats();
+ if formats.is_empty() {
+ return None;
+ }
+
+ let target_pixels = preference.width as u64 * preference.height as u64;
+
+ let score_format = |f: &VideoFormat| {
+ let format_priority = preference
+ .format_priority
+ .iter()
+ .position(|&pf| pf == f.pixel_format())
+ .map(|pos| 1000 - pos as i32)
+ .unwrap_or(0);
+
+ let pixels = f.width() as u64 * f.height() as u64;
+ let resolution_score = if pixels == target_pixels {
+ 500
+ } else if pixels > target_pixels {
+ 400 - ((pixels - target_pixels) / 10000).min(300) as i32
+ } else {
+ 300 - ((target_pixels - pixels) / 10000).min(200) as i32
+ };
+
+ let fps_diff = (f.frame_rate() - preference.frame_rate).abs();
+ let fps_score = 100 - (fps_diff * 10.0).min(100.0) as i32;
+
+ format_priority + resolution_score + fps_score
+ };
+
+ formats.into_iter().max_by_key(score_format)
+ }
+
+ pub fn find_format_with_fallback(&self, preference: &FormatPreference) -> Option<VideoFormat> {
+ if let Some(format) = self.find_best_format(preference) {
+ return Some(format);
+ }
+
+ let fallback_formats = [
+ PixelFormat::NV12,
+ PixelFormat::YUYV422,
+ PixelFormat::UYVY422,
+ PixelFormat::MJPEG,
+ PixelFormat::RGB32,
+ PixelFormat::YUV420P,
+ ];
+
+ let formats = self.formats();
+ for fallback_pixel_format in fallback_formats {
+ if let Some(format) = formats
+ .iter()
+ .filter(|f| f.pixel_format() == fallback_pixel_format)
+ .max_by_key(|f| {
+ let res_score = (f.width() as i32).min(preference.width as i32)
+ + (f.height() as i32).min(preference.height as i32);
+ let fps_score =
+ (100.0 - (f.frame_rate() - preference.frame_rate).abs().min(100.0)) as i32;
+ res_score + fps_score
+ })
+ {
+ return Some(format.clone());
+ }
+ }
+
+ formats.into_iter().next()
+ }
+
pub fn is_mf(&self) -> bool {
matches!(self.inner, VideoDeviceInfoInner::MediaFoundation { .. })
}
@@ -285,11 +519,13 @@ pub fn get_devices() -> Result<Vec<VideoDeviceInfo>, GetDevicesError> {
let name = device.name()?;
let id = device.id()?;
let model_id = device.model_id();
+ let category = detect_device_category(&name, model_id.as_deref());
Ok::<_, windows_core::Error>(VideoDeviceInfo {
name,
id,
model_id,
+ category,
inner: VideoDeviceInfoInner::MediaFoundation { device },
})
})
@@ -308,11 +544,13 @@ pub fn get_devices() -> Result<Vec<VideoDeviceInfo>, GetDevicesError> {
let id = device.id()?;
let name = device.name()?;
let model_id = device.model_id();
+ let category = detect_device_category(&name, model_id.as_deref());
Some(VideoDeviceInfo {
name,
id,
model_id,
+ category,
inner: VideoDeviceInfoInner::DirectShow(device),
})
})
diff --git a/crates/frame-converter/src/d3d11.rs b/crates/frame-converter/src/d3d11.rs
index 34eb84e68..8dac4f6dd 100644
--- a/crates/frame-converter/src/d3d11.rs
+++ b/crates/frame-converter/src/d3d11.rs
@@ -73,6 +73,26 @@ pub struct GpuInfo {
pub device_id: u32,
pub description: String,
pub dedicated_video_memory: u64,
+ pub adapter_index: u32,
+ pub is_software_adapter: bool,
+}
+
+impl GpuInfo {
+ pub fn is_basic_render_driver(&self) -> bool {
+ self.vendor == GpuVendor::Microsoft
+ && (self.description.contains("Basic Render Driver")
+ || self.description.contains("Microsoft Basic")
+ || self.dedicated_video_memory == 0)
+ }
+
+ pub fn is_warp(&self) -> bool {
+ self.description.contains("Microsoft Basic Render Driver")
+ || self.description.contains("WARP")
+ }
+
+ pub fn supports_hardware_encoding(&self) -> bool {
+ !self.is_software_adapter && !self.is_basic_render_driver()
+ }
}
impl GpuInfo {
@@ -90,19 +110,30 @@ impl GpuInfo {
}
static DETECTED_GPU: OnceLock<Option<GpuInfo>> = OnceLock::new();
+static ALL_GPUS: OnceLock<Vec<GpuInfo>> = OnceLock::new();
pub fn detect_primary_gpu() -> Option<&'static GpuInfo> {
DETECTED_GPU
.get_or_init(|| {
- let result = detect_primary_gpu_inner();
+ let all_gpus = enumerate_all_gpus();
+ let result = select_best_gpu(&all_gpus);
if let Some(ref info) = result {
tracing::debug!(
- "Detected primary GPU: {} (Vendor: {}, VendorID: 0x{:04X}, VRAM: {} MB)",
+ "Selected primary GPU: {} (Vendor: {}, VendorID: 0x{:04X}, VRAM: {} MB, Adapter: {}, SoftwareRenderer: {})",
info.description,
info.vendor_name(),
info.vendor_id,
- info.dedicated_video_memory / (1024 * 1024)
+ info.dedicated_video_memory / (1024 * 1024),
+ info.adapter_index,
+ info.is_software_adapter
);
+
+ if info.is_basic_render_driver() {
+ tracing::warn!(
+ "Detected Microsoft Basic Render Driver - hardware encoding will be disabled. \
+ This may indicate missing GPU drivers or a remote desktop session."
+ );
+ }
} else {
tracing::debug!("No GPU detected via DXGI, using default encoder order");
}
@@ -111,29 +142,126 @@ pub fn detect_primary_gpu() -> Option<&'static GpuInfo> {
.as_ref()
}
-fn detect_primary_gpu_inner() -> Option<GpuInfo> {
+pub fn get_all_gpus() -> &'static Vec<GpuInfo> {
+ ALL_GPUS.get_or_init(enumerate_all_gpus)
+}
+
+fn enumerate_all_gpus() -> Vec<GpuInfo> {
+ let mut gpus = Vec::new();
+
unsafe {
- let factory: IDXGIFactory1 = CreateDXGIFactory1().ok()?;
- let adapter: IDXGIAdapter = factory.EnumAdapters(0).ok()?;
- let desc = adapter.GetDesc().ok()?;
+ let factory: IDXGIFactory1 = match CreateDXGIFactory1() {
+ Ok(f) => f,
+ Err(e) => {
+ tracing::warn!("Failed to create DXGI factory: {e:?}");
+ return gpus;
+ }
+ };
- let description = String::from_utf16_lossy(
- &desc
- .Description
- .iter()
- .take_while(|&&c| c != 0)
- .copied()
- .collect::<Vec<_>>(),
- );
+ let mut adapter_index = 0u32;
+ loop {
+ let adapter: IDXGIAdapter = match factory.EnumAdapters(adapter_index) {
+ Ok(a) => a,
+ Err(_) => break,
+ };
- Some(GpuInfo {
- vendor: GpuVendor::from_id(desc.VendorId),
- vendor_id: desc.VendorId,
- device_id: desc.DeviceId,
- description,
- dedicated_video_memory: desc.DedicatedVideoMemory as u64,
+ if let Ok(desc) = adapter.GetDesc() {
+ let description = String::from_utf16_lossy(
+ &desc
+ .Description
+ .iter()
+ .take_while(|&&c| c != 0)
+ .copied()
+ .collect::<Vec<_>>(),
+ );
+
+ let is_software = desc.VendorId == 0x1414
+ && (description.contains("Basic Render")
+ || description.contains("WARP")
+ || description.contains("Microsoft Basic"));
+
+ let gpu_info = GpuInfo {
+ vendor: GpuVendor::from_id(desc.VendorId),
+ vendor_id: desc.VendorId,
+ device_id: desc.DeviceId,
+ description: description.clone(),
+ dedicated_video_memory: desc.DedicatedVideoMemory as u64,
+ adapter_index,
+ is_software_adapter: is_software,
+ };
+
+ tracing::debug!(
+ "Found GPU adapter {}: {} (Vendor: 0x{:04X}, VRAM: {} MB, Software: {})",
+ adapter_index,
+ description,
+ desc.VendorId,
+ desc.DedicatedVideoMemory / (1024 * 1024),
+ is_software
+ );
+
+ gpus.push(gpu_info);
+ }
+
+ adapter_index += 1;
+ }
+ }
+
+ if gpus.is_empty() {
+ tracing::warn!("No GPU adapters found via DXGI enumeration");
+ } else {
+ tracing::info!("Enumerated {} GPU adapter(s)", gpus.len());
+ }
+
+ gpus
+}
+
+fn select_best_gpu(gpus: &[GpuInfo]) -> Option<GpuInfo> {
+ if gpus.is_empty() {
+ return None;
+ }
+
+ let hardware_gpus: Vec<&GpuInfo> = gpus.iter().filter(|g| !g.is_software_adapter).collect();
+
+ if hardware_gpus.is_empty() {
+ tracing::warn!("No hardware GPUs found, falling back to software adapter");
+ return gpus.first().cloned();
+ }
+
+ let discrete_gpus: Vec<&GpuInfo> = hardware_gpus
+ .iter()
+ .filter(|g| {
+ matches!(
+ g.vendor,
+ GpuVendor::Nvidia | GpuVendor::Amd | GpuVendor::Qualcomm | GpuVendor::Arm
+ )
})
+ .copied()
+ .collect();
+
+ if !discrete_gpus.is_empty() {
+ let best = discrete_gpus
+ .iter()
+ .max_by_key(|g| g.dedicated_video_memory)
+ .unwrap();
+
+ if discrete_gpus.len() > 1 || hardware_gpus.len() > 1 {
+ tracing::info!(
+ "Multi-GPU system detected ({} GPUs). Selected {} with {} MB VRAM for encoding.",
+ gpus.len(),
+ best.description,
+ best.dedicated_video_memory / (1024 * 1024)
+ );
+ }
+
+ return Some((*best).clone());
}
+
+ let best = hardware_gpus
+ .iter()
+ .max_by_key(|g| g.dedicated_video_memory)
+ .unwrap();
+
+ Some((*best).clone())
}
struct D3D11Resources {
@@ -189,12 +317,19 @@ fn get_gpu_info(device: &ID3D11Device) -> Result<GpuInfo, ConvertError> {
.collect::<Vec<_>>(),
);
+ let is_software = desc.VendorId == 0x1414
+ && (description.contains("Basic Render")
+ || description.contains("WARP")
+ || description.contains("Microsoft Basic"));
+
Ok(GpuInfo {
vendor: GpuVendor::from_id(desc.VendorId),
vendor_id: desc.VendorId,
device_id: desc.DeviceId,
description,
dedicated_video_memory: desc.DedicatedVideoMemory as u64,
+ adapter_index: 0,
+ is_software_adapter: is_software,
})
}
}
diff --git a/crates/recording/src/diagnostics.rs b/crates/recording/src/diagnostics.rs
index b304d95d7..3822ca12a 100644
--- a/crates/recording/src/diagnostics.rs
+++ b/crates/recording/src/diagnostics.rs
@@ -20,6 +20,28 @@ mod windows_impl {
pub vendor: String,
pub description: String,
pub dedicated_video_memory_mb: f64,
+ pub adapter_index: u32,
+ pub is_software_adapter: bool,
+ pub is_basic_render_driver: bool,
+ pub supports_hardware_encoding: bool,
+ }
+
+ #[derive(Debug, Clone, Serialize, Type)]
+ #[serde(rename_all = "camelCase")]
+ pub struct AllGpusInfo {
+ pub gpus: Vec<GpuInfoDiag>,
+ pub primary_gpu_index: Option<u32>,
+ pub is_multi_gpu_system: bool,
+ pub has_discrete_gpu: bool,
+ }
+
+ #[derive(Debug, Clone, Serialize, Type)]
+ #[serde(rename_all = "camelCase")]
+ pub struct RenderingStatus {
+ pub is_using_software_rendering: bool,
+ pub is_using_basic_render_driver: bool,
+ pub hardware_encoding_available: bool,
+ pub warning_message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Type)]
@@ -27,6 +49,8 @@ mod windows_impl {
pub struct SystemDiagnostics {
pub windows_version: Option<WindowsVersionInfo>,
pub gpu_info: Option<GpuInfoDiag>,
+ pub all_gpus: Option<AllGpusInfo>,
+ pub rendering_status: RenderingStatus,
pub available_encoders: Vec<String>,
pub graphics_capture_supported: bool,
pub d3d11_video_processor_available: bool,
@@ -35,6 +59,8 @@ mod windows_impl {
pub fn collect_diagnostics() -> SystemDiagnostics {
let windows_version = get_windows_version_info();
let gpu_info = get_gpu_info();
+ let all_gpus = get_all_gpus_info();
+ let rendering_status = get_rendering_status(&gpu_info);
let available_encoders = get_available_encoders();
let graphics_capture_supported = check_graphics_capture_support();
let d3d11_video_processor_available = check_d3d11_video_processor();
@@ -44,7 +70,29 @@ mod windows_impl {
tracing::info!(" Windows: {}", ver.display_name);
}
if let Some(ref gpu) = gpu_info {
- tracing::info!(" GPU: {} ({})", gpu.description, gpu.vendor);
+ tracing::info!(
+ " Primary GPU: {} ({}) - Software: {}, BasicRender: {}",
+ gpu.description,
+ gpu.vendor,
+ gpu.is_software_adapter,
+ gpu.is_basic_render_driver
+ );
+ }
+ if let Some(ref all) = all_gpus {
+ tracing::info!(
+ " GPU Count: {}, Multi-GPU: {}, Has Discrete: {}",
+ all.gpus.len(),
+ all.is_multi_gpu_system,
+ all.has_discrete_gpu
+ );
+ }
+ tracing::info!(
+ " Rendering: SoftwareRendering={}, HardwareEncoding={}",
+ rendering_status.is_using_software_rendering,
+ rendering_status.hardware_encoding_available
+ );
+ if let Some(ref warning) = rendering_status.warning_message {
+ tracing::warn!(" Warning: {}", warning);
}
tracing::info!(" Encoders: {:?}", available_encoders);
tracing::info!(" Graphics Capture: {}", graphics_capture_supported);
@@ -56,6 +104,8 @@ mod windows_impl {
SystemDiagnostics {
windows_version,
gpu_info,
+ all_gpus,
+ rendering_status,
available_encoders,
graphics_capture_supported,
d3d11_video_processor_available,
@@ -73,14 +123,101 @@ mod windows_impl {
})
}
- fn get_gpu_info() -> Option<GpuInfoDiag> {
- cap_frame_converter::detect_primary_gpu().map(|info| GpuInfoDiag {
+ fn gpu_info_to_diag(info: &cap_frame_converter::GpuInfo) -> GpuInfoDiag {
+ GpuInfoDiag {
vendor: info.vendor_name().to_string(),
description: info.description.clone(),
dedicated_video_memory_mb: (info.dedicated_video_memory / (1024 * 1024)) as f64,
+ adapter_index: info.adapter_index,
+ is_software_adapter: info.is_software_adapter,
+ is_basic_render_driver: info.is_basic_render_driver(),
+ supports_hardware_encoding: info.supports_hardware_encoding(),
+ }
+ }
+
+ fn get_gpu_info() -> Option<GpuInfoDiag> {
+ cap_frame_converter::detect_primary_gpu().map(gpu_info_to_diag)
+ }
+
+ fn get_all_gpus_info() -> Option<AllGpusInfo> {
+ let all_gpus = cap_frame_converter::get_all_gpus();
+
+ if all_gpus.is_empty() {
+ return None;
+ }
+
+ let gpus: Vec<GpuInfoDiag> = all_gpus.iter().map(gpu_info_to_diag).collect();
+
+ let primary_gpu = cap_frame_converter::detect_primary_gpu();
+ let primary_gpu_index = primary_gpu.and_then(|primary| {
+ all_gpus
+ .iter()
+ .position(|g| g.adapter_index == primary.adapter_index)
+ .map(|idx| idx as u32)
+ });
+
+ let has_discrete = all_gpus.iter().any(|g| {
+ matches!(
+ g.vendor,
+ cap_frame_converter::GpuVendor::Nvidia
+ | cap_frame_converter::GpuVendor::Amd
+ | cap_frame_converter::GpuVendor::Qualcomm
+ | cap_frame_converter::GpuVendor::Arm
+ ) && !g.is_software_adapter
+ });
+
+ Some(AllGpusInfo {
+ is_multi_gpu_system: gpus.len() > 1,
+ has_discrete_gpu: has_discrete,
+ primary_gpu_index,
+ gpus,
})
}
+ fn get_rendering_status(gpu_info: &Option<GpuInfoDiag>) -> RenderingStatus {
+ let (is_software, is_basic_render, hw_encoding, warning) = match gpu_info {
+ Some(gpu) => {
+ let is_basic = gpu.is_basic_render_driver;
+ let is_software = gpu.is_software_adapter;
+ let hw_available = gpu.supports_hardware_encoding;
+
+ let warning = if is_basic {
+ Some(
+ "Microsoft Basic Render Driver detected. This may indicate missing GPU drivers or a remote desktop session. Recording will use software encoding which may impact performance."
+ .to_string(),
+ )
+ } else if is_software {
+ Some(
+ "Software rendering is active. Hardware GPU acceleration is not available. Update your graphics drivers for better performance."
+ .to_string(),
+ )
+ } else if !hw_available {
+ Some(
+ "Hardware encoding may not be available on this GPU. Software encoding will be used as a fallback."
+ .to_string(),
+ )
+ } else {
+ None
+ };
+
+ (is_software, is_basic, hw_available, warning)
+ }
+ None => (
+ true,
+ false,
+ false,
+ Some("No GPU detected. Recording will use software encoding.".to_string()),
+ ),
+ };
+
+ RenderingStatus {
+ is_using_software_rendering: is_software,
+ is_using_basic_render_driver: is_basic_render,
+ hardware_encoding_available: hw_encoding,
+ warning_message: warning,
+ }
+ }
+
fn get_available_encoders() -> Vec<String> {
let candidates = [
"h264_nvenc",
diff --git a/crates/recording/src/output_pipeline/win.rs b/crates/recording/src/output_pipeline/win.rs
index 6312f370b..459ea13e7 100644
--- a/crates/recording/src/output_pipeline/win.rs
+++ b/crates/recording/src/output_pipeline/win.rs
@@ -867,18 +867,54 @@ impl AudioMuxer for WindowsCameraMuxer {
fn convert_uyvy_to_yuyv(src: &[u8], width: u32, height: u32) -> Vec<u8> {
let total_bytes = (width * height * 2) as usize;
+ let src_len = src.len().min(total_bytes);
let mut dst = vec![0u8; total_bytes];
- for i in (0..src.len().min(total_bytes)).step_by(4) {
- if i + 3 < src.len() && i + 3 < total_bytes {
+ #[cfg(target_arch = "x86_64")]
+ {
+ if is_x86_feature_detected!("ssse3") {
+ unsafe {
+ convert_uyvy_to_yuyv_ssse3(src, &mut dst, src_len);
+ }
+ return dst;
+ }
+ }
+
+ convert_uyvy_to_yuyv_scalar(src, &mut dst, src_len);
+ dst
+}
+
+#[cfg(target_arch = "x86_64")]
+#[target_feature(enable = "ssse3")]
+unsafe fn convert_uyvy_to_yuyv_ssse3(src: &[u8], dst: &mut [u8], len: usize) {
+ use std::arch::x86_64::*;
+
+ unsafe {
+ let shuffle_mask = _mm_setr_epi8(1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14);
+
+ let mut i = 0;
+ let simd_end = len & !15;
+
+ while i < simd_end {
+ let chunk = _mm_loadu_si128(src.as_ptr().add(i) as *const __m128i);
+ let shuffled = _mm_shuffle_epi8(chunk, shuffle_mask);
+ _mm_storeu_si128(dst.as_mut_ptr().add(i) as *mut __m128i, shuffled);
+ i += 16;
+ }
+
+ convert_uyvy_to_yuyv_scalar(&src[i..], &mut dst[i..], len - i);
+ }
+}
+
+fn convert_uyvy_to_yuyv_scalar(src: &[u8], dst: &mut [u8], len: usize) {
+ for i in (0..len).step_by(4) {
+ if i + 3 < src.len() && i + 3 < dst.len() {
dst[i] = src[i + 1];
dst[i + 1] = src[i];
dst[i + 2] = src[i + 3];
dst[i + 3] = src[i + 2];
}
}
-
- dst
}
pub fn camera_frame_to_ffmpeg(frame: &NativeCameraFrame) -> anyhow::Result<ffmpeg::frame::Video> {