The FileDescriptor class is a generic helper that matches the criteria for the base library. Move it there. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
87 lines
2 KiB
C++
87 lines
2 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* v4l2_camera.h - V4L2 compatibility camera
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <deque>
|
|
#include <utility>
|
|
|
|
#include <libcamera/base/file_descriptor.h>
|
|
#include <libcamera/base/mutex.h>
|
|
#include <libcamera/base/semaphore.h>
|
|
|
|
#include <libcamera/camera.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();
|
|
|
|
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);
|
|
|
|
int allocBuffers(unsigned int count);
|
|
void freeBuffers();
|
|
libcamera::FileDescriptor getBufferFd(unsigned int index);
|
|
|
|
int streamOn();
|
|
int streamOff();
|
|
|
|
int qbuf(unsigned int index);
|
|
|
|
void waitForBufferAvailable();
|
|
bool isBufferAvailable();
|
|
|
|
bool isRunning();
|
|
|
|
private:
|
|
void requestComplete(libcamera::Request *request);
|
|
|
|
std::shared_ptr<libcamera::Camera> camera_;
|
|
std::unique_ptr<libcamera::CameraConfiguration> config_;
|
|
|
|
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_;
|
|
|
|
int efd_;
|
|
|
|
libcamera::Mutex bufferMutex_;
|
|
libcamera::ConditionVariable bufferCV_;
|
|
unsigned int bufferAvailableCount_;
|
|
};
|