#[derive(Debug)]
pub enum BoxData {
String(String),
AsciiString(String),
DateTime(chrono::DateTime<chrono::Utc>),
UnsignedInt(u32),
Float(f32),
Float64(f64),
SimpleBlockData(BlockData),
UncompressedFourCC(String),
}
#[derive(Debug)]
pub struct BlockData {
pub start: u64,
pub size: u64,
pub is_keyframe: bool,
pub is_invisible: bool,
pub is_discardable: bool,
pub track_number: u64,
pub timestamp: i16,
}
pub struct EbmlElement {
pub(crate) tag: Tag,
pub(crate) position: u64,
pub(crate) full_size: u64,
pub(crate) data_size: u64,
pub(crate) children: Vec<EbmlElement>,
pub(crate) box_data: Option<BoxData>,
}
impl EbmlElement {
#[inline]
pub fn tag(&self) -> Tag {
self.tag
}
#[inline]
pub fn position(&self) -> u64 {
self.position
}
#[inline]
pub fn full_size(&self) -> u64 {
self.full_size
}
#[inline]
pub fn data_size(&self) -> u64 {
self.data_size
}
#[inline]
pub fn box_data(&self) -> Option<&BoxData> {
self.box_data.as_ref()
}
#[inline]
pub fn children(&self) -> &[EbmlElement] {
&self.children
}
}
#[derive(PartialEq, Eq, Clone, Copy)]
pub struct Hex32(u32);
impl std::fmt::Debug for Hex32 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "0x{:x}", self.0)
}
}
macro_rules! impl_tags {
( $( ($name:ident, $val:expr, $dtype:expr) ),* ) => {
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Tag {
$(
$name,
)*
Other(Hex32),
}
impl Tag {
pub fn dtype(&self) -> u8 {
use Tag::*;
match self {
$(
$name => $dtype,
)*
Other(_) => b'b',
}
}
}
impl From<u32> for Tag {
fn from(id: u32) -> Tag {
use Tag::*;
match id {
$(
$val => $name,
)*
id => Other(Hex32(id)),
}
}
}
};
}
impl_tags!(
(EBML, 0x1a45_dfa3, b'm'),
(DocType, 0x4282, b'b'),
(DocTypeReadVersion, 0x4285, b'b'),
(Version, 0x4286, b'b'),
(DocTypeVersion, 0x4287, b'b'),
(ReadVersion, 0x42F7, b'b'),
(EBMLMaxIDLength, 0x42F2, b'u'),
(EBMLMaxSizeLength, 0x42F3, b'u'),
(Cues, 0x1c53_bb6b, b'm'),
(CuePoint, 0xbb, b'b'),
(Void, 0xEC, b'b'),
(Info, 0x1549_A966, b'm'),
(Segment, 0x1853_8067, b'm'),
(SeekHead, 0x114D_9B74, b'b'),
(Seek, 0x4DBB, b'b'),
(SeekID, 0x53AB, b'b'),
(SeekPosition, 0x53AC, b'b'),
(TimestampScale, 0x2ad7b1, b'u'),
(Duration, 0x4489, b'f'),
(DateUTC, 0x4461, b'd'),
(Title, 0x7BA9, b'8'),
(MuxingApp, 0x4D80, b'8'),
(WritingApp, 0x5741, b'8'),
(Tracks, 0x1654_ae6b, b'm'),
(TrackEntry, 0xAE, b'm'),
(TrackNumber, 0xD7, b'b'),
(TrackUID, 0x73c5, b'b'),
(TrackType, 0x83, b'b'),
(CodecID, 0x86, b's'),
(Video, 0xe0, b'm'),
(PixelWidth, 0xB0, b'u'),
(PixelHeight, 0xBA, b'u'),
(UncompressedFourCC, 0x2eb524, b'b'),
(GammaValue, 0x2fb523, b'f'),
(Cluster, 0x1F43_B675, b'm'),
(Timestamp, 0xE7, b'u'),
(SimpleBlock, 0xA3, b'b')
);