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    #[serde(skip)] // skip as long as there are no values
10    pub mpv: MpvBackendSettings,
11    #[serde(skip)] // skip as long as there are no values
12    pub gst: GstBackendSettings,
13}
14
15/// Default Buffer capacity in bytes
16///
17/// 1024 * 1024 * 4 = 4 MiB
18///
19/// [`BufReader`]'s default size is 8 Kib
20pub const FILEBUF_SIZE_DEFAULT: u64 = 1024 * 1024 * 4;
21
22/// The minimal and default size the decode-ringbuffer should have.
23///
24/// Currently the size is based on 192kHz * 1 channel * 1 seconds, or 2 seconds of 48kHz stereo(2 channel) audio.
25// NOTE: this may desync with the actual `MIN_RING_SIZE` if the type or message size should change, and that should be consulted instead
26pub const DECODEDBUF_SIZE_DEFAULT: u64 = 192_000 * size_of::<f32>() as u64;
27
28/// Settings specific to the `rusty` backend
29#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
30#[serde(default)] // allow missing fields and fill them with the `..Self::default()` in this struct
31pub struct RustyBackendSettings {
32    /// Enable or disable `soundtouch`; only has a effect if `rusty-soundtouch` is compiled-in
33    pub soundtouch: bool,
34    /// Set the buffer size for the raw file.
35    /// This value will be clamped to the actual file's size.
36    /// Note this only applies to local files like music or downloaded podcasts. Does not apply to streamed podcasts or radio.
37    ///
38    /// If the given value is less than the default, the default will be used instead.
39    pub file_buffer_size: ByteSize,
40    /// Set the decoded ring buffer size.
41    /// This controls how many decoded audio bytes are stored.
42    /// Unlike `file_buffer_size`, this buffer will always be this size, regardless if there is less data.
43    /// Note this only applies to local files like music or downloaded podcasts. Does not apply to streamed podcasts or radio.
44    ///
45    /// If the given value is less than the default, the default will be used instead.
46    pub decoded_buffer_size: ByteSize,
47}
48
49impl Default for RustyBackendSettings {
50    fn default() -> Self {
51        Self {
52            soundtouch: true,
53            file_buffer_size: ByteSize::b(FILEBUF_SIZE_DEFAULT),
54            decoded_buffer_size: ByteSize::b(DECODEDBUF_SIZE_DEFAULT),
55        }
56    }
57}
58
59/// Settings specific to the `mpv` backend
60#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Default)]
61#[serde(default)] // allow missing fields and fill them with the `..Self::default()` in this struct
62pub struct MpvBackendSettings {
63    // None for now
64}
65
66/// Settings specific to the `gst` backend
67#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Default)]
68#[serde(default)] // allow missing fields and fill them with the `..Self::default()` in this struct
69pub struct GstBackendSettings {
70    // None for now
71}