new file mode 100644
@@ -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 */
@@ -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_;
@@ -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',
new file mode 100644
@@ -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 */
new file mode 100644
@@ -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 */
@@ -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)
{
}
@@ -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',
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> --- include/libcamera/internal/camera_device.h | 31 +++++++++++++ include/libcamera/internal/media_device.h | 13 +++--- include/libcamera/internal/meson.build | 2 + include/libcamera/internal/usb_device.h | 52 ++++++++++++++++++++++ src/libcamera/camera_device.cpp | 22 +++++++++ src/libcamera/media_device.cpp | 2 +- src/libcamera/meson.build | 1 + 7 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 include/libcamera/internal/camera_device.h create mode 100644 include/libcamera/internal/usb_device.h create mode 100644 src/libcamera/camera_device.cpp