From b76f24402298c2cd44562171c181be1ec3cf1d29 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Mon, 7 Aug 2017 01:12:18 -0400 Subject: [PATCH] Encode Timecodes into WebM stub --- src/bin/stub.rs | 4 ++++ src/ebml.rs | 9 +++++++++ src/webm.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/src/bin/stub.rs b/src/bin/stub.rs index 3b26f35..617437c 100644 --- a/src/bin/stub.rs +++ b/src/bin/stub.rs @@ -10,6 +10,10 @@ pub fn main() { encode_webm_element(WebmElement::Segment, &mut cursor).unwrap(); encode_webm_element(WebmElement::Cluster, &mut cursor).unwrap(); + encode_webm_element(WebmElement::Timecode(0), &mut cursor).unwrap(); + + encode_webm_element(WebmElement::Cluster, &mut cursor).unwrap(); + encode_webm_element(WebmElement::Timecode(1000), &mut cursor).unwrap(); stdout().write_all(&cursor.get_ref()).unwrap(); } diff --git a/src/ebml.rs b/src/ebml.rs index 4a39625..e4b07b3 100644 --- a/src/ebml.rs +++ b/src/ebml.rs @@ -202,6 +202,15 @@ pub fn encode_string(tag: u64, string: &str, output: &mut T) -> IoResu encode_tag_header(tag, Varint::Value(string.len() as u64), output)?; output.write_all(string.as_ref()) } + +/// Tries to write a simple EBML tag with an integer value +pub fn encode_integer(tag: u64, value: u64, output: &mut T) -> IoResult<()> { + encode_tag_header(tag, Varint::Value(8), output)?; + + let mut buffer = Cursor::new([0; 8]); + buffer.put_u64::(value); + + output.write_all(&buffer.get_ref()[..]) } #[derive(Debug, PartialEq)] diff --git a/src/webm.rs b/src/webm.rs index b2f134c..9868e49 100644 --- a/src/webm.rs +++ b/src/webm.rs @@ -89,6 +89,7 @@ pub fn encode_webm_element(element: WebmElement, output: &mut T WebmElement::SeekHead => Ok(()), WebmElement::Cues => Ok(()), WebmElement::Cluster => encode_tag_header(CLUSTER_ID, Varint::Unknown, output), + WebmElement::Timecode(time) => encode_integer(TIMECODE_ID, time, output), _ => Err(IoError::new(ErrorKind::InvalidInput, WriteError::OutOfRange)) } }