Skip to content

Commit

Permalink
prepare for configurable streamsize
Browse files Browse the repository at this point in the history
See #120
  • Loading branch information
dheijl committed Feb 28, 2024
1 parent 9027770 commit a5ffda7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/enums/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ impl fmt::Display for StreamingFormat {
}
}
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StreamSize {
NoneChunked,
U32maxChunked,
U32maxNotChunked,
U64maxChunked,
U64maxNotChunked,
}

impl fmt::Display for StreamSize {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
StreamSize::NoneChunked => write!(f, "NoneChunked"),
StreamSize::U32maxChunked => write!(f, "U32maxChunked"),
StreamSize::U32maxNotChunked => write!(f, "U32maxNotChunked"),
StreamSize::U64maxChunked => write!(f, "U64maxChunked"),
StreamSize::U64maxNotChunked => write!(f, "U64maxNotChunked"),
}
}
}
43 changes: 35 additions & 8 deletions src/utils/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{enums::streaming::StreamingFormat, globals::statics::SERVER_PORT};
use crate::{
enums::streaming::StreamSize, enums::streaming::StreamingFormat, globals::statics::SERVER_PORT,
};
use lexopt::{prelude::*, Parser};
use log::LevelFilter;
use serde::{Deserialize, Serialize};
Expand All @@ -13,17 +15,31 @@ use toml::from_str;
const CONFIGFILE: &str = "config{}.toml";
const PKGNAME: &str = env!("CARGO_PKG_NAME");

// default values for Serde
struct CfgDefaults {}

impl CfgDefaults {
fn disable_chunked() -> bool {
true
}
pub fn log_level() -> LevelFilter {
LevelFilter::Info
}
pub fn ssdp_interval_mins() -> f64 {
10.0
}
pub fn stream_size() -> StreamSize {
StreamSize::U64maxNotChunked
}
}

// the configuration struct, read from and saved in config.ini
#[derive(Deserialize, Serialize, Clone, Debug)]
struct Config {
#[serde(alias = "Configuration")]
pub configuration: Configuration,
}

fn disable_chunked() -> bool {
true
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct Configuration {
#[serde(alias = "ServerPort")]
Expand All @@ -34,15 +50,25 @@ pub struct Configuration {
pub sound_source: String,
#[serde(alias = "SoundCardIndex")]
pub sound_source_index: Option<i32>,
#[serde(alias = "LogLevel")]
#[serde(alias = "LogLevel", default = "CfgDefaults::log_level")]
pub log_level: LevelFilter,
#[serde(alias = "SSDPIntervalMins")]
#[serde(
alias = "SSDPIntervalMins",
default = "CfgDefaults::ssdp_interval_mins"
)]
pub ssdp_interval_mins: f64,
#[serde(alias = "AutoReconnect")]
pub auto_reconnect: bool,
// removed in 1.8.5
#[serde(alias = "DisableChunked", skip, default = "disable_chunked")]
#[serde(
alias = "DisableChunked",
skip,
default = "CfgDefaults::disable_chunked"
)]
_disable_chunked: bool,
// added in 1.9.9
#[serde(alias = "StreamSize", default = "CfgDefaults::stream_size")]
pub stream_size: StreamSize,
#[serde(alias = "UseWaveFormat")]
pub use_wave_format: bool,
#[serde(alias = "BitsPerSample")]
Expand Down Expand Up @@ -83,6 +109,7 @@ impl Configuration {
ssdp_interval_mins: 10.0,
auto_reconnect: false,
_disable_chunked: true,
stream_size: StreamSize::U64maxNotChunked,
use_wave_format: false,
bits_per_sample: Some(16),
streaming_format: Some(StreamingFormat::Lpcm),
Expand Down

0 comments on commit a5ffda7

Please sign in to comment.