16 #include <unordered_set> 19 #include <linux/videodev2.h> 46 return reinterpret_cast<const char *
>(v4l2_capability::driver);
50 return reinterpret_cast<const char *
>(v4l2_capability::card);
54 return reinterpret_cast<const char *
>(v4l2_capability::bus_info);
58 return capabilities & V4L2_CAP_DEVICE_CAPS
59 ? v4l2_capability::device_caps
60 : v4l2_capability::capabilities;
64 return device_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
65 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
66 V4L2_CAP_VIDEO_M2M_MPLANE);
71 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
72 V4L2_CAP_META_CAPTURE);
77 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
78 V4L2_CAP_META_OUTPUT);
83 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
84 V4L2_CAP_VIDEO_OUTPUT |
85 V4L2_CAP_VIDEO_OUTPUT_MPLANE);
90 V4L2_CAP_VIDEO_M2M_MPLANE);
95 V4L2_CAP_META_OUTPUT);
127 V4L2BufferCache(
const std::vector<std::unique_ptr<FrameBuffer>> &buffers);
130 bool isEmpty()
const;
132 void put(
unsigned int index);
139 Entry(
bool free, uint64_t lastUsed,
const FrameBuffer &buffer);
157 std::vector<Plane> planes_;
160 uint64_t lastUsedCounter_;
161 std::vector<Entry> cache_;
163 unsigned int missCounter_;
179 unsigned int planesCount = 0;
181 const std::string toString()
const;
189 using Formats = std::map<V4L2PixelFormat, std::vector<SizeRange>>;
196 int open(
SharedFD handle,
enum v4l2_buf_type type);
201 const char *
busName()
const {
return caps_.bus_info(); }
208 Formats formats(uint32_t code = 0);
210 int getSelection(
unsigned int target,
Rectangle *rect);
211 int setSelection(
unsigned int target,
Rectangle *rect);
213 int allocateBuffers(
unsigned int count,
214 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
215 int exportBuffers(
unsigned int count,
216 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
217 int importBuffers(
unsigned int count);
218 int releaseBuffers();
229 static std::unique_ptr<V4L2VideoDevice>
230 fromEntityName(
const MediaDevice *media,
const std::string &entity);
235 std::string logPrefix()
const override;
257 std::vector<V4L2PixelFormat> enumPixelformats(uint32_t code);
260 int requestBuffers(
unsigned int count,
enum v4l2_memory memoryType);
261 int createBuffers(
unsigned int count,
262 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
263 std::unique_ptr<FrameBuffer> createBuffer(
unsigned int index);
264 UniqueFD exportDmabufFd(
unsigned int index,
unsigned int plane);
266 void bufferAvailable();
269 void watchdogExpired();
272 static std::optional<ColorSpace> toColorSpace(
const T &v4l2Format);
277 std::unordered_set<V4L2PixelFormat> pixelFormats_;
279 enum v4l2_buf_type bufferType_;
280 enum v4l2_memory memoryType_;
283 std::map<unsigned int, FrameBuffer *> queuedBuffers_;
288 std::optional<unsigned int> firstFrame_;
307 std::string deviceNode_;
RAII-style wrapper for file descriptors.
Definition: shared_fd.h:16
bool isCapture() const
Identify if the video device captures data.
Definition: v4l2_videodevice.h:68
Utilities to help constructing class interfaces.
const V4L2Capability & caps() const
Retrieve the device V4L2 capabilities.
Definition: v4l2_videodevice.h:203
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:32
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:506
Class and enums to represent color spaces.
File descriptor wrapper that owns a file descriptor.
bool isMetaCapture() const
Identify if the video device captures image meta-data.
Definition: v4l2_videodevice.h:105
Top-level libcamera namespace.
Definition: backtrace.h:17
V4L2VideoDevice * capture()
Retrieve the capture V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:304
bool isOutput() const
Identify if the video device outputs data.
Definition: v4l2_videodevice.h:74
unsigned int length
The plane length in bytes.
Definition: framebuffer.h:57
Frame buffer data and its associated dynamic metadata.
Definition: framebuffer.h:48
Describe a two-dimensional size.
Definition: geometry.h:50
Miscellaneous utility functions.
const char * bus_info() const
Retrieve the location of the video device in the system.
Definition: v4l2_videodevice.h:52
bool isVideoOutput() const
Identify if the video device outputs images.
Definition: v4l2_videodevice.h:101
Signal dequeueTimeout
A Signal emitted when the dequeue watchdog timer expires.
Definition: v4l2_videodevice.h:227
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:186
std::map< V4L2PixelFormat, std::vector< SizeRange > > Formats
A map of supported V4L2 pixel formats to frame sizes.
Definition: v4l2_videodevice.h:189
const char * driverName() const
Retrieve the name of the V4L2 device driver.
Definition: v4l2_videodevice.h:199
bool hasMediaController() const
Determine if the video device uses Media Controller to configure I/O.
Definition: v4l2_videodevice.h:117
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Signal & slot implementation.
struct v4l2_capability object wrapper and helpers
Definition: v4l2_videodevice.h:43
Describe a rectangle's position and dimensions.
Definition: geometry.h:240
V4L2VideoDevice * output()
Retrieve the output V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:303
Single-shot timer interface.
Definition: timer.h:21
bool isM2M() const
Identify if the device is a Memory-to-Memory device.
Definition: v4l2_videodevice.h:87
unique_ptr-like wrapper for a file descriptor
Definition: unique_fd.h:16
Common base for V4L2 devices and subdevices.
bool isVideoCapture() const
Identify if the video device captures images.
Definition: v4l2_videodevice.h:97
SharedFD fd
The dmabuf file descriptor.
Definition: framebuffer.h:55
bool isMeta() const
Identify if the video device captures or outputs image meta-data.
Definition: v4l2_videodevice.h:92
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition: geometry.cpp:91
bool isMultiplanar() const
Identify if the video device implements the V4L2 multiplanar APIs.
Definition: v4l2_videodevice.h:62
Helper class from std::chrono::duration that represents a time duration in nanoseconds with double pr...
Definition: utils.h:370
int get() const
Retrieve the numerical file descriptor.
Definition: shared_fd.h:30
Generic signal and slot communication mechanism.
Definition: object.h:22
A memory region to store a single plane of a frame.
Definition: framebuffer.h:53
bool isVideo() const
Identify if the video device captures or outputs images.
Definition: v4l2_videodevice.h:80
Notify of activity on a file descriptor.
Definition: event_notifier.h:19
Signal< FrameBuffer * > bufferReady
A Signal emitted when a framebuffer completes.
Definition: v4l2_videodevice.h:221
bool hasStreaming() const
Determine if the video device can perform Streaming I/O.
Definition: v4l2_videodevice.h:113
const char * deviceName() const
Retrieve the name of the V4L2 video device.
Definition: v4l2_videodevice.h:200
Data structures related to geometric objects.
unsigned int device_caps() const
Retrieve the capabilities of the video device.
Definition: v4l2_videodevice.h:56
const char * card() const
Retrieve the video device card name.
Definition: v4l2_videodevice.h:48
Hot cache of associations between V4L2 buffer indexes and FrameBuffer.
Definition: v4l2_videodevice.h:123
const char * driver() const
Retrieve the driver module name.
Definition: v4l2_videodevice.h:44
Memory-to-Memory video device.
Definition: v4l2_videodevice.h:294
const char * busName() const
Retrieve the location of the device in the system.
Definition: v4l2_videodevice.h:201
bool isMetaOutput() const
Identify if the video device outputs image meta-data.
Definition: v4l2_videodevice.h:109