record-daemon: give the audio sources the window OBS reads
Recordings came back silent apart from the microphone. win-wasapi's process capture looks a window up from one setting, "window", a string of title, class and executable joined by colons; the video source got that string, the audio sources got "executable", "title" and "class" as separate keys, which the plugin never reads. Both sources therefore had nothing to hook, and the game and Discord tracks were empty. window_string builds the value the plugin expects, escaping ':' and '#' the way libobs decodes them, so a title with a colon in it still splits into three fields. The game source asks for the League window by executable, and an application source asks for its process the same way. Checked against a recording: a process source for a browser playing a loop now opens the loopback device for it, where before the plugin logged "Failed to find window" for every audio source but the mic. OBS's own log now goes into the daemon log under the obs target. A daemon started in the background has no console, so its warnings about a hook that never landed or a device that vanished were being thrown away, and those are the lines that explain a silent track.
This commit is contained in:
1 parent
976fcdc354
commit
2953ab1ee3
1 file changed
+42
-6
@@ -18,10 +18,12 @@ use libobs_wrapper::context::ObsContext as LibObsContext;
|
||||
use libobs_wrapper::data::object::ObsObjectTrait;
|
||||
use libobs_wrapper::data::ObsData;
|
||||
use libobs_wrapper::data::ObsObjectBuilder;
|
||||
use libobs_wrapper::enums::ObsLogLevel;
|
||||
use libobs_wrapper::logger::ObsLogger;
|
||||
use libobs_wrapper::sources::{ObsSourceBuilder, ObsSourceRef};
|
||||
use libobs_wrapper::utils::{SourceInfo, StartupInfo};
|
||||
use serde_json::json;
|
||||
use tracing::{info, warn};
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
use super::encoder::{best_available_encoder, EncoderCapability};
|
||||
use crate::config::{AudioSettings, AudioSourceType, VideoSettings};
|
||||
@@ -50,6 +52,36 @@ fn apply_volume(source: &ObsSourceRef, percent: u32) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `window` value an application audio capture source reads.
|
||||
///
|
||||
/// win-wasapi parses it as `title:class:exe` and looks for a window whose fields match, and it
|
||||
/// reads this key alone. Passing `executable`, `title` and `class` on their own left the source
|
||||
/// with no target and the recordings silent. `:` and `#` are escaped the way libobs decodes them
|
||||
/// (`libobs/util/windows/window-helpers.c`), so a title with a colon still yields three fields.
|
||||
#[cfg(target_os = "windows")]
|
||||
fn window_string(title: &str, class: &str, executable: &str) -> String {
|
||||
let escape = |field: &str| field.replace('#', "#22").replace(':', "#3A");
|
||||
format!("{}:{}:{}", escape(title), escape(class), escape(executable))
|
||||
}
|
||||
|
||||
/// libobs writes its own warnings to stdout, and a daemon started in the background has no one
|
||||
/// reading that. A failed game hook or a dropped audio device is exactly what explains a silent
|
||||
/// recording, so OBS's log goes into the daemon log with everything else.
|
||||
#[derive(Debug)]
|
||||
struct ObsLog;
|
||||
|
||||
impl ObsLogger for ObsLog {
|
||||
fn log(&mut self, level: ObsLogLevel, msg: String) {
|
||||
let msg = msg.trim_end();
|
||||
match level {
|
||||
ObsLogLevel::Error => error!(target: "obs", "{msg}"),
|
||||
ObsLogLevel::Warning => warn!(target: "obs", "{msg}"),
|
||||
ObsLogLevel::Info => info!(target: "obs", "{msg}"),
|
||||
ObsLogLevel::Debug => debug!(target: "obs", "{msg}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Builder for OBS context.
|
||||
pub struct ObsContextBuilder {
|
||||
video_settings: Option<VideoSettings>,
|
||||
@@ -157,7 +189,9 @@ impl ObsContext {
|
||||
warn!("libobs version mismatch with wrapper, continuing anyway");
|
||||
}
|
||||
|
||||
let info = StartupInfo::default().set_video_info(video_info);
|
||||
let info = StartupInfo::default()
|
||||
.set_video_info(video_info)
|
||||
.set_logger(Box::new(ObsLog));
|
||||
let context = catch_native("creating the OBS context", || {
|
||||
LibObsContext::new(info).map_err(|e| {
|
||||
RecordingError::ObsInitError(format!("failed to create OBS context: {:?}", e))
|
||||
@@ -413,9 +447,11 @@ fn add_audio_sources(
|
||||
game_plugin,
|
||||
"game_audio",
|
||||
json!({
|
||||
"executable": "League of Legends.exe",
|
||||
"title": "League of Legends (TM) Client",
|
||||
"class": "RiotWindowClass",
|
||||
"window": window_string(
|
||||
"League of Legends (TM) Client",
|
||||
"RiotWindowClass",
|
||||
"League of Legends.exe"
|
||||
),
|
||||
"priority": 2
|
||||
}),
|
||||
audio.game_volume,
|
||||
@@ -441,7 +477,7 @@ fn add_audio_sources(
|
||||
let (plugin, settings) = match app.source_type {
|
||||
AudioSourceType::Application => (
|
||||
game_plugin,
|
||||
json!({ "executable": app.device, "priority": 2 }),
|
||||
json!({ "window": window_string("", "", &app.device), "priority": 2 }),
|
||||
),
|
||||
AudioSourceType::DeviceOutput => (out_plugin, json!({ "device_id": app.device })),
|
||||
AudioSourceType::DeviceInput => (mic_plugin, json!({ "device_id": app.device })),
|
||||
|
||||
Reference in new issue
Block a user