steam_audio_codec/
error.rs

1use std::fmt::Display;
2
3#[derive(Debug)]
4pub enum SteamAudioError {
5    CrcMismatch {
6        expected: u32,
7        actual: u32,
8    },
9    InsufficientData,
10    InsufficientOutputBuffer,
11    UnknownPacketType {
12        ty: u8,
13    },
14    #[cfg(feature = "opus")]
15    Opus(opus::Error),
16    NoSampleRate,
17}
18
19impl Display for SteamAudioError {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            SteamAudioError::CrcMismatch { expected, actual } => write!(
23                f,
24                "crc mismatch for packet, got {actual}, expected: {expected}"
25            ),
26            SteamAudioError::InsufficientData => write!(f, "insufficient number of bytes provided"),
27            SteamAudioError::InsufficientOutputBuffer => {
28                write!(f, "insufficient space in output buffer")
29            }
30            SteamAudioError::UnknownPacketType { ty } => write!(f, "unknown packet type: {ty}"),
31            #[cfg(feature = "opus")]
32            SteamAudioError::Opus(e) => write!(f, "{e}"),
33            SteamAudioError::NoSampleRate => {
34                write!(f, "audio data received before sample rate is set")
35            }
36        }
37    }
38}
39
40#[cfg(feature = "opus")]
41impl From<opus::Error> for SteamAudioError {
42    fn from(e: opus::Error) -> Self {
43        SteamAudioError::Opus(e)
44    }
45}