From patchwork Wed Jun 19 02:51:28 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: 1465 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 CB9A161A31 for ; Wed, 19 Jun 2019 04:52:33 +0200 (CEST) X-Halon-ID: 41478f34-923d-11e9-8ab4-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id 41478f34-923d-11e9-8ab4-005056917a89; Wed, 19 Jun 2019 04:52:20 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 19 Jun 2019 04:51:28 +0200 Message-Id: <20190619025129.21164-16-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190619025129.21164-1-niklas.soderlund@ragnatech.se> References: <20190619025129.21164-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 15/16] cam: Add --info option to print information about stream(s) 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: Wed, 19 Jun 2019 02:52:34 -0000 Add a new option to the cam tool that prints information about the configuration supplied by the user. If the option is specified, information about the configuration is printed after the configuration has been verified and possibly adjusted by the camera. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/main.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ src/cam/main.h | 1 + 2 files changed, 43 insertions(+) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 4e9abf666fedf211..77bb20e9622ec857 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -5,6 +5,7 @@ * main.cpp - cam - The libcamera swiss army knife */ +#include #include #include #include @@ -34,6 +35,7 @@ public: private: int parseOptions(int argc, char *argv[]); int prepareConfig(); + int infoConfiguration(); int run(); static CamApp *app_; @@ -169,6 +171,8 @@ int CamApp::parseOptions(int argc, char *argv[]) "Set configuration of a camera stream", "stream", true); parser.addOption(OptHelp, OptionNone, "Display this help message", "help"); + parser.addOption(OptInfo, OptionNone, + "Display information about stream(s)", "info"); parser.addOption(OptList, OptionNone, "List all cameras", "list"); options_ = parser.parse(argc, argv); @@ -258,8 +262,40 @@ int CamApp::prepareConfig() return 0; } +int CamApp::infoConfiguration() +{ + if (!config_) { + std::cout << "Cannot print stream information without a camera" + << std::endl; + return -EINVAL; + } + + unsigned int index = 0; + for (const StreamConfiguration &cfg : *config_) { + std::cout << index << ": " << cfg.toString() << std::endl; + + const StreamFormats &formats = cfg.formats(); + for (unsigned int pixelformat : formats.pixelformats()) { + std::cout << " * Pixelformat: 0x" << std::hex + << std::setw(8) << pixelformat << " " + << formats.range(pixelformat).toString() + << std::endl; + + for (const Size &size : formats.sizes(pixelformat)) + std::cout << " - " << size.toString() + << std::endl; + } + + index++; + } + + return 0; +} + int CamApp::run() { + int ret; + if (options_.isSet(OptList)) { std::cout << "Available cameras:" << std::endl; @@ -270,6 +306,12 @@ int CamApp::run() } } + if (options_.isSet(OptInfo)) { + ret = infoConfiguration(); + if (ret) + return ret; + } + if (options_.isSet(OptCapture)) { Capture capture(camera_.get(), config_.get()); return capture.run(loop_, options_); diff --git a/src/cam/main.h b/src/cam/main.h index fff81b1f6c860b57..0997476bb335e446 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -12,6 +12,7 @@ enum { OptCapture = 'C', OptFile = 'F', OptHelp = 'h', + OptInfo = 'I', OptList = 'l', OptStream = 's', };