From patchwork Fri May 1 02:34:27 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: 3642 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2683361469 for ; Fri, 1 May 2020 04:34:43 +0200 (CEST) X-Halon-ID: 4f0d3510-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 4f0d3510-8b54-11ea-89d0-0050569116f7; Fri, 01 May 2020 04:34:41 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 1 May 2020 04:34:27 +0200 Message-Id: <20200501023432.90032-2-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 1/6] cam: options: Make KeyValueParser::parse() virtual 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:43 -0000 Prepare for sub-classing of the KeyValueParser by making the parse() method virtual. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cam/options.h b/src/cam/options.h index 5e346b474f765841..ad5c93a4fabd089f 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -71,10 +71,12 @@ public: { }; + virtual ~KeyValueParser() {} + bool addOption(const char *name, OptionType type, const char *help, OptionArgument argument = ArgumentNone); - Options parse(const char *arguments); + virtual Options parse(const char *arguments); void usage(int indent); private: From patchwork Fri May 1 02:34:28 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: 3644 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FB6B6149A for ; Fri, 1 May 2020 04:34:43 +0200 (CEST) X-Halon-ID: 4f4eebda-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 4f4eebda-8b54-11ea-89d0-0050569116f7; Fri, 01 May 2020 04:34:41 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 1 May 2020 04:34:28 +0200 Message-Id: <20200501023432.90032-3-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 2/6] cam: options: Add public method to invalidate options 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:43 -0000 Extend OptionsBase with a public invalidate() method. This allows for further examination of the options and if found unsuitable be invalidated. The intended user for this new interface are subclasses of KeyValueParser. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 6 ++++++ src/cam/options.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 2c56eacf006e9857..77b3cc1f8c5a59e9 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -64,6 +64,12 @@ const OptionValue &OptionsBase::operator[](const T &opt) const return values_.find(opt)->second; } +template +void OptionsBase::invalidate() +{ + valid_ = false; +} + template bool OptionsBase::parseValue(const T &opt, const Option &option, const char *optarg) diff --git a/src/cam/options.h b/src/cam/options.h index ad5c93a4fabd089f..184866195eef990a 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -54,6 +54,8 @@ public: bool isSet(const T &opt) const; const OptionValue &operator[](const T &opt) const; + void invalidate(); + private: friend class KeyValueParser; friend class OptionsParser; From patchwork Fri May 1 02:34:29 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: 3645 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 277FA6148D for ; Fri, 1 May 2020 04:34:44 +0200 (CEST) X-Halon-ID: 4f9a3cbd-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 4f9a3cbd-8b54-11ea-89d0-0050569116f7; Fri, 01 May 2020 04:34:41 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 1 May 2020 04:34:29 +0200 Message-Id: <20200501023432.90032-4-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 3/6] cam: Add helper class to parse stream configuration 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:44 -0000 Create a new helper class StreamKeyValueParser to parse command line options describing stream configurations. The goal is to share this new class between cam and qcam. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v2 - Return bool from parseRole() - s/TODO/\\todo/ - s/!streamParameters.size()/streamParameters.empty()/ - Rework logic in parseRole() --- src/cam/meson.build | 1 + src/cam/stream_options.cpp | 129 +++++++++++++++++++++++++++++++++++++ src/cam/stream_options.h | 32 +++++++++ 3 files changed, 162 insertions(+) create mode 100644 src/cam/stream_options.cpp create mode 100644 src/cam/stream_options.h diff --git a/src/cam/meson.build b/src/cam/meson.build index 2419d648bc17e02b..162d6333f94e4851 100644 --- a/src/cam/meson.build +++ b/src/cam/meson.build @@ -4,6 +4,7 @@ cam_sources = files([ 'event_loop.cpp', 'main.cpp', 'options.cpp', + 'stream_options.cpp', ]) cam = executable('cam', cam_sources, diff --git a/src/cam/stream_options.cpp b/src/cam/stream_options.cpp new file mode 100644 index 0000000000000000..bd12c8fdb48e7135 --- /dev/null +++ b/src/cam/stream_options.cpp @@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd. + * + * stream_options.cpp - Helper to parse options for streams + */ +#include "stream_options.h" + +#include + +using namespace libcamera; + +StreamKeyValueParser::StreamKeyValueParser() +{ + addOption("role", OptionString, + "Role for the stream (viewfinder, video, still, stillraw)", + ArgumentRequired); + addOption("width", OptionInteger, "Width in pixels", + ArgumentRequired); + addOption("height", OptionInteger, "Height in pixels", + ArgumentRequired); + addOption("pixelformat", OptionInteger, "Pixel format", + ArgumentRequired); +} + +KeyValueParser::Options StreamKeyValueParser::parse(const char *arguments) +{ + KeyValueParser::Options options = KeyValueParser::parse(arguments); + StreamRole role; + + if (options.valid() && options.isSet("role") && + !parseRole(&role, options)) { + std::cerr << "Unknown stream role " + << options["role"].toString() << std::endl; + options.invalidate(); + } + + return options; +} + +StreamRoles StreamKeyValueParser::roles(const OptionValue &values) +{ + const std::vector &streamParameters = values.toArray(); + + /* If no configuration values to examine default to viewfinder. */ + if (streamParameters.empty()) + return { StreamRole::Viewfinder }; + + StreamRoles roles; + for (auto const &value : streamParameters) { + KeyValueParser::Options opts = value.toKeyValues(); + StreamRole role; + + /* If role is invalid or not set default to viewfinder. */ + if (!parseRole(&role, value)) + role = StreamRole::Viewfinder; + + roles.push_back(role); + } + + return roles; +} + +int StreamKeyValueParser::updateConfiguration(CameraConfiguration *config, + const OptionValue &values) +{ + const std::vector &streamParameters = values.toArray(); + + if (!config) { + std::cerr << "No configuration provided" << std::endl; + return -EINVAL; + } + + /* If no configuration values nothing to do. */ + if (!streamParameters.size()) + return 0; + + if (config->size() != streamParameters.size()) { + std::cerr + << "Number of streams in configuration " + << config->size() + << " does not match number of streams parsed " + << streamParameters.size() + << std::endl; + return -EINVAL; + } + + unsigned int i = 0; + for (auto const &value : streamParameters) { + KeyValueParser::Options opts = value.toKeyValues(); + StreamConfiguration &cfg = config->at(i++); + + if (opts.isSet("width") && opts.isSet("height")) { + cfg.size.width = opts["width"]; + cfg.size.height = opts["height"]; + } + + /* \todo Translate 4CC string to pixelformat with modifier. */ + if (opts.isSet("pixelformat")) + cfg.pixelFormat = PixelFormat(opts["pixelformat"]); + } + + return 0; +} + +bool StreamKeyValueParser::parseRole(StreamRole *role, + const KeyValueParser::Options &options) +{ + if (!options.isSet("role")) + return false; + + std::string name = options["role"].toString(); + + if (name == "viewfinder") { + *role = StreamRole::Viewfinder; + return true; + } else if (name == "video") { + *role = StreamRole::VideoRecording; + return true; + } else if (name == "still") { + *role = StreamRole::StillCapture; + return true; + } else if (name == "stillraw") { + *role = StreamRole::StillCaptureRaw; + return true; + } + + return false; +} diff --git a/src/cam/stream_options.h b/src/cam/stream_options.h new file mode 100644 index 0000000000000000..577391f05570e85c --- /dev/null +++ b/src/cam/stream_options.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Raspberry Pi (Trading) Ltd. + * + * stream_options.h - Helper to parse options for streams + */ +#ifndef __CAM_STREAM_OPTIONS_H__ +#define __CAM_STREAM_OPTIONS_H__ + +#include + +#include "options.h" + +using namespace libcamera; + +class StreamKeyValueParser : public KeyValueParser +{ +public: + StreamKeyValueParser(); + + KeyValueParser::Options parse(const char *arguments) override; + + static StreamRoles roles(const OptionValue &values); + static int updateConfiguration(CameraConfiguration *config, + const OptionValue &values); + +private: + static bool parseRole(StreamRole *role, + const KeyValueParser::Options &options); +}; + +#endif /* __CAM_STREAM_OPTIONS_H__ */ From patchwork Fri May 1 02:34:30 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: 3646 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AA816614C9 for ; Fri, 1 May 2020 04:34:44 +0200 (CEST) X-Halon-ID: 50003b78-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 50003b78-8b54-11ea-89d0-0050569116f7; Fri, 01 May 2020 04:34:42 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 1 May 2020 04:34:30 +0200 Message-Id: <20200501023432.90032-5-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 4/6] cam: 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 StreamOptionsParser helper to parse stream configuration from the command line. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v2 - Add log message --- src/cam/main.cpp | 68 +++++------------------------------------------- 1 file changed, 7 insertions(+), 61 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index ced4f567b8f38e00..2512fe9da782165b 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -17,6 +17,7 @@ #include "event_loop.h" #include "main.h" #include "options.h" +#include "stream_options.h" using namespace libcamera; @@ -154,16 +155,7 @@ void CamApp::quit() int CamApp::parseOptions(int argc, char *argv[]) { - KeyValueParser streamKeyValue; - streamKeyValue.addOption("role", OptionString, - "Role for the stream (viewfinder, video, still, stillraw)", - ArgumentRequired); - streamKeyValue.addOption("width", OptionInteger, "Width in pixels", - ArgumentRequired); - streamKeyValue.addOption("height", OptionInteger, "Height in pixels", - ArgumentRequired); - streamKeyValue.addOption("pixelformat", OptionInteger, "Pixel format", - ArgumentRequired); + StreamKeyValueParser streamKeyValue; OptionsParser parser; parser.addOption(OptCamera, OptionString, @@ -202,38 +194,7 @@ int CamApp::parseOptions(int argc, char *argv[]) int CamApp::prepareConfig() { - StreamRoles roles; - - if (options_.isSet(OptStream)) { - const std::vector &streamOptions = - options_[OptStream].toArray(); - - /* Use roles and get a default configuration. */ - for (auto const &value : streamOptions) { - KeyValueParser::Options opt = value.toKeyValues(); - - std::string role = opt.isSet("role") - ? opt["role"].toString() - : "viewfinder"; - - if (role == "viewfinder") { - roles.push_back(StreamRole::Viewfinder); - } else if (role == "video") { - roles.push_back(StreamRole::VideoRecording); - } else if (role == "still") { - roles.push_back(StreamRole::StillCapture); - } else if (role == "stillraw") { - roles.push_back(StreamRole::StillCaptureRaw); - } else { - std::cerr << "Unknown stream role " - << role << std::endl; - return -EINVAL; - } - } - } else { - /* If no configuration is provided assume a single video stream. */ - roles.push_back(StreamRole::VideoRecording); - } + StreamRoles roles = StreamKeyValueParser::roles(options_[OptStream]); config_ = camera_->generateConfiguration(roles); if (!config_ || config_->size() != roles.size()) { @@ -243,25 +204,10 @@ int CamApp::prepareConfig() } /* Apply configuration if explicitly requested. */ - if (options_.isSet(OptStream)) { - const std::vector &streamOptions = - options_[OptStream].toArray(); - - unsigned int i = 0; - for (auto const &value : streamOptions) { - KeyValueParser::Options opt = value.toKeyValues(); - StreamConfiguration &cfg = config_->at(i++); - - if (opt.isSet("width")) - cfg.size.width = opt["width"]; - - if (opt.isSet("height")) - cfg.size.height = opt["height"]; - - /* TODO: Translate 4CC string to ID. */ - if (opt.isSet("pixelformat")) - cfg.pixelFormat = PixelFormat(opt["pixelformat"]); - } + if (StreamKeyValueParser::updateConfiguration(config_.get(), + options_[OptStream])) { + std::cerr << "Failed to update configuration" << std::endl; + return -EINVAL; } switch (config_->validate()) { 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', ]) From patchwork Fri May 1 02:34:32 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: 3648 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D47606148D for ; Fri, 1 May 2020 04:34:45 +0200 (CEST) X-Halon-ID: 50ba9d6b-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 50ba9d6b-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:32 +0200 Message-Id: <20200501023432.90032-7-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 6/6] qcam: Check that camera can generate configuration from roles 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 If the camera can not generate a configuration from the requested roles it returns a nullptr which leads to a nullptr dereference. Fix this by adding a check that the camera generated a configuration before trying to access it. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/qcam/main_window.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 74427592ea47de28..b9348111dfa28914 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -296,6 +296,10 @@ int MainWindow::startCapture() /* Configure the camera. */ config_ = camera_->generateConfiguration(roles); + if (!config_) { + qWarning() << "Failed to generate configuration from roles"; + return -EINVAL; + } StreamConfiguration &cfg = config_->at(0);