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:
1 parent
7468bdf5de
commit
4f9f84446d
13 files changed
+1711
-69
No files matched your search
@@ -934,10 +934,41 @@ impl ObsContext {
|
||||
/// Set up audio capture for game audio (Windows only).
|
||||
#[cfg(target_os = "windows")]
|
||||
fn setup_audio_capture(&mut self) -> Result<()> {
|
||||
info!("[AUDIO_CAPTURE] Setting up multi-source audio capture...");
|
||||
|
||||
// Clone necessary data to avoid borrow issues
|
||||
let capture_game = self.audio_settings.capture_game;
|
||||
let capture_mic = self.audio_settings.capture_mic;
|
||||
let capture_apps = self.audio_settings.capture_apps.clone();
|
||||
|
||||
// 1. Game audio capture (desktop audio via WASAPI process output)
|
||||
if capture_game {
|
||||
self.setup_game_audio_capture_internal()?;
|
||||
}
|
||||
|
||||
// 2. Microphone capture
|
||||
if capture_mic {
|
||||
self.setup_microphone_capture_internal()?;
|
||||
}
|
||||
|
||||
// 3. Application audio captures (Discord, Spotify, etc.)
|
||||
for app_source in &capture_apps {
|
||||
if app_source.enabled {
|
||||
self.setup_app_audio_capture_internal(app_source)?;
|
||||
}
|
||||
}
|
||||
|
||||
info!("[AUDIO_CAPTURE] All audio sources configured successfully");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set up game audio capture via WASAPI process output (Windows).
|
||||
#[cfg(target_os = "windows")]
|
||||
fn setup_game_audio_capture_internal(&mut self) -> Result<()> {
|
||||
use libobs_wrapper::data::ObsData;
|
||||
use libobs_wrapper::utils::SourceInfo;
|
||||
|
||||
info!("[AUDIO_CAPTURE] Setting up WASAPI audio capture...");
|
||||
info!("[AUDIO_CAPTURE] Setting up game audio capture...");
|
||||
|
||||
let context = self.context.as_mut().ok_or_else(|| {
|
||||
error!("[AUDIO_CAPTURE] OBS not initialized");
|
||||
@@ -955,19 +986,18 @@ impl ObsContext {
|
||||
let audio_settings_data = ObsData::from_json(settings_json, context.runtime().clone())
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] Failed to create audio settings from JSON: {:?}",
|
||||
"[AUDIO_CAPTURE] Failed to create game audio settings from JSON: {:?}",
|
||||
e
|
||||
);
|
||||
RecordingError::StartError(format!(
|
||||
"Failed to create audio settings from JSON: {:?}",
|
||||
"Failed to create game audio settings from JSON: {:?}",
|
||||
e
|
||||
))
|
||||
})?;
|
||||
|
||||
info!("[AUDIO_CAPTURE] Audio settings configured for League of Legends");
|
||||
info!("[AUDIO_CAPTURE] Game audio settings configured for League of Legends");
|
||||
|
||||
// Configure WASAPI process output capture for game audio
|
||||
// This captures the audio output from a specific process (the game)
|
||||
let source_info = SourceInfo::new(
|
||||
"wasapi_process_output_capture",
|
||||
"game_audio",
|
||||
@@ -975,44 +1005,249 @@ impl ObsContext {
|
||||
None,
|
||||
);
|
||||
|
||||
info!("[AUDIO_CAPTURE] Creating WASAPI process output capture source...");
|
||||
info!("[AUDIO_CAPTURE] Creating WASAPI process output capture source for game...");
|
||||
|
||||
let runtime = context.runtime().clone();
|
||||
let audio_source_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
libobs_wrapper::sources::ObsSourceRef::new_from_info(
|
||||
source_info,
|
||||
context.runtime().clone(),
|
||||
)
|
||||
libobs_wrapper::sources::ObsSourceRef::new_from_info(source_info, runtime)
|
||||
}));
|
||||
|
||||
let _audio_source = match audio_source_result {
|
||||
Ok(Ok(s)) => {
|
||||
info!("[AUDIO_CAPTURE] WASAPI audio source created");
|
||||
s
|
||||
match audio_source_result {
|
||||
Ok(Ok(_s)) => {
|
||||
info!("[AUDIO_CAPTURE] Game audio source created successfully");
|
||||
// TODO: Apply volume from self.audio_settings.game_volume
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
error!("[AUDIO_CAPTURE] Failed to create audio source: {:?}", e);
|
||||
error!("[AUDIO_CAPTURE] Failed to create game audio source: {:?}", e);
|
||||
return Err(RecordingError::StartError(format!(
|
||||
"Failed to create audio source: {:?}",
|
||||
"Failed to create game audio source: {:?}",
|
||||
e
|
||||
))
|
||||
.into());
|
||||
}
|
||||
Err(panic_info) => {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] PANIC creating audio source: {:?}",
|
||||
"[AUDIO_CAPTURE] PANIC creating game audio source: {:?}",
|
||||
panic_info
|
||||
);
|
||||
eprintln!(
|
||||
"[AUDIO_CAPTURE] PANIC creating audio source: {:?}",
|
||||
return Err(RecordingError::StartError(
|
||||
"Panic creating game audio source".to_string(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set up microphone capture via WASAPI input (Windows).
|
||||
#[cfg(target_os = "windows")]
|
||||
fn setup_microphone_capture_internal(&mut self) -> Result<()> {
|
||||
use libobs_wrapper::data::ObsData;
|
||||
use libobs_wrapper::utils::SourceInfo;
|
||||
|
||||
info!("[AUDIO_CAPTURE] Setting up microphone capture...");
|
||||
|
||||
let context = self.context.as_mut().ok_or_else(|| {
|
||||
error!("[AUDIO_CAPTURE] OBS not initialized");
|
||||
RecordingError::ObsInitError("OBS not initialized".to_string())
|
||||
})?;
|
||||
|
||||
let device_id = self
|
||||
.audio_settings
|
||||
.mic_device
|
||||
.as_deref()
|
||||
.unwrap_or("default");
|
||||
|
||||
info!("[AUDIO_CAPTURE] Using microphone device: {}", device_id);
|
||||
|
||||
// Create microphone settings
|
||||
// Use default device if no specific device is specified
|
||||
let settings_json = if device_id == "default" {
|
||||
r#"{
|
||||
"device_id": "default"
|
||||
}"#.to_string()
|
||||
} else {
|
||||
format!(
|
||||
r#"{{
|
||||
"device_id": "{}"
|
||||
}}"#,
|
||||
device_id
|
||||
)
|
||||
};
|
||||
|
||||
let mic_settings_data = ObsData::from_json(&settings_json, context.runtime().clone())
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] Failed to create microphone settings from JSON: {:?}",
|
||||
e
|
||||
);
|
||||
RecordingError::StartError(format!(
|
||||
"Failed to create microphone settings from JSON: {:?}",
|
||||
e
|
||||
))
|
||||
})?;
|
||||
|
||||
// Configure WASAPI input capture for microphone
|
||||
let source_info = SourceInfo::new(
|
||||
"wasapi_input_capture",
|
||||
"microphone",
|
||||
Some(mic_settings_data),
|
||||
None,
|
||||
);
|
||||
|
||||
info!("[AUDIO_CAPTURE] Creating WASAPI input capture source for microphone...");
|
||||
|
||||
let runtime = context.runtime().clone();
|
||||
let mic_source_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
libobs_wrapper::sources::ObsSourceRef::new_from_info(source_info, runtime)
|
||||
}));
|
||||
|
||||
match mic_source_result {
|
||||
Ok(Ok(_s)) => {
|
||||
info!("[AUDIO_CAPTURE] Microphone source created successfully");
|
||||
// TODO: Apply volume from self.audio_settings.mic_volume
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
error!("[AUDIO_CAPTURE] Failed to create microphone source: {:?}", e);
|
||||
// Don't fail the whole recording if mic isn't available, just warn
|
||||
warn!(
|
||||
"[AUDIO_CAPTURE] Microphone capture unavailable, continuing without mic: {:?}",
|
||||
e
|
||||
);
|
||||
}
|
||||
Err(panic_info) => {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] PANIC creating microphone source: {:?}",
|
||||
panic_info
|
||||
);
|
||||
return Err(
|
||||
RecordingError::StartError("Panic creating audio source".to_string()).into(),
|
||||
);
|
||||
warn!("[AUDIO_CAPTURE] Microphone capture failed due to panic, continuing without mic");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set up application audio capture (Discord, Spotify, etc.) via WASAPI loopback (Windows).
|
||||
#[cfg(target_os = "windows")]
|
||||
fn setup_app_audio_capture_internal(
|
||||
&mut self,
|
||||
app_source: &crate::config::AudioSourceConfig,
|
||||
) -> Result<()> {
|
||||
use libobs_wrapper::data::ObsData;
|
||||
use libobs_wrapper::utils::SourceInfo;
|
||||
|
||||
info!(
|
||||
"[AUDIO_CAPTURE] Setting up application audio capture for: {}",
|
||||
app_source.name
|
||||
);
|
||||
|
||||
let context = self.context.as_mut().ok_or_else(|| {
|
||||
error!("[AUDIO_CAPTURE] OBS not initialized");
|
||||
RecordingError::ObsInitError("OBS not initialized".to_string())
|
||||
})?;
|
||||
|
||||
// Build settings based on source type
|
||||
let settings_json = match app_source.source_type {
|
||||
crate::config::AudioSourceType::Application => {
|
||||
// Capture audio from a specific application by executable name
|
||||
format!(
|
||||
r#"{{
|
||||
"executable": "{}",
|
||||
"priority": 2
|
||||
}}"#,
|
||||
app_source.device
|
||||
)
|
||||
}
|
||||
crate::config::AudioSourceType::DeviceOutput => {
|
||||
// Capture all audio from a specific output device
|
||||
format!(
|
||||
r#"{{
|
||||
"device_id": "{}"
|
||||
}}"#,
|
||||
app_source.device
|
||||
)
|
||||
}
|
||||
crate::config::AudioSourceType::DeviceInput => {
|
||||
// Capture from an input device
|
||||
format!(
|
||||
r#"{{
|
||||
"device_id": "{}"
|
||||
}}"#,
|
||||
app_source.device
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
info!("[AUDIO_CAPTURE] Audio source created successfully");
|
||||
let app_settings_data = ObsData::from_json(&settings_json, context.runtime().clone())
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] Failed to create app audio settings: {:?}",
|
||||
e
|
||||
);
|
||||
RecordingError::StartError(format!(
|
||||
"Failed to create app audio settings for {}: {:?}",
|
||||
app_source.name, e
|
||||
))
|
||||
})?;
|
||||
|
||||
// Determine the source type string for WASAPI
|
||||
let source_type_str = match app_source.source_type {
|
||||
crate::config::AudioSourceType::Application => "wasapi_process_output_capture",
|
||||
crate::config::AudioSourceType::DeviceOutput => "wasapi_output_capture",
|
||||
crate::config::AudioSourceType::DeviceInput => "wasapi_input_capture",
|
||||
};
|
||||
|
||||
// Create a unique source name for this app
|
||||
let source_name = format!("app_audio_{}", app_source.id);
|
||||
|
||||
let source_info = SourceInfo::new(
|
||||
source_type_str,
|
||||
source_name.as_str(),
|
||||
Some(app_settings_data),
|
||||
None,
|
||||
);
|
||||
|
||||
info!(
|
||||
"[AUDIO_CAPTURE] Creating {} source for {}...",
|
||||
source_type_str, app_source.name
|
||||
);
|
||||
|
||||
let runtime = context.runtime().clone();
|
||||
let app_source_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
libobs_wrapper::sources::ObsSourceRef::new_from_info(source_info, runtime)
|
||||
}));
|
||||
|
||||
match app_source_result {
|
||||
Ok(Ok(_s)) => {
|
||||
info!(
|
||||
"[AUDIO_CAPTURE] Application audio source '{}' created successfully",
|
||||
app_source.name
|
||||
);
|
||||
// TODO: Apply volume from app_source.volume or self.audio_settings.apps_volume
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] Failed to create app audio source '{}': {:?}",
|
||||
app_source.name, e
|
||||
);
|
||||
// Don't fail the whole recording if an app source isn't available, just warn
|
||||
warn!(
|
||||
"[AUDIO_CAPTURE] App audio capture for '{}' unavailable: {:?}",
|
||||
app_source.name, e
|
||||
);
|
||||
}
|
||||
Err(panic_info) => {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] PANIC creating app audio source '{}': {:?}",
|
||||
app_source.name, panic_info
|
||||
);
|
||||
warn!(
|
||||
"[AUDIO_CAPTURE] App audio capture for '{}' failed due to panic",
|
||||
app_source.name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1020,6 +1255,7 @@ impl ObsContext {
|
||||
/// Set up audio capture for game audio (Linux only).
|
||||
#[cfg(target_os = "linux")]
|
||||
fn setup_audio_capture(&mut self) -> Result<()> {
|
||||
use libobs_wrapper::data::ObsData;
|
||||
use libobs_wrapper::utils::SourceInfo;
|
||||
|
||||
info!("[AUDIO_CAPTURE] Setting up PulseAudio capture...");
|
||||
@@ -1029,6 +1265,37 @@ impl ObsContext {
|
||||
RecordingError::ObsInitError("OBS not initialized".to_string())
|
||||
})?;
|
||||
|
||||
// 1. Game audio capture (desktop audio via PulseAudio)
|
||||
if self.audio_settings.capture_game {
|
||||
self.setup_game_audio_capture_linux(context)?;
|
||||
}
|
||||
|
||||
// 2. Microphone capture
|
||||
if self.audio_settings.capture_mic {
|
||||
self.setup_microphone_capture_linux(context)?;
|
||||
}
|
||||
|
||||
// 3. Application audio captures (Discord, Spotify, etc.)
|
||||
for app_source in &self.audio_settings.capture_apps {
|
||||
if app_source.enabled {
|
||||
self.setup_app_audio_capture_linux(context, app_source)?;
|
||||
}
|
||||
}
|
||||
|
||||
info!("[AUDIO_CAPTURE] All audio sources configured successfully");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set up game audio capture via PulseAudio (Linux).
|
||||
#[cfg(target_os = "linux")]
|
||||
fn setup_game_audio_capture_linux(
|
||||
&mut self,
|
||||
context: &mut libobs_wrapper::context::ObsContext,
|
||||
) -> Result<()> {
|
||||
use libobs_wrapper::utils::SourceInfo;
|
||||
|
||||
info!("[AUDIO_CAPTURE] Setting up game audio capture (Linux)...");
|
||||
|
||||
// Create audio source settings
|
||||
let audio_settings_data = context.data().map_err(|e| {
|
||||
error!("[AUDIO_CAPTURE] Failed to create audio settings: {:?}", e);
|
||||
@@ -1043,7 +1310,7 @@ impl ObsContext {
|
||||
None,
|
||||
);
|
||||
|
||||
info!("[AUDIO_CAPTURE] Creating PulseAudio capture source...");
|
||||
info!("[AUDIO_CAPTURE] Creating PulseAudio capture source for game...");
|
||||
|
||||
let audio_source_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
libobs_wrapper::sources::ObsSourceRef::new_from_info(
|
||||
@@ -1052,35 +1319,172 @@ impl ObsContext {
|
||||
)
|
||||
}));
|
||||
|
||||
let _audio_source = match audio_source_result {
|
||||
Ok(Ok(s)) => {
|
||||
info!("[AUDIO_CAPTURE] PulseAudio source created");
|
||||
s
|
||||
match audio_source_result {
|
||||
Ok(Ok(_s)) => {
|
||||
info!("[AUDIO_CAPTURE] PulseAudio game audio source created");
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
error!("[AUDIO_CAPTURE] Failed to create audio source: {:?}", e);
|
||||
error!("[AUDIO_CAPTURE] Failed to create game audio source: {:?}", e);
|
||||
return Err(RecordingError::StartError(format!(
|
||||
"Failed to create audio source: {:?}",
|
||||
"Failed to create game audio source: {:?}",
|
||||
e
|
||||
))
|
||||
.into());
|
||||
}
|
||||
Err(panic_info) => {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] PANIC creating audio source: {:?}",
|
||||
"[AUDIO_CAPTURE] PANIC creating game audio source: {:?}",
|
||||
panic_info
|
||||
);
|
||||
eprintln!(
|
||||
"[AUDIO_CAPTURE] PANIC creating audio source: {:?}",
|
||||
panic_info
|
||||
);
|
||||
return Err(
|
||||
RecordingError::StartError("Panic creating audio source".to_string()).into(),
|
||||
);
|
||||
return Err(RecordingError::StartError(
|
||||
"Panic creating game audio source".to_string(),
|
||||
)
|
||||
.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set up microphone capture via PulseAudio (Linux).
|
||||
#[cfg(target_os = "linux")]
|
||||
fn setup_microphone_capture_linux(
|
||||
&mut self,
|
||||
context: &mut libobs_wrapper::context::ObsContext,
|
||||
) -> Result<()> {
|
||||
use libobs_wrapper::data::ObsData;
|
||||
use libobs_wrapper::utils::SourceInfo;
|
||||
|
||||
info!("[AUDIO_CAPTURE] Setting up microphone capture (Linux)...");
|
||||
|
||||
let device_id = self
|
||||
.audio_settings
|
||||
.mic_device
|
||||
.as_deref()
|
||||
.unwrap_or("default");
|
||||
|
||||
info!("[AUDIO_CAPTURE] Using microphone device: {}", device_id);
|
||||
|
||||
// Create microphone settings
|
||||
let settings_json = if device_id == "default" {
|
||||
r#"{"device_id": "default"}"#.to_string()
|
||||
} else {
|
||||
format!(r#"{{"device_id": "{}"}}"#, device_id)
|
||||
};
|
||||
|
||||
info!("[AUDIO_CAPTURE] Audio source created successfully");
|
||||
let mic_settings_data = ObsData::from_json(&settings_json, context.runtime().clone())
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] Failed to create microphone settings: {:?}",
|
||||
e
|
||||
);
|
||||
RecordingError::StartError(format!(
|
||||
"Failed to create microphone settings: {:?}",
|
||||
e
|
||||
))
|
||||
})?;
|
||||
|
||||
let source_info = SourceInfo::new(
|
||||
"pulse_input_capture",
|
||||
"microphone",
|
||||
Some(mic_settings_data),
|
||||
None,
|
||||
);
|
||||
|
||||
let mic_source_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
libobs_wrapper::sources::ObsSourceRef::new_from_info(
|
||||
source_info,
|
||||
context.runtime().clone(),
|
||||
)
|
||||
}));
|
||||
|
||||
match mic_source_result {
|
||||
Ok(Ok(_s)) => {
|
||||
info!("[AUDIO_CAPTURE] Microphone source created successfully (Linux)");
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
warn!(
|
||||
"[AUDIO_CAPTURE] Microphone capture unavailable (Linux): {:?}",
|
||||
e
|
||||
);
|
||||
}
|
||||
Err(panic_info) => {
|
||||
warn!(
|
||||
"[AUDIO_CAPTURE] Microphone capture failed due to panic (Linux): {:?}",
|
||||
panic_info
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set up application audio capture via PulseAudio (Linux).
|
||||
#[cfg(target_os = "linux")]
|
||||
fn setup_app_audio_capture_linux(
|
||||
&mut self,
|
||||
context: &mut libobs_wrapper::context::ObsContext,
|
||||
app_source: &crate::config::AudioSourceConfig,
|
||||
) -> Result<()> {
|
||||
use libobs_wrapper::data::ObsData;
|
||||
use libobs_wrapper::utils::SourceInfo;
|
||||
|
||||
info!(
|
||||
"[AUDIO_CAPTURE] Setting up application audio capture for: {} (Linux)",
|
||||
app_source.name
|
||||
);
|
||||
|
||||
// On Linux, we use PulseAudio application capture
|
||||
let settings_json = format!(r#"{{"app_name": "{}"}}"#, app_source.device);
|
||||
|
||||
let app_settings_data = ObsData::from_json(&settings_json, context.runtime().clone())
|
||||
.map_err(|e| {
|
||||
error!(
|
||||
"[AUDIO_CAPTURE] Failed to create app audio settings: {:?}",
|
||||
e
|
||||
);
|
||||
RecordingError::StartError(format!(
|
||||
"Failed to create app audio settings for {}: {:?}",
|
||||
app_source.name, e
|
||||
))
|
||||
})?;
|
||||
|
||||
let source_name = format!("app_audio_{}", app_source.id);
|
||||
|
||||
let source_info = SourceInfo::new(
|
||||
"pulse_input_capture",
|
||||
&source_name,
|
||||
Some(app_settings_data),
|
||||
None,
|
||||
);
|
||||
|
||||
let app_source_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
libobs_wrapper::sources::ObsSourceRef::new_from_info(
|
||||
source_info,
|
||||
context.runtime().clone(),
|
||||
)
|
||||
}));
|
||||
|
||||
match app_source_result {
|
||||
Ok(Ok(_s)) => {
|
||||
info!(
|
||||
"[AUDIO_CAPTURE] Application audio source '{}' created successfully (Linux)",
|
||||
app_source.name
|
||||
);
|
||||
}
|
||||
Ok(Err(e)) => {
|
||||
warn!(
|
||||
"[AUDIO_CAPTURE] App audio capture for '{}' unavailable (Linux): {:?}",
|
||||
app_source.name, e
|
||||
);
|
||||
}
|
||||
Err(panic_info) => {
|
||||
warn!(
|
||||
"[AUDIO_CAPTURE] App audio capture for '{}' failed due to panic (Linux): {:?}",
|
||||
app_source.name, panic_info
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user