7#ifndef __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__
8#define __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__
17#include <linux/videodev2.h>
41 return reinterpret_cast<const char *
>(v4l2_capability::driver);
45 return reinterpret_cast<const char *
>(v4l2_capability::card);
49 return reinterpret_cast<const char *
>(v4l2_capability::bus_info);
53 return capabilities & V4L2_CAP_DEVICE_CAPS
54 ? v4l2_capability::device_caps
55 : v4l2_capability::capabilities;
59 return device_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
60 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
61 V4L2_CAP_VIDEO_M2M_MPLANE);
66 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
67 V4L2_CAP_META_CAPTURE);
72 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
73 V4L2_CAP_META_OUTPUT);
78 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
79 V4L2_CAP_VIDEO_OUTPUT |
80 V4L2_CAP_VIDEO_OUTPUT_MPLANE);
85 V4L2_CAP_VIDEO_M2M_MPLANE);
90 V4L2_CAP_META_OUTPUT);
118 V4L2BufferCache(
const std::vector<std::unique_ptr<FrameBuffer>> &buffers);
122 void put(
unsigned int index);
129 Entry(
bool free, uint64_t lastUsed,
const FrameBuffer &buffer);
147 std::vector<Plane> planes_;
150 std::atomic<uint64_t> lastUsedCounter_;
151 std::vector<Entry> cache_;
153 unsigned int missCounter_;
176 using Formats = std::map<V4L2PixelFormat, std::vector<SizeRange>>;
183 int open(
int handle,
enum v4l2_buf_type type);
200 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
202 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
212 static std::unique_ptr<V4L2VideoDevice>
230 std::vector<V4L2PixelFormat> enumPixelformats(uint32_t code);
233 int requestBuffers(
unsigned int count,
enum v4l2_memory memoryType);
234 int createBuffers(
unsigned int count,
235 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
236 std::unique_ptr<FrameBuffer> createBuffer(
unsigned int index);
237 FileDescriptor exportDmabufFd(
unsigned int index,
unsigned int plane);
239 void bufferAvailable();
246 enum v4l2_buf_type bufferType_;
247 enum v4l2_memory memoryType_;
250 std::map<unsigned int, FrameBuffer *> queuedBuffers_;
270 std::string deviceNode_;
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY(klass)
Disable copy construction and assignment of the klass.
Notify of activity on a file descriptor.
Definition: event_notifier.h:20
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:16
int fd() const
Retrieve the numerical file descriptor.
Definition: file_descriptor.h:28
Frame buffer data and its associated dynamic metadata.
Definition: framebuffer.h:49
Describe a rectangle's position and dimensions.
Definition: geometry.h:207
Generic signal and slot communication mechanism.
Definition: signal.h:39
Describe a two-dimensional size.
Definition: geometry.h:51
Hot cache of associations between V4L2 buffer indexes and FrameBuffer.
Definition: v4l2_videodevice.h:115
V4L2BufferCache(unsigned int numEntries)
Create an empty cache with numEntries entries.
Definition: v4l2_videodevice.cpp:169
int get(const FrameBuffer &buffer)
Find the best V4L2 buffer for a FrameBuffer.
Definition: v4l2_videodevice.cpp:211
void put(unsigned int index)
Mark buffer index as free in the cache.
Definition: v4l2_videodevice.cpp:253
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:27
const std::string & deviceNode() const
Retrieve the device node path.
Definition: v4l2_device.h:39
Memory-to-Memory video device.
Definition: v4l2_videodevice.h:258
V4L2VideoDevice * capture()
Retrieve the capture V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:267
void close()
Close the memory-to-memory device, releasing any resources acquired by open()
Definition: v4l2_videodevice.cpp:1926
int open()
Open a V4L2 Memory to Memory device.
Definition: v4l2_videodevice.cpp:1883
V4L2VideoDevice * output()
Retrieve the output V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:266
V4L2M2MDevice(const std::string &deviceNode)
Create a new V4L2M2MDevice from the deviceNode.
Definition: v4l2_videodevice.cpp:1862
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:174
std::map< V4L2PixelFormat, std::vector< SizeRange > > Formats
A map of supported V4L2 pixel formats to frame sizes.
Definition: v4l2_videodevice.h:176
const char * driverName() const
Retrieve the name of the V4L2 device driver.
Definition: v4l2_videodevice.h:186
int importBuffers(unsigned int count)
Prepare the device to import count buffers.
Definition: v4l2_videodevice.cpp:1423
int releaseBuffers()
Release resources allocated by allocateBuffers() or importBuffers()
Definition: v4l2_videodevice.cpp:1451
int tryFormat(V4L2DeviceFormat *format)
Try an image format on the V4L2 video device.
Definition: v4l2_videodevice.cpp:765
const char * deviceName() const
Retrieve the name of the V4L2 video device.
Definition: v4l2_videodevice.h:187
int allocateBuffers(unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)
Allocate and export buffers from the video device.
Definition: v4l2_videodevice.cpp:1204
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: v4l2_videodevice.cpp:734
int open()
Open the V4L2 video device node and query its capabilities.
Definition: v4l2_videodevice.cpp:520
int streamOn()
Start the video stream.
Definition: v4l2_videodevice.cpp:1754
int queueBuffer(FrameBuffer *buffer)
Queue a buffer to the video device.
Definition: v4l2_videodevice.cpp:1475
V4L2VideoDevice(const std::string &deviceNode)
Construct a V4L2VideoDevice.
Definition: v4l2_videodevice.cpp:487
int streamOff()
Stop the video stream.
Definition: v4l2_videodevice.cpp:1783
int getFormat(V4L2DeviceFormat *format)
Retrieve the image format set on the V4L2 video device.
Definition: v4l2_videodevice.cpp:745
int exportBuffers(unsigned int count, std::vector< std::unique_ptr< FrameBuffer > > *buffers)
Export buffers from the video device.
Definition: v4l2_videodevice.cpp:1253
void close()
Close the video device, releasing any resources acquired by open()
Definition: v4l2_videodevice.cpp:697
const char * busName() const
Retrieve the location of the device in the system.
Definition: v4l2_videodevice.h:188
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:1821
int setSelection(unsigned int target, Rectangle *rect)
Set a selection rectangle rect for target.
Definition: v4l2_videodevice.cpp:1118
const V4L2Capability & caps() const
Retrieve the device V4L2 capabilities.
Definition: v4l2_videodevice.h:190
Signal< FrameBuffer * > bufferReady
A Signal emitted when a framebuffer completes.
Definition: v4l2_videodevice.h:207
int setFormat(V4L2DeviceFormat *format)
Configure an image format on the V4L2 video device.
Definition: v4l2_videodevice.cpp:784
Formats formats(uint32_t code=0)
Enumerate all pixel formats and frame sizes.
Definition: v4l2_videodevice.cpp:995
Data structures related to geometric objects.
Top-level libcamera namespace.
Definition: bound_method.h:15
bool operator==(const Point &lhs, const Point &rhs)
Compare points for equality.
Definition: geometry.cpp:75
Signal & slot implementation.
A memory region to store a single plane of a frame.
Definition: framebuffer.h:53
unsigned int length
The plane length in bytes.
Definition: framebuffer.h:57
FileDescriptor fd
The dmabuf file descriptor.
Definition: framebuffer.h:55
struct v4l2_capability object wrapper and helpers
Definition: v4l2_videodevice.h:38
bool hasStreaming() const
Determine if the video device can perform Streaming I/O.
Definition: v4l2_videodevice.h:108
unsigned int device_caps() const
Retrieve the capabilities of the video device.
Definition: v4l2_videodevice.h:51
bool isVideoOutput() const
Identify if the video device outputs images.
Definition: v4l2_videodevice.h:96
bool isM2M() const
Identify if the device is a Memory-to-Memory device.
Definition: v4l2_videodevice.h:82
bool isMetaCapture() const
Identify if the video device captures image meta-data.
Definition: v4l2_videodevice.h:100
bool isOutput() const
Identify if the video device outputs data.
Definition: v4l2_videodevice.h:69
bool isVideoCapture() const
Identify if the video device captures images.
Definition: v4l2_videodevice.h:92
bool isMultiplanar() const
Identify if the video device implements the V4L2 multiplanar APIs.
Definition: v4l2_videodevice.h:57
bool isMeta() const
Identify if the video device captures or outputs image meta-data.
Definition: v4l2_videodevice.h:87
bool isCapture() const
Identify if the video device captures data.
Definition: v4l2_videodevice.h:63
bool isMetaOutput() const
Identify if the video device outputs image meta-data.
Definition: v4l2_videodevice.h:104
const char * bus_info() const
Retrieve the location of the video device in the system.
Definition: v4l2_videodevice.h:47
const char * card() const
Retrieve the video device card name.
Definition: v4l2_videodevice.h:43
bool isVideo() const
Identify if the video device captures or outputs images.
Definition: v4l2_videodevice.h:75
const char * driver() const
Retrieve the driver module name.
Definition: v4l2_videodevice.h:39
Common base for V4L2 devices and subdevices.