1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::error::Error;
#[derive(Debug)]
pub enum Vp9ParserError {
BitReaderError(bitreader::BitReaderError),
IoError(std::io::Error),
TryFromSliceError(std::array::TryFromSliceError),
TryFromIntError(std::num::TryFromIntError),
InvalidFrameMarker,
InvalidPadding,
InvalidSyncByte,
InvalidRefFrameIndex,
InvalidMetadata,
InvalidFrameSizeByteSize(usize),
}
impl std::fmt::Display for Vp9ParserError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Vp9ParserError::BitReaderError(err) => {
write!(f, "{:?}", err.source())
}
Vp9ParserError::IoError(err) => {
write!(f, "{:?}", err.source())
}
Vp9ParserError::TryFromSliceError(err) => {
write!(f, "{:?}", err.source())
}
Vp9ParserError::TryFromIntError(err) => {
write!(f, "{:?}", err.source())
}
Vp9ParserError::InvalidFrameMarker => {
write!(f, "invalid frame marker")
}
Vp9ParserError::InvalidPadding => {
write!(f, "invalid padding")
}
Vp9ParserError::InvalidSyncByte => {
write!(f, "invalid sync byte")
}
Vp9ParserError::InvalidRefFrameIndex => {
write!(f, "invalid reference frame index")
}
Vp9ParserError::InvalidMetadata => {
write!(f, "invalid metadata")
}
Vp9ParserError::InvalidFrameSizeByteSize(size) => {
write!(f, "invalid frame_size byte size: {}", size)
}
}
}
}
impl From<std::io::Error> for Vp9ParserError {
fn from(err: std::io::Error) -> Vp9ParserError {
Vp9ParserError::IoError(err)
}
}
impl From<std::array::TryFromSliceError> for Vp9ParserError {
fn from(err: std::array::TryFromSliceError) -> Vp9ParserError {
Vp9ParserError::TryFromSliceError(err)
}
}
impl From<std::num::TryFromIntError> for Vp9ParserError {
fn from(err: std::num::TryFromIntError) -> Vp9ParserError {
Vp9ParserError::TryFromIntError(err)
}
}
impl From<bitreader::BitReaderError> for Vp9ParserError {
fn from(err: bitreader::BitReaderError) -> Vp9ParserError {
Vp9ParserError::BitReaderError(err)
}
}
impl std::error::Error for Vp9ParserError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Vp9ParserError::IoError(ref e) => Some(e),
Vp9ParserError::TryFromSliceError(ref e) => Some(e),
Vp9ParserError::TryFromIntError(ref e) => Some(e),
Vp9ParserError::BitReaderError(ref e) => Some(e),
_ => None,
}
}
}