From patchwork Thu Feb 28 16:29:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 659 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 29A99610C5 for ; Thu, 28 Feb 2019 17:29:27 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 95CBB988 for ; Thu, 28 Feb 2019 17:29:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551371366; bh=9tcO8ejHe9LiecA5bcaLEI7h/BG/tJna7/U9DP5oIUg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=I4WF+UFaYwcBooVwQQUQHfIlFadIiNhLwbx5FJALnn9oZ0rOeJXOXPwdh3QPNiXgp 2vXMkkPWYx59tzx6qOwsg0Hk7RtW22qxbhKvl3uS+2QeHuGaqQSDHWIuzlN+4g3hQ/ cee3BwL54mhMYItQ91QN3A5+h/XCSQdd8mRx9B3k= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Feb 2019 18:29:09 +0200 Message-Id: <20190228162913.6508-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> References: <20190228162913.6508-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/10] libcamera: pipeline_handler: Make pipeline-specific data mandatory X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2019 16:29:27 -0000 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 Reviewed-by: Niklas Söderlund --- src/libcamera/include/pipeline_handler.h | 4 +- src/libcamera/pipeline/ipu3/ipu3.cpp | 3 +- src/libcamera/pipeline/uvcvideo.cpp | 4 +- src/libcamera/pipeline/vimc.cpp | 4 +- src/libcamera/pipeline_handler.cpp | 56 +++++------------------- 5 files changed, 15 insertions(+), 56 deletions(-) diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index bc4da5820ac4..b2b9c94cebdc 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -63,11 +63,11 @@ public: virtual int queueRequest(Camera *camera, Request *request) = 0; protected: - void registerCamera(std::shared_ptr camera); + void registerCamera(std::shared_ptr camera, + std::unique_ptr data); void hotplugMediaDevice(MediaDevice *media); CameraData *cameraData(const Camera *camera); - void setCameraData(const Camera *camera, std::unique_ptr data); CameraManager *manager_; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 347ee657fddf..776b7f07f78d 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -406,8 +406,7 @@ void PipelineHandlerIPU3::registerCameras() if (ret) continue; - setCameraData(camera.get(), std::move(data)); - registerCamera(std::move(camera)); + registerCamera(std::move(camera), std::move(data)); LOG(IPU3, Info) << "Registered Camera[" << numCameras << "] \"" diff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp index 9af4838891f4..f121d3c5633e 100644 --- a/src/libcamera/pipeline/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo.cpp @@ -201,9 +201,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) /* Create and register the camera. */ std::vector streams{ &data->stream_ }; std::shared_ptr camera = Camera::create(this, media_->model(), streams); - - setCameraData(camera.get(), std::move(data)); - registerCamera(std::move(camera)); + registerCamera(std::move(camera), std::move(data)); /* Enable hot-unplug notifications. */ hotplugMediaDevice(media_.get()); diff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp index c4c1eb0dc19f..6d022c37eb9f 100644 --- a/src/libcamera/pipeline/vimc.cpp +++ b/src/libcamera/pipeline/vimc.cpp @@ -209,9 +209,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) std::vector streams{ &data->stream_ }; std::shared_ptr camera = Camera::create(this, "VIMC Sensor B", streams); - - setCameraData(camera.get(), std::move(data)); - registerCamera(std::move(camera)); + registerCamera(std::move(camera), std::move(data)); return true; } diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index ac1acea5a318..54f237942a48 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -247,20 +247,18 @@ PipelineHandler::~PipelineHandler() /** * \brief Register a camera to the camera manager and pipeline handler * \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 - * 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. + * handle with the camera manager. It associates the pipeline-specific \a data + * with the camera, for later retrieval with cameraData(). Ownership of \a data + * is transferred to the PipelineHandler. */ -void PipelineHandler::registerCamera(std::shared_ptr camera) +void PipelineHandler::registerCamera(std::shared_ptr camera, + std::unique_ptr data) { - if (!cameraData_.count(camera.get())) { - std::unique_ptr data = utils::make_unique(this); - setCameraData(camera.get(), std::move(data)); - } - - cameraData(camera.get())->camera_ = camera.get(); + data->camera_ = camera.get(); + cameraData_[camera.get()] = std::move(data); cameras_.push_back(camera); manager_->addCamera(std::move(camera)); } @@ -325,51 +323,17 @@ void PipelineHandler::disconnect() * \brief Retrieve the pipeline-specific data associated with a Camera * \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 * valid until the pipeline handler is destroyed. It shall not be deleted * manually by the caller. */ CameraData *PipelineHandler::cameraData(const Camera *camera) { - if (!cameraData_.count(camera)) { - LOG(Pipeline, Error) - << "Cannot get data associated with camera " - << camera->name(); - return nullptr; - } - + ASSERT(cameraData_.count(camera)); 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 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_ * \brief The Camera manager associated with the pipeline handler