Files
dmf-studio-rnd/nodes/testpattern/main.cpp
T
JohannesItten 42507886fe feat: multiple test patterns in testpattern node
V210.hpp: add fill_colorbars, fill_ire_ramp, fill_black, fill_white.
Shared fill_solid helper stamps the first line across all rows via
memcpy. Generic write_palette_line template handles both SMPTE and
IRE bar palettes. fill_frame kept as a backward-compat alias.

testpattern/main.cpp: read "pattern" from node config and dispatch
to the appropriate fill function (bars/ire/black/white).

build_graph: pass {"pattern","bars"} to testpattern node params.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-01 13:24:06 +03:00

77 lines
3.0 KiB
C++

#include <string>
#include <mxl/flow.h>
#include <mxl/time.h>
#include "NodeBase.hpp"
#include "FlowDef.hpp"
#include "V210.hpp"
class TestPatternNode : public dmf::NodeBase {
void run() override {
const auto flow_info = config().at("flow_id");
const auto flow_id = flow_info.at("id").get<std::string>();
const int width = flow_info.value("width", 1920);
const int height = flow_info.value("height", 1080);
const int fps_num = flow_info.value("fps_num", 25);
const int fps_den = flow_info.value("fps_den", 1);
log("flow=%s %dx%d @ %d/%d fps", flow_id.c_str(), width, height, fps_num, fps_den);
const std::string flow_def =
dmf::make_video_flow_def(flow_id, node_id(), width, height, fps_num, fps_den);
mxlFlowWriter writer{};
mxlFlowConfigInfo cfg_info{};
bool created = false;
mxlStatus st = mxlCreateFlowWriter(
instance(), flow_def.c_str(), nullptr, &writer, &cfg_info, &created);
if (st != MXL_STATUS_OK) {
log("mxlCreateFlowWriter failed (status=%d)", st);
return;
}
const uint32_t stride = cfg_info.discrete.sliceSizes[0];
const auto pattern = config().value("pattern", "bars");
log("stride=%u B/line grain=%u B ring=%u grains pattern=%s",
stride, stride * static_cast<uint32_t>(height), cfg_info.discrete.grainCount,
pattern.c_str());
const mxlRational rate = {fps_num, fps_den};
uint64_t index = mxlGetCurrentIndex(&rate);
log("start index=%llu", index);
while (dmf::g_running.load(std::memory_order_relaxed)) {
mxlGrainInfo grain{};
uint8_t* buf = nullptr;
st = mxlFlowWriterOpenGrain(writer, index, &grain, &buf);
if (st != MXL_STATUS_OK) {
log("OpenGrain failed (status=%d), skipping index=%llu", st, index);
index++;
continue;
}
if (pattern == "bars") dmf::v210::fill_colorbars(buf, width, height, stride);
else if (pattern == "ire") dmf::v210::fill_ire_ramp (buf, width, height, stride);
else if (pattern == "black") dmf::v210::fill_black (buf, width, height, stride);
else if (pattern == "white") dmf::v210::fill_white (buf, width, height, stride);
else dmf::v210::fill_colorbars (buf, width, height, stride);
grain.flags = 0;
grain.validSlices = grain.totalSlices; // mark grain complete so readers can consume it
mxlFlowWriterCommitGrain(writer, &grain);
const uint64_t ns = mxlGetNsUntilIndex(index + 1, &rate);
if (ns > 0 && ns < 2'000'000'000ULL) mxlSleepForNs(ns);
index++;
}
log("stopped at index=%llu", index);
mxlReleaseFlowWriter(instance(), writer);
}
};
int main() {
TestPatternNode node;
return node.execute();
}