Try to make the audio sink mess clear

This commit is contained in:
Yukino Song
2024-07-31 20:16:00 +08:00
committed by Yukino Song
parent d5605cc899
commit 774ce93162
7 changed files with 56 additions and 22 deletions

View File

@@ -192,6 +192,8 @@ namespace audio {
}
}
BOOST_LOG(info) << "Selected audio sink: "sv << *sink;
// Only the first to start a session may change the default sink
if (!ref->sink_flag->exchange(true, std::memory_order_acquire)) {
// If the selected sink is different than the current one, change sinks.
@@ -238,6 +240,7 @@ namespace audio {
case platf::capture_e::timeout:
continue;
case platf::capture_e::reinit:
if (config::audio.auto_capture) {
BOOST_LOG(info) << "Reinitializing audio capture"sv;
mic.reset();
do {
@@ -246,6 +249,8 @@ namespace audio {
BOOST_LOG(warning) << "Couldn't re-initialize audio input"sv;
}
} while (!mic && !shutdown_event->view(5s));
}
continue;
default:
return;

View File

@@ -384,6 +384,8 @@ namespace config {
{}, // audio_sink
{}, // virtual_sink
true, // install_steam_drivers
true, // keep_sink_default
true, // auto_capture
};
stream_t stream {
@@ -1051,6 +1053,8 @@ namespace config {
string_f(vars, "audio_sink", audio.sink);
string_f(vars, "virtual_sink", audio.virtual_sink);
bool_f(vars, "install_steam_audio_drivers", audio.install_steam_drivers);
bool_f(vars, "keep_sink_default", audio.keep_default);
bool_f(vars, "auto_capture_sink", audio.auto_capture);
string_restricted_f(vars, "origin_web_ui_allowed", nvhttp.origin_web_ui_allowed, { "pc"sv, "lan"sv, "wan"sv });

View File

@@ -81,6 +81,8 @@ namespace config {
std::string sink;
std::string virtual_sink;
bool install_steam_drivers;
bool keep_default;
bool auto_capture;
};
constexpr int ENCRYPTION_MODE_NEVER = 0; // Never use video encryption, even if the client supports it

View File

@@ -758,6 +758,7 @@ namespace platf::audio {
return nullptr;
}
if (config::audio.keep_default) {
// If this is a virtual sink, set a callback that will change the sink back if it's changed
auto virtual_sink_info = extract_virtual_sink_info(assigned_sink);
if (virtual_sink_info) {
@@ -766,6 +767,7 @@ namespace platf::audio {
set_sink(assigned_sink);
};
}
}
return mic;
}

View File

@@ -10,6 +10,10 @@
border-top: none;
}
.pre-wrap {
white-space: pre-wrap;
}
.buttons {
padding: 1em 0;
}
@@ -172,6 +176,8 @@
"audio_sink": "",
"virtual_sink": "",
"install_steam_audio_drivers": "enabled",
"keep_sink_default": "enabled",
"auto_capture_sink": "enabled",
"adapter_name": "",
"output_name": "",
"resolutions": "[352x240,480x360,858x480,1280x720,1920x1080,2560x1080,2560x1440,3440x1440,1920x1200,3840x2160,3840x1600]",

View File

@@ -27,7 +27,7 @@ const config = ref(props.config)
<input type="text" class="form-control" id="audio_sink"
:placeholder="$tp('config.audio_sink_placeholder', 'alsa_output.pci-0000_09_00.3.analog-stereo')"
v-model="config.audio_sink" />
<div class="form-text">
<div class="form-text pre-wrap">
{{ $tp('config.audio_sink_desc') }}<br>
<PlatformLayout :platform="platform">
<template #windows>
@@ -45,7 +45,6 @@ const config = ref(props.config)
</div>
</div>
<PlatformLayout :platform="platform">
<template #windows>
<!-- Virtual Sink -->
@@ -53,9 +52,8 @@ const config = ref(props.config)
<label for="virtual_sink" class="form-label">{{ $t('config.virtual_sink') }}</label>
<input type="text" class="form-control" id="virtual_sink" :placeholder="$t('config.virtual_sink_placeholder')"
v-model="config.virtual_sink" />
<div class="form-text">{{ $t('config.virtual_sink_desc') }}</div>
<div class="form-text pre-wrap">{{ $t('config.virtual_sink_desc') }}</div>
</div>
<!-- Install Steam Audio Drivers -->
<div class="mb-3">
<label for="install_steam_audio_drivers" class="form-label">{{ $t('config.install_steam_audio_drivers') }}</label>
@@ -63,11 +61,28 @@ const config = ref(props.config)
<option value="disabled">{{ $t('_common.disabled') }}</option>
<option value="enabled">{{ $t('_common.enabled_def') }}</option>
</select>
<div class="form-text">{{ $t('config.install_steam_audio_drivers_desc') }}</div>
<div class="form-text pre-wrap">{{ $t('config.install_steam_audio_drivers_desc') }}</div>
</div>
<div class="mb-3">
<label for="keep_sink_default" class="form-label">{{ 'Keep virtual sink as default' }}</label>
<select id="keep_sink_default" class="form-select" v-model="config.keep_sink_default">
<option value="disabled">{{ $t('_common.disabled') }}</option>
<option value="enabled">{{ $t('_common.enabled_def') }}</option>
</select>
<div class="form-text pre-wrap">{{ 'Whether to force selected virtual sink as default (effective when host audio output is disabled).' }}</div>
</div>
<div class="mb-3">
<label for="auto_capture_sink" class="form-label">{{ 'Auto capture current sink' }}</label>
<select id="auto_capture_sink" class="form-select" v-model="config.auto_capture_sink">
<option value="disabled">{{ $t('_common.disabled') }}</option>
<option value="enabled">{{ $t('_common.enabled_def') }}</option>
</select>
<div class="form-text pre-wrap">{{ 'Auto capture current sink after default audio sink changed.' }}</div>
</div>
</template>
</PlatformLayout>
<AdapterNameSelector
:platform="platform"
:config="config"

View File

@@ -125,7 +125,7 @@
"audio_sink": "Audio Sink",
"audio_sink_desc_linux": "The name of the audio sink used for Audio Loopback. If you do not specify this variable, pulseaudio will select the default monitor device. You can find the name of the audio sink using either command:",
"audio_sink_desc_macos": "The name of the audio sink used for Audio Loopback. Apollo can only access microphones on macOS due to system limitations. To stream system audio using Soundflower or BlackHole.",
"audio_sink_desc_windows": "Manually specify a specific audio device to capture. If unset, the device is chosen automatically. We strongly recommend leaving this field blank to use automatic device selection! If you have multiple audio devices with identical names, you can get the Device ID using the following command:",
"audio_sink_desc_windows": "The audio device to be used when audio output is allowed on host by the client.\nIf unset, the device is chosen automatically.\nYou can get the Device ID using the following command:",
"audio_sink_placeholder_macos": "BlackHole 2ch",
"audio_sink_placeholder_windows": "Speakers (High Definition Audio Device)",
"av1_mode": "AV1 Support",
@@ -314,7 +314,7 @@
"upnp": "UPnP",
"upnp_desc": "Automatically configure port forwarding for streaming over the Internet",
"virtual_sink": "Virtual Sink",
"virtual_sink_desc": "Manually specify a virtual audio device to use. If unset, the device is chosen automatically. We strongly recommend leaving this field blank to use automatic device selection!",
"virtual_sink_desc": "The audio device to be used when audio output isn't allowed on host by the client.\nIf unset, the device is chosen automatically.\nWe strongly recommend leaving this field blank to use automatic device selection!",
"virtual_sink_placeholder": "Steam Streaming Speakers",
"vt_coder": "VideoToolbox Coder",
"vt_realtime": "VideoToolbox Realtime Encoding",