From 9b1e61ff80f338183b88386bd2149e3436825f98 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Wed, 11 Apr 2018 22:47:03 -0400 Subject: [PATCH] delete bin/ toys that aren't especially useful anymore --- src/bin/loop_server.rs | 57 ------------------------- src/bin/resynth.rs | 95 ------------------------------------------ 2 files changed, 152 deletions(-) delete mode 100644 src/bin/loop_server.rs delete mode 100644 src/bin/resynth.rs diff --git a/src/bin/loop_server.rs b/src/bin/loop_server.rs deleted file mode 100644 index c290944..0000000 --- a/src/bin/loop_server.rs +++ /dev/null @@ -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>; - -impl Service for LoopServer { - type Request = Request; - type Response = Response; - type Error = hyper::Error; - type Future = FutureResult; - - 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(); -} diff --git a/src/bin/resynth.rs b/src/bin/resynth.rs deleted file mode 100644 index be77627..0000000 --- a/src/bin/resynth.rs +++ /dev/null @@ -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 - } - } -}