Skip to main content

video_interop/
error.rs

1use std::io;
2
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6#[non_exhaustive]
7pub enum DmaBufAllocationSizeError {
8    #[error("failed to stat DMA-BUF fd: {0}")]
9    Stat(#[source] io::Error),
10    #[error("failed to query DMA-BUF allocation size: {0}")]
11    Seek(#[source] io::Error),
12    #[error("failed to restore DMA-BUF file position: {0}")]
13    Restore(#[source] io::Error),
14    #[error("DMA-BUF allocation size is zero")]
15    Zero,
16    #[error("DMA-BUF stat size is negative: {0}")]
17    NegativeStat(i64),
18    #[error("DMA-BUF size probes disagree: fstat={stat}, seek_end={seek_end}")]
19    ProbeMismatch { stat: u64, seek_end: u64 },
20}
21
22#[derive(Debug, Error, PartialEq, Eq)]
23pub enum ValidationError {
24    #[error("coded frame size must be positive, got {width}x{height}")]
25    ZeroCodedSize { width: u32, height: u32 },
26    #[error("visible frame size must be positive, got {width}x{height}")]
27    ZeroVisibleSize { width: u32, height: u32 },
28    #[error("visible rectangle arithmetic overflowed")]
29    VisibleRectOverflow,
30    #[error(
31        "visible rectangle ({x}, {y}, {width}, {height}) exceeds coded size {coded_width}x{coded_height}"
32    )]
33    VisibleRectOutOfBounds {
34        x: u32,
35        y: u32,
36        width: u32,
37        height: u32,
38        coded_width: u32,
39        coded_height: u32,
40    },
41    #[error("unsupported descriptor version {0}")]
42    UnsupportedDescriptorVersion(u32),
43    #[error("descriptor has no objects")]
44    EmptyObjects,
45    #[error("descriptor has no layers")]
46    EmptyLayers,
47    #[error("descriptor has {actual} {kind}; maximum is {maximum}")]
48    TooManyEntries {
49        kind: &'static str,
50        actual: usize,
51        maximum: usize,
52    },
53    #[error("object {index} has negative fd {fd}")]
54    NegativeFd { index: usize, fd: i32 },
55    #[error("acquire fence has negative fd {0}")]
56    NegativeAcquireFence(i32),
57    #[error("binary storage has no planes")]
58    EmptyBinaryPlanes,
59    #[error("binary storage has {0} planes; only one plane is supported")]
60    UnsupportedBinaryPlaneCount(usize),
61    #[error("binary storage plane has zero stride")]
62    ZeroBinaryStride,
63    #[error("binary storage plane offset {offset} is outside {data_size} bytes")]
64    BinaryOffsetOutOfBounds { offset: u64, data_size: u64 },
65    #[error("binary storage last row starts at {offset}, outside {data_size} bytes")]
66    BinaryLastRowOutOfBounds { offset: u64, data_size: u64 },
67    #[error("binary storage requires implicit synchronization")]
68    BinaryStorageRequiresImplicitSync,
69    #[error("object {index} is not referenced by any descriptor plane")]
70    UnreferencedObject { index: usize },
71    #[error("object {index} has zero size")]
72    ZeroObjectSize { index: usize },
73    #[error("layer {index} has invalid DRM fourcc 0")]
74    InvalidFourcc { index: usize },
75    #[error("layer {index} has no planes")]
76    EmptyPlanes { index: usize },
77    #[error("descriptor has {actual} total planes; maximum is {maximum}")]
78    TooManyPlanes { actual: usize, maximum: usize },
79    #[error("layer {layer} plane {plane} has zero pitch")]
80    ZeroPitch { layer: usize, plane: usize },
81    #[error(
82        "layer {layer} plane {plane} references object {object_index}, but only {object_count} objects exist"
83    )]
84    InvalidObjectIndex {
85        layer: usize,
86        plane: usize,
87        object_index: u32,
88        object_count: usize,
89    },
90    #[error(
91        "layer {layer} plane {plane} offset {offset} is outside object {object_index} of size {object_size}"
92    )]
93    PlaneOffsetOutOfBounds {
94        layer: usize,
95        plane: usize,
96        object_index: u32,
97        offset: u64,
98        object_size: u64,
99    },
100}
101
102#[derive(Debug, Error)]
103pub enum DuplicateError {
104    #[error(transparent)]
105    InvalidFrame(#[from] ValidationError),
106    #[error("acquire fence has negative fd {0}")]
107    NegativeAcquireFence(i32),
108    #[error("failed to duplicate object {index} fd {fd}: {source}")]
109    DuplicateObjectFd {
110        index: usize,
111        fd: i32,
112        #[source]
113        source: io::Error,
114    },
115    #[error("failed to duplicate acquire-fence fd {fd}: {source}")]
116    DuplicateAcquireFence {
117        fd: i32,
118        #[source]
119        source: io::Error,
120    },
121}
122
123#[cfg(feature = "rustler")]
124#[derive(Clone, Debug, Error, PartialEq, Eq)]
125#[error("video-interop release dispatcher unavailable: {message}")]
126pub struct DispatcherError {
127    pub(crate) message: String,
128}
129
130#[cfg(feature = "rustler")]
131impl DispatcherError {
132    pub(crate) fn new(message: impl Into<String>) -> Self {
133        Self {
134            message: message.into(),
135        }
136    }
137}
138
139#[cfg(feature = "rustler")]
140pub type ReleaseWorkerError = DispatcherError;
141
142#[cfg(feature = "rustler")]
143#[derive(Debug, Error)]
144pub enum PrepareError {
145    #[error("borrowed video frame storage requires a lease")]
146    MissingLease,
147    #[error("owned binary video frame storage must not carry a lease")]
148    UnexpectedLease,
149    #[error(transparent)]
150    Duplicate(#[from] DuplicateError),
151    #[error(transparent)]
152    Dispatcher(#[from] DispatcherError),
153}