diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-08-30 01:20:10 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-08-10 20:33:28 +0300 |
commit | dfc6d711c9f7f0a9868afa5158aa2089163bded3 (patch) | |
tree | f0e6e1825fd93a7b52033df184efb50e097e5469 /include | |
parent | 434edb7b4480a34521aa8741dea02615e9dd714d (diff) |
libcamera: Allow concurrent use of cameras from same pipeline handler
libcamera implements a pipeline handler locking mechanism based on
advisory locks on media devices, to prevent concurrent access to cameras
from the same pipeline handler from different processes (this only works
between multiple libcamera instances, as other processes won't use
advisory locks on media devices).
A side effect of the implementation prevents multiple cameras created by
the same pipeline handler from being used concurrently. Fix this by
turning the PipelineHandler lock() and unlock() functions into acquire()
and release(), with a use count to replace the boolean lock flag. The
Camera class is updated accordingly.
As a consequence of this change, the IPU3 pipeline handler will fail to
operate properly when the cameras it exposes are operated concurrently.
The android.hardware.camera2.cts.MultiViewTest#testDualCameraPreview
test fails as a result. This should be fixed in the IPU3 pipeline
handler to implement mutual exclusion between cameras.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libcamera/internal/camera.h | 1 | ||||
-rw-r--r-- | include/libcamera/internal/pipeline_handler.h | 8 |
2 files changed, 6 insertions, 3 deletions
diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h index 597426a6..38dd94ff 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -50,6 +50,7 @@ private: CameraRunning, }; + bool isAcquired() const; bool isRunning() const; int isAccessAllowed(State state, bool allowDisconnected = false, const char *from = __builtin_FUNCTION()) const; diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index c3e4c258..20f1cbb0 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -45,8 +45,8 @@ public: MediaDevice *acquireMediaDevice(DeviceEnumerator *enumerator, const DeviceMatch &dm); - bool lock(); - void unlock(); + bool acquire(); + void release(); virtual CameraConfiguration *generateConfiguration(Camera *camera, const StreamRoles &roles) = 0; @@ -77,6 +77,8 @@ protected: CameraManager *manager_; private: + void unlockMediaDevices(); + void mediaDeviceDisconnected(MediaDevice *media); virtual void disconnect(); @@ -91,7 +93,7 @@ private: const char *name_; Mutex lock_; - bool lockOwner_ LIBCAMERA_TSA_GUARDED_BY(lock_); /* *Not* ownership of lock_ */ + unsigned int useCount_ LIBCAMERA_TSA_GUARDED_BY(lock_); friend class PipelineHandlerFactory; }; |