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