summaryrefslogtreecommitdiff
path: root/src/libcamera/pipeline_handler.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-04-14 01:48:57 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-05-17 20:35:27 +0200
commitd6a88607479937a9941f1ea2c82a7e5c66b20647 (patch)
treeeff0e2193ef12e2b1e058943fb10d8a171c70e56 /src/libcamera/pipeline_handler.cpp
parent2e22ee4310d47bc76c9db0da1b6b48f12f032743 (diff)
libcamera: pipeline_handler: Keep track of MediaDevice
Instead of requiring each pipeline handle implementation to keep track of calling release() on its media devices upon deletion, keep track of them in the base class. Add a helper that pipeline handlers shall use to acquire a media device instead of directly interacting with the DeviceEnumerator. This also means that pipeline handler implementations do no need to keep a shared_ptr<> reference to the media devices they store locally as the PipelineHandler base class will keep a shared_ptr<> reference to all media devices consumed for the entire lifetime of the pipeline handler implementation. Centrally keeping track of media devices will also be beneficial to implement exclusive access to pipelines across processes. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/pipeline_handler.cpp')
-rw-r--r--src/libcamera/pipeline_handler.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index 4ecd6c49..c92ee782 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -11,6 +11,7 @@
#include <libcamera/camera.h>
#include <libcamera/camera_manager.h>
+#include "device_enumerator.h"
#include "log.h"
#include "media_device.h"
#include "utils.h"
@@ -116,6 +117,8 @@ PipelineHandler::PipelineHandler(CameraManager *manager)
PipelineHandler::~PipelineHandler()
{
+ for (std::shared_ptr<MediaDevice> media : mediaDevices_)
+ media->release();
};
/**
@@ -150,6 +153,35 @@ PipelineHandler::~PipelineHandler()
*/
/**
+ * \brief Search and acquire a MediDevice matching a device pattern
+ * \param[in] enumerator Enumerator containing all media devices in the system
+ * \param[in] dm Device match pattern
+ *
+ * Search the device \a enumerator for an available media device matching the
+ * device match pattern \a dm. Matching media device that have previously been
+ * acquired by MediaDevice::acquire() are not considered. If a match is found,
+ * the media device is acquired and returned. The caller shall not release the
+ * device explicitly, it will be automatically released when the pipeline
+ * handler is destroyed.
+ *
+ * \return A pointer to the matching MediaDevice, or nullptr if no match is found
+ */
+MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,
+ const DeviceMatch &dm)
+{
+ std::shared_ptr<MediaDevice> media = enumerator->search(dm);
+ if (!media)
+ return nullptr;
+
+ if (!media->acquire())
+ return nullptr;
+
+ mediaDevices_.push_back(media);
+
+ return media.get();
+}
+
+/**
* \fn PipelineHandler::streamConfiguration()
* \brief Retrieve a group of stream configurations for a specified camera
* \param[in] camera The camera to fetch default configuration from