[{"id":33909,"web_url":"https://patchwork.libcamera.org/comment/33909/","msgid":"<vcw5hr4lo3wxizpdskqs5x355r27tpknqnsbpkhzcemmfe6kbk@6upaw3f7blob>","date":"2025-04-03T10:34:56","subject":"Re: [PATCH v4 3/3] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"On Wed, Apr 02, 2025 at 04:39:18PM +0900, Paul Elder wrote:\n> From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \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> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 86 +++++++++---------------\n>  1 file changed, 32 insertions(+), 54 deletions(-)\n\nNice when that code gets shorter :-)\nAcked-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 52633fe3cb85..705615b86b0c 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -42,6 +42,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> @@ -116,6 +117,11 @@ public:\n>  \n>  \tControlInfoMap ipaControls_;\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 paramsComputed(unsigned int frame, unsigned int bytesused);\n>  \tvoid setSensorControls(unsigned int frame,\n> @@ -180,8 +186,7 @@ private:\n>  \tfriend RkISP1CameraConfiguration;\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 imageBufferReady(FrameBuffer *buffer);\n> @@ -199,7 +204,6 @@ private:\n>  \tstd::unique_ptr<V4L2Subdevice> isp_;\n>  \tstd::unique_ptr<V4L2VideoDevice> param_;\n>  \tstd::unique_ptr<V4L2VideoDevice> stat_;\n> -\tstd::unique_ptr<V4L2Subdevice> csi_;\n>  \n>  \tbool hasSelfPath_;\n>  \tbool isRaw_;\n> @@ -223,8 +227,6 @@ private:\n>  \tstd::queue<FrameBuffer *> availableStatBuffers_;\n>  \n>  \tCamera *activeCamera_;\n> -\n> -\tconst MediaPad *ispSink_;\n>  };\n>  \n>  RkISP1Frames::RkISP1Frames(PipelineHandler *pipe)\n> @@ -798,7 +800,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> @@ -821,12 +823,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> @@ -1201,7 +1203,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> @@ -1212,31 +1213,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> @@ -1312,6 +1298,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> +\t\treturn ret;\n> +\t}\n> +\n>  \tdata->sensor_ = CameraSensorFactoryBase::create(sensor);\n>  \tif (!data->sensor_)\n>  \t\treturn -ENODEV;\n> @@ -1347,6 +1340,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> @@ -1354,8 +1348,6 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n>  \n>  bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator)\n>  {\n> -\tconst MediaPad *pad;\n> -\n>  \tDeviceMatch dm(\"rkisp1\");\n>  \tdm.add(\"rkisp1_isp\");\n>  \tdm.add(\"rkisp1_resizer_mainpath\");\n> @@ -1380,22 +1372,6 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator)\n>  \tif (isp_->open() < 0)\n>  \t\treturn false;\n>  \n> -\t/* Locate and open the optional CSI-2 receiver. */\n> -\tispSink_ = isp_->entity()->getPadByIndex(0);\n> -\tif (!ispSink_ || ispSink_->links().empty())\n> -\t\treturn false;\n> -\n> -\tpad = ispSink_->links().at(0)->source();\n> -\tif (pad->entity()->function() == MEDIA_ENT_F_VID_IF_BRIDGE) {\n> -\t\tcsi_ = std::make_unique<V4L2Subdevice>(pad->entity());\n> -\t\tif (csi_->open() < 0)\n> -\t\t\treturn false;\n> -\n> -\t\tispSink_ = csi_->entity()->getPadByIndex(0);\n> -\t\tif (!ispSink_)\n> -\t\t\treturn false;\n> -\t}\n> -\n>  \t/* Locate and open the stats and params video nodes. */\n>  \tstat_ = V4L2VideoDevice::fromEntityName(media_, \"rkisp1_stats\");\n>  \tif (stat_->open() < 0)\n> @@ -1446,8 +1422,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, Debug) << \"Identified \" << entity->name();\n> +\t\tif (!createCamera(entity))\n>  \t\t\tregistered = true;\n>  \t}\n>  \n> -- \n> 2.47.2\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 808D1C327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  3 Apr 2025 10:35:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BD557689A0;\n\tThu,  3 Apr 2025 12:34:59 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 169ED68994\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  3 Apr 2025 12:34:59 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:6d9d:9854:3fc1:4bb2])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 71BF0105D;\n\tThu,  3 Apr 2025 12:33:05 +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=\"D4EOfbkr\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1743676385;\n\tbh=Edi/l2MgQWRU6KXiknN0FrPCV0Z7QLpK8Plq4M3ALLs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=D4EOfbkrKSuUzcYf8h5vWNc+lrJOlMhQCtovzT4kzjpIxWm9CZwyv5Im242lGDHl5\n\tI//2/YGECTnjCDLy0L/e55AxtqWhgFQ/birgANOqV7NBHWutCuPiMXeI/wRZRIbXc/\n\tC9EYHLAgJou+C5i1mBZvkbCdDBzl8R8FarmC1kJg=","Date":"Thu, 3 Apr 2025 12:34:56 +0200","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tUmang Jain <umang.jain@ideasonboard.com>, \n\tDaniel Scally <dan.scally@ideasonboard.com>,\n\tJacopo Mondi <jacopo.mondi@ideasonboard.com>","Subject":"Re: [PATCH v4 3/3] libcamera: pipeline: rkisp1: Convert to use\n\tMediaPipeline","Message-ID":"<vcw5hr4lo3wxizpdskqs5x355r27tpknqnsbpkhzcemmfe6kbk@6upaw3f7blob>","References":"<20250402073919.183330-1-paul.elder@ideasonboard.com>\n\t<20250402073919.183330-4-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250402073919.183330-4-paul.elder@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>"}}]