dvb_si/pid.rs
1//! Reserved DVB/MPEG-2 PIDs.
2//!
3//! Values are fixed by ETSI EN 300 468 §5.1.3 Table 1 and ISO/IEC 13818-1.
4
5/// A 13-bit MPEG-TS Packet Identifier.
6///
7/// Thin newtype over the wire `u16`. Values are masked to 13 bits on
8/// construction (`0x0000..=0x1FFF`), matching the transport header field
9/// width (ISO/IEC 13818-1 §2.4.3.2).
10#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12#[cfg_attr(feature = "serde", serde(transparent))]
13pub struct Pid(u16);
14
15impl Pid {
16 /// Mask covering the 13 valid PID bits.
17 pub const MASK: u16 = 0x1FFF;
18
19 /// Construct a `Pid`, masking to the low 13 bits.
20 #[must_use]
21 pub const fn new(value: u16) -> Self {
22 Self(value & Self::MASK)
23 }
24
25 /// The raw 13-bit value.
26 #[must_use]
27 pub const fn value(self) -> u16 {
28 self.0
29 }
30}
31
32impl From<u16> for Pid {
33 fn from(value: u16) -> Self {
34 Self::new(value)
35 }
36}
37
38impl From<Pid> for u16 {
39 fn from(pid: Pid) -> Self {
40 pid.0
41 }
42}
43
44impl core::fmt::Debug for Pid {
45 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
46 write!(f, "Pid(0x{:04X})", self.0)
47 }
48}
49
50impl core::fmt::Display for Pid {
51 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52 write!(f, "0x{:04X}", self.0)
53 }
54}
55
56/// Well-known PIDs. The transport stream MUST carry the corresponding tables
57/// on these PIDs.
58///
59/// **API 2.0 type change:** constants are now [`crate::pid::Pid`] instead of `u16`.
60/// Call `.value()` to obtain the raw `u16`, or use `Pid::from(u16)` /
61/// `u16::from(Pid)` for conversions.
62pub mod well_known {
63 use super::Pid;
64
65 /// Program Association Table (MPEG-2).
66 pub const PAT: Pid = Pid::new(0x0000);
67 /// Conditional Access Table (MPEG-2).
68 pub const CAT: Pid = Pid::new(0x0001);
69 /// Transport Stream Description Table (MPEG-2).
70 pub const TSDT: Pid = Pid::new(0x0002);
71 /// IPMP Control Information Table (MPEG-2).
72 pub const IPMP_CIT: Pid = Pid::new(0x0003);
73 /// Network Information Table (DVB).
74 pub const NIT: Pid = Pid::new(0x0010);
75 /// Service Description Table + Bouquet Association Table (DVB).
76 pub const SDT_BAT: Pid = Pid::new(0x0011);
77 /// Event Information Table (DVB).
78 pub const EIT: Pid = Pid::new(0x0012);
79 /// Running Status Table (DVB).
80 pub const RST: Pid = Pid::new(0x0013);
81 /// Time and Date + Time Offset + Stuffing (DVB).
82 pub const TDT_TOT: Pid = Pid::new(0x0014);
83 /// Network synchronisation.
84 pub const NETWORK_SYNC: Pid = Pid::new(0x0015);
85 /// Resolution Notification Table.
86 pub const RNT: Pid = Pid::new(0x0016);
87 /// Satellite Access Table (EN 300 468 Table 1).
88 pub const SAT: Pid = Pid::new(0x001B);
89 /// Link-local inband signalling (reserved).
90 pub const INBAND_SIGNALLING: Pid = Pid::new(0x001C);
91 /// Measurement (reserved).
92 pub const MEASUREMENT: Pid = Pid::new(0x001D);
93 /// Discontinuity Information Table.
94 pub const DIT: Pid = Pid::new(0x001E);
95 /// Selection Information Table.
96 pub const SIT: Pid = Pid::new(0x001F);
97
98 /// ATSC PSIP base PID.
99 pub const ATSC_PSIP: Pid = Pid::new(0x1FFB);
100
101 /// Null-packet padding PID. Payload is ignored.
102 pub const NULL: Pid = Pid::new(0x1FFF);
103}