G1: JUCE engine SHM chain rong POC - probe pass, khong lag them

This commit is contained in:
2026-08-28 12:35:37 +07:00
parent d7dd626dd5
commit 9c0d35def4
13 changed files with 517 additions and 33 deletions
+5 -30
View File
@@ -10,6 +10,7 @@
// nhận JSON mảng {path,bypass,preset_b64} (type/name bỏ qua).
#include "RenderFxJob.h"
#include "FxRealtimeIPC.h"
#include "FxShm.h"
#ifdef _WIN32
#ifndef NOMINMAX
@@ -31,32 +32,6 @@
namespace {
struct ShmView {
void* map = nullptr;
void* view = nullptr;
};
ShmView* openShm(const std::string& name, size_t size) {
int wlen = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), -1, nullptr, 0);
std::wstring wname(wlen, L'\0');
MultiByteToWideChar(CP_UTF8, 0, name.c_str(), -1, &wname[0], wlen);
HANDLE map = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, wname.c_str());
if (!map) return nullptr;
void* view = MapViewOfFile(map, FILE_MAP_ALL_ACCESS, 0, 0, size);
if (!view) { CloseHandle(map); return nullptr; }
ShmView* v = new ShmView();
v->map = map;
v->view = view;
return v;
}
void closeShm(ShmView* v) {
if (!v) return;
if (v->view) UnmapViewOfFile(v->view);
if (v->map) CloseHandle((HANDLE)v->map);
delete v;
}
static bool parentAlive(uint32_t pid) {
if (pid == 0) return true;
HANDLE h = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
@@ -137,7 +112,7 @@ int run_realtime_fx_loop(const std::string& jobPath, const std::string& shmName,
RealtimeFxChain chain;
chain.setChain(chainJson, sampleRate, (int32_t)batchN);
ShmView* v = openShm(shmName, sizeof(FxRealtimeIPC));
fxshm::ShmView* v = fxshm::openShm(shmName, sizeof(FxRealtimeIPC));
if (!v) {
std::cerr << "[RealtimeFxLoop] cannot open SHM: " << shmName
<< " (engine phải tạo trước)" << std::endl;
@@ -149,12 +124,12 @@ int run_realtime_fx_loop(const std::string& jobPath, const std::string& shmName,
for (int i = 0; i < 200 && ipc->h.magic != FXRT_MAGIC; ++i) sleepMs(10);
if (ipc->h.magic != FXRT_MAGIC) {
std::cerr << "[RealtimeFxLoop] SHM magic mismatch (engine chưa init?)" << std::endl;
closeShm(v);
fxshm::closeShm(v);
return 2;
}
if (ipc->h.inSlots != FXRT_IN_SLOTS || ipc->h.outSlots != FXRT_OUT_SLOTS) {
std::cerr << "[RealtimeFxLoop] slot count mismatch" << std::endl;
closeShm(v);
fxshm::closeShm(v);
return 2;
}
// Windows timer resolution 1ms — bỏ granularity Sleep 15.6ms cho toàn
@@ -359,7 +334,7 @@ int run_realtime_fx_loop(const std::string& jobPath, const std::string& shmName,
}
ipc->h.state = FXRT_STATE_STARTING; // đã dừng
hb.join();
closeShm(v);
fxshm::closeShm(v);
#ifdef _WIN32
timeEndPeriod(1);
#endif