termusiclib/config/v2/server/backends.rs
1use bytesize::ByteSize;
2use serde::{Deserialize, Serialize};
3
4/// Settings specific to a backend
5#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Default)]
6#[serde(default)] // allow missing fields and fill them with the `..Self::default()` in this struct
7pub struct BackendSettings {
8 pub rusty: RustyBackendSettings,
9 pub mpv: MpvBackendSettings,
10 #[serde(skip)] // skip as long as there are no values
11 pub gst: GstBackendSettings,
12}
13
14/// Default Buffer capacity in bytes
15///
16/// 1024 * 1024 * 4 = 4 MiB
17///
18/// [`BufReader`]'s default size is 8 Kib
19pub const FILEBUF_SIZE_DEFAULT: u64 = 1024 * 1024 * 4;
20
21/// The minimal and default size the decode-ringbuffer should have.
22///
23/// Currently the size is based on 192kHz * 1 channel * 1 seconds, or 2 seconds of 48kHz stereo(2 channel) audio.
24// NOTE: this may desync with the actual `MIN_RING_SIZE` if the type or message size should change, and that should be consulted instead
25pub const DECODEDBUF_SIZE_DEFAULT: u64 = 192_000 * size_of::<f32>() as u64;
26
27/// Settings specific to the `rusty` backend
28#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
29#[serde(default)] // allow missing fields and fill them with the `..Self::default()` in this struct
30pub struct RustyBackendSettings {
31 /// Enable or disable `soundtouch`; only has a effect if `rusty-soundtouch` is compiled-in
32 pub soundtouch: bool,
33 /// Set the buffer size for the raw file.
34 /// This value will be clamped to the actual file's size.
35 /// Note this only applies to local files like music or downloaded podcasts. Does not apply to streamed podcasts or radio.
36 ///
37 /// If the given value is less than the default, the default will be used instead.
38 pub file_buffer_size: ByteSize,
39 /// Set the decoded ring buffer size.
40 /// This controls how many decoded audio bytes are stored.
41 /// Unlike `file_buffer_size`, this buffer will always be this size, regardless if there is less data.
42 /// Note this only applies to local files like music or downloaded podcasts. Does not apply to streamed podcasts or radio.
43 ///
44 /// If the given value is less than the default, the default will be used instead.
45 pub decoded_buffer_size: ByteSize,
46 /// Set the preferred output sample rate.
47 ///
48 /// Default `48_000`
49 /// Recommeded Values: `44_100`, `48_000`, `96_000` `192_000`.
50 pub output_sample_rate: u32,
51}
52
53impl Default for RustyBackendSettings {
54 fn default() -> Self {
55 Self {
56 soundtouch: true,
57 file_buffer_size: ByteSize::b(FILEBUF_SIZE_DEFAULT),
58 decoded_buffer_size: ByteSize::b(DECODEDBUF_SIZE_DEFAULT),
59 output_sample_rate: 48_000,
60 }
61 }
62}
63
64/// Settings specific to the `mpv` backend
65#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
66#[serde(default)] // allow missing fields and fill them with the `..Self::default()` in this struct
67pub struct MpvBackendSettings {
68 /// Select the audio device mpv should be using, analog to mpv's `--audio-device=` option.
69 ///
70 /// See all available options for mpv by running `mpv --audio-device=help`
71 ///
72 /// Default: `auto`
73 pub audio_device: String,
74}
75
76impl Default for MpvBackendSettings {
77 fn default() -> Self {
78 Self {
79 audio_device: "auto".to_string(),
80 }
81 }
82}
83
84/// Settings specific to the `gst` backend
85#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Default)]
86#[serde(default)] // allow missing fields and fill them with the `..Self::default()` in this struct
87pub struct GstBackendSettings {
88 // None for now
89}