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(transparent)]
12 BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
13
14 /// Output buffer smaller than the serialized form requires.
15 #[error(transparent)]
16 OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
17
18 /// `packet_start_code_prefix` was not `0x000001`.
19 #[error(transparent)]
20 InvalidSync(#[from] broadcast_common::error::InvalidSync),
21 /// A required `marker_bit` was not `1` in a PTS/DTS field.
22 #[error("bad timestamp marker bit in {0}")]
23 BadTimestampMarker(&'static str),
24 /// The PTS/DTS leading 4-bit prefix did not match the expected `0010`/`0011`/`0001`.
25 #[error("bad timestamp prefix in {0}")]
26 BadTimestampPrefix(&'static str),
27 /// `optional_fields` exceeds the 255-byte `PES_header_data_length` limit
28 /// (an 8-bit field) โ cannot be serialized.
29 #[error("optional_fields too large to serialize: {0} bytes (max 255)")]
30 OptionalFieldsTooLarge(usize),
31 /// A length or count field's value does not fit its wire field
32 /// (see `broadcast_common::len`, #1129).
33 #[error(transparent)]
34 FieldOverflow(#[from] broadcast_common::len::FieldOverflow),
35 /// The two fixed marker bits of the first PES header flag byte were not
36 /// `'10'` (ISO/IEC 13818-1 Table 2-21): not an MPEG-2 PES header.
37 #[error("PES header marker bits are not '10'")]
38 BadHeaderMarker,
39 /// `PTS_DTS_flags` on the wire was `01` (ISO/IEC 13818-1 Table 2-21
40 /// reserves this combination โ only `00`/`10`/`11` are defined), or a
41 /// `PesHeader` had `dts.is_some()` with `pts.is_none()` (the same
42 /// forbidden combination, one layer up, that `serialize_into` refuses
43 /// to write silently as `PTS_DTS_flags=00`).
44 #[error("forbidden PTS_DTS_flags combination: DTS without PTS")]
45 ForbiddenPtsDtsFlags,
46}