libcamera: pipeline_handler: Store pipe and camera in CameraData

Extend the CameraData class with two member variables pipe_ and camera_
that store pointers to the pipeline handler and camera that the
CameraData instance is related to. This will be used by pipeline
handlers to access the camera and the pipeline in member methods of
their CameraData derived classes.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Laurent Pinchart 2019-02-28 12:29:13 +02:00
parent 40439a933f
commit 61a62ddbd8
5 changed files with 63 additions and 15 deletions

View file

@ -19,6 +19,7 @@ class Camera;
class CameraManager; class CameraManager;
class DeviceEnumerator; class DeviceEnumerator;
class MediaDevice; class MediaDevice;
class PipelineHandler;
class Request; class Request;
class Stream; class Stream;
class StreamConfiguration; class StreamConfiguration;
@ -26,10 +27,14 @@ class StreamConfiguration;
class CameraData class CameraData
{ {
public: public:
explicit CameraData(PipelineHandler *pipe)
: pipe_(pipe)
{
}
virtual ~CameraData() {} virtual ~CameraData() {}
protected: Camera *camera_;
CameraData() {} PipelineHandler *pipe_;
private: private:
CameraData(const CameraData &) = delete; CameraData(const CameraData &) = delete;

View file

@ -50,8 +50,11 @@ private:
class IPU3CameraData : public CameraData class IPU3CameraData : public CameraData
{ {
public: public:
IPU3CameraData() IPU3CameraData(PipelineHandler *pipe)
: cio2_(nullptr), csi2_(nullptr), sensor_(nullptr) {} : CameraData(pipe), cio2_(nullptr), csi2_(nullptr),
sensor_(nullptr)
{
}
~IPU3CameraData() ~IPU3CameraData()
{ {
@ -365,7 +368,7 @@ void PipelineHandlerIPU3::registerCameras()
if (link->setEnabled(true)) if (link->setEnabled(true))
continue; continue;
std::unique_ptr<IPU3CameraData> data = utils::make_unique<IPU3CameraData>(); std::unique_ptr<IPU3CameraData> data = utils::make_unique<IPU3CameraData>(this);
std::string cameraName = sensor->name() + " " + std::to_string(id); std::string cameraName = sensor->name() + " " + std::to_string(id);
std::set<Stream *> streams{ &data->stream_ }; std::set<Stream *> streams{ &data->stream_ };

View file

@ -46,8 +46,8 @@ private:
class UVCCameraData : public CameraData class UVCCameraData : public CameraData
{ {
public: public:
UVCCameraData() UVCCameraData(PipelineHandler *pipe)
: video_(nullptr) : CameraData(pipe), video_(nullptr)
{ {
} }
@ -181,7 +181,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
media_->acquire(); media_->acquire();
std::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(); std::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(this);
/* Locate and open the default video node. */ /* Locate and open the default video node. */
for (MediaEntity *entity : media_->entities()) { for (MediaEntity *entity : media_->entities()) {

View file

@ -46,7 +46,8 @@ private:
class VimcCameraData : public CameraData class VimcCameraData : public CameraData
{ {
public: public:
VimcCameraData() VimcCameraData(PipelineHandler *pipe)
: CameraData(pipe)
{ {
} }
@ -190,7 +191,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
media_->acquire(); media_->acquire();
std::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(); std::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);
/* Locate and open the capture video node. */ /* Locate and open the capture video node. */
data->video_ = new V4L2Device(media_->getEntityByName("Raw Capture 1")); data->video_ = new V4L2Device(media_->getEntityByName("Raw Capture 1"));

View file

@ -11,6 +11,7 @@
#include "log.h" #include "log.h"
#include "media_device.h" #include "media_device.h"
#include "pipeline_handler.h" #include "pipeline_handler.h"
#include "utils.h"
/** /**
* \file pipeline_handler.h * \file pipeline_handler.h
@ -44,6 +45,35 @@ LOG_DEFINE_CATEGORY(Pipeline)
* with cameraData(). * with cameraData().
*/ */
/**
* \fn CameraData::CameraData(PipelineHandler *pipe)
* \brief Construct a CameraData instance for the given pipeline handler
* \param[in] pipe The pipeline handler
*
* The reference to the pipeline handler is stored internally, the caller shall
* guarantee that the pointer remains valid as long as the CameraData instance
* exists.
*/
/**
* \var CameraData::camera_
* \brief The camera related to this CameraData instance
*
* The camera_ pointer provides access to the Camera object that this instance
* is related to. It is set when the Camera is registered with
* PipelineHandler::registerCamera() and remains valid until the CameraData
* instance is destroyed.
*/
/**
* \var CameraData::pipe_
* \brief The pipeline handler related to this CameraData instance
*
* The pipe_ pointer provides access to the PipelineHandler object that this
* instance is related to. It is set when the CameraData instance is created
* and remains valid until the instance is destroyed.
*/
/** /**
* \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
@ -218,11 +248,19 @@ PipelineHandler::~PipelineHandler()
* \brief Register a camera to the camera manager and pipeline handler * \brief Register a camera to the camera manager and pipeline handler
* \param[in] camera The camera to be added * \param[in] camera The camera to be added
* *
* This function is called by pipeline handlers to register the cameras they * This method is called by pipeline handlers to register the cameras they
* handle with the camera manager. * handle with the camera manager. If no CameraData has been associated with
* the camera with setCameraData() by the pipeline handler, the method creates
* a default CameraData instance for the \a camera.
*/ */
void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera) void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera)
{ {
if (!cameraData_.count(camera.get())) {
std::unique_ptr<CameraData> data = utils::make_unique<CameraData>(this);
setCameraData(camera.get(), std::move(data));
}
cameraData(camera.get())->camera_ = camera.get();
cameras_.push_back(camera); cameras_.push_back(camera);
manager_->addCamera(std::move(camera)); manager_->addCamera(std::move(camera));
} }
@ -313,9 +351,10 @@ CameraData *PipelineHandler::cameraData(const Camera *camera)
* information with \a camera. Ownership of \a data is transferred to * information with \a camera. Ownership of \a data is transferred to
* the PipelineHandler. * the PipelineHandler.
* *
* Pipeline-specific data can only be set once. Any attempt to call * Pipeline-specific data can only be set once, and shall be set before
* this method after the first one with the same camera won't change * registering the camera with registerCamera(). Any attempt to call this
* the pipeline-specific data. * method more than once for the same camera, or to call it after registering
* the camera, will not change the pipeline-specific data.
* *
* The data can be retrieved by pipeline handlers using the cameraData() method. * The data can be retrieved by pipeline handlers using the cameraData() method.
*/ */