Files
DeeJanuzandClaude Opus 5.5 499035216c Make hand tracking a Frametop component
- Programs: ft-camd (the camera broker), ft-hands (the tracker), and
  ft-handreplay and ft-ringplay for recordings, built by hands/build.sh
  into hands/build/ with one Makefile. The first build fetches ncnn at
  frame-hands' pinned tag and builds it with the same options.
- ft-camd gets its privileges from file capabilities (CAP_SYS_PTRACE,
  CAP_PERFMON, CAP_DAC_READ_SEARCH) that hands/run.sh install sets with
  sudo, and drops them once set up. It still works under sudo. It runs
  on the host, linked statically, as frametop-camd.service. ft-hands
  runs in the dev container as frametop-hands.service. Both start and
  stop with SteamVR.
- Files move to /run/user/UID/frametop/ (cam-ring, hands, gestures),
  not $XDG_RUNTIME_DIR, which a terminal in the Frametop desktop has
  its own of. SIGUSR1 recordings go to ~/.local/share/frametop/hands.
- The calibration is read through /run/host in the container.
- Settings: HANDS_SWAP_SIDES and HANDS_CPUS in frametop.conf.
- install.sh offers hand tracking as an optional last step.
- The container gets jsoncpp-devel, glibc-static, and NumPy and OpenCV
  for the Python tools.
- tools/ring.py reads the ring, and models/NOTICE credits the
  Apache-2.0 models.

Checked: ft-handreplay gives identical summaries and byte-identical
depth dumps to frame-hands' fh-replay on both 2026-09-29 recordings.

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

70 lines
1.9 KiB
C++

// Recordings of frame sets, for replaying live sessions through the tracker offline
// (ft-handreplay). 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;
};