diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-07-05 07:15:53 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2021-07-22 17:13:43 +0300 |
commit | 4cd0f586fbc7bc8451bd18aaa3b59fbd8d53574e (patch) | |
tree | 6147fa3225677933db60aa7b78ba4936120e3894 /src/cam/camera_session.cpp | |
parent | 011b3ff288826460b76c59a5899c92ecd8226643 (diff) |
cam: Move event loop execution from CameraSession to CamApp
To prepare for multiple concurrent camera sessions, move the event loop
exec() call from the CameraSession class to the CamApp class.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/cam/camera_session.cpp')
-rw-r--r-- | src/cam/camera_session.cpp | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp index 16c1c66a..b1200e60 100644 --- a/src/cam/camera_session.cpp +++ b/src/cam/camera_session.cpp @@ -22,11 +22,11 @@ CameraSession::CameraSession(std::shared_ptr<Camera> camera, CameraConfiguration *config) : camera_(camera), config_(config), writer_(nullptr), last_(0), queueCount_(0), captureCount_(0), captureLimit_(0), - printMetadata_(false) + printMetadata_(false), allocator_(nullptr) { } -int CameraSession::run(const OptionsParser::Options &options) +int CameraSession::start(const OptionsParser::Options &options) { int ret; @@ -61,36 +61,39 @@ int CameraSession::run(const OptionsParser::Options &options) writer_ = new BufferWriter(); } - FrameBufferAllocator *allocator = new FrameBufferAllocator(camera_); + allocator_ = new FrameBufferAllocator(camera_); - ret = capture(allocator); + return startCapture(); +} - if (options.isSet(OptFile)) { - delete writer_; - writer_ = nullptr; - } +void CameraSession::stop() +{ + int ret = camera_->stop(); + if (ret) + std::cout << "Failed to stop capture" << std::endl; - requests_.clear(); + delete writer_; + writer_ = nullptr; - delete allocator; + requests_.clear(); - return ret; + delete allocator_; } -int CameraSession::capture(FrameBufferAllocator *allocator) +int CameraSession::startCapture() { int ret; /* Identify the stream with the least number of buffers. */ unsigned int nbuffers = UINT_MAX; for (StreamConfiguration &cfg : *config_) { - ret = allocator->allocate(cfg.stream()); + ret = allocator_->allocate(cfg.stream()); if (ret < 0) { std::cerr << "Can't allocate buffers" << std::endl; return -ENOMEM; } - unsigned int allocated = allocator->buffers(cfg.stream()).size(); + unsigned int allocated = allocator_->buffers(cfg.stream()).size(); nbuffers = std::min(nbuffers, allocated); } @@ -109,7 +112,7 @@ int CameraSession::capture(FrameBufferAllocator *allocator) for (StreamConfiguration &cfg : *config_) { Stream *stream = cfg.stream(); const std::vector<std::unique_ptr<FrameBuffer>> &buffers = - allocator->buffers(stream); + allocator_->buffers(stream); const std::unique_ptr<FrameBuffer> &buffer = buffers[i]; ret = request->addBuffer(stream, buffer.get()); @@ -146,15 +149,7 @@ int CameraSession::capture(FrameBufferAllocator *allocator) else std::cout << "Capture until user interrupts by SIGINT" << std::endl; - ret = EventLoop::instance()->exec(); - if (ret) - std::cout << "Failed to run capture loop" << std::endl; - - ret = camera_->stop(); - if (ret) - std::cout << "Failed to stop capture" << std::endl; - - return ret; + return 0; } int CameraSession::queueRequest(Request *request) |