Skip to main content

media_pp/
error.rs

1use thiserror::Error;
2
3#[cfg(all(target_os = "windows", feature = "dxgi-capture"))]
4use crate::elements::DxgiCaptureSourceError;
5#[cfg(feature = "ort")]
6use crate::elements::OrtDetectorError;
7#[cfg(all(target_os = "linux", feature = "pipewire-audio-capture"))]
8use crate::elements::PipeWireAudioCaptureSourceError;
9#[cfg(all(target_os = "linux", feature = "pipewire-audio-renderer"))]
10use crate::elements::PipeWireAudioRendererError;
11#[cfg(all(target_os = "linux", feature = "pipewire-screen-capture"))]
12use crate::elements::PipeWireScreenCaptureSourceError;
13use crate::elements::RtspSinkError;
14#[cfg(all(target_os = "windows", feature = "wasapi-capture"))]
15use crate::elements::WasapiCaptureSourceError;
16#[cfg(all(target_os = "windows", feature = "wasapi-renderer"))]
17use crate::elements::WasapiRendererError;
18#[cfg(feature = "webrtc")]
19use crate::elements::WebRtcError;
20#[cfg(feature = "cuda")]
21use crate::elements::{
22    CudaConverterError, CudaDecoderError, CudaDownloadError, CudaEncoderError, CudaRendererError,
23    CudaScalerError, CudaUploadError, CudaVideoCompositorError,
24};
25#[cfg(all(target_os = "windows", feature = "d3d11"))]
26use crate::elements::{
27    D3d11DownloadError, D3d11NvencEncoderError, D3d11RendererError, D3d11ScalerError,
28    D3d11TextLayerError, D3d11UploadError, D3d11VideoCompositorError, D3d11vaDecoderError,
29};
30#[cfg(all(target_os = "windows", feature = "d3d12"))]
31use crate::elements::{D3d12RendererError, D3d12UploadError, D3d12vaDecoderError};
32use crate::{
33    elements::{
34        AppSourceError, AudioMixerError, AudioResamplerError, AudioVolumeError, FileDemuxError,
35        HlsMuxerError, Mp4MuxerError, PacerError, RtspSourceError, SwAudioEncoderError,
36        SwDecoderError, SwEncoderError, SwScalerError, SwVideoCompositorError,
37        TestAudioSourceError, TestVideoSourceError, VideoSynchronizerError,
38    },
39    graph::GraphError,
40    log::LogInitError,
41    queue::QueueError,
42};
43
44/// Crate-wide error. Each element defines its own `{Element}Error` (see
45/// [`FileDemuxError`], [`SwDecoderError`], [`QueueError`]) for its own
46/// domain-specific failures; this enum just aggregates them so trait
47/// methods (`Sink::consume`, `SourceElement::run`, ...) — which have to
48/// return one common error type to stay object-safe across arbitrary
49/// `Box<dyn Sink>` — can report any of them. `?` chains through
50/// automatically: an element's own function returns its own error type,
51/// and the moment that gets used with `?` inside a function returning
52/// this top-level `Result`, it's converted here via `#[from]`.
53#[derive(Debug, Error)]
54pub enum Error {
55    #[error(transparent)]
56    FileDemuxError(#[from] FileDemuxError),
57
58    #[error(transparent)]
59    AppSourceError(#[from] AppSourceError),
60
61    #[error(transparent)]
62    RtspSourceError(#[from] RtspSourceError),
63
64    #[error(transparent)]
65    TestVideoSourceError(#[from] TestVideoSourceError),
66
67    #[error(transparent)]
68    TestAudioSourceError(#[from] TestAudioSourceError),
69
70    #[error(transparent)]
71    SwDecoderError(#[from] SwDecoderError),
72
73    #[cfg(feature = "cuda")]
74    #[error(transparent)]
75    CudaDecoderError(#[from] CudaDecoderError),
76
77    #[cfg(feature = "cuda")]
78    #[error(transparent)]
79    CudaRendererError(#[from] CudaRendererError),
80
81    #[cfg(feature = "cuda")]
82    #[error(transparent)]
83    CudaUploadError(#[from] CudaUploadError),
84
85    #[cfg(feature = "cuda")]
86    #[error(transparent)]
87    CudaDownloadError(#[from] CudaDownloadError),
88
89    #[cfg(feature = "cuda")]
90    #[error(transparent)]
91    CudaScalerError(#[from] CudaScalerError),
92
93    #[cfg(feature = "cuda")]
94    #[error(transparent)]
95    CudaConverterError(#[from] CudaConverterError),
96
97    #[cfg(feature = "cuda")]
98    #[error(transparent)]
99    CudaVideoCompositorError(#[from] CudaVideoCompositorError),
100
101    #[cfg(feature = "cuda")]
102    #[error(transparent)]
103    CudaEncoderError(#[from] CudaEncoderError),
104
105    #[error(transparent)]
106    SwEncoderError(#[from] SwEncoderError),
107
108    #[error(transparent)]
109    PacerError(#[from] PacerError),
110
111    #[error(transparent)]
112    VideoSynchronizerError(#[from] VideoSynchronizerError),
113
114    #[error(transparent)]
115    SwAudioEncoderError(#[from] SwAudioEncoderError),
116
117    #[error(transparent)]
118    AudioResamplerError(#[from] AudioResamplerError),
119
120    #[error(transparent)]
121    AudioVolumeError(#[from] AudioVolumeError),
122
123    #[error(transparent)]
124    SwScalerError(#[from] SwScalerError),
125
126    #[error(transparent)]
127    QueueError(#[from] QueueError),
128
129    #[error(transparent)]
130    GraphError(#[from] GraphError),
131
132    #[error(transparent)]
133    LogInitError(#[from] LogInitError),
134
135    #[error(transparent)]
136    AudioMixerError(#[from] AudioMixerError),
137
138    #[error(transparent)]
139    SwVideoCompositorError(#[from] SwVideoCompositorError),
140
141    #[error(transparent)]
142    Mp4MuxerError(#[from] Mp4MuxerError),
143
144    #[error(transparent)]
145    HlsMuxerError(#[from] HlsMuxerError),
146
147    #[error(transparent)]
148    RtspSinkError(#[from] RtspSinkError),
149
150    #[cfg(all(target_os = "windows", feature = "d3d12"))]
151    #[error(transparent)]
152    D3d12RendererError(#[from] D3d12RendererError),
153
154    #[cfg(all(target_os = "windows", feature = "d3d12"))]
155    #[error(transparent)]
156    D3d12vaDecoderError(#[from] D3d12vaDecoderError),
157
158    #[cfg(all(target_os = "windows", feature = "d3d12"))]
159    #[error(transparent)]
160    D3d12UploadError(#[from] D3d12UploadError),
161
162    #[cfg(all(target_os = "windows", feature = "d3d11"))]
163    #[error(transparent)]
164    D3d11vaDecoderError(#[from] D3d11vaDecoderError),
165
166    #[cfg(all(target_os = "windows", feature = "d3d11"))]
167    #[error(transparent)]
168    D3d11UploadError(#[from] D3d11UploadError),
169
170    #[cfg(all(target_os = "windows", feature = "d3d11"))]
171    #[error(transparent)]
172    D3d11DownloadError(#[from] D3d11DownloadError),
173
174    #[cfg(all(target_os = "windows", feature = "d3d11"))]
175    #[error(transparent)]
176    D3d11ScalerError(#[from] D3d11ScalerError),
177
178    #[cfg(all(target_os = "windows", feature = "d3d11"))]
179    #[error(transparent)]
180    D3d11NvencEncoderError(#[from] D3d11NvencEncoderError),
181
182    #[cfg(all(target_os = "windows", feature = "d3d11"))]
183    #[error(transparent)]
184    D3d11RendererError(#[from] D3d11RendererError),
185
186    #[cfg(all(target_os = "windows", feature = "d3d11"))]
187    #[error(transparent)]
188    D3d11VideoCompositorError(#[from] D3d11VideoCompositorError),
189
190    #[cfg(all(target_os = "windows", feature = "d3d11"))]
191    #[error(transparent)]
192    D3d11TextLayerError(#[from] D3d11TextLayerError),
193
194    #[cfg(all(target_os = "windows", feature = "dxgi-capture"))]
195    #[error(transparent)]
196    DxgiCaptureSourceError(#[from] DxgiCaptureSourceError),
197
198    #[cfg(all(target_os = "linux", feature = "pipewire-audio-capture"))]
199    #[error(transparent)]
200    PipeWireAudioCaptureSourceError(#[from] PipeWireAudioCaptureSourceError),
201
202    #[cfg(all(target_os = "linux", feature = "pipewire-audio-renderer"))]
203    #[error(transparent)]
204    PipeWireAudioRendererError(#[from] PipeWireAudioRendererError),
205
206    #[cfg(all(target_os = "linux", feature = "pipewire-screen-capture"))]
207    #[error(transparent)]
208    PipeWireScreenCaptureSourceError(#[from] PipeWireScreenCaptureSourceError),
209
210    #[cfg(all(target_os = "windows", feature = "wasapi-capture"))]
211    #[error(transparent)]
212    WasapiCaptureSourceError(#[from] WasapiCaptureSourceError),
213
214    #[cfg(all(target_os = "windows", feature = "wasapi-renderer"))]
215    #[error(transparent)]
216    WasapiRendererError(#[from] WasapiRendererError),
217
218    #[cfg(feature = "ort")]
219    #[error(transparent)]
220    OrtDetectorError(#[from] OrtDetectorError),
221
222    #[cfg(feature = "webrtc")]
223    #[error(transparent)]
224    WebRtcError(#[from] WebRtcError),
225
226    #[error("ffmpeg error: {0}")]
227    Ffmpeg(#[from] ffmpeg_next::Error),
228
229    #[error("{0}")]
230    Other(String),
231}
232
233pub type Result<T> = std::result::Result<T, Error>;