[libcamera-devel,RFC,0/9] libcamera: Generalize device match and support USB devices
mbox series

Message ID 20230808125228.29043-1-jacopo.mondi@ideasonboard.com
Headers show
Series
  • libcamera: Generalize device match and support USB devices
Related show

Message

Jacopo Mondi Aug. 8, 2023, 12:52 p.m. UTC
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