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

+68
View File
@@ -54,6 +54,10 @@ pub mod commands {
pub const RESET_SETTINGS: &str = "resetSettings";
pub const GET_STATUS: &str = "getStatus";
pub const GET_ENCODERS: &str = "getEncoders";
pub const GET_AUDIO_DEVICES: &str = "getAudioDevices";
pub const ADD_AUDIO_SOURCE: &str = "addAudioSource";
pub const REMOVE_AUDIO_SOURCE: &str = "removeAudioSource";
pub const UPDATE_AUDIO_SOURCE: &str = "updateAudioSource";
pub const START_RECORDING: &str = "startRecording";
pub const STOP_RECORDING: &str = "stopRecording";
pub const SHUTDOWN: &str = "shutdown";
@@ -554,6 +558,70 @@ pub async fn daemon_shutdown() -> Result<serde_json::Value, String> {
}
}
/// Get available audio devices from the daemon.
#[tauri::command]
pub async fn daemon_get_audio_devices() -> Result<serde_json::Value, String> {
let client = IpcClient::new();
let response = client
.send_command(commands::GET_AUDIO_DEVICES, None)
.await
.map_err(|e| e)?;
if response.success {
Ok(response.data.unwrap_or(serde_json::Value::Null))
} else {
Err(response.error.unwrap_or_else(|| "Unknown error".to_string()))
}
}
/// Add an audio source to the daemon settings.
#[tauri::command]
pub async fn daemon_add_audio_source(source: serde_json::Value) -> Result<serde_json::Value, String> {
let client = IpcClient::new();
let response = client
.send_command(commands::ADD_AUDIO_SOURCE, Some(source))
.await
.map_err(|e| e)?;
if response.success {
Ok(response.data.unwrap_or(serde_json::Value::Null))
} else {
Err(response.error.unwrap_or_else(|| "Unknown error".to_string()))
}
}
/// Remove an audio source from the daemon settings.
#[tauri::command]
pub async fn daemon_remove_audio_source(id: String) -> Result<serde_json::Value, String> {
let client = IpcClient::new();
let response = client
.send_command(commands::REMOVE_AUDIO_SOURCE, Some(serde_json::json!({ "id": id })))
.await
.map_err(|e| e)?;
if response.success {
Ok(response.data.unwrap_or(serde_json::Value::Null))
} else {
Err(response.error.unwrap_or_else(|| "Unknown error".to_string()))
}
}
/// Update an audio source in the daemon settings.
#[tauri::command]
pub async fn daemon_update_audio_source(source: serde_json::Value) -> Result<serde_json::Value, String> {
let client = IpcClient::new();
let response = client
.send_command(commands::UPDATE_AUDIO_SOURCE, Some(source))
.await
.map_err(|e| e)?;
if response.success {
Ok(response.data.unwrap_or(serde_json::Value::Null))
} else {
Err(response.error.unwrap_or_else(|| "Unknown error".to_string()))
}
}
/// Get the daemon log file path.
#[tauri::command]
pub fn daemon_get_log_path() -> Result<String, String> {
+4
View File
@@ -440,6 +440,10 @@ pub fn run() {
daemon_ipc::daemon_update_settings,
daemon_ipc::daemon_reset_settings,
daemon_ipc::daemon_get_encoders,
daemon_ipc::daemon_get_audio_devices,
daemon_ipc::daemon_add_audio_source,
daemon_ipc::daemon_remove_audio_source,
daemon_ipc::daemon_update_audio_source,
daemon_ipc::daemon_start_recording,
daemon_ipc::daemon_stop_recording,
daemon_ipc::daemon_shutdown,
+362 -5
View File
@@ -10,6 +10,9 @@ import type {
X264Preset,
DaemonStatusResponse,
EncodersResponse,
GetAudioDevicesResponse,
AudioSourceConfig,
AudioSourceType,
} from "../types/daemon";
import {
QUALITY_LEVELS,
@@ -40,6 +43,15 @@ const statusPolling = ref<ReturnType<typeof setInterval> | null>(null);
const autostartEnabled = ref(false);
const autostartLoading = ref(false);
// Audio devices state
const audioDevices = ref<GetAudioDevicesResponse>({ input_devices: [], output_devices: [] });
const loadingAudioDevices = ref(false);
// New audio source form state
const newAppSourceType = ref<AudioSourceType>("application");
const newAppName = ref("");
const newAppDevice = ref("");
// Active settings tab
type SettingsTab = "video" | "output" | "audio" | "daemon";
const activeTab = ref<SettingsTab>("video");
@@ -162,6 +174,84 @@ async function resetSettings() {
}
}
// ---------------------------------------------------------------------------
// Audio devices and sources
// ---------------------------------------------------------------------------
async function loadAudioDevices() {
if (!daemonRunning.value) return;
try {
loadingAudioDevices.value = true;
const devices = await invoke<GetAudioDevicesResponse>("daemon_get_audio_devices");
audioDevices.value = devices;
} catch (e) {
console.error("Failed to load audio devices:", e);
} finally {
loadingAudioDevices.value = false;
}
}
async function addAudioSource() {
if (!settings.value || !newAppName.value || !newAppDevice.value) return;
const source: AudioSourceConfig = {
id: crypto.randomUUID(),
name: newAppName.value,
type: newAppSourceType.value,
device: newAppDevice.value,
enabled: true,
volume: null,
};
try {
await invoke("daemon_add_audio_source", { source });
settings.value.audio.capture_apps.push(source);
// Reset form
newAppName.value = "";
newAppDevice.value = "";
newAppSourceType.value = "application";
saveSuccess.value = true;
setTimeout(() => {
saveSuccess.value = false;
}, 2000);
} catch (e) {
error.value = `Failed to add audio source: ${e}`;
}
}
async function removeAudioSource(id: string) {
if (!settings.value) return;
try {
await invoke("daemon_remove_audio_source", { id });
settings.value.audio.capture_apps = settings.value.audio.capture_apps.filter(s => s.id !== id);
saveSuccess.value = true;
setTimeout(() => {
saveSuccess.value = false;
}, 2000);
} catch (e) {
error.value = `Failed to remove audio source: ${e}`;
}
}
function addPresetSource(preset: "discord" | "spotify" | "browser") {
const presets: Record<string, { name: string; device: string; type: AudioSourceType }> = {
discord: { name: "Discord", device: "Discord.exe", type: "application" },
spotify: { name: "Spotify", device: "Spotify.exe", type: "application" },
browser: { name: "Browser", device: "chrome.exe", type: "application" },
};
const p = presets[preset];
newAppName.value = p.name;
newAppDevice.value = p.device;
newAppSourceType.value = p.type;
// Immediately add the source
addAudioSource();
}
// ---------------------------------------------------------------------------
// Daemon control
// ---------------------------------------------------------------------------
@@ -272,6 +362,7 @@ const statusColor = computed(() => {
onMounted(async () => {
await loadSettings();
await checkAutostart();
await loadAudioDevices();
// Poll daemon status every 3 seconds
statusPolling.value = setInterval(refreshStatus, 3000);
});
@@ -652,6 +743,8 @@ onUnmounted(() => {
<section class="settings-section">
<h3>Audio Sources</h3>
<!-- Game Audio -->
<div class="form-group">
<label class="form-label">Capture Game Audio</label>
<label class="toggle">
@@ -660,6 +753,21 @@ onUnmounted(() => {
</label>
<span class="form-hint">Record the game's audio output</span>
</div>
<div v-if="settings.audio.capture_game" class="form-group">
<label class="form-label">Game Audio Volume</label>
<div class="volume-control">
<input
v-model.number="settings.audio.game_volume"
type="range"
min="0"
max="100"
class="volume-slider"
/>
<span class="volume-value">{{ settings.audio.game_volume }}%</span>
</div>
</div>
<!-- Microphone -->
<div class="form-group">
<label class="form-label">Capture Microphone</label>
<label class="toggle">
@@ -668,15 +776,102 @@ onUnmounted(() => {
</label>
<span class="form-hint">Record microphone input alongside game audio</span>
</div>
<div v-if="settings.audio.capture_mic" class="form-group">
<label class="form-label">Microphone Device</label>
<template v-if="settings.audio.capture_mic">
<div class="form-group">
<label class="form-label">Microphone Device</label>
<select v-model="settings.audio.mic_device" class="form-select">
<option :value="null">Default Microphone</option>
<option v-for="device in audioDevices.input_devices" :key="device.id" :value="device.id">
{{ device.name }}{{ device.is_default ? ' (Default)' : '' }}
</option>
</select>
<button class="btn btn-small btn-secondary" @click="loadAudioDevices" :disabled="loadingAudioDevices">
<span v-if="loadingAudioDevices">Loading...</span>
<span v-else>Refresh</span>
</button>
</div>
<div class="form-group">
<label class="form-label">Microphone Volume</label>
<div class="volume-control">
<input
v-model.number="settings.audio.mic_volume"
type="range"
min="0"
max="100"
class="volume-slider"
/>
<span class="volume-value">{{ settings.audio.mic_volume }}%</span>
</div>
</div>
</template>
<!-- Application Audio (Discord, Spotify, etc.) -->
<div class="form-group">
<label class="form-label">Application Audio Capture</label>
<span class="form-hint">Capture audio from specific applications like Discord or Spotify</span>
</div>
<div v-if="settings.audio.capture_apps && settings.audio.capture_apps.length > 0" class="app-sources-list">
<div v-for="source in settings.audio.capture_apps" :key="source.id" class="app-source-item">
<div class="app-source-header">
<label class="toggle toggle-small">
<input v-model="source.enabled" type="checkbox" />
<span class="toggle-slider"></span>
</label>
<span class="app-source-name">{{ source.name }}</span>
<span class="app-source-type">({{ source.type }})</span>
<button class="btn btn-small btn-danger" @click="removeAudioSource(source.id)">Remove</button>
</div>
<div v-if="source.enabled" class="app-source-controls">
<div class="form-group-inline">
<label>Device/Process:</label>
<input v-model="source.device" type="text" class="form-input-small" placeholder="e.g., Discord.exe" />
</div>
<div class="form-group-inline">
<label>Volume:</label>
<input
v-model.number="source.volume"
type="number"
min="0"
max="100"
class="form-input-small"
placeholder="Global"
/>
<span class="form-hint-inline">%</span>
</div>
</div>
</div>
</div>
<div class="add-app-source">
<select v-model="newAppSourceType" class="form-select">
<option value="application">Application (by executable)</option>
<option value="deviceOutput">Audio Output Device</option>
<option value="deviceInput">Audio Input Device</option>
</select>
<input
v-model="settings.audio.mic_device"
v-model="newAppName"
type="text"
class="form-input"
placeholder="Default device"
placeholder="Name (e.g., Discord)"
/>
<span class="form-hint">Leave empty for system default microphone</span>
<input
v-model="newAppDevice"
type="text"
class="form-input"
placeholder="Executable or Device ID"
/>
<button class="btn btn-secondary" @click="addAudioSource" :disabled="!newAppName || !newAppDevice">
Add Source
</button>
</div>
<!-- Quick Add Presets -->
<div class="quick-add-presets">
<span class="presets-label">Quick Add:</span>
<button class="btn btn-small btn-secondary" @click="addPresetSource('discord')">Discord</button>
<button class="btn btn-small btn-secondary" @click="addPresetSource('spotify')">Spotify</button>
<button class="btn btn-small btn-secondary" @click="addPresetSource('browser')">Browser</button>
</div>
</section>
</div>
@@ -1261,6 +1456,168 @@ onUnmounted(() => {
gap: 8px;
}
/* Volume control */
.volume-control {
display: flex;
align-items: center;
gap: 12px;
}
.volume-slider {
flex: 1;
height: 6px;
-webkit-appearance: none;
appearance: none;
background: rgba(255, 255, 255, 0.1);
border-radius: 3px;
outline: none;
}
.volume-slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
background: #3b82f6;
border-radius: 50%;
cursor: pointer;
transition: background 0.15s;
}
.volume-slider::-webkit-slider-thumb:hover {
background: #60a5fa;
}
.volume-slider::-moz-range-thumb {
width: 16px;
height: 16px;
background: #3b82f6;
border-radius: 50%;
cursor: pointer;
border: none;
}
.volume-value {
min-width: 45px;
text-align: right;
font-size: 13px;
color: #94a3b8;
}
/* App sources list */
.app-sources-list {
display: flex;
flex-direction: column;
gap: 12px;
margin-bottom: 16px;
}
.app-source-item {
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 8px;
padding: 12px;
}
.app-source-header {
display: flex;
align-items: center;
gap: 10px;
}
.app-source-name {
font-weight: 500;
color: #e2e8f0;
}
.app-source-type {
font-size: 12px;
color: #64748b;
text-transform: capitalize;
}
.app-source-header .btn {
margin-left: auto;
}
.app-source-controls {
display: flex;
flex-direction: column;
gap: 8px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.form-group-inline {
display: flex;
align-items: center;
gap: 8px;
}
.form-group-inline label {
min-width: 100px;
font-size: 13px;
color: #94a3b8;
}
.form-input-small {
flex: 1;
padding: 6px 10px;
background: rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 6px;
color: #e2e8f0;
font-size: 13px;
}
.form-hint-inline {
font-size: 12px;
color: #64748b;
}
/* Add app source form */
.add-app-source {
display: flex;
gap: 8px;
margin-top: 12px;
flex-wrap: wrap;
}
.add-app-source .form-select,
.add-app-source .form-input {
flex: 1;
min-width: 120px;
}
/* Quick add presets */
.quick-add-presets {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
flex-wrap: wrap;
}
.presets-label {
font-size: 13px;
color: #64748b;
}
.toggle-small {
width: 36px;
height: 20px;
}
.toggle-small .toggle-slider::before {
width: 14px;
height: 14px;
}
.toggle-small input:checked + .toggle-slider::before {
transform: translateX(16px);
}
/* Responsive */
@media (max-width: 640px) {
.settings-header {
+30
View File
@@ -60,8 +60,38 @@ export interface AudioSettings {
sample_rate: number;
channels: number;
capture_game: boolean;
game_volume: number;
capture_mic: boolean;
mic_device: string | null;
mic_volume: number;
capture_apps: AudioSourceConfig[];
apps_volume: number;
}
export interface AudioSourceConfig {
id: string;
name: string;
type: AudioSourceType;
device: string;
enabled: boolean;
volume: number | null;
}
export type AudioSourceType = "application" | "deviceOutput" | "deviceInput";
export interface AudioDeviceInfo {
id: string;
name: string;
is_default: boolean;
}
export interface GetAudioDevicesResponse {
input_devices: AudioDeviceInfo[];
output_devices: AudioDeviceInfo[];
}
export interface AudioSourceResponse {
source: AudioSourceConfig;
}
export interface DaemonSettings {