From patchwork Wed May 4 13:21:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 15776 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 6643CC3256 for ; Wed, 4 May 2022 13:22:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D969A65656; Wed, 4 May 2022 15:22:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651670523; bh=hE0Dr1CqY/aox8FLLWv/Lak0S2JJYop4QweVrZJxg1A=; 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=WCWiLxnouxs/lDFHQYvvQj6HtIFV+Ju2xf3EE/zWhBOLUx1VXDupVXR8F5/G+fSOx N01Y4NffMjDoKYeQ2aYyEe4A5u0sCTwIbAlGA2tk3W5Nlx7+JgcKZHoz12hOsS3qFm kINZ0LUxNNRvl75S1AfT6/EDoBTihN5QUDFJilcG1ekO5axT6gJ5hkjl8G/SL6jZJ6 zJWbxpWnEN+xcGXUu9+WgwiW/0R88aP+nW7RfAO5vRoTB/G55dIgq9Y3ahcSdMOISp /dLfO4uqtdHAW48lk4vsNFHzvYM0sF2MFqVprCXKYPhO2JLh1v56y254vvvRiIj3mF CrfHOo9BNbLNw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AEDFD65641 for ; Wed, 4 May 2022 15:22:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Ctr296pK"; 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 59AF4835 for ; Wed, 4 May 2022 15:22:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1651670520; bh=hE0Dr1CqY/aox8FLLWv/Lak0S2JJYop4QweVrZJxg1A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ctr296pKSEBjuTRe39rO0gzC8U7JmzTuu7LoSzcntofNzRYIeOO3hq0hqnPyQ70kS x4SVDE952NE0sBi3Kh/wOEHXhkJxuC6YdH5zszOwbQi3aTXIumUy/nd4lQxmRRKsu9 3cri87eRVFl5Y/RuYXPDmjYAGZJZMqbsB2w1zFCw= To: libcamera-devel@lists.libcamera.org Date: Wed, 4 May 2022 16:21:52 +0300 Message-Id: <20220504132154.9681-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220504132154.9681-1-laurent.pinchart@ideasonboard.com> References: <20220504132154.9681-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 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 --- src/libcamera/pipeline/simple/simple.cpp | 110 ++++++++++++----------- 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 4f963df16315..19deb9447c96 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -250,6 +250,9 @@ public: std::queue> converterQueue_; private: + void tryPipeline(unsigned int code, const Size &size); + static std::vector routedSourcePads(MediaPad *sink); + void converterInputDone(FrameBuffer *buffer); void converterOutputDone(FrameBuffer *buffer); }; @@ -466,58 +469,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 +497,58 @@ int SimpleCameraData::init() return 0; } +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;