Add SeekHead & Cluster to Webm schema

This commit is contained in:
Tangent 128 2017-04-16 16:35:48 -04:00
parent efe708ca6b
commit c567099b73

View file

@ -148,14 +148,16 @@ impl<'b, S: Schema<'b>> IntoIterator for Ebml<'b, S, &'b[u8]> {
pub struct Webm; pub struct Webm;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum WebmElement { pub enum WebmElement<'b> {
EbmlHead, EbmlHead,
Segment, Segment,
SeekHead,
Cluster(&'b[u8]),
Unknown(u64) Unknown(u64)
} }
impl<'a> Schema<'a> for Webm { impl<'a> Schema<'a> for Webm {
type Element = WebmElement; type Element = WebmElement<'a>;
fn should_unwrap(&self, element_id: u64) -> bool { fn should_unwrap(&self, element_id: u64) -> bool {
match element_id { match element_id {
@ -165,10 +167,12 @@ impl<'a> Schema<'a> for Webm {
} }
} }
fn decode<'b: 'a>(&self, element_id: u64, bytes: &'b[u8]) -> Result<WebmElement, Error> { fn decode<'b: 'a>(&self, element_id: u64, bytes: &'b[u8]) -> Result<WebmElement<'b>, Error> {
match element_id { match element_id {
0x0A45DFA3 => Ok(WebmElement::EbmlHead), 0x0A45DFA3 => Ok(WebmElement::EbmlHead),
0x08538067 => Ok(WebmElement::Segment), 0x08538067 => Ok(WebmElement::Segment),
0x014D9B74 => Ok(WebmElement::SeekHead),
0x0F43B675 => Ok(WebmElement::Cluster(bytes)),
_ => Ok(WebmElement::Unknown(element_id)) _ => Ok(WebmElement::Unknown(element_id))
} }
} }
@ -293,7 +297,8 @@ mod tests {
#[test] #[test]
fn decode_webm_test1() { fn decode_webm_test1() {
let mut iter = Ebml(Webm, TEST_FILE).into_iter(); let source = &TEST_FILE;
let mut iter = Ebml(Webm, source).into_iter();
// EBML Header // EBML Header
assert_eq!(iter.next(), Some(WebmElement::EbmlHead)); assert_eq!(iter.next(), Some(WebmElement::EbmlHead));
@ -301,7 +306,7 @@ mod tests {
assert_eq!(iter.next(), Some(WebmElement::Segment)); assert_eq!(iter.next(), Some(WebmElement::Segment));
// SeekHead // SeekHead
assert_eq!(iter.next(), Some(WebmElement::Unknown(0x014D9B74))); assert_eq!(iter.next(), Some(WebmElement::SeekHead));
} }
} }