Skip to main content

media_doctor/
lib.rs

1//! `media-doctor` — media diagnostics harness for DVB / MPEG-2 Transport Streams.
2//!
3//! An extensible lint-style analysis framework: individual [`Diagnostic`]s each
4//! check one rule against a TS byte-stream, producing [`Finding`]s that feed into
5//! a [`Report`]. A trivial built-in [`SyncByteCheck`] proves the
6//! harness.
7//!
8//! # Feature flags
9//!
10//! | Feature | Default | Description |
11//! |---|---|---|
12//! | `std`   | yes     | `std::error::Error` impls |
13//! | `serde` | yes     | JSON report output via `serde` / `serde_json` |
14//! | `cli`   | yes     | `clap`-based CLI binary, incl. `watch` (issue #665) |
15//!
16//! # Quick start (library)
17//!
18//! ```rust
19//! use media_doctor::{Diagnostic, Report, SyncByteCheck};
20//!
21//! let mut report = Report::new();
22//! let diag = SyncByteCheck;
23//! diag.run(&[0x47, 0x00, 0x00, 0x10], &mut report);
24//! assert!(report.findings().is_empty());
25//! ```
26
27#![cfg_attr(not(feature = "std"), no_std)]
28#![forbid(unsafe_code)]
29#![cfg_attr(docsrs, feature(doc_cfg))]
30
31extern crate alloc;
32
33mod container_codec;
34mod dash_validator;
35mod diagnostics;
36mod hls_validator;
37mod playlist;
38mod report;
39mod watch;
40
41pub use container_codec::check_container_codec;
42pub use dash_validator::check_dash_mpd;
43pub use diagnostics::cc_anomaly::CcAnomalyCheck;
44pub use diagnostics::codec_signalling::CodecSignallingCheck;
45pub use diagnostics::fps_cadence::FpsCadenceCheck;
46pub use diagnostics::interlace::InterlaceCheck;
47pub use diagnostics::param_sets::ParamSetsCheck;
48pub use diagnostics::pat_pmt_version::PatPmtVersionCheck;
49pub use diagnostics::pcr_check::PcrCheck;
50pub use diagnostics::pts_check::PtsCheck;
51pub use diagnostics::scte35_check::Scte35Check;
52pub use diagnostics::sync_byte::SyncByteCheck;
53pub use hls_validator::check_hls_playlist;
54pub use playlist::check_playlist;
55pub use report::{Finding, Location, Report, Severity};
56pub use watch::WatchState;
57
58/// A pluggable diagnostic check that examines a Transport Stream byte buffer.
59///
60/// Implementors receive the full TS byte slice (contiguous 188-byte packets, no
61/// framing gaps — `ts.len()` is a multiple of 188) and push any findings into
62/// `report`.
63pub trait Diagnostic {
64    /// Check a TS byte buffer, appending findings to `report`.
65    fn run(&self, ts: &[u8], report: &mut Report);
66}
67
68/// Run every registered [`Diagnostic`] against a TS buffer.
69///
70/// This is the simplest harness runner: it feeds the buffer through each
71/// diagnostic in order. A streaming version will follow in a later story.
72pub fn run_all(ts: &[u8], diagnostics: &[&dyn Diagnostic], report: &mut Report) {
73    for diag in diagnostics {
74        diag.run(ts, report);
75    }
76}
77
78#[cfg(feature = "cli")]
79pub mod cli;