From patchwork Thu Aug 8 17:39:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 20848 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 7779EC323E for ; Thu, 8 Aug 2024 17:39:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 29AB963382; Thu, 8 Aug 2024 19:39:29 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mSqi5QiW"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CE6E16337F for ; Thu, 8 Aug 2024 19:39:24 +0200 (CEST) Received: from Monstersaurus.tail69b4.ts.net (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E9048C8E; Thu, 8 Aug 2024 19:38:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723138711; bh=l4hjMp0+x9x77pS0m7uX5MOyVl1PnogMgw8D/SO5su8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mSqi5QiWBbLEhIA5Dl8G/lHArcayEWiZV+wZgQeLfr9C8WTn4FqM3RCC44tTBhYFG lbk6u0SXSx3vnmf8CCelodll6aKnIrx1GcvRnxWjelQ49017rs+4+euARC/x+k5+VU a1RpKDUWP17SbgZTyWFk0J5fMnzYdGUvYn9DtDbo= From: Kieran Bingham To: libcamera devel Cc: Paul Elder , Kieran Bingham Subject: [PATCH 1/2] pipeline: simple: Remove media member variable Date: Thu, 8 Aug 2024 18:39:20 +0100 Message-Id: <20240808173921.2519957-2-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808173921.2519957-1-kieran.bingham@ideasonboard.com> References: <20240808173921.2519957-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 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" From: Paul Elder There is no need for the simple pipeline handler to save the media device. Remove it. Signed-off-by: Paul Elder Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/simple/simple.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 9910900e0e5e..222052ce02f8 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -363,13 +363,12 @@ private: return static_cast(camera->_d()); } - std::vector locateSensors(); + std::vector locateSensors(MediaDevice *media); static int resetRoutingTable(V4L2Subdevice *subdev); const MediaPad *acquirePipeline(SimpleCameraData *data); void releasePipeline(SimpleCameraData *data); - MediaDevice *media_; std::map entities_; MediaDevice *converter_; @@ -1424,7 +1423,8 @@ int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request) * Match and Setup */ -std::vector SimplePipelineHandler::locateSensors() +std::vector +SimplePipelineHandler::locateSensors(MediaDevice *media) { std::vector entities; @@ -1432,7 +1432,7 @@ std::vector SimplePipelineHandler::locateSensors() * Gather all the camera sensor entities based on the function they * expose. */ - for (MediaEntity *entity : media_->entities()) { + for (MediaEntity *entity : media->entities()) { if (entity->function() == MEDIA_ENT_F_CAM_SENSOR) entities.push_back(entity); } @@ -1520,17 +1520,18 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) { const SimplePipelineInfo *info = nullptr; unsigned int numStreams = 1; + MediaDevice *media; for (const SimplePipelineInfo &inf : supportedDevices) { DeviceMatch dm(inf.driver); - media_ = acquireMediaDevice(enumerator, dm); - if (media_) { + media = acquireMediaDevice(enumerator, dm); + if (media) { info = &inf; break; } } - if (!media_) + if (!media) return false; for (const auto &[name, streams] : info->converters) { @@ -1545,13 +1546,13 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) swIspEnabled_ = info->swIspEnabled; /* Locate the sensors. */ - std::vector sensors = locateSensors(); + std::vector sensors = locateSensors(media); if (sensors.empty()) { - LOG(SimplePipeline, Info) << "No sensor found for " << media_->deviceNode(); + LOG(SimplePipeline, Info) << "No sensor found for " << media->deviceNode(); return false; } - LOG(SimplePipeline, Debug) << "Sensor found for " << media_->deviceNode(); + LOG(SimplePipeline, Debug) << "Sensor found for " << media->deviceNode(); /* * Create one camera data instance for each sensor and gather all From patchwork Thu Aug 8 17:39:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 20849 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 C9BA7C323E for ; Thu, 8 Aug 2024 17:39:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 61D74633B4; Thu, 8 Aug 2024 19:39:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="EuHgcExi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id ED5D263382 for ; Thu, 8 Aug 2024 19:39:24 +0200 (CEST) Received: from Monstersaurus.tail69b4.ts.net (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3B57C124E; Thu, 8 Aug 2024 19:38:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1723138711; bh=assIro+CC+XYMVMUNLpVmwfxKJAsTHIOpgXaxvnQMZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EuHgcExi0oL8rZj7IpFl6luLOx/04t+EzIBW5PnQ3U3GCf4WsrUxwWdHhb6c+OoCa If80HNlZ/u5bKQ9cm8eOAfV3+0ov/evTMUigvX6TD7iSVyVqPLQ3NEyJN03xaY35fz 0/drVXkrmXbV7kN8mbXH46hPg48vVFCSNxzeAd3w= From: Kieran Bingham To: libcamera devel Cc: Paul Elder , Kieran Bingham Subject: [PATCH 2/2] pipeline: simple: Fix matching with empty media graphs Date: Thu, 8 Aug 2024 18:39:21 +0100 Message-Id: <20240808173921.2519957-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240808173921.2519957-1-kieran.bingham@ideasonboard.com> References: <20240808173921.2519957-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 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" From: Paul Elder The match() function currently reports that it is not possible to create any cameras if it encounters an empty media graph. Fix this by looping over all media graphs and only returning false when all of them fail to create a camera. Signed-off-by: Paul Elder Signed-off-by: Kieran Bingham --- src/libcamera/pipeline/simple/simple.cpp | 50 ++++++++++++++++-------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 222052ce02f8..115f8528fc71 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -363,6 +363,9 @@ private: return static_cast(camera->_d()); } + bool matchDevice(MediaDevice *media, const SimplePipelineInfo &info, + DeviceEnumerator *enumerator); + std::vector locateSensors(MediaDevice *media); static int resetRoutingTable(V4L2Subdevice *subdev); @@ -1516,25 +1519,13 @@ int SimplePipelineHandler::resetRoutingTable(V4L2Subdevice *subdev) return 0; } -bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) +bool SimplePipelineHandler::matchDevice(MediaDevice *media, + const SimplePipelineInfo &info, + DeviceEnumerator *enumerator) { - const SimplePipelineInfo *info = nullptr; unsigned int numStreams = 1; - MediaDevice *media; - for (const SimplePipelineInfo &inf : supportedDevices) { - DeviceMatch dm(inf.driver); - media = acquireMediaDevice(enumerator, dm); - if (media) { - info = &inf; - break; - } - } - - if (!media) - return false; - - for (const auto &[name, streams] : info->converters) { + for (const auto &[name, streams] : info.converters) { DeviceMatch converterMatch(name); converter_ = acquireMediaDevice(enumerator, converterMatch); if (converter_) { @@ -1543,7 +1534,7 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) } } - swIspEnabled_ = info->swIspEnabled; + swIspEnabled_ = info.swIspEnabled; /* Locate the sensors. */ std::vector sensors = locateSensors(media); @@ -1662,6 +1653,31 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) return registered; } +bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) +{ + MediaDevice *media; + + for (const SimplePipelineInfo &inf : supportedDevices) { + DeviceMatch dm(inf.driver); + while ((media = acquireMediaDevice(enumerator, dm))) { + /* + * If match succeeds, return true to let match() be + * called again on a new instance of the pipeline + * handler. Otherwise keep looping until we do + * successfully match one (or run out). + */ + if (matchDevice(media, inf, enumerator)) { + LOG(SimplePipeline, Debug) + << "Matched on device: " + << media->deviceNode(); + return true; + } + } + } + + return false; +} + V4L2VideoDevice *SimplePipelineHandler::video(const MediaEntity *entity) { auto iter = entities_.find(entity);