use alloc::vec::Vec;
use super::{CodecConfig, Sample};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct TrackSpec {
pub track_id: u32,
pub timescale: u32,
pub config: CodecConfig,
pub source_pid: Option<u16>,
pub es_info_descriptors: Vec<u8>,
}
impl TrackSpec {
pub fn new(track_id: u32, timescale: u32, config: CodecConfig) -> Self {
Self {
track_id,
timescale,
config,
source_pid: None,
es_info_descriptors: Vec::new(),
}
}
pub fn with_source(mut self, source_pid: u16, es_info_descriptors: Vec<u8>) -> Self {
self.source_pid = Some(source_pid);
self.es_info_descriptors = es_info_descriptors;
self
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct Track {
pub spec: TrackSpec,
pub samples: Vec<Sample>,
pub start_decode_time: u64,
pub encryption: Option<TrackEncryption>,
}
impl Track {
pub fn new(spec: TrackSpec, samples: Vec<Sample>) -> Self {
Self {
spec,
samples,
start_decode_time: 0,
encryption: None,
}
}
pub fn new_at(spec: TrackSpec, samples: Vec<Sample>, start_decode_time: u64) -> Self {
Self {
spec,
samples,
start_decode_time,
encryption: None,
}
}
pub fn with_start_decode_time(mut self, start_decode_time: u64) -> Self {
self.start_decode_time = start_decode_time;
self
}
pub fn track_id(&self) -> u32 {
self.spec.track_id
}
pub fn timescale(&self) -> u32 {
self.spec.timescale
}
pub fn config(&self) -> &CodecConfig {
&self.spec.config
}
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct TrackEncryption {
pub scheme: crate::cenc::CencScheme,
pub tenc: crate::cenc::TrackEncryptionBox,
pub samples: Vec<crate::cenc::SampleEncryptionEntry>,
pub constant_iv_senc: crate::cenc::ConstantIvSenc,
}
impl TrackEncryption {
#[allow(clippy::too_many_arguments)]
pub fn new(
scheme: crate::cenc::CencScheme,
tenc: crate::cenc::TrackEncryptionBox,
samples: Vec<crate::cenc::SampleEncryptionEntry>,
constant_iv_senc: crate::cenc::ConstantIvSenc,
) -> Self {
Self {
scheme,
tenc,
samples,
constant_iv_senc,
}
}
}