From patchwork Sun Jun 12 15:23:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16200 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 52631C3275 for ; Sun, 12 Jun 2022 15:23:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 05CB265636; Sun, 12 Jun 2022 17:23:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655047408; bh=NEvw7Yb0BDqt535enhFpoKtHVCWV4h2LVLSYk7WADs0=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=nclsfMlYSydR28u72ANXXh33tQpHJv5EuDBrtneF/x6Eo7p3PGOZZ5T87AF7CtGsa YW4BjJd2T8Ic5R3O5ysAYdpTTLd/Um610VomdAVYMkF3xlnnVkZ88acZw3lJNx4lQp X41zgGA3m724aAS36tGk6acGn3Q2YUhQUL7soMHKbxa95vR9Tn7UrMIORQAemTvJMt EeKD7gmK6J7BhY1FevKCtbfxsZ0RPZ14CC8piCG3nQ2YCqSuftS7pTHXSw60TleRCn L6K1xWxQq5jgTyMCn2fBRmfiBZ7IVfi6cmcLXSnlWfePMznAVAtBkI7LGMPBVwZqkc gFJUI2U/8Q9bg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 06E89600F4 for ; Sun, 12 Jun 2022 17:23:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SeTrA16P"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2FC05DDE; Sun, 12 Jun 2022 17:23:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1655047405; bh=NEvw7Yb0BDqt535enhFpoKtHVCWV4h2LVLSYk7WADs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SeTrA16PJqt9YR+DyiA2qHtwHsJvgl3lvSS020ayKUGjya1pmKDJ/tJj2ZHyE3lZP CVLpugj9GTyzZT2cgQhWQa4qLSsSbVeFvP0rNweoOWzbaph/lGqnOsMLlPmal3UnZJ wsQgznzJi2ohAdIQEoDHnqgML9u6TZ4kvSVRTlSM= To: libcamera-devel@lists.libcamera.org Date: Sun, 12 Jun 2022 18:23:09 +0300 Message-Id: <20220612152311.8408-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220612152311.8408-1-laurent.pinchart@ideasonboard.com> References: <20220612152311.8408-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/5] libcamera: pipeline: simple: Factor out format test to separate function 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 Cc: Dorota Czaplejewicz , Benjamin Schaaf Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To prepare for the implementation of a more complex format discovery method, factor out code that tries a pipeline configuration to a separate function. No functional change intended. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- Changes since v1: - Drop unused function declaration - Document the tryPipeline() function --- src/libcamera/pipeline/simple/simple.cpp | 118 +++++++++++++---------- 1 file changed, 67 insertions(+), 51 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index b09368aee20b..3c90bdec60e0 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -250,6 +250,8 @@ public: std::queue> converterQueue_; private: + void tryPipeline(unsigned int code, const Size &size); + void converterInputDone(FrameBuffer *buffer); void converterOutputDone(FrameBuffer *buffer); }; @@ -466,58 +468,11 @@ int SimpleCameraData::init() return ret; /* - * Enumerate the possible pipeline configurations. For each media bus - * format supported by the sensor, propagate the formats through the - * pipeline, and enumerate the corresponding possible V4L2 pixel - * formats on the video node. + * Generate the list of possible pipeline configurations by trying each + * media bus format supported by the sensor. */ - for (unsigned int code : sensor_->mbusCodes()) { - V4L2SubdeviceFormat format{}; - format.mbus_code = code; - format.size = sensor_->resolution(); - - ret = setupFormats(&format, V4L2Subdevice::TryFormat); - if (ret < 0) { - LOG(SimplePipeline, Debug) - << "Media bus code " << utils::hex(code, 4) - << " not supported for this pipeline"; - /* Try next mbus_code supported by the sensor */ - continue; - } - - V4L2VideoDevice::Formats videoFormats = - video_->formats(format.mbus_code); - - LOG(SimplePipeline, Debug) - << "Adding configuration for " << format.size - << " in pixel formats [ " - << utils::join(videoFormats, ", ", - [](const auto &f) { - return f.first.toString(); - }) - << " ]"; - - for (const auto &videoFormat : videoFormats) { - PixelFormat pixelFormat = videoFormat.first.toPixelFormat(); - if (!pixelFormat) - continue; - - Configuration config; - config.code = code; - config.captureFormat = pixelFormat; - config.captureSize = format.size; - - if (!converter_) { - config.outputFormats = { pixelFormat }; - config.outputSizes = config.captureSize; - } else { - config.outputFormats = converter_->formats(pixelFormat); - config.outputSizes = converter_->sizes(format.size); - } - - configs_.push_back(config); - } - } + for (unsigned int code : sensor_->mbusCodes()) + tryPipeline(code, sensor_->resolution()); if (configs_.empty()) { LOG(SimplePipeline, Error) << "No valid configuration found"; @@ -541,6 +496,67 @@ int SimpleCameraData::init() return 0; } +/* + * Generate a list of supported pipeline configurations for a sensor media bus + * code and size. + * + * First propagate the media bus code and size through the pipeline from the + * camera sensor to the video node. Then, query the video node for all supported + * pixel formats compatible with the media bus code. For each pixel format, store + * a full pipeline configuration in the configs_ vector. + */ +void SimpleCameraData::tryPipeline(unsigned int code, const Size &size) +{ + /* + * Propagate the format through the pipeline, and enumerate the + * corresponding possible V4L2 pixel formats on the video node. + */ + V4L2SubdeviceFormat format{}; + format.mbus_code = code; + format.size = size; + + int ret = setupFormats(&format, V4L2Subdevice::TryFormat); + if (ret < 0) { + /* Pipeline configuration failed, skip this configuration. */ + LOG(SimplePipeline, Debug) + << "Media bus code " << utils::hex(code, 4) + << " not supported for this pipeline"; + return; + } + + V4L2VideoDevice::Formats videoFormats = video_->formats(format.mbus_code); + + LOG(SimplePipeline, Debug) + << "Adding configuration for " << format.size + << " in pixel formats [ " + << utils::join(videoFormats, ", ", + [](const auto &f) { + return f.first.toString(); + }) + << " ]"; + + for (const auto &videoFormat : videoFormats) { + PixelFormat pixelFormat = videoFormat.first.toPixelFormat(); + if (!pixelFormat) + continue; + + Configuration config; + config.code = code; + config.captureFormat = pixelFormat; + config.captureSize = format.size; + + if (!converter_) { + config.outputFormats = { pixelFormat }; + config.outputSizes = config.captureSize; + } else { + config.outputFormats = converter_->formats(pixelFormat); + config.outputSizes = converter_->sizes(format.size); + } + + configs_.push_back(config); + } +} + int SimpleCameraData::setupLinks() { int ret;