From patchwork Mon May 20 12:01:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20080 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 229B2BDE6B for ; Mon, 20 May 2024 12:01:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AAEF06347F; Mon, 20 May 2024 14:01:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="r9W3h7Zv"; dkim-atps=neutral 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 623AA61A58 for ; Mon, 20 May 2024 14:01:19 +0200 (CEST) Received: from fedora.local (unknown [IPv6:2405:201:2015:f873:c173:4b:4a04:3a21]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 785CAC67; Mon, 20 May 2024 14:01:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1716206468; bh=M0bUn3sLO2cAs+46gPIvIjFfXiJJRiFv6bNkrFznt1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r9W3h7ZvOAbauvL37MxkQx0HnO56xCs8OAiHlI1oZx2mp3QJRxgdFe2poo9P71Cgg dFr1D+17FeYKyeQxJySZfJqZTvq3n2QY8blIF3vNo3YXbVl/p1HpqCMYkeD2sQajh+ NdUhfa+5dhtsGYL6xtTGDMTZGz3uH6NTQKhC3TwI= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Paul Elder Subject: [PATCH 1/2] apps: cam: Add option to configure sensor Date: Mon, 20 May 2024 17:31:09 +0530 Message-ID: <20240520120110.110067-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240520120110.110067-1-umang.jain@ideasonboard.com> References: <20240520120110.110067-1-umang.jain@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: Jacopo Mondi 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 Signed-off-by: Paul Elder --- 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 f13355ba..a51dcfbc 100644 --- a/src/apps/cam/camera_session.cpp +++ b/src/apps/cam/camera_session.cpp @@ -90,6 +90,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 4f87f200..0f751469 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, @@ -178,6 +179,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 64e6a20e..65844ac5 100644 --- a/src/apps/cam/main.h +++ b/src/apps/cam/main.h @@ -20,6 +20,7 @@ enum { OptOrientation = 'o', 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 99239e07..55a2d3d2 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 a93f104c..f1020d8c 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); +}; From patchwork Mon May 20 12:01:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 20081 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 EA5C4C322E for ; Mon, 20 May 2024 12:01:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B6CCE63481; Mon, 20 May 2024 14:01:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mkKda7Bt"; dkim-atps=neutral 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 E71DB63481 for ; Mon, 20 May 2024 14:01:20 +0200 (CEST) Received: from fedora.local (unknown [IPv6:2405:201:2015:f873:c173:4b:4a04:3a21]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ABB36593; Mon, 20 May 2024 14:01:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1716206469; bh=bYFUcPzCfZYsOxJmEAwN9C8yVOH0QZ40cxlffmO0zLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mkKda7BtaslyQmUyN1T5bOMbBeM6U9U6ZE/3G1SjBZ2Zu6VxQT5Hm9aM1abWwaCji ASR7gfazUgSUDGkF2aSN9bfjr8eppwVQCQR+X1EZJE5qz4tWD0T/TWoYqBj/oNN8LK U+PkdXuC55npTWmi+MlQGXdvK7jiWQ6VFv0olkgE= From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Paul Elder Subject: [PATCH 2/2] apps: qcam: Add option to configure sensor Date: Mon, 20 May 2024 17:31:10 +0530 Message-ID: <20240520120110.110067-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240520120110.110067-1-umang.jain@ideasonboard.com> References: <20240520120110.110067-1-umang.jain@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: Kieran Bingham Add a '-f|--sensor_format' option to qcam to allow forcing a sensor configuration from the command line. As an example: qcam -f width=3840,height=2160,bitDepth=10 Signed-off-by: Kieran Bingham Signed-off-by: Paul Elder --- src/apps/qcam/main.cpp | 3 +++ src/apps/qcam/main_window.cpp | 7 +++++++ src/apps/qcam/main_window.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/apps/qcam/main.cpp b/src/apps/qcam/main.cpp index 9846fba5..2d0d0c5f 100644 --- a/src/apps/qcam/main.cpp +++ b/src/apps/qcam/main.cpp @@ -30,6 +30,7 @@ void signalHandler([[maybe_unused]] int signal) OptionsParser::Options parseOptions(int argc, char *argv[]) { StreamKeyValueParser streamKeyValue; + SensorKeyValueParser sensorKeyValue; OptionsParser parser; parser.addOption(OptCamera, OptionString, @@ -42,6 +43,8 @@ OptionsParser::Options parseOptions(int argc, char *argv[]) "renderer", ArgumentRequired, "renderer"); parser.addOption(OptStream, &streamKeyValue, "Set configuration of a camera stream", "stream", true); + parser.addOption(OptSensorFmt, &sensorKeyValue, + "Apply a format to the sensor", "sensor_format", true); parser.addOption(OptVerbose, OptionNone, "Print verbose log messages", "verbose"); diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp index d515beed..aa725344 100644 --- a/src/apps/qcam/main_window.cpp +++ b/src/apps/qcam/main_window.cpp @@ -414,6 +414,13 @@ int MainWindow::startCapture() return -EINVAL; } + /* Apply a sensor configuration if requested. */ + if (SensorKeyValueParser::updateConfiguration(config_.get(), + options_[OptSensorFmt])) { + qWarning() << "Failed to apply sensor configuration"; + return -EINVAL; + } + CameraConfiguration::Status validation = config_->validate(); if (validation == CameraConfiguration::Invalid) { qWarning() << "Failed to create valid camera configuration"; diff --git a/src/apps/qcam/main_window.h b/src/apps/qcam/main_window.h index 4cead734..60c46388 100644 --- a/src/apps/qcam/main_window.h +++ b/src/apps/qcam/main_window.h @@ -42,6 +42,7 @@ enum { OptHelp = 'h', OptRenderer = 'r', OptStream = 's', + OptSensorFmt = 'f', OptVerbose = 'v', };