1 use failure::{Backtrace, Fail}; 2 use std::fmt; 3 4 use bytesio::bytes_errors::BytesReadError; 5 use bytesio::bytes_errors::BytesWriteError; 6 7 #[derive(Debug, Fail)] 8 pub enum TagParseErrorValue { 9 #[fail(display = "bytes read error\n")] 10 BytesReadError(BytesReadError), 11 #[fail(display = "tag data length error\n")] 12 TagDataLength, 13 #[fail(display = "unknow tag type error\n")] 14 UnknownTagType, 15 } 16 #[derive(Debug)] 17 pub struct TagParseError { 18 pub value: TagParseErrorValue, 19 } 20 21 impl From<BytesReadError> for TagParseError { 22 fn from(error: BytesReadError) -> Self { 23 TagParseError { 24 value: TagParseErrorValue::BytesReadError(error), 25 } 26 } 27 } 28 29 impl fmt::Display for TagParseError { 30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 31 fmt::Display::fmt(&self.value, f) 32 } 33 } 34 35 impl Fail for TagParseError { 36 fn cause(&self) -> Option<&dyn Fail> { 37 self.value.cause() 38 } 39 40 fn backtrace(&self) -> Option<&Backtrace> { 41 self.value.backtrace() 42 } 43 } 44 #[derive(Debug)] 45 pub struct MuxerError { 46 pub value: MuxerErrorValue, 47 } 48 49 #[derive(Debug, Fail)] 50 pub enum MuxerErrorValue { 51 // #[fail(display = "server error")] 52 // Error, 53 #[fail(display = "bytes write error")] 54 BytesWriteError(BytesWriteError), 55 } 56 57 impl From<BytesWriteError> for MuxerError { 58 fn from(error: BytesWriteError) -> Self { 59 MuxerError { 60 value: MuxerErrorValue::BytesWriteError(error), 61 } 62 } 63 } 64 65 impl fmt::Display for MuxerError { 66 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 67 fmt::Display::fmt(&self.value, f) 68 } 69 } 70 71 #[derive(Debug)] 72 pub struct FlvDemuxerError { 73 pub value: DemuxerErrorValue, 74 } 75 76 #[derive(Debug, Fail)] 77 pub enum DemuxerErrorValue { 78 // #[fail(display = "server error")] 79 // Error, 80 #[fail(display = "bytes write error")] 81 BytesWriteError(BytesWriteError), 82 #[fail(display = "bytes read error\n")] 83 BytesReadError(BytesReadError), 84 #[fail(display = "mpeg avc error\n")] 85 MpegAvcError(MpegAvcError), 86 #[fail(display = "mpeg aac error\n")] 87 MpegAacError(MpegAacError), 88 } 89 90 impl From<BytesWriteError> for FlvDemuxerError { 91 fn from(error: BytesWriteError) -> Self { 92 FlvDemuxerError { 93 value: DemuxerErrorValue::BytesWriteError(error), 94 } 95 } 96 } 97 98 impl From<BytesReadError> for FlvDemuxerError { 99 fn from(error: BytesReadError) -> Self { 100 FlvDemuxerError { 101 value: DemuxerErrorValue::BytesReadError(error), 102 } 103 } 104 } 105 106 impl From<MpegAvcError> for FlvDemuxerError { 107 fn from(error: MpegAvcError) -> Self { 108 FlvDemuxerError { 109 value: DemuxerErrorValue::MpegAvcError(error), 110 } 111 } 112 } 113 114 impl From<MpegAacError> for FlvDemuxerError { 115 fn from(error: MpegAacError) -> Self { 116 FlvDemuxerError { 117 value: DemuxerErrorValue::MpegAacError(error), 118 } 119 } 120 } 121 122 impl fmt::Display for FlvDemuxerError { 123 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 124 fmt::Display::fmt(&self.value, f) 125 } 126 } 127 128 #[derive(Debug, Fail)] 129 pub enum MpegAacErrorValue { 130 #[fail(display = "bytes read error\n")] 131 BytesReadError(BytesReadError), 132 133 #[fail(display = "bytes write error\n")] 134 BytesWriteError(BytesWriteError), 135 136 #[fail(display = "there is not enough bits to read\n")] 137 NotEnoughBitsToRead, 138 139 #[fail(display = "should not come here\n")] 140 ShouldNotComeHere, 141 } 142 #[derive(Debug)] 143 pub struct MpegAvcError { 144 pub value: MpegAacErrorValue, 145 } 146 147 impl From<BytesReadError> for MpegAvcError { 148 fn from(error: BytesReadError) -> Self { 149 MpegAvcError { 150 value: MpegAacErrorValue::BytesReadError(error), 151 } 152 } 153 } 154 155 impl From<BytesWriteError> for MpegAvcError { 156 fn from(error: BytesWriteError) -> Self { 157 MpegAvcError { 158 value: MpegAacErrorValue::BytesWriteError(error), 159 } 160 } 161 } 162 163 #[derive(Debug)] 164 pub struct MpegAacError { 165 pub value: MpegAacErrorValue, 166 } 167 168 impl From<BytesReadError> for MpegAacError { 169 fn from(error: BytesReadError) -> Self { 170 MpegAacError { 171 value: MpegAacErrorValue::BytesReadError(error), 172 } 173 } 174 } 175 176 impl From<BytesWriteError> for MpegAacError { 177 fn from(error: BytesWriteError) -> Self { 178 MpegAacError { 179 value: MpegAacErrorValue::BytesWriteError(error), 180 } 181 } 182 } 183 184 #[derive(Debug, Fail)] 185 pub enum BitVecErrorValue { 186 #[fail(display = "not enough bits left\n")] 187 NotEnoughBits, 188 } 189 #[derive(Debug)] 190 pub struct BitVecError { 191 pub value: BitVecErrorValue, 192 } 193