use crate::budgets::MemoryBudgets;
pub const DEFAULT_MAX_INPUT_BYTES: u64 = 1 << 30;
pub const DEFAULT_MAX_DURATION_SECS: f64 = 7200.0;
pub const DEFAULT_MAX_SAMPLE_RATE: u32 = 192_000;
pub const DEFAULT_MAX_DECODE_SAMPLE_RATE: u32 = 48_000;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ChannelMode {
#[default]
Mono,
Split,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct DecodeOptions {
pub channel_mode: ChannelMode,
pub max_duration_secs: f64,
pub max_sample_rate: u32,
pub max_decode_sample_rate: u32,
pub memory: MemoryBudgets,
}
impl Default for DecodeOptions {
fn default() -> Self {
Self {
channel_mode: ChannelMode::Mono,
max_duration_secs: DEFAULT_MAX_DURATION_SECS,
max_sample_rate: DEFAULT_MAX_SAMPLE_RATE,
max_decode_sample_rate: DEFAULT_MAX_DECODE_SAMPLE_RATE,
memory: MemoryBudgets::default(),
}
}
}
impl DecodeOptions {
#[inline]
pub fn speech() -> Self {
Self::default()
}
#[inline]
pub fn audio() -> Self {
Self {
channel_mode: ChannelMode::Split,
..Self::speech()
}
}
#[inline]
pub fn unbounded() -> Self {
Self {
channel_mode: ChannelMode::Split,
max_duration_secs: f64::INFINITY,
max_sample_rate: u32::MAX,
max_decode_sample_rate: u32::MAX,
memory: MemoryBudgets::unbounded_collection(),
}
}
#[inline]
pub fn with_channel_mode(mut self, mode: ChannelMode) -> Self {
self.channel_mode = mode;
self
}
#[inline]
pub fn with_max_duration_secs(mut self, secs: f64) -> Self {
self.max_duration_secs = secs;
self
}
#[inline]
pub fn with_max_sample_rate(mut self, rate: u32) -> Self {
self.max_sample_rate = rate;
self
}
#[inline]
pub fn with_memory(mut self, memory: MemoryBudgets) -> Self {
self.memory = memory;
self
}
}
#[path = "options_container.rs"]
mod container;
pub use container::EncodeContainer;
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct EncodeOptions {
pub container: EncodeContainer,
pub bitrate_bps: u32,
pub lookahead: bool,
pub ath: bool,
pub tonality: bool,
pub short_tns: bool,
pub short_group: bool,
pub band_refine: bool,
pub pns: bool,
pub intensity: bool,
pub he: bool,
pub ps: bool,
#[doc(hidden)]
pub ps_iid_fine: bool,
pub ld: bool,
pub quality: Option<u8>,
pub cbr: bool,
}
impl Default for EncodeOptions {
fn default() -> Self {
Self {
container: EncodeContainer::Adts,
bitrate_bps: 128_000,
lookahead: false,
ath: false,
tonality: false,
short_tns: false,
short_group: false,
band_refine: false,
pns: false,
intensity: false,
he: false,
ps: false,
ps_iid_fine: false,
ld: false,
quality: None,
cbr: false,
}
}
}
impl EncodeOptions {
#[inline]
pub fn adts() -> Self {
Self::default()
}
#[inline]
pub fn m4a() -> Self {
Self {
container: EncodeContainer::M4a,
..Self::default()
}
}
#[inline]
pub fn high_quality() -> Self {
Self::default().with_bitrate_bps(192_000)
}
#[inline]
pub fn low_rate() -> Self {
Self::default().with_bitrate_bps(48_000).with_he(true)
}
#[inline]
pub fn with_quality(mut self, level: u8) -> Self {
self.quality = Some(level);
self
}
#[inline]
pub fn raw() -> Self {
Self {
container: EncodeContainer::Raw,
..Self::default()
}
}
#[inline]
pub fn with_container(mut self, container: EncodeContainer) -> Self {
self.container = container;
self
}
#[inline]
pub fn with_bitrate_bps(mut self, bps: u32) -> Self {
self.bitrate_bps = bps;
self
}
#[inline]
pub fn with_lookahead(mut self, on: bool) -> Self {
self.lookahead = on;
self
}
#[inline]
pub fn with_ath(mut self, on: bool) -> Self {
self.ath = on;
self
}
#[inline]
pub fn with_tonality(mut self, on: bool) -> Self {
self.tonality = on;
self
}
#[inline]
pub fn with_short_tns(mut self, on: bool) -> Self {
self.short_tns = on;
self
}
#[inline]
pub fn with_short_group(mut self, on: bool) -> Self {
self.short_group = on;
self
}
#[inline]
pub fn with_band_refine(mut self, on: bool) -> Self {
self.band_refine = on;
self
}
#[inline]
pub fn with_pns(mut self, on: bool) -> Self {
self.pns = on;
self
}
#[inline]
pub fn with_intensity(mut self, on: bool) -> Self {
self.intensity = on;
self
}
}
#[path = "options_cbr.rs"]
mod cbr_opt;
#[path = "options_he.rs"]
mod he_v2;
#[path = "options_ld.rs"]
mod ld;
#[path = "options_validate.rs"]
mod validate;
#[cfg(test)]
#[path = "options_tests.rs"]
mod options_tests;