1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! MPEG-1/2 Program Stream parsing — ISO/IEC 13818-1 (Rec. ITU-T H.222.0) §2.5.
//!
//! The Program Stream (`.mpg` / `.vob`) framing that wraps PES packets: the
//! [`PackHeader`] (42-bit SCR + `program_mux_rate`), the optional
//! [`SystemHeader`] (rate/audio/video bounds + per-stream P-STD buffer bounds),
//! and the [`ProgramStreamMap`] (PSM).
//!
//! PES payloads are parsed via the `mpeg-pes` crate.
//!
//! Depends only on `broadcast-common` + `mpeg-pes` and is `#![no_std]` (+ `alloc`).
//!
//! # Examples
//!
//! Parse a pack header from bytes:
//!
//! ```
//! use mpeg_ps::PackHeader;
//! use broadcast_common::Parse;
//!
//! // A minimal pack header: start_code 0x000001BA, SCR=0, mux_rate=3, stuffing=0
//! let bytes = [
//! 0x00, 0x00, 0x01, 0xBA,
//! 0x44, 0x00, 0x04, 0x00, 0x04, 0x01,
//! 0x40, 0x00, 0x03, 0x00,
//! ];
//! let h = PackHeader::parse(&bytes).unwrap();
//! assert_eq!(h.program_mux_rate, 3);
//! assert_eq!(h.scr.ticks(), 0);
//! ```
//!
//! Walk a Program Stream:
//!
//! ```no_run
//! # use std::fs;
//! # use mpeg_ps::program_stream;
//! let data = fs::read("tests/fixtures/ffmpeg-mpeg2-ps.mpg").unwrap();
//! let (packs, _trailing) = program_stream::parse_all_packs(&data).unwrap();
//! println!("Found {} packs", packs.len());
//! for (i, pack) in packs.iter().enumerate() {
//! println!("Pack {}: SCR={} ticks, mux_rate={} B/s",
//! i, pack.pack_header.scr.ticks(),
//! pack.pack_header.program_mux_rate * 50);
//! }
//! ```
// Runnable examples, embedded so they render on docs.rs and stay in sync with
// the actual `examples/*.rs` files (shown, not compiled).
extern crate alloc;
pub use ;
pub use PackHeader;
pub use ;
pub use Scr;
pub use ;
/// The 3-byte `packet_start_code_prefix` that opens PES and PSM packets (`0x000001`).
pub const PACKET_START_CODE_PREFIX: = ;
/// `MPEG_program_end_code` — `0x000001B9`, terminates the program stream.
pub const PROGRAM_END_CODE: u32 = 0x0000_01B9;