Treat WebmElements as value types
This commit is contained in:
parent
45012385c2
commit
7b9df1e269
4 changed files with 27 additions and 27 deletions
|
@ -37,15 +37,15 @@ pub fn main() {
|
|||
let mut fixer = TimecodeFixer::new();
|
||||
|
||||
for element in &head {
|
||||
encode_webm_element(&fixer.process(element), &mut cursor).unwrap();
|
||||
encode_webm_element(fixer.process(element), &mut cursor).unwrap();
|
||||
}
|
||||
|
||||
for element in &body {
|
||||
encode_webm_element(&fixer.process(element), &mut cursor).unwrap();
|
||||
encode_webm_element(fixer.process(element), &mut cursor).unwrap();
|
||||
}
|
||||
|
||||
for element in &body {
|
||||
encode_webm_element(&fixer.process(element), &mut cursor).unwrap();
|
||||
encode_webm_element(fixer.process(element), &mut cursor).unwrap();
|
||||
}
|
||||
|
||||
output = cursor.into_inner();
|
||||
|
|
|
@ -6,23 +6,23 @@ use lab_ebml::webm::*;
|
|||
pub fn main() {
|
||||
let mut cursor = Cursor::new(Vec::new());
|
||||
|
||||
encode_webm_element(&WebmElement::EbmlHead, &mut cursor).unwrap();
|
||||
encode_webm_element(&WebmElement::Segment, &mut cursor).unwrap();
|
||||
encode_webm_element(WebmElement::EbmlHead, &mut cursor).unwrap();
|
||||
encode_webm_element(WebmElement::Segment, &mut cursor).unwrap();
|
||||
|
||||
encode_webm_element(&WebmElement::Tracks(&[]), &mut cursor).unwrap();
|
||||
encode_webm_element(WebmElement::Tracks(&[]), &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(0), &mut cursor).unwrap();
|
||||
|
||||
encode_webm_element(&WebmElement::SimpleBlock(SimpleBlock {
|
||||
encode_webm_element(WebmElement::SimpleBlock(SimpleBlock {
|
||||
track: 3,
|
||||
flags: 0x0,
|
||||
timecode: 123,
|
||||
data: "Hello, World".as_bytes()
|
||||
}), &mut cursor).unwrap();
|
||||
|
||||
encode_webm_element(&WebmElement::Cluster, &mut cursor).unwrap();
|
||||
encode_webm_element(&WebmElement::Timecode(1000), &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();
|
||||
}
|
||||
|
|
10
src/chunk.rs
10
src/chunk.rs
|
@ -33,8 +33,8 @@ impl ClusterHead {
|
|||
self.end = self.start + delta;
|
||||
let mut cursor = Cursor::new(self.bytes.as_mut());
|
||||
// buffer is sized so these should never fail
|
||||
encode_webm_element(&WebmElement::Cluster, &mut cursor).unwrap();
|
||||
encode_webm_element(&WebmElement::Timecode(timecode), &mut cursor).unwrap();
|
||||
encode_webm_element(WebmElement::Cluster, &mut cursor).unwrap();
|
||||
encode_webm_element(WebmElement::Timecode(timecode), &mut cursor).unwrap();
|
||||
self.bytes_used = cursor.position() as u8;
|
||||
}
|
||||
pub fn observe_simpleblock_timecode(&mut self, timecode: i16) {
|
||||
|
@ -120,7 +120,7 @@ impl<'a, S: EbmlEventSource> Stream for WebmChunker<S>
|
|||
Ok(Async::Ready(Some(WebmElement::Info))) => continue,
|
||||
Ok(Async::Ready(Some(WebmElement::Void))) => continue,
|
||||
Ok(Async::Ready(Some(element @ _))) => {
|
||||
match encode_webm_element(&element, buffer) {
|
||||
match encode_webm_element(element, buffer) {
|
||||
Ok(_) => continue,
|
||||
Err(err) => (
|
||||
Err(ChunkingError::IoError(err)),
|
||||
|
@ -152,7 +152,7 @@ impl<'a, S: EbmlEventSource> Stream for WebmChunker<S>
|
|||
cluster_head.keyframe = true;
|
||||
}
|
||||
cluster_head.observe_simpleblock_timecode(block.timecode);
|
||||
match encode_webm_element(&WebmElement::SimpleBlock(*block), buffer) {
|
||||
match encode_webm_element(WebmElement::SimpleBlock(*block), buffer) {
|
||||
Ok(_) => continue,
|
||||
Err(err) => (
|
||||
Err(ChunkingError::IoError(err)),
|
||||
|
@ -164,7 +164,7 @@ impl<'a, S: EbmlEventSource> Stream for WebmChunker<S>
|
|||
Ok(Async::Ready(Some(WebmElement::Void))) => continue,
|
||||
Ok(Async::Ready(Some(WebmElement::Unknown(_)))) => continue,
|
||||
Ok(Async::Ready(Some(element @ _))) => {
|
||||
match encode_webm_element(&element, buffer) {
|
||||
match encode_webm_element(element, buffer) {
|
||||
Ok(_) => continue,
|
||||
Err(err) => (
|
||||
Err(ChunkingError::IoError(err)),
|
||||
|
|
22
src/webm.rs
22
src/webm.rs
|
@ -86,8 +86,8 @@ fn decode_simple_block(bytes: &[u8]) -> Result<WebmElement, EbmlError> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn encode_simple_block<T: Write>(block: &SimpleBlock, output: &mut T) -> IoResult<()> {
|
||||
let &SimpleBlock {
|
||||
pub fn encode_simple_block<T: Write>(block: SimpleBlock, output: &mut T) -> IoResult<()> {
|
||||
let SimpleBlock {
|
||||
track,
|
||||
timecode,
|
||||
flags,
|
||||
|
@ -111,18 +111,18 @@ pub fn encode_simple_block<T: Write>(block: &SimpleBlock, output: &mut T) -> IoR
|
|||
output.write_all(data)
|
||||
}
|
||||
|
||||
pub fn encode_webm_element<T: Write + Seek>(element: &WebmElement, output: &mut T) -> IoResult<()> {
|
||||
pub fn encode_webm_element<T: Write + Seek>(element: WebmElement, output: &mut T) -> IoResult<()> {
|
||||
match element {
|
||||
&WebmElement::EbmlHead => encode_element(EBML_HEAD_ID, output, |output| {
|
||||
WebmElement::EbmlHead => encode_element(EBML_HEAD_ID, output, |output| {
|
||||
encode_bytes(DOC_TYPE_ID, "webm".as_bytes(), output)
|
||||
}),
|
||||
&WebmElement::Segment => encode_tag_header(SEGMENT_ID, Varint::Unknown, output),
|
||||
&WebmElement::SeekHead => Ok(()),
|
||||
&WebmElement::Cues => Ok(()),
|
||||
&WebmElement::Tracks(data) => encode_bytes(TRACKS_ID, data, output),
|
||||
&WebmElement::Cluster => encode_tag_header(CLUSTER_ID, Varint::Unknown, output),
|
||||
&WebmElement::Timecode(time) => encode_integer(TIMECODE_ID, time, output),
|
||||
&WebmElement::SimpleBlock(ref block) => encode_simple_block(block, output),
|
||||
WebmElement::Segment => encode_tag_header(SEGMENT_ID, Varint::Unknown, output),
|
||||
WebmElement::SeekHead => Ok(()),
|
||||
WebmElement::Cues => Ok(()),
|
||||
WebmElement::Tracks(data) => encode_bytes(TRACKS_ID, data, output),
|
||||
WebmElement::Cluster => encode_tag_header(CLUSTER_ID, Varint::Unknown, output),
|
||||
WebmElement::Timecode(time) => encode_integer(TIMECODE_ID, time, output),
|
||||
WebmElement::SimpleBlock(block) => encode_simple_block(block, output),
|
||||
_ => Err(IoError::new(ErrorKind::InvalidInput, WriteError::OutOfRange))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue