From patchwork Sat Jul 18 13:23:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8857 X-Patchwork-Delegate: niklas.soderlund@ragnatech.se Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 011A4C2E68 for ; Sat, 18 Jul 2020 13:23:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AFF47607BD; Sat, 18 Jul 2020 15:23:39 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20CAC6071C for ; Sat, 18 Jul 2020 15:23:36 +0200 (CEST) X-Halon-ID: e1449c5b-c8f9-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id e1449c5b-c8f9-11ea-933e-005056917a89; Sat, 18 Jul 2020 15:23:34 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sat, 18 Jul 2020 15:23:23 +0200 Message-Id: <20200718132324.867815-9-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200718132324.867815-1-niklas.soderlund@ragnatech.se> References: <20200718132324.867815-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 8/9] libcamera: camera: Add create() that operates on CameraSensor X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To make help pipeline handlers name their cameras more uniformly add a second Camera::create() method that takes a CameraSensor instead of a name and ID as arguments. The CameraSensor is used to generate the name and ID for the camera. The new create() method is optional and pipelines may still control the name and ID themself if they wish. Signed-off-by: Niklas Söderlund --- include/libcamera/camera.h | 5 +++++ src/libcamera/camera.cpp | 20 +++++++++++++++++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 10 ++++------ .../pipeline/raspberrypi/raspberrypi.cpp | 4 +--- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 3 +-- src/libcamera/pipeline/simple/simple.cpp | 4 +--- src/libcamera/pipeline/vimc/vimc.cpp | 3 +-- 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 132225a37dcd1ef4..aa283bcb4713506b 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -19,6 +19,7 @@ namespace libcamera { +class CameraSensor; class FrameBuffer; class FrameBufferAllocator; class PipelineHandler; @@ -74,6 +75,10 @@ public: const std::string &name, const std::set &streams); + static std::shared_ptr create(PipelineHandler *pipe, + const CameraSensor *sensor, + const std::set &streams); + Camera(const Camera &) = delete; Camera &operator=(const Camera &) = delete; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 638d15e0da5e1ca9..91498f23092cec39 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -14,7 +14,9 @@ #include #include +#include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/log.h" +#include "libcamera/internal/media_object.h" #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/utils.h" @@ -477,6 +479,24 @@ std::shared_ptr Camera::create(PipelineHandler *pipe, return std::shared_ptr(camera, Deleter()); } +/** + * \brief Create a camera instance + * \param[in] pipe The pipeline handler responsible for the camera device + * \param[in] sensor The sensor of the camera device + * \param[in] streams Array of streams the camera provides + * + * Create a camera with name and ID from \a sensor. + * + * \return A shared pointer to the newly created camera object + */ +std::shared_ptr Camera::create(PipelineHandler *pipe, + const CameraSensor *sensor, + const std::set &streams) +{ + return Camera::create(pipe, sensor->id(), sensor->entity()->name(), + streams); +} + /** * \brief Retrieve the name of the camera * \context This function is \threadsafe. diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 09bab78b999b8b52..9d01c6b714e880b9 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -813,19 +813,17 @@ int PipelineHandlerIPU3::registerCameras() &IPU3CameraData::imguOutputBufferReady); /* Create and register the Camera instance. */ - std::string cameraName = cio2->sensor()->entity()->name(); std::shared_ptr camera = Camera::create(this, - cio2->sensor()->id(), - cameraName, + cio2->sensor(), streams); - registerCamera(std::move(camera), std::move(data)); - LOG(IPU3, Info) << "Registered Camera[" << numCameras << "] \"" - << cameraName << "\"" + << camera->name() << "\"" << " connected to CSI-2 receiver " << id; + registerCamera(std::move(camera), std::move(data)); + numCameras++; } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index bead2a6220e207f5..de0fe0fb4e09d82b 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -973,9 +973,7 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) streams.insert(&data->isp_[Isp::Stats]); /* Create and register the camera. */ - std::shared_ptr camera = Camera::create(this, - data->sensor_->id(), - data->sensor_->entity()->name(), + std::shared_ptr camera = Camera::create(this, data->sensor_, streams); registerCamera(std::move(camera), std::move(data)); diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 6f3699fe1a53eeaf..663e45b109aae9eb 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -971,8 +971,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) std::set streams{ &data->stream_ }; std::shared_ptr camera = - Camera::create(this, data->sensor_->id(), sensor->name(), - streams); + Camera::create(this, data->sensor_, streams); registerCamera(std::move(camera), std::move(data)); return 0; diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 3c27cc28f672e020..cc8e14d511799dab 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -800,9 +800,7 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) continue; std::shared_ptr camera = - Camera::create(this, data->sensor_->id(), - data->sensor_->entity()->name(), - data->streams()); + Camera::create(this, data->sensor_.get(), data->streams()); registerCamera(std::move(camera), std::move(data)); } diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 6560b632ae55b304..225c1bfb453e17bb 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -433,8 +433,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) /* Create and register the camera. */ std::set streams{ &data->stream_ }; - std::shared_ptr camera = Camera::create(this, data->sensor_->id(), - data->sensor_->entity()->name(), + std::shared_ptr camera = Camera::create(this, data->sensor_, streams); registerCamera(std::move(camera), std::move(data));