fix: main.c migrate-to-library + deltacast audit cleanup

This commit is contained in:
Zac Gaetano 2026-06-02 19:01:31 -04:00
parent 5525041901
commit d8df8755e2

View file

@ -37,6 +37,10 @@
#include "VideoMasterHD_Sdi.h" #include "VideoMasterHD_Sdi.h"
#include "VideoMasterHD_Sdi_Audio.h" #include "VideoMasterHD_Sdi_Audio.h"
#ifndef F_SETPIPE_SZ
#define F_SETPIPE_SZ 1031
#endif
/* ── Constants ────────────────────────────────────────────────────────── */ /* ── Constants ────────────────────────────────────────────────────────── */
#define MAX_PORTS 8 #define MAX_PORTS 8
@ -74,7 +78,7 @@ static ULONG loopback_prop(unsigned port) {
case 1: return VHD_CORE_BP_PASSIVE_LOOPBACK_1; case 1: return VHD_CORE_BP_PASSIVE_LOOPBACK_1;
case 2: return VHD_CORE_BP_PASSIVE_LOOPBACK_2; case 2: return VHD_CORE_BP_PASSIVE_LOOPBACK_2;
case 3: return VHD_CORE_BP_PASSIVE_LOOPBACK_3; case 3: return VHD_CORE_BP_PASSIVE_LOOPBACK_3;
default: return VHD_CORE_BP_PASSIVE_LOOPBACK_0; default: return -1; /* ports 4-7 have no passive loopback property; call site guards p < 4 */
} }
} }
@ -246,10 +250,6 @@ static void *audio_thread(void *arg) {
nanosleep(&ts, NULL); nanosleep(&ts, NULL);
continue; continue;
} }
fprintf(stderr, "[audio:%u] FIFO writer connected\n", ps->port);
#ifndef F_SETPIPE_SZ
#define F_SETPIPE_SZ 1031
#endif
fcntl(fd, F_SETPIPE_SZ, 1024 * 1024); fcntl(fd, F_SETPIPE_SZ, 1024 * 1024);
/* Reset wall-clock baseline after potentially blocking on open(). /* Reset wall-clock baseline after potentially blocking on open().
@ -257,12 +257,6 @@ static void *audio_thread(void *arg) {
struct timespec next; struct timespec next;
clock_gettime(CLOCK_MONOTONIC, &next); clock_gettime(CLOCK_MONOTONIC, &next);
/* Audio-rate telemetry: count samples written per second so drift is
* visible in the log ([audio:N] rate=<samples/s>). At 48 kHz it must
* average 48000. */
unsigned long dbg_samples = 0;
struct timespec dbg_t0; clock_gettime(CLOCK_MONOTONIC, &dbg_t0);
/* Inner loop: feed audio into the open FIFO until reader exits (EPIPE). */ /* Inner loop: feed audio into the open FIFO until reader exits (EPIPE). */
while (!atomic_load(&g_stop) && !atomic_load(&g_port_stop[ps->port])) { while (!atomic_load(&g_stop) && !atomic_load(&g_port_stop[ps->port])) {
size_t out_bytes = 0; size_t out_bytes = 0;
@ -292,14 +286,6 @@ static void *audio_thread(void *arg) {
fprintf(stderr, "[audio:%u] EPIPE — waiting for next reader\n", ps->port); fprintf(stderr, "[audio:%u] EPIPE — waiting for next reader\n", ps->port);
break; break;
} }
dbg_samples += out_bytes / FRAME_BYTES;
struct timespec dnow; clock_gettime(CLOCK_MONOTONIC, &dnow);
double el = (dnow.tv_sec - dbg_t0.tv_sec) + (dnow.tv_nsec - dbg_t0.tv_nsec)/1e9;
if (el >= 5.0) {
fprintf(stderr, "[audio:%u] rate=%.1f samples/s (target 48000)\n",
ps->port, dbg_samples / el);
dbg_samples = 0; dbg_t0 = dnow;
}
} }
/* No wall-clock sleep — the board's slot cadence is the clock. */ /* No wall-clock sleep — the board's slot cadence is the clock. */
continue; continue;
@ -370,16 +356,10 @@ static void *video_thread(void *arg) {
nanosleep(&ts, NULL); nanosleep(&ts, NULL);
continue; continue;
} }
fprintf(stderr, "[video:%u] FIFO writer connected\n", ps->port);
#ifndef F_SETPIPE_SZ
#define F_SETPIPE_SZ 1031
#endif
{ {
int pipe_sz = 64 * 1024 * 1024; /* 64 MB — ~16 frames of 1080p UYVY */ int pipe_sz = 64 * 1024 * 1024; /* 64 MB — ~16 frames of 1080p UYVY */
if (fcntl(fd, F_SETPIPE_SZ, pipe_sz) < 0) { if (fcntl(fd, F_SETPIPE_SZ, pipe_sz) < 0) {
fprintf(stderr, "[video:%u] fcntl F_SETPIPE_SZ failed: %s\n", ps->port, strerror(errno)); fprintf(stderr, "[video:%u] fcntl F_SETPIPE_SZ failed: %s\n", ps->port, strerror(errno));
} else {
fprintf(stderr, "[video:%u] FIFO pipe size increased to %dMB\n", ps->port, pipe_sz / (1024*1024));
} }
} }
@ -407,13 +387,6 @@ static void *video_thread(void *arg) {
} }
} }
VHD_UnlockSlotHandle(slot); VHD_UnlockSlotHandle(slot);
static __thread unsigned long processed = 0;
if (++processed % 60 == 0) {
ULONG sc = 0, sd = 0;
VHD_GetStreamProperty(ps->video_stream, VHD_CORE_SP_SLOTS_COUNT, &sc);
VHD_GetStreamProperty(ps->video_stream, VHD_CORE_SP_SLOTS_DROPPED, &sd);
fprintf(stderr, "[video:%u] locked=%lu (sc=%lu, sd=%lu)\n", ps->port, processed, sc, sd);
}
} else if (r != VHDERR_TIMEOUT) { } else if (r != VHDERR_TIMEOUT) {
fprintf(stderr, "[video:%u] VHD_LockSlotHandle error %lu — stopping port\n", fprintf(stderr, "[video:%u] VHD_LockSlotHandle error %lu — stopping port\n",
ps->port, r); ps->port, r);