xref: /xiu/protocol/rtmp/src/remuxer/errors.rs (revision 2f8005f4)
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     tokio::sync::broadcast::error::RecvError,
9     xflv::errors::FlvMuxerError,
10     xflv::errors::Mpeg4AvcHevcError,
11 };
12 
13 pub struct RtmpRemuxerError {
14     pub value: RtmpRemuxerErrorValue,
15 }
16 
17 #[derive(Debug, Fail)]
18 pub enum RtmpRemuxerErrorValue {
19     #[fail(display = "hls error")]
20     Error,
21     #[fail(display = "session error:{}\n", _0)]
22     SessionError(#[cause] SessionError),
23     #[fail(display = "amf write error:{}\n", _0)]
24     Amf0WriteError(#[cause] Amf0WriteError),
25     #[fail(display = "metadata error:{}\n", _0)]
26     MetadataError(#[cause] MetadataError),
27     #[fail(display = "receive error:{}\n", _0)]
28     RecvError(#[cause] RecvError),
29     #[fail(display = "bytes read error:{}\n", _0)]
30     BytesReadError(#[cause] BytesReadError),
31     #[fail(display = "bytes write error:{}\n", _0)]
32     BytesWriteError(#[cause] BytesWriteError),
33     #[fail(display = "mpeg avc error\n")]
34     MpegAvcError(#[cause] Mpeg4AvcHevcError),
35     #[fail(display = "flv muxer error\n")]
36     FlvMuxerError(#[cause] FlvMuxerError),
37     #[fail(display = "stream hub event send error\n")]
38     StreamHubEventSendErr,
39 }
40 impl From<RecvError> for RtmpRemuxerError {
41     fn from(error: RecvError) -> Self {
42         RtmpRemuxerError {
43             value: RtmpRemuxerErrorValue::RecvError(error),
44         }
45     }
46 }
47 
48 impl From<SessionError> for RtmpRemuxerError {
49     fn from(error: SessionError) -> Self {
50         RtmpRemuxerError {
51             value: RtmpRemuxerErrorValue::SessionError(error),
52         }
53     }
54 }
55 
56 impl From<Amf0WriteError> for RtmpRemuxerError {
57     fn from(error: Amf0WriteError) -> Self {
58         RtmpRemuxerError {
59             value: RtmpRemuxerErrorValue::Amf0WriteError(error),
60         }
61     }
62 }
63 
64 impl From<MetadataError> for RtmpRemuxerError {
65     fn from(error: MetadataError) -> Self {
66         RtmpRemuxerError {
67             value: RtmpRemuxerErrorValue::MetadataError(error),
68         }
69     }
70 }
71 
72 impl From<BytesReadError> for RtmpRemuxerError {
73     fn from(error: BytesReadError) -> Self {
74         RtmpRemuxerError {
75             value: RtmpRemuxerErrorValue::BytesReadError(error),
76         }
77     }
78 }
79 
80 impl From<BytesWriteError> for RtmpRemuxerError {
81     fn from(error: BytesWriteError) -> Self {
82         RtmpRemuxerError {
83             value: RtmpRemuxerErrorValue::BytesWriteError(error),
84         }
85     }
86 }
87 
88 impl From<Mpeg4AvcHevcError> for RtmpRemuxerError {
89     fn from(error: Mpeg4AvcHevcError) -> Self {
90         RtmpRemuxerError {
91             value: RtmpRemuxerErrorValue::MpegAvcError(error),
92         }
93     }
94 }
95 
96 impl From<FlvMuxerError> for RtmpRemuxerError {
97     fn from(error: FlvMuxerError) -> Self {
98         RtmpRemuxerError {
99             value: RtmpRemuxerErrorValue::FlvMuxerError(error),
100         }
101     }
102 }
103 
104 impl fmt::Display for RtmpRemuxerError {
105     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
106         fmt::Display::fmt(&self.value, f)
107     }
108 }
109