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("An unknown error occurred. ret:{0}")]
471 UnknownError(i32),
472}
473
474impl From<i32> for FindStreamError {
475 fn from(err_code: i32) -> Self {
476 match err_code {
477 AVERROR_OUT_OF_MEMORY => FindStreamError::OutOfMemory,
478 AVERROR_INVALID_ARGUMENT => FindStreamError::InvalidArgument,
479 AVERROR_EOF => FindStreamError::EndOfFile,
480 AVERROR_TIMEOUT => FindStreamError::Timeout,
481 AVERROR_IO_ERROR => FindStreamError::IOError,
482 AVERROR_INVALIDDATA => FindStreamError::InvalidData,
483 AVERROR_NOT_IMPLEMENTED => FindStreamError::NotImplemented,
484 AVERROR_OPERATION_NOT_PERMITTED => FindStreamError::OperationNotPermitted,
485 _ => FindStreamError::UnknownError(err_code),
486 }
487 }
488}
489
490#[derive(thiserror::Error, Debug)]
491pub enum FilterGraphParseError {
492 #[error("Memory allocation error")]
493 OutOfMemory,
494
495 #[error("Invalid argument provided")]
496 InvalidArgument,
497
498 #[error("End of file reached during parsing")]
499 EndOfFile,
500
501 #[error("I/O error occurred during parsing")]
502 IOError,
503
504 #[error("Invalid data encountered during parsing")]
505 InvalidData,
506
507 #[error("Functionality not implemented or unsupported filter format")]
508 NotImplemented,
509
510 #[error("Permission denied during filter graph parsing")]
511 PermissionDenied,
512
513 #[error("Socket operation on non-socket during filter graph parsing")]
514 NotSocket,
515
516 #[error("Option not found during filter graph configuration")]
517 OptionNotFound,
518
519 #[error("Invalid file index {0} in filtergraph description {1}")]
520 InvalidFileIndexInFg(usize, String),
521
522 #[error("Invalid file index {0} in output url: {1}")]
523 InvalidFileIndexInOutput(usize, String),
524
525 #[error("Invalid filter specifier {0}")]
526 InvalidFilterSpecifier(String),
527
528 #[error("Filter '{0}' has output {1} ({2}) unconnected")]
529 OutputUnconnected(String, usize, String),
530
531 #[error("An unknown error occurred. ret: {0}")]
532 UnknownError(i32),
533}
534
535impl From<i32> for FilterGraphParseError {
536 fn from(err_code: i32) -> Self {
537 match err_code {
538 AVERROR_OUT_OF_MEMORY => FilterGraphParseError::OutOfMemory,
539 AVERROR_INVALID_ARGUMENT => FilterGraphParseError::InvalidArgument,
540 AVERROR_EOF => FilterGraphParseError::EndOfFile,
541 AVERROR_IO_ERROR => FilterGraphParseError::IOError,
542 AVERROR_INVALIDDATA => FilterGraphParseError::InvalidData,
543 AVERROR_NOT_IMPLEMENTED => FilterGraphParseError::NotImplemented,
544 AVERROR_OPTION_NOT_FOUND => FilterGraphParseError::OptionNotFound,
545 _ => FilterGraphParseError::UnknownError(err_code),
546 }
547 }
548}
549
550#[derive(thiserror::Error, Debug)]
551pub enum AllocOutputContextError {
552 #[error("Memory allocation error")]
553 OutOfMemory,
554
555 #[error("Invalid argument provided")]
556 InvalidArgument,
557
558 #[error("File or stream not found")]
559 NotFound,
560
561 #[error("I/O error occurred while allocating the output context")]
562 IOError,
563
564 #[error("Pipe error, possibly the stream or data connection was broken")]
565 PipeError,
566
567 #[error("Invalid file descriptor")]
568 BadFileDescriptor,
569
570 #[error("Functionality not implemented or unsupported output format")]
571 NotImplemented,
572
573 #[error("Operation not permitted to allocate the output context")]
574 OperationNotPermitted,
575
576 #[error("Permission denied while allocating the output context")]
577 PermissionDenied,
578
579 #[error("The connection timed out while trying to allocate the output context")]
580 Timeout,
581
582 #[error("An unknown error occurred. ret:{0}")]
583 UnknownError(i32),
584}
585
586impl From<i32> for AllocOutputContextError {
587 fn from(err_code: i32) -> Self {
588 match err_code {
589 AVERROR_OUT_OF_MEMORY => AllocOutputContextError::OutOfMemory,
590 AVERROR_INVALID_ARGUMENT => AllocOutputContextError::InvalidArgument,
591 AVERROR_NOT_FOUND => AllocOutputContextError::NotFound,
592 AVERROR_IO_ERROR => AllocOutputContextError::IOError,
593 AVERROR_PIPE_ERROR => AllocOutputContextError::PipeError,
594 AVERROR_BAD_FILE_DESCRIPTOR => AllocOutputContextError::BadFileDescriptor,
595 AVERROR_NOT_IMPLEMENTED => AllocOutputContextError::NotImplemented,
596 AVERROR_OPERATION_NOT_PERMITTED => AllocOutputContextError::OperationNotPermitted,
597 AVERROR_PERMISSION_DENIED => AllocOutputContextError::PermissionDenied,
598 AVERROR_TIMEOUT => AllocOutputContextError::Timeout,
599 _ => AllocOutputContextError::UnknownError(err_code),
600 }
601 }
602}
603
604#[derive(thiserror::Error, Debug)]
605pub enum OpenOutputError {
606 #[error("Memory allocation error")]
607 OutOfMemory,
608
609 #[error("Invalid argument provided")]
610 InvalidArgument,
611
612 #[error("File or stream not found")]
613 NotFound,
614
615 #[error("I/O error occurred while opening the file or stream")]
616 IOError,
617
618 #[error("Pipe error, possibly the stream or data connection was broken")]
619 PipeError,
620
621 #[error("Invalid file descriptor")]
622 BadFileDescriptor,
623
624 #[error("Functionality not implemented or unsupported output format")]
625 NotImplemented,
626
627 #[error("Operation not permitted to open the file or stream")]
628 OperationNotPermitted,
629
630 #[error("Permission denied while opening the file or stream")]
631 PermissionDenied,
632
633 #[error("The connection timed out while trying to open the file or stream")]
634 Timeout,
635
636 #[error("encoder not found")]
637 EncoderNotFound,
638
639 #[error("Stream map '{0}' matches no streams;")]
640 MatchesNoStreams(String),
641
642 #[error("Invalid label {0}")]
643 InvalidLabel(String),
644
645 #[error("not contain any stream")]
646 NotContainStream,
647
648 #[error("unknown format of the frame")]
649 UnknownFrameFormat,
650
651 #[error("Invalid file index {0} in input url: {1}")]
652 InvalidFileIndexInIntput(usize, String),
653
654 #[error("An unknown error occurred. ret:{0}")]
655 UnknownError(i32),
656
657 #[error("Invalid sink provided")]
658 InvalidSink,
659
660 #[error("No seek callback is provided")]
661 SeekFunctionMissing,
662
663 #[error("Format '{0}' is unsupported")]
664 FormatUnsupported(String),
665}
666
667impl From<i32> for OpenOutputError {
668 fn from(err_code: i32) -> Self {
669 match err_code {
670 AVERROR_OUT_OF_MEMORY => OpenOutputError::OutOfMemory,
671 AVERROR_INVALID_ARGUMENT => OpenOutputError::InvalidArgument,
672 AVERROR_NOT_FOUND => OpenOutputError::NotFound,
673 AVERROR_IO_ERROR => OpenOutputError::IOError,
674 AVERROR_PIPE_ERROR => OpenOutputError::PipeError,
675 AVERROR_BAD_FILE_DESCRIPTOR => OpenOutputError::BadFileDescriptor,
676 AVERROR_NOT_IMPLEMENTED => OpenOutputError::NotImplemented,
677 AVERROR_OPERATION_NOT_PERMITTED => OpenOutputError::OperationNotPermitted,
678 AVERROR_PERMISSION_DENIED => OpenOutputError::PermissionDenied,
679 AVERROR_TIMEOUT => OpenOutputError::Timeout,
680 AVERROR_ENCODER_NOT_FOUND => OpenOutputError::EncoderNotFound,
681 _ => OpenOutputError::UnknownError(err_code),
682 }
683 }
684}
685
686#[derive(thiserror::Error, Debug)]
687pub enum FindDevicesError {
688 #[error("AVCaptureDevice class not found in macOS")]
689 AVCaptureDeviceNotFound,
690
691 #[error("current media_type({0}) is not supported")]
692 MediaTypeSupported(i32),
693 #[error("current OS is not supported")]
694 OsNotSupported,
695 #[error("device_description can not to string")]
696 UTF8Error,
697
698 #[error("Memory allocation error")]
699 OutOfMemory,
700 #[error("Invalid argument provided")]
701 InvalidArgument,
702 #[error("Device or stream not found")]
703 NotFound,
704 #[error("I/O error occurred while accessing the device or stream")]
705 IOError,
706 #[error("Operation not permitted for this device or stream")]
707 OperationNotPermitted,
708 #[error("Permission denied while accessing the device or stream")]
709 PermissionDenied,
710 #[error("This functionality is not implemented")]
711 NotImplemented,
712 #[error("Bad file descriptor")]
713 BadFileDescriptor,
714 #[error("An unknown error occurred. ret:{0}")]
715 UnknownError(i32),
716}
717
718impl From<i32> for FindDevicesError {
719 fn from(err_code: i32) -> Self {
720 match err_code {
721 AVERROR_OUT_OF_MEMORY => FindDevicesError::OutOfMemory,
722 AVERROR_INVALID_ARGUMENT => FindDevicesError::InvalidArgument,
723 AVERROR_NOT_FOUND => FindDevicesError::NotFound,
724 AVERROR_IO_ERROR => FindDevicesError::IOError,
725 AVERROR_OPERATION_NOT_PERMITTED => FindDevicesError::OperationNotPermitted,
726 AVERROR_PERMISSION_DENIED => FindDevicesError::PermissionDenied,
727 AVERROR_NOT_IMPLEMENTED => FindDevicesError::NotImplemented,
728 AVERROR_BAD_FILE_DESCRIPTOR => FindDevicesError::BadFileDescriptor,
729 _ => FindDevicesError::UnknownError(err_code),
730 }
731 }
732}
733
734#[derive(thiserror::Error, Debug)]
735pub enum WriteHeaderError {
736 #[error("Memory allocation error")]
737 OutOfMemory,
738
739 #[error("Invalid argument provided")]
740 InvalidArgument,
741
742 #[error("File or stream not found")]
743 NotFound,
744
745 #[error("I/O error occurred while writing the header")]
746 IOError,
747
748 #[error("Pipe error, possibly the stream or data connection was broken")]
749 PipeError,
750
751 #[error("Invalid file descriptor")]
752 BadFileDescriptor,
753
754 #[error("Functionality not implemented or unsupported output format")]
755 NotImplemented,
756
757 #[error("Operation not permitted to write the header")]
758 OperationNotPermitted,
759
760 #[error("Permission denied while writing the header")]
761 PermissionDenied,
762
763 #[error("The connection timed out while trying to write the header")]
764 Timeout,
765
766 #[error("An unknown error occurred. ret:{0}")]
767 UnknownError(i32),
768}
769
770impl From<i32> for WriteHeaderError {
771 fn from(err_code: i32) -> Self {
772 match err_code {
773 AVERROR_OUT_OF_MEMORY => WriteHeaderError::OutOfMemory,
774 AVERROR_INVALID_ARGUMENT => WriteHeaderError::InvalidArgument,
775 AVERROR_NOT_FOUND => WriteHeaderError::NotFound,
776 AVERROR_IO_ERROR => WriteHeaderError::IOError,
777 AVERROR_PIPE_ERROR => WriteHeaderError::PipeError,
778 AVERROR_BAD_FILE_DESCRIPTOR => WriteHeaderError::BadFileDescriptor,
779 AVERROR_NOT_IMPLEMENTED => WriteHeaderError::NotImplemented,
780 AVERROR_OPERATION_NOT_PERMITTED => WriteHeaderError::OperationNotPermitted,
781 AVERROR_PERMISSION_DENIED => WriteHeaderError::PermissionDenied,
782 AVERROR_TIMEOUT => WriteHeaderError::Timeout,
783 _ => WriteHeaderError::UnknownError(err_code),
784 }
785 }
786}
787
788#[derive(thiserror::Error, Debug)]
789pub enum WriteFrameError {
790 #[error("Memory allocation error")]
791 OutOfMemory,
792
793 #[error("Invalid argument provided")]
794 InvalidArgument,
795
796 #[error("Reached end of file while writing data")]
797 EndOfFile,
798
799 #[error("Timeout occurred while writing data")]
800 Timeout,
801
802 #[error("I/O error occurred while writing data")]
803 IOError,
804
805 #[error("Bad file descriptor")]
806 BadFileDescriptor,
807
808 #[error("Pipe error occurred")]
809 PipeError,
810
811 #[error("Functionality not implemented or unsupported operation")]
812 NotImplemented,
813
814 #[error("Operation not permitted")]
815 OperationNotPermitted,
816
817 #[error("Permission denied")]
818 PermissionDenied,
819
820 #[error("Not a valid socket")]
821 NotSocket,
822
823 #[error("An unknown error occurred. ret: {0}")]
824 UnknownError(i32),
825}
826
827impl From<i32> for WriteFrameError {
828 fn from(err_code: i32) -> Self {
829 match err_code {
830 AVERROR_OUT_OF_MEMORY => WriteFrameError::OutOfMemory,
831 AVERROR_INVALID_ARGUMENT => WriteFrameError::InvalidArgument,
832 AVERROR_EOF => WriteFrameError::EndOfFile,
833 AVERROR_TIMEOUT => WriteFrameError::Timeout,
834 AVERROR_IO_ERROR => WriteFrameError::IOError,
835 AVERROR_BAD_FILE_DESCRIPTOR => WriteFrameError::BadFileDescriptor,
836 AVERROR_PIPE_ERROR => WriteFrameError::PipeError,
837 AVERROR_NOT_IMPLEMENTED => WriteFrameError::NotImplemented,
838 AVERROR_OPERATION_NOT_PERMITTED => WriteFrameError::OperationNotPermitted,
839 AVERROR_PERMISSION_DENIED => WriteFrameError::PermissionDenied,
840 AVERROR_NOT_SOCKET => WriteFrameError::NotSocket,
841 _ => WriteFrameError::UnknownError(err_code),
842 }
843 }
844}
845
846#[derive(thiserror::Error, Debug)]
847pub enum EncodeSubtitleError {
848 #[error("Memory allocation error while encoding subtitle")]
849 OutOfMemory,
850
851 #[error("Invalid argument provided for subtitle encoding")]
852 InvalidArgument,
853
854 #[error("Operation not permitted while encoding subtitle")]
855 OperationNotPermitted,
856
857 #[error("The encoding functionality is not implemented or unsupported")]
858 NotImplemented,
859
860 #[error("Encoder temporarily unable to process, please retry")]
861 TryAgain,
862
863 #[error("Subtitle encoding failed with unknown error. ret: {0}")]
864 UnknownError(i32),
865}
866
867impl From<i32> for EncodeSubtitleError {
868 fn from(err_code: i32) -> Self {
869 match err_code {
870 AVERROR_OUT_OF_MEMORY => EncodeSubtitleError::OutOfMemory,
871 AVERROR_INVALID_ARGUMENT => EncodeSubtitleError::InvalidArgument,
872 AVERROR_OPERATION_NOT_PERMITTED => EncodeSubtitleError::OperationNotPermitted,
873 AVERROR_NOT_IMPLEMENTED => EncodeSubtitleError::NotImplemented,
874 AVERROR_AGAIN => EncodeSubtitleError::TryAgain,
875 _ => EncodeSubtitleError::UnknownError(err_code),
876 }
877 }
878}
879
880#[derive(thiserror::Error, Debug)]
881pub enum AllocPacketError {
882 #[error("Memory allocation error while alloc packet")]
883 OutOfMemory,
884}
885
886#[derive(thiserror::Error, Debug)]
887pub enum AllocFrameError {
888 #[error("Memory allocation error while alloc frame")]
889 OutOfMemory,
890}
891
892#[derive(thiserror::Error, Debug)]
893pub enum MuxingError {
894 #[error("Memory allocation error")]
895 OutOfMemory,
896
897 #[error("Invalid argument provided")]
898 InvalidArgument,
899
900 #[error("I/O error occurred during muxing")]
901 IOError,
902
903 #[error("Broken pipe during muxing")]
904 PipeError,
905
906 #[error("Bad file descriptor encountered")]
907 BadFileDescriptor,
908
909 #[error("Functionality not implemented or unsupported")]
910 NotImplemented,
911
912 #[error("Operation not permitted")]
913 OperationNotPermitted,
914
915 #[error("Resource temporarily unavailable")]
916 TryAgain,
917
918 #[error("An unknown error occurred. ret:{0}")]
919 UnknownError(i32),
920}
921
922impl From<i32> for MuxingError {
923 fn from(err_code: i32) -> Self {
924 match err_code {
925 AVERROR_OUT_OF_MEMORY => MuxingError::OutOfMemory,
926 AVERROR_INVALID_ARGUMENT => MuxingError::InvalidArgument,
927 AVERROR_IO_ERROR => MuxingError::IOError,
928 AVERROR_PIPE_ERROR => MuxingError::PipeError,
929 AVERROR_BAD_FILE_DESCRIPTOR => MuxingError::BadFileDescriptor,
930 AVERROR_NOT_IMPLEMENTED => MuxingError::NotImplemented,
931 AVERROR_OPERATION_NOT_PERMITTED => MuxingError::OperationNotPermitted,
932 AVERROR_AGAIN => MuxingError::TryAgain,
933 _ => MuxingError::UnknownError(err_code),
934 }
935 }
936}
937
938#[derive(thiserror::Error, Debug)]
939pub enum OpenEncoderError {
940 #[error("Memory allocation error occurred during encoder initialization")]
941 OutOfMemory,
942
943 #[error("Invalid argument provided to encoder")]
944 InvalidArgument,
945
946 #[error("I/O error occurred while opening encoder")]
947 IOError,
948
949 #[error("Broken pipe encountered during encoder initialization")]
950 PipeError,
951
952 #[error("Bad file descriptor used in encoder")]
953 BadFileDescriptor,
954
955 #[error("Encoder functionality not implemented or unsupported")]
956 NotImplemented,
957
958 #[error("Operation not permitted while configuring encoder")]
959 OperationNotPermitted,
960
961 #[error("Resource temporarily unavailable during encoder setup")]
962 TryAgain,
963
964 #[error("An unknown error occurred in encoder setup. ret:{0}")]
965 UnknownError(i32),
966}
967
968impl From<i32> for OpenEncoderError {
969 fn from(err_code: i32) -> Self {
970 match err_code {
971 AVERROR_OUT_OF_MEMORY => OpenEncoderError::OutOfMemory,
972 AVERROR_INVALID_ARGUMENT => OpenEncoderError::InvalidArgument,
973 AVERROR_IO_ERROR => OpenEncoderError::IOError,
974 AVERROR_PIPE_ERROR => OpenEncoderError::PipeError,
975 AVERROR_BAD_FILE_DESCRIPTOR => OpenEncoderError::BadFileDescriptor,
976 AVERROR_NOT_IMPLEMENTED => OpenEncoderError::NotImplemented,
977 AVERROR_OPERATION_NOT_PERMITTED => OpenEncoderError::OperationNotPermitted,
978 AVERROR_AGAIN => OpenEncoderError::TryAgain,
979 _ => OpenEncoderError::UnknownError(err_code),
980 }
981 }
982}
983
984#[derive(thiserror::Error, Debug)]
985pub enum EncodingError {
986 #[error("Memory allocation error during encoding")]
987 OutOfMemory,
988
989 #[error("Invalid argument provided to encoder")]
990 InvalidArgument,
991
992 #[error("I/O error occurred during encoding")]
993 IOError,
994
995 #[error("Broken pipe encountered during encoding")]
996 PipeError,
997
998 #[error("Bad file descriptor encountered during encoding")]
999 BadFileDescriptor,
1000
1001 #[error("Functionality not implemented or unsupported encoding feature")]
1002 NotImplemented,
1003
1004 #[error("Operation not permitted for encoder")]
1005 OperationNotPermitted,
1006
1007 #[error("Resource temporarily unavailable, try again later")]
1008 TryAgain,
1009
1010 #[error("End of stream reached or no more frames to encode")]
1011 EndOfStream,
1012
1013 #[error("An unknown error occurred during encoding. ret: {0}")]
1014 UnknownError(i32),
1015}
1016
1017impl From<i32> for EncodingError {
1018 fn from(err_code: i32) -> Self {
1019 match err_code {
1020 AVERROR_OUT_OF_MEMORY => EncodingError::OutOfMemory,
1021 AVERROR_INVALID_ARGUMENT => EncodingError::InvalidArgument,
1022 AVERROR_IO_ERROR => EncodingError::IOError,
1023 AVERROR_PIPE_ERROR => EncodingError::PipeError,
1024 AVERROR_BAD_FILE_DESCRIPTOR => EncodingError::BadFileDescriptor,
1025 AVERROR_NOT_IMPLEMENTED => EncodingError::NotImplemented,
1026 AVERROR_OPERATION_NOT_PERMITTED => EncodingError::OperationNotPermitted,
1027 AVERROR_AGAIN => EncodingError::TryAgain,
1028 AVERROR_EOF => EncodingError::EndOfStream,
1029 _ => EncodingError::UnknownError(err_code),
1030 }
1031 }
1032}
1033
1034#[derive(thiserror::Error, Debug)]
1035pub enum FilterGraphError {
1036 #[error("Memory allocation error during filter graph processing")]
1037 OutOfMemory,
1038
1039 #[error("Invalid argument provided to filter graph processing")]
1040 InvalidArgument,
1041
1042 #[error("I/O error occurred during filter graph processing")]
1043 IOError,
1044
1045 #[error("Broken pipe during filter graph processing")]
1046 PipeError,
1047
1048 #[error("Bad file descriptor encountered during filter graph processing")]
1049 BadFileDescriptor,
1050
1051 #[error("Functionality not implemented or unsupported during filter graph processing")]
1052 NotImplemented,
1053
1054 #[error("Operation not permitted during filter graph processing")]
1055 OperationNotPermitted,
1056
1057 #[error("Resource temporarily unavailable during filter graph processing")]
1058 TryAgain,
1059
1060 #[error("EOF")]
1061 EOF,
1062
1063 #[error("An unknown error occurred during filter graph processing. ret:{0}")]
1064 UnknownError(i32),
1065}
1066
1067impl From<i32> for FilterGraphError {
1068 fn from(err_code: i32) -> Self {
1069 match err_code {
1070 AVERROR_OUT_OF_MEMORY => FilterGraphError::OutOfMemory,
1071 AVERROR_INVALID_ARGUMENT => FilterGraphError::InvalidArgument,
1072 AVERROR_IO_ERROR => FilterGraphError::IOError,
1073 AVERROR_PIPE_ERROR => FilterGraphError::PipeError,
1074 AVERROR_BAD_FILE_DESCRIPTOR => FilterGraphError::BadFileDescriptor,
1075 AVERROR_NOT_IMPLEMENTED => FilterGraphError::NotImplemented,
1076 AVERROR_OPERATION_NOT_PERMITTED => FilterGraphError::OperationNotPermitted,
1077 AVERROR_AGAIN => FilterGraphError::TryAgain,
1078 AVERROR_EOF => FilterGraphError::EOF,
1079 _ => FilterGraphError::UnknownError(err_code),
1080 }
1081 }
1082}
1083
1084#[derive(thiserror::Error, Debug)]
1085pub enum OpenDecoderError {
1086 #[error("Memory allocation error during decoder initialization")]
1087 OutOfMemory,
1088
1089 #[error("Invalid argument provided during decoder initialization")]
1090 InvalidArgument,
1091
1092 #[error("Functionality not implemented or unsupported during decoder initialization")]
1093 NotImplemented,
1094
1095 #[error("Resource temporarily unavailable during decoder initialization")]
1096 TryAgain,
1097
1098 #[error("I/O error occurred during decoder initialization")]
1099 IOError,
1100
1101 #[error("An unknown error occurred during decoder initialization: {0}")]
1102 UnknownError(i32),
1103}
1104
1105impl From<i32> for OpenDecoderError {
1106 fn from(err_code: i32) -> Self {
1107 match err_code {
1108 AVERROR_OUT_OF_MEMORY => OpenDecoderError::OutOfMemory,
1109 AVERROR_INVALID_ARGUMENT => OpenDecoderError::InvalidArgument,
1110 AVERROR_NOT_IMPLEMENTED => OpenDecoderError::NotImplemented,
1111 AVERROR_AGAIN => OpenDecoderError::TryAgain,
1112 AVERROR_IO_ERROR => OpenDecoderError::IOError,
1113 _ => OpenDecoderError::UnknownError(err_code),
1114 }
1115 }
1116}
1117
1118#[derive(thiserror::Error, Debug)]
1119pub enum DecodingError {
1120 #[error("Memory allocation error")]
1121 OutOfMemory,
1122
1123 #[error("Invalid argument provided")]
1124 InvalidArgument,
1125
1126 #[error("I/O error occurred during decoding")]
1127 IOError,
1128
1129 #[error("Timeout occurred during decoding")]
1130 Timeout,
1131
1132 #[error("Broken pipe encountered during decoding")]
1133 PipeError,
1134
1135 #[error("Bad file descriptor encountered during decoding")]
1136 BadFileDescriptor,
1137
1138 #[error("Unsupported functionality or format encountered")]
1139 NotImplemented,
1140
1141 #[error("Operation not permitted")]
1142 OperationNotPermitted,
1143
1144 #[error("Resource temporarily unavailable")]
1145 TryAgain,
1146
1147 #[error("An unknown decoding error occurred. ret:{0}")]
1148 UnknownError(i32),
1149}
1150
1151impl From<i32> for DecodingError {
1152 fn from(err_code: i32) -> Self {
1153 match err_code {
1154 AVERROR_OUT_OF_MEMORY => DecodingError::OutOfMemory,
1155 AVERROR_INVALID_ARGUMENT => DecodingError::InvalidArgument,
1156 AVERROR_IO_ERROR => DecodingError::IOError,
1157 AVERROR_TIMEOUT => DecodingError::Timeout,
1158 AVERROR_PIPE_ERROR => DecodingError::PipeError,
1159 AVERROR_BAD_FILE_DESCRIPTOR => DecodingError::BadFileDescriptor,
1160 AVERROR_NOT_IMPLEMENTED => DecodingError::NotImplemented,
1161 AVERROR_OPERATION_NOT_PERMITTED => DecodingError::OperationNotPermitted,
1162 AVERROR_AGAIN => DecodingError::TryAgain,
1163 _ => DecodingError::UnknownError(err_code),
1164 }
1165 }
1166}
1167
1168#[derive(thiserror::Error, Debug)]
1169pub enum DecoderError {
1170 #[error("not found.")]
1171 NotFound,
1172}
1173
1174#[derive(thiserror::Error, Debug)]
1175pub enum DemuxingError {
1176 #[error("Memory allocation error")]
1177 OutOfMemory,
1178
1179 #[error("Invalid argument provided")]
1180 InvalidArgument,
1181
1182 #[error("I/O error occurred during demuxing")]
1183 IOError,
1184
1185 #[error("End of file reached during demuxing")]
1186 EndOfFile,
1187
1188 #[error("Resource temporarily unavailable")]
1189 TryAgain,
1190
1191 #[error("Functionality not implemented or unsupported")]
1192 NotImplemented,
1193
1194 #[error("Operation not permitted")]
1195 OperationNotPermitted,
1196
1197 #[error("Bad file descriptor encountered")]
1198 BadFileDescriptor,
1199
1200 #[error("Invalid data found when processing input")]
1201 InvalidData,
1202
1203 #[error("An unknown error occurred. ret:{0}")]
1204 UnknownError(i32),
1205}
1206
1207impl From<i32> for DemuxingError {
1208 fn from(err_code: i32) -> Self {
1209 match err_code {
1210 AVERROR_OUT_OF_MEMORY => DemuxingError::OutOfMemory,
1211 AVERROR_INVALID_ARGUMENT => DemuxingError::InvalidArgument,
1212 AVERROR_IO_ERROR => DemuxingError::IOError,
1213 AVERROR_EOF => DemuxingError::EndOfFile,
1214 AVERROR_AGAIN => DemuxingError::TryAgain,
1215 AVERROR_NOT_IMPLEMENTED => DemuxingError::NotImplemented,
1216 AVERROR_OPERATION_NOT_PERMITTED => DemuxingError::OperationNotPermitted,
1217 AVERROR_BAD_FILE_DESCRIPTOR => DemuxingError::BadFileDescriptor,
1218 AVERROR_INVALIDDATA => DemuxingError::InvalidData,
1219 _ => DemuxingError::UnknownError(err_code),
1220 }
1221 }
1222}
1223
1224#[derive(thiserror::Error, Debug)]
1226pub enum PacketScannerError {
1227 #[error("while seeking: {0}")]
1229 SeekError(DemuxingError),
1230
1231 #[error("while reading packet: {0}")]
1233 ReadError(DemuxingError),
1234}