ez_ffmpeg/
error.rs

1use ffmpeg_next::ffi::AVERROR;
2use ffmpeg_sys_next::*;
3use std::ffi::NulError;
4use std::{io, result};
5
6/// Result type of all ez-ffmpeg library calls.
7pub type Result<T, E = Error> = result::Result<T, E>;
8
9#[derive(thiserror::Error, Debug)]
10pub enum Error {
11    #[error("Scheduler is not started")]
12    NotStarted,
13
14    #[error("URL error: {0}")]
15    Url(#[from] UrlError),
16
17    #[error("Open input stream error: {0}")]
18    OpenInputStream(#[from] OpenInputError),
19
20    #[error("Find stream info error: {0}")]
21    FindStream(#[from] FindStreamError),
22
23    #[error("Decoder error: {0}")]
24    Decoder(#[from] DecoderError),
25
26    #[error("Filter graph parse error: {0}")]
27    FilterGraphParse(#[from] FilterGraphParseError),
28
29    #[error("Ffilter description converted to utf8 string error")]
30    FilterDescUtf8,
31
32    #[error("Filter name converted to utf8 string error")]
33    FilterNameUtf8,
34
35    #[error("A filtergraph has zero outputs, this is not supported")]
36    FilterZeroOutputs,
37
38    #[error("Input is not a valid number")]
39    ParseInteger,
40
41    #[error("Alloc output context error: {0}")]
42    AllocOutputContext(#[from] AllocOutputContextError),
43
44    #[error("Open output error: {0}")]
45    OpenOutput(#[from] OpenOutputError),
46
47    #[error("Output file '{0}' is the same as an input file")]
48    FileSameAsInput(String),
49
50    #[error("Find devices error: {0}")]
51    FindDevices(#[from] FindDevicesError),
52
53    #[error("Alloc frame error: {0}")]
54    AllocFrame(#[from] AllocFrameError),
55
56    #[error("Alloc packet error: {0}")]
57    AllocPacket(#[from] AllocPacketError),
58
59    // ---- Muxing ----
60    #[error("Muxing operation failed {0}")]
61    Muxing(#[from] MuxingOperationError),
62
63    // ---- Open Encoder ----
64    #[error("Open encoder operation failed {0}")]
65    OpenEncoder(#[from] OpenEncoderOperationError),
66
67    // ---- Encoding ----
68    #[error("Encoding operation failed {0}")]
69    Encoding(#[from] EncodingOperationError),
70
71    // ---- FilterGraph ----
72    #[error("Filter graph operation failed {0}")]
73    FilterGraph(#[from] FilterGraphOperationError),
74
75    // ---- Open Decoder ----
76    #[error("Open decoder operation failed {0}")]
77    OpenDecoder(#[from] OpenDecoderOperationError),
78
79    // ---- Decoding ----
80    #[error("Decoding operation failed {0}")]
81    Decoding(#[from] DecodingOperationError),
82
83    // ---- Demuxing ----
84    #[error("Demuxing operation failed {0}")]
85    Demuxing(#[from] DemuxingOperationError),
86
87    // ---- Frame Filter ----
88    #[error("Frame filter init failed: {0}")]
89    FrameFilterInit(String),
90
91    #[error("Frame filter process failed: {0}")]
92    FrameFilterProcess(String),
93
94    #[error("Frame filter request failed: {0}")]
95    FrameFilterRequest(String),
96
97    #[error("No {0} stream of the type:{1} were found while build frame pipeline")]
98    FrameFilterTypeNoMatched(String, String),
99
100    #[error("{0} stream:{1} of the type:{2} were mismatched while build frame pipeline")]
101    FrameFilterStreamTypeNoMatched(String, usize, String),
102
103    #[error("Frame filter pipeline destination already finished")]
104    FrameFilterDstFinished,
105
106    #[error("Frame filter pipeline send frame failed, out of memory")]
107    FrameFilterSendOOM,
108
109    #[error("Frame filter pipeline thread exited")]
110    FrameFilterThreadExited,
111
112    #[cfg(feature = "rtmp")]
113    #[error("Rtmp stream already exists with key: {0}")]
114    RtmpStreamAlreadyExists(String),
115
116    #[cfg(feature = "rtmp")]
117    #[error("Rtmp create stream failed. Check whether the server is stopped.")]
118    RtmpCreateStream,
119
120    #[cfg(feature = "rtmp")]
121    #[error("Rtmp server session error: {0}")]
122    RtmpServerSession(#[from] rml_rtmp::sessions::ServerSessionError),
123
124    #[cfg(feature = "rtmp")]
125    #[error("Rtmp server thread exited")]
126    RtmpThreadExited,
127
128    #[error("IO error:{0}")]
129    IO(#[from] io::Error),
130
131    #[error("EOF")]
132    EOF,
133    #[error("Exit")]
134    Exit,
135    #[error("Bug")]
136    Bug,
137}
138
139impl PartialEq for Error {
140    fn eq(&self, other: &Self) -> bool {
141        match (self, other) {
142            (Error::EOF, Error::EOF) => true,
143            (Error::Exit, Error::Exit) => true,
144            (Error::Bug, Error::Bug) => true,
145            _ => false,
146        }
147    }
148}
149
150impl Eq for Error {}
151
152#[derive(thiserror::Error, Debug)]
153pub enum DemuxingOperationError {
154    #[error("while reading frame: {0}")]
155    ReadFrameError(DemuxingError),
156
157    #[error("while referencing packet: {0}")]
158    PacketRefError(DemuxingError),
159
160    #[error("while seeking file: {0}")]
161    SeekFileError(DemuxingError),
162
163    #[error("Thread exited")]
164    ThreadExited,
165}
166
167#[derive(thiserror::Error, Debug)]
168pub enum DecodingOperationError {
169    #[error("during frame reference creation: {0}")]
170    FrameRefError(DecodingError),
171
172    #[error("during frame properties copy: {0}")]
173    FrameCopyPropsError(DecodingError),
174
175    #[error("during subtitle decoding: {0}")]
176    DecodeSubtitleError(DecodingError),
177
178    #[error("during subtitle copy: {0}")]
179    CopySubtitleError(DecodingError),
180
181    #[error("during packet submission to decoder: {0}")]
182    SendPacketError(DecodingError),
183
184    #[error("during frame reception from decoder: {0}")]
185    ReceiveFrameError(DecodingError),
186
187    #[error("during frame allocation: {0}")]
188    FrameAllocationError(DecodingError),
189
190    #[error("during packet allocation: {0}")]
191    PacketAllocationError(DecodingError),
192
193    #[error("during AVSubtitle allocation: {0}")]
194    SubtitleAllocationError(DecodingError),
195
196    #[error("corrupt decoded frame")]
197    CorruptFrame,
198
199    #[error("during retrieve data on hw: {0}")]
200    HWRetrieveDataError(DecodingError),
201
202    #[error("during cropping: {0}")]
203    CroppingError(DecodingError),
204}
205
206#[derive(thiserror::Error, Debug)]
207pub enum OpenDecoderOperationError {
208    #[error("during context allocation: {0}")]
209    ContextAllocationError(OpenDecoderError),
210
211    #[error("while applying parameters to context: {0}")]
212    ParameterApplicationError(OpenDecoderError),
213
214    #[error("while opening decoder: {0}")]
215    DecoderOpenError(OpenDecoderError),
216
217    #[error("while copying channel layout: {0}")]
218    ChannelLayoutCopyError(OpenDecoderError),
219
220    #[error("while Hw setup: {0}")]
221    HwSetupError(OpenDecoderError),
222
223    #[error("Invalid decoder name")]
224    InvalidName,
225
226    #[error("Thread exited")]
227    ThreadExited,
228}
229
230#[derive(thiserror::Error, Debug)]
231pub enum FilterGraphOperationError {
232    #[error("during requesting oldest frame: {0}")]
233    RequestOldestError(FilterGraphError),
234
235    #[error("during process frames: {0}")]
236    ProcessFramesError(FilterGraphError),
237
238    #[error("during send frames: {0}")]
239    SendFramesError(FilterGraphError),
240
241    #[error("during copying channel layout: {0}")]
242    ChannelLayoutCopyError(FilterGraphError),
243
244    #[error("during buffer source add frame: {0}")]
245    BufferSourceAddFrameError(FilterGraphError),
246
247    #[error("during closing buffer source: {0}")]
248    BufferSourceCloseError(FilterGraphError),
249
250    #[error("during replace buffer: {0}")]
251    BufferReplaceoseError(FilterGraphError),
252
253    #[error("during parse: {0}")]
254    ParseError(FilterGraphParseError),
255
256    #[error("The data in the frame is invalid or corrupted")]
257    InvalidData,
258
259    #[error("Thread exited")]
260    ThreadExited,
261}
262
263#[derive(thiserror::Error, Debug)]
264pub enum EncodingOperationError {
265    #[error("during frame submission: {0}")]
266    SendFrameError(EncodingError),
267
268    #[error("during packet retrieval: {0}")]
269    ReceivePacketError(EncodingError),
270
271    #[error("during audio frame receive: {0}")]
272    ReceiveAudioError(EncodingError),
273
274    #[error(": Subtitle packets must have a pts")]
275    SubtitleNotPts,
276
277    #[error(": Muxer already finished")]
278    MuxerFinished,
279
280    #[error("Encode subtitle error: {0}")]
281    EncodeSubtitle(#[from] EncodeSubtitleError),
282
283    #[error(": {0}")]
284    AllocPacket(AllocPacketError),
285}
286
287#[derive(thiserror::Error, Debug)]
288pub enum MuxingOperationError {
289    #[error("during write header: {0}")]
290    WriteHeader(WriteHeaderError),
291
292    #[error("during interleaved write: {0}")]
293    InterleavedWriteError(MuxingError),
294
295    #[error("during trailer write: {0}")]
296    TrailerWriteError(MuxingError),
297
298    #[error("during closing IO: {0}")]
299    IOCloseError(MuxingError),
300
301    #[error("Thread exited")]
302    ThreadExited,
303}
304
305#[derive(thiserror::Error, Debug)]
306pub enum OpenEncoderOperationError {
307    #[error("during frame side data cloning: {0}")]
308    FrameSideDataCloneError(OpenEncoderError),
309
310    #[error("during channel layout copying: {0}")]
311    ChannelLayoutCopyError(OpenEncoderError),
312
313    #[error("during codec opening: {0}")]
314    CodecOpenError(OpenEncoderError),
315
316    #[error("while setting codec parameters: {0}")]
317    CodecParametersError(OpenEncoderError),
318
319    #[error(": unknown format of the frame")]
320    UnknownFrameFormat,
321
322    #[error("while setting subtitle: {0}")]
323    SettingSubtitleError(OpenEncoderError),
324
325    #[error("while Hw setup: {0}")]
326    HwSetupError(OpenEncoderError),
327
328    #[error("during context allocation: {0}")]
329    ContextAllocationError(OpenEncoderError),
330
331    #[error("Thread exited")]
332    ThreadExited,
333}
334
335#[derive(thiserror::Error, Debug)]
336pub enum UrlError {
337    #[error("Null byte found in string at position {0}")]
338    NullByteError(usize),
339}
340
341impl From<NulError> for Error {
342    fn from(err: NulError) -> Self {
343        Error::Url(UrlError::NullByteError(err.nul_position()))
344    }
345}
346
347#[derive(thiserror::Error, Debug)]
348pub enum OpenInputError {
349    #[error("Memory allocation error")]
350    OutOfMemory,
351
352    #[error("Invalid argument provided")]
353    InvalidArgument,
354
355    #[error("File or stream not found")]
356    NotFound,
357
358    #[error("I/O error occurred while opening the file or stream")]
359    IOError,
360
361    #[error("Pipe error, possibly the stream or data connection was broken")]
362    PipeError,
363
364    #[error("Invalid file descriptor")]
365    BadFileDescriptor,
366
367    #[error("Functionality not implemented or unsupported input format")]
368    NotImplemented,
369
370    #[error("Operation not permitted to access the file or stream")]
371    OperationNotPermitted,
372
373    #[error("The data in the file or stream is invalid or corrupted")]
374    InvalidData,
375
376    #[error("The connection timed out while trying to open the stream")]
377    Timeout,
378
379    #[error("An unknown error occurred. ret:{0}")]
380    UnknownError(i32),
381
382    #[error("Invalid source provided")]
383    InvalidSource,
384
385    #[error("Invalid source format:{0}")]
386    InvalidFormat(String),
387
388    #[error("No seek callback is provided")]
389    SeekFunctionMissing,
390}
391
392impl From<i32> for OpenInputError {
393    fn from(err_code: i32) -> Self {
394        match err_code {
395            AVERROR_OUT_OF_MEMORY => OpenInputError::OutOfMemory,
396            AVERROR_INVALID_ARGUMENT => OpenInputError::InvalidArgument,
397            AVERROR_NOT_FOUND => OpenInputError::NotFound,
398            AVERROR_IO_ERROR => OpenInputError::IOError,
399            AVERROR_PIPE_ERROR => OpenInputError::PipeError,
400            AVERROR_BAD_FILE_DESCRIPTOR => OpenInputError::BadFileDescriptor,
401            AVERROR_NOT_IMPLEMENTED => OpenInputError::NotImplemented,
402            AVERROR_OPERATION_NOT_PERMITTED => OpenInputError::OperationNotPermitted,
403            AVERROR_INVALIDDATA => OpenInputError::InvalidData,
404            AVERROR_TIMEOUT => OpenInputError::Timeout,
405            _ => OpenInputError::UnknownError(err_code),
406        }
407    }
408}
409
410const AVERROR_OUT_OF_MEMORY: i32 = AVERROR(ENOMEM);
411const AVERROR_INVALID_ARGUMENT: i32 = AVERROR(EINVAL);
412const AVERROR_NOT_FOUND: i32 = AVERROR(ENOENT);
413const AVERROR_IO_ERROR: i32 = AVERROR(EIO);
414const AVERROR_PIPE_ERROR: i32 = AVERROR(EPIPE);
415const AVERROR_BAD_FILE_DESCRIPTOR: i32 = AVERROR(EBADF);
416const AVERROR_NOT_IMPLEMENTED: i32 = AVERROR(ENOSYS);
417const AVERROR_OPERATION_NOT_PERMITTED: i32 = AVERROR(EPERM);
418const AVERROR_PERMISSION_DENIED: i32 = AVERROR(EACCES);
419const AVERROR_TIMEOUT: i32 = AVERROR(ETIMEDOUT);
420const AVERROR_NOT_SOCKET: i32 = AVERROR(ENOTSOCK);
421const AVERROR_AGAIN: i32 = AVERROR(EAGAIN);
422
423#[derive(thiserror::Error, Debug)]
424pub enum FindStreamError {
425    #[error("Memory allocation error")]
426    OutOfMemory,
427
428    #[error("Invalid argument provided")]
429    InvalidArgument,
430
431    #[error("Reached end of file while looking for stream info")]
432    EndOfFile,
433
434    #[error("Timeout occurred while reading stream info")]
435    Timeout,
436
437    #[error("I/O error occurred while reading stream info")]
438    IOError,
439
440    #[error("The data in the stream is invalid or corrupted")]
441    InvalidData,
442
443    #[error("Functionality not implemented or unsupported stream format")]
444    NotImplemented,
445
446    #[error("Operation not permitted to access the file or stream")]
447    OperationNotPermitted,
448
449    #[error("No Stream found")]
450    NoStreamFound,
451
452    #[error("No codec parameters found")]
453    NoCodecparFound,
454
455    #[error("An unknown error occurred. ret:{0}")]
456    UnknownError(i32),
457}
458
459impl From<i32> for FindStreamError {
460    fn from(err_code: i32) -> Self {
461        match err_code {
462            AVERROR_OUT_OF_MEMORY => FindStreamError::OutOfMemory,
463            AVERROR_INVALID_ARGUMENT => FindStreamError::InvalidArgument,
464            AVERROR_EOF => FindStreamError::EndOfFile,
465            AVERROR_TIMEOUT => FindStreamError::Timeout,
466            AVERROR_IO_ERROR => FindStreamError::IOError,
467            AVERROR_INVALIDDATA => FindStreamError::InvalidData,
468            AVERROR_NOT_IMPLEMENTED => FindStreamError::NotImplemented,
469            AVERROR_OPERATION_NOT_PERMITTED => FindStreamError::OperationNotPermitted,
470            _ => FindStreamError::UnknownError(err_code),
471        }
472    }
473}
474
475#[derive(thiserror::Error, Debug)]
476pub enum FilterGraphParseError {
477    #[error("Memory allocation error")]
478    OutOfMemory,
479
480    #[error("Invalid argument provided")]
481    InvalidArgument,
482
483    #[error("End of file reached during parsing")]
484    EndOfFile,
485
486    #[error("I/O error occurred during parsing")]
487    IOError,
488
489    #[error("Invalid data encountered during parsing")]
490    InvalidData,
491
492    #[error("Functionality not implemented or unsupported filter format")]
493    NotImplemented,
494
495    #[error("Permission denied during filter graph parsing")]
496    PermissionDenied,
497
498    #[error("Socket operation on non-socket during filter graph parsing")]
499    NotSocket,
500
501    #[error("Option not found during filter graph configuration")]
502    OptionNotFound,
503
504    #[error("Invalid file index {0} in filtergraph description {1}")]
505    InvalidFileIndexInFg(usize, String),
506
507    #[error("Invalid file index {0} in output url: {1}")]
508    InvalidFileIndexInOutput(usize, String),
509
510    #[error("Invalid filter specifier {0}")]
511    InvalidFilterSpecifier(String),
512
513    #[error("Filter '{0}' has output {1} ({2}) unconnected")]
514    OutputUnconnected(String, usize, String),
515
516    #[error("An unknown error occurred. ret: {0}")]
517    UnknownError(i32),
518}
519
520impl From<i32> for FilterGraphParseError {
521    fn from(err_code: i32) -> Self {
522        match err_code {
523            AVERROR_OUT_OF_MEMORY => FilterGraphParseError::OutOfMemory,
524            AVERROR_INVALID_ARGUMENT => FilterGraphParseError::InvalidArgument,
525            AVERROR_EOF => FilterGraphParseError::EndOfFile,
526            AVERROR_IO_ERROR => FilterGraphParseError::IOError,
527            AVERROR_INVALIDDATA => FilterGraphParseError::InvalidData,
528            AVERROR_NOT_IMPLEMENTED => FilterGraphParseError::NotImplemented,
529            AVERROR_OPTION_NOT_FOUND => FilterGraphParseError::OptionNotFound,
530            _ => FilterGraphParseError::UnknownError(err_code),
531        }
532    }
533}
534
535#[derive(thiserror::Error, Debug)]
536pub enum AllocOutputContextError {
537    #[error("Memory allocation error")]
538    OutOfMemory,
539
540    #[error("Invalid argument provided")]
541    InvalidArgument,
542
543    #[error("File or stream not found")]
544    NotFound,
545
546    #[error("I/O error occurred while allocating the output context")]
547    IOError,
548
549    #[error("Pipe error, possibly the stream or data connection was broken")]
550    PipeError,
551
552    #[error("Invalid file descriptor")]
553    BadFileDescriptor,
554
555    #[error("Functionality not implemented or unsupported output format")]
556    NotImplemented,
557
558    #[error("Operation not permitted to allocate the output context")]
559    OperationNotPermitted,
560
561    #[error("Permission denied while allocating the output context")]
562    PermissionDenied,
563
564    #[error("The connection timed out while trying to allocate the output context")]
565    Timeout,
566
567    #[error("An unknown error occurred. ret:{0}")]
568    UnknownError(i32),
569}
570
571impl From<i32> for AllocOutputContextError {
572    fn from(err_code: i32) -> Self {
573        match err_code {
574            AVERROR_OUT_OF_MEMORY => AllocOutputContextError::OutOfMemory,
575            AVERROR_INVALID_ARGUMENT => AllocOutputContextError::InvalidArgument,
576            AVERROR_NOT_FOUND => AllocOutputContextError::NotFound,
577            AVERROR_IO_ERROR => AllocOutputContextError::IOError,
578            AVERROR_PIPE_ERROR => AllocOutputContextError::PipeError,
579            AVERROR_BAD_FILE_DESCRIPTOR => AllocOutputContextError::BadFileDescriptor,
580            AVERROR_NOT_IMPLEMENTED => AllocOutputContextError::NotImplemented,
581            AVERROR_OPERATION_NOT_PERMITTED => AllocOutputContextError::OperationNotPermitted,
582            AVERROR_PERMISSION_DENIED => AllocOutputContextError::PermissionDenied,
583            AVERROR_TIMEOUT => AllocOutputContextError::Timeout,
584            _ => AllocOutputContextError::UnknownError(err_code),
585        }
586    }
587}
588
589#[derive(thiserror::Error, Debug)]
590pub enum OpenOutputError {
591    #[error("Memory allocation error")]
592    OutOfMemory,
593
594    #[error("Invalid argument provided")]
595    InvalidArgument,
596
597    #[error("File or stream not found")]
598    NotFound,
599
600    #[error("I/O error occurred while opening the file or stream")]
601    IOError,
602
603    #[error("Pipe error, possibly the stream or data connection was broken")]
604    PipeError,
605
606    #[error("Invalid file descriptor")]
607    BadFileDescriptor,
608
609    #[error("Functionality not implemented or unsupported output format")]
610    NotImplemented,
611
612    #[error("Operation not permitted to open the file or stream")]
613    OperationNotPermitted,
614
615    #[error("Permission denied while opening the file or stream")]
616    PermissionDenied,
617
618    #[error("The connection timed out while trying to open the file or stream")]
619    Timeout,
620
621    #[error("encoder not found")]
622    EncoderNotFound,
623
624    #[error("Stream map '{0}' matches no streams;")]
625    MatchesNoStreams(String),
626
627    #[error("Invalid label {0}")]
628    InvalidLabel(String),
629
630    #[error("not contain any stream")]
631    NotContainStream,
632
633    #[error("unknown format of the frame")]
634    UnknownFrameFormat,
635
636    #[error("Invalid file index {0} in input url: {1}")]
637    InvalidFileIndexInIntput(usize, String),
638
639    #[error("An unknown error occurred. ret:{0}")]
640    UnknownError(i32),
641
642    #[error("Invalid sink provided")]
643    InvalidSink,
644
645    #[error("No seek callback is provided")]
646    SeekFunctionMissing,
647
648    #[error("Format '{0}' is unsupported")]
649    FormatUnsupported(String),
650}
651
652impl From<i32> for OpenOutputError {
653    fn from(err_code: i32) -> Self {
654        match err_code {
655            AVERROR_OUT_OF_MEMORY => OpenOutputError::OutOfMemory,
656            AVERROR_INVALID_ARGUMENT => OpenOutputError::InvalidArgument,
657            AVERROR_NOT_FOUND => OpenOutputError::NotFound,
658            AVERROR_IO_ERROR => OpenOutputError::IOError,
659            AVERROR_PIPE_ERROR => OpenOutputError::PipeError,
660            AVERROR_BAD_FILE_DESCRIPTOR => OpenOutputError::BadFileDescriptor,
661            AVERROR_NOT_IMPLEMENTED => OpenOutputError::NotImplemented,
662            AVERROR_OPERATION_NOT_PERMITTED => OpenOutputError::OperationNotPermitted,
663            AVERROR_PERMISSION_DENIED => OpenOutputError::PermissionDenied,
664            AVERROR_TIMEOUT => OpenOutputError::Timeout,
665            AVERROR_ENCODER_NOT_FOUND => OpenOutputError::EncoderNotFound,
666            _ => OpenOutputError::UnknownError(err_code),
667        }
668    }
669}
670
671#[derive(thiserror::Error, Debug)]
672pub enum FindDevicesError {
673    #[error("AVCaptureDevice class not found in macOS")]
674    AVCaptureDeviceNotFound,
675
676    #[error("current media_type({0}) is not supported")]
677    MediaTypeSupported(i32),
678    #[error("current OS is not supported")]
679    OsNotSupported,
680    #[error("device_description can not to string")]
681    UTF8Error,
682
683    #[error("Memory allocation error")]
684    OutOfMemory,
685    #[error("Invalid argument provided")]
686    InvalidArgument,
687    #[error("Device or stream not found")]
688    NotFound,
689    #[error("I/O error occurred while accessing the device or stream")]
690    IOError,
691    #[error("Operation not permitted for this device or stream")]
692    OperationNotPermitted,
693    #[error("Permission denied while accessing the device or stream")]
694    PermissionDenied,
695    #[error("This functionality is not implemented")]
696    NotImplemented,
697    #[error("Bad file descriptor")]
698    BadFileDescriptor,
699    #[error("An unknown error occurred. ret:{0}")]
700    UnknownError(i32),
701}
702
703impl From<i32> for FindDevicesError {
704    fn from(err_code: i32) -> Self {
705        match err_code {
706            AVERROR_OUT_OF_MEMORY => FindDevicesError::OutOfMemory,
707            AVERROR_INVALID_ARGUMENT => FindDevicesError::InvalidArgument,
708            AVERROR_NOT_FOUND => FindDevicesError::NotFound,
709            AVERROR_IO_ERROR => FindDevicesError::IOError,
710            AVERROR_OPERATION_NOT_PERMITTED => FindDevicesError::OperationNotPermitted,
711            AVERROR_PERMISSION_DENIED => FindDevicesError::PermissionDenied,
712            AVERROR_NOT_IMPLEMENTED => FindDevicesError::NotImplemented,
713            AVERROR_BAD_FILE_DESCRIPTOR => FindDevicesError::BadFileDescriptor,
714            _ => FindDevicesError::UnknownError(err_code),
715        }
716    }
717}
718
719#[derive(thiserror::Error, Debug)]
720pub enum WriteHeaderError {
721    #[error("Memory allocation error")]
722    OutOfMemory,
723
724    #[error("Invalid argument provided")]
725    InvalidArgument,
726
727    #[error("File or stream not found")]
728    NotFound,
729
730    #[error("I/O error occurred while writing the header")]
731    IOError,
732
733    #[error("Pipe error, possibly the stream or data connection was broken")]
734    PipeError,
735
736    #[error("Invalid file descriptor")]
737    BadFileDescriptor,
738
739    #[error("Functionality not implemented or unsupported output format")]
740    NotImplemented,
741
742    #[error("Operation not permitted to write the header")]
743    OperationNotPermitted,
744
745    #[error("Permission denied while writing the header")]
746    PermissionDenied,
747
748    #[error("The connection timed out while trying to write the header")]
749    Timeout,
750
751    #[error("An unknown error occurred. ret:{0}")]
752    UnknownError(i32),
753}
754
755impl From<i32> for WriteHeaderError {
756    fn from(err_code: i32) -> Self {
757        match err_code {
758            AVERROR_OUT_OF_MEMORY => WriteHeaderError::OutOfMemory,
759            AVERROR_INVALID_ARGUMENT => WriteHeaderError::InvalidArgument,
760            AVERROR_NOT_FOUND => WriteHeaderError::NotFound,
761            AVERROR_IO_ERROR => WriteHeaderError::IOError,
762            AVERROR_PIPE_ERROR => WriteHeaderError::PipeError,
763            AVERROR_BAD_FILE_DESCRIPTOR => WriteHeaderError::BadFileDescriptor,
764            AVERROR_NOT_IMPLEMENTED => WriteHeaderError::NotImplemented,
765            AVERROR_OPERATION_NOT_PERMITTED => WriteHeaderError::OperationNotPermitted,
766            AVERROR_PERMISSION_DENIED => WriteHeaderError::PermissionDenied,
767            AVERROR_TIMEOUT => WriteHeaderError::Timeout,
768            _ => WriteHeaderError::UnknownError(err_code),
769        }
770    }
771}
772
773#[derive(thiserror::Error, Debug)]
774pub enum WriteFrameError {
775    #[error("Memory allocation error")]
776    OutOfMemory,
777
778    #[error("Invalid argument provided")]
779    InvalidArgument,
780
781    #[error("Reached end of file while writing data")]
782    EndOfFile,
783
784    #[error("Timeout occurred while writing data")]
785    Timeout,
786
787    #[error("I/O error occurred while writing data")]
788    IOError,
789
790    #[error("Bad file descriptor")]
791    BadFileDescriptor,
792
793    #[error("Pipe error occurred")]
794    PipeError,
795
796    #[error("Functionality not implemented or unsupported operation")]
797    NotImplemented,
798
799    #[error("Operation not permitted")]
800    OperationNotPermitted,
801
802    #[error("Permission denied")]
803    PermissionDenied,
804
805    #[error("Not a valid socket")]
806    NotSocket,
807
808    #[error("An unknown error occurred. ret: {0}")]
809    UnknownError(i32),
810}
811
812impl From<i32> for WriteFrameError {
813    fn from(err_code: i32) -> Self {
814        match err_code {
815            AVERROR_OUT_OF_MEMORY => WriteFrameError::OutOfMemory,
816            AVERROR_INVALID_ARGUMENT => WriteFrameError::InvalidArgument,
817            AVERROR_EOF => WriteFrameError::EndOfFile,
818            AVERROR_TIMEOUT => WriteFrameError::Timeout,
819            AVERROR_IO_ERROR => WriteFrameError::IOError,
820            AVERROR_BAD_FILE_DESCRIPTOR => WriteFrameError::BadFileDescriptor,
821            AVERROR_PIPE_ERROR => WriteFrameError::PipeError,
822            AVERROR_NOT_IMPLEMENTED => WriteFrameError::NotImplemented,
823            AVERROR_OPERATION_NOT_PERMITTED => WriteFrameError::OperationNotPermitted,
824            AVERROR_PERMISSION_DENIED => WriteFrameError::PermissionDenied,
825            AVERROR_NOT_SOCKET => WriteFrameError::NotSocket,
826            _ => WriteFrameError::UnknownError(err_code),
827        }
828    }
829}
830
831#[derive(thiserror::Error, Debug)]
832pub enum EncodeSubtitleError {
833    #[error("Memory allocation error while encoding subtitle")]
834    OutOfMemory,
835
836    #[error("Invalid argument provided for subtitle encoding")]
837    InvalidArgument,
838
839    #[error("Operation not permitted while encoding subtitle")]
840    OperationNotPermitted,
841
842    #[error("The encoding functionality is not implemented or unsupported")]
843    NotImplemented,
844
845    #[error("Encoder temporarily unable to process, please retry")]
846    TryAgain,
847
848    #[error("Subtitle encoding failed with unknown error. ret: {0}")]
849    UnknownError(i32),
850}
851
852impl From<i32> for EncodeSubtitleError {
853    fn from(err_code: i32) -> Self {
854        match err_code {
855            AVERROR_OUT_OF_MEMORY => EncodeSubtitleError::OutOfMemory,
856            AVERROR_INVALID_ARGUMENT => EncodeSubtitleError::InvalidArgument,
857            AVERROR_OPERATION_NOT_PERMITTED => EncodeSubtitleError::OperationNotPermitted,
858            AVERROR_NOT_IMPLEMENTED => EncodeSubtitleError::NotImplemented,
859            AVERROR_AGAIN => EncodeSubtitleError::TryAgain,
860            _ => EncodeSubtitleError::UnknownError(err_code),
861        }
862    }
863}
864
865#[derive(thiserror::Error, Debug)]
866pub enum AllocPacketError {
867    #[error("Memory allocation error while alloc packet")]
868    OutOfMemory,
869}
870
871#[derive(thiserror::Error, Debug)]
872pub enum AllocFrameError {
873    #[error("Memory allocation error while alloc frame")]
874    OutOfMemory,
875}
876
877#[derive(thiserror::Error, Debug)]
878pub enum MuxingError {
879    #[error("Memory allocation error")]
880    OutOfMemory,
881
882    #[error("Invalid argument provided")]
883    InvalidArgument,
884
885    #[error("I/O error occurred during muxing")]
886    IOError,
887
888    #[error("Broken pipe during muxing")]
889    PipeError,
890
891    #[error("Bad file descriptor encountered")]
892    BadFileDescriptor,
893
894    #[error("Functionality not implemented or unsupported")]
895    NotImplemented,
896
897    #[error("Operation not permitted")]
898    OperationNotPermitted,
899
900    #[error("Resource temporarily unavailable")]
901    TryAgain,
902
903    #[error("An unknown error occurred. ret:{0}")]
904    UnknownError(i32),
905}
906
907impl From<i32> for MuxingError {
908    fn from(err_code: i32) -> Self {
909        match err_code {
910            AVERROR_OUT_OF_MEMORY => MuxingError::OutOfMemory,
911            AVERROR_INVALID_ARGUMENT => MuxingError::InvalidArgument,
912            AVERROR_IO_ERROR => MuxingError::IOError,
913            AVERROR_PIPE_ERROR => MuxingError::PipeError,
914            AVERROR_BAD_FILE_DESCRIPTOR => MuxingError::BadFileDescriptor,
915            AVERROR_NOT_IMPLEMENTED => MuxingError::NotImplemented,
916            AVERROR_OPERATION_NOT_PERMITTED => MuxingError::OperationNotPermitted,
917            AVERROR_AGAIN => MuxingError::TryAgain,
918            _ => MuxingError::UnknownError(err_code),
919        }
920    }
921}
922
923#[derive(thiserror::Error, Debug)]
924pub enum OpenEncoderError {
925    #[error("Memory allocation error occurred during encoder initialization")]
926    OutOfMemory,
927
928    #[error("Invalid argument provided to encoder")]
929    InvalidArgument,
930
931    #[error("I/O error occurred while opening encoder")]
932    IOError,
933
934    #[error("Broken pipe encountered during encoder initialization")]
935    PipeError,
936
937    #[error("Bad file descriptor used in encoder")]
938    BadFileDescriptor,
939
940    #[error("Encoder functionality not implemented or unsupported")]
941    NotImplemented,
942
943    #[error("Operation not permitted while configuring encoder")]
944    OperationNotPermitted,
945
946    #[error("Resource temporarily unavailable during encoder setup")]
947    TryAgain,
948
949    #[error("An unknown error occurred in encoder setup. ret:{0}")]
950    UnknownError(i32),
951}
952
953impl From<i32> for OpenEncoderError {
954    fn from(err_code: i32) -> Self {
955        match err_code {
956            AVERROR_OUT_OF_MEMORY => OpenEncoderError::OutOfMemory,
957            AVERROR_INVALID_ARGUMENT => OpenEncoderError::InvalidArgument,
958            AVERROR_IO_ERROR => OpenEncoderError::IOError,
959            AVERROR_PIPE_ERROR => OpenEncoderError::PipeError,
960            AVERROR_BAD_FILE_DESCRIPTOR => OpenEncoderError::BadFileDescriptor,
961            AVERROR_NOT_IMPLEMENTED => OpenEncoderError::NotImplemented,
962            AVERROR_OPERATION_NOT_PERMITTED => OpenEncoderError::OperationNotPermitted,
963            AVERROR_AGAIN => OpenEncoderError::TryAgain,
964            _ => OpenEncoderError::UnknownError(err_code),
965        }
966    }
967}
968
969#[derive(thiserror::Error, Debug)]
970pub enum EncodingError {
971    #[error("Memory allocation error during encoding")]
972    OutOfMemory,
973
974    #[error("Invalid argument provided to encoder")]
975    InvalidArgument,
976
977    #[error("I/O error occurred during encoding")]
978    IOError,
979
980    #[error("Broken pipe encountered during encoding")]
981    PipeError,
982
983    #[error("Bad file descriptor encountered during encoding")]
984    BadFileDescriptor,
985
986    #[error("Functionality not implemented or unsupported encoding feature")]
987    NotImplemented,
988
989    #[error("Operation not permitted for encoder")]
990    OperationNotPermitted,
991
992    #[error("Resource temporarily unavailable, try again later")]
993    TryAgain,
994
995    #[error("End of stream reached or no more frames to encode")]
996    EndOfStream,
997
998    #[error("An unknown error occurred during encoding. ret: {0}")]
999    UnknownError(i32),
1000}
1001
1002impl From<i32> for EncodingError {
1003    fn from(err_code: i32) -> Self {
1004        match err_code {
1005            AVERROR_OUT_OF_MEMORY => EncodingError::OutOfMemory,
1006            AVERROR_INVALID_ARGUMENT => EncodingError::InvalidArgument,
1007            AVERROR_IO_ERROR => EncodingError::IOError,
1008            AVERROR_PIPE_ERROR => EncodingError::PipeError,
1009            AVERROR_BAD_FILE_DESCRIPTOR => EncodingError::BadFileDescriptor,
1010            AVERROR_NOT_IMPLEMENTED => EncodingError::NotImplemented,
1011            AVERROR_OPERATION_NOT_PERMITTED => EncodingError::OperationNotPermitted,
1012            AVERROR_AGAIN => EncodingError::TryAgain,
1013            AVERROR_EOF => EncodingError::EndOfStream,
1014            _ => EncodingError::UnknownError(err_code),
1015        }
1016    }
1017}
1018
1019#[derive(thiserror::Error, Debug)]
1020pub enum FilterGraphError {
1021    #[error("Memory allocation error during filter graph processing")]
1022    OutOfMemory,
1023
1024    #[error("Invalid argument provided to filter graph processing")]
1025    InvalidArgument,
1026
1027    #[error("I/O error occurred during filter graph processing")]
1028    IOError,
1029
1030    #[error("Broken pipe during filter graph processing")]
1031    PipeError,
1032
1033    #[error("Bad file descriptor encountered during filter graph processing")]
1034    BadFileDescriptor,
1035
1036    #[error("Functionality not implemented or unsupported during filter graph processing")]
1037    NotImplemented,
1038
1039    #[error("Operation not permitted during filter graph processing")]
1040    OperationNotPermitted,
1041
1042    #[error("Resource temporarily unavailable during filter graph processing")]
1043    TryAgain,
1044
1045    #[error("EOF")]
1046    EOF,
1047
1048    #[error("An unknown error occurred during filter graph processing. ret:{0}")]
1049    UnknownError(i32),
1050}
1051
1052impl From<i32> for FilterGraphError {
1053    fn from(err_code: i32) -> Self {
1054        match err_code {
1055            AVERROR_OUT_OF_MEMORY => FilterGraphError::OutOfMemory,
1056            AVERROR_INVALID_ARGUMENT => FilterGraphError::InvalidArgument,
1057            AVERROR_IO_ERROR => FilterGraphError::IOError,
1058            AVERROR_PIPE_ERROR => FilterGraphError::PipeError,
1059            AVERROR_BAD_FILE_DESCRIPTOR => FilterGraphError::BadFileDescriptor,
1060            AVERROR_NOT_IMPLEMENTED => FilterGraphError::NotImplemented,
1061            AVERROR_OPERATION_NOT_PERMITTED => FilterGraphError::OperationNotPermitted,
1062            AVERROR_AGAIN => FilterGraphError::TryAgain,
1063            AVERROR_EOF => FilterGraphError::EOF,
1064            _ => FilterGraphError::UnknownError(err_code),
1065        }
1066    }
1067}
1068
1069#[derive(thiserror::Error, Debug)]
1070pub enum OpenDecoderError {
1071    #[error("Memory allocation error during decoder initialization")]
1072    OutOfMemory,
1073
1074    #[error("Invalid argument provided during decoder initialization")]
1075    InvalidArgument,
1076
1077    #[error("Functionality not implemented or unsupported during decoder initialization")]
1078    NotImplemented,
1079
1080    #[error("Resource temporarily unavailable during decoder initialization")]
1081    TryAgain,
1082
1083    #[error("I/O error occurred during decoder initialization")]
1084    IOError,
1085
1086    #[error("An unknown error occurred during decoder initialization: {0}")]
1087    UnknownError(i32),
1088}
1089
1090impl From<i32> for OpenDecoderError {
1091    fn from(err_code: i32) -> Self {
1092        match err_code {
1093            AVERROR_OUT_OF_MEMORY => OpenDecoderError::OutOfMemory,
1094            AVERROR_INVALID_ARGUMENT => OpenDecoderError::InvalidArgument,
1095            AVERROR_NOT_IMPLEMENTED => OpenDecoderError::NotImplemented,
1096            AVERROR_AGAIN => OpenDecoderError::TryAgain,
1097            AVERROR_IO_ERROR => OpenDecoderError::IOError,
1098            _ => OpenDecoderError::UnknownError(err_code),
1099        }
1100    }
1101}
1102
1103#[derive(thiserror::Error, Debug)]
1104pub enum DecodingError {
1105    #[error("Memory allocation error")]
1106    OutOfMemory,
1107
1108    #[error("Invalid argument provided")]
1109    InvalidArgument,
1110
1111    #[error("I/O error occurred during decoding")]
1112    IOError,
1113
1114    #[error("Timeout occurred during decoding")]
1115    Timeout,
1116
1117    #[error("Broken pipe encountered during decoding")]
1118    PipeError,
1119
1120    #[error("Bad file descriptor encountered during decoding")]
1121    BadFileDescriptor,
1122
1123    #[error("Unsupported functionality or format encountered")]
1124    NotImplemented,
1125
1126    #[error("Operation not permitted")]
1127    OperationNotPermitted,
1128
1129    #[error("Resource temporarily unavailable")]
1130    TryAgain,
1131
1132    #[error("An unknown decoding error occurred. ret:{0}")]
1133    UnknownError(i32),
1134}
1135
1136impl From<i32> for DecodingError {
1137    fn from(err_code: i32) -> Self {
1138        match err_code {
1139            AVERROR_OUT_OF_MEMORY => DecodingError::OutOfMemory,
1140            AVERROR_INVALID_ARGUMENT => DecodingError::InvalidArgument,
1141            AVERROR_IO_ERROR => DecodingError::IOError,
1142            AVERROR_TIMEOUT => DecodingError::Timeout,
1143            AVERROR_PIPE_ERROR => DecodingError::PipeError,
1144            AVERROR_BAD_FILE_DESCRIPTOR => DecodingError::BadFileDescriptor,
1145            AVERROR_NOT_IMPLEMENTED => DecodingError::NotImplemented,
1146            AVERROR_OPERATION_NOT_PERMITTED => DecodingError::OperationNotPermitted,
1147            AVERROR_AGAIN => DecodingError::TryAgain,
1148            _ => DecodingError::UnknownError(err_code),
1149        }
1150    }
1151}
1152
1153#[derive(thiserror::Error, Debug)]
1154pub enum DecoderError {
1155    #[error("not found.")]
1156    NotFound,
1157}
1158
1159#[derive(thiserror::Error, Debug)]
1160pub enum DemuxingError {
1161    #[error("Memory allocation error")]
1162    OutOfMemory,
1163
1164    #[error("Invalid argument provided")]
1165    InvalidArgument,
1166
1167    #[error("I/O error occurred during demuxing")]
1168    IOError,
1169
1170    #[error("End of file reached during demuxing")]
1171    EndOfFile,
1172
1173    #[error("Resource temporarily unavailable")]
1174    TryAgain,
1175
1176    #[error("Functionality not implemented or unsupported")]
1177    NotImplemented,
1178
1179    #[error("Operation not permitted")]
1180    OperationNotPermitted,
1181
1182    #[error("Bad file descriptor encountered")]
1183    BadFileDescriptor,
1184
1185    #[error("Invalid data found when processing input")]
1186    InvalidData,
1187
1188    #[error("An unknown error occurred. ret:{0}")]
1189    UnknownError(i32),
1190}
1191
1192impl From<i32> for DemuxingError {
1193    fn from(err_code: i32) -> Self {
1194        match err_code {
1195            AVERROR_OUT_OF_MEMORY => DemuxingError::OutOfMemory,
1196            AVERROR_INVALID_ARGUMENT => DemuxingError::InvalidArgument,
1197            AVERROR_IO_ERROR => DemuxingError::IOError,
1198            AVERROR_EOF => DemuxingError::EndOfFile,
1199            AVERROR_AGAIN => DemuxingError::TryAgain,
1200            AVERROR_NOT_IMPLEMENTED => DemuxingError::NotImplemented,
1201            AVERROR_OPERATION_NOT_PERMITTED => DemuxingError::OperationNotPermitted,
1202            AVERROR_BAD_FILE_DESCRIPTOR => DemuxingError::BadFileDescriptor,
1203            AVERROR_INVALIDDATA => DemuxingError::InvalidData,
1204            _ => DemuxingError::UnknownError(err_code),
1205        }
1206    }
1207}