1a3d19cccSHarlanC use { 26685cacbSHarlanC failure::{Backtrace, Fail}, 3a3d19cccSHarlanC rtmp::{ 4a3d19cccSHarlanC amf0::errors::Amf0WriteError, cache::errors::MetadataError, session::errors::SessionError, 5a3d19cccSHarlanC }, 6a3d19cccSHarlanC std::fmt, 7*a4ef5d6cSHarlanC streamhub::errors::ChannelError, 8a3d19cccSHarlanC tokio::sync::broadcast::error::RecvError, 9*a4ef5d6cSHarlanC tokio::sync::oneshot::error::RecvError as OneshotRecvError, 106685cacbSHarlanC xflv::errors::FlvDemuxerError, 116685cacbSHarlanC xmpegts::errors::MpegTsError, 12a3d19cccSHarlanC }; 13abfa5883SHarlanC 14abfa5883SHarlanC #[derive(Debug)] 15abfa5883SHarlanC pub struct ServerError { 16abfa5883SHarlanC pub value: ServerErrorValue, 17abfa5883SHarlanC } 18abfa5883SHarlanC 19abfa5883SHarlanC #[derive(Debug, Fail)] 20abfa5883SHarlanC pub enum ServerErrorValue { 21abfa5883SHarlanC #[fail(display = "server error")] 22abfa5883SHarlanC Error, 23abfa5883SHarlanC } 2427addbf4SHarlanC #[derive(Debug)] 2527addbf4SHarlanC pub struct MediaError { 2627addbf4SHarlanC pub value: MediaErrorValue, 2727addbf4SHarlanC } 2827addbf4SHarlanC 2927addbf4SHarlanC #[derive(Debug, Fail)] 3027addbf4SHarlanC pub enum MediaErrorValue { 3127addbf4SHarlanC #[fail(display = "server error")] 3227addbf4SHarlanC Error, 33*a4ef5d6cSHarlanC #[fail(display = "channel recv error")] 34*a4ef5d6cSHarlanC ChannelRecvError, 3569de9bbdSHarlanC #[fail(display = "session error:{}", _0)] 366685cacbSHarlanC SessionError(#[cause] SessionError), 3769de9bbdSHarlanC #[fail(display = "amf write error:{}", _0)] 386685cacbSHarlanC Amf0WriteError(#[cause] Amf0WriteError), 3969de9bbdSHarlanC #[fail(display = "metadata error:{}", _0)] 406685cacbSHarlanC MetadataError(#[cause] MetadataError), 4169de9bbdSHarlanC #[fail(display = "flv demuxer error:{}", _0)] 426685cacbSHarlanC FlvDemuxerError(#[cause] FlvDemuxerError), 4369de9bbdSHarlanC #[fail(display = "mpegts error:{}", _0)] 446685cacbSHarlanC MpegTsError(#[cause] MpegTsError), 4569de9bbdSHarlanC #[fail(display = "write file error:{}", _0)] 466685cacbSHarlanC IOError(#[cause] std::io::Error), 4727addbf4SHarlanC } 4827addbf4SHarlanC 4927addbf4SHarlanC impl From<SessionError> for MediaError { from(error: SessionError) -> Self5027addbf4SHarlanC fn from(error: SessionError) -> Self { 5127addbf4SHarlanC MediaError { 5227addbf4SHarlanC value: MediaErrorValue::SessionError(error), 5327addbf4SHarlanC } 5427addbf4SHarlanC } 5527addbf4SHarlanC } 5627addbf4SHarlanC 5727addbf4SHarlanC impl From<FlvDemuxerError> for MediaError { from(error: FlvDemuxerError) -> Self5827addbf4SHarlanC fn from(error: FlvDemuxerError) -> Self { 5927addbf4SHarlanC MediaError { 6027addbf4SHarlanC value: MediaErrorValue::FlvDemuxerError(error), 6127addbf4SHarlanC } 6227addbf4SHarlanC } 6327addbf4SHarlanC } 6427addbf4SHarlanC 652f5b0df1SHarlanC impl From<MpegTsError> for MediaError { from(error: MpegTsError) -> Self662f5b0df1SHarlanC fn from(error: MpegTsError) -> Self { 672f5b0df1SHarlanC MediaError { 682f5b0df1SHarlanC value: MediaErrorValue::MpegTsError(error), 692f5b0df1SHarlanC } 702f5b0df1SHarlanC } 712f5b0df1SHarlanC } 722f5b0df1SHarlanC 7327addbf4SHarlanC impl From<Amf0WriteError> for MediaError { from(error: Amf0WriteError) -> Self7427addbf4SHarlanC fn from(error: Amf0WriteError) -> Self { 7527addbf4SHarlanC MediaError { 7627addbf4SHarlanC value: MediaErrorValue::Amf0WriteError(error), 7727addbf4SHarlanC } 7827addbf4SHarlanC } 7927addbf4SHarlanC } 8027addbf4SHarlanC 8127addbf4SHarlanC impl From<MetadataError> for MediaError { from(error: MetadataError) -> Self8227addbf4SHarlanC fn from(error: MetadataError) -> Self { 8327addbf4SHarlanC MediaError { 8427addbf4SHarlanC value: MediaErrorValue::MetadataError(error), 8527addbf4SHarlanC } 8627addbf4SHarlanC } 8727addbf4SHarlanC } 8827addbf4SHarlanC 8990a45d49SHarlanC impl From<std::io::Error> for MediaError { from(error: std::io::Error) -> Self9090a45d49SHarlanC fn from(error: std::io::Error) -> Self { 91f4262a36SHarlanC MediaError { 9290a45d49SHarlanC value: MediaErrorValue::IOError(error), 93f4262a36SHarlanC } 94f4262a36SHarlanC } 95f4262a36SHarlanC } 96f4262a36SHarlanC 9727addbf4SHarlanC impl fmt::Display for MediaError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result9827addbf4SHarlanC fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 9927addbf4SHarlanC fmt::Display::fmt(&self.value, f) 10027addbf4SHarlanC } 10127addbf4SHarlanC } 102abfa5883SHarlanC 1036685cacbSHarlanC impl Fail for MediaError { cause(&self) -> Option<&dyn Fail>1046685cacbSHarlanC fn cause(&self) -> Option<&dyn Fail> { 1056685cacbSHarlanC self.value.cause() 1066685cacbSHarlanC } 1076685cacbSHarlanC backtrace(&self) -> Option<&Backtrace>1086685cacbSHarlanC fn backtrace(&self) -> Option<&Backtrace> { 1096685cacbSHarlanC self.value.backtrace() 1106685cacbSHarlanC } 1116685cacbSHarlanC } 1126685cacbSHarlanC 113abfa5883SHarlanC pub struct HlsError { 114abfa5883SHarlanC pub value: HlsErrorValue, 115abfa5883SHarlanC } 116abfa5883SHarlanC 117abfa5883SHarlanC #[derive(Debug, Fail)] 118abfa5883SHarlanC pub enum HlsErrorValue { 1196685cacbSHarlanC #[fail(display = "hls error")] 120abfa5883SHarlanC Error, 121*a4ef5d6cSHarlanC #[fail(display = "channel recv error")] 122*a4ef5d6cSHarlanC ChannelRecvError, 123*a4ef5d6cSHarlanC #[fail(display = "channel error:{}", _0)] 124*a4ef5d6cSHarlanC ChannelError(#[cause] ChannelError), 12569de9bbdSHarlanC #[fail(display = "session error:{}", _0)] 1266685cacbSHarlanC SessionError(#[cause] SessionError), 12769de9bbdSHarlanC #[fail(display = "amf write error:{}", _0)] 1286685cacbSHarlanC Amf0WriteError(#[cause] Amf0WriteError), 12969de9bbdSHarlanC #[fail(display = "metadata error:{}", _0)] 1306685cacbSHarlanC MetadataError(#[cause] MetadataError), 13169de9bbdSHarlanC #[fail(display = "flv demuxer error:{}", _0)] 1326685cacbSHarlanC FlvDemuxerError(#[cause] FlvDemuxerError), 13369de9bbdSHarlanC #[fail(display = "media error:{}", _0)] 1346685cacbSHarlanC MediaError(#[cause] MediaError), 13569de9bbdSHarlanC #[fail(display = "receive error:{}", _0)] 1366685cacbSHarlanC RecvError(#[cause] RecvError), 137*a4ef5d6cSHarlanC #[fail(display = "tokio: oneshot receiver err: {}", _0)] 138*a4ef5d6cSHarlanC OneshotRecvError(#[cause] OneshotRecvError), 13927addbf4SHarlanC } 14022fbd29aSHarlanC impl From<RecvError> for HlsError { from(error: RecvError) -> Self14122fbd29aSHarlanC fn from(error: RecvError) -> Self { 14222fbd29aSHarlanC HlsError { 14322fbd29aSHarlanC value: HlsErrorValue::RecvError(error), 14422fbd29aSHarlanC } 14522fbd29aSHarlanC } 14622fbd29aSHarlanC } 14722fbd29aSHarlanC 14827addbf4SHarlanC impl From<MediaError> for HlsError { from(error: MediaError) -> Self14927addbf4SHarlanC fn from(error: MediaError) -> Self { 15027addbf4SHarlanC HlsError { 15127addbf4SHarlanC value: HlsErrorValue::MediaError(error), 15227addbf4SHarlanC } 15327addbf4SHarlanC } 154abfa5883SHarlanC } 155abfa5883SHarlanC 156abfa5883SHarlanC impl From<SessionError> for HlsError { from(error: SessionError) -> Self157abfa5883SHarlanC fn from(error: SessionError) -> Self { 158abfa5883SHarlanC HlsError { 159abfa5883SHarlanC value: HlsErrorValue::SessionError(error), 160abfa5883SHarlanC } 161abfa5883SHarlanC } 162abfa5883SHarlanC } 163abfa5883SHarlanC 164abfa5883SHarlanC impl From<FlvDemuxerError> for HlsError { from(error: FlvDemuxerError) -> Self165abfa5883SHarlanC fn from(error: FlvDemuxerError) -> Self { 166abfa5883SHarlanC HlsError { 167abfa5883SHarlanC value: HlsErrorValue::FlvDemuxerError(error), 168abfa5883SHarlanC } 169abfa5883SHarlanC } 170abfa5883SHarlanC } 171abfa5883SHarlanC 172abfa5883SHarlanC impl From<Amf0WriteError> for HlsError { from(error: Amf0WriteError) -> Self173abfa5883SHarlanC fn from(error: Amf0WriteError) -> Self { 174abfa5883SHarlanC HlsError { 175abfa5883SHarlanC value: HlsErrorValue::Amf0WriteError(error), 176abfa5883SHarlanC } 177abfa5883SHarlanC } 178abfa5883SHarlanC } 179abfa5883SHarlanC 180abfa5883SHarlanC impl From<MetadataError> for HlsError { from(error: MetadataError) -> Self181abfa5883SHarlanC fn from(error: MetadataError) -> Self { 182abfa5883SHarlanC HlsError { 183abfa5883SHarlanC value: HlsErrorValue::MetadataError(error), 184abfa5883SHarlanC } 185abfa5883SHarlanC } 186abfa5883SHarlanC } 187abfa5883SHarlanC 188*a4ef5d6cSHarlanC impl From<ChannelError> for HlsError { from(error: ChannelError) -> Self189*a4ef5d6cSHarlanC fn from(error: ChannelError) -> Self { 190*a4ef5d6cSHarlanC HlsError { 191*a4ef5d6cSHarlanC value: HlsErrorValue::ChannelError(error), 192*a4ef5d6cSHarlanC } 193*a4ef5d6cSHarlanC } 194*a4ef5d6cSHarlanC } 195*a4ef5d6cSHarlanC 196*a4ef5d6cSHarlanC impl From<OneshotRecvError> for HlsError { from(error: OneshotRecvError) -> Self197*a4ef5d6cSHarlanC fn from(error: OneshotRecvError) -> Self { 198*a4ef5d6cSHarlanC HlsError { 199*a4ef5d6cSHarlanC value: HlsErrorValue::OneshotRecvError(error), 200*a4ef5d6cSHarlanC } 201*a4ef5d6cSHarlanC } 202*a4ef5d6cSHarlanC } 203*a4ef5d6cSHarlanC 204abfa5883SHarlanC impl fmt::Display for HlsError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result205abfa5883SHarlanC fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 206abfa5883SHarlanC fmt::Display::fmt(&self.value, f) 207abfa5883SHarlanC } 208abfa5883SHarlanC } 209