feat: add custom audio sources

- Add capture_apps list of AudioSourceConfig (application, deviceOutput
  or deviceInput) to AudioSettings, serialized in the settings JSON
- Add IPC commands getAudioDevices, addAudioSource, removeAudioSource
  and updateAudioSource
- obs_context builds wasapi sources for the microphone and configured
  apps alongside the game-capture source
- Settings.vue gains an audio sources tab with device dropdowns and
  per-source volume
- getAudioDevices temporarily returns hardcoded defaults while the
  WASAPI enumeration crash is investigated; crash marker files around
  IPC and native call sites are part of that investigation
This commit is contained in:
vhaudiquet committed 2026-11-12 23:17:26 +01:00
1 parent 7468bdf5de
commit 4f9f84446d
13 files changed
+1711 -69

No files matched your search

+4 -1
View File
@@ -8,7 +8,10 @@ mod presets;
mod settings;
pub use persistence::{load_config, save_config, ConfigPersistence};
pub use presets::{AmfQuality, AudioSettings, EncoderPreset, QualityLevel};
pub use presets::{
AmfQuality, AudioDeviceInfo, AudioDeviceType, AudioSettings, AudioSourceConfig,
AudioSourceType, EncoderPreset, QualityLevel,
};
pub use settings::{OutputSettings, Settings, VideoSettings};
use std::path::PathBuf;
+123 -2
View File
@@ -159,17 +159,33 @@ pub struct AudioSettings {
#[serde(default = "default_channels")]
pub channels: u32,
/// Capture game audio.
/// Capture game audio (desktop audio).
#[serde(default = "preset_default_true")]
pub capture_game: bool,
/// Game audio volume (0-100).
#[serde(default = "default_volume")]
pub game_volume: u32,
/// Capture microphone.
#[serde(default)]
pub capture_mic: bool,
/// Microphone device name (if capture_mic is true).
/// Microphone device ID (if capture_mic is true).
#[serde(default)]
pub mic_device: Option<String>,
/// Microphone volume (0-100).
#[serde(default = "default_volume")]
pub mic_volume: u32,
/// Capture application audio (e.g., Discord, Spotify).
#[serde(default)]
pub capture_apps: Vec<AudioSourceConfig>,
/// Application audio volume (0-100) - global for all app sources.
#[serde(default = "default_volume")]
pub apps_volume: u32,
}
impl Default for AudioSettings {
@@ -180,12 +196,117 @@ impl Default for AudioSettings {
sample_rate: default_sample_rate(),
channels: default_channels(),
capture_game: true,
game_volume: default_volume(),
capture_mic: false,
mic_device: None,
mic_volume: default_volume(),
capture_apps: Vec::new(),
apps_volume: default_volume(),
}
}
}
fn default_volume() -> u32 {
100
}
/// Configuration for an individual audio source (e.g., Discord, Spotify).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct AudioSourceConfig {
/// Unique identifier for this source.
#[serde(default)]
pub id: String,
/// Display name for the source.
pub name: String,
/// Type of audio source.
#[serde(rename = "type")]
pub source_type: AudioSourceType,
/// The device ID or process name to capture.
pub device: String,
/// Whether this source is enabled.
#[serde(default = "preset_default_true")]
pub enabled: bool,
/// Individual volume for this source (0-100), if None uses global apps_volume.
#[serde(skip_serializing_if = "Option::is_none")]
pub volume: Option<u32>,
}
impl AudioSourceConfig {
/// Create a new application audio source configuration.
pub fn new(name: &str, source_type: AudioSourceType, device: &str) -> Self {
Self {
id: uuid::Uuid::new_v4().to_string(),
name: name.to_string(),
source_type,
device: device.to_string(),
enabled: true,
volume: None,
}
}
/// Create a Discord audio source.
pub fn discord() -> Self {
Self::new(
"Discord",
AudioSourceType::Application,
"Discord.exe",
)
}
/// Create a Spotify audio source.
pub fn spotify() -> Self {
Self::new(
"Spotify",
AudioSourceType::Application,
"Spotify.exe",
)
}
}
/// Type of audio source.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
#[serde(rename_all = "lowercase")]
pub enum AudioSourceType {
/// Application audio (captures specific process on Windows via WASAPI loopback).
#[default]
Application,
/// Audio output device (captures all audio from a specific output device).
DeviceOutput,
/// Audio input device (microphone, line-in, etc.).
DeviceInput,
}
/// Information about an available audio device.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct AudioDeviceInfo {
/// Device ID (used for device selection).
pub id: String,
/// Display name of the device.
pub name: String,
/// Type of the device.
pub device_type: AudioDeviceType,
/// Whether this is the default device for its type.
pub is_default: bool,
}
/// Type of audio device.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum AudioDeviceType {
/// Input device (microphone, line-in).
Input,
/// Output device (speakers, headphones).
Output,
}
fn default_audio_bitrate() -> u32 {
192
}