Skip to main content

mpeg_audio/
error.rs

1//! Public error type.
2
3#![forbid(unsafe_code)]
4
5/// Errors from MPEG audio (Layer III) mux/demux.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// `bitrate_kbps` is not one of the 14 standard Layer III rates for this `MpegVersion`.
10    #[error("bitrate {0} kbps has no Layer III bitrate index for this MPEG version")]
11    UnsupportedBitrate(u16),
12    /// `sample_rate` is not one of the 3 standard rates for this `MpegVersion`.
13    #[error("sample rate {0} has no sampling_rate_index for this MPEG version")]
14    UnsupportedSampleRate(u32),
15    /// `frame_body.len()` doesn't match `FrameHeader::frame_len() - 4` (header size).
16    #[error(
17        "frame body length {actual} does not match the expected {expected} bytes for this header"
18    )]
19    FrameBodyLengthMismatch {
20        /// Expected body length (`frame_len() - 4`).
21        expected: usize,
22        /// Actual `frame_body.len()` passed in.
23        actual: usize,
24    },
25    /// The next 3 bytes are not a valid frame sync + version/layer/bitrate/samplerate combination.
26    #[error("bad MPEG audio frame sync or reserved header field")]
27    BadSyncOrReservedField,
28    /// Layer is not Layer III (`01`) — only Layer III is supported by this crate.
29    #[error("unsupported layer (only Layer III is implemented)")]
30    UnsupportedLayer,
31}