VOXL OpenVINS Server 0.7.0
Visual Inertial Odometry Server for VOXL Platform
Loading...
Searching...
No Matches
VoxlVioIngest.h
1#pragma once
2/**
3 * VoxlVioIngest.h -- wires the server's per-frame post-processing into VioManager's async ingest.
4 *
5 * @author Joao Leonardo Silva Cotta (@zauberflote1)
6 *
7 * Since the lock-free camera ingest lives inside ov_msckf (AsyncCameraBuffer), the server no
8 * longer loops over camera batches: cameras push frames straight into the VioManager from their
9 * pipe threads, and the IMU feed releases them in global timestamp order on the VIO thread.
10 * This hook runs after each released frame (processed=true) or for every frame the ingest drops
11 * (processed=false): it releases external cl_mem image handles exactly once, and publishes the
12 * updated state. Returning false pauses draining while a reset is pending.
13 *
14 * Register on EVERY VioManager instance right after construction (boot + hard-reset swap).
15 *
16 * Author: Joao Leonardo Silva Cotta (@zauberflote1)
17 */
18
19#include <atomic>
20
21#include "VoxlHK.h" // voxl::Publisher
22#include "VoxlVars.h" // vio_manager, is_resetting, vio_error_codes (+ vio pipe error codes)
23
24#if HAVE_OPENCL
25#include <CL/cl.h>
26#endif
27
28namespace voxl {
29
30/// Release any external (cl_mem) image handles carried by this frame (idempotent per frame:
31/// handles are zeroed after release so a double call cannot double-free)
32inline void release_frame_handles(const ov_core::CameraData &msg) {
33#if HAVE_OPENCL
34 for (auto &frame : msg.img_frames) {
35 if (frame.img.handle_type == modal_flow::ExternalType::ClMem && frame.img.external_handle != 0) {
36 cl_mem handle = reinterpret_cast<cl_mem>(static_cast<uintptr_t>(frame.img.external_handle));
37 cl_int err = clReleaseMemObject(handle);
38 if (err != CL_SUCCESS) {
39 fprintf(stderr, "Failed to release Frame cl_mem, err=%d\n", err);
40 }
41 const_cast<modal_flow::ImageView &>(frame.img).external_handle = 0;
42 }
43 }
44#else
45 (void)msg;
46#endif
47}
48
49/// Install the per-frame hook on a VioManager (call once per instance, right after construction)
50inline void register_vio_camera_callback(ov_msckf::VioManager &vm) {
51 vm.set_camera_processed_callback([](const ov_core::CameraData &msg, bool processed) -> bool {
52 // Handles are released for EVERY frame that entered the ingest, dropped or processed
54 if (!processed) {
55 vio_error_codes |= ERROR_CODE_DROPPED_CAM;
56 return true;
57 }
58 if (is_resetting.load(std::memory_order_acquire)) {
59 return false; // pause draining; the reset path owns the estimator now
60 }
61 // Publish the updated state (same VIO thread that ran the update). The map is taken by
62 // reference -- valid for the whole callback because publish never re-enters feed/drain --
63 // which deletes two full deep copies (~12 tree nodes + ~50 shared_ptr refcount pairs per
64 // entry) per camera tick.
65 auto st = vio_manager->get_state();
66 const auto &feats = vio_manager->get_used_features_map_ref();
67 if (is_resetting.load(std::memory_order_relaxed)) {
68 return false;
69 }
71 return true;
72 });
73}
74
75} // namespace voxl
Housekeeping and data publishing for VOXL OpenVINS.
std::unique_ptr< ov_msckf::VioManager > vio_manager
Main VIO manager instance.
Definition VoxlVars.cpp:31
Global variable declarations and constants for VOXL OpenVINS server.
std::atomic< bool > is_resetting
VIO reset state flag.
std::atomic< uint32_t > vio_error_codes
VIO error codes.
static Publisher & getInstance()
Get singleton instance.
Definition VoxlHK.h:137
void publish(std::shared_ptr< ov_msckf::State > state, const std::map< double, std::vector< std::shared_ptr< ov_core::Feature > > > &used_features_map={})
Publish VIO data.
Main namespace for VOXL OpenVINS server components.
void register_vio_camera_callback(ov_msckf::VioManager &vm)
Install the per-frame hook on a VioManager (call once per instance, right after construction)
void release_frame_handles(const ov_core::CameraData &msg)
Release any external (cl_mem) image handles carried by this frame (idempotent per frame: handles are ...