use crate::types::{AudioCodec, ChannelId};
use std::time::Duration;
use teamtalk_sys as ffi;
#[derive(Clone, Debug)]
pub enum RecordingSampleFormat {
PcmS16Le,
WavS16Le,
}
#[derive(Clone, Debug)]
pub enum RecordingTarget {
Channel(ChannelId),
CurrentChannel,
Streams {
stream_types: u32,
codec: AudioCodec,
},
Muxed { codec: AudioCodec },
}
#[derive(Clone, Debug)]
pub struct RecordingOptions {
pub template: String,
pub format: ffi::AudioFileFormat,
pub start_index: u32,
pub max_duration: Option<Duration>,
pub max_size_bytes: Option<u64>,
pub rotate_on_channel_change: bool,
pub rotate_on_codec_change: bool,
}
impl RecordingOptions {
pub fn new(template: impl Into<String>, format: ffi::AudioFileFormat) -> Self {
Self {
template: template.into(),
format,
start_index: 1,
max_duration: None,
max_size_bytes: None,
rotate_on_channel_change: true,
rotate_on_codec_change: true,
}
}
pub fn with_max_duration(mut self, duration: Duration) -> Self {
self.max_duration = Some(duration);
self
}
pub fn with_max_size_bytes(mut self, size: u64) -> Self {
self.max_size_bytes = Some(size);
self
}
}
pub(crate) fn segment_path(template: &str, index: u32) -> String {
if template.contains("{index}") {
return template.replace("{index}", &index.to_string());
}
let base = template.to_string();
if let Some(pos) = base.rfind('.') {
let (stem, ext) = base.split_at(pos);
format!("{stem}.part{index}{ext}")
} else {
format!("{base}.part{index}")
}
}