libcamera: Add support for V4L2 requests

The V4L2 requests API provides support to atomically tie controls to a
set of buffers. This is especially common for m2m devices. Such a
request is represented by an fd that is allocated via
MEDIA_IOC_REQUEST_ALLOC and then passed to the various V4L2 functions.

Implement a V4L2Request class to wrap such an fd and add the
corresponding utility functions.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stefan Klug
2025-11-25 17:28:15 +01:00
parent 39c052c1e9
commit cdc2620549
10 changed files with 269 additions and 9 deletions
@@ -8,6 +8,7 @@
#pragma once
#include <map>
#include <optional>
#include <string>
#include <vector>
@@ -18,6 +19,7 @@
#include <libcamera/base/unique_fd.h>
#include "libcamera/internal/media_object.h"
#include "libcamera/internal/v4l2_request.h"
namespace libcamera {
@@ -57,6 +59,11 @@ public:
std::vector<MediaEntity *> locateEntities(unsigned int function);
int allocateRequests(unsigned int count,
std::vector<std::unique_ptr<V4L2Request>> *requests);
bool supportsRequests();
protected:
std::string logPrefix() const override;
@@ -87,6 +94,7 @@ private:
UniqueFD fd_;
bool valid_;
bool acquired_;
std::optional<bool> supportsRequests_;
std::map<unsigned int, MediaObject *> objects_;
std::vector<MediaEntity *> entities_;
+1
View File
@@ -44,6 +44,7 @@ libcamera_internal_headers = files([
'sysfs.h',
'v4l2_device.h',
'v4l2_pixelformat.h',
'v4l2_request.h',
'v4l2_subdevice.h',
'v4l2_videodevice.h',
'vector.h',
+3 -2
View File
@@ -24,6 +24,7 @@
#include <libcamera/controls.h>
#include "libcamera/internal/formats.h"
#include "libcamera/internal/v4l2_request.h"
namespace libcamera {
@@ -37,8 +38,8 @@ public:
const ControlInfoMap &controls() const { return controls_; }
ControlList getControls(Span<const uint32_t> ids);
int setControls(ControlList *ctrls);
ControlList getControls(Span<const uint32_t> ids, const V4L2Request *request = nullptr);
int setControls(ControlList *ctrls, const V4L2Request *request = nullptr);
const struct v4l2_query_ext_ctrl *controlInfo(uint32_t id) const;
+44
View File
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2025, Ideas On Board
*
* V4L2 Request
*/
#pragma once
#include <string>
#include <linux/videodev2.h>
#include <libcamera/base/event_notifier.h>
#include <libcamera/base/log.h>
#include <libcamera/base/signal.h>
#include <libcamera/base/unique_fd.h>
namespace libcamera {
class V4L2Request : protected Loggable
{
public:
bool isValid() const { return fd_.isValid(); }
int fd() const { return fd_.get(); }
int reinit();
int queue();
V4L2Request(UniqueFD &&fd);
Signal<V4L2Request *> requestDone;
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(V4L2Request)
void requestReady();
std::string logPrefix() const override;
UniqueFD fd_;
EventNotifier fdNotifier_;
};
} /* namespace libcamera */
@@ -33,6 +33,7 @@
#include "libcamera/internal/formats.h"
#include "libcamera/internal/v4l2_device.h"
#include "libcamera/internal/v4l2_pixelformat.h"
#include "libcamera/internal/v4l2_request.h"
namespace libcamera {
@@ -217,7 +218,7 @@ public:
int importBuffers(unsigned int count);
int releaseBuffers();
int queueBuffer(FrameBuffer *buffer);
int queueBuffer(FrameBuffer *buffer, const V4L2Request *request = nullptr);
Signal<FrameBuffer *> bufferReady;
int streamOn();