Create stub stream operator to bolt on fixing chunk timecodes

This commit is contained in:
Tangent 128 2017-09-30 02:33:36 -04:00
parent 3e1bec93ee
commit bad7b42e5b
2 changed files with 31 additions and 1 deletions

View File

@ -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()))

View File

@ -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<S> {
stream: S
}
impl<S: Stream<Item = Chunk>> Stream for ChunkTimecodeFixer<S>
{
type Item = S::Item;
type Error = S::Error;
fn poll(&mut self) -> Result<Async<Option<Self::Item>>, Self::Error> {
self.stream.poll()
}
}
pub trait ChunkStream<T> {
fn fix_timecodes(self) -> ChunkTimecodeFixer<T>;
}
impl<T: Stream<Item = Chunk>> ChunkStream<T> for T {
fn fix_timecodes(self) -> ChunkTimecodeFixer<T> {
ChunkTimecodeFixer {
stream: self
}
}
}