fix: separate grain processing thread from LWS event loop

The fundamental issue: mxlSleepUntil/mxlSleepForNs blocks the entire
thread, making LWS unresponsive and causing control commands to hang.
Meanwhile, LWS poll(1) adds latency that makes grain timing unreliable.

Solution: run node->process() in a dedicated thread that can freely use
mxlSleepUntil for precise grain timing, while the main thread runs
control_server->poll(10) for LWS event handling.

Passthrough now uses mxlSleepUntil(deadline) matching the mxl-gst-sink
Cursor pattern, with 2-grain read delay for buffering.
This commit is contained in:
Johanness
2026-05-26 22:55:57 +03:00
parent d677b654f0
commit 5b48d86c6e
3 changed files with 14 additions and 15 deletions
+10 -11
View File
@@ -170,20 +170,19 @@ int NodeRunner::exec(std::unique_ptr<Node> node) {
running_ = true;
spdlog::info("Node '{}' entering process loop", node_id_);
while (g_running && running_) {
control_server->poll(1);
node->process();
static int status_counter = 0;
if (++status_counter % 100 == 0) {
nlohmann::json status_event;
status_event["event"] = "status";
status_event["node_id"] = node_id_;
status_event["data"] = node->status();
control_server->send_event(status_event);
std::thread process_thread([&]() {
while (g_running && running_) {
node->process();
}
});
while (g_running && running_) {
control_server->poll(10);
}
running_ = false;
process_thread.join();
spdlog::info("Node '{}' shutting down", node_id_);
mxlDestroyInstance(mxl_instance_);
return 0;