7 #ifndef __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__ 8 #define __LIBCAMERA_INTERNAL_V4L2_VIDEODEVICE_H__ 17 #include <linux/videodev2.h> 40 return reinterpret_cast<const char *
>(v4l2_capability::driver);
44 return reinterpret_cast<const char *
>(v4l2_capability::card);
48 return reinterpret_cast<const char *
>(v4l2_capability::bus_info);
52 return capabilities & V4L2_CAP_DEVICE_CAPS
53 ? v4l2_capability::device_caps
54 : v4l2_capability::capabilities;
58 return device_caps() & (V4L2_CAP_VIDEO_CAPTURE_MPLANE |
59 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
60 V4L2_CAP_VIDEO_M2M_MPLANE);
65 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
66 V4L2_CAP_META_CAPTURE);
71 V4L2_CAP_VIDEO_OUTPUT_MPLANE |
72 V4L2_CAP_META_OUTPUT);
77 V4L2_CAP_VIDEO_CAPTURE_MPLANE |
78 V4L2_CAP_VIDEO_OUTPUT |
79 V4L2_CAP_VIDEO_OUTPUT_MPLANE);
84 V4L2_CAP_VIDEO_M2M_MPLANE);
89 V4L2_CAP_META_OUTPUT);
117 V4L2BufferCache(
const std::vector<std::unique_ptr<FrameBuffer>> &buffers);
121 void put(
unsigned int index);
128 Entry(
bool free, uint64_t lastUsed,
const FrameBuffer &buffer);
146 std::vector<Plane> planes_;
149 std::atomic<uint64_t> lastUsedCounter_;
150 std::vector<Entry> cache_;
152 unsigned int missCounter_;
167 unsigned int planesCount = 0;
169 const std::string toString()
const;
175 using Formats = std::map<V4L2PixelFormat, std::vector<SizeRange>>;
182 int open(
int handle,
enum v4l2_buf_type type);
187 const char *
busName()
const {
return caps_.bus_info(); }
194 Formats formats(uint32_t code = 0);
196 int setSelection(
unsigned int target,
Rectangle *rect);
198 int allocateBuffers(
unsigned int count,
199 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
200 int exportBuffers(
unsigned int count,
201 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
202 int importBuffers(
unsigned int count);
203 int releaseBuffers();
211 static std::unique_ptr<V4L2VideoDevice>
212 fromEntityName(
const MediaDevice *media,
const std::string &entity);
217 std::string logPrefix()
const override;
231 std::vector<V4L2PixelFormat> enumPixelformats(uint32_t code);
234 int requestBuffers(
unsigned int count,
enum v4l2_memory memoryType);
235 int createBuffers(
unsigned int count,
236 std::vector<std::unique_ptr<FrameBuffer>> *buffers);
237 std::unique_ptr<FrameBuffer> createBuffer(
unsigned int index);
238 FileDescriptor exportDmabufFd(
unsigned int index,
unsigned int plane);
245 enum v4l2_buf_type bufferType_;
246 enum v4l2_memory memoryType_;
249 std::map<unsigned int, FrameBuffer *> queuedBuffers_;
269 std::string deviceNode_;
bool isCapture() const
Identify if the video device captures data.
Definition: v4l2_videodevice.h:62
Utilities to help constructing class interfaces.
const V4L2Capability & caps() const
Retrieve the device V4L2 capabilities.
Definition: v4l2_videodevice.h:189
Base class for V4L2VideoDevice and V4L2Subdevice.
Definition: v4l2_device.h:26
bool isMetaCapture() const
Identify if the video device captures image meta-data.
Definition: v4l2_videodevice.h:99
RAII-style wrapper for file descriptors.
Definition: file_descriptor.h:14
Top-level libcamera namespace.
Definition: bound_method.h:15
V4L2VideoDevice * capture()
Retrieve the capture V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:266
bool isOutput() const
Identify if the video device outputs data.
Definition: v4l2_videodevice.h:68
unsigned int length
The plane length in bytes.
Definition: buffer.h:42
Frame buffer data and its associated dynamic metadata.
Definition: buffer.h:37
Describe a two-dimensional size.
Definition: geometry.h:50
const char * bus_info() const
Retrieve the location of the video device in the system.
Definition: v4l2_videodevice.h:46
bool isVideoOutput() const
Identify if the video device outputs images.
Definition: v4l2_videodevice.h:95
V4L2VideoDevice object and API.
Definition: v4l2_videodevice.h:172
std::map< V4L2PixelFormat, std::vector< SizeRange > > Formats
A map of supported V4L2 pixel formats to frame sizes.
Definition: v4l2_videodevice.h:175
const char * driverName() const
Retrieve the name of the V4L2 device driver.
Definition: v4l2_videodevice.h:185
#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:37
Describe a rectangle's position and dimensions.
Definition: geometry.h:206
V4L2VideoDevice * output()
Retrieve the output V4L2VideoDevice instance.
Definition: v4l2_videodevice.h:265
bool isM2M() const
Identify if the device is a Memory-to-Memory device.
Definition: v4l2_videodevice.h:81
Common base for V4L2 devices and subdevices.
bool isVideoCapture() const
Identify if the video device captures images.
Definition: v4l2_videodevice.h:91
FileDescriptor fd
The dmabuf file descriptor.
Definition: buffer.h:41
bool isMeta() const
Identify if the video device captures or outputs image meta-data.
Definition: v4l2_videodevice.h:86
bool isMultiplanar() const
Identify if the video device implements the V4L2 multiplanar APIs.
Definition: v4l2_videodevice.h:56
Generic signal and slot communication mechanism.
Definition: object.h:20
A memory region to store a single plane of a frame.
Definition: buffer.h:40
bool isVideo() const
Identify if the video device captures or outputs images.
Definition: v4l2_videodevice.h:74
Notify of activity on a file descriptor.
Definition: event_notifier.h:17
int fd() const
Retrieve the numerical file descriptor.
Definition: file_descriptor.h:27
bool operator==(const Point &lhs, const Point &rhs)
Compare points for equality.
Definition: geometry.cpp:75
Signal< FrameBuffer * > bufferReady
A Signal emitted when a framebuffer completes.
Definition: v4l2_videodevice.h:206
bool hasStreaming() const
Determine if the video device can perform Streaming I/O.
Definition: v4l2_videodevice.h:107
const char * deviceName() const
Retrieve the name of the V4L2 video device.
Definition: v4l2_videodevice.h:186
Data structures related to geometric objects.
unsigned int device_caps() const
Retrieve the capabilities of the video device.
Definition: v4l2_videodevice.h:50
const char * card() const
Retrieve the video device card name.
Definition: v4l2_videodevice.h:42
Hot cache of associations between V4L2 buffer indexes and FrameBuffer.
Definition: v4l2_videodevice.h:113
const char * driver() const
Retrieve the driver module name.
Definition: v4l2_videodevice.h:38
Memory-to-Memory video device.
Definition: v4l2_videodevice.h:256
const char * busName() const
Retrieve the location of the device in the system.
Definition: v4l2_videodevice.h:187
bool isMetaOutput() const
Identify if the video device outputs image meta-data.
Definition: v4l2_videodevice.h:103