From patchwork Fri May 1 02:34:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 3647 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4E612614BC for ; Fri, 1 May 2020 04:34:45 +0200 (CEST) X-Halon-ID: 505b946d-8b54-11ea-89d0-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 505b946d-8b54-11ea-89d0-0050569116f7; Fri, 01 May 2020 04:34:43 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 1 May 2020 04:34:31 +0200 Message-Id: <20200501023432.90032-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200501023432.90032-1-niklas.soderlund@ragnatech.se> References: <20200501023432.90032-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 5/6] qcam: Make use of StreamKeyValueParser 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-List-Received-Date: Fri, 01 May 2020 02:34:46 -0000 Use the StreamKeyValueParser helper to parse stream configuration from the command line. This extends qcam to accept role hints and pixel format in addition to a size. Currently only one viewfinder stream is supported, add a check to keep this behavior. Going forward this restriction will be lifted to support more then one stream. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v2 - Add log messages --- src/qcam/main.cpp | 13 +++++-------- src/qcam/main_window.cpp | 37 ++++++++++++++++++++----------------- src/qcam/main_window.h | 4 ++-- src/qcam/meson.build | 1 + 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp index 862d714f467c04f9..b3468cbf47e28894 100644 --- a/src/qcam/main.cpp +++ b/src/qcam/main.cpp @@ -13,8 +13,9 @@ #include -#include "main_window.h" #include "../cam/options.h" +#include "../cam/stream_options.h" +#include "main_window.h" void signalHandler(int signal) { @@ -24,11 +25,7 @@ void signalHandler(int signal) OptionsParser::Options parseOptions(int argc, char *argv[]) { - KeyValueParser sizeParser; - sizeParser.addOption("width", OptionInteger, "Width in pixels", - ArgumentRequired); - sizeParser.addOption("height", OptionInteger, "Height in pixels", - ArgumentRequired); + StreamKeyValueParser streamKeyValue; OptionsParser parser; parser.addOption(OptCamera, OptionString, @@ -36,8 +33,8 @@ OptionsParser::Options parseOptions(int argc, char *argv[]) ArgumentRequired, "camera"); parser.addOption(OptHelp, OptionNone, "Display this help message", "help"); - parser.addOption(OptSize, &sizeParser, "Set the stream size", - "size", true); + parser.addOption(OptStream, &streamKeyValue, + "Set configuration of a camera stream", "stream", true); OptionsParser::Options options = parser.parse(argc, argv); if (options.isSet(OptHelp)) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 5a2ac699f349f7cc..74427592ea47de28 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -280,29 +280,25 @@ void MainWindow::toggleCapture(bool start) */ int MainWindow::startCapture() { + StreamRoles roles = StreamKeyValueParser::roles(options_[OptStream]); int ret; + /* Verify roles are supported. */ + if (roles.size() != 1) { + qCritical() << "Only one stream supported"; + return -EINVAL; + } + + if (roles[0] != StreamRole::Viewfinder) { + qCritical() << "Only viewfinder supported"; + return -EINVAL; + } + /* Configure the camera. */ - config_ = camera_->generateConfiguration({ StreamRole::Viewfinder }); + config_ = camera_->generateConfiguration(roles); StreamConfiguration &cfg = config_->at(0); - if (options_.isSet(OptSize)) { - const std::vector &sizeOptions = - options_[OptSize].toArray(); - - /* Set desired stream size if requested. */ - for (const auto &value : sizeOptions) { - KeyValueParser::Options opt = value.toKeyValues(); - - if (opt.isSet("width")) - cfg.size.width = opt["width"]; - - if (opt.isSet("height")) - cfg.size.height = opt["height"]; - } - } - /* Use a format supported by the viewfinder if available. */ std::vector formats = cfg.formats().pixelformats(); for (const PixelFormat &format : viewfinder_->nativeFormats()) { @@ -316,6 +312,13 @@ int MainWindow::startCapture() } } + /* Allow user to override configuration. */ + if (StreamKeyValueParser::updateConfiguration(config_.get(), + options_[OptStream])) { + qWarning() << "Failed to update configuration"; + return -EINVAL; + } + CameraConfiguration::Status validation = config_->validate(); if (validation == CameraConfiguration::Invalid) { qWarning() << "Failed to create valid camera configuration"; diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 4ec37d40e1cff495..aea1f1dee20fcbb6 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -23,7 +23,7 @@ #include #include -#include "../cam/options.h" +#include "../cam/stream_options.h" #include "viewfinder.h" using namespace libcamera; @@ -34,7 +34,7 @@ class QComboBox; enum { OptCamera = 'c', OptHelp = 'h', - OptSize = 's', + OptStream = 's', }; class MainWindow : public QMainWindow diff --git a/src/qcam/meson.build b/src/qcam/meson.build index c256d06f8ccfc0ae..895264be4a3388f4 100644 --- a/src/qcam/meson.build +++ b/src/qcam/meson.build @@ -3,6 +3,7 @@ qcam_sources = files([ 'main.cpp', 'main_window.cpp', '../cam/options.cpp', + '../cam/stream_options.cpp', 'viewfinder.cpp', ])