snapcast_client/
config.rs1use std::path::PathBuf;
4
5use snapcast_proto::SampleFormat;
6
7#[derive(Debug, Clone)]
9pub struct ServerSettings {
10 pub scheme: String,
12 pub host: String,
14 pub port: u16,
16 pub auth: Option<Auth>,
18 pub server_certificate: Option<PathBuf>,
20 pub certificate: Option<PathBuf>,
22 pub certificate_key: Option<PathBuf>,
24 pub key_password: Option<String>,
26}
27
28#[derive(Debug, Clone)]
30pub struct Auth {
31 pub scheme: String,
33 pub param: String,
35}
36
37#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
39pub enum MixerMode {
40 #[default]
42 Software,
43 Hardware,
45 Script,
47 None,
49}
50
51#[derive(Debug, Clone, Default)]
53pub struct MixerSettings {
54 pub mode: MixerMode,
56 pub parameter: String,
58}
59
60#[derive(Debug, Clone)]
62pub struct PcmDevice {
63 pub idx: i32,
65 pub name: String,
67 pub description: String,
69}
70
71impl Default for PcmDevice {
72 fn default() -> Self {
73 Self {
74 idx: -1,
75 name: "default".into(),
76 description: String::new(),
77 }
78 }
79}
80
81#[derive(Debug, Clone, Default)]
83pub struct PlayerSettings {
84 pub player_name: String,
86 pub parameter: String,
88 pub latency: i32,
90 pub pcm_device: PcmDevice,
92 pub sample_format: SampleFormat,
94 pub mixer: MixerSettings,
96}
97
98#[derive(Debug, Clone)]
100pub struct LoggingSettings {
101 pub sink: String,
103 pub filter: String,
105}
106
107impl Default for LoggingSettings {
108 fn default() -> Self {
109 Self {
110 sink: "stdout".into(),
111 filter: "*:info".into(),
112 }
113 }
114}
115
116#[cfg(unix)]
118#[derive(Debug, Clone, Default)]
119pub struct DaemonSettings {
120 pub priority: Option<i32>,
122 pub user: Option<String>,
124}
125
126#[derive(Debug, Clone)]
128pub struct ClientSettings {
129 pub instance: u32,
131 pub host_id: String,
133 pub server: ServerSettings,
135 pub player: PlayerSettings,
137 pub logging: LoggingSettings,
139 #[cfg(unix)]
141 pub daemon: Option<DaemonSettings>,
142}
143
144impl Default for ServerSettings {
145 fn default() -> Self {
146 Self {
147 scheme: "tcp".into(),
148 host: String::new(),
149 port: snapcast_proto::DEFAULT_STREAM_PORT,
150 auth: None,
151 server_certificate: None,
152 certificate: None,
153 certificate_key: None,
154 key_password: None,
155 }
156 }
157}
158
159impl Default for ClientSettings {
160 fn default() -> Self {
161 Self {
162 instance: 1,
163 host_id: String::new(),
164 server: ServerSettings::default(),
165 player: PlayerSettings::default(),
166 logging: LoggingSettings::default(),
167 #[cfg(unix)]
168 daemon: None,
169 }
170 }
171}
172
173#[cfg(test)]
174mod tests {
175 use super::*;
176
177 #[test]
178 fn defaults_match_cpp() {
179 let s = ClientSettings::default();
180 assert_eq!(s.instance, 1);
181 assert_eq!(s.server.scheme, "tcp");
182 assert_eq!(s.server.port, 1704);
183 assert_eq!(s.player.latency, 0);
184 assert_eq!(s.player.pcm_device.name, "default");
185 assert_eq!(s.player.mixer.mode, MixerMode::Software);
186 assert_eq!(s.logging.filter, "*:info");
187 }
188}