summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo.mondi@ideasonboard.com>2023-08-08 10:59:24 +0200
committerJacopo Mondi <jacopo.mondi@ideasonboard.com>2023-08-08 13:47:29 +0200
commit41ebdcd2a98c8648542e5201ebe06adc278f321a (patch)
tree81c47e91b31e28dc7c99efdeb4d59757bc438f50
parent796adbe28e3c28547947eebf575dd55af5d7dcf2 (diff)
libcamera: Introduce CameraDevice and USBDevice
Introduce a CameraDevice base class from which the MediaDevice and USBDevice derive from. This allows to generalize the PipelineHandler base class implementation to use a generic 'CameraDevice' type in the later patches. Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
-rw-r--r--include/libcamera/internal/camera_device.h31
-rw-r--r--include/libcamera/internal/media_device.h13
-rw-r--r--include/libcamera/internal/meson.build2
-rw-r--r--include/libcamera/internal/usb_device.h52
-rw-r--r--src/libcamera/camera_device.cpp22
-rw-r--r--src/libcamera/media_device.cpp2
-rw-r--r--src/libcamera/meson.build1
7 files changed, 115 insertions, 8 deletions
diff --git a/include/libcamera/internal/camera_device.h b/include/libcamera/internal/camera_device.h
new file mode 100644
index 00000000..421d77e8
--- /dev/null
+++ b/include/libcamera/internal/camera_device.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Ideas On Board Oy
+ *
+ * camera_device.h - Base class for camera devices
+ */
+
+#pragma once
+
+namespace libcamera {
+
+class CameraDevice
+{
+public:
+ CameraDevice()
+ : acquired_(false)
+ {
+ }
+
+ virtual bool acquire() = 0;
+ virtual void release() = 0;
+ bool busy() const { return acquired_; }
+
+ virtual bool lock() = 0;
+ virtual void unlock() = 0;
+
+protected:
+ bool acquired_;
+};
+
+} /* namespace libcamera */
diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h
index eb8cfde4..2c748ae6 100644
--- a/include/libcamera/internal/media_device.h
+++ b/include/libcamera/internal/media_device.h
@@ -18,22 +18,22 @@
#include <libcamera/base/signal.h>
#include <libcamera/base/unique_fd.h>
+#include "libcamera/internal/camera_device.h"
#include "libcamera/internal/media_object.h"
namespace libcamera {
-class MediaDevice : protected Loggable
+class MediaDevice : protected Loggable, public CameraDevice
{
public:
MediaDevice(const std::string &deviceNode);
~MediaDevice();
- bool acquire();
- void release();
- bool busy() const { return acquired_; }
+ bool acquire() override;
+ void release() override;
- bool lock();
- void unlock();
+ bool lock() override;
+ void unlock() override;
int populate();
bool isValid() const { return valid_; }
@@ -85,7 +85,6 @@ private:
UniqueFD fd_;
bool valid_;
- bool acquired_;
std::map<unsigned int, MediaObject *> objects_;
std::vector<MediaEntity *> entities_;
diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build
index 169e0655..c683283d 100644
--- a/include/libcamera/internal/meson.build
+++ b/include/libcamera/internal/meson.build
@@ -14,6 +14,7 @@ libcamera_internal_headers = files([
'byte_stream_buffer.h',
'camera.h',
'camera_controls.h',
+ 'camera_device.h',
'camera_lens.h',
'camera_manager.h',
'camera_sensor.h',
@@ -41,6 +42,7 @@ libcamera_internal_headers = files([
'request.h',
'source_paths.h',
'sysfs.h',
+ 'usb_device.h',
'v4l2_device.h',
'v4l2_pixelformat.h',
'v4l2_subdevice.h',
diff --git a/include/libcamera/internal/usb_device.h b/include/libcamera/internal/usb_device.h
new file mode 100644
index 00000000..7fe0f7c4
--- /dev/null
+++ b/include/libcamera/internal/usb_device.h
@@ -0,0 +1,52 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Ideas On Board Oy
+ *
+ * usb_device.h - Description of a USB device
+ */
+
+#pragma once
+
+#include "libcamera/internal/camera_device.h"
+
+namespace libcamera {
+
+class USBDevice : public CameraDevice
+{
+public:
+ USBDevice(const char *vid, const char *pid)
+ : CameraDevice(), vid_(vid), pid_(pid)
+ {
+ }
+
+ /* \todo Implement acquire/release and lock/unlock */
+ bool acquire() override
+ {
+ /* This only works within the same process!! */
+ if (acquired_)
+ return false;
+
+ acquired_ = true;
+ return true;
+ }
+ void release() override
+ {
+ }
+
+ bool lock() override
+ {
+ return true;
+ }
+ void unlock() override
+ {
+ }
+
+ const std::string &vid() const { return vid_; };
+ const std::string &pid() const { return pid_; };
+
+private:
+ std::string vid_;
+ std::string pid_;
+};
+
+} /* namespace libcamera */
diff --git a/src/libcamera/camera_device.cpp b/src/libcamera/camera_device.cpp
new file mode 100644
index 00000000..a0ceba0d
--- /dev/null
+++ b/src/libcamera/camera_device.cpp
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Ideas On Board Oy
+ *
+ * camera_device.cpp - Base class for camera devices
+ */
+
+#include "libcamera/internal/camera_device.h"
+
+/**
+ * \file camera_device.h
+ * \brief Base class for camera devices
+ */
+
+namespace libcamera {
+
+/**
+ * \class CameraDevice
+ * \brief Base class for camera devices
+ */
+
+} /* namespace libcamera */
diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index 2949816b..f9c2dbf2 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -63,7 +63,7 @@ LOG_DEFINE_CATEGORY(MediaDevice)
* populate() before the media graph can be queried.
*/
MediaDevice::MediaDevice(const std::string &deviceNode)
- : deviceNode_(deviceNode), valid_(false), acquired_(false)
+ : CameraDevice(), deviceNode_(deviceNode), valid_(false)
{
}
diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
index d5562afc..3a70946a 100644
--- a/src/libcamera/meson.build
+++ b/src/libcamera/meson.build
@@ -5,6 +5,7 @@ libcamera_sources = files([
'byte_stream_buffer.cpp',
'camera.cpp',
'camera_controls.cpp',
+ 'camera_device.cpp',
'camera_lens.cpp',
'camera_manager.cpp',
'camera_sensor.cpp',