Skip to main content

dvb_t2mi/
lib.rs

1//! ETSI TS 102 773 v1.4.1 DVB-T2 Modulator Interface (T2-MI) parser + builder.
2//!
3//! Entry points:
4//! - [`Parse`](dvb_common::Parse) / [`Serialize`](dvb_common::Serialize) — the two
5//!   symmetric contracts every payload type implements.
6//! - [`packet`] — T2-MI packet header and type parsing.
7//! - [`payload`] — BBFrame, L1, FEF, timestamp, and addressing payload types.
8//! - [`crc`] — CRC-32 per Annex A.
9//!
10//! # RFU policy
11//!
12//! Payload parsers REJECT non-zero reserved (rfu) bits with
13//! `ReservedBitsViolation` and serialize them as 0 — with one deliberate
14//! exception: individual addressing (0x21) PRESERVES its leading rfu byte
15//! verbatim so gateway streams round-trip byte-exact (see
16//! `payload::individual_addressing`).
17//!
18//! # Quickstart: pump a TS, get typed payloads
19//!
20//! [`pump::T2miPump`] filters a TS by PID, reassembles + CRC-validates T2-MI
21//! packets, and hands back events whose [`payload`](pump::T2miEvent::payload)
22//! dispatches to a typed [`payload::AnyPayload`]:
23//!
24//! ```no_run
25//! # #[cfg(feature = "ts")] {
26//! use dvb_t2mi::pump::T2miPump;
27//! use dvb_t2mi::payload::AnyPayload;
28//!
29//! let mut pump = T2miPump::new(0x0006); // T2-MI PID from the PMT
30//! # let ts_packets: Vec<[u8; 188]> = Vec::new();
31//! for packet in &ts_packets {          // each aligned 188-byte TS packet
32//!     for event in pump.feed_ts(packet) {
33//!         if let Ok(AnyPayload::Bbframe(bb)) = event.payload() {
34//!             println!("BBFrame plp_id={}", bb.plp_id);
35//!         }
36//!     }
37//! }
38//! # }
39//! ```
40//!
41//! # The full signal chain
42//!
43//! T2-MI carries DVB-T2 BBFrames, which carry the inner MPEG-TS, which carries
44//! SI. The crates compose end to end — T2-MI here, BBFrame extraction in
45//! [`dvb-bbframe`](https://docs.rs/dvb-bbframe), SI demux in
46//! [`dvb-si`](https://docs.rs/dvb-si):
47//!
48//! ```text
49//! TS (T2-MI PID) ─▶ T2miPump ─▶ AnyPayload::Bbframe
50//!                                   │ bb.bbframe
51//!                                   ▼
52//!                          dvb_bbframe::Bbheader::parse + up_iter
53//!                                   │ inner TS packets
54//!                                   ▼
55//!                          dvb_si::demux::SiDemux ─▶ AnyTableSection
56//! ```
57//!
58//! A complete, working version of this chain (synthetic fixture, every layer
59//! built and asserted) lives in `dvb-t2mi/tests/chain.rs`.
60//!
61//! # Features
62//!
63//! | Feature | Default | Enables |
64//! |---|---|---|
65//! | `ts` | on | [`pump::T2miPump`] — PID-filtered TS reassembly + CRC validation. Off → bring your own complete T2-MI packet bytes. |
66//! | `serde` | on | **Serialize-only** — for display/export (JSON via serde_json); parsing FROM JSON is deliberately unsupported, re-parse from wire bytes. `Serialize` on every packet/payload type. |
67//! | `yoke` | off | [`yoke::Yokeable`] on the zero-copy payload view types — own a parsed T2-MI payload past the input buffer's borrow without re-parsing. |
68//!
69//! # Header-only example
70//!
71//! ```
72//! use dvb_t2mi::packet::Header;
73//! use dvb_common::Parse;
74//! let buf = [0x00u8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
75//! let hdr = Header::parse(&buf[..]).unwrap();
76//! assert_eq!(hdr.payload_len_bits, 0);
77//! ```
78
79#![warn(missing_docs)]
80
81pub mod crc;
82pub mod error;
83pub mod packet;
84pub mod payload;
85pub mod traits;
86
87#[cfg(feature = "ts")]
88pub mod pump;
89
90#[cfg(feature = "ts")]
91pub mod ts;
92
93pub use error::{Error, Result};