mpeg_ts/error.rs
1//! Error type returned by every parser and builder in this crate.
2
3use thiserror::Error;
4
5/// Crate-wide result alias.
6pub type Result<T> = core::result::Result<T, Error>;
7
8/// Error variants that parsers + builders can return.
9///
10/// Spec references inside `#[error(...)]` strings quote clauses from
11/// ITU-T H.222.0 (= ISO/IEC 13818-1) where applicable.
12#[derive(Debug, Error, PartialEq, Eq, Clone)]
13#[non_exhaustive]
14pub enum Error {
15 /// Input buffer was shorter than the smallest valid encoding for the type.
16 #[error(transparent)]
17 BufferTooShort(#[from] broadcast_common::error::BufferTooShort),
18
19 /// CRC-32 validation failed for a table section.
20 #[error(transparent)]
21 CrcMismatch(#[from] broadcast_common::error::CrcMismatch),
22
23 /// A fixed marker did not match (TS sync byte, expected `0x47`).
24 #[error(transparent)]
25 InvalidSync(#[from] broadcast_common::error::InvalidSync),
26
27 /// Write buffer passed to `serialize_into` was smaller than `serialized_len()`.
28 #[error(transparent)]
29 OutputBufferTooSmall(#[from] broadcast_common::error::OutputBufferTooSmall),
30
31 /// A `section_length` declared more bytes than the containing buffer could hold.
32 #[error("section_length {declared} exceeds remaining buffer ({available} bytes)")]
33 SectionLengthOverflow {
34 /// Length bytes declared inside the section header.
35 declared: usize,
36 /// Bytes actually available after the header.
37 available: usize,
38 },
39
40 /// A payload was longer than a single TS packet's fixed payload capacity
41 /// (see `OwnedTsPacket::serialize_with_payload`, #1129).
42 #[error("payload {len} bytes exceeds the {max}-byte TS packet payload capacity")]
43 PayloadTooLarge {
44 /// The payload length that did not fit.
45 len: usize,
46 /// The maximum payload capacity.
47 max: usize,
48 },
49
50 /// A PCR or ESCR value did not fit the 27 MHz clock: a base wider than
51 /// 33 bits, or an extension `>= 300` (the 9-bit wire field can carry
52 /// `300..=511`).
53 #[error(transparent)]
54 ClockOutOfRange(#[from] broadcast_common::clock33::ClockOutOfRange),
55
56 /// A length or count field's value does not fit its wire field
57 /// (see `broadcast_common::len`, #1129).
58 #[error(transparent)]
59 FieldOverflow(#[from] broadcast_common::len::FieldOverflow),
60
61 /// The packet has no adaptation field, so it has no PCR (and no OPCR)
62 /// slot to rewrite.
63 #[error("packet has no adaptation field")]
64 NoAdaptationField,
65
66 /// The adaptation field has no PCR (or OPCR) slot: either it is shorter
67 /// than the flags byte plus the 6-byte field, or the packet's own flag
68 /// byte does not set the corresponding flag.
69 #[error("packet has no {which} slot")]
70 NoClockReference {
71 /// The missing field: `"PCR"` or `"OPCR"`.
72 which: &'static str,
73 },
74
75 /// The adaptation field is shorter than the field being written into it.
76 #[error("adaptation field is {have} bytes, {need} needed")]
77 AdaptationFieldTooShort {
78 /// Bytes the write needs.
79 need: usize,
80 /// `adaptation_field_length` the packet declares.
81 have: usize,
82 },
83}