Files
DeeJanuz--frametop/hands/track/record.h
T
DeeJanuzandClaude Opus 5.5 3e3d31c728 Lay out hands/ like Frametop's other components
trackd/ becomes track/, and the calibration helper the Python tools
import moves from the prototype's folder into tools/. The model
development tools (nettest and the scripts that compare it with the
Python models or cut int8 calibration crops) stay in frame-hands with
the prototype they need.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 09:01:10 -06:00

70 lines
1.9 KiB
C++

// Recordings of frame sets, for replaying live sessions through the tracker offline
// (fh-replay). A recording is DIR/sets.bin: one record per frame set, each
// fh_set_hdr_t, then per camera fh_set_cam_t, then each camera's pixels (w x h, packed)
// in the same camera order.
#pragma once
#include <condition_variable>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#define FH_SET_MAGIC "FHSET01"
struct fh_set_hdr_t {
char magic[8];
uint32_t ncams;
uint32_t bytes; // the whole record, this header included
};
struct fh_set_cam_t {
char name[16]; // calibration name, e.g. "slam_left"
uint32_t width, height;
uint64_t capture_ns; // CLOCK_MONOTONIC_RAW, as the ring has it
uint64_t dqbuf_ns; // CLOCK_MONOTONIC
};
struct SetFrame {
std::string name;
const uint8_t *px;
uint32_t width, height;
uint64_t capture_ns, dqbuf_ns;
};
// Writes sets on its own thread, so a slow disk never holds up tracking; drops sets
// when too many are waiting.
class Recorder {
public:
~Recorder();
bool open(const std::string &dir, std::string &err);
void add(const std::vector<SetFrame> &frames);
size_t written() const { return written_; }
size_t dropped() const { return dropped_; }
private:
void loop();
FILE *f_ = nullptr;
std::thread thread_;
std::mutex mu_;
std::condition_variable wake_;
std::deque<std::vector<uint8_t>> queue_;
bool stop_ = false;
size_t written_ = 0, dropped_ = 0;
};
// Reads a recording back one set at a time.
class SetReader {
public:
bool open(const std::string &dir, std::string &err);
// False at the end (or on a truncated last set).
bool next(std::vector<fh_set_cam_t> &cams, std::vector<std::vector<uint8_t>> &pixels);
~SetReader();
private:
FILE *f_ = nullptr;
};