Skip to main content

mpeg_pes/
error.rs

1//! Error type for PES parsing.
2
3/// Result alias for PES parsing.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A PES parse error.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10    /// Input shorter than required.
11    #[error("buffer too short: need {need}, have {have} ({what})")]
12    BufferTooShort {
13        /// Bytes required.
14        need: usize,
15        /// Bytes available.
16        have: usize,
17        /// What was being parsed.
18        what: &'static str,
19    },
20    /// `packet_start_code_prefix` was not `0x000001`.
21    #[error("invalid packet_start_code_prefix: {0:#08X} (expected 0x000001)")]
22    BadStartCode(u32),
23    /// A required `marker_bit` was not `1` in a PTS/DTS field.
24    #[error("bad timestamp marker bit in {0}")]
25    BadTimestampMarker(&'static str),
26    /// The PTS/DTS leading 4-bit prefix did not match the expected `0010`/`0011`/`0001`.
27    #[error("bad timestamp prefix in {0}")]
28    BadTimestampPrefix(&'static str),
29    /// `optional_fields` exceeds the 255-byte `PES_header_data_length` limit
30    /// (an 8-bit field) โ€” cannot be serialized.
31    #[error("optional_fields too large to serialize: {0} bytes (max 255)")]
32    OptionalFieldsTooLarge(usize),
33    /// A length or count field's value does not fit its wire field
34    /// (see `broadcast_common::len`, #1129).
35    #[error(transparent)]
36    FieldOverflow(#[from] broadcast_common::len::FieldOverflow),
37    /// `PTS_DTS_flags` on the wire was `01` (ISO/IEC 13818-1 Table 2-21
38    /// reserves this combination โ€” only `00`/`10`/`11` are defined), or a
39    /// `PesHeader` had `dts.is_some()` with `pts.is_none()` (the same
40    /// forbidden combination, one layer up, that `serialize_into` refuses
41    /// to write silently as `PTS_DTS_flags=00`).
42    #[error("forbidden PTS_DTS_flags combination: DTS without PTS")]
43    ForbiddenPtsDtsFlags,
44}