From bbb58ab76787d090d32ed56964bfcf194b8f6a3d Mon Sep 17 00:00:00 2001 From: Brandon Elam Barker Date: Mon, 5 Feb 2024 22:48:11 -0500 Subject: [PATCH] Clone for device (#830) * Clone for Device and Alsa Device * fix cloning around PCM * add Clone for oboe Device * add Clone for ASIO Device --- src/host/alsa/enumerate.rs | 7 ++++--- src/host/alsa/mod.rs | 3 ++- src/host/asio/device.rs | 1 + src/host/oboe/mod.rs | 1 + src/platform/mod.rs | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/host/alsa/enumerate.rs b/src/host/alsa/enumerate.rs index 64c1c5e38..0aa7fb0d7 100644 --- a/src/host/alsa/enumerate.rs +++ b/src/host/alsa/enumerate.rs @@ -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 { @@ -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)), }); } } @@ -50,7 +51,7 @@ impl Iterator for Devices { pub fn default_input_device() -> Option { Some(Device { name: "default".to_owned(), - handles: Mutex::new(Default::default()), + handles: Arc::new(Mutex::new(Default::default())), }) } @@ -58,7 +59,7 @@ pub fn default_input_device() -> Option { pub fn default_output_device() -> Option { Some(Device { name: "default".to_owned(), - handles: Mutex::new(Default::default()), + handles: Arc::new(Mutex::new(Default::default())), }) } diff --git a/src/host/alsa/mod.rs b/src/host/alsa/mod.rs index 830ef86f3..137ae2b4a 100644 --- a/src/host/alsa/mod.rs +++ b/src/host/alsa/mod.rs @@ -236,9 +236,10 @@ impl DeviceHandles { } } +#[derive(Clone)] pub struct Device { name: String, - handles: Mutex, + handles: Arc>, } impl Device { diff --git a/src/host/asio/device.rs b/src/host/asio/device.rs index f48163504..b1532258d 100644 --- a/src/host/asio/device.rs +++ b/src/host/asio/device.rs @@ -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, diff --git a/src/host/oboe/mod.rs b/src/host/oboe/mod.rs index 788c05476..e2acb5208 100644 --- a/src/host/oboe/mod.rs +++ b/src/host/oboe/mod.rs @@ -37,6 +37,7 @@ const SAMPLE_RATES: [i32; 13] = [ ]; pub struct Host; +#[derive(Clone)] pub struct Device(Option); pub enum Stream { Input(Box>), diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 1446a41f8..4cb4d5a29 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -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`] @@ -89,6 +90,7 @@ macro_rules! impl_platform_host { } /// Contains a platform specific [`Device`] implementation. + #[derive(Clone)] pub enum DeviceInner { $( $(#[cfg($feat)])?