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