{"id":658,"url":"https://patchwork.libcamera.org/api/1.1/patches/658/?format=json","web_url":"https://patchwork.libcamera.org/patch/658/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190228162913.6508-6-laurent.pinchart@ideasonboard.com>","date":"2019-02-28T16:29:08","name":"[libcamera-devel,05/10] libcamera: pipeline_handler: Store pipe and camera in CameraData","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"519b82fd45af0e9bdbbf1d9ff0c62ddf9339741d","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/658/mbox/","series":[{"id":196,"url":"https://patchwork.libcamera.org/api/1.1/series/196/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=196","date":"2019-02-28T16:29:03","name":"Rework request completion handling","version":1,"mbox":"https://patchwork.libcamera.org/series/196/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/658/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/658/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D51F0610C9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Feb 2019 17:29:26 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 389F867\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Feb 2019 17:29:26 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1551371366;\n\tbh=EuIVei7PUtsE3JHCMW6RkCvMQSdim9WFfEm+OkLaUkI=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=I28k7d44DenBdrtALsfUeFDho+8RKb/C0j4v9j31sik04hHrmMtf4nMaQdtChjwCf\n\tOPzNpIohVLfxdha5OefGUGNAHIwBSwfev/C2Xo9r6f9K7vyAKo/HbO6aeUu4t5U60v\n\tSPiEWrIMjaLAe7THX/vyFgHeQg+jx2/c4JV+FGFk=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 28 Feb 2019 18:29:08 +0200","Message-Id":"<20190228162913.6508-6-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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 05/10] libcamera: pipeline_handler: Store\n\tpipe and camera in CameraData","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Thu, 28 Feb 2019 16:29:27 -0000"},"content":"Extend the CameraData class with two member variables pipe_ and camera_\nthat store pointers to the pipeline handler and camera that the\nCameraData instance is related to. This will be used by pipeline\nhandlers to access the camera and the pipeline in member methods of\ntheir CameraData derived classes.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/pipeline_handler.h |  9 ++++-\n src/libcamera/pipeline/ipu3/ipu3.cpp     |  9 +++--\n src/libcamera/pipeline/uvcvideo.cpp      |  5 ++-\n src/libcamera/pipeline/vimc.cpp          |  5 ++-\n src/libcamera/pipeline_handler.cpp       | 49 +++++++++++++++++++++---\n 5 files changed, 63 insertions(+), 14 deletions(-)","diff":"diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h\nindex 45e1f07ffca9..bc4da5820ac4 100644\n--- a/src/libcamera/include/pipeline_handler.h\n+++ b/src/libcamera/include/pipeline_handler.h\n@@ -19,6 +19,7 @@ class Camera;\n class CameraManager;\n class DeviceEnumerator;\n class MediaDevice;\n+class PipelineHandler;\n class Request;\n class Stream;\n class StreamConfiguration;\n@@ -26,10 +27,14 @@ class StreamConfiguration;\n class CameraData\n {\n public:\n+\texplicit CameraData(PipelineHandler *pipe)\n+\t\t: pipe_(pipe)\n+\t{\n+\t}\n \tvirtual ~CameraData() {}\n \n-protected:\n-\tCameraData() {}\n+\tCamera *camera_;\n+\tPipelineHandler *pipe_;\n \n private:\n \tCameraData(const CameraData &) = delete;\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 248e921117f4..347ee657fddf 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -50,8 +50,11 @@ private:\n \tclass IPU3CameraData : public CameraData\n \t{\n \tpublic:\n-\t\tIPU3CameraData()\n-\t\t\t: cio2_(nullptr), csi2_(nullptr), sensor_(nullptr) {}\n+\t\tIPU3CameraData(PipelineHandler *pipe)\n+\t\t\t: CameraData(pipe), cio2_(nullptr), csi2_(nullptr),\n+\t\t\t  sensor_(nullptr)\n+\t\t{\n+\t\t}\n \n \t\t~IPU3CameraData()\n \t\t{\n@@ -365,7 +368,7 @@ void PipelineHandlerIPU3::registerCameras()\n \t\tif (link->setEnabled(true))\n \t\t\tcontinue;\n \n-\t\tstd::unique_ptr<IPU3CameraData> data = utils::make_unique<IPU3CameraData>();\n+\t\tstd::unique_ptr<IPU3CameraData> data = utils::make_unique<IPU3CameraData>(this);\n \n \t\tstd::string cameraName = sensor->name() + \" \" + std::to_string(id);\n \t\tstd::vector<Stream *> streams{ &data->stream_ };\ndiff --git a/src/libcamera/pipeline/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo.cpp\nindex cc513513cb34..9af4838891f4 100644\n--- a/src/libcamera/pipeline/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo.cpp\n@@ -46,7 +46,8 @@ private:\n \tclass UVCCameraData : public CameraData\n \t{\n \tpublic:\n-\t\tUVCCameraData()\n+\t\tUVCCameraData(PipelineHandler *pipe)\n+\t\t\t: CameraData(pipe)\n \t\t{\n \t\t}\n \n@@ -180,7 +181,7 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n \n \tmedia_->acquire();\n \n-\tstd::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>();\n+\tstd::unique_ptr<UVCCameraData> data = utils::make_unique<UVCCameraData>(this);\n \n \t/* Locate and open the default video node. */\n \tfor (MediaEntity *entity : media_->entities()) {\ndiff --git a/src/libcamera/pipeline/vimc.cpp b/src/libcamera/pipeline/vimc.cpp\nindex 1d01fa80f8d5..c4c1eb0dc19f 100644\n--- a/src/libcamera/pipeline/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc.cpp\n@@ -46,7 +46,8 @@ private:\n \tclass VimcCameraData : public CameraData\n \t{\n \tpublic:\n-\t\tVimcCameraData()\n+\t\tVimcCameraData(PipelineHandler *pipe)\n+\t\t\t: CameraData(pipe)\n \t\t{\n \t\t}\n \n@@ -190,7 +191,7 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)\n \n \tmedia_->acquire();\n \n-\tstd::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>();\n+\tstd::unique_ptr<VimcCameraData> data = utils::make_unique<VimcCameraData>(this);\n \n \t/* Locate and open the capture video node. */\n \tMediaEntity *entity = media_->getEntityByName(\"Raw Capture 1\");\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex c440aa8382ff..ac1acea5a318 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -11,6 +11,7 @@\n #include \"log.h\"\n #include \"media_device.h\"\n #include \"pipeline_handler.h\"\n+#include \"utils.h\"\n \n /**\n  * \\file pipeline_handler.h\n@@ -44,6 +45,35 @@ LOG_DEFINE_CATEGORY(Pipeline)\n  * with cameraData().\n  */\n \n+/**\n+ * \\fn CameraData::CameraData(PipelineHandler *pipe)\n+ * \\brief Construct a CameraData instance for the given pipeline handler\n+ * \\param[in] pipe The pipeline handler\n+ *\n+ * The reference to the pipeline handler is stored internally, the caller shall\n+ * guarantee that the pointer remains valid as long as the CameraData instance\n+ * exists.\n+ */\n+\n+/**\n+ * \\var CameraData::camera_\n+ * \\brief The camera related to this CameraData instance\n+ *\n+ * The camera_ pointer provides access to the Camera object that this instance\n+ * is related to. It is set when the Camera is registered with\n+ * PipelineHandler::registerCamera() and remains valid until the CameraData\n+ * instance is destroyed.\n+ */\n+\n+/**\n+ * \\var CameraData::pipe_\n+ * \\brief The pipeline handler related to this CameraData instance\n+ *\n+ * The pipe_ pointer provides access to the PipelineHandler object that this\n+ * instance is related to. It is set when the CameraData instance is created\n+ * and remains valid until the instance is destroyed.\n+ */\n+\n /**\n  * \\class PipelineHandler\n  * \\brief Create and manage cameras based on a set of media devices\n@@ -218,11 +248,19 @@ PipelineHandler::~PipelineHandler()\n  * \\brief Register a camera to the camera manager and pipeline handler\n  * \\param[in] camera The camera to be added\n  *\n- * This function is called by pipeline handlers to register the cameras they\n- * handle with the camera manager.\n+ * This method is called by pipeline handlers to register the cameras they\n+ * handle with the camera manager. If no CameraData has been associated with\n+ * the camera with setCameraData() by the pipeline handler, the method creates\n+ * a default CameraData instance for the \\a camera.\n  */\n void PipelineHandler::registerCamera(std::shared_ptr<Camera> camera)\n {\n+\tif (!cameraData_.count(camera.get())) {\n+\t\tstd::unique_ptr<CameraData> data = utils::make_unique<CameraData>(this);\n+\t\tsetCameraData(camera.get(), std::move(data));\n+\t}\n+\n+\tcameraData(camera.get())->camera_ = camera.get();\n \tcameras_.push_back(camera);\n \tmanager_->addCamera(std::move(camera));\n }\n@@ -313,9 +351,10 @@ CameraData *PipelineHandler::cameraData(const Camera *camera)\n  * information with \\a camera. Ownership of \\a data is transferred to\n  * the PipelineHandler.\n  *\n- * Pipeline-specific data can only be set once. Any attempt to call\n- * this method after the first one with the same camera won't change\n- * the pipeline-specific data.\n+ * Pipeline-specific data can only be set once, and shall be set before\n+ * registering the camera with registerCamera(). Any attempt to call this\n+ * method more than once for the same camera, or to call it after registering\n+ * the camera, will not change the pipeline-specific data.\n  *\n  * The data can be retrieved by pipeline handlers using the cameraData() method.\n  */\n","prefixes":["libcamera-devel","05/10"]}