feat(windows-nui): file logging + Global namespace shm fallback for cross-session diagnosis
This commit is contained in:
1 parent
ec169053c3
commit
e88e0e5c58
3 files changed
+93
-1
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include "nui_interfaces.h"
|
||||
#include "sensor.h"
|
||||
#include "sensor_com.h"
|
||||
#include "shim_log.h"
|
||||
|
||||
using namespace nui_shim;
|
||||
|
||||
@@ -20,6 +21,7 @@ HRESULT WINAPI NuiGetSensorCount(int* pCount) {
|
||||
return E_POINTER;
|
||||
}
|
||||
*pCount = 1;
|
||||
ShimLog("NuiGetSensorCount -> 1");
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -31,6 +33,7 @@ HRESULT WINAPI NuiCreateSensorByIndex(int index, INuiSensor** ppNuiSensor) {
|
||||
return E_NUI_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
*ppNuiSensor = new NuiSensorCom(EnsureGlobalSensor());
|
||||
ShimLog("NuiCreateSensorByIndex(%d) -> sensor", index);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "sensor.h"
|
||||
|
||||
#include "shim_log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@@ -113,7 +115,19 @@ HRESULT VirtualKinectSensor::Initialize(DWORD dwFlags) {
|
||||
return E_NUI_ALREADY_INITIALIZED;
|
||||
}
|
||||
init_flags_ = dwFlags;
|
||||
source_.open(MappingName().c_str());
|
||||
std::wstring name = MappingName();
|
||||
bool opened = source_.open(name.c_str());
|
||||
DWORD err = opened ? 0u : GetLastError();
|
||||
if (!opened) {
|
||||
std::wstring global = L"Global\\" + name;
|
||||
opened = source_.open(global.c_str());
|
||||
ShimLog("NuiInitialize flags=0x%08X shm='%ls' local-open=0 (err=%lu) global-open=%d (err=%lu)",
|
||||
dwFlags, name.c_str(), err, opened ? 1 : 0,
|
||||
opened ? 0u : GetLastError());
|
||||
} else {
|
||||
ShimLog("NuiInitialize flags=0x%08X shm='%ls' local-open=1", dwFlags,
|
||||
name.c_str());
|
||||
}
|
||||
|
||||
stop_event_ = CreateEventW(nullptr, TRUE, FALSE, nullptr);
|
||||
skeleton_ready_event_ = CreateEventW(nullptr, TRUE, FALSE, nullptr);
|
||||
@@ -180,6 +194,8 @@ HRESULT VirtualKinectSensor::SkeletonTrackingEnable(HANDLE hNextFrameEvent,
|
||||
skeleton_flags_ = dwFlags;
|
||||
skeleton_app_event_ = hNextFrameEvent;
|
||||
LeaveCriticalSection(&lock_);
|
||||
ShimLog("SkeletonTrackingEnable flags=0x%08X event=%p", dwFlags,
|
||||
hNextFrameEvent);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -302,6 +318,9 @@ HRESULT VirtualKinectSensor::ImageStreamOpen(NUI_IMAGE_TYPE eImageType,
|
||||
|
||||
*phStreamHandle = reinterpret_cast<HANDLE>(slot);
|
||||
LeaveCriticalSection(&lock_);
|
||||
ShimLog("ImageStreamOpen type=%d res=%d -> %ux%u bpp=%u ring=%zu",
|
||||
static_cast<int>(eImageType), static_cast<int>(eResolution), width,
|
||||
height, bpp, slot->ring_size);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -492,6 +511,24 @@ void VirtualKinectSensor::ProducerLoop() {
|
||||
|
||||
SourceFrame src;
|
||||
const bool got = source_.is_open() && source_.read_latest(src);
|
||||
if ((frame_number % 60u) == 0u) {
|
||||
std::size_t depth_nonzero = 0;
|
||||
if (got) {
|
||||
for (uint16_t p : src.depth_pixels) {
|
||||
if (p != 0) {
|
||||
++depth_nonzero;
|
||||
}
|
||||
}
|
||||
}
|
||||
ShimLog("producer tick=%u src_open=%d got_frame=%d has_player=%d depth_nonzero=%zu streams_open=%d skel_enabled=%d",
|
||||
frame_number, source_.is_open() ? 1 : 0, got ? 1 : 0,
|
||||
got && src.has_player ? 1 : 0, depth_nonzero,
|
||||
std::any_of(streams_.begin(), streams_.end(),
|
||||
[](const ImageStream& s) { return s.open; })
|
||||
? 1
|
||||
: 0,
|
||||
skeleton_enabled_ ? 1 : 0);
|
||||
}
|
||||
if (!got) {
|
||||
src = SourceFrame{};
|
||||
src.has_player = false;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef FALLBACK_WINDOWS_NUI_SHIM_LOG_H
|
||||
#define FALLBACK_WINDOWS_NUI_SHIM_LOG_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
namespace nui_shim {
|
||||
|
||||
inline CRITICAL_SECTION& ShimLogLock() {
|
||||
static CRITICAL_SECTION cs;
|
||||
static BOOL once = [] {
|
||||
InitializeCriticalSection(&cs);
|
||||
return TRUE;
|
||||
}();
|
||||
(void)once;
|
||||
return cs;
|
||||
}
|
||||
|
||||
inline void ShimLog(const char* fmt, ...) {
|
||||
wchar_t path[MAX_PATH];
|
||||
DWORD n = GetEnvironmentVariableW(L"KINECT_SHIM_LOG", path, MAX_PATH);
|
||||
if (n == 0 || n >= MAX_PATH) {
|
||||
wchar_t tmp[MAX_PATH];
|
||||
DWORD t = GetTempPathW(MAX_PATH, tmp);
|
||||
if (t == 0 || t >= MAX_PATH) {
|
||||
return;
|
||||
}
|
||||
_snwprintf(path, MAX_PATH, L"%skinect_shim.log", tmp);
|
||||
}
|
||||
|
||||
EnterCriticalSection(&ShimLogLock());
|
||||
FILE* f = _wfopen(path, L"a");
|
||||
if (f != nullptr) {
|
||||
SYSTEMTIME st;
|
||||
GetLocalTime(&st);
|
||||
fprintf(f, "[%02d:%02d:%02d.%03d] ", st.wHour, st.wMinute, st.wSecond,
|
||||
st.wMilliseconds);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(f, fmt, args);
|
||||
va_end(args);
|
||||
fprintf(f, "\n");
|
||||
fclose(f);
|
||||
}
|
||||
LeaveCriticalSection(&ShimLogLock());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user