record-daemon: obs-context refactoring, gpu detection code
record-daemon / Build, check and test (push) Failing after 48s

This commit is contained in:
vhaudiquet committed 2026-03-21 18:54:01 +01:00
1 parent 5d4fecc108
commit 8e885ffc64
5 files changed
+262 -141

No files matched your search

+180 -13
View File
@@ -294,11 +294,9 @@ impl EncoderCapability {
///
/// This function checks the system for available GPU encoders.
pub fn detect_hardware_encoders() -> Vec<EncoderCapability> {
use std::io::Write;
use tracing::info;
info!("[ENCODER_DETECT] Starting hardware encoder detection...");
std::io::stderr().flush().ok();
let mut capabilities = Vec::new();
@@ -322,7 +320,7 @@ pub fn detect_hardware_encoders() -> Vec<EncoderCapability> {
// On Windows, check for NVIDIA first
// Try to load nvenc DLL
info!("[ENCODER_DETECT] Checking for NVENC...");
std::io::stderr().flush().ok();
if is_nvenc_available() {
info!("[ENCODER_DETECT] NVENC available");
capabilities.push(EncoderCapability::Nvenc);
@@ -332,7 +330,7 @@ pub fn detect_hardware_encoders() -> Vec<EncoderCapability> {
// Check for AMD AMF
info!("[ENCODER_DETECT] Checking for AMF...");
std::io::stderr().flush().ok();
if is_amf_available() {
info!("[ENCODER_DETECT] AMF available");
capabilities.push(EncoderCapability::Amf);
@@ -342,7 +340,7 @@ pub fn detect_hardware_encoders() -> Vec<EncoderCapability> {
// Check for Intel QuickSync
info!("[ENCODER_DETECT] Checking for QuickSync...");
std::io::stderr().flush().ok();
if is_quicksync_available() {
info!("[ENCODER_DETECT] QuickSync available");
capabilities.push(EncoderCapability::QuickSync);
@@ -356,31 +354,200 @@ pub fn detect_hardware_encoders() -> Vec<EncoderCapability> {
capabilities.push(EncoderCapability::Software);
info!("[ENCODER_DETECT] Detected encoders: {:?}", capabilities);
std::io::stderr().flush().ok();
capabilities
}
/// GPU vendor type for encoder detection.
#[cfg(target_os = "windows")]
#[derive(Debug, Clone, Copy, PartialEq)]
enum GpuVendor {
Nvidia,
Amd,
Intel,
}
/// Detect GPU vendors by querying Windows registry.
/// This is more reliable than checking for specific DLL paths.
#[cfg(target_os = "windows")]
fn detect_gpu_vendors() -> Vec<GpuVendor> {
use tracing::info;
use winreg::enums::HKEY_LOCAL_MACHINE;
use winreg::RegKey;
let mut vendors = Vec::new();
// Display adapter class GUID in Windows registry
const DISPLAY_ADAPTER_CLASS: &str =
r"SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}";
info!("[ENCODER_DETECT] Querying Windows registry for GPU vendors...");
// Open the display adapter class key
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let class_key = match hklm.open_subkey(DISPLAY_ADAPTER_CLASS) {
Ok(key) => key,
Err(e) => {
info!(
"[ENCODER_DETECT] Failed to open display adapter registry key: {}",
e
);
return vendors;
}
};
// Enumerate subkeys (each subkey is a display adapter)
for subkey_name in class_key.enum_keys().filter_map(|k| k.ok()) {
if let Ok(adapter_key) = class_key.open_subkey(&subkey_name) {
// Read ProviderName
if let Ok(provider) = adapter_key.get_value::<String, _>("ProviderName") {
info!("[ENCODER_DETECT] Found GPU provider: {}", provider);
let provider_lower = provider.to_lowercase();
if provider_lower.contains("nvidia") && !vendors.contains(&GpuVendor::Nvidia) {
vendors.push(GpuVendor::Nvidia);
} else if (provider_lower.contains("amd")
|| provider_lower.contains("advanced micro devices")
|| provider_lower.contains("radeon"))
&& !vendors.contains(&GpuVendor::Amd)
{
vendors.push(GpuVendor::Amd);
} else if provider_lower.contains("intel") && !vendors.contains(&GpuVendor::Intel) {
vendors.push(GpuVendor::Intel);
}
}
}
}
info!("[ENCODER_DETECT] Detected GPU vendors: {:?}", vendors);
vendors
}
/// Check if NVIDIA NVENC is available.
#[cfg(target_os = "windows")]
fn is_nvenc_available() -> bool {
// Check for NVENC DLL
std::path::Path::new("C:\\Windows\\System32\\nvEncMFTH264.dll").exists()
|| std::path::Path::new("C:\\Windows\\System32\\nvEncMFTH265.dll").exists()
use tracing::info;
use winreg::enums::{HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE};
use winreg::RegKey;
// First check if NVIDIA GPU is present via registry
let vendors = detect_gpu_vendors();
if !vendors.contains(&GpuVendor::Nvidia) {
info!("[ENCODER_DETECT] No NVIDIA GPU detected via registry");
return false;
}
// NVIDIA GPU found, now check for NVENC support
// NVENC is available on most modern NVIDIA GPUs (GTX 600+ and all RTX cards)
// We can verify by checking if nvEncAPI is loadable or by checking registry
// Check for NVENC capability in registry (NVIDIA stores encoder info here)
const NVENC_REGISTRY_PATH: &str = r"SOFTWARE\NVIDIA Corporation\Global\NvEnc";
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
// Try HKCU first
if hkcu.open_subkey(NVENC_REGISTRY_PATH).is_ok() {
info!("[ENCODER_DETECT] NVENC registry key found (HKCU)");
return true;
}
// Try HKLM
if hklm.open_subkey(NVENC_REGISTRY_PATH).is_ok() {
info!("[ENCODER_DETECT] NVENC registry key found (HKLM)");
return true;
}
// If NVIDIA GPU is present, assume NVENC is available
// Modern NVIDIA GPUs (GTX 600 series and newer) all have NVENC
// This is a reasonable fallback since the registry check might not work on all systems
info!("[ENCODER_DETECT] NVIDIA GPU detected, assuming NVENC available");
true
}
/// Check if AMD AMF is available.
#[cfg(target_os = "windows")]
fn is_amf_available() -> bool {
// Check for AMF runtime
std::path::Path::new("C:\\Windows\\System32\\amdocl64.dll").exists()
use tracing::info;
use winreg::enums::HKEY_LOCAL_MACHINE;
use winreg::RegKey;
// Check if AMD GPU is present via registry
let vendors = detect_gpu_vendors();
if !vendors.contains(&GpuVendor::Amd) {
info!("[ENCODER_DETECT] No AMD GPU detected via registry");
return false;
}
// AMD GPU found, check for AMF runtime
// AMF is available on modern AMD GPUs (RX 400+ and some older cards)
// Check for AMF runtime in registry
const AMF_REGISTRY_PATH: &str = r"SOFTWARE\AMD\AMF";
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
if hklm.open_subkey(AMF_REGISTRY_PATH).is_ok() {
info!("[ENCODER_DETECT] AMF registry key found");
return true;
}
// Fallback: check for amdocl64.dll or amfrt64.dll in system
let system32 = std::env::var("SystemRoot").unwrap_or_else(|_| "C:\\Windows".to_string());
let amdocl_path = format!("{}\\System32\\amdocl64.dll", system32);
let amfrt_path = format!("{}\\System32\\amfrt64.dll", system32);
if std::path::Path::new(&amdocl_path).exists() || std::path::Path::new(&amfrt_path).exists() {
info!("[ENCODER_DETECT] AMF DLL found");
return true;
}
// If AMD GPU is present, assume AMF is available on modern cards
info!("[ENCODER_DETECT] AMD GPU detected, assuming AMF available");
true
}
/// Check if Intel QuickSync is available.
#[cfg(target_os = "windows")]
fn is_quicksync_available() -> bool {
// Check for Intel Media SDK
std::path::Path::new("C:\\Windows\\System32\\mfx64.dll").exists()
use tracing::info;
// Check if Intel GPU is present via registry
let vendors = detect_gpu_vendors();
if !vendors.contains(&GpuVendor::Intel) {
info!("[ENCODER_DETECT] No Intel GPU detected via registry");
return false;
}
// Intel GPU found, check for QuickSync (Intel Media SDK / oneVPL)
// QuickSync is available on Intel CPUs with integrated graphics (Sandy Bridge and newer)
// Check for Intel Media SDK or oneVPL
let system32 = std::env::var("SystemRoot").unwrap_or_else(|_| "C:\\Windows".to_string());
let mfx_path = format!("{}\\System32\\mfx64.dll", system32);
let vpl_path = format!("{}\\System32\\libmfx64.dll", system32);
if std::path::Path::new(&mfx_path).exists() || std::path::Path::new(&vpl_path).exists() {
info!("[ENCODER_DETECT] Intel Media SDK DLL found");
return true;
}
// Check for oneVPL runtime
const VPL_REGISTRY_PATH: &str = r"SOFTWARE\Intel\oneVPL";
use winreg::enums::HKEY_LOCAL_MACHINE;
use winreg::RegKey;
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
if hklm.open_subkey(VPL_REGISTRY_PATH).is_ok() {
info!("[ENCODER_DETECT] oneVPL registry key found");
return true;
}
// If Intel GPU is present, assume QuickSync might be available
// Note: Not all Intel GPUs have QuickSync (some low-end chips don't)
info!("[ENCODER_DETECT] Intel GPU detected, assuming QuickSync available");
true
}
/// Get the best available encoder capability.