1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 17:59:24 +02:00

refactor: clean up Rodio fallback handling

This commit is contained in:
Roderick van Domburg 2025-08-13 17:11:43 +02:00
parent 648c9e30ea
commit 445f8b10a2
No known key found for this signature in database
GPG key ID: 607FA06CB5236AE0

View file

@ -193,11 +193,18 @@ fn create_sink(
AudioFormat::S16 => cpal::SampleFormat::I16, AudioFormat::S16 => cpal::SampleFormat::I16,
}; };
let stream = rodio::OutputStreamBuilder::default() let stream = match rodio::OutputStreamBuilder::default()
.with_device(cpal_device) .with_device(cpal_device.clone())
.with_config(&config.config()) .with_config(&config.config())
.with_sample_format(sample_format) .with_sample_format(sample_format)
.open_stream_or_fallback()?; .open_stream()
{
Ok(exact_stream) => exact_stream,
Err(e) => {
warn!("unable to create Rodio output, falling back to default: {e}");
rodio::OutputStreamBuilder::from_device(cpal_device)?.open_stream_or_fallback()?
}
};
let sink = rodio::Sink::connect_new(stream.mixer()); let sink = rodio::Sink::connect_new(stream.mixer());
Ok((sink, stream)) Ok((sink, stream))
@ -209,12 +216,6 @@ pub fn open(host: cpal::Host, device: Option<String>, format: AudioFormat) -> Ro
host.id().name() host.id().name()
); );
let mut format = format;
if format != AudioFormat::S16 && format != AudioFormat::F32 {
error!("Rodio currently only supports F32 and S16 formats, falling back to S16");
format = AudioFormat::S16;
}
let (sink, stream) = create_sink(&host, device, format).unwrap(); let (sink, stream) = create_sink(&host, device, format).unwrap();
debug!("Rodio sink was created"); debug!("Rodio sink was created");