@@ -77,6 +77,49 @@ void SimpleCapture::stop()
allocator_->free(stream);
}
+bool SimpleCapture::captureCompleted()
+{
+ captureCount_++;
+ if (captureCount_ >= captureLimit_) {
+ loop_->exit(0);
+ return true;
+ }
+
+ return false;
+}
+
+int SimpleCapture::queueRequest(Request *request)
+{
+ return camera_->queueRequest(request);
+}
+
+void SimpleCapture::queueRequests(Stream *stream,
+ const std::vector<std::unique_ptr<FrameBuffer>> &buffers)
+{
+ for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
+ std::unique_ptr<Request> request = camera_->createRequest();
+ ASSERT_TRUE(request) << "Can't create request";
+
+ ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request";
+
+ ASSERT_EQ(queueRequest(request.get()), 0) << "Failed to queue request";
+
+ requests_.push_back(std::move(request));
+ }
+}
+
+int SimpleCapture::runCaptureSession()
+{
+ loop_ = new EventLoop();
+ int status = loop_->exec();
+
+ /* After session ended */
+ stop();
+ delete loop_;
+
+ return status;
+}
+
/* SimpleCaptureBalanced */
SimpleCaptureBalanced::SimpleCaptureBalanced(std::shared_ptr<Camera> camera)
@@ -103,23 +146,9 @@ void SimpleCaptureBalanced::capture(unsigned int numRequests)
captureCount_ = 0;
captureLimit_ = numRequests;
- /* Queue the recommended number of reqeuests. */
- for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
- std::unique_ptr<Request> request = camera_->createRequest();
- ASSERT_TRUE(request) << "Can't create request";
-
- ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request";
+ queueRequests(stream, buffers);
- ASSERT_EQ(queueRequest(request.get()), 0) << "Failed to queue request";
-
- requests_.push_back(std::move(request));
- }
-
- /* Run capture session. */
- loop_ = new EventLoop();
- loop_->exec();
- stop();
- delete loop_;
+ runCaptureSession();
ASSERT_EQ(captureCount_, captureLimit_);
}
@@ -135,11 +164,8 @@ int SimpleCaptureBalanced::queueRequest(Request *request)
void SimpleCaptureBalanced::requestComplete(Request *request)
{
- captureCount_++;
- if (captureCount_ >= captureLimit_) {
- loop_->exit(0);
+ if (captureCompleted())
return;
- }
request->reuse(Request::ReuseBuffers);
if (queueRequest(request))
@@ -163,34 +189,17 @@ void SimpleCaptureUnbalanced::capture(unsigned int numRequests)
captureCount_ = 0;
captureLimit_ = numRequests;
- /* Queue the recommended number of reqeuests. */
- for (const std::unique_ptr<FrameBuffer> &buffer : buffers) {
- std::unique_ptr<Request> request = camera_->createRequest();
- ASSERT_TRUE(request) << "Can't create request";
-
- ASSERT_EQ(request->addBuffer(stream, buffer.get()), 0) << "Can't set buffer for request";
+ queueRequests(stream, buffers);
- ASSERT_EQ(camera_->queueRequest(request.get()), 0) << "Failed to queue request";
-
- requests_.push_back(std::move(request));
- }
-
- /* Run capture session. */
- loop_ = new EventLoop();
- int status = loop_->exec();
- stop();
- delete loop_;
+ int status = runCaptureSession();
ASSERT_EQ(status, 0);
}
void SimpleCaptureUnbalanced::requestComplete(Request *request)
{
- captureCount_++;
- if (captureCount_ >= captureLimit_) {
- loop_->exit(0);
+ if (captureCompleted())
return;
- }
request->reuse(Request::ReuseBuffers);
if (camera_->queueRequest(request))
@@ -25,11 +25,19 @@ protected:
void start();
void stop();
+ virtual int queueRequest(libcamera::Request *request);
+ void queueRequests(libcamera::Stream *stream,
+ const std::vector<std::unique_ptr<libcamera::FrameBuffer>> &buffers);
+ bool captureCompleted();
+ int runCaptureSession();
virtual void requestComplete(libcamera::Request *request) = 0;
EventLoop *loop_;
+ unsigned int captureCount_;
+ unsigned int captureLimit_;
+
std::shared_ptr<libcamera::Camera> camera_;
std::unique_ptr<libcamera::FrameBufferAllocator> allocator_;
std::unique_ptr<libcamera::CameraConfiguration> config_;
@@ -44,12 +52,10 @@ public:
void capture(unsigned int numRequests);
private:
- int queueRequest(libcamera::Request *request);
+ int queueRequest(libcamera::Request *request) override;
void requestComplete(libcamera::Request *request) override;
unsigned int queueCount_;
- unsigned int captureCount_;
- unsigned int captureLimit_;
};
class SimpleCaptureUnbalanced : public SimpleCapture
@@ -61,7 +67,4 @@ public:
private:
void requestComplete(libcamera::Request *request) override;
-
- unsigned int captureCount_;
- unsigned int captureLimit_;
};