use std::fmt;
use std::io;
#[derive(Debug)]
pub enum PgsError {
Io(io::Error),
InvalidEbml(String),
InvalidVint,
InvalidMkv(String),
InvalidTs(String),
InvalidPgs(String),
NoPgsTracks,
TrackNotFound(u32),
UnknownFormat,
EncodingError(String),
}
impl fmt::Display for PgsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PgsError::Io(e) => write!(f, "I/O error: {e}"),
PgsError::InvalidEbml(msg) => write!(f, "invalid EBML: {msg}"),
PgsError::InvalidVint => write!(f, "malformed EBML VINT"),
PgsError::InvalidMkv(msg) => write!(f, "invalid MKV: {msg}"),
PgsError::InvalidTs(msg) => write!(f, "invalid TS: {msg}"),
PgsError::InvalidPgs(msg) => write!(f, "invalid PGS: {msg}"),
PgsError::NoPgsTracks => write!(f, "no PGS tracks found"),
PgsError::TrackNotFound(id) => write!(f, "track {id} not found"),
PgsError::UnknownFormat => write!(f, "unknown container format"),
PgsError::EncodingError(msg) => write!(f, "encoding error: {msg}"),
}
}
}
impl std::error::Error for PgsError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
PgsError::Io(e) => Some(e),
_ => None,
}
}
}
impl From<io::Error> for PgsError {
fn from(e: io::Error) -> Self {
PgsError::Io(e)
}
}