diff options
author | metamuffin <metamuffin@disroot.org> | 2023-01-16 21:54:28 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-01-16 21:54:28 +0100 |
commit | e65619de86080d72bf81ba72311dce5325976478 (patch) | |
tree | 0296089fb71550169a896dfbc7de88e33e655f86 /matroska/src/block.rs | |
parent | 56cf07697695dea747b1c62768999e6237c55448 (diff) | |
download | jellything-e65619de86080d72bf81ba72311dce5325976478.tar jellything-e65619de86080d72bf81ba72311dce5325976478.tar.bz2 jellything-e65619de86080d72bf81ba72311dce5325976478.tar.zst |
stuff
Diffstat (limited to 'matroska/src/block.rs')
-rw-r--r-- | matroska/src/block.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/matroska/src/block.rs b/matroska/src/block.rs index e69de29..b0d6f6b 100644 --- a/matroska/src/block.rs +++ b/matroska/src/block.rs @@ -0,0 +1,43 @@ +use crate::read::ReadExt; +use anyhow::Result; +use std::io::Cursor; + +pub enum LacingType { + FixedSize, + Ebml, + Xiph, +} + +pub struct Block { + pub track: u64, + pub timestamp_off: i16, + pub invisible: bool, + pub lacing: Option<LacingType>, + pub data: Vec<u8>, +} + +impl Block { + pub fn parse(buf: &[u8]) -> Result<Self> { + let (track, c) = Cursor::new(buf).read_vint_len()?; + let timestamp_off = i16::from_be_bytes(buf[c..c + 2].try_into().unwrap()); + let flags = buf[c + 2]; + let data = Vec::from(&buf[c + 3..]); + + let invisible = (flags & 0b10000) == 0b10000; + let lacing = match flags & 0b1100 { + 0b0000 => None, + 0b0100 => Some(LacingType::Xiph), + 0b1000 => Some(LacingType::Ebml), + 0b1100 => Some(LacingType::FixedSize), + _ => unreachable!(), + }; + + Ok(Self { + track, + data, + invisible, + lacing, + timestamp_off, + }) + } +} |