Skip to content

Commit

Permalink
Clone for device (RustAudio#830)
Browse files Browse the repository at this point in the history
* Clone for Device and Alsa Device

* fix cloning around PCM

* add Clone for oboe Device

* add Clone for ASIO Device
  • Loading branch information
bbarker committed Feb 6, 2024
1 parent 4706396 commit bbb58ab
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/host/alsa/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::alsa;
use super::parking_lot::Mutex;
use super::{Device, DeviceHandles};
use crate::{BackendSpecificError, DevicesError};
use std::sync::Arc;

/// ALSA's implementation for `Devices`.
pub struct Devices {
Expand Down Expand Up @@ -37,7 +38,7 @@ impl Iterator for Devices {
if let Ok(handles) = DeviceHandles::open(&name) {
return Some(Device {
name,
handles: Mutex::new(handles),
handles: Arc::new(Mutex::new(handles)),
});
}
}
Expand All @@ -50,15 +51,15 @@ impl Iterator for Devices {
pub fn default_input_device() -> Option<Device> {
Some(Device {
name: "default".to_owned(),
handles: Mutex::new(Default::default()),
handles: Arc::new(Mutex::new(Default::default())),
})
}

#[inline]
pub fn default_output_device() -> Option<Device> {
Some(Device {
name: "default".to_owned(),
handles: Mutex::new(Default::default()),
handles: Arc::new(Mutex::new(Default::default())),
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/host/alsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,10 @@ impl DeviceHandles {
}
}

#[derive(Clone)]
pub struct Device {
name: String,
handles: Mutex<DeviceHandles>,
handles: Arc<Mutex<DeviceHandles>>,
}

impl Device {
Expand Down
1 change: 1 addition & 0 deletions src/host/asio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::hash::{Hash, Hasher};
use std::sync::Arc;

/// A ASIO Device
#[derive(Clone)]
pub struct Device {
/// The driver represented by this device.
pub driver: Arc<sys::Driver>,
Expand Down
1 change: 1 addition & 0 deletions src/host/oboe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const SAMPLE_RATES: [i32; 13] = [
];

pub struct Host;
#[derive(Clone)]
pub struct Device(Option<oboe::AudioDeviceInfo>);
pub enum Stream {
Input(Box<RefCell<dyn AudioInputStream>>),
Expand Down
2 changes: 2 additions & 0 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ macro_rules! impl_platform_host {

/// The `Device` implementation associated with the platform's dynamically dispatched
/// [`Host`] type.
#[derive(Clone)]
pub struct Device(DeviceInner);

/// The `Devices` iterator associated with the platform's dynamically dispatched [`Host`]
Expand Down Expand Up @@ -89,6 +90,7 @@ macro_rules! impl_platform_host {
}

/// Contains a platform specific [`Device`] implementation.
#[derive(Clone)]
pub enum DeviceInner {
$(
$(#[cfg($feat)])?
Expand Down

0 comments on commit bbb58ab

Please sign in to comment.