mpeg-ts 0.11.0

MPEG-2 Transport Stream framing (ITU-T H.222.0 / ISO/IEC 13818-1): TS packet, adaptation field, PCR, PSI section reassembly + packetisation, resync. no_std.
Documentation
//! MPEG-2 Transport Stream framing (ITU-T H.222.0 / ISO/IEC 13818-1 §2.4.3):
//! 188-byte packet headers, adaptation fields, PCR, PSI section reassembly and
//! packetisation, and byte-stream resync. It sits below `dvb-si` (which
//! interprets table bodies), `mpeg-pes`, `dvb-conformance` and `transmux`; it
//! depends only on `broadcast-core`, `broadcast-common`, `bytes` and
//! `thiserror`, and does no I/O.
//!
//! # Quickstart
//!
//! Parse a TS packet and recover a complete PSI section from its payload:
//!
//! ```rust
//! use mpeg_ts::pid::well_known;
//! use mpeg_ts::ts::{SectionReassembler, TsPacket};
//!
//! let mut raw = [0xFFu8; 188];
//! raw[..21].copy_from_slice(&[
//!     0x47, 0x40, 0x00, 0x10,
//!     0x00,
//!     0x00, 0xB0, 0x0D, 0x00, 0x01, 0xC1, 0x00, 0x00, 0x04, 0x01, 0xE0, 0x64,
//!     0xF9, 0xB4, 0x63, 0xEF,
//! ]);
//!
//! let packet = TsPacket::parse(&raw)?;
//! assert_eq!(packet.header.pid, well_known::PAT);
//! assert!(packet.header.pusi);
//! let mut reassembler = SectionReassembler::default();
//! reassembler.feed(packet.payload.expect("payload"), packet.header.pusi);
//! let section = reassembler.pop_section().expect("one complete section");
//! assert_eq!(section[0], 0x00);
//! # Ok::<(), mpeg_ts::Error>(())
//! ```
//!
//! # How do I...
//!
//! - Parse or serialize one packet: [`ts::TsPacket`], `examples/iter_packets.rs`.
//! - Edit a packet in place (continuity counter, PCR): [`OwnedTsPacket`],
//!   `examples/edit_packet.rs`.
//! - Reassemble PSI sections across packets: [`ts::SectionReassembler`],
//!   `examples/demux.rs`.
//! - Packetise sections into TS packets: [`mux::SectionPacketiser`],
//!   `examples/demux.rs`.
//! - Recover alignment in an unknown byte stream: [`resync::TsResync`],
//!   `examples/iter_packets.rs`.
//! - Reassemble a PES-like payload unit: [`unit::UnitReassembler`],
//!   `examples/demux.rs`.
//! - Work with PCR values and step detection: [`pcr`], `examples/edit_packet.rs`.
//! - Enumerate reserved PIDs: [`pid::well_known`], `examples/demux.rs`.
//!
//! # Modules
//!
//! Packet layer: [`ts`] (borrowed packets and headers), [`owned`] (mutable
//! packet bytes), [`pid`] (PID values), [`pcr`] (PCR and OPCR values),
//! [`bitrate`] (packet-rate arithmetic), [`ts_dup`] (duplicate-packet
//! detection).
//!
//! Section and payload layer: [`section`] (section syntax and CRC),
//! [`descriptor_loop`] (borrowed descriptor loops), [`mux`] (section
//! packetisation), [`mod@unit`] (payload-unit reassembly).
//!
//! Framing recovery: [`resync`] (stride and phase search), [`reader`]
//! (`std`-only byte reader).
//!
//! Shared vocabulary: [`error`] (typed errors).
//!
//! # Feature flags
//!
//! - `std` (default): `std::error::Error` impls and [`reader`].
//! - `serde`: serialize-only `serde::Serialize` on packet and section types.
//!
//! # Spec citations
//!
//! ITU-T H.222.0 / ISO/IEC 13818-1 §2.4.3.2 (packet layer), §2.4.3.4
//! (adaptation field), §2.4.4 (`pointer_field` and sections), §2.4.3.5
//! (adaptation-field extension); ETSI EN 300 468 §5.1.1 (section header).
#![deny(missing_docs)]
#![no_std]
#![forbid(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_cfg))]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

#[cfg(doctest)]
#[doc = include_str!("../README.md")]
struct ReadmeDoctests;

pub mod bitrate;
pub mod descriptor_loop;
pub mod error;
pub mod mux;
pub mod owned;
pub mod pcr;
pub mod pid;
#[cfg(feature = "std")]
pub mod reader;
pub mod resync;
pub mod section;
pub mod ts;
pub mod ts_dup;
pub mod unit;

pub use error::{Error, Result};
pub use owned::OwnedTsPacket;
pub use ts::{
    AdaptationField, AdaptationFieldControl, AdaptationFieldExtension, ContinuityCounter, Ltw,
    LtwOffset, Pcr, PiecewiseRate, ScramblingControl, SeamlessSplice, TS_BYTES_PER_DATAGRAM,
    TS_PACKET_SIZE, TS_PACKETS_PER_DATAGRAM, TS_SYNC_BYTE, TsHeader, TsPacket,
};