Skip to content

Commit

Permalink
fix(streamer): 🐛 Tweaks and bugfixes for linux audio (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Jul 6, 2024
1 parent a4dbccc commit 362391b
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 35 deletions.
4 changes: 1 addition & 3 deletions alvr/audio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use alvr_common::{
parking_lot::Mutex,
ConnectionError, ToAny,
};
use alvr_session::{
AudioBufferingConfig, CustomAudioDeviceConfig, LinuxAudioBackend, MicrophoneDevicesConfig,
};
use alvr_session::{AudioBufferingConfig, CustomAudioDeviceConfig, MicrophoneDevicesConfig};
use alvr_sockets::{StreamReceiver, StreamSender};
use cpal::{
traits::{DeviceTrait, HostTrait, StreamTrait},
Expand Down
4 changes: 2 additions & 2 deletions alvr/audio/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn play_microphone_loop_pipewire(
.ok();
}

if let Err(_) = pw_sender.send(Terminate) {
if pw_sender.send(Terminate).is_err() {
error!(
"Couldn't send pipewire termination signal, deinitializing forcefully.
Restart VR app to reinitialize pipewire."
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn record_audio_blocking_pipewire(
Arc::clone(&is_running);
thread::spawn(move || {
while is_running_clone_for_pw_terminate() {}
if let Err(_) = pw_sender.send(Terminate) {
if pw_sender.send(Terminate).is_err() {
error!(
"Couldn't send pipewire termination signal, deinitializing forcefully.
Restart VR app to reinitialize pipewire."
Expand Down
6 changes: 2 additions & 4 deletions alvr/dashboard/src/dashboard/components/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ impl SettingsTab {
resolution_preset: PresetControl::new(builtin_schema::resolution_schema()),
framerate_preset: PresetControl::new(builtin_schema::framerate_schema()),
encoder_preset: PresetControl::new(builtin_schema::encoder_preset_schema()),
game_audio_preset: cfg!(target_os = "linux")
.then(|| PresetControl::new(builtin_schema::linux_game_audio_schema())),
microphone_preset: cfg!(target_os = "linux")
.then(|| PresetControl::new(builtin_schema::linux_microphone_schema())),
game_audio_preset: None,
microphone_preset: None,
eye_face_tracking_preset: PresetControl::new(builtin_schema::eye_face_tracking_schema()),
top_level_entries,
session_settings_json: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ pub fn encoder_preset_schema() -> PresetSchemaNode {
})
}

pub fn linux_game_audio_schema() -> PresetSchemaNode {
#[cfg(target_os = "linux")]
pub fn game_audio_schema(_: Vec<String>) -> PresetSchemaNode {
PresetSchemaNode::HigherOrderChoice(HigherOrderChoiceSchema {
name: "game_audio".into(),
strings: [("display_name".into(), "Game audio".into())]
.into_iter()
.collect(),
name: "Headset speaker".into(),
strings: HashMap::new(),
flags: HashSet::new(),
options: [
HigherOrderChoiceOption {
Expand All @@ -174,12 +173,11 @@ pub fn linux_game_audio_schema() -> PresetSchemaNode {
})
}

pub fn linux_microphone_schema() -> PresetSchemaNode {
#[cfg(target_os = "linux")]
pub fn microphone_schema(_: Vec<String>) -> PresetSchemaNode {
PresetSchemaNode::HigherOrderChoice(HigherOrderChoiceSchema {
name: "microphone".into(),
strings: [("display_name".into(), "Microphone".into())]
.into_iter()
.collect(),
name: "Headset microphone".into(),
strings: HashMap::new(),
flags: HashSet::new(),
options: [
HigherOrderChoiceOption {
Expand All @@ -206,6 +204,7 @@ pub fn linux_microphone_schema() -> PresetSchemaNode {
})
}

#[cfg(not(target_os = "linux"))]
pub fn game_audio_schema(devices: Vec<String>) -> PresetSchemaNode {
let mut game_audio_options = vec![
HigherOrderChoiceOption {
Expand Down Expand Up @@ -249,7 +248,7 @@ pub fn game_audio_schema(devices: Vec<String>) -> PresetSchemaNode {
}

PresetSchemaNode::HigherOrderChoice(HigherOrderChoiceSchema {
name: "game_audio".into(),
name: "Headset speaker".into(),
strings: [(
"help".into(),
"You should keep this as default. Change the default audio device from the global OS settings".into(),
Expand All @@ -263,6 +262,7 @@ pub fn game_audio_schema(devices: Vec<String>) -> PresetSchemaNode {
})
}

#[cfg(not(target_os = "linux"))]
pub fn microphone_schema(devices: Vec<String>) -> PresetSchemaNode {
let mut microhone_options = vec![HigherOrderChoiceOption {
display_name: "Disabled".to_owned(),
Expand Down Expand Up @@ -310,7 +310,7 @@ pub fn microphone_schema(devices: Vec<String>) -> PresetSchemaNode {
};

PresetSchemaNode::HigherOrderChoice(HigherOrderChoiceSchema {
name: "microphone".into(),
name: "Headset microphone".into(),
strings: HashMap::new(),
flags: HashSet::new(),
options: microhone_options.into_iter().collect(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Entry {
id: DisplayString,
help: Option<String>,
// notice: Option<String>,
hidden: bool,
steamvr_restart_flag: bool,
real_time_flag: bool,
control: SettingControl,
Expand All @@ -41,6 +42,7 @@ impl Control {
let display = super::get_display_name(&id, &entry.strings);
let help = entry.strings.get("help").cloned();
// let notice = entry.strings.get("notice").cloned();
let hidden = entry.flags.contains("hidden");
let steamvr_restart_flag = entry.flags.contains("steamvr-restart");
let real_time_flag = entry.flags.contains("real-time");

Expand All @@ -51,6 +53,7 @@ impl Control {
id: DisplayString { id, display },
help,
// notice,
hidden,
steamvr_restart_flag,
real_time_flag,
control: SettingControl::new(nesting_info, entry.content),
Expand Down Expand Up @@ -100,6 +103,10 @@ impl Control {

if !collapsed {
for (i, entry) in self.entries.iter_mut().enumerate() {
if entry.hidden {
continue;
}

ui.horizontal(|ui| {
ui.add_space(INDENTATION_STEP * self.nesting_info.indentation_level as f32);
let label_res = ui.label(&entry.id.display);
Expand Down
1 change: 0 additions & 1 deletion alvr/dashboard/src/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ impl Dashboard {

// Audio devices need to be queried early to mitigate buggy/slow hardware queries on Linux.
data_sources.request(ServerRequest::GetSession);
#[cfg(not(target_os = "linux"))]
data_sources.request(ServerRequest::GetAudioDevices);

Self {
Expand Down
1 change: 0 additions & 1 deletion alvr/dashboard/src/data_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ impl DataSources {
report_session_local(&context, &events_sender, data_manager);
}
ServerRequest::GetAudioDevices => {
#[cfg(not(target_os = "linux"))]
if let Ok(list) = data_manager.get_audio_devices_list() {
report_event_local(
&context,
Expand Down
1 change: 0 additions & 1 deletion alvr/server/src/web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ async fn http_api(
data_manager.update_client_list(hostname, action);
}
ServerRequest::GetAudioDevices => {
#[cfg(not(target_os = "linux"))]
if let Ok(list) = SERVER_DATA_MANAGER.read().get_audio_devices_list() {
alvr_events::send_event(EventType::AudioDevices(list));
}
Expand Down
2 changes: 0 additions & 2 deletions alvr/server_io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ impl ServerDataManager {
}
}

#[cfg(not(target_os = "linux"))]
#[cfg_attr(not(target_os = "linux"), allow(unused_variables))]
pub fn get_audio_devices_list(&self) -> Result<AudioDevicesList> {
let host = cpal::default_host();

Expand Down
13 changes: 4 additions & 9 deletions alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,6 @@ pub struct VideoConfig {
pub clientside_foveation: Switch<ClientsideFoveationConfig>,
}

#[derive(SettingsSchema, Serialize, Deserialize, Clone, Copy)]
#[schema(gui = "button_group")]
pub enum LinuxAudioBackend {
#[schema(strings(display_name = "ALSA"))]
Alsa,

Jack,
}

#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
#[schema(gui = "button_group")]
pub enum CustomAudioDeviceConfig {
Expand All @@ -601,8 +592,10 @@ pub struct AudioBufferingConfig {
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
#[schema(collapsible)]
pub struct GameAudioConfig {
#[cfg_attr(target_os = "linux", schema(flag = "hidden"))]
pub device: Option<CustomAudioDeviceConfig>,

#[cfg_attr(target_os = "linux", schema(flag = "hidden"))]
#[schema(strings(display_name = "Mute desktop audio when streaming"))]
pub mute_when_streaming: bool,

Expand Down Expand Up @@ -633,7 +626,9 @@ pub enum MicrophoneDevicesConfig {
#[derive(SettingsSchema, Serialize, Deserialize, Clone)]
#[schema(collapsible)]
pub struct MicrophoneConfig {
#[cfg_attr(target_os = "linux", schema(flag = "hidden"))]
pub devices: MicrophoneDevicesConfig,

pub buffering: AudioBufferingConfig,
}

Expand Down

0 comments on commit 362391b

Please sign in to comment.