/* Headless csdk integration test: use the library's threaded reader * (mag160c_ir_start) + attached FFC scheduler + frame callback to verify * the exact Linux-portable pipeline on the Windows device. */ #include #include #include #include #include "mag160c/mag160c.h" #include "mag160c/mag160c_display.h" static volatile long g_n0; static volatile long g_n1; static volatile long g_nframes; static void on_frame(uint32_t idx, const uint8_t *frame, size_t size, void *user) { (void)idx; (void)user; if (size < 0x1c + 2) return; uint32_t type = (uint32_t)frame[12] | ((uint32_t)frame[13] << 8) | ((uint32_t)frame[14] << 16) | ((uint32_t)frame[15] << 24); if (type == 0) g_n0++; else g_n1++; g_nframes++; } int main(void) { printf("csdk ir-start + ffc-scheduler test\n"); mag160c_ctx_t *ctx = NULL; mag160c_ir_t *ir = NULL; mag160c_error_t rc = mag160c_init(&ctx); if (rc == MAG160C_OK) rc = mag160c_ir_open(ctx, &ir); if (rc == MAG160C_OK) { mag160c_ffc_scheduler_t *s = (mag160c_ffc_scheduler_t *)calloc(1, sizeof(*s)); mag160c_ffc_scheduler_init(s, 400, 9); rc = mag160c_ir_set_ffc_scheduler(ir, s, 1); } if (rc == MAG160C_OK) rc = mag160c_ir_set_frame_callback(ir, on_frame, NULL); if (rc == MAG160C_OK) rc = mag160c_ir_start(ir); if (rc != MAG160C_OK) { fprintf(stderr, "%s: %s\n", mag160c_error_name(rc), mag160c_last_error()); return 2; } printf("streaming...\n"); DWORD t0 = GetTickCount(); long last = 0; while (g_n0 < 1000 && GetTickCount() - t0 < 130000) { Sleep(5000); double secs = (GetTickCount() - t0) / 1000.0; printf(" t=%5.1fs frames=%ld type0=%ld type1=%ld fps=%.1f\n", secs, g_nframes, g_n0, g_n1, g_n0 / secs); if (g_nframes == last) { printf(" STALL? no new frames in 5s\n"); } last = g_nframes; } double secs = (GetTickCount() - t0) / 1000.0; printf("DONE: frames=%ld type0=%ld type1=%ld in %.1fs\n", g_nframes, g_n0, g_n1, secs); int pass = g_n0 >= 1000; printf("%s\n", pass ? "PASS: csdk threaded pipeline >= 1000 type=0 frames" : "FAIL"); mag160c_ir_stop(ir); mag160c_ir_close(ir); mag160c_shutdown(ctx); return pass ? 0 : 2; }