summaryrefslogtreecommitdiff
path: root/src/cam
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2021-01-26 18:17:06 +0100
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2021-02-05 11:10:29 +0100
commita3c75bba84bac0a4f8a4c815cc7dcd9a72116c59 (patch)
treef5fa09e45940991a617a443cf610c8fc1cb12dd8 /src/cam
parent5b60b689c14bcb84ee034bdf400a75c0b63ef999 (diff)
cam: Only queue the exact number of requests asked for
The cam option --capture=N is suppose to only capture N requests. But if the processing done for each request is large (such as writing it to a slow disk) the current implementation could queue more than N requests before the exit condition is detected and capturing stopped. Solve this by only queueing N requests while still waiting for N requests to complete before exiting. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/cam')
-rw-r--r--src/cam/capture.cpp17
-rw-r--r--src/cam/capture.h2
2 files changed, 16 insertions, 3 deletions
diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp
index 113ea49d..7b55fc67 100644
--- a/src/cam/capture.cpp
+++ b/src/cam/capture.cpp
@@ -18,7 +18,7 @@ using namespace libcamera;
Capture::Capture(std::shared_ptr<Camera> camera, CameraConfiguration *config,
EventLoop *loop)
: camera_(camera), config_(config), writer_(nullptr), last_(0), loop_(loop),
- captureCount_(0), captureLimit_(0)
+ queueCount_(0), captureCount_(0), captureLimit_(0)
{
}
@@ -26,6 +26,7 @@ int Capture::run(const OptionsParser::Options &options)
{
int ret;
+ queueCount_ = 0;
captureCount_ = 0;
captureLimit_ = options[OptCapture].toInteger();
@@ -128,7 +129,7 @@ int Capture::capture(FrameBufferAllocator *allocator)
}
for (std::unique_ptr<Request> &request : requests_) {
- ret = camera_->queueRequest(request.get());
+ ret = queueRequest(request.get());
if (ret < 0) {
std::cerr << "Can't queue request" << std::endl;
camera_->stop();
@@ -152,6 +153,16 @@ int Capture::capture(FrameBufferAllocator *allocator)
return ret;
}
+int Capture::queueRequest(Request *request)
+{
+ if (captureLimit_ && queueCount_ >= captureLimit_)
+ return 0;
+
+ queueCount_++;
+
+ return camera_->queueRequest(request);
+}
+
void Capture::requestComplete(Request *request)
{
if (request->status() == Request::RequestCancelled)
@@ -213,5 +224,5 @@ void Capture::processRequest(Request *request)
}
request->reuse(Request::ReuseBuffers);
- camera_->queueRequest(request);
+ queueRequest(request);
}
diff --git a/src/cam/capture.h b/src/cam/capture.h
index d21c95a2..c7c9dc00 100644
--- a/src/cam/capture.h
+++ b/src/cam/capture.h
@@ -32,6 +32,7 @@ public:
private:
int capture(libcamera::FrameBufferAllocator *allocator);
+ int queueRequest(libcamera::Request *request);
void requestComplete(libcamera::Request *request);
void processRequest(libcamera::Request *request);
@@ -43,6 +44,7 @@ private:
uint64_t last_;
EventLoop *loop_;
+ unsigned int queueCount_;
unsigned int captureCount_;
unsigned int captureLimit_;