From patchwork Tue Aug 8 12:52:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18931 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3F784C32A9 for ; Tue, 8 Aug 2023 12:52:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BC358627ED; Tue, 8 Aug 2023 14:52:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1691499175; bh=+/Rkd7Z+xBQAH+rNSIjq7t7JFy+zXhHsZnkvSO6d3VU=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=bfWEJunW0+NUqZoQxpI7FlAxLnsKTdM4Qu45OCuxw1zE55/N+w50N2EvPFndqUYZf CKFG73CLlbT6gLdPZg49st5tSiyPmqFzMZxvcPcEOY010Iw/J5Zxq/2NUvgHAa5lV2 JTxkDOn2o7axdYbZozmaMFoR6rxCoEET+BmHBxEaUn6dfWg4/WlYsMhWul5K9XNgzE e29aMdamU/wPndOSwf9IMQc/dH/ggKmf+LaMeF/V5bu0reXB82V0djQID/0Fi2fOqg /uMWGrBETW/QxZUfmVTwbK71OF8Iys3Eu1c3JU4nMjpqS/j05OC4ke0r40tghlYmKx Q4fyx6Jk0yiZQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B88C8627EC for ; Tue, 8 Aug 2023 14:52:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="AOQ82FU+"; dkim-atps=neutral Received: from uno.localdomain (mob-5-90-60-22.net.vodafone.it [5.90.60.22]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D4B72396D; Tue, 8 Aug 2023 14:51:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691499101; bh=+/Rkd7Z+xBQAH+rNSIjq7t7JFy+zXhHsZnkvSO6d3VU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AOQ82FU+V3At2vgtArnZHPv83zvtHWXBOv1rAx6EbWi8M1VUfbuYXsuuUQyJsZo+j dSxYAsODXX6QURNeiYbXaY36WOHeABW1Nja0QkEzNfxl98uyBKyFhgLpVLu1Vuiphj TSAuncmqD7+Jl8hz1oVVebQArAdq+5cGjhuc1atQ= To: libcamera-devel@lists.libcamera.org, Sophie Friedrich Date: Tue, 8 Aug 2023 14:52:23 +0200 Message-Id: <20230808125228.29043-5-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808125228.29043-1-jacopo.mondi@ideasonboard.com> References: <20230808125228.29043-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 4/9] libcamera: Introduce CameraDevice and USBDevice X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- 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 diff --git a/include/libcamera/internal/camera_device.h b/include/libcamera/internal/camera_device.h new file mode 100644 index 000000000000..421d77e8d6cf --- /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 eb8cfde48e20..2c748ae66545 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -18,22 +18,22 @@ #include #include +#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 objects_; std::vector entities_; diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 169e06557106..c683283da37d 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 000000000000..7fe0f7c4d6a9 --- /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 000000000000..a0ceba0db5af --- /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 2949816b4a64..f9c2dbf289f1 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 d5562afc50c7..3a70946a6f78 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',