feat(tracker-native): kinect_tracker.log diagnostics for playtest
Adds a ShimLog-style trace log next to the exe (startup, camera enumeration, negotiated capture format + MF_MT_DEFAULT_STRIDE, per-N-frame presence/tracked, shm CreateFileMapping result, errors) so the first real-hardware run is diagnosable instead of blind - mirrors how kinect_shim.log drove the shim fixes. Logs the camera stride so a top-down/bottom-up RGB32 image-flip is immediately visible.
This commit is contained in:
1 parent
31178f1675
commit
b2513c5722
5 files changed
+96
-2
No files matched your search
@@ -18,6 +18,7 @@ mkdir -p "${HERE}/build/dist"
|
||||
-static -static-libgcc -static-libstdc++ \
|
||||
-I "${ORTW}/include" -I "${HERE}/src" -I "${CORE}" \
|
||||
"${HERE}/src/win_main.cpp" "${HERE}/src/win_camera.cpp" \
|
||||
"${HERE}/src/trace_log.cpp" \
|
||||
"${HERE}/src/pose_estimator.cpp" "${HERE}/src/shm_publisher.cpp" \
|
||||
"${HERE}/src/frame_pipeline.cpp" \
|
||||
"${CORE}/mapping/mapping.cpp" "${CORE}/synth/synth.cpp" \
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "trace_log.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
namespace kinect_tracker {
|
||||
namespace {
|
||||
|
||||
std::mutex g_mutex;
|
||||
|
||||
std::string LogPath() {
|
||||
wchar_t path[MAX_PATH];
|
||||
GetModuleFileNameW(nullptr, path, MAX_PATH);
|
||||
std::wstring w(path);
|
||||
const size_t slash = w.find_last_of(L"\\/");
|
||||
std::wstring dir = slash == std::wstring::npos ? L"." : w.substr(0, slash);
|
||||
std::wstring full = dir + L"\\kinect_tracker.log";
|
||||
std::string s(full.begin(), full.end());
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TraceLog(const char* fmt, ...) {
|
||||
std::lock_guard<std::mutex> lock(g_mutex);
|
||||
static std::string path = LogPath();
|
||||
FILE* f = std::fopen(path.c_str(), "a");
|
||||
if (!f) return;
|
||||
SYSTEMTIME t;
|
||||
GetLocalTime(&t);
|
||||
std::fprintf(f, "[%02d:%02d:%02d.%03d] ", t.wHour, t.wMinute, t.wSecond, t.wMilliseconds);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
std::vfprintf(f, fmt, args);
|
||||
va_end(args);
|
||||
std::fputc('\n', f);
|
||||
std::fclose(f);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef TRACKER_NATIVE_TRACE_LOG_H
|
||||
#define TRACKER_NATIVE_TRACE_LOG_H
|
||||
|
||||
namespace kinect_tracker {
|
||||
|
||||
void TraceLog(const char* fmt, ...);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "trace_log.h"
|
||||
|
||||
namespace kinect_tracker {
|
||||
namespace {
|
||||
|
||||
@@ -131,20 +133,29 @@ bool Camera::open(const std::wstring& symbolic_link, int width, int height) {
|
||||
hr = reader->SetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, nullptr, mt);
|
||||
SafeRelease(&mt);
|
||||
if (FAILED(hr)) {
|
||||
TraceLog("camera open FAILED: SetCurrentMediaType RGB32 %dx%d hr=0x%08lX",
|
||||
width, height, static_cast<unsigned long>(hr));
|
||||
SafeRelease(&reader);
|
||||
return false;
|
||||
}
|
||||
|
||||
IMFMediaType* cur = nullptr;
|
||||
LONG stride = 0;
|
||||
if (SUCCEEDED(reader->GetCurrentMediaType(MF_SOURCE_READER_FIRST_VIDEO_STREAM, &cur))) {
|
||||
UINT32 w = 0, h = 0;
|
||||
if (SUCCEEDED(MFGetAttributeSize(cur, MF_MT_FRAME_SIZE, &w, &h))) {
|
||||
width = static_cast<int>(w);
|
||||
height = static_cast<int>(h);
|
||||
}
|
||||
UINT32 s = 0;
|
||||
if (SUCCEEDED(cur->GetUINT32(MF_MT_DEFAULT_STRIDE, &s))) {
|
||||
stride = static_cast<LONG>(s);
|
||||
}
|
||||
SafeRelease(&cur);
|
||||
}
|
||||
|
||||
TraceLog("camera open OK: negotiated %dx%d default_stride=%ld (expect top-down +%d)",
|
||||
width, height, stride, width * 4);
|
||||
reader_ = reader;
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
@@ -169,6 +180,12 @@ bool Camera::read_frame(std::vector<uint8_t>& bgra, int& width, int& height) {
|
||||
DWORD max_len = 0, cur_len = 0;
|
||||
if (SUCCEEDED(buffer->Lock(&data, &max_len, &cur_len))) {
|
||||
const size_t need = static_cast<size_t>(width_) * height_ * 4u;
|
||||
static unsigned logged = 0;
|
||||
if (logged < 3) {
|
||||
TraceLog("read_frame: buffer=%lu bytes, need=%zu (%dx%d*4)",
|
||||
static_cast<unsigned long>(cur_len), need, width_, height_);
|
||||
++logged;
|
||||
}
|
||||
if (cur_len >= need) {
|
||||
bgra.resize(need);
|
||||
std::memcpy(bgra.data(), data, need);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "frame_pipeline.h"
|
||||
#include "pose_estimator.h"
|
||||
#include "shm_publisher.h"
|
||||
#include "trace_log.h"
|
||||
#include "win_camera.h"
|
||||
|
||||
using namespace kinect_tracker;
|
||||
@@ -115,12 +116,16 @@ void DrawOverlay(std::vector<uint8_t>& bgra, int w, int h, const PoseResult& pos
|
||||
void WorkerLoop(std::wstring symlink, int req_w, int req_h) {
|
||||
Camera camera;
|
||||
if (!camera.open(symlink, req_w, req_h)) {
|
||||
TraceLog("WorkerLoop: camera.open(%dx%d) FAILED", req_w, req_h);
|
||||
SetStatus("ERROR: could not open camera");
|
||||
g_app.running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
PoseEstimator estimator(ModelPath().c_str());
|
||||
const std::string model_path = ModelPath();
|
||||
TraceLog("WorkerLoop: camera open, loading model '%s'", model_path.c_str());
|
||||
PoseEstimator estimator(model_path.c_str());
|
||||
TraceLog("WorkerLoop: model loaded, entering capture loop");
|
||||
PipelineConfig cfg;
|
||||
FramePipeline pipeline(g_app.shm_base, cfg);
|
||||
|
||||
@@ -157,6 +162,11 @@ void WorkerLoop(std::wstring symlink, int req_w, int req_h) {
|
||||
const int64_t ts_us = (now.QuadPart - t0_now.QuadPart) * 1000000 / freq.QuadPart;
|
||||
pipeline.publish(++frame_number, ts_us, tracked ? &pose : nullptr, bgra.data(), w, h);
|
||||
|
||||
if (frame_number <= 3 || frame_number % 150u == 0) {
|
||||
TraceLog("frame#%u %dx%d presence=%.3f tracked=%d",
|
||||
frame_number, w, h, pose.presence, tracked ? 1 : 0);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> overlay = bgra;
|
||||
if (tracked) DrawOverlay(overlay, w, h, pose);
|
||||
{
|
||||
@@ -177,9 +187,13 @@ bool StartShm() {
|
||||
g_app.mapping = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE,
|
||||
static_cast<DWORD>((region >> 32) & 0xffffffffu),
|
||||
static_cast<DWORD>(region & 0xffffffffu), kShmName);
|
||||
if (!g_app.mapping) return false;
|
||||
if (!g_app.mapping) {
|
||||
TraceLog("shm CreateFileMapping FAILED err=%lu", GetLastError());
|
||||
return false;
|
||||
}
|
||||
g_app.shm_base = static_cast<uint8_t*>(
|
||||
MapViewOfFile(g_app.mapping, FILE_MAP_ALL_ACCESS, 0, 0, region));
|
||||
TraceLog("shm '%ls' region=%zu mapped=%d", kShmName, region, g_app.shm_base ? 1 : 0);
|
||||
return g_app.shm_base != nullptr;
|
||||
}
|
||||
|
||||
@@ -220,6 +234,8 @@ void StartCapture() {
|
||||
}
|
||||
g_app.running = true;
|
||||
const CameraResolution res = g_app.resolutions[rsel];
|
||||
TraceLog("Start: device[%d]='%s' %dx%d", dsel, g_app.devices[dsel].name.c_str(),
|
||||
res.width, res.height);
|
||||
g_app.worker = std::thread(WorkerLoop, g_app.devices[dsel].symbolic_link, res.width,
|
||||
res.height);
|
||||
SetWindowTextA(g_app.start_btn, "Stop");
|
||||
@@ -272,6 +288,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
512, 12, 300, 20, hwnd,
|
||||
reinterpret_cast<HMENU>(kIdStatus), inst, nullptr);
|
||||
g_app.devices = enumerate_cameras();
|
||||
TraceLog("enumerated %zu camera(s)", g_app.devices.size());
|
||||
for (const auto& d : g_app.devices) {
|
||||
TraceLog(" camera: %s", d.name.c_str());
|
||||
}
|
||||
for (const auto& d : g_app.devices) {
|
||||
SendMessageA(g_app.device_combo, CB_ADDSTRING, 0,
|
||||
reinterpret_cast<LPARAM>(d.name.c_str()));
|
||||
@@ -327,6 +347,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||
int WINAPI wWinMain(HINSTANCE inst, HINSTANCE, PWSTR, int show) {
|
||||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
MFStartup(MF_VERSION);
|
||||
TraceLog("==== kinect-tracker starting ====");
|
||||
|
||||
WNDCLASSW wc{};
|
||||
wc.lpfnWndProc = WndProc;
|
||||
|
||||
Reference in new issue
Block a user