From d015e8245291247ba5907fa90720d027fde0cd07 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 16 May 2023 09:34:49 +0200 Subject: cue drift fixed. YAYYY! --- matroska/src/write.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'matroska') diff --git a/matroska/src/write.rs b/matroska/src/write.rs index 8fc17c3..63cec2b 100644 --- a/matroska/src/write.rs +++ b/matroska/src/write.rs @@ -90,13 +90,15 @@ impl MatroskaTag { pub fn write_full(&self, w: &mut Vec) -> Result<()> { let mut buf = vec![]; buf.extend(self.id().to_be_bytes().iter().skip_while(|&v| *v == 0u8)); - // note: it is relevant here, to pass the buffer with the id, such that closing tags, can clear it + //* note: it is relevant here, to pass the buffer with the id, such that closing tags, can clear it self.write(&mut buf)?; w.extend_from_slice(&buf); Ok(()) } } +/// this routine works only, if the varint is as small as it can possibly be. +/// thats not always what we do though - see below pub fn vint_length(v: u64) -> usize { let mut len = 1; while len <= 8 { @@ -107,8 +109,17 @@ pub fn vint_length(v: u64) -> usize { } len } +pub fn bad_vint_length(v: u64) -> usize { + match 64 - v.leading_zeros() { + x if x <= 8 => 1, + x if x <= 16 => 2, + x if x <= 32 => 4, + _ => 8, + } +} pub trait WriteValue { + /// writes the contents of a tag, including the size but excluding the id. fn write_to(&self, w: &mut Vec) -> Result<()>; } -- cgit v1.2.3-70-g09d2