delete bin/ toys that aren't especially useful anymore
This commit is contained in:
parent
f890437c17
commit
9b1e61ff80
2 changed files with 0 additions and 152 deletions
|
@ -1,57 +0,0 @@
|
||||||
extern crate futures;
|
|
||||||
extern crate hyper;
|
|
||||||
extern crate webmetro;
|
|
||||||
|
|
||||||
use std::env::args;
|
|
||||||
use std::net::ToSocketAddrs;
|
|
||||||
|
|
||||||
use futures::future::FutureResult;
|
|
||||||
use futures::stream::repeat;
|
|
||||||
use futures::stream::Stream;
|
|
||||||
use hyper::{Get, StatusCode};
|
|
||||||
use hyper::header::ContentType;
|
|
||||||
use hyper::server::{Http, Request, Response, Service};
|
|
||||||
use webmetro::chunk::{Chunk, WebmStream, ChunkingError};
|
|
||||||
use webmetro::fixers::ChunkStream;
|
|
||||||
use webmetro::stream_parser::StreamEbml;
|
|
||||||
|
|
||||||
const SRC_FILE: &'static [u8] = include_bytes!("../data/test1.webm");
|
|
||||||
|
|
||||||
struct LoopServer;
|
|
||||||
|
|
||||||
type BodyStream = Box<Stream<Item = Chunk, Error = hyper::Error>>;
|
|
||||||
|
|
||||||
impl Service for LoopServer {
|
|
||||||
type Request = Request;
|
|
||||||
type Response = Response<BodyStream>;
|
|
||||||
type Error = hyper::Error;
|
|
||||||
type Future = FutureResult<Self::Response, hyper::Error>;
|
|
||||||
|
|
||||||
fn call(&self, req: Request) -> Self::Future {
|
|
||||||
let response = match (req.method(), req.path()) {
|
|
||||||
(&Get, "/loop") => {
|
|
||||||
let stream: BodyStream = Box::new(
|
|
||||||
repeat::<&[u8], ()>(SRC_FILE).take(5)
|
|
||||||
.parse_ebml().chunk_webm().fix_timecodes().find_starting_point()
|
|
||||||
.map_err(|err| match err {
|
|
||||||
ChunkingError::IoError(io_err) => hyper::Error::Io(io_err),
|
|
||||||
ChunkingError::OtherError(_) => hyper::Error::Incomplete
|
|
||||||
})
|
|
||||||
);
|
|
||||||
Response::new()
|
|
||||||
.with_header(ContentType("video/webm".parse().unwrap()))
|
|
||||||
.with_body(stream)
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
Response::new()
|
|
||||||
.with_status(StatusCode::NotFound)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
futures::future::ok(response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
let addr = args().nth(1).expect("Need binding address+port").to_socket_addrs().unwrap().next().unwrap();
|
|
||||||
Http::new().bind(&addr, move || Ok(LoopServer)).unwrap().run().unwrap();
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
extern crate webmetro;
|
|
||||||
|
|
||||||
use std::io::{Cursor, stdout, Write};
|
|
||||||
|
|
||||||
use webmetro::webm::*;
|
|
||||||
use webmetro::webm::WebmElement::*;
|
|
||||||
|
|
||||||
const SRC_FILE: &'static [u8] = include_bytes!("../data/test1.webm");
|
|
||||||
|
|
||||||
pub fn main() {
|
|
||||||
|
|
||||||
let mut head = Vec::new();
|
|
||||||
let mut body = Vec::new();
|
|
||||||
|
|
||||||
let mut reading_head = true;
|
|
||||||
|
|
||||||
for element in parse_webm(SRC_FILE) {
|
|
||||||
match element {
|
|
||||||
Cluster => reading_head = false,
|
|
||||||
// TODO: skip elements not required for streaming
|
|
||||||
Info => continue,
|
|
||||||
Void => continue,
|
|
||||||
Unknown(_) => continue,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
if reading_head {
|
|
||||||
head.push(element);
|
|
||||||
} else {
|
|
||||||
body.push(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut cursor = Cursor::new(Vec::new());
|
|
||||||
|
|
||||||
let mut fixer = TimecodeFixer::new();
|
|
||||||
|
|
||||||
for element in &head {
|
|
||||||
encode_webm_element(fixer.process(element), &mut cursor).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
for element in &body {
|
|
||||||
encode_webm_element(fixer.process(element), &mut cursor).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
for element in &body {
|
|
||||||
encode_webm_element(fixer.process(element), &mut cursor).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut output = cursor.into_inner();
|
|
||||||
stdout().write_all(&output).unwrap();
|
|
||||||
output.clear();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TimecodeFixer {
|
|
||||||
pub current_offset: u64,
|
|
||||||
pub last_cluster_base: u64,
|
|
||||||
pub last_observed_timecode: u64,
|
|
||||||
pub assumed_duration: u64
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TimecodeFixer {
|
|
||||||
pub fn new() -> TimecodeFixer {
|
|
||||||
TimecodeFixer {
|
|
||||||
current_offset: 0,
|
|
||||||
last_cluster_base: 0,
|
|
||||||
last_observed_timecode: 0,
|
|
||||||
assumed_duration: 33
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process<'b>(&mut self, element: &WebmElement<'b>) -> WebmElement<'b> {
|
|
||||||
match element {
|
|
||||||
&WebmElement::Timecode(timecode) => {
|
|
||||||
// detect a jump backwards in the source, meaning we need to recalculate our offset
|
|
||||||
if timecode < self.last_cluster_base {
|
|
||||||
let next_timecode = self.last_observed_timecode + self.assumed_duration;
|
|
||||||
self.current_offset = next_timecode - timecode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remember the source timecode to detect future jumps
|
|
||||||
self.last_cluster_base = timecode;
|
|
||||||
|
|
||||||
// return adjusted timecode
|
|
||||||
WebmElement::Timecode(timecode + self.current_offset)
|
|
||||||
},
|
|
||||||
&WebmElement::SimpleBlock(block) => {
|
|
||||||
self.last_observed_timecode = self.last_cluster_base + (block.timecode as u64);
|
|
||||||
*element
|
|
||||||
},
|
|
||||||
_ => *element
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue