[libcamera-devel,v2,00/12] Add basic camera enumeration

Message ID 20181229032855.26249-1-niklas.soderlund@ragnatech.se
Headers show
Series
  • Add basic camera enumeration
Related show

Message

Niklas Söderlund Dec. 29, 2018, 3:28 a.m. UTC
Hi,

This series adds basic camera enumeration to libcamera. The idea is to
provide something which can server as a starting point to solve other
problems around and enhance the enumeration process once the overall
design is properly reviewed and requirements on the features missing
becomes a bit more clear. The code in this series is fully functional
and allows to add more pipeline handlers and enumerate cameras.

In this series there are however a few known limitations which I find
acceptable to get started and which can be solved one by one once the
basic structure of enumeration is reviewed and hopefully upstream.  The
known limitations are:

- No sysfs based device enumerator. This will be needed so libcamera
  have something to fallback on if udev enumeration fails or is not
  available at all. The rational to focus on udev first is that it's
  more complex and will support more features then sysfs (most notably
  hot-(un)plug support.

- The camera object (1/12) in this series is a mix of Jacopo's and
  Laurent's previous patches with modifications by me. By no means would
  I like to claim authorship of all work in this patch but as I modified
  it I did claim authorship of it. If any of you wish to be claim
  authorship for it let me know, I don't want you to be unprepared when
  you get (git) blamed for my mistakes :-)

- The DeviceInfo class should probably down the road be replaced by a
  more comprehensive MediaDevice class. For now i feel this solution
  works as it allows us to move forward with a MediaDevice class focused
  on the needs of the Camera class and later extend it with the limited
  features needed to replace DeviceInfo. For this reason I chose the
  name DeciceInfo to not cause conflicts and allow the two to live in
  parallel for a short wile if needed.

- There is no support for hot-plug or hot-unplug. The state of the
  system is assumed to be static for the entire execution. Some care
  have been taken to facilitate addition of hot-plug support.

- There is only one pipeline handler included in this series for the
  vimc driver. It should be fairly trivial to add one for the Soraka, I
  chose not to do so to reduce the number of patches and to increase the
  number of potential testers as anyone can do 'modprobe vimc' and have
  the test case for this series passing.

Patch 1/12 adds a mock for a Camera class and stubs in lifetime
management features needed to allow the camera manger to try and control
the lifetime of objects. Patch 2/12 adds a build requirement on libudev.

Patch 3/12 -- 7/12 adds the device enumerator and accompanying classes
to allow storing and searching for media devices by a pipeline handler.
Patch 8/12 adds the documentation for all enumerator related classes. I
chose to split this in multiple patches to ease review, I'm open to
squashing them together if someone feels it's better for some reason or
other.

Patch 9/12 adds a base class for pipeline handlers and a global list of
pipe handlers in the system which each pipeline implementation can
register it self with to be included in the enumeration of cameras. This
approach allows the pipeline implementations to be self contained in a
single .cpp file, thanks Kieran for pointing me in the right direction
for how to do this in C++ ;-)

Patch 10/12 adds the camera manger which tracks lifetime management of
cameras in the system and is the interface to applications to list and
get cameras out of the library. Patch 11/12 adds a pipeline handler for
the vimc driver and lastly 12/12 adds a test case which simply uses most
features of the series to list all cameras in the system.

This series is based on top of the current master branch and the test
case have been run under valgrind and no memory issues are found.

valgrind --tool=memcheck --leak-check=full ./test/list
==25960== Memcheck, a memory error detector
==25960== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==25960== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==25960== Command: ./test/list
==25960== 
[273:11:28.468815052] INFO device_enumerator.cpp:71 Device: /dev/media1 Entity: 'Venus USB2.0 Camera: Venus USB2' -> /dev/video4
[273:11:28.502392360] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'Debayer A' -> /dev/v4l-subdev2
[273:11:28.502798125] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'Debayer B' -> /dev/v4l-subdev3
[273:11:28.502964381] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'RGB/YUV Capture' -> /dev/video2
[273:11:28.503035373] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'RGB/YUV Input' -> /dev/v4l-subdev4
[273:11:28.503255023] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'Raw Capture 0' -> /dev/video0
[273:11:28.503457774] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'Raw Capture 1' -> /dev/video1
[273:11:28.503527816] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'Scaler' -> /dev/v4l-subdev5
[273:11:28.503621969] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'Sensor A' -> /dev/v4l-subdev0
[273:11:28.503729366] INFO device_enumerator.cpp:71 Device: /dev/media0 Entity: 'Sensor B' -> /dev/v4l-subdev1
- Venus USB2.0 Camera: Venus USB2
- Dummy VIMC Camera
==25960== 
==25960== HEAP SUMMARY:
==25960==     in use at exit: 0 bytes in 0 blocks
==25960==   total heap usage: 822 allocs, 822 frees, 426,836 bytes allocated
==25960== 
==25960== All heap blocks were freed -- no leaks are possible
==25960== 
==25960== For counts of detected and suppressed errors, rerun with: -v
==25960== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Niklas Söderlund (12):
  libcamera: Add Camera class
  libcamera: add dependency on libudev
  libcamera: device_enumerator: add DeviceInfo class
  libcamera: device_enumerator: add DeviceMatch class
  libcamera: device_enumerator: add DeviceEnumerator class
  libcamera: device_enumerator: add DeviceEnumeratorUdev class
  libcamera: device_enumerator: add factory for DeviceEnumerators
  libcamera: device_enumerator: add documentation
  libcamera: pipeline_handler: add PipelineHandler class
  libcamera: camera_manager: add CameraManager class
  libcamera: pipeline: vimc: add pipeline handler for vimc
  tests: add test to list all cameras in the system

 include/libcamera/camera.h                |  31 ++
 include/libcamera/camera_manager.h        |  38 ++
 include/libcamera/libcamera.h             |   3 +
 include/libcamera/meson.build             |   2 +
 src/libcamera/camera.cpp                  |  89 ++++
 src/libcamera/camera_manager.cpp          | 166 ++++++
 src/libcamera/device_enumerator.cpp       | 594 ++++++++++++++++++++++
 src/libcamera/include/device_enumerator.h |  97 ++++
 src/libcamera/include/pipeline_handler.h  |  62 +++
 src/libcamera/meson.build                 |  13 +-
 src/libcamera/pipeline/meson.build        |   3 +
 src/libcamera/pipeline/vimc.cpp           |  91 ++++
 src/libcamera/pipeline_handler.cpp        | 138 +++++
 test/list.cpp                             |  54 ++
 test/meson.build                          |   5 +
 15 files changed, 1385 insertions(+), 1 deletion(-)
 create mode 100644 include/libcamera/camera.h
 create mode 100644 include/libcamera/camera_manager.h
 create mode 100644 src/libcamera/camera.cpp
 create mode 100644 src/libcamera/camera_manager.cpp
 create mode 100644 src/libcamera/device_enumerator.cpp
 create mode 100644 src/libcamera/include/device_enumerator.h
 create mode 100644 src/libcamera/include/pipeline_handler.h
 create mode 100644 src/libcamera/pipeline/meson.build
 create mode 100644 src/libcamera/pipeline/vimc.cpp
 create mode 100644 src/libcamera/pipeline_handler.cpp
 create mode 100644 test/list.cpp