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