[{"id":30719,"web_url":"https://patchwork.libcamera.org/comment/30719/","msgid":"<20240811001251.GA22014@pendragon.ideasonboard.com>","date":"2024-08-11T00:12:51","subject":"Re: [PATCH 2/2] pipeline: simple: Fix matching with empty media\n\tgraphs","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran and Paul,\n\nThank you for the patch.\n\nOn Thu, Aug 08, 2024 at 06:39:21PM +0100, Kieran Bingham wrote:\n> From: Paul Elder <paul.elder@ideasonboard.com>\n> \n> The match() function currently reports that it is not possible to create\n> any cameras if it encounters an empty media graph.\n> \n> Fix this by looping over all media graphs and only returning false when\n> all of them fail to create a camera.\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/simple/simple.cpp | 50 ++++++++++++++++--------\n>  1 file changed, 33 insertions(+), 17 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\n> index 222052ce02f8..115f8528fc71 100644\n> --- a/src/libcamera/pipeline/simple/simple.cpp\n> +++ b/src/libcamera/pipeline/simple/simple.cpp\n> @@ -363,6 +363,9 @@ private:\n>  \t\treturn static_cast<SimpleCameraData *>(camera->_d());\n>  \t}\n>  \n> +\tbool matchDevice(MediaDevice *media, const SimplePipelineInfo &info,\n> +\t\t\t DeviceEnumerator *enumerator);\n> +\n>  \tstd::vector<MediaEntity *> locateSensors(MediaDevice *media);\n>  \tstatic int resetRoutingTable(V4L2Subdevice *subdev);\n>  \n> @@ -1516,25 +1519,13 @@ int SimplePipelineHandler::resetRoutingTable(V4L2Subdevice *subdev)\n>  \treturn 0;\n>  }\n>  \n> -bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n> +bool SimplePipelineHandler::matchDevice(MediaDevice *media,\n> +\t\t\t\t\tconst SimplePipelineInfo &info,\n> +\t\t\t\t\tDeviceEnumerator *enumerator)\n>  {\n> -\tconst SimplePipelineInfo *info = nullptr;\n>  \tunsigned int numStreams = 1;\n> -\tMediaDevice *media;\n>  \n> -\tfor (const SimplePipelineInfo &inf : supportedDevices) {\n> -\t\tDeviceMatch dm(inf.driver);\n> -\t\tmedia = acquireMediaDevice(enumerator, dm);\n> -\t\tif (media) {\n> -\t\t\tinfo = &inf;\n> -\t\t\tbreak;\n> -\t\t}\n> -\t}\n> -\n> -\tif (!media)\n> -\t\treturn false;\n> -\n> -\tfor (const auto &[name, streams] : info->converters) {\n> +\tfor (const auto &[name, streams] : info.converters) {\n>  \t\tDeviceMatch converterMatch(name);\n>  \t\tconverter_ = acquireMediaDevice(enumerator, converterMatch);\n>  \t\tif (converter_) {\n> @@ -1543,7 +1534,7 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n>  \t\t}\n>  \t}\n>  \n> -\tswIspEnabled_ = info->swIspEnabled;\n> +\tswIspEnabled_ = info.swIspEnabled;\n>  \n>  \t/* Locate the sensors. */\n>  \tstd::vector<MediaEntity *> sensors = locateSensors(media);\n> @@ -1662,6 +1653,31 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n>  \treturn registered;\n>  }\n>  \n> +bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n> +{\n> +\tMediaDevice *media;\n> +\n> +\tfor (const SimplePipelineInfo &inf : supportedDevices) {\n\ns/inf/info/\n\n> +\t\tDeviceMatch dm(inf.driver);\n> +\t\twhile ((media = acquireMediaDevice(enumerator, dm))) {\n> +\t\t\t/*\n> +\t\t\t * If match succeeds, return true to let match() be\n> +\t\t\t * called again on a new instance of the pipeline\n> +\t\t\t * handler. Otherwise keep looping until we do\n> +\t\t\t * successfully match one (or run out).\n> +\t\t\t */\n> +\t\t\tif (matchDevice(media, inf, enumerator)) {\n> +\t\t\t\tLOG(SimplePipeline, Debug)\n> +\t\t\t\t\t<< \"Matched on device: \"\n> +\t\t\t\t\t<< media->deviceNode();\n> +\t\t\t\treturn true;\n> +\t\t\t}\n> +\t\t}\n\nIf some media devices match, they will get added to the mediaDevices_\nlist by acquireMediaDevice(), regardless of whether or not they result\nin a valid pipeline. This means that invalid media devices followed by a\nvalid media device will be stored in the mediaDevices_ list for the\npipeline handler instance corresponding to the valid media device. The\ncameras create by that pipeline handler instance will end up reporting\nthe invalid media devices in the SystemDevices property. Is that\nsomething you're aware of, and is that acceptable ?\n\n> +\t}\n> +\n> +\treturn false;\n> +}\n> +\n>  V4L2VideoDevice *SimplePipelineHandler::video(const MediaEntity *entity)\n>  {\n>  \tauto iter = entities_.find(entity);","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 3A8EBC323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 11 Aug 2024 00:13:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 12399633B5;\n\tSun, 11 Aug 2024 02:13:18 +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 9F88263393\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 11 Aug 2024 02:13:15 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F3A753E6;\n\tSun, 11 Aug 2024 02:12:19 +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=\"jgMtfGeX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1723335140;\n\tbh=qcEgL2j1TNoLLhSThsPwLA51uzBWrVwxGKTkY87HGOM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jgMtfGeXr6qL2/rjDIagNnAitRDc3CdIq0bkl2SHrtcG1rDuOC7OMtPJBBnvz0i9Y\n\tOkgBpEIhUF82/KS7byvDtWeK71Ib0ywXMb/qm8dzTIH6dSrTMH0P7wsmx+nrq1fIYz\n\tgmLxsMZtgEPMG5Lde22dl1VTdSgv4g7u1CBqvto0=","Date":"Sun, 11 Aug 2024 03:12:51 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>,\n\tPaul Elder <paul.elder@ideasonboard.com>","Subject":"Re: [PATCH 2/2] pipeline: simple: Fix matching with empty media\n\tgraphs","Message-ID":"<20240811001251.GA22014@pendragon.ideasonboard.com>","References":"<20240808173921.2519957-1-kieran.bingham@ideasonboard.com>\n\t<20240808173921.2519957-3-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20240808173921.2519957-3-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>"}}]