From patchwork Fri Jul 24 13:43:18 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: 8965 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 65C33BD86F for ; Fri, 24 Jul 2020 13:43:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8AE5861236; Fri, 24 Jul 2020 15:43:31 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 627F360535 for ; Fri, 24 Jul 2020 15:43:30 +0200 (CEST) X-Halon-ID: a8560279-cdb3-11ea-8fb8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id a8560279-cdb3-11ea-8fb8-005056917f90; Fri, 24 Jul 2020 15:43:29 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jul 2020 15:43:18 +0200 Message-Id: <20200724134320.637696-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724134320.637696-1-niklas.soderlund@ragnatech.se> References: <20200724134320.637696-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 an '--strict-formats' option which fails the camera configuration step if the format is adjusted, Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- 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..a223563ad37e9fe5 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 << "Adjustng camera configuration not allowed" + << 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 13:43:19 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: 8966 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 580C5BD86F for ; Fri, 24 Jul 2020 13:43:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 33E5161243; Fri, 24 Jul 2020 15:43:32 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B55AE60535 for ; Fri, 24 Jul 2020 15:43:30 +0200 (CEST) X-Halon-ID: a895f877-cdb3-11ea-8fb8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id a895f877-cdb3-11ea-8fb8-005056917f90; Fri, 24 Jul 2020 15:43:30 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jul 2020 15:43:19 +0200 Message-Id: <20200724134320.637696-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724134320.637696-1-niklas.soderlund@ragnatech.se> References: <20200724134320.637696-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 --- src/cam/capture.cpp | 10 ++++++---- src/cam/capture.h | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index 55fa2dabcee97f21..aa53c407d7b71b44 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -17,7 +17,7 @@ using namespace libcamera; Capture::Capture(std::shared_ptr camera, CameraConfiguration *config) - : camera_(camera), config_(config), writer_(nullptr) + : camera_(camera), config_(config), writer_(nullptr), loop_(nullptr) { } @@ -25,6 +25,8 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options) { int ret; + loop_ = loop; + if (!camera_) { std::cout << "Can't capture without a camera" << std::endl; return -ENODEV; @@ -54,7 +56,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 +68,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 +134,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..67c6260bfe24aefc 100644 --- a/src/cam/capture.h +++ b/src/cam/capture.h @@ -28,8 +28,7 @@ public: int run(EventLoop *loop, const OptionsParser::Options &options); private: - int capture(EventLoop *loop, - libcamera::FrameBufferAllocator *allocator); + int capture(libcamera::FrameBufferAllocator *allocator); void requestComplete(libcamera::Request *request); @@ -39,6 +38,8 @@ private: std::map streamName_; BufferWriter *writer_; std::chrono::steady_clock::time_point last_; + + EventLoop *loop_; }; #endif /* __CAM_CAPTURE_H__ */ From patchwork Fri Jul 24 13:43:20 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: 8967 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 0E08DBD86F for ; Fri, 24 Jul 2020 13:43:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DB3D361212; Fri, 24 Jul 2020 15:43:35 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5176561244 for ; Fri, 24 Jul 2020 15:43:32 +0200 (CEST) X-Halon-ID: a8d8c379-cdb3-11ea-8fb8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id a8d8c379-cdb3-11ea-8fb8-005056917f90; Fri, 24 Jul 2020 15:43:31 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jul 2020 15:43:20 +0200 Message-Id: <20200724134320.637696-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200724134320.637696-1-niklas.soderlund@ragnatech.se> References: <20200724134320.637696-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] cam: Add option to exit capture loop after n frames 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 an option '--count' to specify how many frames to capture before terminating the capture loop. Signed-off-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/cam/capture.cpp | 17 +++++++++++++++-- src/cam/capture.h | 2 ++ src/cam/main.cpp | 2 ++ src/cam/main.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index aa53c407d7b71b44..3ca70d9c6a8c7b7e 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -17,7 +17,8 @@ using namespace libcamera; Capture::Capture(std::shared_ptr camera, CameraConfiguration *config) - : camera_(camera), config_(config), writer_(nullptr), loop_(nullptr) + : camera_(camera), config_(config), writer_(nullptr), loop_(nullptr), + captureCount_(0), captureLimit_(0) { } @@ -26,6 +27,8 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options) int ret; loop_ = loop; + captureCount_ = 0; + captureLimit_ = options.isSet(OptCount) ? options[OptCount].toInteger() : 0; if (!camera_) { std::cout << "Can't capture without a camera" << std::endl; @@ -133,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; @@ -202,5 +209,11 @@ void Capture::requestComplete(Request *request) request->addBuffer(stream, buffer); } + captureCount_++; + if (captureLimit_ && captureCount_ >= captureLimit_) { + loop_->exit(0); + return; + } + camera_->queueRequest(request); } diff --git a/src/cam/capture.h b/src/cam/capture.h index 67c6260bfe24aefc..0a1cbc519f2a90c5 100644 --- a/src/cam/capture.h +++ b/src/cam/capture.h @@ -40,6 +40,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 a223563ad37e9fe5..f3bacb4a895600ee 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -188,6 +188,8 @@ int CamApp::parseOptions(int argc, char *argv[]) parser.addOption(OptStrictFormats, OptionNone, "Do not allow requested stream format(s) to be adjusted", "strict-formats"); + parser.addOption(OptCount, OptionInteger, "Number of frames to capture", + "count", ArgumentRequired, "count"); options_ = parser.parse(argc, argv); if (!options_.valid()) diff --git a/src/cam/main.h b/src/cam/main.h index 6f95add31a6341cf..d4c93fee35681e86 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -18,6 +18,7 @@ enum { OptStream = 's', OptListControls = 256, OptStrictFormats = 257, + OptCount = 258, }; #endif /* __CAM_MAIN_H__ */