17#include <unordered_set>
20#include <linux/videodev2.h>
47 return reinterpret_cast<const char *
>(v4l2_capability::driver);
51 return reinterpret_cast<const char *
>(v4l2_capability::card);
55 return reinterpret_cast<const char *
>(v4l2_capability::bus_info);
59 return capabilities & V4L2_CAP_DEVICE_CAPS
60 ? v4l2_capability::device_caps
61 : v4l2_capability::capabilities;
65 return device_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
66 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
67 V4L2_CAP_VIDEO_M2M_MPLANE);
72 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
73 V4L2_CAP_META_CAPTURE);
78 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
79 V4L2_CAP_META_OUTPUT);
84 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
85 V4L2_CAP_VIDEO_OUTPUT |
86 V4L2_CAP_VIDEO_OUTPUT_MPLANE);
91 V4L2_CAP_VIDEO_M2M_MPLANE);
96 V4L2_CAP_META_OUTPUT);
128 V4L2BufferCache(
const std::vector<std::unique_ptr<FrameBuffer>> &buffers);
133 void put(
unsigned int index);
140 Entry(
bool free, uint64_t lastUsed,
const FrameBuffer &buffer);
158 std::vector<Plane> planes_;
161 std::atomic<uint64_t> lastUsedCounter_;
162 std::vector<Entry> cache_;
164 unsigned int missCounter_;
190 using Formats = std::map<V4L2PixelFormat, std::vector<SizeRange>>;
209 Formats formats(uint32_t code = 0);
214 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
216 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
229 static std::unique_ptr<V4L2VideoDevice>
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_;
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Definition class.h:27
Notify of activity on a file descriptor.
Definition event_notifier.h:20
Frame buffer data and its associated dynamic metadata.
Definition framebuffer.h:49
Describe a rectangle's position and dimensions.
Definition geometry.h:243
RAII-style wrapper for file descriptors.
Definition shared_fd.h:17
int get() const
Retrieve the numerical file descriptor.
Definition shared_fd.h:30
Generic signal and slot communication mechanism.
Definition signal.h:39
Describe a two-dimensional size.
Definition geometry.h:53
Single-shot timer interface.
Definition timer.h:22
unique_ptr-like wrapper for a file descriptor
Definition unique_fd.h:18
Hot cache of associations between V4L2 buffer indexes and FrameBuffer.
Definition v4l2_videodevice.h:125
V4L2BufferCache(unsigned int numEntries)
Create an empty cache with numEntries entries.
Definition v4l2_videodevice.cpp:174
int get(const FrameBuffer &buffer)
Find the best V4L2 buffer for a FrameBuffer.
Definition v4l2_videodevice.cpp:229
bool isEmpty() const
Check if all the entries in the cache are unused.
Definition v4l2_videodevice.cpp:206
void put(unsigned int index)
Mark buffer index as free in the cache.
Definition v4l2_videodevice.cpp:271
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition v4l2_device.h:32
const std::string & deviceNode() const
Retrieve the device node path.
Definition v4l2_device.h:44
Memory-to-Memory video device.
Definition v4l2_videodevice.h:295
void close()
Close the memory-to-memory device, releasing any resources acquired by open()
Definition v4l2_videodevice.cpp:2180
V4L2VideoDevice * output()
Retrieve the output V4L2VideoDevice instance.
Definition v4l2_videodevice.h:303
V4L2VideoDevice * capture()
Retrieve the capture V4L2VideoDevice instance.
Definition v4l2_videodevice.h:304
int open()
Open a V4L2 Memory to Memory device.
Definition v4l2_videodevice.cpp:2143
V4L2M2MDevice(const std::string &deviceNode)
Create a new V4L2M2MDevice from the deviceNode.
Definition v4l2_videodevice.cpp:2122
V4L2VideoDevice object and API.
Definition v4l2_videodevice.h:188
int importBuffers(unsigned int count)
Prepare the device to import count buffers.
Definition v4l2_videodevice.cpp:1531
int releaseBuffers()
Release resources allocated by allocateBuffers() or importBuffers()
Definition v4l2_videodevice.cpp:1559
int tryFormat(V4L2DeviceFormat *format)
Try an image format on the V4L2 video device.
Definition v4l2_videodevice.cpp:830
int allocateBuffers(unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)
Allocate and export buffers from the video device.
Definition v4l2_videodevice.cpp:1312
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition v4l2_videodevice.cpp:792
std::map< V4L2PixelFormat, std::vector< SizeRange > > Formats
A map of supported V4L2 pixel formats to frame sizes.
Definition v4l2_videodevice.h:190
void setDequeueTimeout(utils::Duration timeout)
Set the dequeue timeout value.
Definition v4l2_videodevice.cpp:2010
int open()
Open the V4L2 video device node and query its capabilities.
Definition v4l2_videodevice.cpp:569
Signal< FrameBuffer * > bufferReady
A Signal emitted when a framebuffer completes.
Definition v4l2_videodevice.h:221
const char * busName() const
Retrieve the location of the device in the system.
Definition v4l2_videodevice.h:202
int streamOn()
Start the video stream.
Definition v4l2_videodevice.cpp:1923
int queueBuffer(FrameBuffer *buffer)
Queue a buffer to the video device.
Definition v4l2_videodevice.cpp:1589
V4L2VideoDevice(const std::string &deviceNode)
Construct a V4L2VideoDevice.
Definition v4l2_videodevice.cpp:534
int streamOff()
Stop the video stream.
Definition v4l2_videodevice.cpp:1956
int getFormat(V4L2DeviceFormat *format)
Retrieve the image format set on the V4L2 video device.
Definition v4l2_videodevice.cpp:803
int exportBuffers(unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)
Export buffers from the video device.
Definition v4l2_videodevice.cpp:1361
Signal dequeueTimeout
A Signal emitted when the dequeue watchdog timer expires.
Definition v4l2_videodevice.h:227
const char * driverName() const
Retrieve the name of the V4L2 device driver.
Definition v4l2_videodevice.h:200
void close()
Close the video device, releasing any resources acquired by open()
Definition v4l2_videodevice.cpp:755
const V4L2Capability & caps() const
Retrieve the device V4L2 capabilities.
Definition v4l2_videodevice.h:204
static std::unique_ptr< V4L2VideoDevice > fromEntityName(const MediaDevice *media, const std::string &entity)
Create a new video device instance from entity in media device media.
Definition v4l2_videodevice.cpp:2047
int setSelection(unsigned int target, Rectangle *rect)
Set a selection rectangle rect for target.
Definition v4l2_videodevice.cpp:1226
V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat) const
Convert PixelFormat to a V4L2PixelFormat supported by the device.
Definition v4l2_videodevice.cpp:2078
int setFormat(V4L2DeviceFormat *format)
Configure an image format on the V4L2 video device.
Definition v4l2_videodevice.cpp:856
const char * deviceName() const
Retrieve the name of the V4L2 video device.
Definition v4l2_videodevice.h:201
Helper class from std::chrono::duration that represents a time duration in nanoseconds with double pr...
Definition utils.h:354
Class and enums to represent color spaces.
Data structures related to geometric objects.
Top-level libcamera namespace.
Definition backtrace.h:17
std::ostream & operator<<(std::ostream &out, const Point &p)
Insert a text representation of a Point into an output stream.
Definition geometry.cpp:91
Signal & slot implementation.
A memory region to store a single plane of a frame.
Definition framebuffer.h:53
SharedFD fd
The dmabuf file descriptor.
Definition framebuffer.h:55
unsigned int length
The plane length in bytes.
Definition framebuffer.h:57
struct v4l2_capability object wrapper and helpers
Definition v4l2_videodevice.h:44
bool hasStreaming() const
Determine if the video device can perform Streaming I/O.
Definition v4l2_videodevice.h:114
const char * bus_info() const
Retrieve the location of the video device in the system.
Definition v4l2_videodevice.h:53
bool isVideoCapture() const
Identify if the video device captures images.
Definition v4l2_videodevice.h:98
bool isMultiplanar() const
Identify if the video device implements the V4L2 multiplanar APIs.
Definition v4l2_videodevice.h:63
bool isOutput() const
Identify if the video device outputs data.
Definition v4l2_videodevice.h:75
bool isMetaOutput() const
Identify if the video device outputs image meta-data.
Definition v4l2_videodevice.h:110
bool isMeta() const
Identify if the video device captures or outputs image meta-data.
Definition v4l2_videodevice.h:93
bool isMetaCapture() const
Identify if the video device captures image meta-data.
Definition v4l2_videodevice.h:106
bool hasMediaController() const
Determine if the video device uses Media Controller to configure I/O.
Definition v4l2_videodevice.h:118
const char * driver() const
Retrieve the driver module name.
Definition v4l2_videodevice.h:45
bool isM2M() const
Identify if the device is a Memory-to-Memory device.
Definition v4l2_videodevice.h:88
bool isVideoOutput() const
Identify if the video device outputs images.
Definition v4l2_videodevice.h:102
bool isVideo() const
Identify if the video device captures or outputs images.
Definition v4l2_videodevice.h:81
bool isCapture() const
Identify if the video device captures data.
Definition v4l2_videodevice.h:69
unsigned int device_caps() const
Retrieve the capabilities of the video device.
Definition v4l2_videodevice.h:57
const char * card() const
Retrieve the video device card name.
Definition v4l2_videodevice.h:49
File descriptor wrapper that owns a file descriptor.
Miscellaneous utility functions.
Common base for V4L2 devices and subdevices.