v4l/io/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*! V4l2-specific errors */

use std::io;
use thiserror;

/// Contains errors returned by the STREAMON call. The error is not created to make handling easier, but instead to describe the problem to the user in an informative way.
#[derive(thiserror::Error, Debug)]
pub enum StartError {
    /// The buffer type is not supported, or no buffers have been allocated (memory mapping) or enqueued (output) yet.
    #[error("Bad buffer configuration")]
    Buffer,
    /// The driver implements pad-level format configuration and the pipeline configuration is invalid.
    #[error("Bad pipeline configuration")]
    Pipeline,
    /// The driver implements Media Controller interface and the pipeline link configuration is invalid.
    #[error("Bad link configuration")]
    Link,
    /// Any other error
    #[error("Generic error - see kernel media docs")]
    Generic(io::Error),
}

impl From<io::Error> for StartError {
    fn from(value: io::Error) -> Self {
        match value.kind() {
            io::ErrorKind::BrokenPipe => Self::Pipeline,
            io::ErrorKind::InvalidInput => Self::Buffer,
            _ => Self::Generic(value),
        }
    }
}

/// Covers all the possible reasons for things not working.
/// This should be coupled with a traceback, in order to find out which call was actually responsible.
#[derive(thiserror::Error, Debug)]
pub enum Error {
    /// The buffer type is not supported, or no buffers have been allocated (memory mapping) or enqueued (output) yet.
    #[error("Bad buffer configuration")]
    Buffer,
    /// The driver implements pad-level format configuration and the pipeline configuration is invalid.
    #[error("Bad pipeline configuration")]
    Pipeline,
    /// The driver implements Media Controller interface and the pipeline link configuration is invalid.
    #[error("Bad link configuration")]
    Link,
    /// Any other error
    #[error("Generic error - see kernel media docs")]
    Generic(io::Error),
    /// An error that 
    #[error("Error without interpretation - check trace")]
    Io(io::Error),
}

impl From<StartError> for Error {
    fn from(value: StartError) -> Self {
        match value {
            StartError::Buffer => Self::Buffer,
            StartError::Pipeline => Self::Pipeline,
            StartError::Link => Self::Link,
            StartError::Generic(e) => Self::Generic(e),
        }
    }
}

impl From<io::Error> for Error {
    fn from(value: io::Error) -> Self {
        Self::Io(value)
    }
}