VNOX-Client/src/audio/devices/output.rs
loki5512344 3b95df9e9c
fix(client): list only real audio devices and persist the choice by id
The device pickers showed every ALSA PCM plugin (Discard all samples, Rate
Converter, JACK, Open Sound System, surround/dmix aliases). Enumeration now
goes through a pure filter that keeps the system default, the PipeWire and
PulseAudio servers and one entry per hardware endpoint, with technical tails
removed and a stable sort.

Selections are stored by device id instead of list position, so the filter
and hotplug cannot move a saved choice. Indexes saved by older versions are
migrated by device name; a missing device falls back to the default.

The same preferences change records whether the voice mode was chosen by
the person: a profile that only carries the old push-to-talk default now
starts in voice activation, explicit choices are kept.
2026-10-25 10:03:20 +01:00

22 lines
771 B
Rust

use anyhow::{Result, anyhow};
use cpal::Device;
use cpal::traits::HostTrait;
use tracing::warn;
/// Opens the output with persisted id `id`; an empty id is the system default. A saved
/// device that has disappeared falls back to the default instead of failing the join.
pub fn open_output(id: &str) -> Result<Device> {
let host = cpal::default_host();
if !id.is_empty() {
let alsa = super::is_alsa(&host);
if let Some(device) = super::find_by_id(host.output_devices()?, id, alsa) {
return Ok(device);
}
warn!(
device = id,
"saved output device not found, using the system default"
);
}
host.default_output_device()
.ok_or_else(|| anyhow!("no default output device"))
}