mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-19 18:35:07 +03:00
cam: capture: Cache the EventLoop handler
Prepare for the ability to exit the event loop based on conditions in the request complete handler by caching the pointer instead of passing it as an argument. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
01ea694003
commit
ed73469335
3 changed files with 15 additions and 12 deletions
|
@ -16,12 +16,13 @@
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
Capture::Capture(std::shared_ptr<Camera> camera, CameraConfiguration *config)
|
Capture::Capture(std::shared_ptr<Camera> camera, CameraConfiguration *config,
|
||||||
: camera_(camera), config_(config), writer_(nullptr)
|
EventLoop *loop)
|
||||||
|
: camera_(camera), config_(config), writer_(nullptr), loop_(loop)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int Capture::run(EventLoop *loop, const OptionsParser::Options &options)
|
int Capture::run(const OptionsParser::Options &options)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)
|
||||||
|
|
||||||
FrameBufferAllocator *allocator = new FrameBufferAllocator(camera_);
|
FrameBufferAllocator *allocator = new FrameBufferAllocator(camera_);
|
||||||
|
|
||||||
ret = capture(loop, allocator);
|
ret = capture(allocator);
|
||||||
|
|
||||||
if (options.isSet(OptFile)) {
|
if (options.isSet(OptFile)) {
|
||||||
delete writer_;
|
delete writer_;
|
||||||
|
@ -66,7 +67,7 @@ int Capture::run(EventLoop *loop, const OptionsParser::Options &options)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Capture::capture(EventLoop *loop, FrameBufferAllocator *allocator)
|
int Capture::capture(FrameBufferAllocator *allocator)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -132,7 +133,7 @@ int Capture::capture(EventLoop *loop, FrameBufferAllocator *allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Capture until user interrupts by SIGINT" << std::endl;
|
std::cout << "Capture until user interrupts by SIGINT" << std::endl;
|
||||||
ret = loop->exec();
|
ret = loop_->exec();
|
||||||
if (ret)
|
if (ret)
|
||||||
std::cout << "Failed to run capture loop" << std::endl;
|
std::cout << "Failed to run capture loop" << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,12 @@ class Capture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Capture(std::shared_ptr<libcamera::Camera> camera,
|
Capture(std::shared_ptr<libcamera::Camera> camera,
|
||||||
libcamera::CameraConfiguration *config);
|
libcamera::CameraConfiguration *config,
|
||||||
|
EventLoop *loop);
|
||||||
|
|
||||||
int run(EventLoop *loop, const OptionsParser::Options &options);
|
int run(const OptionsParser::Options &options);
|
||||||
private:
|
private:
|
||||||
int capture(EventLoop *loop,
|
int capture(libcamera::FrameBufferAllocator *allocator);
|
||||||
libcamera::FrameBufferAllocator *allocator);
|
|
||||||
|
|
||||||
void requestComplete(libcamera::Request *request);
|
void requestComplete(libcamera::Request *request);
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ private:
|
||||||
std::map<libcamera::Stream *, std::string> streamName_;
|
std::map<libcamera::Stream *, std::string> streamName_;
|
||||||
BufferWriter *writer_;
|
BufferWriter *writer_;
|
||||||
std::chrono::steady_clock::time_point last_;
|
std::chrono::steady_clock::time_point last_;
|
||||||
|
|
||||||
|
EventLoop *loop_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __CAM_CAPTURE_H__ */
|
#endif /* __CAM_CAPTURE_H__ */
|
||||||
|
|
|
@ -341,8 +341,8 @@ int CamApp::run()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options_.isSet(OptCapture)) {
|
if (options_.isSet(OptCapture)) {
|
||||||
Capture capture(camera_, config_.get());
|
Capture capture(camera_, config_.get(), loop_);
|
||||||
return capture.run(loop_, options_);
|
return capture.run(options_);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue