mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-19 10:25:05 +03:00
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
94d828d880
commit
453583e189
3 changed files with 9 additions and 10 deletions
|
@ -13,13 +13,14 @@
|
||||||
#include <libcamera/control_ids.h>
|
#include <libcamera/control_ids.h>
|
||||||
|
|
||||||
#include "camera_session.h"
|
#include "camera_session.h"
|
||||||
|
#include "event_loop.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
CameraSession::CameraSession(std::shared_ptr<Camera> camera,
|
CameraSession::CameraSession(std::shared_ptr<Camera> camera,
|
||||||
CameraConfiguration *config, EventLoop *loop)
|
CameraConfiguration *config)
|
||||||
: camera_(camera), config_(config), writer_(nullptr), last_(0), loop_(loop),
|
: camera_(camera), config_(config), writer_(nullptr), last_(0),
|
||||||
queueCount_(0), captureCount_(0), captureLimit_(0),
|
queueCount_(0), captureCount_(0), captureLimit_(0),
|
||||||
printMetadata_(false)
|
printMetadata_(false)
|
||||||
{
|
{
|
||||||
|
@ -145,7 +146,7 @@ int CameraSession::capture(FrameBufferAllocator *allocator)
|
||||||
else
|
else
|
||||||
std::cout << "Capture until user interrupts by SIGINT" << std::endl;
|
std::cout << "Capture until user interrupts by SIGINT" << std::endl;
|
||||||
|
|
||||||
ret = loop_->exec();
|
ret = EventLoop::instance()->exec();
|
||||||
if (ret)
|
if (ret)
|
||||||
std::cout << "Failed to run capture loop" << std::endl;
|
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
|
* Defer processing of the completed request to the event loop, to avoid
|
||||||
* blocking the camera manager thread.
|
* blocking the camera manager thread.
|
||||||
*/
|
*/
|
||||||
loop_->callLater([=]() { processRequest(request); });
|
EventLoop::instance()->callLater([=]() { processRequest(request); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraSession::processRequest(Request *request)
|
void CameraSession::processRequest(Request *request)
|
||||||
|
@ -231,7 +232,7 @@ void CameraSession::processRequest(Request *request)
|
||||||
|
|
||||||
captureCount_++;
|
captureCount_++;
|
||||||
if (captureLimit_ && captureCount_ >= captureLimit_) {
|
if (captureLimit_ && captureCount_ >= captureLimit_) {
|
||||||
loop_->exit(0);
|
EventLoop::instance()->exit(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,17 +18,16 @@
|
||||||
#include <libcamera/stream.h>
|
#include <libcamera/stream.h>
|
||||||
|
|
||||||
#include "buffer_writer.h"
|
#include "buffer_writer.h"
|
||||||
#include "event_loop.h"
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
class CameraSession
|
class CameraSession
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CameraSession(std::shared_ptr<libcamera::Camera> camera,
|
CameraSession(std::shared_ptr<libcamera::Camera> camera,
|
||||||
libcamera::CameraConfiguration *config,
|
libcamera::CameraConfiguration *config);
|
||||||
EventLoop *loop);
|
|
||||||
|
|
||||||
int run(const OptionsParser::Options &options);
|
int run(const OptionsParser::Options &options);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int capture(libcamera::FrameBufferAllocator *allocator);
|
int capture(libcamera::FrameBufferAllocator *allocator);
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ private:
|
||||||
BufferWriter *writer_;
|
BufferWriter *writer_;
|
||||||
uint64_t last_;
|
uint64_t last_;
|
||||||
|
|
||||||
EventLoop *loop_;
|
|
||||||
unsigned int queueCount_;
|
unsigned int queueCount_;
|
||||||
unsigned int captureCount_;
|
unsigned int captureCount_;
|
||||||
unsigned int captureLimit_;
|
unsigned int captureLimit_;
|
||||||
|
|
|
@ -363,7 +363,7 @@ int CamApp::run()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options_.isSet(OptCapture)) {
|
if (options_.isSet(OptCapture)) {
|
||||||
CameraSession session(camera_, config_.get(), &loop_);
|
CameraSession session(camera_, config_.get());
|
||||||
return session.run(options_);
|
return session.run(options_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue