use crate::config::{Builder, Format};
use crate::signal::Mode;
use std::assert_matches;
#[derive(Debug)]
#[derive_const(Clone)]
pub struct Config {
pub sample_depth: u8,
pub channel_count: u8,
pub width: u16,
pub height: u16,
pub frame_count: u32,
pub frame_rate: u32,
pub format: Format,
}
impl Config {
pub const MAX_SAMPLE_DEPTH: u32 = 2_u32.pow(u8::BITS - 1);
pub const MAX_CHANNEL_COUNT: u32 = Mode::MAX_CHANNEL_COUNT;
pub const MAX_WIDTH: u32 = Mode::MAX_WIDTH;
pub const MAX_FRAME_COUNT: u32 = Mode::MAX_FRAME_COUNT;
pub const MAX_FRAME_RATE: u32 = 2_u32.pow(u32::BITS - 1);
#[must_use]
pub fn from_builder(builder: Builder) -> Self {
let sample_depth = builder.sample_depth
.expect("expected sampling depth");
let channel_count = builder.channel_count
.expect("expected channel count");
let width = builder.width
.expect("expected frame width");
let height = builder.height
.expect("expected frame height");
let frame_count = builder.frame_count
.expect("expected frame count");
let frame_rate = builder.frame_rate
.expect("expected frame frame rate");
let format = builder.format
.expect("expected output format");
assert_matches!(
sample_depth,
1..=Self::MAX_SAMPLE_DEPTH,
"sampling depth must be non-zero and at most `{}`",
Self::MAX_SAMPLE_DEPTH,
);
assert_matches!(
channel_count,
1..=Self::MAX_CHANNEL_COUNT,
"channel count must be non-zero and at most `{}`",
Self::MAX_CHANNEL_COUNT,
);
assert_matches!(
width,
1..=Self::MAX_WIDTH,
"frame width must be non-zero and at most `{}`",
Self::MAX_WIDTH,
);
assert_matches!(
height,
1..=Self::MAX_WIDTH,
"frame height must be non-zero and at most `{}`",
Self::MAX_WIDTH,
);
assert_matches!(
frame_count,
1..=Self::MAX_FRAME_COUNT,
"frame count must be non-zero and at most `{}`",
Self::MAX_FRAME_COUNT,
);
assert_matches!(
frame_rate,
0..=Self::MAX_FRAME_RATE,
"frame count may not be greater than `{}`",
Self::MAX_FRAME_RATE,
);
Self {
sample_depth: sample_depth as u8,
channel_count: channel_count as u8,
width: width as u16,
height: height as u16,
frame_count,
frame_rate,
format,
}
}
}