[libcamera-devel,RFC,00/11] libcamerea: Add support for exclusive access to cameras between processes
mbox series

Message ID 20190414013506.10515-1-niklas.soderlund@ragnatech.se
Headers show
Series
  • libcamerea: Add support for exclusive access to cameras between processes
Related show

Message

Niklas Söderlund April 14, 2019, 1:34 a.m. UTC
Hi,

This RFC is a proposal on how to solve mutably exclusive access to a 
camera between two or more processes by the use of lockf(). In the 
process of adding support for this the MediaDevice implementation is 
cleaned up a bit and stricter call patterns are enforced. At the same 
time a small load is taken of pipeline handler implementations.

As a camera might share resources with other cameras from the same 
pipeline handler instance I have chosen to put the granularity of the 
lock at the media device level. When a camera is acquired by an 
applications all media devices the pipeline handler it belongs to have 
claimed are locked and becomes unavailable to other processes. Other 
process can still enumerate locked media devices and list all cameras 
they provide but they can't use any of the cameras who are backed by a 
locked media device.

Patches 1/11 -- 8/11 deals with tidying up and adding more restrictions 
to the MediaDevices and how they handled inside pipeline handlers. While 
patches 9/11 -- 11/11 adds the new locking scheme which depends on the 
new stricter handling of media devices.

As this is a RFC there are some limitations,
- Documentation is missing for some of the new functions, but they are 
  pretty straight forward.
- The new stricter MediaDevice call schema prevents 
  media_device_link_test to run properly as it now needs access to 
  private functions to operate. As it's outside the scope of this RFC to 
  solve testing of private functions I simply dropped it for now.
- Some functions name are not as nice as they could be... I really hate 
  PipelineHandler::tryAcquire(), suggestions are welcome!

All comments welcome, including ones telling me I'm a moron! ;-)

Niklas Söderlund (11):
  libcamera: Always check return value of MediaDevice::acquire()
  libcamera: media_device: Open and close media device inside populate()
  libcamera: media_device: Only read device information in populate()
  libcamera: media_device: Handle media device fd in acquire() and
    release()
  libcamera: media_device: Make open() and close() private
  libcamera: pipeline_handler: Keep track of MediaDevice
  [HACK] tests: disable media_device_link_test
  libcamera: media_device: Restrict acquire() and release()
  libcamera: media_device: Add functions to lock device for other
    processes
  libcamera: pipeline_handler: Add functions to lock a whole pipeline
  libcamera: camera: Lock the pipeline handler in acquire()

 src/libcamera/camera.cpp                      |   7 +
 src/libcamera/device_enumerator.cpp           |   8 +-
 src/libcamera/include/media_device.h          |  16 +-
 src/libcamera/include/pipeline_handler.h      |   7 +
 src/libcamera/media_device.cpp                | 250 +++++++++---------
 src/libcamera/pipeline/ipu3/ipu3.cpp          |  47 +---
 src/libcamera/pipeline/uvcvideo.cpp           |  23 +-
 src/libcamera/pipeline/vimc.cpp               |  21 +-
 src/libcamera/pipeline_handler.cpp            |  40 +++
 test/media_device/media_device_link_test.cpp  |   9 +-
 test/media_device/media_device_print_test.cpp |  17 --
 test/media_device/meson.build                 |   1 -
 test/pipeline/ipu3/ipu3_pipeline_test.cpp     |   5 -
 test/v4l2_device/v4l2_device_test.cpp         |   4 -
 test/v4l2_subdevice/v4l2_subdevice_test.cpp   |  16 +-
 15 files changed, 216 insertions(+), 255 deletions(-)