From 30e0ea843eb96a93f8282466e3a328fdda7fafdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20S=C3=B6derlund?= Date: Fri, 24 Jul 2020 15:24:39 +0200 Subject: cam: Add optional argument to --capture to specify how many frames to capture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/cam/capture.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/cam/capture.cpp') diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index f811a18c..3d8e89d5 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. -- cgit v1.2.1