Skip to main content

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