use container_probe::Probe;
fn main() {
let path = std::env::args().nth(1).unwrap_or_else(|| {
concat!(env!("CARGO_MANIFEST_DIR"), "/../fixtures/ts/h264_aac.ts").to_string()
});
let data = match std::fs::read(&path) {
Ok(d) => d,
Err(e) => {
eprintln!("failed to read {path}: {e}");
std::process::exit(2);
}
};
println!("streaming probe of {path} ({} bytes total)", data.len());
println!("feeding a growing prefix, starting at 64 bytes and doubling:");
println!(" budget verdict");
let mut budget = 64usize;
loop {
let p = container_probe::probe_with_budget(&data, budget);
let full = budget >= data.len();
match &p {
Probe::Identified {
format, confidence, ..
} => {
println!(
" {budget:<8} IDENTIFIED: {} ({}) — stopping",
format.name(),
confidence.name()
);
break;
}
Probe::Insufficient { need_at_least, .. } => {
println!(" {budget:<8} Insufficient: supply >= {need_at_least} bytes (read more)");
}
Probe::Unknown => {
println!(
" {budget:<8} Unknown — a TS at this prefix would be Insufficient; unexpected"
);
}
Probe::Ambiguous { .. } => {
println!(" {budget:<8} Ambiguous; stopping");
break;
}
_ => {} }
if full {
println!(" exhausted the buffer at {budget} bytes");
break;
}
budget = budget.saturating_mul(2).min(data.len());
}
}