Skip to main content

m2ts_packet/
lib.rs

1//! A MPEG2 Transport Stream (TS) packet decoder.
2//!
3//! This crate provides low-level decoding of 188-byte MPEG-TS packets and
4//! reassembly into PES (Packetized Elementary Stream) packets and PSI sections
5//! (PAT / PMT).
6//!
7//! # Core types
8//!
9//! | Type | Description |
10//! |------|-------------|
11//! | [`TsPacket`] | A single 188-byte transport stream packet |
12//! | [`TsPacketDecoder`] | A [`tokio_util::codec::Decoder`] that reads `TsPacket`s from a byte stream |
13//! | [`PesPacket`] | A reassembled elementary stream item (video, audio, PAT, PMT, etc.) |
14//! | [`PacketizedElementaryStream`] | A `Stream` adapter that reassembles `TsPacket`s into `PesPacket`s |
15//! | [`PesAssembler`] | A pull-based assembler — same logic, but driven by an async callback |
16//!
17//! # Stream-based usage
18//!
19//! Wrap any `AsyncRead` source with [`TsPacketDecoder`] via `FramedRead`, then
20//! feed the packet stream into [`PacketizedElementaryStream`]:
21//!
22#![doc = concat!("```no_run\n", include_str!("../examples/stream.rs"), "\n```")]
23//!
24//! # Pull-based usage
25//!
26//! If you don't have a `Stream` or need finer control, use [`PesAssembler`]
27//! with an async callback that provides `TsPacket`s on demand:
28//!
29#![doc = concat!("```no_run\n", include_str!("../examples/assemble.rs"), "\n```")]
30
31use bitfield_struct::{bitenum, bitfield};
32use bytes::{Buf, Bytes, BytesMut};
33
34mod error;
35pub use error::*;
36
37use ts_header::*;
38mod ts_header;
39
40pub use adaptation_field::*;
41mod adaptation_field;
42
43pub use ts_packet::{TsPacket, TsPacketDecoder};
44mod ts_packet;
45
46pub use pes_packet::*;
47mod pes_packet;