192 lines
6.4 KiB
C++
192 lines
6.4 KiB
C++
#include "AppConfigProvider.h"
|
|
#include "AppConfigJson.h"
|
|
#include "DeckLinkDisplayMode.h"
|
|
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
namespace
|
|
{
|
|
int gFailures = 0;
|
|
|
|
void Expect(bool condition, const std::string& message)
|
|
{
|
|
if (condition)
|
|
return;
|
|
|
|
++gFailures;
|
|
std::cerr << "FAILED: " << message << "\n";
|
|
}
|
|
|
|
std::filesystem::path WriteConfigFixture()
|
|
{
|
|
const std::filesystem::path path = std::filesystem::temp_directory_path() / "render-cadence-compositor-config-test.json";
|
|
std::ofstream output(path, std::ios::binary);
|
|
output
|
|
<< "{\n"
|
|
<< " \"shaderLibrary\": \"test-shaders\",\n"
|
|
<< " \"serverPort\": 8181,\n"
|
|
<< " \"oscBindAddress\": \"127.0.0.1\",\n"
|
|
<< " \"oscPort\": 9100,\n"
|
|
<< " \"oscSmoothing\": 0.25,\n"
|
|
<< " \"input\": {\n"
|
|
<< " \"backend\": \"none\",\n"
|
|
<< " \"device\": \"input-card-1\",\n"
|
|
<< " \"resolution\": \"720p\",\n"
|
|
<< " \"frameRate\": \"50\"\n"
|
|
<< " },\n"
|
|
<< " \"output\": {\n"
|
|
<< " \"backend\": \"decklink\",\n"
|
|
<< " \"device\": \"output-card-1\",\n"
|
|
<< " \"resolution\": \"2160p\",\n"
|
|
<< " \"frameRate\": \"60\",\n"
|
|
<< " \"pixelFormat\": \"uyvy8\",\n"
|
|
<< " \"keying\": {\n"
|
|
<< " \"external\": true,\n"
|
|
<< " \"alphaRequired\": true\n"
|
|
<< " }\n"
|
|
<< " },\n"
|
|
<< " \"autoReload\": false,\n"
|
|
<< " \"maxTemporalHistoryFrames\": 8,\n"
|
|
<< " \"previewEnabled\": true,\n"
|
|
<< " \"previewFps\": 24,\n"
|
|
<< " \"runtimeShaderId\": \"solid-color\"\n"
|
|
<< "}\n";
|
|
return path;
|
|
}
|
|
|
|
void TestLoadsRuntimeHostConfig()
|
|
{
|
|
using namespace RenderCadenceCompositor;
|
|
|
|
const std::filesystem::path path = WriteConfigFixture();
|
|
AppConfigProvider provider;
|
|
std::string error;
|
|
const bool loaded = provider.Load(path, error);
|
|
const AppConfig& config = provider.Config();
|
|
|
|
Expect(loaded, "config loads");
|
|
Expect(error.empty(), "config load has no error");
|
|
Expect(provider.LoadedFromFile(), "provider records file load");
|
|
Expect(config.shaderLibrary == "test-shaders", "shader library loads");
|
|
Expect(config.http.preferredPort == 8181, "server port loads");
|
|
Expect(config.oscBindAddress == "127.0.0.1", "OSC bind address loads");
|
|
Expect(config.oscPort == 9100, "OSC port loads");
|
|
Expect(config.oscSmoothing == 0.25, "OSC smoothing loads");
|
|
Expect(config.input.resolution == "720p", "input resolution loads");
|
|
Expect(config.input.frameRate == "50", "input frame rate loads");
|
|
Expect(config.input.device == "input-card-1", "input device loads");
|
|
Expect(config.output.resolution == "2160p", "output resolution loads");
|
|
Expect(config.output.frameRate == "60", "output frame rate loads");
|
|
Expect(config.output.pixelFormat == "uyvy8", "output pixel format loads");
|
|
Expect(config.output.device == "output-card-1", "output device loads");
|
|
Expect(config.input.backend == "none", "video input backend loads");
|
|
Expect(config.output.backend == "decklink", "video output backend loads");
|
|
Expect(!config.autoReload, "auto reload loads");
|
|
Expect(config.maxTemporalHistoryFrames == 8, "history length loads");
|
|
Expect(config.previewEnabled, "preview enabled toggle loads");
|
|
Expect(config.previewFps == 24.0, "preview fps loads");
|
|
Expect(config.runtimeShaderId == "solid-color", "runtime shader id loads");
|
|
Expect(config.output.externalKeyingEnabled, "external keying loads");
|
|
Expect(config.output.outputAlphaRequired, "output alpha requirement loads");
|
|
|
|
std::filesystem::remove(path);
|
|
}
|
|
|
|
void TestCommandLineOverrides()
|
|
{
|
|
using namespace RenderCadenceCompositor;
|
|
|
|
AppConfigProvider provider;
|
|
const char* argv[] = {
|
|
"app.exe",
|
|
"--shader",
|
|
"solid-color",
|
|
"--port",
|
|
"8282"
|
|
};
|
|
provider.ApplyCommandLine(5, const_cast<char**>(argv));
|
|
|
|
const AppConfig& config = provider.Config();
|
|
Expect(config.runtimeShaderId == "solid-color", "shader CLI override applies");
|
|
Expect(config.http.preferredPort == 8282, "port CLI override applies");
|
|
}
|
|
|
|
void TestPreviewDefaultsAreOptIn()
|
|
{
|
|
using namespace RenderCadenceCompositor;
|
|
|
|
const AppConfig config = DefaultAppConfig();
|
|
Expect(!config.previewEnabled, "preview is disabled by default");
|
|
Expect(config.previewFps == 60.0, "preview fps default is 60");
|
|
}
|
|
|
|
void TestConfigJsonRoundTrip()
|
|
{
|
|
using namespace RenderCadenceCompositor;
|
|
|
|
AppConfig config = DefaultAppConfig();
|
|
config.shaderLibrary = "custom-shaders";
|
|
config.output.backend = "ndi";
|
|
config.output.device = "Program";
|
|
config.output.pixelFormat = "uyvy8";
|
|
config.previewEnabled = true;
|
|
config.runtimeShaderId = "solid-color";
|
|
|
|
const std::string json = AppConfigToJson(config);
|
|
AppConfig parsed;
|
|
std::string error;
|
|
Expect(ParseAppConfigJson(json, parsed, error), "serialized config parses");
|
|
Expect(error.empty(), "serialized config parse has no error");
|
|
Expect(parsed.shaderLibrary == "custom-shaders", "shader library round trips");
|
|
Expect(parsed.output.backend == "ndi", "output backend round trips");
|
|
Expect(parsed.output.device == "Program", "output device round trips");
|
|
Expect(parsed.output.pixelFormat == "uyvy8", "output pixel format round trips");
|
|
Expect(parsed.previewEnabled, "preview enabled round trips");
|
|
Expect(parsed.runtimeShaderId == "solid-color", "runtime shader id round trips");
|
|
}
|
|
|
|
void TestHelpers()
|
|
{
|
|
using namespace RenderCadenceCompositor;
|
|
|
|
unsigned width = 0;
|
|
unsigned height = 0;
|
|
VideoFormatDimensions("720p", width, height);
|
|
Expect(width == 1280 && height == 720, "720p dimensions resolve");
|
|
|
|
VideoFormatDimensions("2160p", width, height);
|
|
Expect(width == 3840 && height == 2160, "2160p dimensions resolve");
|
|
|
|
const double duration = FrameDurationMillisecondsFromRateString("50");
|
|
Expect(duration > 19.9 && duration < 20.1, "frame duration parses numeric rate");
|
|
const double deckLinkDuration = FrameDurationMillisecondsFromDisplayMode(bmdModeHD1080p5994, 0.0);
|
|
Expect(deckLinkDuration > 16.6833 && deckLinkDuration < 16.6834, "DeckLink 59.94 display mode duration is exact");
|
|
|
|
const std::filesystem::path configPath = FindConfigFile();
|
|
Expect(!configPath.empty(), "default config is discoverable from test working directory");
|
|
Expect(configPath.filename() == "runtime-host.json", "default config discovery returns runtime-host.json");
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
TestLoadsRuntimeHostConfig();
|
|
TestCommandLineOverrides();
|
|
TestPreviewDefaultsAreOptIn();
|
|
TestConfigJsonRoundTrip();
|
|
TestHelpers();
|
|
|
|
if (gFailures != 0)
|
|
{
|
|
std::cerr << gFailures << " RenderCadenceCompositorAppConfigProvider test failure(s).\n";
|
|
return 1;
|
|
}
|
|
|
|
std::cout << "RenderCadenceCompositorAppConfigProvider tests passed.\n";
|
|
return 0;
|
|
}
|