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);