libcamera: pipeline_handler: Make pipeline-specific data mandatory

Mandate creationg of pipeline-specific data by pipeline handlers. This
allows simplifying the API by passing the pipeline-specific data to the
registerCamera() method and removing the separate setCameraData()
method.

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 13:15:09 +02:00
parent 61a62ddbd8
commit b581b9576a
5 changed files with 15 additions and 56 deletions

View file

@ -63,11 +63,11 @@ public:
virtual int queueRequest(Camera *camera, Request *request) = 0; virtual int queueRequest(Camera *camera, Request *request) = 0;
protected: protected:
void registerCamera(std::shared_ptr<Camera> camera); void registerCamera(std::shared_ptr<Camera> camera,
std::unique_ptr<CameraData> data);
void hotplugMediaDevice(MediaDevice *media); void hotplugMediaDevice(MediaDevice *media);
CameraData *cameraData(const Camera *camera); CameraData *cameraData(const Camera *camera);
void setCameraData(const Camera *camera, std::unique_ptr<CameraData> data);
CameraManager *manager_; CameraManager *manager_;

View file

@ -406,8 +406,7 @@ void PipelineHandlerIPU3::registerCameras()
if (ret) if (ret)
continue; continue;
setCameraData(camera.get(), std::move(data)); registerCamera(std::move(camera), std::move(data));
registerCamera(std::move(camera));
LOG(IPU3, Info) LOG(IPU3, Info)
<< "Registered Camera[" << numCameras << "] \"" << "Registered Camera[" << numCameras << "] \""

View file

@ -202,9 +202,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
/* Create and register the camera. */ /* Create and register the camera. */
std::set<Stream *> streams{ &data->stream_ }; std::set<Stream *> streams{ &data->stream_ };
std::shared_ptr<Camera> camera = Camera::create(this, media_->model(), streams); std::shared_ptr<Camera> camera = Camera::create(this, media_->model(), streams);
registerCamera(std::move(camera), std::move(data));
setCameraData(camera.get(), std::move(data));
registerCamera(std::move(camera));
/* Enable hot-unplug notifications. */ /* Enable hot-unplug notifications. */
hotplugMediaDevice(media_.get()); hotplugMediaDevice(media_.get());

View file

@ -202,9 +202,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
std::set<Stream *> streams{ &data->stream_ }; std::set<Stream *> streams{ &data->stream_ };
std::shared_ptr<Camera> camera = Camera::create(this, "VIMC Sensor B", std::shared_ptr<Camera> camera = Camera::create(this, "VIMC Sensor B",
streams); streams);
registerCamera(std::move(camera), std::move(data));
setCameraData(camera.get(), std::move(data));
registerCamera(std::move(camera));
return true; return true;
} }

View file

@ -247,20 +247,18 @@ 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
* \param[in] data Pipeline-specific data for the camera
* *
* This method 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. If no CameraData has been associated with * handle with the camera manager. It associates the pipeline-specific \a data
* the camera with setCameraData() by the pipeline handler, the method creates * with the camera, for later retrieval with cameraData(). Ownership of \a data
* a default CameraData instance for the \a camera. * is transferred to the PipelineHandler.
*/ */
void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera) void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera,
std::unique_ptr<CameraData> data)
{ {
if (!cameraData_.count(camera.get())) { data->camera_ = camera.get();
std::unique_ptr<CameraData> data = utils::make_unique<CameraData>(this); cameraData_[camera.get()] = std::move(data);
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));
} }
@ -325,51 +323,17 @@ void PipelineHandler::disconnect()
* \brief Retrieve the pipeline-specific data associated with a Camera * \brief Retrieve the pipeline-specific data associated with a Camera
* \param camera The camera whose data to retrieve * \param camera The camera whose data to retrieve
* *
* \return A pointer to the pipeline-specific data set with setCameraData(). * \return A pointer to the pipeline-specific data passed to registerCamera().
* The returned pointer is a borrowed reference and is guaranteed to remain * The returned pointer is a borrowed reference and is guaranteed to remain
* valid until the pipeline handler is destroyed. It shall not be deleted * valid until the pipeline handler is destroyed. It shall not be deleted
* manually by the caller. * manually by the caller.
*/ */
CameraData *PipelineHandler::cameraData(const Camera *camera) CameraData *PipelineHandler::cameraData(const Camera *camera)
{ {
if (!cameraData_.count(camera)) { ASSERT(cameraData_.count(camera));
LOG(Pipeline, Error)
<< "Cannot get data associated with camera "
<< camera->name();
return nullptr;
}
return cameraData_[camera].get(); return cameraData_[camera].get();
} }
/**
* \brief Set pipeline-specific data for 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. Ownership of \a data is transferred to
* the PipelineHandler.
*
* Pipeline-specific data can only be set once, and shall be set before
* registering the camera with registerCamera(). Any attempt to call this
* 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.
*/
void PipelineHandler::setCameraData(const Camera *camera,
std::unique_ptr<CameraData> data)
{
if (cameraData_.find(camera) != cameraData_.end()) {
LOG(Pipeline, Error)
<< "Replacing data associated with a camera is forbidden";
return;
}
cameraData_[camera] = std::move(data);
}
/** /**
* \var PipelineHandler::manager_ * \var PipelineHandler::manager_
* \brief The Camera manager associated with the pipeline handler * \brief The Camera manager associated with the pipeline handler