Skip to content

Commit 4c7eaad

Browse files
committed
refactor: remove unused ALSA code and incorrect Send/Sync implementations
1 parent f5d9165 commit 4c7eaad

File tree

2 files changed

+10
-33
lines changed

2 files changed

+10
-33
lines changed

src/host/alsa/enumerate.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::{
33
sync::{Arc, Mutex},
44
};
55

6-
use super::{
7-
alsa, {Device, DeviceHandles},
8-
};
6+
use super::{alsa, Device};
97
use crate::{BackendSpecificError, DevicesError};
108

119
/// ALSA's implementation for `Devices`.
@@ -26,16 +24,13 @@ impl Devices {
2624
}
2725
}
2826

29-
unsafe impl Send for Devices {}
30-
unsafe impl Sync for Devices {}
31-
3227
impl Iterator for Devices {
3328
type Item = Device;
3429

35-
fn next(&mut self) -> Option<Device> {
30+
fn next(&mut self) -> Option<Self::Item> {
3631
loop {
3732
let hint = self.hint_iter.next()?;
38-
if let Ok(device) = Device::try_from(hint) {
33+
if let Ok(device) = Self::Item::try_from(hint) {
3934
if self.enumerated_pcm_ids.insert(device.pcm_id.clone()) {
4035
return Some(device);
4136
} else {
@@ -77,20 +72,15 @@ impl TryFrom<alsa::device_name::Hint> for Device {
7772
type Error = BackendSpecificError;
7873

7974
fn try_from(hint: alsa::device_name::Hint) -> Result<Self, Self::Error> {
80-
let pcm_id = hint.name.ok_or_else(|| BackendSpecificError {
75+
let pcm_id = hint.name.ok_or_else(|| Self::Error {
8176
description: "ALSA hint missing PCM ID".to_string(),
8277
})?;
8378

84-
// Don't try to open handles during enumeration to avoid ALSA logging errors
85-
// for device templates (e.g., with $CARD placeholders) or unavailable devices.
86-
// Opening will be attempted when the device is actually used.
87-
let handles = DeviceHandles::default();
88-
8979
// Include all devices from ALSA hints (matches `aplay -L` behavior)
9080
Ok(Self {
9181
pcm_id: pcm_id.to_owned(),
9282
desc: hint.desc,
93-
handles: Arc::new(Mutex::new(handles)),
83+
handles: Arc::new(Mutex::new(Default::default())),
9484
})
9585
}
9686
}

src/host/alsa/mod.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl DeviceTrait for Device {
151151
{
152152
let stream_inner =
153153
self.build_stream_inner(conf, sample_format, alsa::Direction::Capture)?;
154-
let stream = Stream::new_input(
154+
let stream = Self::Stream::new_input(
155155
Arc::new(stream_inner),
156156
data_callback,
157157
error_callback,
@@ -174,7 +174,7 @@ impl DeviceTrait for Device {
174174
{
175175
let stream_inner =
176176
self.build_stream_inner(conf, sample_format, alsa::Direction::Playback)?;
177-
let stream = Stream::new_output(
177+
let stream = Self::Stream::new_output(
178178
Arc::new(stream_inner),
179179
data_callback,
180180
error_callback,
@@ -235,19 +235,6 @@ struct DeviceHandles {
235235
}
236236

237237
impl DeviceHandles {
238-
/// Create `DeviceHandles` for `name` and try to open a handle for both
239-
/// directions. Returns `Ok` if either direction is opened successfully.
240-
fn open(pcm_id: &str) -> Result<Self, alsa::Error> {
241-
let mut handles = Self::default();
242-
let playback_err = handles.try_open(pcm_id, alsa::Direction::Playback).err();
243-
let capture_err = handles.try_open(pcm_id, alsa::Direction::Capture).err();
244-
if let Some(err) = capture_err.and(playback_err) {
245-
Err(err)
246-
} else {
247-
Ok(handles)
248-
}
249-
}
250-
251238
/// Get a mutable reference to the `Option` for a specific `stream_type`.
252239
/// If the `Option` is `None`, the `alsa::PCM` will be opened and placed in
253240
/// the `Option` before returning. If `handle_mut()` returns `Ok` the contained
@@ -1089,7 +1076,7 @@ impl Stream {
10891076
);
10901077
})
10911078
.unwrap();
1092-
Stream {
1079+
Self {
10931080
thread: Some(thread),
10941081
inner,
10951082
trigger: tx,
@@ -1121,7 +1108,7 @@ impl Stream {
11211108
);
11221109
})
11231110
.unwrap();
1124-
Stream {
1111+
Self {
11251112
thread: Some(thread),
11261113
inner,
11271114
trigger: tx,
@@ -1378,7 +1365,7 @@ fn set_sw_params_from_format(
13781365

13791366
impl From<alsa::Error> for BackendSpecificError {
13801367
fn from(err: alsa::Error) -> Self {
1381-
BackendSpecificError {
1368+
Self {
13821369
description: err.to_string(),
13831370
}
13841371
}

0 commit comments

Comments
 (0)