wayle_audio/types/
device.rs1use std::collections::HashMap;
2
3use libpulse_binding::time::MicroSeconds;
4
5use super::format::{AudioFormat, ChannelMap, SampleSpec};
6use crate::volume::types::Volume;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub enum DeviceState {
11 Running,
13 Idle,
15 Suspended,
17 Offline,
19}
20
21#[derive(Debug, Clone, PartialEq)]
23pub struct DevicePort {
24 pub name: String,
26 pub description: String,
28 pub priority: u32,
30 pub available: bool,
32}
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
36pub enum DeviceType {
37 Input,
39 Output,
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45pub struct DeviceKey {
46 pub index: u32,
48 pub device_type: DeviceType,
50}
51
52impl DeviceKey {
53 pub fn new(index: u32, device_type: DeviceType) -> Self {
55 Self { index, device_type }
56 }
57}
58
59#[derive(Debug, Clone, PartialEq)]
60pub(crate) struct DeviceInfo {
61 pub index: u32,
62 pub name: String,
63 pub description: String,
64 pub card_index: Option<u32>,
65 pub owner_module: Option<u32>,
66 pub driver: String,
67 pub state: DeviceState,
68 pub volume: Volume,
69 pub base_volume: Volume,
70 pub n_volume_steps: u32,
71 pub muted: bool,
72 pub properties: HashMap<String, String>,
73 pub ports: Vec<DevicePort>,
74 pub active_port: Option<String>,
75 pub formats: Vec<AudioFormat>,
76 pub sample_spec: SampleSpec,
77 pub channel_map: ChannelMap,
78 pub latency: MicroSeconds,
79 pub configured_latency: MicroSeconds,
80 pub flags: u32,
81}
82
83#[derive(Debug, Clone, PartialEq)]
84pub(crate) struct SinkInfo {
85 pub device: DeviceInfo,
86 pub monitor_source: u32,
87 pub monitor_source_name: String,
88}
89
90#[derive(Debug, Clone, PartialEq)]
91pub(crate) struct SourceInfo {
92 pub device: DeviceInfo,
93 pub monitor_of_sink: Option<u32>,
94 pub monitor_of_sink_name: Option<String>,
95 pub is_monitor: bool,
96}
97
98impl DeviceInfo {
99 pub(crate) fn key(&self, device_type: DeviceType) -> DeviceKey {
100 DeviceKey {
101 index: self.index,
102 device_type,
103 }
104 }
105}
106
107impl SinkInfo {
108 pub(crate) fn key(&self) -> DeviceKey {
109 self.device.key(DeviceType::Output)
110 }
111}
112
113impl SourceInfo {
114 pub(crate) fn key(&self) -> DeviceKey {
115 self.device.key(DeviceType::Input)
116 }
117}
118
119#[derive(Debug, Clone, PartialEq)]
120pub(crate) enum Device {
121 Sink(SinkInfo),
122 Source(SourceInfo),
123}
124
125impl Device {
126 pub(crate) fn key(&self) -> DeviceKey {
127 match self {
128 Device::Sink(sink) => sink.key(),
129 Device::Source(source) => source.key(),
130 }
131 }
132}