From 453583e189e01bbef321b9a50c0c435cc05fef63 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 5 Jul 2021 06:59:21 +0300 Subject: cam: camera_session: Access event loop through global instance Don't pass the event loop to the CameraSession constructor, as passing this global object explicitly isn't a design that can scale. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/camera_session.cpp | 11 ++++++----- src/cam/camera_session.h | 6 ++---- src/cam/main.cpp | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index 439dcdb2..b26c7974 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -13,13 +13,14 @@ #include #include "camera_session.h" +#include "event_loop.h" #include "main.h" using namespace libcamera; CameraSession::CameraSession(std::shared_ptr camera, - CameraConfiguration *config, EventLoop *loop) - : camera_(camera), config_(config), writer_(nullptr), last_(0), loop_(loop), + CameraConfiguration *config) + : camera_(camera), config_(config), writer_(nullptr), last_(0), queueCount_(0), captureCount_(0), captureLimit_(0), printMetadata_(false) { @@ -145,7 +146,7 @@ int CameraSession::capture(FrameBufferAllocator *allocator) else std::cout << "Capture until user interrupts by SIGINT" << std::endl; - ret = loop_->exec(); + ret = EventLoop::instance()->exec(); if (ret) std::cout << "Failed to run capture loop" << std::endl; @@ -175,7 +176,7 @@ void CameraSession::requestComplete(Request *request) * Defer processing of the completed request to the event loop, to avoid * blocking the camera manager thread. */ - loop_->callLater([=]() { processRequest(request); }); + EventLoop::instance()->callLater([=]() { processRequest(request); }); } void CameraSession::processRequest(Request *request) @@ -231,7 +232,7 @@ void CameraSession::processRequest(Request *request) captureCount_++; if (captureLimit_ && captureCount_ >= captureLimit_) { - loop_->exit(0); + EventLoop::instance()->exit(0); return; } diff --git a/src/cam/camera_session.h b/src/cam/camera_session.h index ef8a11c3..270ba3e9 100644 --- a/src/cam/camera_session.h +++ b/src/cam/camera_session.h @@ -18,17 +18,16 @@ #include #include "buffer_writer.h" -#include "event_loop.h" #include "options.h" class CameraSession { public: CameraSession(std::shared_ptr camera, - libcamera::CameraConfiguration *config, - EventLoop *loop); + libcamera::CameraConfiguration *config); int run(const OptionsParser::Options &options); + private: int capture(libcamera::FrameBufferAllocator *allocator); @@ -43,7 +42,6 @@ private: BufferWriter *writer_; uint64_t last_; - EventLoop *loop_; unsigned int queueCount_; unsigned int captureCount_; unsigned int captureLimit_; diff --git a/src/cam/main.cpp b/src/cam/main.cpp index f71b65a2..90435206 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -363,7 +363,7 @@ int CamApp::run() } if (options_.isSet(OptCapture)) { - CameraSession session(camera_, config_.get(), &loop_); + CameraSession session(camera_, config_.get()); return session.run(options_); } -- cgit v1.2.1