use ::cpal::{
traits::{DeviceTrait, HostTrait},
DefaultStreamConfigError, Device, Host, SupportedStreamConfig,
};
pub mod playback;
pub mod record;
pub type OutputDevice = Device;
pub type InputDevice = Device;
pub use cpal;
#[allow(missing_debug_implementations)]
pub struct HostDevice {
pub output: Option<OutputDevice>,
pub input: Option<InputDevice>,
}
impl HostDevice {
pub fn new(output: Option<Device>, input: Option<Device>) -> Self {
Self { output, input }
}
pub fn get_input_config(
&self,
) -> Option<Result<SupportedStreamConfig, DefaultStreamConfigError>> {
self.input
.clone()
.map(|input_device| input_device.default_input_config())
}
pub fn get_output_config(
&self,
) -> Option<Result<SupportedStreamConfig, DefaultStreamConfigError>> {
self.output
.clone()
.map(|input_device| input_device.default_output_config())
}
}
pub use cpal::{available_hosts, default_host, host_from_id};
pub fn get_audio_device(device: Host) -> HostDevice {
HostDevice {
input: device.default_input_device(),
output: device.default_output_device(),
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, deepsize::DeepSizeOf)]
pub enum EncoderType {
Opus(bool),
}
#[derive(Debug, deepsize::DeepSizeOf)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SoundPacket {
pub encoder_type: EncoderType,
pub sample_rate: u32,
pub channels: u32,
pub bytes: Vec<u8>,
pub samples_per_frame: u64,
}