use crate::colour::ContainerColour;
use crate::edit::EditList;
use crate::metadata::MetadataItem;
use crate::track::{FourCc, Language, PixelAspect, TrackKind, TrackReference};
pub const IDENTITY_MATRIX: [i32; 9] = [0x10000, 0, 0, 0, 0x10000, 0, 0, 0, 0x4000_0000];
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct TrackId(pub(crate) u32);
impl TrackId {
pub const fn get(self) -> u32 {
self.0
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum VisualCodec {
Avc,
Hevc,
Av1,
}
impl VisualCodec {
pub(crate) const fn boxes(self) -> (&'static [u8; 4], &'static [u8; 4]) {
match self {
Self::Avc => (b"avc1", b"avcC"),
Self::Hevc => (b"hvc1", b"hvcC"),
Self::Av1 => (b"av01", b"av1C"),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum AudioCodec {
Aac,
Opus,
}
impl AudioCodec {
pub(crate) const fn boxes(self) -> (&'static [u8; 4], &'static [u8; 4]) {
match self {
Self::Aac => (b"mp4a", b"esds"),
Self::Opus => (b"Opus", b"dOps"),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SampleEntrySpec {
Raw(Vec<u8>),
Visual {
codec: VisualCodec,
config: Vec<u8>,
width: u16,
height: u16,
},
Audio {
codec: AudioCodec,
config: Vec<u8>,
channels: u16,
sample_rate: u32,
},
Tx3g,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum PacketFormat {
#[default]
AsIs,
PlainText,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TrackSpec {
pub kind: TrackKind,
pub handler: FourCc,
pub handler_name: String,
pub timescale: u32,
pub sample_entry: SampleEntrySpec,
pub language: Language,
pub matrix: [i32; 9],
pub display_width: u32,
pub display_height: u32,
pub pixel_aspect: Option<PixelAspect>,
pub colour: Option<ContainerColour>,
pub enabled: bool,
pub edit_list: EditList,
pub references: Vec<TrackReference>,
pub metadata: Vec<MetadataItem>,
pub packet_format: PacketFormat,
pub default_duration: Option<u32>,
}
impl TrackSpec {
pub fn new(kind: TrackKind, timescale: u32, sample_entry: SampleEntrySpec) -> Self {
let (handler, handler_name) = match kind {
TrackKind::Video => (b"vide", "VideoHandler"),
TrackKind::Audio => (b"soun", "SoundHandler"),
TrackKind::Subtitle => (b"sbtl", "SubtitleHandler"),
TrackKind::Data | TrackKind::Other => (b"meta", "DataHandler"),
};
Self {
kind,
handler: FourCc(*handler),
handler_name: handler_name.to_owned(),
timescale,
sample_entry,
language: Language::Iso639(*b"und"),
matrix: IDENTITY_MATRIX,
display_width: 0,
display_height: 0,
pixel_aspect: None,
colour: None,
enabled: true,
edit_list: EditList::default(),
references: Vec::new(),
metadata: Vec::new(),
packet_format: PacketFormat::AsIs,
default_duration: None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PacketIn<'a> {
pub data: &'a [u8],
pub pts: i64,
pub dts: i64,
pub duration: Option<u64>,
pub sync: bool,
}