[{"id":31448,"web_url":"https://patchwork.libcamera.org/comment/31448/","msgid":"<53fdd264-4c83-464c-abbf-a4a9cdcedc6c@ideasonboard.com>","date":"2024-09-27T14:56:57","subject":"Re: [PATCH 4/4] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Kieran,\n\nI reviewed this first, since it helps better understand 3/4. Just a few \ncomments, otherwise looks good to me.\n\nOn 16/09/24 7:32 pm, Kieran Bingham wrote:\n> Use the new MediaPipeline to manage and identify all sensors connected\n> to complex pipelines that can connect to the CSI2 receiver before the\n> ISP.\n>\n> This can include chained multiplexors that supply multiple cameras, so\n\ns/multiplexors/multiplexers/\n> make use of the MediaDevice::locateEntities to search for all cameras\n> and construct a pipeline for each.\n>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>   src/libcamera/pipeline/rkisp1/rkisp1.cpp | 65 ++++++++++++------------\n>   1 file changed, 32 insertions(+), 33 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 2fee84e56d4d..914f5181b51d 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -37,6 +37,7 @@\n>   #include \"libcamera/internal/framebuffer.h\"\n>   #include \"libcamera/internal/ipa_manager.h\"\n>   #include \"libcamera/internal/media_device.h\"\n> +#include \"libcamera/internal/media_pipeline.h\"\n>   #include \"libcamera/internal/pipeline_handler.h\"\n>   #include \"libcamera/internal/v4l2_subdevice.h\"\n>   #include \"libcamera/internal/v4l2_videodevice.h\"\n> @@ -108,6 +109,11 @@ public:\n>   \n>   \tstd::unique_ptr<ipa::rkisp1::IPAProxyRkISP1> ipa_;\n>   \n> +\t/*\n> +\t * All entities in the pipeline, from the camera sensor to the RKISP1.\n\ns/RKISP1/RkISP1\n> +\t */\n> +\tMediaPipeline pipe_;\n> +\n>   private:\n>   \tvoid paramFilled(unsigned int frame, unsigned int bytesused);\n>   \tvoid setSensorControls(unsigned int frame,\n> @@ -171,8 +177,7 @@ private:\n>   \tfriend RkISP1CameraData;\n>   \tfriend RkISP1Frames;\n>   \n> -\tint initLinks(Camera *camera, const CameraSensor *sensor,\n> -\t\t      const RkISP1CameraConfiguration &config);\n> +\tint initLinks(Camera *camera, const RkISP1CameraConfiguration &config);\n>   \tint createCamera(MediaEntity *sensor);\n>   \tvoid tryCompleteRequest(RkISP1FrameInfo *info);\n>   \tvoid bufferReady(FrameBuffer *buffer);\n> @@ -712,7 +717,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>   \tCameraSensor *sensor = data->sensor_.get();\n>   \tint ret;\n>   \n> -\tret = initLinks(camera, sensor, *config);\n> +\tret = initLinks(camera, *config);\n>   \tif (ret)\n>   \t\treturn ret;\n>   \n> @@ -729,12 +734,12 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>   \n>   \tLOG(RkISP1, Debug) << \"Sensor configured with \" << format;\n>   \n> -\tif (csi_) {\n> -\t\tret = csi_->setFormat(0, &format);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n> -\t}\n> +\t/* Propagate format through the internal media pipeline up to the ISP */\n> +\tret = data->pipe_.configure(sensor, &format);\n> +\tif (ret < 0)\n> +\t\treturn ret;\n>   \n> +\tLOG(RkISP1, Debug) << \"Configuring ISP with : \" << format;\n>   \tret = isp_->setFormat(0, &format);\n>   \tif (ret < 0)\n>   \t\treturn ret;\n> @@ -1035,7 +1040,6 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request)\n>    */\n>   \n>   int PipelineHandlerRkISP1::initLinks(Camera *camera,\n> -\t\t\t\t     const CameraSensor *sensor,\n>   \t\t\t\t     const RkISP1CameraConfiguration &config)\n>   {\n>   \tRkISP1CameraData *data = cameraData(camera);\n> @@ -1046,31 +1050,16 @@ int PipelineHandlerRkISP1::initLinks(Camera *camera,\n>   \t\treturn ret;\n>   \n>   \t/*\n> -\t * Configure the sensor links: enable the link corresponding to this\n> -\t * camera.\n> +\t * Configure the sensor links: enable the links corresponding to this\n> +\t * pipeline all the way up to the ISP, through any connected CSI receiver.\n>   \t */\n> -\tfor (MediaLink *link : ispSink_->links()) {\n> -\t\tif (link->source()->entity() != sensor->entity())\n> -\t\t\tcontinue;\n> -\n> -\t\tLOG(RkISP1, Debug)\n> -\t\t\t<< \"Enabling link from sensor '\"\n> -\t\t\t<< link->source()->entity()->name()\n> -\t\t\t<< \"' to ISP\";\n> -\n> -\t\tret = link->setEnabled(true);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n> -\t}\n> -\n> -\tif (csi_) {\n> -\t\tMediaLink *link = isp_->entity()->getPadByIndex(0)->links().at(0);\n> -\n> -\t\tret = link->setEnabled(true);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n> +\tret = data->pipe_.initLinks();\n> +\tif (ret) {\n> +\t\tLOG(RkISP1, Error) << \"Failed to set up pipe links\";\n> +\t\treturn ret;\n>   \t}\n>   \n> +\t/* Configure the paths after the ISP */\n>   \tfor (const StreamConfiguration &cfg : config) {\n>   \t\tif (cfg.stream() == &data->mainPathStream_)\n>   \t\t\tret = data->mainPath_->setEnabled(true);\n> @@ -1094,6 +1083,13 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n>   \t\tstd::make_unique<RkISP1CameraData>(this, &mainPath_,\n>   \t\t\t\t\t\t   hasSelfPath_ ? &selfPath_ : nullptr);\n>   \n> +\t/* Identify the pipeline path between the sensor and the rkisp1_isp */\n> +\tret = data->pipe_.init(sensor, \"rkisp1_isp\");\n> +\tif (ret) {\n> +\t\tLOG(RkISP1, Error) << \"Failed to identify path from sensor to sink\";\n\ns/sink/rkisp1_isp possibly, for clarity?\n\nRest looks good.\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> +\t\treturn ret;\n> +\t}\n> +\n>   \tdata->sensor_ = std::make_unique<CameraSensor>(sensor);\n>   \tret = data->sensor_->init();\n>   \tif (ret)\n> @@ -1129,6 +1125,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n>   \tconst std::string &id = data->sensor_->id();\n>   \tstd::shared_ptr<Camera> camera =\n>   \t\tCamera::create(std::move(data), id, streams);\n> +\n>   \tregisterCamera(std::move(camera));\n>   \n>   \treturn 0;\n> @@ -1205,8 +1202,10 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator)\n>   \t * camera instance for each of them.\n>   \t */\n>   \tbool registered = false;\n> -\tfor (MediaLink *link : ispSink_->links()) {\n> -\t\tif (!createCamera(link->source()->entity()))\n> +\n> +\tfor (MediaEntity *entity : media_->locateEntities(MEDIA_ENT_F_CAM_SENSOR)) {\n> +\t\tLOG(RkISP1, Info) << \"Identified \" << entity->name();\n> +\t\tif (!createCamera(entity))\n>   \t\t\tregistered = true;\n>   \t}\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 08C9CC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 14:57:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 35AFC6350F;\n\tFri, 27 Sep 2024 16:57:04 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 074CE634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 16:57:03 +0200 (CEST)","from [IPV6:2405:201:2015:f873:55d7:c02e:b2eb:ee3f] (unknown\n\t[IPv6:2405:201:2015:f873:55d7:c02e:b2eb:ee3f])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6B47883D;\n\tFri, 27 Sep 2024 16:55:32 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"cEXwYCLC\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727448934;\n\tbh=hBndlVwcimhJX0UQ3YPQDuNIg+baGPUt5+1kI1VUKbE=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=cEXwYCLCP6Bt8qhkSE5/vMfnwjGiFIgmSx0bhRplQEKObyjbUjx0VvGiDu79E6u/Q\n\tiZ6KqqU1UJGqzhtO8jyFzPH5WisnCJdz7fSh8RIK5DYluDTd75aT2lBwDJZJsD3+Qf\n\taFK1IQr7D7eyTOuUSl+PXZtIKKGgsf3PeWY0btoA=","Message-ID":"<53fdd264-4c83-464c-abbf-a4a9cdcedc6c@ideasonboard.com>","Date":"Fri, 27 Sep 2024 20:26:57 +0530","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH 4/4] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera devel <libcamera-devel@lists.libcamera.org>","References":"<20240916140241.47845-1-kieran.bingham@ideasonboard.com>\n\t<20240916140241.47845-5-kieran.bingham@ideasonboard.com>","Content-Language":"en-US","From":"Umang Jain <umang.jain@ideasonboard.com>","In-Reply-To":"<20240916140241.47845-5-kieran.bingham@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31457,"web_url":"https://patchwork.libcamera.org/comment/31457/","msgid":"<u6nntd455vqa4jk377hjd4mf7a64dsyv5h4tw35yfg2bdesyou@xk5jhsmgfjxy>","date":"2024-09-27T20:51:10","subject":"Re: [PATCH 4/4] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Kieran\n\nOn Mon, Sep 16, 2024 at 04:02:41PM GMT, Kieran Bingham wrote:\n> Use the new MediaPipeline to manage and identify all sensors connected\n> to complex pipelines that can connect to the CSI2 receiver before the\n> ISP.\n>\n> This can include chained multiplexors that supply multiple cameras, so\n> make use of the MediaDevice::locateEntities to search for all cameras\n> and construct a pipeline for each.\n>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 65 ++++++++++++------------\n>  1 file changed, 32 insertions(+), 33 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 2fee84e56d4d..914f5181b51d 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -37,6 +37,7 @@\n>  #include \"libcamera/internal/framebuffer.h\"\n>  #include \"libcamera/internal/ipa_manager.h\"\n>  #include \"libcamera/internal/media_device.h\"\n> +#include \"libcamera/internal/media_pipeline.h\"\n>  #include \"libcamera/internal/pipeline_handler.h\"\n>  #include \"libcamera/internal/v4l2_subdevice.h\"\n>  #include \"libcamera/internal/v4l2_videodevice.h\"\n> @@ -108,6 +109,11 @@ public:\n>\n>  \tstd::unique_ptr<ipa::rkisp1::IPAProxyRkISP1> ipa_;\n>\n> +\t/*\n> +\t * All entities in the pipeline, from the camera sensor to the RKISP1.\n> +\t */\n> +\tMediaPipeline pipe_;\n> +\n>  private:\n>  \tvoid paramFilled(unsigned int frame, unsigned int bytesused);\n>  \tvoid setSensorControls(unsigned int frame,\n> @@ -171,8 +177,7 @@ private:\n>  \tfriend RkISP1CameraData;\n>  \tfriend RkISP1Frames;\n>\n> -\tint initLinks(Camera *camera, const CameraSensor *sensor,\n> -\t\t      const RkISP1CameraConfiguration &config);\n> +\tint initLinks(Camera *camera, const RkISP1CameraConfiguration &config);\n>  \tint createCamera(MediaEntity *sensor);\n>  \tvoid tryCompleteRequest(RkISP1FrameInfo *info);\n>  \tvoid bufferReady(FrameBuffer *buffer);\n> @@ -712,7 +717,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>  \tCameraSensor *sensor = data->sensor_.get();\n>  \tint ret;\n>\n> -\tret = initLinks(camera, sensor, *config);\n> +\tret = initLinks(camera, *config);\n>  \tif (ret)\n>  \t\treturn ret;\n>\n> @@ -729,12 +734,12 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n>\n>  \tLOG(RkISP1, Debug) << \"Sensor configured with \" << format;\n>\n> -\tif (csi_) {\n> -\t\tret = csi_->setFormat(0, &format);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n> -\t}\n> +\t/* Propagate format through the internal media pipeline up to the ISP */\n> +\tret = data->pipe_.configure(sensor, &format);\n> +\tif (ret < 0)\n> +\t\treturn ret;\n>\n> +\tLOG(RkISP1, Debug) << \"Configuring ISP with : \" << format;\n>  \tret = isp_->setFormat(0, &format);\n>  \tif (ret < 0)\n>  \t\treturn ret;\n> @@ -1035,7 +1040,6 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request)\n>   */\n>\n>  int PipelineHandlerRkISP1::initLinks(Camera *camera,\n> -\t\t\t\t     const CameraSensor *sensor,\n>  \t\t\t\t     const RkISP1CameraConfiguration &config)\n>  {\n>  \tRkISP1CameraData *data = cameraData(camera);\n> @@ -1046,31 +1050,16 @@ int PipelineHandlerRkISP1::initLinks(Camera *camera,\n>  \t\treturn ret;\n>\n>  \t/*\n> -\t * Configure the sensor links: enable the link corresponding to this\n> -\t * camera.\n> +\t * Configure the sensor links: enable the links corresponding to this\n> +\t * pipeline all the way up to the ISP, through any connected CSI receiver.\n>  \t */\n> -\tfor (MediaLink *link : ispSink_->links()) {\n> -\t\tif (link->source()->entity() != sensor->entity())\n> -\t\t\tcontinue;\n> -\n> -\t\tLOG(RkISP1, Debug)\n> -\t\t\t<< \"Enabling link from sensor '\"\n> -\t\t\t<< link->source()->entity()->name()\n> -\t\t\t<< \"' to ISP\";\n> -\n> -\t\tret = link->setEnabled(true);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n> -\t}\n> -\n> -\tif (csi_) {\n> -\t\tMediaLink *link = isp_->entity()->getPadByIndex(0)->links().at(0);\n> -\n> -\t\tret = link->setEnabled(true);\n> -\t\tif (ret < 0)\n> -\t\t\treturn ret;\n> +\tret = data->pipe_.initLinks();\n> +\tif (ret) {\n> +\t\tLOG(RkISP1, Error) << \"Failed to set up pipe links\";\n> +\t\treturn ret;\n>  \t}\n>\n> +\t/* Configure the paths after the ISP */\n>  \tfor (const StreamConfiguration &cfg : config) {\n>  \t\tif (cfg.stream() == &data->mainPathStream_)\n>  \t\t\tret = data->mainPath_->setEnabled(true);\n> @@ -1094,6 +1083,13 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n>  \t\tstd::make_unique<RkISP1CameraData>(this, &mainPath_,\n>  \t\t\t\t\t\t   hasSelfPath_ ? &selfPath_ : nullptr);\n>\n> +\t/* Identify the pipeline path between the sensor and the rkisp1_isp */\n> +\tret = data->pipe_.init(sensor, \"rkisp1_isp\");\n\nThis part is not clear to me how can work at\nMediaPipeline::configure() time, as the pipeline keeps a V4L2Subevice\ninstance open for the CSI-2 receiver, and since the init() call stops\nat \"rkisp1_isp\" I presume data->pipe_ creates and entity for the\nCSI-2 receiver as well ?\n\n> +\tif (ret) {\n> +\t\tLOG(RkISP1, Error) << \"Failed to identify path from sensor to sink\";\n> +\t\treturn ret;\n> +\t}\n> +\n>  \tdata->sensor_ = std::make_unique<CameraSensor>(sensor);\n>  \tret = data->sensor_->init();\n>  \tif (ret)\n> @@ -1129,6 +1125,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n>  \tconst std::string &id = data->sensor_->id();\n>  \tstd::shared_ptr<Camera> camera =\n>  \t\tCamera::create(std::move(data), id, streams);\n> +\n>  \tregisterCamera(std::move(camera));\n>\n>  \treturn 0;\n> @@ -1205,8 +1202,10 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator)\n>  \t * camera instance for each of them.\n>  \t */\n>  \tbool registered = false;\n> -\tfor (MediaLink *link : ispSink_->links()) {\n> -\t\tif (!createCamera(link->source()->entity()))\n\nMaybe we don't need \"ispSink_\" anymore ?\n\n> +\n> +\tfor (MediaEntity *entity : media_->locateEntities(MEDIA_ENT_F_CAM_SENSOR)) {\n> +\t\tLOG(RkISP1, Info) << \"Identified \" << entity->name();\n> +\t\tif (!createCamera(entity))\n>  \t\t\tregistered = true;\n>  \t}\n>\n> --\n> 2.46.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9137AC0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 27 Sep 2024 20:51:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9A22F6350F;\n\tFri, 27 Sep 2024 22:51:15 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 59412634F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 27 Sep 2024 22:51:14 +0200 (CEST)","from ideasonboard.com (mob-5-91-122-74.net.vodafone.it\n\t[5.91.122.74])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0A57783D;\n\tFri, 27 Sep 2024 22:49:44 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"GgBBJFxK\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727470185;\n\tbh=VCvOAJHxn8xf6Lk4/EFIC3yCpnZhMW3v5VZ7u0kt85Y=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=GgBBJFxKjv5CGjPvsnLQDkDiTeT2S6BZorh/SrdUJiYyigPQ/rYXiHLXsh1MZydsQ\n\tFdFy8IIFJMydzPgmteNquywCUgrQ0Saw7mosIniXrIMLxqgCGaIk+oGlE9SDT/ItG4\n\tFkUyPOX3MneVt7d8dsxs//fJ1GlneFV/SpLJvEV0=","Date":"Fri, 27 Sep 2024 22:51:10 +0200","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Subject":"Re: [PATCH 4/4] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","Message-ID":"<u6nntd455vqa4jk377hjd4mf7a64dsyv5h4tw35yfg2bdesyou@xk5jhsmgfjxy>","References":"<20240916140241.47845-1-kieran.bingham@ideasonboard.com>\n\t<20240916140241.47845-5-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240916140241.47845-5-kieran.bingham@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":31532,"web_url":"https://patchwork.libcamera.org/comment/31532/","msgid":"<172790238574.2318304.16012006226089913134@ping.linuxembedded.co.uk>","date":"2024-10-02T20:53:05","subject":"Re: [PATCH 4/4] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Jacopo Mondi (2024-09-27 21:51:10)\n> Hi Kieran\n> \n> On Mon, Sep 16, 2024 at 04:02:41PM GMT, Kieran Bingham wrote:\n> > Use the new MediaPipeline to manage and identify all sensors connected\n> > to complex pipelines that can connect to the CSI2 receiver before the\n> > ISP.\n> >\n> > This can include chained multiplexors that supply multiple cameras, so\n> > make use of the MediaDevice::locateEntities to search for all cameras\n> > and construct a pipeline for each.\n> >\n> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > ---\n> >  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 65 ++++++++++++------------\n> >  1 file changed, 32 insertions(+), 33 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > index 2fee84e56d4d..914f5181b51d 100644\n> > --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> > @@ -37,6 +37,7 @@\n> >  #include \"libcamera/internal/framebuffer.h\"\n> >  #include \"libcamera/internal/ipa_manager.h\"\n> >  #include \"libcamera/internal/media_device.h\"\n> > +#include \"libcamera/internal/media_pipeline.h\"\n> >  #include \"libcamera/internal/pipeline_handler.h\"\n> >  #include \"libcamera/internal/v4l2_subdevice.h\"\n> >  #include \"libcamera/internal/v4l2_videodevice.h\"\n> > @@ -108,6 +109,11 @@ public:\n> >\n> >       std::unique_ptr<ipa::rkisp1::IPAProxyRkISP1> ipa_;\n> >\n> > +     /*\n> > +      * All entities in the pipeline, from the camera sensor to the RKISP1.\n> > +      */\n> > +     MediaPipeline pipe_;\n> > +\n> >  private:\n> >       void paramFilled(unsigned int frame, unsigned int bytesused);\n> >       void setSensorControls(unsigned int frame,\n> > @@ -171,8 +177,7 @@ private:\n> >       friend RkISP1CameraData;\n> >       friend RkISP1Frames;\n> >\n> > -     int initLinks(Camera *camera, const CameraSensor *sensor,\n> > -                   const RkISP1CameraConfiguration &config);\n> > +     int initLinks(Camera *camera, const RkISP1CameraConfiguration &config);\n> >       int createCamera(MediaEntity *sensor);\n> >       void tryCompleteRequest(RkISP1FrameInfo *info);\n> >       void bufferReady(FrameBuffer *buffer);\n> > @@ -712,7 +717,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n> >       CameraSensor *sensor = data->sensor_.get();\n> >       int ret;\n> >\n> > -     ret = initLinks(camera, sensor, *config);\n> > +     ret = initLinks(camera, *config);\n> >       if (ret)\n> >               return ret;\n> >\n> > @@ -729,12 +734,12 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c)\n> >\n> >       LOG(RkISP1, Debug) << \"Sensor configured with \" << format;\n> >\n> > -     if (csi_) {\n> > -             ret = csi_->setFormat(0, &format);\n> > -             if (ret < 0)\n> > -                     return ret;\n> > -     }\n> > +     /* Propagate format through the internal media pipeline up to the ISP */\n> > +     ret = data->pipe_.configure(sensor, &format);\n> > +     if (ret < 0)\n> > +             return ret;\n> >\n> > +     LOG(RkISP1, Debug) << \"Configuring ISP with : \" << format;\n> >       ret = isp_->setFormat(0, &format);\n> >       if (ret < 0)\n> >               return ret;\n> > @@ -1035,7 +1040,6 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request)\n> >   */\n> >\n> >  int PipelineHandlerRkISP1::initLinks(Camera *camera,\n> > -                                  const CameraSensor *sensor,\n> >                                    const RkISP1CameraConfiguration &config)\n> >  {\n> >       RkISP1CameraData *data = cameraData(camera);\n> > @@ -1046,31 +1050,16 @@ int PipelineHandlerRkISP1::initLinks(Camera *camera,\n> >               return ret;\n> >\n> >       /*\n> > -      * Configure the sensor links: enable the link corresponding to this\n> > -      * camera.\n> > +      * Configure the sensor links: enable the links corresponding to this\n> > +      * pipeline all the way up to the ISP, through any connected CSI receiver.\n> >        */\n> > -     for (MediaLink *link : ispSink_->links()) {\n> > -             if (link->source()->entity() != sensor->entity())\n> > -                     continue;\n> > -\n> > -             LOG(RkISP1, Debug)\n> > -                     << \"Enabling link from sensor '\"\n> > -                     << link->source()->entity()->name()\n> > -                     << \"' to ISP\";\n> > -\n> > -             ret = link->setEnabled(true);\n> > -             if (ret < 0)\n> > -                     return ret;\n> > -     }\n> > -\n> > -     if (csi_) {\n> > -             MediaLink *link = isp_->entity()->getPadByIndex(0)->links().at(0);\n> > -\n> > -             ret = link->setEnabled(true);\n> > -             if (ret < 0)\n> > -                     return ret;\n> > +     ret = data->pipe_.initLinks();\n> > +     if (ret) {\n> > +             LOG(RkISP1, Error) << \"Failed to set up pipe links\";\n> > +             return ret;\n> >       }\n> >\n> > +     /* Configure the paths after the ISP */\n> >       for (const StreamConfiguration &cfg : config) {\n> >               if (cfg.stream() == &data->mainPathStream_)\n> >                       ret = data->mainPath_->setEnabled(true);\n> > @@ -1094,6 +1083,13 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n> >               std::make_unique<RkISP1CameraData>(this, &mainPath_,\n> >                                                  hasSelfPath_ ? &selfPath_ : nullptr);\n> >\n> > +     /* Identify the pipeline path between the sensor and the rkisp1_isp */\n> > +     ret = data->pipe_.init(sensor, \"rkisp1_isp\");\n> \n> This part is not clear to me how can work at\n> MediaPipeline::configure() time, as the pipeline keeps a V4L2Subevice\n> instance open for the CSI-2 receiver, and since the init() call stops\n> at \"rkisp1_isp\" I presume data->pipe_ creates and entity for the\n> CSI-2 receiver as well ?\n\nYes, the CSI2 receiver can now be managed through the MediaPipeline\npath.\n\nLets see if there's more handling I can remove from the rkisp1 pipeline\nhandler to further simplify.\n\n> \n> > +     if (ret) {\n> > +             LOG(RkISP1, Error) << \"Failed to identify path from sensor to sink\";\n> > +             return ret;\n> > +     }\n> > +\n> >       data->sensor_ = std::make_unique<CameraSensor>(sensor);\n> >       ret = data->sensor_->init();\n> >       if (ret)\n> > @@ -1129,6 +1125,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n> >       const std::string &id = data->sensor_->id();\n> >       std::shared_ptr<Camera> camera =\n> >               Camera::create(std::move(data), id, streams);\n> > +\n> >       registerCamera(std::move(camera));\n> >\n> >       return 0;\n> > @@ -1205,8 +1202,10 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator)\n> >        * camera instance for each of them.\n> >        */\n> >       bool registered = false;\n> > -     for (MediaLink *link : ispSink_->links()) {\n> > -             if (!createCamera(link->source()->entity()))\n> \n> Maybe we don't need \"ispSink_\" anymore ?\n\nOh - I think that's a good spot. I'll see what else I can find too.\n--\nKieran\n\n\n> \n> > +\n> > +     for (MediaEntity *entity : media_->locateEntities(MEDIA_ENT_F_CAM_SENSOR)) {\n> > +             LOG(RkISP1, Info) << \"Identified \" << entity->name();\n> > +             if (!createCamera(entity))\n> >                       registered = true;\n> >       }\n> >\n> > --\n> > 2.46.0\n> >","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 64A64BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  2 Oct 2024 20:53:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1655763525;\n\tWed,  2 Oct 2024 22:53:11 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EBEA063510\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  2 Oct 2024 22:53:08 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2E24D3E6;\n\tWed,  2 Oct 2024 22:51:36 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"urj4UA1I\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1727902296;\n\tbh=ytONEeGD13W6VCYxP3QXQWBHzQv5PaWESzkJYA/0xY4=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=urj4UA1Idb+ZE/gk/opWY3ApFoIjyp3ERbt3QPK/Tfdvh9hL4I+Ax9qd7J8+MTO5W\n\tthTQmvVUoX+BQVrBFeZ2kDnYTDbiSYx+mK/O6HziLWNSPQ79ZL16pHHPINRhE7rqOZ\n\tH+NCeZS2f1WzUut2M7CH1+cvrJinmedhymDZk04U=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<u6nntd455vqa4jk377hjd4mf7a64dsyv5h4tw35yfg2bdesyou@xk5jhsmgfjxy>","References":"<20240916140241.47845-1-kieran.bingham@ideasonboard.com>\n\t<20240916140241.47845-5-kieran.bingham@ideasonboard.com>\n\t<u6nntd455vqa4jk377hjd4mf7a64dsyv5h4tw35yfg2bdesyou@xk5jhsmgfjxy>","Subject":"Re: [PATCH 4/4] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Date":"Wed, 02 Oct 2024 21:53:05 +0100","Message-ID":"<172790238574.2318304.16012006226089913134@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]