feat(framecache): phase 1 — framecache container + consumer library
- services/framecache/: new standalone container
- slot.h/slot.c: shm ring buffer (120 frames, FC_MAGIC header, atomic
write_cursor, POSIX semaphore per slot)
- registry.h/registry.c: in-memory slot registry + /dev/shm/framecache/
registry.json persistence
- framecache.c: HTTP API server (libmicrohttpd, port 7435)
POST /slots, GET /slots, GET /slots/:id, DELETE /slots/:id, GET /health
- fc_client.h/fc_client.c: consumer library — fc_consumer_open/read/close
with per-consumer cursor, timeout via sem_timedwait, automatic skip+count
when consumer falls behind writer by > ring_depth frames
- fc_test_consumer.c: dev utility to attach to any slot and print fps/stats
- CMakeLists.txt: framecache server + fc_client static lib + test consumer
- Dockerfile: builder + slim runtime stages
- docker-compose.worker.yml: add framecache service (profile: capture,
ipc: host, shm_size from FC_SHM_SIZE_GB env var, healthcheck)
- .env.example: document FC_SHM_SIZE_GB with per-node guidance
2026-06-03 10:53:51 -04:00
|
|
|
/**
|
|
|
|
|
* fc_client.h — Consumer-side framecache client library.
|
|
|
|
|
*
|
|
|
|
|
* Usage:
|
|
|
|
|
* fc_consumer_t *c = fc_consumer_open("deltacast-zampp3-0");
|
|
|
|
|
* fc_frame_ref_t ref;
|
|
|
|
|
* while (fc_consumer_read(c, &ref, 2000) == FC_OK) {
|
|
|
|
|
* // ref.data valid until next fc_consumer_read call
|
|
|
|
|
* process_frame(ref.data, ref.size, ref.pts_us);
|
|
|
|
|
* }
|
|
|
|
|
* fc_consumer_close(c);
|
|
|
|
|
*
|
|
|
|
|
* Each consumer tracks its own read_cursor — multiple consumers on the same
|
|
|
|
|
* slot are fully independent and never block each other or the writer.
|
|
|
|
|
*
|
|
|
|
|
* If a consumer falls more than ring_depth frames behind the writer its cursor
|
|
|
|
|
* is snapped to the latest frame and FC_DROPPED is returned once.
|
|
|
|
|
*/
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Return codes */
|
2026-06-03 12:25:34 -04:00
|
|
|
#define FC_OK 0 /* valid frame returned in ref */
|
|
|
|
|
#define FC_TIMEOUT 1 /* no new frame within timeout_ms — ref not populated */
|
|
|
|
|
#define FC_DROPPED 2 /* valid frame returned in ref, BUT one or more older
|
|
|
|
|
* frames were skipped first (consumer fell behind).
|
|
|
|
|
* ref IS populated — caller should USE the frame. */
|
|
|
|
|
#define FC_LAPPED 3 /* the copy was overwritten mid-read (writer lapped the
|
|
|
|
|
* consumer during memcpy). ref NOT populated — caller
|
|
|
|
|
* should call fc_consumer_read again. */
|
feat(framecache): phase 1 — framecache container + consumer library
- services/framecache/: new standalone container
- slot.h/slot.c: shm ring buffer (120 frames, FC_MAGIC header, atomic
write_cursor, POSIX semaphore per slot)
- registry.h/registry.c: in-memory slot registry + /dev/shm/framecache/
registry.json persistence
- framecache.c: HTTP API server (libmicrohttpd, port 7435)
POST /slots, GET /slots, GET /slots/:id, DELETE /slots/:id, GET /health
- fc_client.h/fc_client.c: consumer library — fc_consumer_open/read/close
with per-consumer cursor, timeout via sem_timedwait, automatic skip+count
when consumer falls behind writer by > ring_depth frames
- fc_test_consumer.c: dev utility to attach to any slot and print fps/stats
- CMakeLists.txt: framecache server + fc_client static lib + test consumer
- Dockerfile: builder + slim runtime stages
- docker-compose.worker.yml: add framecache service (profile: capture,
ipc: host, shm_size from FC_SHM_SIZE_GB env var, healthcheck)
- .env.example: document FC_SHM_SIZE_GB with per-node guidance
2026-06-03 10:53:51 -04:00
|
|
|
#define FC_ERROR -1
|
|
|
|
|
|
|
|
|
|
typedef struct fc_consumer fc_consumer_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2026-06-03 12:25:34 -04:00
|
|
|
const uint8_t *data; /* pointer to a CONSUMER-OWNED copy of the frame —
|
|
|
|
|
* stable until the next fc_consumer_read() call.
|
|
|
|
|
* (Previously a zero-copy pointer into the shm ring,
|
|
|
|
|
* which the writer could overwrite mid-use when it
|
|
|
|
|
* lapped a slow consumer. We now copy into the
|
|
|
|
|
* consumer's own buffer and re-validate the cursor
|
|
|
|
|
* AFTER the copy, so a lapped frame is discarded
|
|
|
|
|
* rather than streamed corrupt.) */
|
feat(framecache): phase 1 — framecache container + consumer library
- services/framecache/: new standalone container
- slot.h/slot.c: shm ring buffer (120 frames, FC_MAGIC header, atomic
write_cursor, POSIX semaphore per slot)
- registry.h/registry.c: in-memory slot registry + /dev/shm/framecache/
registry.json persistence
- framecache.c: HTTP API server (libmicrohttpd, port 7435)
POST /slots, GET /slots, GET /slots/:id, DELETE /slots/:id, GET /health
- fc_client.h/fc_client.c: consumer library — fc_consumer_open/read/close
with per-consumer cursor, timeout via sem_timedwait, automatic skip+count
when consumer falls behind writer by > ring_depth frames
- fc_test_consumer.c: dev utility to attach to any slot and print fps/stats
- CMakeLists.txt: framecache server + fc_client static lib + test consumer
- Dockerfile: builder + slim runtime stages
- docker-compose.worker.yml: add framecache service (profile: capture,
ipc: host, shm_size from FC_SHM_SIZE_GB env var, healthcheck)
- .env.example: document FC_SHM_SIZE_GB with per-node guidance
2026-06-03 10:53:51 -04:00
|
|
|
uint32_t size; /* bytes */
|
|
|
|
|
uint64_t pts_us; /* presentation timestamp (microseconds) */
|
|
|
|
|
uint64_t wall_us; /* wall clock at write time (microseconds) */
|
|
|
|
|
uint64_t seq; /* write_cursor value for this frame */
|
|
|
|
|
} fc_frame_ref_t;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Open a consumer handle for the named slot.
|
|
|
|
|
* Polls the slot shm file until it appears (up to wait_ms milliseconds).
|
|
|
|
|
* Returns NULL if slot not found within wait_ms or on error.
|
|
|
|
|
*/
|
|
|
|
|
fc_consumer_t *fc_consumer_open(const char *slot_id, uint64_t wait_ms);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read the next frame.
|
|
|
|
|
* Blocks up to timeout_ms waiting for a new frame (via semaphore).
|
|
|
|
|
* Returns FC_OK, FC_TIMEOUT, FC_DROPPED, or FC_ERROR.
|
|
|
|
|
* On FC_OK or FC_DROPPED the ref fields are populated.
|
|
|
|
|
*/
|
|
|
|
|
int fc_consumer_read(fc_consumer_t *c, fc_frame_ref_t *ref, uint64_t timeout_ms);
|
|
|
|
|
|
|
|
|
|
/** Close the consumer handle. Does NOT destroy the slot. */
|
|
|
|
|
void fc_consumer_close(fc_consumer_t *c);
|
|
|
|
|
|
|
|
|
|
/** Current write_cursor of the slot (approximate — no lock). */
|
|
|
|
|
uint64_t fc_consumer_write_cursor(fc_consumer_t *c);
|
|
|
|
|
|
|
|
|
|
/** Frames dropped by this consumer since open. */
|
|
|
|
|
uint64_t fc_consumer_dropped(fc_consumer_t *c);
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|