diff options
author | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2023-08-08 10:59:24 +0200 |
---|---|---|
committer | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2023-08-08 13:47:29 +0200 |
commit | 41ebdcd2a98c8648542e5201ebe06adc278f321a (patch) | |
tree | 81c47e91b31e28dc7c99efdeb4d59757bc438f50 /include | |
parent | 796adbe28e3c28547947eebf575dd55af5d7dcf2 (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>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/internal/camera_device.h | 31 | ||||
-rw-r--r-- | include/libcamera/internal/media_device.h | 13 | ||||
-rw-r--r-- | include/libcamera/internal/meson.build | 2 | ||||
-rw-r--r-- | include/libcamera/internal/usb_device.h | 52 |
4 files changed, 91 insertions, 7 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 */ |