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

Niklas Söderlund niklas.soderlund at ragnatech.se
Sun Dec 23 00:00:29 CET 2018


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
==29822== Memcheck, a memory error detector
==29822== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==29822== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==29822== Command: ./test/list
==29822==
[18:23:20.377682367] INFO deviceenumerator.cpp:70 Device: /dev/media0 Entity: 'Integrated Camera: Integrated C' -> /dev/video1
[18:23:20.422617627] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'Debayer A' -> /dev/v4l-subdev2
[18:23:20.423131606] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'Debayer B' -> /dev/v4l-subdev3
[18:23:20.423351904] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'RGB/YUV Capture' -> /dev/video4
[18:23:20.423484244] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'RGB/YUV Input' -> /dev/v4l-subdev4
[18:23:20.423736672] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'Raw Capture 0' -> /dev/video2
[18:23:20.423962866] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'Raw Capture 1' -> /dev/video3
[18:23:20.424090475] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'Scaler' -> /dev/v4l-subdev5
[18:23:20.424215875] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'Sensor A' -> /dev/v4l-subdev0
[18:23:20.424337060] INFO deviceenumerator.cpp:70 Device: /dev/media1 Entity: 'Sensor B' -> /dev/v4l-subdev1
[18:23:20.458610283]  DBG camera.cpp:57 Camera Constructed for Dummy VIMC Camera
- Dummy VIMC Camera
[18:23:20.478303363]  DBG camera.cpp:65 Camera Destroyed
==29822==
==29822== HEAP SUMMARY:
==29822==     in use at exit: 0 bytes in 0 blocks
==29822==   total heap usage: 756 allocs, 756 frees, 418,671 bytes allocated
==29822==
==29822== All heap blocks were freed -- no leaks are possible
==29822==
==29822== For counts of detected and suppressed errors, rerun with: -v
==29822== 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: deviceenumerator: add DeviceInfo class
  libcamera: deviceenumerator: add DeviceMatch class
  libcamera: deviceenumerator: add DeviceEnumerator class
  libcamera: deviceenumerator: add DeviceEnumeratorUdev class
  libcamera: deviceenumerator: add factory for DeviceEnumerators
  libcamera: deviceenumerator: add documentation
  libcamera: pipelinehandler: add PipelineHandler class
  libcamera: cameramanager: add CameraManager class
  libcamera: pipe-vimc: add pipeline handler for vimc
  tests: add test to list all cameras in the system

 include/libcamera/camera.h               |  31 ++
 include/libcamera/cameramanager.h        |  38 ++
 include/libcamera/libcamera.h            |   3 +
 include/libcamera/meson.build            |   2 +
 src/libcamera/camera.cpp                 |  97 ++++
 src/libcamera/cameramanager.cpp          | 173 +++++++
 src/libcamera/deviceenumerator.cpp       | 622 +++++++++++++++++++++++
 src/libcamera/include/deviceenumerator.h | 100 ++++
 src/libcamera/include/pipelinehandler.h  |  71 +++
 src/libcamera/meson.build                |  12 +-
 src/libcamera/pipe-vimc.cpp              |  92 ++++
 src/libcamera/pipelinehandler.cpp        | 122 +++++
 test/list.cpp                            |  54 ++
 test/meson.build                         |   5 +
 14 files changed, 1421 insertions(+), 1 deletion(-)
 create mode 100644 include/libcamera/camera.h
 create mode 100644 include/libcamera/cameramanager.h
 create mode 100644 src/libcamera/camera.cpp
 create mode 100644 src/libcamera/cameramanager.cpp
 create mode 100644 src/libcamera/deviceenumerator.cpp
 create mode 100644 src/libcamera/include/deviceenumerator.h
 create mode 100644 src/libcamera/include/pipelinehandler.h
 create mode 100644 src/libcamera/pipe-vimc.cpp
 create mode 100644 src/libcamera/pipelinehandler.cpp
 create mode 100644 test/list.cpp

-- 
2.20.1



More information about the libcamera-devel mailing list