Move bin/dump into a debug subcommand, read stdin instead of a file
This commit is contained in:
parent
9dbd59c313
commit
da54623006
4 changed files with 62 additions and 30 deletions
|
@ -1,29 +0,0 @@
|
|||
extern crate webmetro;
|
||||
|
||||
use std::env::args;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use webmetro::webm::{ parse_webm, SimpleBlock };
|
||||
use webmetro::webm::WebmElement::*;
|
||||
|
||||
pub fn main() {
|
||||
let mut args = args();
|
||||
let _ = args.next();
|
||||
let filename = args.next().expect("Reading filename");
|
||||
|
||||
let mut buffer = Vec::new();
|
||||
let mut file = File::open(Path::new(&filename)).expect("Opening file");
|
||||
|
||||
file.read_to_end(&mut buffer).expect("Reading file contents");
|
||||
|
||||
for element in parse_webm(buffer.as_slice()) {
|
||||
match element {
|
||||
// suppress printing byte arrays
|
||||
Tracks(slice) => println!("Tracks[{}]", slice.len()),
|
||||
SimpleBlock(SimpleBlock {timecode, ..}) => println!("SimpleBlock@{}", timecode),
|
||||
other => println!("{:?}", other)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
55
src/commands/dump.rs
Normal file
55
src/commands/dump.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use std::{
|
||||
error::Error,
|
||||
io::{self, prelude::*}
|
||||
};
|
||||
|
||||
use clap::{App, AppSettings, ArgMatches, SubCommand};
|
||||
use futures::{
|
||||
Async,
|
||||
stream::poll_fn
|
||||
};
|
||||
|
||||
use webmetro::{
|
||||
stream_parser::StreamEbml,
|
||||
webm::{
|
||||
SimpleBlock,
|
||||
WebmElement::*
|
||||
}
|
||||
};
|
||||
|
||||
pub fn options() -> App<'static, 'static> {
|
||||
SubCommand::with_name("dump")
|
||||
.setting(AppSettings::Hidden)
|
||||
.about("Dumps WebM parsing events from parsing stdin")
|
||||
}
|
||||
|
||||
pub fn run(_args: &ArgMatches) -> Result<(), Box<Error>> {
|
||||
|
||||
let stdin = io::stdin();
|
||||
let mut buf_reader = stdin.lock();
|
||||
let mut read_bytes = 0;
|
||||
|
||||
let mut events = poll_fn(|| {
|
||||
buf_reader.consume(read_bytes);
|
||||
buf_reader.fill_buf().map(|slice| {
|
||||
read_bytes = slice.len();
|
||||
if read_bytes > 0 {
|
||||
Async::Ready(Some(Into::<Vec<u8>>::into(slice)))
|
||||
} else {
|
||||
Async::Ready(None)
|
||||
}
|
||||
})
|
||||
}).parse_ebml();
|
||||
|
||||
// stdin is sync so Async::NotReady will never happen
|
||||
while let Ok(Async::Ready(Some(element))) = events.poll_event() {
|
||||
match element {
|
||||
// suppress printing byte arrays
|
||||
Tracks(slice) => println!("Tracks[{}]", slice.len()),
|
||||
SimpleBlock(SimpleBlock {timecode, ..}) => println!("SimpleBlock@{}", timecode),
|
||||
other => println!("{:?}", other)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
pub mod dump;
|
||||
pub mod relay;
|
||||
|
|
|
@ -6,7 +6,10 @@ extern crate webmetro;
|
|||
mod commands;
|
||||
|
||||
use clap::{App, AppSettings};
|
||||
use commands::{relay};
|
||||
use commands::{
|
||||
relay,
|
||||
dump
|
||||
};
|
||||
|
||||
fn options() -> App<'static, 'static> {
|
||||
App::new("webmetro")
|
||||
|
@ -14,6 +17,7 @@ fn options() -> App<'static, 'static> {
|
|||
.about("Utilities for broadcasting & relaying live WebM video/audio streams")
|
||||
.setting(AppSettings::VersionlessSubcommands)
|
||||
.subcommand(relay::options())
|
||||
.subcommand(dump::options())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -21,6 +25,7 @@ fn main() {
|
|||
|
||||
match args.subcommand() {
|
||||
("relay", Some(sub_args)) => relay::run(sub_args),
|
||||
("dump", Some(sub_args)) => dump::run(sub_args),
|
||||
_ => {
|
||||
options().print_help().unwrap();
|
||||
println!("");
|
||||
|
|
Loading…
Reference in a new issue