hardcoded decklink mode fix

This commit is contained in:
Johanness
2026-05-28 23:43:26 +03:00
parent 96bef6cd32
commit 34f72c22f0
12 changed files with 222 additions and 35 deletions
@@ -9,6 +9,7 @@ namespace dmf_engine {
class NodeControlClient {
public:
bool send_command(uint16_t port, const std::string& json_cmd);
std::string send_command_with_response(uint16_t port, const std::string& json_cmd);
void register_node(const std::string& node_id, uint16_t port);
void unregister_node(const std::string& node_id);
+22 -1
View File
@@ -254,8 +254,29 @@ static void handle_request(const std::string& method, const std::string& path,
return;
}
int fps_num = 50, fps_den = 1;
int width = 1920, height = 1080;
nlohmann::json status_cmd;
status_cmd["cmd"] = "status";
auto status_resp = cc.send_command_with_response(port_num, status_cmd.dump());
if (!status_resp.empty()) {
try {
auto sr = nlohmann::json::parse(status_resp);
if (sr.contains("data")) {
auto& d = sr["data"];
if (d.contains("grain_rate")) {
fps_num = d["grain_rate"].value("numerator", fps_num);
fps_den = d["grain_rate"].value("denominator", fps_den);
}
width = d.value("width", width);
height = d.value("height", height);
}
} catch (...) {}
}
auto flow_id = fm.create_flow_id();
auto flow_def = fm.create_v210_flow_def(flow_id, 1920, 1080, 50, 1);
auto flow_def = fm.create_v210_flow_def(flow_id, width, height, fps_num, fps_den);
nlohmann::json cmd;
cmd["cmd"] = "add_writer";
@@ -85,4 +85,60 @@ bool NodeControlClient::send_command(uint16_t port, const std::string& json_cmd)
return ok;
}
std::string NodeControlClient::send_command_with_response(uint16_t port, const std::string& json_cmd) {
int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) {
spdlog::error("NodeControlClient: socket() failed: {}", strerror(errno));
return "";
}
struct timeval tv;
tv.tv_sec = 2;
tv.tv_usec = 0;
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
struct sockaddr_in addr;
std::memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
if (connect(fd, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)) < 0) {
spdlog::error("NodeControlClient: connect to port {} failed: {}", port, strerror(errno));
close(fd);
return "";
}
std::ostringstream req;
req << "POST /cmd HTTP/1.1\r\n"
<< "Host: 127.0.0.1:" << port << "\r\n"
<< "Content-Type: application/json\r\n"
<< "Content-Length: " << json_cmd.size() << "\r\n"
<< "Connection: close\r\n"
<< "\r\n"
<< json_cmd;
auto request = req.str();
auto sent = write(fd, request.data(), request.size());
if (sent != static_cast<ssize_t>(request.size())) {
spdlog::error("NodeControlClient: write failed on port {}", port);
close(fd);
return "";
}
std::string full_resp;
char resp_buf[4096];
while (true) {
auto n = read(fd, resp_buf, sizeof(resp_buf));
if (n <= 0) break;
full_resp.append(resp_buf, n);
}
close(fd);
auto body_start = full_resp.find("\r\n\r\n");
if (body_start == std::string::npos) return "";
return full_resp.substr(body_start + 4);
}
} // namespace dmf_engine