From patchwork Tue Aug 8 12:52:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18927 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 60E2ABDB13 for ; Tue, 8 Aug 2023 12:52:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 54EEC60562; Tue, 8 Aug 2023 14:52:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1691499167; bh=/cfcffXyVaewfOa0V1shewCtneEJgfjgIWVqv6bWltk=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=106i8zZ+qqds9+WkvZjwW+ar+GAkPrKvGaOdbrxEEixrAl+obdjIS527tn/SAZ7/m qWhnv7kZYzdIp0+wZ5JVzrnYrEQotu4TV0FO2CxKisroRgnXQamU40Rg4D6wY48eua iSUotwLUY4RQsMBWSeoPwnIrbompShG/MY+5fZhG+45r24oRdE+dugNgshihUsgWs1 ykd30LdxAD5+xWhEUpbBz/1vhGTJepFT3FpsDCBjP+G5DVp57p4YU/w9SJHHnLZVVu 9KUeEh8CAKVQMm9woKjE+xKNH2DW/C/FvXfS3/lw8u0OWP8zh2QT4/SFKC1xIjYa9N J7TOSw0tOigPA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 88EAB60562 for ; Tue, 8 Aug 2023 14:52:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KniEc5RF"; 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 6AD9B331B; Tue, 8 Aug 2023 14:51:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691499098; bh=/cfcffXyVaewfOa0V1shewCtneEJgfjgIWVqv6bWltk=; h=From:To:Cc:Subject:Date:From; b=KniEc5RF2n7ceyJ9fGv2mL1GDm8XFpFnL/I9u9CzlmZcNT0VgoPNQolsJie+RNwZZ Ipj6beGUedrIOQ6rwbQmrKWhCOVLdPr23Qm4kP0bxW5PUlZcFMm+FmRyaBh2CSCaPn M9w2cuMsFk8A9I13w5l/tQ7x1C3lsZPpG1PpzUdI= To: libcamera-devel@lists.libcamera.org, Sophie Friedrich Date: Tue, 8 Aug 2023 14:52:19 +0200 Message-Id: <20230808125228.29043-1-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 0/9] libcamera: Generalize device match and support USB devices 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" Hello list, Hello Sophie As promised a long time ago, I would have liked to help you with your USB-but-not-UVC camera devices, by providing support in core libcamera for generalizing camera device enumeration and matching. This RFC series does that by generalizing the usage of MediaDevice and DeviceMatch and by extending the device enumerator (only the udev-based one for now) to enumerate and create USB devices on which pipeline handlers can match on. The series starts by moving all existing references to "device" and "device match" in the enumerator and device_match files to use the term "MediaDevice" as this is what libcamera currently supports. It then introduces a 'CameraDevice' base class from which 'MediaDevice' and a new 'USBDevice' class inherit from. Similarly, it introduces a 'DeviceMatch' base class from which 'MediaDeviceMatch' and 'USBDeviceMatch' are derived. The (udev) enumerator is augmented to support enumerating USB devices (the USB subsystem will have to be changed as I'm currently using "input" for my testings). Once USB devices are enumerated, the enumerator will keep them in a dedicated list of USBDevice instances. The enumerator is then expanded to support searching a USB device by providing a USBDeviceMatch, and the PipelineHandler base class is expanded similarly with a dedicated method to "acquire" a USB device. Finally, as an experiment a "usb-test" pipeline handler is added, and made to match on my mouse VID/PID, so don't expect this to work out of the box on your system (unless we have the same mouse ofc :) Tested by using the newly introduced usb-test pipeline along with the VIMC and UVC pipeline handlers. With these, 3 cameras are correctly listed on my system (even if one of the three is a mouse). Available cameras: 1: 'Sensor B' (platform/vimc.0 Sensor B) 2: Internal front camera (\_SB_.PCI0.XHC_.RHUB.HS08-8:1.0-5986:2115) 3: (046d/c52b) <-- This is my mouse! Sophie, it would be nice if you could test if what I have here works as a base for you. I do expect you will have to play a little with the udev-based enumerator to have it enumerate on a different USB class, as I don't expect your camera to be part of the 'input' subsystem. From a design point of view, I tried to avoid RTTI everywhere I could, specifically conditional code execution based on RTTI. So far only in the pipeline handler base class it has been necessary to test based on the result of a dynamic_cast<>, but as commented in the code, I do expect this to go away when USBDevice will be fully implemented. Hope this helps your developments Thanks j Jacopo Mondi (9): libcamera: Break-out DeviceMatch libcamera: Define and use MediaDeviceMatch libcamera: device_enumerator: Prepare for more device types libcamera: Introduce CameraDevice and USBDevice libcamera: device_enumerator_udev: Enumerate USB devices libcamera: device_match: Introduce USBDeviceMatch libcamera: device_enumerator: Search for USB devices libcamera: pipeline_handler: Add function to acquire a USB device [HACK] libcamera: pipeline: Add usb-test pipeline Documentation/guides/pipeline-handler.rst | 10 +- include/libcamera/internal/camera_device.h | 31 +++ .../libcamera/internal/device_enumerator.h | 32 ++-- .../internal/device_enumerator_udev.h | 1 + include/libcamera/internal/device_match.h | 51 +++++ include/libcamera/internal/media_device.h | 13 +- include/libcamera/internal/meson.build | 3 + include/libcamera/internal/pipeline_handler.h | 13 +- include/libcamera/internal/usb_device.h | 52 +++++ meson_options.txt | 1 + src/libcamera/camera_device.cpp | 22 +++ src/libcamera/device_enumerator.cpp | 180 +++++++----------- src/libcamera/device_enumerator_sysfs.cpp | 4 +- src/libcamera/device_enumerator_udev.cpp | 40 +++- src/libcamera/device_match.cpp | 128 +++++++++++++ src/libcamera/media_device.cpp | 2 +- src/libcamera/meson.build | 2 + src/libcamera/pipeline/imx8-isi/imx8-isi.cpp | 2 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 +- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 +- src/libcamera/pipeline/rpi/vc4/vc4.cpp | 4 +- src/libcamera/pipeline/simple/simple.cpp | 4 +- src/libcamera/pipeline/usb-test/meson.build | 5 + src/libcamera/pipeline/usb-test/usb_test.cpp | 93 +++++++++ src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 2 +- src/libcamera/pipeline/vimc/vimc.cpp | 2 +- src/libcamera/pipeline_handler.cpp | 72 +++++-- test/camera-sensor.cpp | 2 +- test/delayed_controls.cpp | 2 +- test/libtest/buffer_source.cpp | 2 +- test/media_device/media_device_test.cpp | 2 +- test/v4l2_subdevice/v4l2_subdevice_test.cpp | 2 +- test/v4l2_videodevice/v4l2_m2mdevice.cpp | 2 +- .../v4l2_videodevice_test.cpp | 2 +- 34 files changed, 610 insertions(+), 179 deletions(-) create mode 100644 include/libcamera/internal/camera_device.h create mode 100644 include/libcamera/internal/device_match.h create mode 100644 include/libcamera/internal/usb_device.h create mode 100644 src/libcamera/camera_device.cpp create mode 100644 src/libcamera/device_match.cpp create mode 100644 src/libcamera/pipeline/usb-test/meson.build create mode 100644 src/libcamera/pipeline/usb-test/usb_test.cpp --- 2.40.1