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