Files
dmf-studio-rnd/studio-manager/FlowGraph.hpp
T
JohannesItten 1496cc2e1e refactor: rename video port flow_id → video_flow_id everywhere
All nodes now use video_flow_id/audio_flow_id consistently:
- nodes/testpattern: flow_id → video_flow_id
- nodes/fakesink:    flow_id → video_flow_id
- graph.json:        from_port/to_port flow_id → video_flow_id
- studio-manager:    hardcoded build_graph edges + FlowGraph.hpp comment

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-05 12:52:48 +03:00

63 lines
2.3 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
namespace dmf {
// A node instance in the pipeline graph.
struct NodeDef {
std::string id; // unique instance id; becomes node_id in NODE_CONFIG
std::string type; // binary suffix: "testpattern" → "dmf-node-testpattern"
nlohmann::json params; // node-specific config (width, height, fps_num, ...)
};
// A directed edge between two nodes, carried by one MXL flow.
//
// from_port / to_port are the NODE_CONFIG keys each end receives the flow descriptor under.
// The injected value is a JSON object: { "id": "<uuid>", ...format fields }.
// Nodes read the UUID as cfg["video_flow_id"]["id"] and format fields as cfg["video_flow_id"]["fps_num"] etc.
//
// format examples:
// video: { "kind":"video", "width":1920, "height":1080, "fps_num":25, "fps_den":1 }
// audio: { "kind":"audio", "sample_rate":48000, "channels":2, "bit_depth":24 }
//
// PiP sink example: two edges with to_port "input_a_flow_id" and "input_b_flow_id".
struct FlowEdge {
std::string id; // UUID for the MXL flow (set by build_graph)
std::string from_node;
std::string from_port; // key injected into source's NODE_CONFIG
std::string to_node;
std::string to_port; // key injected into sink's NODE_CONFIG
nlohmann::json format; // flow format metadata (kind, width, height, fps_num, ...)
};
// The complete pipeline description.
struct FlowGraph {
std::vector<NodeDef> nodes;
std::vector<FlowEdge> edges;
// Returns the full NODE_CONFIG JSON for one node.
// Each connected edge injects a flow descriptor object under the port key:
// cfg[port] = { "id": "<uuid>", ...format fields }
nlohmann::json node_config(const std::string& node_id) const {
const NodeDef* nd = nullptr;
for (const auto& n : nodes)
if (n.id == node_id) { nd = &n; break; }
if (!nd) return {};
nlohmann::json cfg = nd->params;
cfg["node_id"] = nd->id;
for (const auto& e : edges) {
nlohmann::json port = e.format;
port["id"] = e.id;
if (e.from_node == node_id) cfg[e.from_port] = port;
if (e.to_node == node_id) cfg[e.to_port] = port;
}
return cfg;
}
};
} // namespace dmf