diff --git a/src/bin/loop_server.rs b/src/bin/loop_server.rs index 7dceff5..df62043 100644 --- a/src/bin/loop_server.rs +++ b/src/bin/loop_server.rs @@ -6,6 +6,7 @@ use futures::future::FutureResult; use futures::stream::{once, iter, Stream}; use lab_ebml::chunk::Chunk; use lab_ebml::Schema; +use lab_ebml::timecode_fixer::ChunkStream; use lab_ebml::webm::*; use lab_ebml::webm::WebmElement::*; use hyper::{Get, StatusCode}; @@ -36,6 +37,7 @@ impl Service for WebmServer { once(Ok(self.0.clone())) .chain(iter(results.into_iter().cycle().take(20))) .map_err(|_| hyper::Error::Incomplete) + .fix_timecodes() ); Response::new() .with_header(ContentType("video/webm".parse().unwrap())) diff --git a/src/timecode_fixer.rs b/src/timecode_fixer.rs index b379dd5..136dd36 100644 --- a/src/timecode_fixer.rs +++ b/src/timecode_fixer.rs @@ -1,4 +1,6 @@ -// TODO: (iterator? stream?) adapter that fixes SimpleBlock/Cluster timecodes +use chunk::Chunk; +use futures::Async; +use futures::stream::Stream; use webm::WebmElement; pub struct TimecodeFixer { @@ -41,3 +43,29 @@ impl TimecodeFixer { } } } + +pub struct ChunkTimecodeFixer { + stream: S +} + +impl> Stream for ChunkTimecodeFixer +{ + type Item = S::Item; + type Error = S::Error; + + fn poll(&mut self) -> Result>, Self::Error> { + self.stream.poll() + } +} + +pub trait ChunkStream { + fn fix_timecodes(self) -> ChunkTimecodeFixer; +} + +impl> ChunkStream for T { + fn fix_timecodes(self) -> ChunkTimecodeFixer { + ChunkTimecodeFixer { + stream: self + } + } +}