Skip to main content

mpeg_ts_core/
error.rs

1//! Public error type.
2
3#![forbid(unsafe_code)]
4
5/// Errors from MPEG-TS mux/demux.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// A PID is outside the 13-bit range (`> 0x1FFF`) or uses a reserved value (`0` = PAT, `1` = CAT).
10    #[error("PID {0} is out of range or reserved (PAT=0, CAT=1; max 0x1FFF)")]
11    InvalidPid(u16),
12    /// `AccessUnit::pid` (or `Muxer::write_access_unit`'s `pid` argument) is not
13    /// one of the streams registered in the PMT.
14    #[error("PID {0} is not a registered elementary stream")]
15    UnknownPid(u16),
16    /// The first byte of a TS packet is not `0x47`.
17    #[error("bad TS sync byte (expected 0x47)")]
18    BadSyncByte,
19    /// A PSI section's CRC-32 doesn't match the computed value.
20    #[error("PSI section CRC mismatch: header claims {expected:#010x}, computed {computed:#010x}")]
21    CrcMismatch {
22        /// CRC from the section's trailing field.
23        expected: u32,
24        /// CRC recomputed over the section bytes.
25        computed: u32,
26    },
27    /// PAT/PMT `table_id` byte doesn't match the expected value for that table.
28    #[error("unexpected PSI table_id {actual} (expected {expected})")]
29    UnexpectedTableId {
30        /// Expected `table_id`.
31        expected: u8,
32        /// Actual `table_id` read.
33        actual: u8,
34    },
35    /// PES packet's `start_code_prefix` isn't `0x000001`.
36    #[error("bad PES start code prefix")]
37    BadPesStartCode,
38    /// PMT references a `stream_type` byte this crate doesn't recognize (see [`crate::StreamType`]).
39    #[error("unrecognized PMT stream_type {0}")]
40    UnrecognizedStreamType(u8),
41}