diff options
Diffstat (limited to 'matroska')
-rw-r--r-- | matroska/src/block.rs | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/matroska/src/block.rs b/matroska/src/block.rs index dd5b340..9e66353 100644 --- a/matroska/src/block.rs +++ b/matroska/src/block.rs @@ -3,13 +3,15 @@ use anyhow::Result; use std::io::Cursor; pub enum LacingType { + Xiph, FixedSize, Ebml, - Xiph, } pub struct Block { pub track: u64, + pub keyframe: bool, + pub discardable: bool, pub timestamp_off: i16, pub invisible: bool, pub lacing: Option<LacingType>, @@ -23,16 +25,20 @@ impl Block { 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), + let invisible = (flags & 0b1000) == 0b1000; + let lacing = match flags & 0b110 { + 0b000 => None, + 0b010 => Some(LacingType::Xiph), + 0b100 => Some(LacingType::FixedSize), + 0b110 => Some(LacingType::Ebml), _ => unreachable!(), }; + let keyframe = (flags & 0b10000000) == 0b10000000; + let discardable = (flags & 0b1) == 0b1; Ok(Self { + keyframe, + discardable, track, data, invisible, @@ -45,16 +51,23 @@ impl Block { write_vint(&mut out, self.track).unwrap(); out.extend(self.timestamp_off.to_be_bytes().into_iter()); out.push( - match self.invisible { - true => 0b10000, - false => 0b00000, + match self.discardable { + true => 0b1, + false => 0b0, + } | match self.invisible { + true => 0b10000000, + false => 0b00000000, + } | match self.invisible { + true => 0b1000, + false => 0b0000, } | match self.lacing { - Some(LacingType::Xiph) => 0b0100, - Some(LacingType::Ebml) => 0b1000, - Some(LacingType::FixedSize) => 0b1100, + Some(LacingType::Xiph) => 0b010, + Some(LacingType::Ebml) => 0b100, + Some(LacingType::FixedSize) => 0b110, None => 0b0000, }, ); + out.extend(self.data.iter()); out } } |