From patchwork Fri Jul 24 19:18:49 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: 8988 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 01AE6BD86F for ; Fri, 24 Jul 2020 19:19:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 754F66124D; Fri, 24 Jul 2020 21:19:18 +0200 (CEST) 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 1CDB66039B for ; Fri, 24 Jul 2020 21:19:17 +0200 (CEST) X-Halon-ID: 6709cb93-cde2-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 6709cb93-cde2-11ea-86ee-0050569116f7; Fri, 24 Jul 2020 21:18:06 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jul 2020 21:18:49 +0200 Message-Id: <20200724191851.803350-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724191851.803350-1-niklas.soderlund@ragnatech.se> References: <20200724191851.803350-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/3] cam: Add option to disallow adjusting of requested formats 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a '--strict-formats' option which fails the camera configuration step if the format is adjusted, Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- * Changes since v2 - Update logged messages to mention --strict-formats argument. * Changes since v1 - Fix spelling in comment and log outputs. --- src/cam/main.cpp | 17 ++++++++++++++++- src/cam/main.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 2512fe9da782165b..ead0abe3e2abf42d 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -49,12 +49,15 @@ private: std::shared_ptr camera_; std::unique_ptr config_; EventLoop *loop_; + + bool strictFormats_; }; CamApp *CamApp::app_ = nullptr; CamApp::CamApp() - : cm_(nullptr), camera_(nullptr), config_(nullptr), loop_(nullptr) + : cm_(nullptr), camera_(nullptr), config_(nullptr), loop_(nullptr), + strictFormats_(false) { CamApp::app_ = this; } @@ -77,6 +80,9 @@ int CamApp::init(int argc, char **argv) if (ret < 0) return ret; + if (options_.isSet(OptStrictFormats)) + strictFormats_ = true; + cm_ = new CameraManager(); ret = cm_->start(); @@ -179,6 +185,9 @@ int CamApp::parseOptions(int argc, char *argv[]) "list-controls"); parser.addOption(OptListProperties, OptionNone, "List cameras properties", "list-properties"); + parser.addOption(OptStrictFormats, OptionNone, + "Do not allow requested stream format(s) to be adjusted", + "strict-formats"); options_ = parser.parse(argc, argv); if (!options_.valid()) @@ -214,6 +223,12 @@ int CamApp::prepareConfig() case CameraConfiguration::Valid: break; case CameraConfiguration::Adjusted: + if (strictFormats_) { + std::cout << "Adjusting camera configuration disallowed by --strict-formats argument" + << std::endl; + config_.reset(); + return -EINVAL; + } std::cout << "Camera configuration adjusted" << std::endl; break; case CameraConfiguration::Invalid: diff --git a/src/cam/main.h b/src/cam/main.h index 4a130d8dd2906ad4..6f95add31a6341cf 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -17,6 +17,7 @@ enum { OptListProperties = 'p', OptStream = 's', OptListControls = 256, + OptStrictFormats = 257, }; #endif /* __CAM_MAIN_H__ */ From patchwork Fri Jul 24 19:18:50 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: 8989 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2A6F9BD86F for ; Fri, 24 Jul 2020 19:19:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 04AC36124B; Fri, 24 Jul 2020 21:19:22 +0200 (CEST) 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 C95E961212 for ; Fri, 24 Jul 2020 21:19:17 +0200 (CEST) X-Halon-ID: 67743bf7-cde2-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 67743bf7-cde2-11ea-86ee-0050569116f7; Fri, 24 Jul 2020 21:18:07 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jul 2020 21:18:50 +0200 Message-Id: <20200724191851.803350-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724191851.803350-1-niklas.soderlund@ragnatech.se> References: <20200724191851.803350-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/3] cam: capture: Cache the EventLoop handler 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Prepare for the ability to exit the event loop based on conditions in the request complete handler by caching the pointer instead of passing it as an argument. Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- * Changes since v2 - Pass EventLoop to constructor instead of run() --- src/cam/capture.cpp | 13 +++++++------ src/cam/capture.h | 10 ++++++---- src/cam/main.cpp | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index 55fa2dabcee97f21..f811a18c579508a1 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -16,12 +16,13 @@ using namespace libcamera; -Capture::Capture(std::shared_ptr camera, CameraConfiguration *config) - : camera_(camera), config_(config), writer_(nullptr) +Capture::Capture(std::shared_ptr camera, CameraConfiguration *config, + EventLoop *loop) + : camera_(camera), config_(config), writer_(nullptr), loop_(loop) { } -int Capture::run(EventLoop *loop, const OptionsParser::Options &options) +int Capture::run(const OptionsParser::Options &options) { int ret; @@ -54,7 +55,7 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options) FrameBufferAllocator *allocator = new FrameBufferAllocator(camera_); - ret = capture(loop, allocator); + ret = capture(allocator); if (options.isSet(OptFile)) { delete writer_; @@ -66,7 +67,7 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options) return ret; } -int Capture::capture(EventLoop *loop, FrameBufferAllocator *allocator) +int Capture::capture(FrameBufferAllocator *allocator) { int ret; @@ -132,7 +133,7 @@ int Capture::capture(EventLoop *loop, FrameBufferAllocator *allocator) } std::cout << "Capture until user interrupts by SIGINT" << std::endl; - ret = loop->exec(); + ret = loop_->exec(); if (ret) std::cout << "Failed to run capture loop" << std::endl; diff --git a/src/cam/capture.h b/src/cam/capture.h index 9bca5661070efcf5..acdefc47b24314d2 100644 --- a/src/cam/capture.h +++ b/src/cam/capture.h @@ -24,12 +24,12 @@ class Capture { public: Capture(std::shared_ptr camera, - libcamera::CameraConfiguration *config); + libcamera::CameraConfiguration *config, + EventLoop *loop); - int run(EventLoop *loop, const OptionsParser::Options &options); + int run(const OptionsParser::Options &options); private: - int capture(EventLoop *loop, - libcamera::FrameBufferAllocator *allocator); + int capture(libcamera::FrameBufferAllocator *allocator); void requestComplete(libcamera::Request *request); @@ -39,6 +39,8 @@ private: std::map streamName_; BufferWriter *writer_; std::chrono::steady_clock::time_point last_; + + EventLoop *loop_; }; #endif /* __CAM_CAPTURE_H__ */ diff --git a/src/cam/main.cpp b/src/cam/main.cpp index ead0abe3e2abf42d..3e83feabe64e036c 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -341,8 +341,8 @@ int CamApp::run() } if (options_.isSet(OptCapture)) { - Capture capture(camera_, config_.get()); - return capture.run(loop_, options_); + Capture capture(camera_, config_.get(), loop_); + return capture.run(options_); } return 0; From patchwork Fri Jul 24 19:18:51 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: 8990 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6D5B6BD879 for ; Fri, 24 Jul 2020 19:19:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2B54D612E1; Fri, 24 Jul 2020 21:19:22 +0200 (CEST) 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 555966121D for ; Fri, 24 Jul 2020 21:19:18 +0200 (CEST) X-Halon-ID: 67dec317-cde2-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 67dec317-cde2-11ea-86ee-0050569116f7; Fri, 24 Jul 2020 21:18:07 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jul 2020 21:18:51 +0200 Message-Id: <20200724191851.803350-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724191851.803350-1-niklas.soderlund@ragnatech.se> References: <20200724191851.803350-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/3] cam: Add optional argument to --capture to specify how many frames to capture 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Extend the '--capture' option with and optional numerical argument to be able to specify how many frames to capture before exiting. If the optional argument is not provided the old behavior of running until the user interrupts with a SIGINT is retained. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v2 - Move check in Capture::requestComplete() as to not leak the created but never used Request. * Changes since v1 - Extend --capture option instead of adding a new --count option. --- src/cam/capture.cpp | 18 ++++++++++++++++-- src/cam/capture.h | 2 ++ src/cam/main.cpp | 5 +++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index f811a18c579508a1..3d8e89d52c7ab68d 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -18,7 +18,8 @@ using namespace libcamera; Capture::Capture(std::shared_ptr camera, CameraConfiguration *config, EventLoop *loop) - : camera_(camera), config_(config), writer_(nullptr), loop_(loop) + : camera_(camera), config_(config), writer_(nullptr), loop_(loop), + captureCount_(0), captureLimit_(0) { } @@ -26,6 +27,9 @@ int Capture::run(const OptionsParser::Options &options) { int ret; + captureCount_ = 0; + captureLimit_ = options[OptCapture].toInteger(); + if (!camera_) { std::cout << "Can't capture without a camera" << std::endl; return -ENODEV; @@ -132,7 +136,11 @@ int Capture::capture(FrameBufferAllocator *allocator) } } - std::cout << "Capture until user interrupts by SIGINT" << std::endl; + if (captureLimit_) + std::cout << "Capture " << captureLimit_ << " frames" << std::endl; + else + std::cout << "Capture until user interrupts by SIGINT" << std::endl; + ret = loop_->exec(); if (ret) std::cout << "Failed to run capture loop" << std::endl; @@ -184,6 +192,12 @@ void Capture::requestComplete(Request *request) std::cout << info.str() << std::endl; + captureCount_++; + if (captureLimit_ && captureCount_ >= captureLimit_) { + loop_->exit(0); + return; + } + /* * Create a new request and populate it with one buffer for each * stream. diff --git a/src/cam/capture.h b/src/cam/capture.h index acdefc47b24314d2..32940a2a12138887 100644 --- a/src/cam/capture.h +++ b/src/cam/capture.h @@ -41,6 +41,8 @@ private: std::chrono::steady_clock::time_point last_; EventLoop *loop_; + unsigned int captureCount_; + unsigned int captureLimit_; }; #endif /* __CAM_CAPTURE_H__ */ diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 3e83feabe64e036c..f5aba041d7c4c181 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -167,8 +167,9 @@ int CamApp::parseOptions(int argc, char *argv[]) parser.addOption(OptCamera, OptionString, "Specify which camera to operate on, by name or by index", "camera", ArgumentRequired, "camera"); - parser.addOption(OptCapture, OptionNone, - "Capture until interrupted by user", "capture"); + parser.addOption(OptCapture, OptionInteger, + "Capture until interrupted by user or until frames captured", + "capture", ArgumentOptional, "count"); parser.addOption(OptFile, OptionString, "Write captured frames to disk\n" "The first '#' character in the file name is expanded to the stream name and frame sequence number.\n"