diff --git a/src/chunk.rs b/src/chunk.rs new file mode 100644 index 0000000..181bcb2 --- /dev/null +++ b/src/chunk.rs @@ -0,0 +1,50 @@ +use std::rc::Rc; + +pub enum Chunk { + Headers { + bytes: Rc> + }, + ClusterHead { + keyframe: bool, + start: u64, + end: u64, + // space for a Cluster tag and a Timecode tag + bytes: [u8;16] + }, + ClusterBody { + bytes: Rc> + } +} + +impl AsRef<[u8]> for Chunk { + fn as_ref(&self) -> &[u8] { + match self { + &Chunk::Headers {ref bytes, ..} => &bytes, + &Chunk::ClusterHead {ref bytes, ..} => bytes, + &Chunk::ClusterBody {ref bytes, ..} => &bytes + } + } +} + +#[cfg(test)] +mod tests { + + use chunk::*; + use std::io::Cursor; + use webm::*; + + #[test] + fn enough_space_for_header() { + let mut chunk = Chunk::ClusterHead { + keyframe: false, + start: 0, + end: 0, + bytes: [0;16] + }; + if let Chunk::ClusterHead {ref mut bytes, ..} = chunk { + let mut cursor = Cursor::new(bytes as &mut [u8]); + encode_webm_element(&WebmElement::Cluster, &mut cursor).unwrap(); + encode_webm_element(&WebmElement::Timecode(u64::max_value()), &mut cursor).unwrap(); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index b20111c..4f689c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ extern crate bytes; extern crate futures; +pub mod chunk; pub mod ebml; mod iterator; pub mod timecode_fixer;