aboutsummaryrefslogtreecommitdiff
path: root/hsm-cam/FFI
diff options
context:
space:
mode:
Diffstat (limited to 'hsm-cam/FFI')
-rw-r--r--hsm-cam/FFI/Cam.cpp88
-rw-r--r--hsm-cam/FFI/Cam.hpp27
2 files changed, 90 insertions, 25 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());
}
diff --git a/hsm-cam/FFI/Cam.hpp b/hsm-cam/FFI/Cam.hpp
index c2cd4ed..374e16a 100644
--- a/hsm-cam/FFI/Cam.hpp
+++ b/hsm-cam/FFI/Cam.hpp
@@ -1,6 +1,16 @@
#ifndef CAM_HPP
#define CAM_HPP
+// RGB888 configuration for ov5647 sensor (Raspberry Pi Camera Module)
+// Must be updated if either:
+// - Pixel format changes (e.g., to BGR, YUV, etc.)
+// - Camera module is replaced
+#define FRAME_WIDTH (800)
+#define FRAME_HEIGHT (600)
+#define FRAME_LINE (FRAME_WIDTH * 3)
+#define FRAME_STRIDE (FRAME_LINE + 32)
+#define FRAME_BUFFER_LENGTH (FRAME_STRIDE * FRAME_HEIGHT + 3072)
+
enum Severity
{
Attention = 0,
@@ -9,7 +19,7 @@ enum Severity
};
typedef void (*HsLogger)(enum Severity, const char *);
-typedef void (*HsCallback)(int fd);
+typedef void (*HsCallback)();
#ifdef __cplusplus
extern "C"
@@ -17,9 +27,18 @@ extern "C"
#endif
void register_logger(HsLogger hs_logger);
void register_callback(HsCallback hs_callback);
- void initialize_ffi();
- void shutdown_ffi();
- void request_capture();
+ void start_camera_manager();
+ void stop_camera_manager();
+ void acquire_camera();
+ void release_camera();
+ void allocate_frame_buffer();
+ void free_frame_buffer();
+ void start_camera();
+ void stop_camera();
+ void create_request();
+
+ int get_dma_buffer_fd();
+ void request_frame();
#ifdef __cplusplus
}
#endif