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:
@@ -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_;
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user