Implement core of filter subcommand

This commit is contained in:
Tangent 128 2018-04-12 02:03:46 -04:00
parent bac34e94c5
commit 413375102e
3 changed files with 47 additions and 0 deletions

43
src/commands/filter.rs Normal file
View file

@ -0,0 +1,43 @@
use std::{
error::Error,
io,
io::prelude::*
};
use clap::{App, ArgMatches, SubCommand};
use futures::Stream;
use super::StdinStream;
use webmetro::{
chunk::{
Chunk,
WebmStream
},
fixers::ChunkStream,
stream_parser::StreamEbml
};
pub fn options() -> App<'static, 'static> {
SubCommand::with_name("filter")
.about("Copies WebM from stdin to stdout, applying the same cleanup & stripping the relay server does.")
}
pub fn run(_args: &ArgMatches) -> Result<(), Box<Error>> {
let stdin = io::stdin();
let chunk_stream: Box<Stream<Item = Chunk, Error = Box<Error>>> = Box::new(
StdinStream::new(stdin.lock())
.parse_ebml()
.chunk_webm()
.map_err(|err| Box::new(err) as Box<Error>)
.fix_timecodes()
);
let stdout = io::stdout();
let mut stdout_writer = stdout.lock();
for chunk in chunk_stream.wait() {
stdout_writer.write_all(chunk?.as_ref())?;
}
Ok(())
}

View file

@ -10,6 +10,7 @@ use futures::{
}; };
pub mod dump; pub mod dump;
pub mod filter;
pub mod relay; pub mod relay;
/// A hackish adapter that makes chunks of bytes from stdin available as a Stream; /// A hackish adapter that makes chunks of bytes from stdin available as a Stream;

View file

@ -8,6 +8,7 @@ mod commands;
use clap::{App, AppSettings}; use clap::{App, AppSettings};
use commands::{ use commands::{
relay, relay,
filter,
dump dump
}; };
@ -17,6 +18,7 @@ fn options() -> App<'static, 'static> {
.about("Utilities for broadcasting & relaying live WebM video/audio streams") .about("Utilities for broadcasting & relaying live WebM video/audio streams")
.setting(AppSettings::VersionlessSubcommands) .setting(AppSettings::VersionlessSubcommands)
.subcommand(relay::options()) .subcommand(relay::options())
.subcommand(filter::options())
.subcommand(dump::options()) .subcommand(dump::options())
} }
@ -24,6 +26,7 @@ fn main() {
let args = options().get_matches(); let args = options().get_matches();
match args.subcommand() { match args.subcommand() {
("filter", Some(sub_args)) => filter::run(sub_args),
("relay", Some(sub_args)) => relay::run(sub_args), ("relay", Some(sub_args)) => relay::run(sub_args),
("dump", Some(sub_args)) => dump::run(sub_args), ("dump", Some(sub_args)) => dump::run(sub_args),
_ => { _ => {