v4l/
buffer.rs

1use bitflags::bitflags;
2use std::fmt;
3
4use crate::timestamp::Timestamp;
5
6/// Buffer type
7///
8/// Specific types of devices require buffers of corresponding types.
9#[allow(clippy::unreadable_literal)]
10#[rustfmt::skip]
11#[repr(u32)]
12#[derive(Debug, Clone, Copy)]
13pub enum Type {
14    VideoCapture        = 1,
15    VideoOutput         = 2,
16    VideoOverlay        = 3,
17    VbiCaputre          = 4,
18    VbiOutput           = 5,
19    SlicedVbiCapture    = 6,
20    SlicedVbiOutput     = 7,
21    VideoOutputOverlay  = 8,
22    VideoCaptureMplane  = 9,
23    VideoOutputMplane   = 10,
24    SdrCapture          = 11,
25    SdrOutput           = 12,
26    MetaCapture         = 13,
27    MetaOutput          = 14,
28
29    /// Deprecated, do not use
30    Private             = 0x80,
31}
32
33bitflags! {
34    #[allow(clippy::unreadable_literal)]
35    pub struct Flags: u32 {
36        /// Buffer is mapped
37        const MAPPED                = 0x00000001;
38        /// Buffer is queued for processing
39        const QUEUED                = 0x00000002;
40        /// Buffer is ready
41        const DONE                  = 0x00000004;
42        /// Image is a keyframe (I-frame)
43        const KEYFRAME              = 0x00000008;
44        /// Image is a P-frame
45        const PFRAME                = 0x00000010;
46        /// Image is a B-frame
47        const BFRAME                = 0x00000020;
48        /// Buffer is ready, but the data contained within is corrupted
49        const ERROR                 = 0x00000040;
50        /// Buffer is added to an unqueued request
51        const IN_REQUEST            = 0x00000080;
52        /// Timecode field is valid
53        const TIMECODE              = 0x00000100;
54        /// Don't return the capture buffer until OUTPUT timestamp changes
55        const M2M_HOLD_CAPTURE_BUF  = 0x00000200;
56        /// Buffer is prepared for queuing
57        const PREPARED              = 0x00000400;
58        /// Cache handling flags
59        const NO_CACHE_INVALIDATE   = 0x00000800;
60        const NO_CACHE_CLEAN        = 0x00001000;
61        /// Timestamp type
62        const TIMESTAMP_MASK        = 0x0000e000;
63        const TIMESTAMP_UNKNOWN     = 0x00000000;
64        const TIMESTAMP_MONOTONIC   = 0x00002000;
65        const TIMESTAMP_COPY        = 0x00004000;
66        /// Timestamp sources
67        const TSTAMP_SRC_MASK       = 0x00070000;
68        const TSTAMP_SRC_EOF        = 0x00000000;
69        const TSTAMP_SRC_SOE        = 0x00010000;
70        /// mem2mem encoder/decoder
71        const LAST                  = 0x00100000;
72        /// request_fd is valid
73        const REQUEST_FD            = 0x00800000;
74    }
75}
76
77impl Default for Flags {
78    fn default() -> Self {
79        Flags::from(0)
80    }
81}
82
83impl From<u32> for Flags {
84    fn from(flags: u32) -> Self {
85        Self::from_bits_truncate(flags)
86    }
87}
88
89impl From<Flags> for u32 {
90    fn from(flags: Flags) -> Self {
91        flags.bits()
92    }
93}
94
95impl fmt::Display for Flags {
96    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
97        fmt::Debug::fmt(self, f)
98    }
99}
100
101/// Buffer metadata, mostly used not to convolute the main buffer structs
102#[derive(Copy, Clone, Default)]
103pub struct Metadata {
104    /// Number of bytes occupied by the data in the buffer
105    pub bytesused: u32,
106    /// Buffer flags
107    pub flags: Flags,
108    /// Indicates the field order of the image in the buffer.
109    pub field: u32,
110    /// Time of capture (usually set by the driver)
111    pub timestamp: Timestamp,
112    /// Sequence number, counting the frames
113    pub sequence: u32,
114}