xref: /xiu/protocol/rtmp/src/remuxer/errors.rs (revision a4ef5d6c)
1 use {
2     crate::{
3         amf0::errors::Amf0WriteError, cache::errors::MetadataError, session::errors::SessionError,
4     },
5     bytesio::bytes_errors::{BytesReadError, BytesWriteError},
6     failure::Fail,
7     std::fmt,
8     streamhub::errors::ChannelError,
9     tokio::sync::broadcast::error::RecvError,
10     tokio::sync::oneshot::error::RecvError as OneshotRecvError,
11     xflv::errors::FlvMuxerError,
12     xflv::errors::Mpeg4AvcHevcError,
13 };
14 
15 pub struct RtmpRemuxerError {
16     pub value: RtmpRemuxerErrorValue,
17 }
18 
19 #[derive(Debug, Fail)]
20 pub enum RtmpRemuxerErrorValue {
21     #[fail(display = "hls error")]
22     Error,
23     #[fail(display = "session error:{}", _0)]
24     SessionError(#[cause] SessionError),
25     #[fail(display = "amf write error:{}", _0)]
26     Amf0WriteError(#[cause] Amf0WriteError),
27     #[fail(display = "metadata error:{}", _0)]
28     MetadataError(#[cause] MetadataError),
29     #[fail(display = "receive error:{}", _0)]
30     RecvError(#[cause] RecvError),
31     #[fail(display = "bytes read error:{}", _0)]
32     BytesReadError(#[cause] BytesReadError),
33     #[fail(display = "bytes write error:{}", _0)]
34     BytesWriteError(#[cause] BytesWriteError),
35     #[fail(display = "mpeg avc error")]
36     MpegAvcError(#[cause] Mpeg4AvcHevcError),
37     #[fail(display = "flv muxer error")]
38     FlvMuxerError(#[cause] FlvMuxerError),
39     #[fail(display = "stream hub event send error")]
40     StreamHubEventSendErr,
41     #[fail(display = "event execute error: {}", _0)]
42     ChannelError(#[cause] ChannelError),
43     #[fail(display = "tokio: oneshot receiver err: {}", _0)]
44     OneshotRecvError(#[cause] OneshotRecvError),
45     #[fail(display = "Channel receive error")]
46     ChannelRecvError,
47 }
48 impl From<RecvError> for RtmpRemuxerError {
from(error: RecvError) -> Self49     fn from(error: RecvError) -> Self {
50         RtmpRemuxerError {
51             value: RtmpRemuxerErrorValue::RecvError(error),
52         }
53     }
54 }
55 
56 impl From<SessionError> for RtmpRemuxerError {
from(error: SessionError) -> Self57     fn from(error: SessionError) -> Self {
58         RtmpRemuxerError {
59             value: RtmpRemuxerErrorValue::SessionError(error),
60         }
61     }
62 }
63 
64 impl From<Amf0WriteError> for RtmpRemuxerError {
from(error: Amf0WriteError) -> Self65     fn from(error: Amf0WriteError) -> Self {
66         RtmpRemuxerError {
67             value: RtmpRemuxerErrorValue::Amf0WriteError(error),
68         }
69     }
70 }
71 
72 impl From<MetadataError> for RtmpRemuxerError {
from(error: MetadataError) -> Self73     fn from(error: MetadataError) -> Self {
74         RtmpRemuxerError {
75             value: RtmpRemuxerErrorValue::MetadataError(error),
76         }
77     }
78 }
79 
80 impl From<BytesReadError> for RtmpRemuxerError {
from(error: BytesReadError) -> Self81     fn from(error: BytesReadError) -> Self {
82         RtmpRemuxerError {
83             value: RtmpRemuxerErrorValue::BytesReadError(error),
84         }
85     }
86 }
87 
88 impl From<BytesWriteError> for RtmpRemuxerError {
from(error: BytesWriteError) -> Self89     fn from(error: BytesWriteError) -> Self {
90         RtmpRemuxerError {
91             value: RtmpRemuxerErrorValue::BytesWriteError(error),
92         }
93     }
94 }
95 
96 impl From<Mpeg4AvcHevcError> for RtmpRemuxerError {
from(error: Mpeg4AvcHevcError) -> Self97     fn from(error: Mpeg4AvcHevcError) -> Self {
98         RtmpRemuxerError {
99             value: RtmpRemuxerErrorValue::MpegAvcError(error),
100         }
101     }
102 }
103 
104 impl From<FlvMuxerError> for RtmpRemuxerError {
from(error: FlvMuxerError) -> Self105     fn from(error: FlvMuxerError) -> Self {
106         RtmpRemuxerError {
107             value: RtmpRemuxerErrorValue::FlvMuxerError(error),
108         }
109     }
110 }
111 
112 impl From<ChannelError> for RtmpRemuxerError {
from(error: ChannelError) -> Self113     fn from(error: ChannelError) -> Self {
114         RtmpRemuxerError {
115             value: RtmpRemuxerErrorValue::ChannelError(error),
116         }
117     }
118 }
119 
120 impl From<OneshotRecvError> for RtmpRemuxerError {
from(error: OneshotRecvError) -> Self121     fn from(error: OneshotRecvError) -> Self {
122         RtmpRemuxerError {
123             value: RtmpRemuxerErrorValue::OneshotRecvError(error),
124         }
125     }
126 }
127 
128 impl fmt::Display for RtmpRemuxerError {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result129     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
130         fmt::Display::fmt(&self.value, f)
131     }
132 }
133