1use crate::frames::{MAX_AUDIO_BYTES, MAX_METADATA_BYTES, MAX_VIDEO_BYTES};
3use crate::media::MAX_ALLOCATION_BYTES;
4use crate::{ColorInfo, ColorPrimaries, FrameMetadataStatus, PixelFormat, TransferFunction};
5use std::time::Duration;
6use thiserror::Error;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
10#[non_exhaustive]
11pub enum ColorMetadataDefect {
12 #[error("the element is not closed")]
14 UnclosedElement,
15 #[error("an attribute cannot start at this byte")]
17 AttributeStart,
18 #[error("an attribute has no value")]
20 MissingValue,
21 #[error("an attribute value is not quoted")]
23 UnquotedValue,
24 #[error("an attribute value has no closing quote")]
26 UnclosedValue,
27 #[error("an attribute occurs twice")]
29 DuplicateAttribute,
30 #[error("a color attribute has an undefined value")]
32 UndefinedValue,
33 #[error("a color attribute has an invalid XML value")]
35 InvalidAttributeValue,
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
40#[non_exhaustive]
41pub enum ImageCodecKind {
42 #[error("PNG")]
44 Png,
45 #[error("JPEG")]
47 Jpeg,
48 #[error("WebP")]
50 Webp,
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
55#[non_exhaustive]
56pub enum ImageSettingKind {
57 #[error("quality")]
59 Quality,
60 #[error("effort")]
62 Effort,
63}
64
65#[derive(Debug, Clone, PartialEq, Eq, Hash, Error)]
67#[error(
68 "the SDK created no {object}: it does not accept {address:?} as a Discovery Server address"
69)]
70pub struct DiscoveryAddressFailure {
71 pub object: &'static str,
73 pub address: Box<str>,
75}
76
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
79#[non_exhaustive]
80pub enum DiscoveryDefect {
81 #[error("SDK discovery array span overflow")]
83 ArraySpanOverflow,
84 #[error("SDK discovery array is null with a nonzero count")]
86 NullArray,
87}
88#[derive(Debug, Clone, PartialEq, Error)]
98#[non_exhaustive]
99pub enum LayoutDefect {
100 #[error("{detail}")]
102 FrameRate {
103 detail: CompactDiagnostic<FrameRateDefect>,
105 },
106 #[error("{detail}")]
108 CompressedVideoDimensions {
109 detail: CompactDiagnostic<VideoDimensionsDefect>,
111 },
112
113 #[error("Video line stride must be positive, got 0")]
115 VideoZeroStride,
116 #[error("Audio channel stride exceeds i32 range")]
118 AudioStrideRange,
119 #[error("Video frame has invalid width: {0}")]
121 VideoWidth(DiagnosticInteger),
122 #[error("NDI video frames require even width, got {0}")]
124 VideoOddWidth(DiagnosticInteger),
125 #[error("Video frame has invalid height: {0}")]
127 VideoHeight(DiagnosticInteger),
128 #[error("Uncompressed video frame has invalid line_stride_in_bytes: {0}")]
130 VideoSdkStride(i32),
131 #[error("Video line_stride_in_bytes {stride} is smaller than minimum row size {minimum} for {format:?} width {width}")]
133 VideoShortStride {
134 stride: usize,
136 minimum: usize,
138 format: PixelFormat,
140 width: u32,
142 },
143 #[error("Video frame exceeds maximum size: {0} bytes > {MAX_VIDEO_BYTES} bytes")]
145 VideoBytes(DiagnosticSize),
146 #[error("Planar 4:2:0 (YV12/I420) video frames require even height and line stride, got height {height} and stride {stride}")]
148 VideoPlanar420 {
149 height: usize,
151 stride: usize,
153 },
154 #[error("Semi-planar 4:2:0 (NV12) video frames require even height, got {0}")]
156 VideoSemiPlanar420(usize),
157 #[error("UYVA video frames require even line stride, got {0}")]
159 VideoUyvaStride(usize),
160 #[error("Video frame has invalid picture aspect ratio: {0}")]
162 PictureAspectRatio(f32),
163 #[error("Invalid sample rate: {0}")]
165 AudioRate(DiagnosticInteger),
166 #[error("Invalid number of {kind}: {value}")]
168 AudioCount {
169 value: DiagnosticInteger,
171 kind: AudioCountKind,
173 },
174 #[error("Invalid channel_stride_in_bytes: {0}")]
176 AudioStride(DiagnosticInteger),
177 #[error("channel_stride_in_bytes must be a multiple of 4, got {0}")]
179 AudioStrideAlignment(usize),
180 #[error(
182 "channel_stride_in_bytes {stride} is smaller than one channel of audio samples {minimum}"
183 )]
184 AudioShortStride {
185 stride: usize,
187 minimum: usize,
189 },
190 #[error("Audio frame exceeds maximum size: {0} bytes > {MAX_AUDIO_BYTES} bytes")]
192 AudioBytes(DiagnosticSize),
193}
194
195#[derive(Debug, Clone, PartialEq, Error)]
201#[non_exhaustive]
202pub enum FrameDefect {
203 #[error("Unknown packet envelope codec FourCC: 0x{fourcc:08X}")]
205 UnknownEnvelopeCodec {
206 fourcc: u32,
208 },
209 #[error(transparent)]
211 Layout(LayoutDefect),
212 #[error("{codec} {dimension} {length} exceeds maximum supported value {maximum}")]
214 ImageDimension {
215 codec: ImageCodecKind,
217 dimension: ImageAxisKind,
219 length: usize,
221 maximum: usize,
223 },
224 #[error("Metadata frame length does not include a trailing NUL terminator")]
226 MetadataMissingTerminator,
227 #[error("Metadata frame contains an interior NUL byte")]
229 MetadataInteriorNul,
230 #[error("Metadata frame has non-zero length with null data pointer")]
232 MetadataNullData,
233 #[error("Video frame has null data pointer")]
235 NullVideoData,
236 #[error("Audio frame has null data pointer")]
238 NullAudioData,
239 #[error("Audio data pointer is not aligned for f32")]
241 AudioMisaligned,
242 #[error("Zero-length audio frame has non-null data pointer")]
244 EmptyAudioHasData,
245 #[error("V210 stride must be a multiple of four and cover every complete pixel group")]
247 V210Stride,
248 #[error("V210 storage exceeds the video limit")]
250 V210Storage,
251 #[error("V210 conversion requires a positive width divisible by six")]
253 V210Width,
254 #[error("P216 frame format and dimensions must match the V210 layout")]
256 P216LayoutMismatch,
257 #[error("planar destination rate, channels and samples must match the interleaved source")]
259 PlanarAudioMismatch,
260 #[error("FrameSync audio rate, channels and samples must match the request")]
262 FrameSyncAudioMismatch,
263 #[error("Truncated compressed packet header")]
265 PacketHeaderTruncated,
266 #[error("Unsupported compressed packet header size")]
268 PacketHeaderSize,
269 #[error("Cannot send a packet with an unsupported header version or unknown flags")]
271 PacketHeaderUnsupported,
272 #[error("Packet codec does not match the frame's codec")]
274 PacketCodecMismatch,
275 #[error("Empty codec payload")]
277 EmptyCodecPayload,
278 #[error("Packet header lengths do not match the size of the frame")]
280 PacketLengthsMismatch,
281 #[error("Keyframes require codec configuration data")]
283 KeyframeConfigurationMissing,
284 #[error("AAC packets must carry the keyframe flag")]
286 AacKeyframeMissing,
287 #[error("AAC packets require their AudioSpecificConfig as codec configuration data")]
289 AacConfigurationMissing,
290 #[error("The AAC configuration names a different sample rate than the frame")]
292 AacRateMismatch,
293 #[error("The AAC configuration names a different channel layout than the frame")]
295 AacChannelsMismatch,
296 #[error("Invalid compressed packet length")]
298 PacketLength,
299 #[error("Compressed packet length overflow")]
301 PacketLengthOverflow,
302 #[error("Truncated compressed packet")]
304 PacketTruncated,
305 #[error("Packet size overflow")]
307 PacketSizeOverflow,
308 #[error("Invalid compressed packet payload size")]
310 PacketPayloadSize,
311 #[error("Unknown compressed video FourCC")]
313 UnknownCompressedVideo,
314 #[error("A SpeedHQ frame begins with its quality, a byte below 100")]
316 SpeedHqQuality,
317 #[error(
319 "An H.264 or HEVC picture on the preview stream is at most 640 pixels wide and 640 high"
320 )]
321 PreviewVideoDimensions,
322 #[error("Invalid compressed video size")]
324 CompressedVideoSize,
325 #[error("Truncated SpeedHQ frame")]
327 SpeedHqTruncated,
328 #[error("Opus is sent at 8000, 12000, 16000, 24000 or 48000 Hz")]
330 OpusSampleRate,
331 #[error("An Opus frame holds 2.5, 5, 10, 20, 40 or 60 ms of audio")]
333 OpusDuration,
334 #[error("An AAC frame holds 1024 samples per channel")]
336 AacSampleCount,
337 #[error("AAC is sent at a sample rate its configuration can name, from 7350 to 96000 Hz")]
339 AacSampleRate,
340 #[error("AAC is sent with one to six or eight channels")]
342 AacChannels,
343 #[error("Invalid compressed audio size")]
345 CompressedAudioSize,
346 #[error("Invalid compressed frame buffer")]
348 CompressedBuffer,
349 #[error("Invalid scatter block count")]
351 ScatterBlockCount,
352 #[error("Scatter blocks must not be empty")]
354 EmptyScatterBlock,
355 #[error("Scatter frame exceeds the packet size limit")]
357 ScatterSize,
358 #[error("The first scatter block must hold the frame's complete header")]
360 ScatterHeader,
361 #[error("Unknown compressed audio FourCC")]
363 UnknownCompressedAudio,
364 #[error("Unknown scan type: 0x{code:08X}")]
366 UnknownScanType {
367 code: u32,
369 },
370 #[error("Audio buffer has {actual} samples, requires at least {minimum}")]
372 AudioBufferTooSmall {
373 actual: usize,
375 minimum: usize,
377 },
378 #[error("Metadata frame has negative length: {length}")]
380 MetadataNegativeLength {
381 length: i32,
383 },
384 #[error("Metadata exceeds maximum size: {length} bytes > {MAX_METADATA_BYTES} bytes")]
386 MetadataTooLarge {
387 length: usize,
389 },
390 #[error("Frame metadata is missing a NUL terminator within {MAX_METADATA_BYTES} bytes")]
392 MetadataUnterminated,
393 #[error("Video data length {actual}, expected {expected} bytes for validated layout")]
395 VideoDataLength {
396 actual: usize,
398 expected: usize,
400 },
401 #[error("{detail}")]
403 AudioDataLength {
404 detail: CompactDiagnostic<AudioLengthDefect>,
406 },
407 #[error("Zero-length audio frame has non-zero channel_stride_in_bytes: {stride}")]
409 EmptyAudioStride {
410 stride: i32,
412 },
413 #[error("Invalid zero-length audio state: sample_rate={sample_rate}, no_channels={channels}")]
415 EmptyAudioFormat {
416 sample_rate: i32,
418 channels: i32,
420 },
421 #[error("Unknown audio format FourCC: 0x{fourcc:08X}")]
423 UnknownAudioFormat {
424 fourcc: u32,
426 },
427 #[error("Unknown pixel format FourCC: 0x{fourcc:08X}")]
429 UnknownPixelFormat {
430 fourcc: u32,
432 },
433 #[error(
435 "FrameSync audio input-format query returned {channels} channels of {samples} samples"
436 )]
437 FrameSyncAudioInput {
438 channels: usize,
440 samples: usize,
442 },
443 #[error("Buffer too small for {format:?}: got {actual} bytes, expected at least {minimum}")]
445 VideoBufferTooSmall {
446 format: PixelFormat,
448 actual: usize,
450 minimum: usize,
452 },
453 #[error("V210 buffer has {actual} words, requires {minimum}")]
455 V210BufferTooSmall {
456 actual: usize,
458 minimum: usize,
460 },
461 #[error(
463 "interleaved audio has {actual} samples, which is not a multiple of {channels} channels"
464 )]
465 InterleavedAudioLength {
466 actual: usize,
468 channels: u32,
470 },
471 #[error("audio destination has {actual} samples, requires {minimum}")]
473 AudioDestinationLength {
474 actual: usize,
476 minimum: usize,
478 },
479 #[error("The frame's color description cannot be read because its metadata was withheld ({status:?}); ColorPolicy::Override explicitly supplies its color conversion")]
481 ColorMetadataWithheld {
482 status: FrameMetadataStatus,
484 },
485 #[error(
487 "The frame's metadata holds ndi_color_info elements that differ: {first:?} and {second:?}"
488 )]
489 ConflictingColorMetadata {
490 first: ColorInfo,
492 second: ColorInfo,
494 },
495 #[error("The frame's ndi_color_info gives the {transfer} transfer function; HdrPolicy::CodeValues encodes its code values to a tagged PNG")]
497 HdrRefused {
498 transfer: TransferFunction,
500 },
501
502 #[error("{diagnostic}")]
504 ColorMetadata {
505 issue: ColorMetadataDefect,
507 diagnostic: Box<str>,
509 },
510 #[error("{codec} encoding failed: {diagnostic}")]
512 EncodingFailed {
513 codec: ImageCodecKind,
515 diagnostic: Box<str>,
517 },
518}
519#[derive(Debug, Clone, PartialEq, Error)]
527#[non_exhaustive]
528pub enum InputDefect {
529 #[error(transparent)]
531 Layout(LayoutDefect),
532
533 #[error("{setting} element {index} must be nonempty and contain neither a comma nor a NUL")]
535 ListElement {
536 setting: &'static str,
538 index: usize,
540 },
541 #[error("Host must be a bare hostname, IP address or NDI machine name")]
543 InvalidHostQuery,
544 #[error("PTZ preset must be within 0..=99")]
546 PtzPreset,
547 #[error("an explicit NDI library path must be absolute")]
549 RelativeLibraryPath,
550 #[error("a listener accepts one Discovery Server endpoint")]
552 MultipleDiscoveryServers,
553 #[error("the registration was issued by another advertiser")]
555 ForeignRegistration,
556 #[error("a recorder must record video, audio or metadata; an empty track selection would record all three")]
558 EmptyRecordingTracks,
559 #[error("a recorder with an exact file name cannot roll over at a format change, because the next file would have the same name; use a filename pattern with {{index}}, or leave format-change rollover unset")]
561 ExactNameFormatRollover,
562 #[error("a recorder with an exact file name cannot roll over at a size limit, because the next file would have the same name; use a filename pattern with {{index}}")]
564 ExactNameSizeRollover,
565 #[error("unmatched filename-pattern brace")]
567 FilenamePatternBrace,
568 #[error(
570 "filename-pattern indexes must be in the file name; move {{index}} out of the directory"
571 )]
572 FilenamePatternIndexInDirectory,
573 #[error("recording file path must end with a file name")]
575 RecordingPathMissingFilename,
576 #[error("file position exceeds 64-bit ticks")]
578 FilePositionOverflow,
579 #[error(
581 "a recording start cannot use Timecode::SYNTHESIZE; choose an explicit start such as zero"
582 )]
583 SynthesizeRecordingStart,
584 #[error("the session counter is exhausted")]
586 SessionCounterExhausted,
587 #[error("the recorder generation is exhausted")]
589 RecorderGenerationExhausted,
590 #[error("Allocator limits must be positive")]
592 AllocatorPositiveLimits,
593 #[error("max_allocation_bytes exceeds {MAX_ALLOCATION_BYTES} bytes")]
595 AllocatorAllocationLimit,
596 #[error("max_concurrent_calls exceeds max_allocations, which counts every call in progress")]
598 AllocatorConcurrentLimit,
599 #[error("max_bytes is less than max_concurrent_calls allocations of max_allocation_bytes")]
601 AllocatorByteLimit,
602 #[error("Compressed allocations have a byte size, not a configurable stride")]
604 CompressedAllocationStride,
605 #[error("External allocation is smaller than the request's minimum")]
607 ExternalAllocationTooSmall,
608 #[error("External allocation is larger than the request's capacity limit")]
610 ExternalAllocationTooLarge,
611 #[error("External allocation is not aligned to 64 bytes")]
613 ExternalAllocationAlignment,
614 #[error("Process allocator generation budget exhausted")]
616 AllocatorGenerationBudget,
617 #[error("Allocator token space exhausted")]
619 AllocatorTokensExhausted,
620 #[error("Allocator limits differ from the existing process allocator service")]
622 AllocatorLimitsDiffer,
623 #[error("Advanced configuration exceeds its byte limit")]
625 ConfigurationTooLarge,
626 #[error("Invalid Advanced configuration JSON")]
628 ConfigurationJson,
629 #[error("Advanced configuration must be a JSON object")]
631 ConfigurationNotObject,
632 #[error("queue requires 1..=65536 frames and a positive addressable byte limit")]
634 QueueLimits,
635 #[error("queue submission identifiers exhausted")]
637 QueueIdentifiersExhausted,
638 #[error("queued conversion requires a sender without advertiser registrations")]
640 QueuedSenderRegistered,
641 #[error("timeout {requested:?} exceeds MAX_TIMEOUT (4294967294 ms, about 49.7 days)")]
643 TimeoutTooLong {
644 requested: DiagnosticDuration,
646 },
647 #[error("timeout {requested:?} ends at an instant this platform cannot represent")]
649 TimeoutInstantOverflow {
650 requested: DiagnosticDuration,
652 },
653 #[error("receive delay {requested:?} exceeds {} ms", crate::ReceiveDelay::MAX.to_sdk())]
655 ReceiveDelayTooLong {
656 requested: DiagnosticDuration,
658 },
659 #[error("{detail}")]
661 PtzValue {
662 detail: CompactDiagnostic<PtzDefect>,
664 },
665 #[error("{member} is already registered")]
667 AlreadyRegistered {
668 member: &'static str,
670 },
671 #[error("{what} must not be empty")]
673 Empty {
674 what: &'static str,
676 },
677 #[error("{what} is not lossless UTF-8")]
679 PathNotUtf8 {
680 what: &'static str,
682 },
683 #[error("unsupported filename-pattern token {{{token}}}")]
685 FilenamePatternToken {
686 token: Box<str>,
688 },
689 #[error("async {queue} queue capacity must be between 1 and 4096, not {capacity}")]
691 FileQueueCapacity {
692 queue: &'static str,
694 capacity: usize,
696 },
697 #[error("An allocation of {bytes} bytes exceeds the capacity limit of {limit} bytes")]
699 AllocationTooLarge {
700 bytes: usize,
702 limit: usize,
704 },
705 #[error("KVM key symbol {keysym:#x} exceeds the SDK's range, 0..=0x7fffffff")]
707 KvmKeySymbol {
708 keysym: u32,
710 },
711 #[error("KVM position ({x}, {y}) is not within 0..=1 on each axis")]
713 KvmPosition {
714 x: f32,
716 y: f32,
718 },
719 #[error("KVM wheel units {units} are not finite")]
721 KvmWheel {
722 units: f32,
724 },
725 #[error("{count} KVM touch points are more than the SDK can count")]
727 KvmTouchCount {
728 count: usize,
730 },
731 #[error("frame retains {bytes} bytes of allocation capacity, exceeding the queue's {limit} byte limit")]
733 QueueFrameTooLarge {
734 bytes: usize,
736 limit: usize,
738 },
739 #[error("{codec} {setting} must be in {minimum}..={maximum}, got {value}")]
741 ImageSetting {
742 codec: ImageCodecKind,
744 setting: ImageSettingKind,
746 value: u8,
748 minimum: u8,
750 maximum: u8,
752 },
753 #[error("{codec} images are 8 bits a channel; SampleDepth::Sixteen needs ImageFormat::Png")]
755 SixteenBitNeedsPng {
756 codec: ImageCodecKind,
758 },
759 #[error(
761 "{codec} cannot carry the required color tag for {} primaries and {} transfer. Use ImageFormat::Png",
762 primaries.map_or("unspecified", ColorPrimaries::name),
763 transfer.map_or("SDR", TransferFunction::name)
764 )]
765 ColorTagNeedsPng {
766 codec: ImageCodecKind,
768 primaries: Option<ColorPrimaries>,
770 transfer: Option<TransferFunction>,
772 },
773 #[error("the expanded recording file path must be absolute. Use {{prefix}} with a RecordingTarget or supply an absolute pattern")]
775 RecordingPathNotAbsolute,
776 #[error("recording file path may reach {longest_bytes} UTF-8 bytes, exceeding the {maximum_bytes}-byte event path limit ({index_digits_reserved} digits reserved for index growth)")]
778 RecordingPathTooLong {
779 maximum_bytes: usize,
781 longest_bytes: usize,
783 index_digits_reserved: usize,
785 },
786
787 #[error("{0}")]
789 DiscoveryAddressRejected(Box<DiscoveryAddressFailure>),
790 #[error("the SDK created no {object}: no Discovery Server was named, and the configuration names none it accepts")]
793 DiscoveryConfigurationRejected {
794 object: &'static str,
796 },
797 #[cfg(feature = "advanced")]
799 #[error("SpeedHQ quality guidance does not apply to {codec:?}")]
800 SpeedHqCodec {
801 codec: crate::advanced::VideoCodec,
803 },
804}
805#[derive(Debug, Clone, PartialEq, Error, Copy, Eq, Hash)]
809#[non_exhaustive]
810pub enum SdkResultDefect {
811 #[error(
813 "native completion protocol failed; use QueuedSender::close to recover retained frames"
814 )]
815 UnknownCompletion,
816 #[error("{operation} returned a negative count: {value}")]
818 NegativeCount {
819 operation: crate::NativeFunction,
821 value: DiagnosticInteger,
823 },
824 #[error("{operation} returned a string longer than the 4 MiB one string may be")]
826 UnterminatedText {
827 operation: crate::NativeFunction,
829 },
830 #[error("SDK returned invalid receive delay: {millis} ms")]
832 InvalidReceiveDelay {
833 millis: i32,
835 },
836 #[error("the source format reports a negative {what}: {value}")]
838 NegativeFormatCount {
839 what: &'static str,
841 value: i32,
843 },
844 #[error("source format reports {count} video tracks; the SDK layout holds {capacity}")]
846 FileTrackCount {
847 count: u32,
849 capacity: usize,
851 },
852 #[error("the File library wrote past the {bytes} bytes this crate's SDK headers give {name}")]
854 FileStructureTooLarge {
855 bytes: usize,
857 name: &'static str,
859 },
860 #[error("{diagnostic}")]
862 EventTypeMismatch {
863 diagnostic: &'static str,
865 },
866 #[error("{operation} returned {value}")]
868 InvalidGuidance {
869 operation: crate::NativeFunction,
871 value: i32,
873 },
874 #[error("NDIlib_avsync_synchronize reported a format change to {sample_rate} Hz and {channels} channels")]
876 AvSyncFormatChange {
877 sample_rate: i32,
879 channels: i32,
881 },
882 #[error("{operation} returned unknown status {code}")]
884 UnknownStatus {
885 operation: crate::NativeFunction,
887 code: i32,
889 },
890 #[error("{operation} returned {kind}")]
892 UnexpectedFrameType {
893 operation: crate::NativeFunction,
895 kind: u32,
897 },
898
899 #[error("{0}")]
901 MalformedDiscoveryData(DiscoveryDefect),
902}
903
904#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
906#[non_exhaustive]
907pub enum ImageAxisKind {
908 #[error("width")]
910 Width,
911 #[error("height")]
913 Height,
914}
915
916#[derive(Debug, Clone, PartialEq, Eq, Hash)]
922pub struct CompactDiagnostic<T> {
923 #[cfg(target_pointer_width = "64")]
924 value: T,
925 #[cfg(not(target_pointer_width = "64"))]
926 value: Box<T>,
927}
928impl<T> CompactDiagnostic<T> {
929 #[must_use]
931 pub fn new(value: T) -> Self {
932 Self {
933 #[cfg(target_pointer_width = "64")]
934 value,
935 #[cfg(not(target_pointer_width = "64"))]
936 value: Box::new(value),
937 }
938 }
939 #[must_use]
941 pub fn into_inner(self) -> T {
942 #[cfg(target_pointer_width = "64")]
943 {
944 self.value
945 }
946 #[cfg(not(target_pointer_width = "64"))]
947 {
948 *self.value
949 }
950 }
951}
952impl<T> std::ops::Deref for CompactDiagnostic<T> {
953 type Target = T;
954 fn deref(&self) -> &T {
955 &self.value
956 }
957}
958impl<T: std::fmt::Display> std::fmt::Display for CompactDiagnostic<T> {
959 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
960 std::fmt::Display::fmt(&**self, f)
961 }
962}
963
964#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
966#[non_exhaustive]
967pub enum AudioCountKind {
968 #[error("channels")]
970 Channels,
971 #[error("samples")]
973 Samples,
974}
975
976#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
978#[error("Invalid frame rate {numerator}/{denominator}: both parts must be in 1..=2147483647")]
979pub struct FrameRateDefect {
980 pub numerator: i64,
982 pub denominator: i64,
984}
985
986#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
988#[error("Compressed video dimensions {width}x{height} must each be in 1..=2147483647")]
989pub struct VideoDimensionsDefect {
990 pub width: i64,
992 pub height: i64,
994}
995
996#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Error)]
998#[error("Audio data length {actual}, expected {expected} samples ({channels} channels x {samples} samples) for validated layout")]
999pub struct AudioLengthDefect {
1000 pub actual: usize,
1002 pub expected: usize,
1004 pub channels: u32,
1006 pub samples: u32,
1008}
1009
1010#[derive(Debug, Clone, Copy, PartialEq, Error)]
1012#[error("{name} must be finite and within {minimum}..={maximum}")]
1013pub struct PtzDefect {
1014 pub name: &'static str,
1016 pub minimum: f32,
1018 pub maximum: f32,
1020}
1021
1022#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1027pub struct DiagnosticSize([u32; 2]);
1028impl DiagnosticSize {
1029 #[must_use]
1031 pub const fn new(value: u64) -> Self {
1032 Self([value as u32, (value >> 32) as u32])
1033 }
1034 #[must_use]
1036 pub const fn get(self) -> u64 {
1037 (self.0[0] as u64) | ((self.0[1] as u64) << 32)
1038 }
1039}
1040impl From<u64> for DiagnosticSize {
1041 fn from(value: u64) -> Self {
1042 Self::new(value)
1043 }
1044}
1045impl std::fmt::Display for DiagnosticSize {
1046 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1047 std::fmt::Display::fmt(&self.get(), f)
1048 }
1049}
1050impl std::fmt::Debug for DiagnosticSize {
1051 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1052 std::fmt::Debug::fmt(&self.get(), f)
1053 }
1054}
1055
1056#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1061pub struct DiagnosticInteger([u32; 2]);
1062impl DiagnosticInteger {
1063 #[must_use]
1065 pub const fn new(value: i64) -> Self {
1066 let bits = value as u64;
1067 Self([bits as u32, (bits >> 32) as u32])
1068 }
1069 #[must_use]
1071 pub const fn get(self) -> i64 {
1072 ((self.0[0] as u64) | ((self.0[1] as u64) << 32)) as i64
1073 }
1074}
1075impl From<i64> for DiagnosticInteger {
1076 fn from(value: i64) -> Self {
1077 Self::new(value)
1078 }
1079}
1080impl From<i32> for DiagnosticInteger {
1081 fn from(value: i32) -> Self {
1082 Self::new(value.into())
1083 }
1084}
1085impl From<u32> for DiagnosticInteger {
1086 fn from(value: u32) -> Self {
1087 Self::new(value.into())
1088 }
1089}
1090impl std::fmt::Display for DiagnosticInteger {
1091 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1092 std::fmt::Display::fmt(&self.get(), f)
1093 }
1094}
1095impl std::fmt::Debug for DiagnosticInteger {
1096 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1097 std::fmt::Debug::fmt(&self.get(), f)
1098 }
1099}
1100
1101#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1106pub struct DiagnosticDuration {
1107 seconds: [u32; 2],
1108 nanoseconds: u32,
1109}
1110impl DiagnosticDuration {
1111 #[must_use]
1113 pub const fn new(value: Duration) -> Self {
1114 let seconds = value.as_secs();
1115 Self {
1116 seconds: [seconds as u32, (seconds >> 32) as u32],
1117 nanoseconds: value.subsec_nanos(),
1118 }
1119 }
1120 #[must_use]
1122 pub const fn get(self) -> Duration {
1123 Duration::new(
1124 (self.seconds[0] as u64) | ((self.seconds[1] as u64) << 32),
1125 self.nanoseconds,
1126 )
1127 }
1128}
1129impl From<Duration> for DiagnosticDuration {
1130 fn from(value: Duration) -> Self {
1131 Self::new(value)
1132 }
1133}
1134impl PartialEq<Duration> for DiagnosticDuration {
1135 fn eq(&self, other: &Duration) -> bool {
1136 self.get() == *other
1137 }
1138}
1139impl PartialEq<DiagnosticDuration> for Duration {
1140 fn eq(&self, other: &DiagnosticDuration) -> bool {
1141 *self == other.get()
1142 }
1143}
1144impl std::fmt::Debug for DiagnosticDuration {
1145 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1146 std::fmt::Debug::fmt(&self.get(), f)
1147 }
1148}