libcamera: pipeline_handler: Add CameraData
Add class definition and methods to associate a Camera with specific data in the pipeline_handler base class. Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
987bd370b0
commit
a6c8f58d96
2 changed files with 88 additions and 1 deletions
|
@ -18,6 +18,20 @@ class CameraManager;
|
||||||
class DeviceEnumerator;
|
class DeviceEnumerator;
|
||||||
class MediaDevice;
|
class MediaDevice;
|
||||||
|
|
||||||
|
class Camera;
|
||||||
|
class CameraData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~CameraData() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CameraData() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
CameraData(const CameraData &) = delete;
|
||||||
|
void operator=(const CameraData &) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
class PipelineHandler : public std::enable_shared_from_this<PipelineHandler>
|
class PipelineHandler : public std::enable_shared_from_this<PipelineHandler>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -32,11 +46,15 @@ protected:
|
||||||
void registerCamera(std::shared_ptr<Camera> camera);
|
void registerCamera(std::shared_ptr<Camera> camera);
|
||||||
void hotplugMediaDevice(MediaDevice *media);
|
void hotplugMediaDevice(MediaDevice *media);
|
||||||
|
|
||||||
|
CameraData *cameraData(const Camera *camera);
|
||||||
|
void setCameraData(const Camera *camera, std::unique_ptr<CameraData> data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void disconnect();
|
virtual void disconnect();
|
||||||
void mediaDeviceDisconnected(MediaDevice *media);
|
void mediaDeviceDisconnected(MediaDevice *media);
|
||||||
|
|
||||||
std::vector<std::weak_ptr<Camera>> cameras_;
|
std::vector<std::weak_ptr<Camera>> cameras_;
|
||||||
|
std::map<const Camera *, std::unique_ptr<CameraData>> cameraData_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PipelineHandlerFactory
|
class PipelineHandlerFactory
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include "media_device.h"
|
#include "media_device.h"
|
||||||
#include "pipeline_handler.h"
|
#include "pipeline_handler.h"
|
||||||
|
|
||||||
|
#include <libcamera/camera.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \file pipeline_handler.h
|
* \file pipeline_handler.h
|
||||||
* \brief Create pipelines and cameras from a set of media devices
|
* \brief Create pipelines and cameras from a set of media devices
|
||||||
|
@ -30,6 +32,20 @@ namespace libcamera {
|
||||||
|
|
||||||
LOG_DEFINE_CATEGORY(Pipeline)
|
LOG_DEFINE_CATEGORY(Pipeline)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class CameraData
|
||||||
|
* \brief Base class for platform-specific data associated with a camera
|
||||||
|
*
|
||||||
|
* The CameraData base abstract class represents platform specific-data
|
||||||
|
* a pipeline handler might want to associate with a Camera to access them
|
||||||
|
* at a later time.
|
||||||
|
*
|
||||||
|
* Pipeline handlers are expected to extend this base class with platform
|
||||||
|
* specific implementation, associate instances of the derived classes
|
||||||
|
* using the setCameraData() method, and access them at a later time
|
||||||
|
* with cameraData().
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class PipelineHandler
|
* \class PipelineHandler
|
||||||
* \brief Create and manage cameras based on a set of media devices
|
* \brief Create and manage cameras based on a set of media devices
|
||||||
|
@ -57,9 +73,16 @@ PipelineHandler::PipelineHandler(CameraManager *manager)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Delete the pipeline handler
|
||||||
|
*
|
||||||
|
* Release the cameraData_ map, causing all data there referenced to be
|
||||||
|
* deleted, as they are stored as unique_ptr<CameraData>
|
||||||
|
*/
|
||||||
PipelineHandler::~PipelineHandler()
|
PipelineHandler::~PipelineHandler()
|
||||||
{
|
{
|
||||||
}
|
cameraData_.clear();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \fn PipelineHandler::match(DeviceEnumerator *enumerator)
|
* \fn PipelineHandler::match(DeviceEnumerator *enumerator)
|
||||||
|
@ -168,6 +191,52 @@ void PipelineHandler::mediaDeviceDisconnected(MediaDevice *media)
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retrieve the pipeline-specific data associated with a Camera
|
||||||
|
* \param camera The camera data is associate with
|
||||||
|
*
|
||||||
|
* \return A pointer to the pipeline-specific data set with setCameraData().
|
||||||
|
* The returned pointer lifetime is associated with the one of the pipeline
|
||||||
|
* handler, and caller of this function shall never release it manually.
|
||||||
|
*/
|
||||||
|
CameraData *PipelineHandler::cameraData(const Camera *camera)
|
||||||
|
{
|
||||||
|
if (!cameraData_.count(camera)) {
|
||||||
|
LOG(Pipeline, Error)
|
||||||
|
<< "Cannot get data associated with camera "
|
||||||
|
<< camera->name();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cameraData_[camera].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set pipeline-specific data in the camera
|
||||||
|
* \param camera The camera to associate data to
|
||||||
|
* \param data The pipeline-specific data
|
||||||
|
*
|
||||||
|
* This method allows pipeline handlers to associate pipeline-specific
|
||||||
|
* information with \a camera. The \a data lifetime gets associated with
|
||||||
|
* the pipeline handler one, and gets released at deletion time.
|
||||||
|
*
|
||||||
|
* If pipeline-specific data has already been associated with the camera by a
|
||||||
|
* previous call to this method, is it replaced by \a data and the previous data
|
||||||
|
* are deleted, rendering all references to them invalid.
|
||||||
|
*
|
||||||
|
* The data can be retrieved by pipeline handlers using the cameraData() method.
|
||||||
|
*/
|
||||||
|
void PipelineHandler::setCameraData(const Camera *camera,
|
||||||
|
std::unique_ptr<CameraData> data)
|
||||||
|
{
|
||||||
|
if (cameraData_.count(camera))
|
||||||
|
LOG(Pipeline, Debug)
|
||||||
|
<< "Replacing data associated with "
|
||||||
|
<< camera->name();
|
||||||
|
|
||||||
|
cameraData_[camera] = std::move(data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class PipelineHandlerFactory
|
* \class PipelineHandlerFactory
|
||||||
* \brief Registration of PipelineHandler classes and creation of instances
|
* \brief Registration of PipelineHandler classes and creation of instances
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue