Create Chunk type for use in packaging WebM streams for clients.

This commit is contained in:
Tangent 128 2017-09-22 23:58:03 -04:00
parent db1731f776
commit 0a18cb408f
2 changed files with 51 additions and 0 deletions

50
src/chunk.rs Normal file
View File

@ -0,0 +1,50 @@
use std::rc::Rc;
pub enum Chunk {
Headers {
bytes: Rc<Vec<u8>>
},
ClusterHead {
keyframe: bool,
start: u64,
end: u64,
// space for a Cluster tag and a Timecode tag
bytes: [u8;16]
},
ClusterBody {
bytes: Rc<Vec<u8>>
}
}
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();
}
}
}

View File

@ -2,6 +2,7 @@
extern crate bytes;
extern crate futures;
pub mod chunk;
pub mod ebml;
mod iterator;
pub mod timecode_fixer;