From patchwork Fri Mar 22 01:53:46 2019 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: 779 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 96B21610B3 for ; Fri, 22 Mar 2019 02:54:07 +0100 (CET) X-Halon-ID: 5fb2d256-4c45-11e9-985a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 5fb2d256-4c45-11e9-985a-005056917f90; Fri, 22 Mar 2019 02:54:05 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Mar 2019 02:53:46 +0100 Message-Id: <20190322015349.14934-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> References: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/4] cam: options: Create own enum for OptionValue types X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Mar 2019 01:54:07 -0000 In preparation to add support specifying the same option multiple times create a own enum for the OptionValue types as it will diverge from the one shared one. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 16 ++++++++-------- src/cam/options.h | 11 +++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 655aa36bb9c93b85..497833397d894f82 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -248,27 +248,27 @@ void KeyValueParser::usage(int indent) */ OptionValue::OptionValue() - : type_(OptionNone) + : type_(ValueNone) { } OptionValue::OptionValue(int value) - : type_(OptionInteger), integer_(value) + : type_(ValueInteger), integer_(value) { } OptionValue::OptionValue(const char *value) - : type_(OptionString), string_(value) + : type_(ValueString), string_(value) { } OptionValue::OptionValue(const std::string &value) - : type_(OptionString), string_(value) + : type_(ValueString), string_(value) { } OptionValue::OptionValue(const KeyValueParser::Options &value) - : type_(OptionKeyValue), keyValues_(value) + : type_(ValueKeyValue), keyValues_(value) { } @@ -289,7 +289,7 @@ OptionValue::operator KeyValueParser::Options() const int OptionValue::toInteger() const { - if (type_ != OptionInteger) + if (type_ != ValueInteger) return 0; return integer_; @@ -297,7 +297,7 @@ int OptionValue::toInteger() const std::string OptionValue::toString() const { - if (type_ != OptionString) + if (type_ != ValueString) return std::string(); return string_; @@ -305,7 +305,7 @@ std::string OptionValue::toString() const KeyValueParser::Options OptionValue::toKeyValues() const { - if (type_ != OptionKeyValue) + if (type_ != ValueKeyValue) return KeyValueParser::Options(); return keyValues_; diff --git a/src/cam/options.h b/src/cam/options.h index 745f4a4a3a433f9e..b33a90fc6058febf 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -79,13 +79,20 @@ private: class OptionValue { public: + enum ValueType { + ValueNone, + ValueInteger, + ValueString, + ValueKeyValue, + }; + OptionValue(); OptionValue(int value); OptionValue(const char *value); OptionValue(const std::string &value); OptionValue(const KeyValueParser::Options &value); - OptionType type() const { return type_; } + ValueType type() const { return type_; } operator int() const; operator std::string() const; @@ -96,7 +103,7 @@ public: KeyValueParser::Options toKeyValues() const; private: - OptionType type_; + ValueType type_; int integer_; std::string string_; KeyValueParser::Options keyValues_; From patchwork Fri Mar 22 01:53:47 2019 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: 780 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BECB36110A for ; Fri, 22 Mar 2019 02:54:07 +0100 (CET) X-Halon-ID: 600d7062-4c45-11e9-985a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 600d7062-4c45-11e9-985a-005056917f90; Fri, 22 Mar 2019 02:54:06 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Mar 2019 02:53:47 +0100 Message-Id: <20190322015349.14934-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> References: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 2/4] cam: options: Add an array data type to OptionValue X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Mar 2019 01:54:08 -0000 To allow specifying the same argument option multiple times a new type of OptionValue is needed. As parsing of options is an iterative process there is a need to append options as they are parsed so a more complex constructor us needed which can combine already stored instances of an option with new ones. Signed-off-by: Niklas Söderlund --- src/cam/options.cpp | 21 +++++++++++++++++++++ src/cam/options.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 497833397d894f82..7995a9b359764ec7 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -272,6 +272,14 @@ OptionValue::OptionValue(const KeyValueParser::Options &value) { } +OptionValue::OptionValue(const OptionValue &value, + const std::vector &array) + : type_(ValueArray) +{ + array_ = array; + array_.push_back(value); +} + OptionValue::operator int() const { return toInteger(); @@ -287,6 +295,11 @@ OptionValue::operator KeyValueParser::Options() const return toKeyValues(); } +OptionValue::operator std::vector() const +{ + return toArray(); +} + int OptionValue::toInteger() const { if (type_ != ValueInteger) @@ -311,6 +324,14 @@ KeyValueParser::Options OptionValue::toKeyValues() const return keyValues_; } +std::vector OptionValue::toArray() const +{ + if (type_ != ValueArray) + return std::vector{}; + + return array_; +} + /* ----------------------------------------------------------------------------- * OptionsParser */ diff --git a/src/cam/options.h b/src/cam/options.h index b33a90fc6058febf..789ba36187dd1fc3 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -10,6 +10,7 @@ #include #include #include +#include class KeyValueParser; class OptionValue; @@ -84,6 +85,7 @@ public: ValueInteger, ValueString, ValueKeyValue, + ValueArray, }; OptionValue(); @@ -91,22 +93,26 @@ public: OptionValue(const char *value); OptionValue(const std::string &value); OptionValue(const KeyValueParser::Options &value); + OptionValue(const OptionValue &value, const std::vector &array); ValueType type() const { return type_; } operator int() const; operator std::string() const; operator KeyValueParser::Options() const; + operator std::vector() const; int toInteger() const; std::string toString() const; KeyValueParser::Options toKeyValues() const; + std::vector toArray() const; private: ValueType type_; int integer_; std::string string_; KeyValueParser::Options keyValues_; + std::vector array_; }; class OptionsParser From patchwork Fri Mar 22 01:53:48 2019 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: 781 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 43BAE610B3 for ; Fri, 22 Mar 2019 02:54:09 +0100 (CET) X-Halon-ID: 6069ab50-4c45-11e9-985a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 6069ab50-4c45-11e9-985a-005056917f90; Fri, 22 Mar 2019 02:54:06 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Mar 2019 02:53:48 +0100 Message-Id: <20190322015349.14934-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> References: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 3/4] cam: options: Add parsing of multiple instances of the same option X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Mar 2019 01:54:10 -0000 Add the ability to allow storing multiple instances of the same option. Signed-off-by: Niklas Söderlund --- src/cam/options.cpp | 12 ++++++------ src/cam/options.h | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 7995a9b359764ec7..e9dcd0c39cdc50ce 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -96,7 +96,7 @@ bool OptionsBase::parseValue(const T &opt, const Option &option, break; } - values_[opt] = value; + values_[opt] = option.array ? OptionValue(value, values_[opt]) : value; return true; } @@ -128,7 +128,7 @@ bool KeyValueParser::addOption(const char *name, OptionType type, return false; optionsMap_[name] = Option({ 0, type, name, argument, nullptr, - help, nullptr }); + help, nullptr, false }); return true; } @@ -338,7 +338,7 @@ std::vector OptionValue::toArray() const bool OptionsParser::addOption(int opt, OptionType type, const char *help, const char *name, OptionArgument argument, - const char *argumentName) + const char *argumentName, bool array) { /* * Options must have at least a short or long name, and a text message. @@ -356,16 +356,16 @@ bool OptionsParser::addOption(int opt, OptionType type, const char *help, return false; options_.push_back(Option({ opt, type, name, argument, argumentName, - help, nullptr })); + help, nullptr, array })); optionsMap_[opt] = &options_.back(); return true; } bool OptionsParser::addOption(int opt, KeyValueParser *parser, const char *help, - const char *name) + const char *name, bool array) { if (!addOption(opt, OptionKeyValue, help, name, ArgumentRequired, - "key=value[,key=value,...]")) + "key=value[,key=value,...]", array)) return false; options_.back().keyValueParser = parser; diff --git a/src/cam/options.h b/src/cam/options.h index 789ba36187dd1fc3..922db4650b49117d 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -36,6 +36,7 @@ struct Option { const char *argumentName; const char *help; KeyValueParser *keyValueParser; + bool array; bool hasShortOption() const { return isalnum(opt); } bool hasLongOption() const { return name != nullptr; } @@ -125,9 +126,9 @@ public: bool addOption(int opt, OptionType type, const char *help, const char *name = nullptr, OptionArgument argument = ArgumentNone, - const char *argumentName = nullptr); + const char *argumentName = nullptr, bool array = false); bool addOption(int opt, KeyValueParser *parser, const char *help, - const char *name = nullptr); + const char *name = nullptr, bool array = false); Options parse(int argc, char *argv[]); void usage(); From patchwork Fri Mar 22 01:53:49 2019 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: 782 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8D384611AB for ; Fri, 22 Mar 2019 02:54:09 +0100 (CET) X-Halon-ID: 6166268b-4c45-11e9-985a-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 6166268b-4c45-11e9-985a-005056917f90; Fri, 22 Mar 2019 02:54:08 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Mar 2019 02:53:49 +0100 Message-Id: <20190322015349.14934-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> References: <20190322015349.14934-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 4/4] cam: Allow specifying configuration for more then one stream X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Mar 2019 01:54:11 -0000 As a step to allow multiple streams extend the cam tool to be able to configure more then one stream. At this point libcamera do not allow an application to associate a stream with a intended use-case so instead add a 'id' field to the --format parser. The numerical id represent the order in the array of streams which are handed to the application from the library. This should change once the library learns stream use-case. This implementation is a small and incomplete step in the direction of extending the cam utility to support cameras with more then one stream. Signed-off-by: Niklas Söderlund --- src/cam/main.cpp | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 1ca7862bf237d85f..c9239ac62a83ce31 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -42,6 +42,8 @@ void signalHandler(int signal) static int parseOptions(int argc, char *argv[]) { KeyValueParser formatKeyValue; + formatKeyValue.addOption("id", OptionInteger, "ID of stream", + ArgumentRequired); formatKeyValue.addOption("width", OptionInteger, "Width in pixels", ArgumentRequired); formatKeyValue.addOption("height", OptionInteger, "Height in pixels", @@ -61,7 +63,7 @@ static int parseOptions(int argc, char *argv[]) "The default file name is 'frame-#.bin'.", "file", ArgumentOptional, "filename"); parser.addOption(OptFormat, &formatKeyValue, - "Set format of the camera's first stream", "format"); + "Set format of the camera's first stream", "format", true); parser.addOption(OptHelp, OptionNone, "Display this help message", "help"); parser.addOption(OptList, OptionNone, "List all cameras", "list"); @@ -77,22 +79,37 @@ static int parseOptions(int argc, char *argv[]) static int configureStreams(Camera *camera, std::set &streams) { - KeyValueParser::Options format = options[OptFormat]; - Stream *id = *streams.begin(); - std::map config = camera->streamConfiguration(streams); if (options.isSet(OptFormat)) { - if (format.isSet("width")) - config[id].width = format["width"]; + int num = 0; + for (Stream *id : streams) { + for (auto const &value : options[OptFormat].toArray()) { + KeyValueParser::Options format = value.toKeyValues(); - if (format.isSet("height")) - config[id].height = format["height"]; + if (!format.isSet("id") || format["id"] != num) + continue; - /* TODO: Translate 4CC string to ID. */ - if (format.isSet("pixelformat")) - config[id].pixelFormat = format["pixelformat"]; + if (format.isSet("width")) + config[id].width = format["width"]; + + if (format.isSet("height")) + config[id].height = format["height"]; + + /* TODO: Translate 4CC string to ID. */ + if (format.isSet("pixelformat")) + config[id].pixelFormat = format["pixelformat"]; + } + num++; + } + } + + for (auto const &it : config) { + const StreamConfiguration &conf = it.second; + + std::cout << "size: " << conf.width << "x" << conf.height + << "pixelformat: " << conf.pixelFormat << std::endl; } return camera->configureStreams(config);