From patchwork Fri Apr 24 01:16:55 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: 3510 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 AE5CB603F9 for ; Fri, 24 Apr 2020 03:17:06 +0200 (CEST) X-Halon-ID: 495e2c41-85c9-11ea-aeed-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de [79.202.35.146]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 495e2c41-85c9-11ea-aeed-005056917f90; Fri, 24 Apr 2020 03:16:55 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Apr 2020 03:16:55 +0200 Message-Id: <20200424011656.2889720-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200424011656.2889720-1-niklas.soderlund@ragnatech.se> References: <20200424011656.2889720-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] cam: Make use of StreamOptionsParser 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, 24 Apr 2020 01:17:06 -0000 Use the StreamOptionsParser helper to parse stream configuration from the command line. Signed-off-by: Niklas Söderlund --- src/cam/main.cpp | 77 +++++------------------------------------------- 1 file changed, 7 insertions(+), 70 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 718740f49762ec7b..b7cc206e6d5176db 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; @@ -42,7 +43,7 @@ private: int run(); static CamApp *app_; - OptionsParser::Options options_; + StreamOptionsParser::Options options_; CameraManager *cm_; std::shared_ptr camera_; std::unique_ptr config_; @@ -153,18 +154,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); - - OptionsParser parser; + StreamOptionsParser parser; parser.addOption(OptCamera, OptionString, "Specify which camera to operate on, by name or by index", "camera", ArgumentRequired, "camera"); @@ -175,8 +165,7 @@ int CamApp::parseOptions(int argc, char *argv[]) "The first '#' character in the file name is expanded to the stream name and frame sequence number.\n" "The default file name is 'frame-#.bin'.", "file", ArgumentOptional, "filename"); - parser.addOption(OptStream, &streamKeyValue, - "Set configuration of a camera stream", "stream", true); + parser.addStreamOptions(OptStream, "stream"); parser.addOption(OptHelp, OptionNone, "Display this help message", "help"); parser.addOption(OptInfo, OptionNone, @@ -199,67 +188,15 @@ 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); - } - - config_ = camera_->generateConfiguration(roles); - if (!config_ || config_->size() != roles.size()) { + config_ = camera_->generateConfiguration(options_.roles()); + if (!config_ || config_->size() != options_.roles().size()) { std::cerr << "Failed to get default stream configuration" << std::endl; return -EINVAL; } /* 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"]); - } - } + options_.applyCameraParameters(config_.get()); switch (config_->validate()) { case CameraConfiguration::Valid: