1use ::cpal::{
5 traits::{DeviceTrait, HostTrait},
6 DefaultStreamConfigError, Device, Host, SupportedStreamConfig,
7};
8
9pub mod playback;
10pub mod record;
11
12pub type OutputDevice = Device;
14
15pub type InputDevice = Device;
17
18pub use cpal;
20
21#[allow(missing_debug_implementations)]
23pub struct HostDevice {
24 pub output: Option<OutputDevice>,
26 pub input: Option<InputDevice>,
28}
29
30impl HostDevice {
31 pub fn new(output: Option<Device>, input: Option<Device>) -> Self {
33 Self { output, input }
34 }
35
36 pub fn get_input_config(
38 &self,
39 ) -> Option<Result<SupportedStreamConfig, DefaultStreamConfigError>> {
40 self.input
41 .clone()
42 .map(|input_device| input_device.default_input_config())
43 }
44
45 pub fn get_output_config(
47 &self,
48 ) -> Option<Result<SupportedStreamConfig, DefaultStreamConfigError>> {
49 self.output
50 .clone()
51 .map(|input_device| input_device.default_output_config())
52 }
53}
54
55pub use cpal::{available_hosts, default_host, host_from_id};
56
57pub fn get_audio_device(device: Host) -> HostDevice {
59 HostDevice {
60 input: device.default_input_device(),
61 output: device.default_output_device(),
62 }
63}
64
65#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
67#[derive(Debug, deepsize::DeepSizeOf)]
68pub enum EncoderType {
69 Opus(bool),
72}
73
74#[derive(Debug, deepsize::DeepSizeOf)]
77#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
78pub struct SoundPacket {
79 pub encoder_type: EncoderType,
81 pub sample_rate: u32,
83 pub channels: u32,
85 pub bytes: Vec<u8>,
87 pub samples_per_frame: u64,
89}
90