Clone for device (#830)
* Clone for Device and Alsa Device * fix cloning around PCM * add Clone for oboe Device * add Clone for ASIO Device
This commit is contained in:
parent
4706396ca3
commit
bbb58ab767
5 changed files with 10 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ use super::alsa;
|
||||||
use super::parking_lot::Mutex;
|
use super::parking_lot::Mutex;
|
||||||
use super::{Device, DeviceHandles};
|
use super::{Device, DeviceHandles};
|
||||||
use crate::{BackendSpecificError, DevicesError};
|
use crate::{BackendSpecificError, DevicesError};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// ALSA's implementation for `Devices`.
|
/// ALSA's implementation for `Devices`.
|
||||||
pub struct Devices {
|
pub struct Devices {
|
||||||
|
|
@ -37,7 +38,7 @@ impl Iterator for Devices {
|
||||||
if let Ok(handles) = DeviceHandles::open(&name) {
|
if let Ok(handles) = DeviceHandles::open(&name) {
|
||||||
return Some(Device {
|
return Some(Device {
|
||||||
name,
|
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<Device> {
|
pub fn default_input_device() -> Option<Device> {
|
||||||
Some(Device {
|
Some(Device {
|
||||||
name: "default".to_owned(),
|
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<Device> {
|
||||||
pub fn default_output_device() -> Option<Device> {
|
pub fn default_output_device() -> Option<Device> {
|
||||||
Some(Device {
|
Some(Device {
|
||||||
name: "default".to_owned(),
|
name: "default".to_owned(),
|
||||||
handles: Mutex::new(Default::default()),
|
handles: Arc::new(Mutex::new(Default::default())),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -236,9 +236,10 @@ impl DeviceHandles {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Device {
|
pub struct Device {
|
||||||
name: String,
|
name: String,
|
||||||
handles: Mutex<DeviceHandles>,
|
handles: Arc<Mutex<DeviceHandles>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Device {
|
impl Device {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ use std::hash::{Hash, Hasher};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// A ASIO Device
|
/// A ASIO Device
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Device {
|
pub struct Device {
|
||||||
/// The driver represented by this device.
|
/// The driver represented by this device.
|
||||||
pub driver: Arc<sys::Driver>,
|
pub driver: Arc<sys::Driver>,
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ const SAMPLE_RATES: [i32; 13] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
pub struct Host;
|
pub struct Host;
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Device(Option<oboe::AudioDeviceInfo>);
|
pub struct Device(Option<oboe::AudioDeviceInfo>);
|
||||||
pub enum Stream {
|
pub enum Stream {
|
||||||
Input(Box<RefCell<dyn AudioInputStream>>),
|
Input(Box<RefCell<dyn AudioInputStream>>),
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ macro_rules! impl_platform_host {
|
||||||
|
|
||||||
/// The `Device` implementation associated with the platform's dynamically dispatched
|
/// The `Device` implementation associated with the platform's dynamically dispatched
|
||||||
/// [`Host`] type.
|
/// [`Host`] type.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Device(DeviceInner);
|
pub struct Device(DeviceInner);
|
||||||
|
|
||||||
/// The `Devices` iterator associated with the platform's dynamically dispatched [`Host`]
|
/// 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.
|
/// Contains a platform specific [`Device`] implementation.
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum DeviceInner {
|
pub enum DeviceInner {
|
||||||
$(
|
$(
|
||||||
$(#[cfg($feat)])?
|
$(#[cfg($feat)])?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue