From patchwork Mon Aug 1 00:05:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16886 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 A6AACBE173 for ; Mon, 1 Aug 2022 00:06:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6955763323; Mon, 1 Aug 2022 02:06:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659312363; bh=BGs5kBdaYnaJfdCOWHtVIvMsV7Xv5oEdih+wQ8J0gaY=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=OKtksVnwz03naIOFV3I7qP6NpT2B9sCip65mjlqKVlSiLZaTfqz003I+NCJGaOZRy 0HQ3D1lCJe6iRpEt+hEdmBQ4qaG0SUgAWpmw+EjRdrAbBwpYrR/2iATXAZMRazWwgv 3/2oV9sLV25i6XXMJM3TCHrLaSmO4BWSc90TVi8KCGO/9FENKkOtrMaFesRzRt3Cll fMoEfsyy1d4QxXzU51WahpoNftQ/REWZLhKrJVZu44Fi4h+1b5IqURGrzquC2aL0ym aTSb768T6li5bsqenlzVQD9EI9E1yl+8ky7jSEZTljla19wUC20ZM4+ga/U55LNO3P 9FlX6igQ8uzgA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD32363312 for ; Mon, 1 Aug 2022 02:06:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lIUI80fi"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 59A179AA; Mon, 1 Aug 2022 02:06:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659312361; bh=BGs5kBdaYnaJfdCOWHtVIvMsV7Xv5oEdih+wQ8J0gaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lIUI80fiiP+49S4H6rS5xHxAKRqbmc67frbgQOGfkYRKbQpm5abJfsE/gmeXaS9ei YEfYs5g/t7PVKyt16Xoe7CxOtP1vEinYXi6fULivBk3XmL10AsPa1iXLkl7+O6N7wJ DQNAeyX7ODtjgrZ/g5nRZ3BZvOQwqrN7PEGes0xM= To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Aug 2022 03:05:39 +0300 Message-Id: <20220801000543.3501-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220801000543.3501-1-laurent.pinchart@ideasonboard.com> References: <20220801000543.3501-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/13] libcamera: pipeline: simple: Reset routing table of subdevs 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Jacopo Mondi Reset the routing table of subdevices supporting the V4L2 streams API to its default state when initializing the pipeline handler. This avoids issues caused by usage of leftover state. Signed-off-by: Jacopo Mondi Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen --- src/libcamera/pipeline/simple/simple.cpp | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index bc0cb1a00c2a..731d355efda6 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -332,6 +332,7 @@ private: } std::vector locateSensors(); + static int resetRoutingTable(V4L2Subdevice *subdev); const MediaPad *acquirePipeline(SimpleCameraData *data); void releasePipeline(SimpleCameraData *data); @@ -1260,6 +1261,37 @@ std::vector SimplePipelineHandler::locateSensors() return sensors; } +int SimplePipelineHandler::resetRoutingTable(V4L2Subdevice *subdev) +{ + /* Reset the media entity routing table to its default state. */ + V4L2Subdevice::Routing routing = {}; + + int ret = subdev->getRouting(&routing, V4L2Subdevice::TryFormat); + if (ret) + return ret; + + ret = subdev->setRouting(&routing, V4L2Subdevice::ActiveFormat); + if (ret) + return ret; + + /* + * If the routing table is empty we won't be able to meaningfully use + * the subdev. + */ + if (routing.empty()) { + LOG(SimplePipeline, Error) + << "Default routing table of " << subdev->deviceNode() + << " is empty"; + return -EINVAL; + } + + LOG(SimplePipeline, Debug) + << "Routing table of " << subdev->deviceNode() + << " reset to " << routing.toString(); + + return 0; +} + bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) { const SimplePipelineInfo *info = nullptr; @@ -1352,6 +1384,23 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) << ": " << strerror(-ret); return false; } + + if (subdev->caps().hasStreams()) { + /* + * Reset the routing table to its default state + * to make sure entities are enumerate according + * to the defaul routing configuration. + */ + ret = resetRoutingTable(subdev.get()); + if (ret) { + LOG(SimplePipeline, Error) + << "Failed to reset routes for " + << subdev->deviceNode() << ": " + << strerror(-ret); + return false; + } + } + break; default: