From patchwork Thu Sep 21 16:55:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 19077 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 C2F80C32B0 for ; Thu, 21 Sep 2023 16:56:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7DA6C62963; Thu, 21 Sep 2023 18:56:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1695315375; bh=LOO4pFx1IRYfHHjHm+nfzSRXK168AXtwhSnNX5UrCIY=; 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=FegbitA24tyk+46IhVmfreVWwQ7MGv5l+yAXT/862Ms5hT2KFj2I9VSMF7kyENWpK F5Xv74eC9aX0WEjgxdQseLUylbVcmcRqc9VVpa66uo99j5hQpUJ/aCWNQ7Wf1Ynort Z/QuPofC5eGpN7qqA7oE+mXVT6wvJ1AArkubpXeWWNLlvLGiuNNuQJFmeE8I8OqI3B jAhcXc07gvWrzc8KZFywUyxeuXhTQkPVV3JijL9deKVgsyOMLzTD5+wubQRw1i18SV TIBY0nOYcbi5UdGMenETFKWCv1ICnSUQ/ifMDIkowJXzqEFJtHGE5N4Xg4kLTv+TeE AvWD7DPGOZVCw== 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 B94D162948 for ; Thu, 21 Sep 2023 18:56:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KS3DEZPr"; dkim-atps=neutral Received: from uno.lan (93-46-82-201.ip106.fastwebnet.it [93.46.82.201]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0865E1102; Thu, 21 Sep 2023 18:54:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1695315269; bh=LOO4pFx1IRYfHHjHm+nfzSRXK168AXtwhSnNX5UrCIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KS3DEZPr/xmrMZueQE5QQIlBIO/nT+Hf12bM+QH1oUGMATNJbb6cZl1wvJdOdN6Mb b2j2bhGCCQjPnxsbwDdJqrwUNO8dKpWQ9P0c31v6gG9SPIkJ4VtSag/wgleKe562TS XQETTqXOP1x45guGZRV1rsFE9zw5pi6f5QPbSmco= To: libcamera-devel@lists.libcamera.org Date: Thu, 21 Sep 2023 18:55:50 +0200 Message-ID: <20230921165550.50956-14-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230921165550.50956-1-jacopo.mondi@ideasonboard.com> References: <20230921165550.50956-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 13/13] apps: cam: Add option to configure sensor 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: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a '-f|--sensor_format' option to cam to allow forcing a sensor configuration from the command line. As an example: cam -c1 -C -S --stream pixelformat=YUYV -f width=3840,height=2160,bitDepth=10 Signed-off-by: Jacopo Mondi --- src/apps/cam/camera_session.cpp | 7 +++++ src/apps/cam/main.cpp | 4 +++ src/apps/cam/main.h | 1 + src/apps/common/stream_options.cpp | 42 ++++++++++++++++++++++++++++++ src/apps/common/stream_options.h | 8 ++++++ 5 files changed, 62 insertions(+) diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp index 066e397b5f47..4e01ebdc3e90 100644 --- a/src/apps/cam/camera_session.cpp +++ b/src/apps/cam/camera_session.cpp @@ -72,6 +72,13 @@ CameraSession::CameraSession(CameraManager *cm, return; } + /* Apply a sensor configuration is requested. */ + if (SensorKeyValueParser::updateConfiguration(config.get(), + options_[OptSensorFmt])) { + std::cerr << "Failed to apply sensor configuration" << std::endl; + return; + } + bool strictFormats = options_.isSet(OptStrictFormats); #ifdef HAVE_KMS diff --git a/src/apps/cam/main.cpp b/src/apps/cam/main.cpp index 5d8a57bc14e5..d15ee875d6b8 100644 --- a/src/apps/cam/main.cpp +++ b/src/apps/cam/main.cpp @@ -110,6 +110,7 @@ void CamApp::quit() int CamApp::parseOptions(int argc, char *argv[]) { StreamKeyValueParser streamKeyValue; + SensorKeyValueParser sensorKeyValue; OptionsParser parser; parser.addOption(OptCamera, OptionString, @@ -171,6 +172,9 @@ int CamApp::parseOptions(int argc, char *argv[]) "Load a capture session configuration script from a file", "script", ArgumentRequired, "script", false, OptCamera); + parser.addOption(OptSensorFmt, &sensorKeyValue, + "Apply a format to the sensor", "sensor_format", true, + OptCamera); options_ = parser.parse(argc, argv); if (!options_.valid()) diff --git a/src/apps/cam/main.h b/src/apps/cam/main.h index 526aecece3f3..1432cfeb5052 100644 --- a/src/apps/cam/main.h +++ b/src/apps/cam/main.h @@ -19,6 +19,7 @@ enum { OptMonitor = 'm', OptSDL = 'S', OptStream = 's', + OptSensorFmt = 'f', OptListControls = 256, OptStrictFormats = 257, OptMetadata = 258, diff --git a/src/apps/common/stream_options.cpp b/src/apps/common/stream_options.cpp index 663b979aa763..a61317ab7fad 100644 --- a/src/apps/common/stream_options.cpp +++ b/src/apps/common/stream_options.cpp @@ -119,3 +119,45 @@ std::optional StreamKeyValueParser::parseRole(const KeyVa return {}; } + +SensorKeyValueParser::SensorKeyValueParser() +{ + addOption("bitDepth", OptionInteger, "Sensor format bit depth", + ArgumentRequired); + addOption("width", OptionInteger, "Sensor frame width in pixels", + ArgumentRequired); + addOption("height", OptionInteger, "Sensor frame height in pixels", + ArgumentRequired); +} + +int SensorKeyValueParser::updateConfiguration(CameraConfiguration *config, + const OptionValue &values) +{ + if (!config) { + std::cerr << "No configuration provided" << std::endl; + return -EINVAL; + } + + /* If no configuration values nothing to do. */ + if (values.empty()) + return 0; + + const std::vector &streamParameters = values.toArray(); + SensorConfiguration sensorConfig; + + for (auto const &value : streamParameters) { + KeyValueParser::Options opts = value.toKeyValues(); + + if (opts.isSet("width") && opts.isSet("height")) { + sensorConfig.outputSize.width = opts["width"]; + sensorConfig.outputSize.height = opts["height"]; + } + + if (opts.isSet("bitDepth")) + sensorConfig.bitDepth = opts["bitDepth"]; + } + + config->sensorConfig = sensorConfig; + + return 0; +} diff --git a/src/apps/common/stream_options.h b/src/apps/common/stream_options.h index a5f3bde08da8..a338206bd005 100644 --- a/src/apps/common/stream_options.h +++ b/src/apps/common/stream_options.h @@ -27,3 +27,11 @@ public: private: static std::optional parseRole(const KeyValueParser::Options &options); }; + +class SensorKeyValueParser : public KeyValueParser +{ +public: + SensorKeyValueParser(); + static int updateConfiguration(libcamera::CameraConfiguration *config, + const OptionValue &values); +};