aboutsummaryrefslogtreecommitdiff
path: root/hsm-cam/FFI/Cam.cpp
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2025-08-20 02:23:39 +0000
committerPaul Oliver <contact@pauloliver.dev>2025-08-23 22:59:12 +0000
commit6db2d77345b1d3da432a73d9eaf0be34165567c3 (patch)
tree0bc2606a60a3458aacb04fd5c3765d2554295e81 /hsm-cam/FFI/Cam.cpp
parent5a78bc1885ad7d6fd7ad63d6ef900188ab38a80c (diff)
Adds camera service
Diffstat (limited to 'hsm-cam/FFI/Cam.cpp')
-rw-r--r--hsm-cam/FFI/Cam.cpp88
1 files changed, 67 insertions, 21 deletions
diff --git a/hsm-cam/FFI/Cam.cpp b/hsm-cam/FFI/Cam.cpp
index 05fd1a8..9e371c1 100644
--- a/hsm-cam/FFI/Cam.cpp
+++ b/hsm-cam/FFI/Cam.cpp
@@ -25,8 +25,9 @@ logMsg(Severity severity, const format_string<Args...> fmt, const Args &...args)
void
request_complete(Request *request)
{
- logMsg(Trace, "Completed request");
- g_callback(request->buffers().begin()->second->planes()[0].fd.get());
+ int sequence = request->buffers().begin()->second->metadata().sequence;
+ logMsg(Trace, "Completed request #{}", sequence);
+ g_callback();
}
extern "C" void
@@ -44,56 +45,101 @@ register_callback(HsCallback hs_callback)
}
extern "C" void
-initialize_ffi()
+start_camera_manager()
{
logMsg(Info, "Starting camera manager");
g_manager = make_unique<CameraManager>();
g_manager->start();
+}
+
+extern "C" void
+stop_camera_manager()
+{
+ logMsg(Info, "Stopping camera manager");
+ g_manager->stop();
+}
+extern "C" void
+acquire_camera()
+{
logMsg(Info, "Acquiring camera");
g_camera = g_manager->cameras()[0];
g_camera->acquire();
+ logMsg(Info, "Acquired camera: {}", g_camera->id());
+}
- logMsg(Info, "Generating still capture configuration");
+extern "C" void
+release_camera()
+{
+ logMsg(Info, "Releasing camera");
+ g_camera->release();
+ g_camera.reset();
+}
+
+extern "C" void
+allocate_frame_buffer()
+{
+ logMsg(Info, "Generating camera configuration");
g_config = g_camera->generateConfiguration({ StreamRole::StillCapture });
+ g_config->at(0).size.width = FRAME_WIDTH;
+ g_config->at(0).size.height = FRAME_HEIGHT;
+ g_config->at(0).pixelFormat = formats::RGB888;
+ logMsg(Info, "Generated camera configuration: {}", g_config->at(0).toString());
g_camera->configure(g_config.get());
- logMsg(Info, "Allocating buffer");
+ logMsg(Info, "Generating frame buffer allocator");
g_allocator = make_unique<FrameBufferAllocator>(g_camera);
- g_allocator->allocate((*g_config)[0].stream());
+ g_allocator->allocate(g_config->at(0).stream());
logMsg(Info, "Registering request complete callback");
g_camera->requestCompleted.connect(request_complete);
+}
+extern "C" void
+free_frame_buffer()
+{
+ logMsg(Info, "Freeing frame buffer allocator");
+ g_allocator->free(g_config->at(0).stream());
+ g_allocator.reset();
+}
+
+extern "C" void
+start_camera()
+{
logMsg(Info, "Starting camera");
g_camera->start();
}
extern "C" void
-shutdown_ffi()
+stop_camera()
{
logMsg(Info, "Stopping camera");
g_camera->stop();
+}
- logMsg(Info, "Freeing frame buffer allocator");
- g_allocator->free((*g_config)[0].stream());
- g_allocator.reset();
+extern "C" void
+create_request()
+{
+ logMsg(Info, "Creating request");
+ g_request = g_camera->createRequest();
- logMsg(Info, "Releasing camera");
- g_camera->release();
- g_camera.reset();
+ logMsg(Info, "Setting buffer for request");
+ Stream *stream = g_config->at(0).stream();
+ g_request->addBuffer(stream, g_allocator->buffers(stream)[0].get());
+}
- logMsg(Info, "Stopping camera manager");
- g_manager->stop();
+extern "C" int
+get_dma_buffer_fd()
+{
+ int fd = g_request->buffers().begin()->second->planes()[0].fd.get();
+ logMsg(Info, "DMA buffer available in FD {}", fd);
+ return fd;
}
extern "C" void
-request_capture()
+request_frame()
{
- logMsg(Trace, "Requesting still capture");
-
- Stream *stream = (*g_config)[0].stream();
- g_request = g_camera->createRequest();
- g_request->addBuffer(stream, g_allocator->buffers(stream)[0].get());
+ logMsg(Trace, "Requested frame");
+ g_request->reuse(Request::ReuseBuffers);
g_camera->queueRequest(g_request.get());
}