diff options
author | Umang Jain <email@uajain.com> | 2020-12-04 13:22:23 +0530 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-12-04 10:33:05 +0000 |
commit | b79a04afa753d5cfda47faee9bb4fc7b46c78b01 (patch) | |
tree | 3f52d090ddb1fb50a0f4d7e9b6889363753bb294 /simple-cam.cpp | |
parent | 14529b6d1c4a6d405b23157eca8a4b0bec632e00 (diff) |
simple-cam: Provide event-loop backed by libevent
libcamera moved its EventDispatcher and Timer API to its internal API,
since providing an event loop to applications should not be the job of
libcamera. Application utility like cam, were ported to use libevent,
hence inspired from that, un-break simple-cam by using the similar
implementation to replace the EventDispatcher and Timer functionality
by libevent.
Signed-off-by: Umang Jain <email@uajain.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'simple-cam.cpp')
-rw-r--r-- | simple-cam.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/simple-cam.cpp b/simple-cam.cpp index bfe30d7..6d1d84f 100644 --- a/simple-cam.cpp +++ b/simple-cam.cpp @@ -11,8 +11,13 @@ #include <libcamera/libcamera.h> +#include "event_loop.h" + +#define TIMEOUT_SEC 3 + using namespace libcamera; std::shared_ptr<Camera> camera; +EventLoop loop; /* * -------------------------------------------------------------------- @@ -21,13 +26,26 @@ std::shared_ptr<Camera> camera; * For each Camera::requestCompleted Signal emitted from the Camera the * connected Slot is invoked. * + * The Slot is invoked in the CameraManager's thread, hence one should avoid + * any heavy processing here. The processing of the request shall be re-directed + * to the application's thread instead, so as not to block the CameraManager's + * thread for large amount of time. + * * The Slot receives the Request as a parameter. */ + +static void processRequest(Request *request); + static void requestComplete(Request *request) { if (request->status() == Request::RequestCancelled) return; + loop.callLater(std::bind(&processRequest, request)); +} + +static void processRequest(Request *request) +{ const Request::BufferMap &buffers = request->buffers(); for (auto bufferPair : buffers) { @@ -320,20 +338,11 @@ int main() * * In order to dispatch events received from the video devices, such * as buffer completions, an event loop has to be run. - * - * Libcamera provides its own default event dispatcher realized by - * polling a set of file descriptors, but applications can integrate - * their own even loop with the Libcamera EventDispatcher. - * - * Here, as an example, run the poll-based EventDispatcher for 3 - * seconds. */ - EventDispatcher *dispatcher = cm->eventDispatcher(); - Timer timer; - timer.start(3000); - while (timer.isRunning()) - dispatcher->processEvents(); - + loop.timeout(TIMEOUT_SEC); + int ret = loop.exec(); + std::cout << "Capture ran for " << TIMEOUT_SEC << " seconds and " + << "stopped with exit status: " << ret << std::endl; /* * -------------------------------------------------------------------- * Clean Up |