Skip to main content

moq_video/
error.rs

1/// Errors returned by `moq-video`.
2#[derive(Clone, Debug, thiserror::Error)]
3#[non_exhaustive]
4pub enum Error {
5	/// A [`decode::Consumer`](crate::decode::Consumer) refused the rendition before
6	/// subscribing: its codec, codec parameters, or description is
7	/// [unsupported](Self::UnsupportedCodec). Backend faults keep their own variants.
8	#[error("unsupported video configuration: {0}")]
9	UnsupportedConfig(String),
10
11	/// No encoder matching the requested codec / hardware preference could be
12	/// opened (none compiled in, or none available on this machine).
13	#[error("no usable video encoder found (tried: {0})")]
14	NoEncoder(String),
15
16	/// Every decoder this build has for the requested codec and hardware preference
17	/// failed to open on this machine, at least one with a fault: missing drivers,
18	/// no device, or a library error. A codec this build has no decoder for, or a
19	/// stream every decoder's device refused, is [`UnsupportedCodec`](Self::UnsupportedCodec).
20	#[error("no usable video decoder found (tried: {0})")]
21	NoDecoder(String),
22
23	/// `Backend::Named` asked for an encoder this build does not have for that
24	/// codec: a name that is not a backend, one whose feature is off, or one
25	/// that does not encode the codec requested.
26	#[error("no encoder named {name} for {codec:?} (this build has: {available})")]
27	UnknownEncoder {
28		/// The name that was asked for.
29		name: String,
30		/// The codec it was asked for.
31		codec: crate::encode::Codec,
32		/// The encoders this build does have for that codec.
33		available: String,
34	},
35
36	/// `Backend::Named` asked for a decoder this build does not have for that
37	/// codec: a name that is not a backend, one whose feature is off, or one
38	/// that does not decode the codec requested.
39	#[error("no decoder named {name} for {codec:?} (this build has: {available})")]
40	UnknownDecoder {
41		/// The name that was asked for.
42		name: String,
43		/// The codec it was asked for.
44		codec: crate::decode::Codec,
45		/// The decoders this build does have for that codec.
46		available: String,
47	},
48
49	/// A track's codec, codec parameters, or description is not supported by the
50	/// native decoders this build has, or by the devices they run on here.
51	#[error("unsupported codec for native decode: {0}")]
52	UnsupportedCodec(String),
53
54	/// The codec session is over: its worker thread stopped, or a cancelled
55	/// call left it out of step with the stream it was decoding.
56	///
57	/// Distinct from [`Codec`](Self::Codec), which describes the bytes of one
58	/// picture and which a caller can reasonably skip past. Nothing about this
59	/// one improves by reading on: the session that would have decoded the next
60	/// picture no longer exists, and only a new encoder or decoder recovers it.
61	#[error("codec session ended: {0}")]
62	CodecGone(String),
63
64	/// The requested capture source or enumeration has no implementation on this
65	/// platform (the message names what is missing).
66	#[error("not supported on this platform: {0}")]
67	Unsupported(String),
68
69	/// The operating system denied access to a capture source.
70	#[error("capture permission denied: {0}")]
71	PermissionDenied(String),
72
73	/// A requested capture source does not exist or disappeared while capturing.
74	#[error("capture source unavailable: {0}")]
75	SourceUnavailable(String),
76
77	/// The configured framerate is outside the supported range.
78	#[error("invalid framerate: {0} (must be between 1 and 1,000,000)")]
79	InvalidFramerate(u32),
80
81	/// This encoder can't change its bitrate once open, so it can't follow a
82	/// congestion-control estimate. Encoding continues at the configured rate.
83	#[error("encoder {0} cannot change bitrate while running")]
84	BitrateUnsupported(&'static str),
85
86	/// This encoder can't force a group boundary, so a cut was refused rather
87	/// than queued. Groups keep falling where its configured GOP puts them.
88	#[error("encoder {0} cannot cut a group on request")]
89	CutUnsupported(&'static str),
90
91	/// A frame's samples are in a different color space than the one the
92	/// encoder writes into the bitstream, so encoding it would mislabel it.
93	/// Open the encoder with [`encode::Config::color`](crate::encode::Config::color)
94	/// set to the frame's [`Surface::color`](crate::Surface::color).
95	#[error("frame is {frame:?} but the encoder signals {encoder:?}")]
96	ColorMismatch {
97		/// The space the frame's samples are in.
98		frame: crate::Color,
99		/// The space the encoder was opened with.
100		encoder: crate::Color,
101	},
102
103	/// [`encode::Config::join`](crate::encode::Config::join) is zero, which opens
104	/// no group.
105	#[error("a join of zero opens no group")]
106	ZeroJoin,
107
108	/// GPU rendering failure: building the pipeline, importing a frame's surface
109	/// as a texture, or the device itself.
110	#[error("render: {0}")]
111	Render(String),
112
113	/// Capture / encode / codec failure (the message carries the detail).
114	#[error("{0}")]
115	Codec(String),
116
117	/// moq-mux muxer/catalog error.
118	#[error(transparent)]
119	Mux(#[from] moq_mux::Error),
120
121	/// moq-net transport error.
122	#[error(transparent)]
123	Net(#[from] moq_net::Error),
124
125	/// Timestamp overflow converting to the moq microsecond timescale, or an
126	/// [unscaled](moq_net::Timestamp::unscaled) timestamp, which has no time.
127	#[error(transparent)]
128	TimeOverflow(#[from] moq_net::TimeOverflow),
129}
130
131impl Error {
132	/// A [`Codec`](Self::Codec) failure, with its whole context chain.
133	pub(crate) fn codec(err: anyhow::Error) -> Self {
134		Self::Codec(format!("{err:#}"))
135	}
136
137	/// A [`Render`](Self::Render) failure, with its whole context chain.
138	#[cfg(feature = "render")]
139	pub(crate) fn render(err: anyhow::Error) -> Self {
140		Self::Render(format!("{err:#}"))
141	}
142}