libcamera/src/v4l2/v4l2_camera.h
Nejc Galof 5456e02d3f v4l2: Support setting frame rate in the V4L2 Adaptation layer
The V4L2 adaptation layer can already support streaming with components
such as OpenCV, however it is not accepting, or handling any requests to
configure the frame rate.

In V4L2 the frame rate is set by configuring the timeperframe component
of the v4l2_streamparm structure through the VIDIOC_S_PARM ioctl.

Extend the V4L2 compatibility layer to accept the VIDIOC_S_PARM ioctls
and provide an interface for setting controls on the V4L2Camera class to
set the requested rate when starting the camera.

Signed-off-by: Nejc Galof <galof.nejc@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2024-09-10 22:17:28 +02:00

95 lines
2.3 KiB
C++

/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* V4L2 compatibility camera
*/
#pragma once
#include <deque>
#include <memory>
#include <vector>
#include <libcamera/base/mutex.h>
#include <libcamera/base/semaphore.h>
#include <libcamera/base/shared_fd.h>
#include <libcamera/camera.h>
#include <libcamera/controls.h>
#include <libcamera/framebuffer.h>
#include <libcamera/framebuffer_allocator.h>
class V4L2Camera
{
public:
struct Buffer {
Buffer(unsigned int index, const libcamera::FrameMetadata &data)
: index_(index), data_(data)
{
}
unsigned int index_;
libcamera::FrameMetadata data_;
};
V4L2Camera(std::shared_ptr<libcamera::Camera> camera);
~V4L2Camera();
int open(libcamera::StreamConfiguration *streamConfig);
void close();
void bind(int efd);
void unbind();
std::vector<Buffer> completedBuffers() LIBCAMERA_TSA_EXCLUDES(bufferLock_);
int configure(libcamera::StreamConfiguration *streamConfigOut,
const libcamera::Size &size,
const libcamera::PixelFormat &pixelformat,
unsigned int bufferCount);
int validateConfiguration(const libcamera::PixelFormat &pixelformat,
const libcamera::Size &size,
libcamera::StreamConfiguration *streamConfigOut);
libcamera::ControlList &controls() { return controls_; }
int allocBuffers(unsigned int count);
void freeBuffers();
int getBufferFd(unsigned int index);
int streamOn();
int streamOff();
int qbuf(unsigned int index);
void waitForBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_);
bool isBufferAvailable() LIBCAMERA_TSA_EXCLUDES(bufferMutex_);
bool isRunning();
private:
void requestComplete(libcamera::Request *request)
LIBCAMERA_TSA_EXCLUDES(bufferLock_);
std::shared_ptr<libcamera::Camera> camera_;
std::unique_ptr<libcamera::CameraConfiguration> config_;
libcamera::ControlList controls_;
bool isRunning_;
libcamera::Mutex bufferLock_;
libcamera::FrameBufferAllocator *bufferAllocator_;
std::vector<std::unique_ptr<libcamera::Request>> requestPool_;
std::deque<libcamera::Request *> pendingRequests_;
std::deque<std::unique_ptr<Buffer>> completedBuffers_
LIBCAMERA_TSA_GUARDED_BY(bufferLock_);
int efd_;
libcamera::Mutex bufferMutex_;
libcamera::ConditionVariable bufferCV_;
unsigned int bufferAvailableCount_ LIBCAMERA_TSA_GUARDED_BY(bufferMutex_);
};