Serve single, unparsed video file.

This commit is contained in:
Tangent 128 2017-09-26 02:21:32 -04:00
parent c3f0de71fa
commit d20081d9a1

View file

@ -3,19 +3,20 @@ extern crate hyper;
extern crate lab_ebml; extern crate lab_ebml;
use futures::future::FutureResult; use futures::future::FutureResult;
use futures::stream::{iter, Stream}; use futures::stream::{once, Stream};
use lab_ebml::chunk::Chunk; use lab_ebml::chunk::Chunk;
use hyper::{Get, StatusCode}; use hyper::{Get, StatusCode};
use hyper::header::ContentType;
use hyper::server::{Http, Request, Response, Service}; use hyper::server::{Http, Request, Response, Service};
use std::env::args; use std::env::args;
use std::rc::Rc; use std::rc::Rc;
use std::net::ToSocketAddrs; use std::net::ToSocketAddrs;
//const SRC_FILE: &'static [u8] = include_bytes!("../data/test1.webm"); const SRC_FILE: &'static [u8] = include_bytes!("../data/test1.webm");
struct WebmServer; struct WebmServer;
type BodyStream = Box<Stream<Item = Chunk<&'static str>, Error = hyper::Error>>; type BodyStream = Box<Stream<Item = Chunk<&'static [u8]>, Error = hyper::Error>>;
impl Service for WebmServer { impl Service for WebmServer {
type Request = Request; type Request = Request;
@ -25,13 +26,9 @@ impl Service for WebmServer {
fn call(&self, req: Request) -> Self::Future { fn call(&self, req: Request) -> Self::Future {
let response = match (req.method(), req.path()) { let response = match (req.method(), req.path()) {
(&Get, "/loop") => { (&Get, "/loop") => {
let pieces = vec![ let stream: BodyStream = Box::new(once(Ok(Chunk::Headers {bytes: Rc::new(SRC_FILE)})));
Chunk::Headers {bytes: Rc::new("<")},
Chunk::Headers {bytes: Rc::new("Insert WebM stream here")},
Chunk::ClusterBody {bytes: Rc::new(">")}
];
let stream: BodyStream = Box::new(iter(pieces.into_iter().map(|x| Ok(x))));
Response::new() Response::new()
.with_header(ContentType("video/webm".parse().unwrap()))
.with_body(stream) .with_body(stream)
}, },
_ => { _ => {