summaryrefslogtreecommitdiff
path: root/src/v4l2/v4l2_camera.h
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2019-12-06 04:14:52 -0500
committerPaul Elder <paul.elder@ideasonboard.com>2020-01-03 19:53:20 -0500
commit0ce8f2390b5280887a2ac179faf2aa01604cb1cc (patch)
treeea8d04e9013b87217bd8266eab5356c03ded19fa /src/v4l2/v4l2_camera.h
parenta3b80f3af87198b97f11f0694ff4d7ddde63fc30 (diff)
v4l2: v4l2_compat: Add V4L2 compatibility layer
Add libcamera V4L2 compatibility layer. This initial implementation supports the minimal set of V4L2 operations, which allows getting, setting, and enumerating formats, and streaming frames from a video device. Some data about the wrapped V4L2 video device are hardcoded. Add a build option named 'v4l2' and adjust the build system to selectively compile the V4L2 compatibility layer. For now we match the V4L2 device node to a libcamera camera based on a devnum that a pipeline handler may optionally map to a libcamera camera. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/v4l2/v4l2_camera.h')
-rw-r--r--src/v4l2/v4l2_camera.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h
new file mode 100644
index 00000000..d24dbca6
--- /dev/null
+++ b/src/v4l2/v4l2_camera.h
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * v4l2_camera.h - V4L2 compatibility camera
+ */
+
+#ifndef __V4L2_CAMERA_H__
+#define __V4L2_CAMERA_H__
+
+#include <deque>
+#include <linux/videodev2.h>
+#include <mutex>
+
+#include <libcamera/buffer.h>
+#include <libcamera/camera.h>
+
+#include "semaphore.h"
+
+using namespace libcamera;
+
+class FrameMetadata
+{
+public:
+ FrameMetadata(Buffer *buffer);
+
+ int index() const { return index_; }
+
+ unsigned int bytesused() const { return bytesused_; }
+ uint64_t timestamp() const { return timestamp_; }
+ unsigned int sequence() const { return sequence_; }
+
+ Buffer::Status status() const { return status_; }
+
+private:
+ int index_;
+
+ unsigned int bytesused_;
+ uint64_t timestamp_;
+ unsigned int sequence_;
+
+ Buffer::Status status_;
+};
+
+class V4L2Camera : public Object
+{
+public:
+ V4L2Camera(std::shared_ptr<Camera> camera);
+ ~V4L2Camera();
+
+ void open(int *ret);
+ void close();
+ void getStreamConfig(StreamConfiguration *streamConfig);
+ std::vector<FrameMetadata> completedBuffers();
+
+ void mmap(void **ret, unsigned int index);
+
+ void configure(int *ret, StreamConfiguration *streamConfigOut,
+ const Size &size, PixelFormat pixelformat,
+ unsigned int bufferCount);
+
+ void allocBuffers(int *ret, unsigned int count);
+ void freeBuffers();
+ void streamOn(int *ret);
+ void streamOff(int *ret);
+
+ void qbuf(int *ret, unsigned int index);
+
+ Semaphore bufferSema_;
+
+private:
+ void requestComplete(Request *request);
+
+ std::shared_ptr<Camera> camera_;
+ std::unique_ptr<CameraConfiguration> config_;
+
+ bool isRunning_;
+
+ std::mutex bufferLock_;
+
+ std::deque<std::unique_ptr<Request>> pendingRequests_;
+ std::deque<std::unique_ptr<FrameMetadata>> completedBuffers_;
+};
+
+#endif /* __V4L2_CAMERA_H__ */