7 #ifndef __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__
8 #define __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__
16 #include <linux/videodev2.h>
38 return reinterpret_cast<const char *
>(v4l2_capability::driver);
42 return reinterpret_cast<const char *
>(v4l2_capability::card);
46 return reinterpret_cast<const char *
>(v4l2_capability::bus_info);
50 return capabilities & V4L2_CAP_DEVICE_CAPS
51 ? v4l2_capability::device_caps
52 : v4l2_capability::capabilities;
56 return device_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
57 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
58 V4L2_CAP_VIDEO_M2M_MPLANE);
63 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
64 V4L2_CAP_META_CAPTURE);
69 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
70 V4L2_CAP_META_OUTPUT);
75 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
76 V4L2_CAP_VIDEO_OUTPUT |
77 V4L2_CAP_VIDEO_OUTPUT_MPLANE);
82 V4L2_CAP_VIDEO_M2M_MPLANE);
87 V4L2_CAP_META_OUTPUT);
115 V4L2BufferCache(
const std::vector<std::unique_ptr<FrameBuffer>> &buffers);
119 void put(
unsigned int index);
126 Entry(
bool free, uint64_t lastUsed,
const FrameBuffer &buffer);
144 std::vector<Plane> planes_;
147 std::atomic<uint64_t> lastUsedCounter_;
148 std::vector<Entry> cache_;
150 unsigned int missCounter_;
179 int open(
int handle,
enum v4l2_buf_type type);
190 std::map<V4L2PixelFormat, std::vector<SizeRange>>
formats(uint32_t code = 0);
195 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
197 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
211 const std::string &entity);
228 std::vector<V4L2PixelFormat> enumPixelformats(uint32_t code);
231 int requestBuffers(
unsigned int count,
enum v4l2_memory memoryType);
232 int createBuffers(
unsigned int count,
233 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
234 std::unique_ptr<FrameBuffer> createBuffer(
unsigned int index);
235 FileDescriptor exportDmabufFd(
unsigned int index,
unsigned int plane);
244 enum v4l2_buf_type bufferType_;
245 enum v4l2_memory memoryType_;
248 std::map<unsigned int, FrameBuffer *> queuedBuffers_;
253 bool frameStartEnabled_;
269 std::string deviceNode_;
Notify of activity on a file descriptor.
Definition: event_notifier.h:18
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:15
int fd() const
Retrieve the numerical file descriptor.
Definition: file_descriptor.h:27
Frame buffer data and its associated dynamic metadata.
Definition: buffer.h:37
Generic signal and slot communication mechanism.
Definition: signal.h:39
Hot cache of associations between V4L2 buffer indexes and FrameBuffer.
Definition: v4l2_videodevice.h:112
V4L2BufferCache(unsigned int numEntries)
Create an empty cache with numEntries entries.
Definition: v4l2_videodevice.cpp:164
int get(const FrameBuffer &buffer)
Find the best V4L2 buffer for a FrameBuffer.
Definition: v4l2_videodevice.cpp:206
void put(unsigned int index)
Mark buffer index as free in the cache.
Definition: v4l2_videodevice.cpp:248
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:22
const std::string & deviceNode() const
Retrieve the device node path.
Definition: v4l2_device.h:32
Memory-to-Memory video device.
Definition: v4l2_videodevice.h:257
V4L2VideoDevice * capture()
Retrieve the capture V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:266
void close()
Close the memory-to-memory device, releasing any resources acquired by open()
Definition: v4l2_videodevice.cpp:1758
int open()
Open a V4L2 Memory to Memory device.
Definition: v4l2_videodevice.cpp:1715
V4L2VideoDevice * output()
Retrieve the output V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:265
V4L2M2MDevice(const std::string &deviceNode)
Create a new V4L2M2MDevice from the deviceNode.
Definition: v4l2_videodevice.cpp:1694
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:169
std::map< V4L2PixelFormat, std::vector< SizeRange > > formats(uint32_t code=0)
Enumerate all pixel formats and frame sizes.
Definition: v4l2_videodevice.cpp:928
const char * driverName() const
Retrieve the name of the V4L2 device driver.
Definition: v4l2_videodevice.h:182
V4L2PixelFormat toV4L2PixelFormat(const PixelFormat &pixelFormat)
Convert PixelFormat to its corresponding V4L2 FourCC.
Definition: v4l2_videodevice.cpp:1657
int importBuffers(unsigned int count)
Prepare the device to import count buffers.
Definition: v4l2_videodevice.cpp:1302
int releaseBuffers()
Release resources allocated by allocateBuffers() or importBuffers()
Definition: v4l2_videodevice.cpp:1330
const char * deviceName() const
Retrieve the name of the V4L2 video device.
Definition: v4l2_videodevice.h:183
std::string logPrefix() const override
Retrieve a string to be prefixed to the log message.
Definition: v4l2_videodevice.cpp:706
int allocateBuffers(unsigned int count, std::vector< std::unique_ptr< FrameBuffer >> *buffers)
Allocate and export buffers from the video device.
Definition: v4l2_videodevice.cpp:1132
int open()
Open the V4L2 video device node and query its capabilities.
Definition: v4l2_videodevice.cpp:501
int streamOn()
Start the video stream.
Definition: v4l2_videodevice.cpp:1576
int queueBuffer(FrameBuffer *buffer)
Queue a buffer to the video device.
Definition: v4l2_videodevice.cpp:1354
Signal< uint32_t > frameStart
A Signal emitted when capture of a frame has started.
Definition: v4l2_videodevice.h:205
V4L2VideoDevice(const std::string &deviceNode)
Construct a V4L2VideoDevice.
Definition: v4l2_videodevice.cpp:468
int streamOff()
Stop the video stream.
Definition: v4l2_videodevice.cpp:1600
int setFrameStartEnabled(bool enable)
Enable or disable frame start event notification.
Definition: v4l2_videodevice.cpp:1547
int getFormat(V4L2DeviceFormat *format)
Retrieve the image format set on the V4L2 video device.
Definition: v4l2_videodevice.cpp:716
void close()
Close the video device, releasing any resources acquired by open()
Definition: v4l2_videodevice.cpp:670
const char * busName() const
Retrieve the location of the device in the system.
Definition: v4l2_videodevice.h:184
int setSelection(unsigned int target, Rectangle *rect)
Set a selection rectangle rect for target.
Definition: v4l2_videodevice.cpp:1051
const V4L2Capability & caps() const
Retrieve the device V4L2 capabilities.
Definition: v4l2_videodevice.h:186
Signal< FrameBuffer * > bufferReady
A Signal emitted when a framebuffer completes.
Definition: v4l2_videodevice.h:202
static 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:1636
int setFormat(V4L2DeviceFormat *format)
Configure an image format on the V4L2 video device.
Definition: v4l2_videodevice.cpp:735
int exportBuffers(unsigned int count, std::vector< std::unique_ptr< FrameBuffer >> *buffers)
Export buffers from the video device.
Definition: v4l2_videodevice.cpp:1176
Data structures related to geometric objects.
bool operator==(const Rectangle &lhs, const Rectangle &rhs)
Compare rectangles for equality.
Definition: geometry.cpp:69
Signal & slot implementation.
A memory region to store a single plane of a frame.
Definition: buffer.h:39
unsigned int length
The plane length in bytes.
Definition: buffer.h:41
FileDescriptor fd
The dmabuf file descriptor.
Definition: buffer.h:40
Describe a rectangle's position and dimensions.
Definition: geometry.h:15
Describe a two-dimensional size.
Definition: geometry.h:30
struct v4l2_capability object wrapper and helpers
Definition: v4l2_videodevice.h:35
bool hasStreaming() const
Determine if the video device can perform Streaming I/O.
Definition: v4l2_videodevice.h:105
unsigned int device_caps() const
Retrieve the capabilities of the video device.
Definition: v4l2_videodevice.h:48
bool isVideoOutput() const
Identify if the video device outputs images.
Definition: v4l2_videodevice.h:93
bool isM2M() const
Identify if the device is a Memory-to-Memory device.
Definition: v4l2_videodevice.h:79
bool isMetaCapture() const
Identify if the video device captures image meta-data.
Definition: v4l2_videodevice.h:97
bool isOutput() const
Identify if the video device outputs data.
Definition: v4l2_videodevice.h:66
bool isVideoCapture() const
Identify if the video device captures images.
Definition: v4l2_videodevice.h:89
bool isMultiplanar() const
Identify if the video device implements the V4L2 multiplanar APIs.
Definition: v4l2_videodevice.h:54
bool isMeta() const
Identify if the video device captures or outputs image meta-data.
Definition: v4l2_videodevice.h:84
bool isCapture() const
Identify if the video device captures data.
Definition: v4l2_videodevice.h:60
bool isMetaOutput() const
Identify if the video device outputs image meta-data.
Definition: v4l2_videodevice.h:101
const char * bus_info() const
Retrieve the location of the video device in the system.
Definition: v4l2_videodevice.h:44
const char * card() const
Retrieve the video device card name.
Definition: v4l2_videodevice.h:40
bool isVideo() const
Identify if the video device captures or outputs images.
Definition: v4l2_videodevice.h:72
const char * driver() const
Retrieve the driver module name.
Definition: v4l2_videodevice.h:36
Common base for V4L2 devices and subdevices.