- Audio sources were created but never added to the scene, so mic, game and app audio never reached the output; all sources are now added with their configured volume via obs_source_set_volume - getAudioDevices enumerates real WASAPI devices again instead of returning hardcoded defaults (the crash-isolation bypass) - Recording module split: encoder selection and output building move to their own files; obs_context shrinks from 1556 to 464 lines - Remove unused IPC (recordings/timeline/export commands), the CommandHandler trait, crash marker files, and the stats plumbing that was never wired to the frontend - Deduplicate the LCU reconnect logic into connect_and_listen
113 lines
3.2 KiB
Rust
113 lines
3.2 KiB
Rust
//! Hardware encoder detection.
|
|
//!
|
|
//! Queries GPU vendor info to decide which OBS hardware encoder
|
|
//! (NVENC, AMF, QuickSync) can be used, falling back to x264.
|
|
|
|
/// A video encoder the daemon can drive through OBS.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum EncoderCapability {
|
|
/// NVIDIA NVENC.
|
|
Nvenc,
|
|
/// AMD AMF.
|
|
Amf,
|
|
/// Intel QuickSync.
|
|
QuickSync,
|
|
/// x264 on the CPU. Always available.
|
|
Software,
|
|
}
|
|
|
|
/// All encoders available on this machine.
|
|
pub fn detect_hardware_encoders() -> Vec<EncoderCapability> {
|
|
let mut capabilities = vec![EncoderCapability::Software];
|
|
|
|
#[cfg(target_os = "windows")]
|
|
{
|
|
let vendors = detect_gpu_vendors();
|
|
if vendors.contains(&GpuVendor::Nvidia) {
|
|
capabilities.push(EncoderCapability::Nvenc);
|
|
}
|
|
if vendors.contains(&GpuVendor::Amd) {
|
|
capabilities.push(EncoderCapability::Amf);
|
|
}
|
|
if vendors.contains(&GpuVendor::Intel) {
|
|
capabilities.push(EncoderCapability::QuickSync);
|
|
}
|
|
}
|
|
|
|
capabilities
|
|
}
|
|
|
|
/// The single best encoder for recording, hardware over software.
|
|
pub fn best_available_encoder() -> EncoderCapability {
|
|
detect_hardware_encoders()
|
|
.into_iter()
|
|
.find(|cap| *cap != EncoderCapability::Software)
|
|
.unwrap_or(EncoderCapability::Software)
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
enum GpuVendor {
|
|
Nvidia,
|
|
Amd,
|
|
Intel,
|
|
}
|
|
|
|
/// Detect GPU vendors from the Windows display adapter registry keys.
|
|
#[cfg(target_os = "windows")]
|
|
fn detect_gpu_vendors() -> Vec<GpuVendor> {
|
|
use tracing::info;
|
|
use winreg::enums::HKEY_LOCAL_MACHINE;
|
|
use winreg::RegKey;
|
|
|
|
const DISPLAY_ADAPTER_CLASS: &str =
|
|
r"SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}";
|
|
|
|
let mut vendors = Vec::new();
|
|
|
|
let class_key = match RegKey::predef(HKEY_LOCAL_MACHINE).open_subkey(DISPLAY_ADAPTER_CLASS) {
|
|
Ok(key) => key,
|
|
Err(e) => {
|
|
info!("Cannot read display adapter registry key: {}", e);
|
|
return vendors;
|
|
}
|
|
};
|
|
|
|
for subkey_name in class_key.enum_keys().filter_map(|k| k.ok()) {
|
|
let adapter = match class_key.open_subkey(&subkey_name) {
|
|
Ok(a) => a,
|
|
Err(_) => continue,
|
|
};
|
|
let provider = match adapter.get_value::<String, _>("ProviderName") {
|
|
Ok(p) => p.to_lowercase(),
|
|
Err(_) => continue,
|
|
};
|
|
|
|
if provider.contains("nvidia") && !vendors.contains(&GpuVendor::Nvidia) {
|
|
vendors.push(GpuVendor::Nvidia);
|
|
} else if (provider.contains("amd")
|
|
|| provider.contains("advanced micro devices")
|
|
|| provider.contains("radeon"))
|
|
&& !vendors.contains(&GpuVendor::Amd)
|
|
{
|
|
vendors.push(GpuVendor::Amd);
|
|
} else if provider.contains("intel") && !vendors.contains(&GpuVendor::Intel) {
|
|
vendors.push(GpuVendor::Intel);
|
|
}
|
|
}
|
|
|
|
info!("GPU vendors: {:?}", vendors);
|
|
vendors
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn detects_at_least_software() {
|
|
let capabilities = detect_hardware_encoders();
|
|
assert!(capabilities.contains(&EncoderCapability::Software));
|
|
}
|
|
}
|