summaryrefslogtreecommitdiff
path: root/src/cam
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-07-24 15:24:39 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2020-07-27 17:31:13 +0200
commit30e0ea843eb96a93f8282466e3a328fdda7fafdc (patch)
tree0502913b4358b2e215b2fc30213205ec377c4a1c /src/cam
parented734693350220f38aab768aee5e106b92dc9eb9 (diff)
cam: Add optional argument to --capture to specify how many frames to capture
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 <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/cam')
-rw-r--r--src/cam/capture.cpp18
-rw-r--r--src/cam/capture.h2
-rw-r--r--src/cam/main.cpp5
3 files changed, 21 insertions, 4 deletions
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> 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 acdefc47..32940a2a 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 3e83feab..f5aba041 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 <count> 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"