From 315cbda9d1178507789760b33da5d9bd93e55132 Mon Sep 17 00:00:00 2001 From: Aiden Date: Fri, 22 May 2026 15:22:11 +1000 Subject: [PATCH] replace direct ownership --- src/app/AppConfig.h | 4 ++-- src/app/RenderCadenceApp.h | 28 ++++++++++++++------------- src/video/core/VideoIOEdges.h | 8 ++++++++ src/video/decklink/DeckLinkOutput.cpp | 2 +- src/video/decklink/DeckLinkOutput.h | 12 +++--------- tests/VideoOutputThreadTests.cpp | 1 + 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/app/AppConfig.h b/src/app/AppConfig.h index c886eb6..0b38db8 100644 --- a/src/app/AppConfig.h +++ b/src/app/AppConfig.h @@ -4,7 +4,7 @@ #include "../logging/Logger.h" #include "../preview/PreviewConfig.h" #include "../telemetry/TelemetryHealthMonitor.h" -#include "DeckLinkOutput.h" +#include "VideoIOEdges.h" #include "VideoOutputThread.h" #include @@ -15,7 +15,7 @@ namespace RenderCadenceCompositor { struct AppConfig { - DeckLinkOutputConfig deckLink; + VideoOutputEdgeConfig deckLink; VideoOutputThreadConfig outputThread; TelemetryHealthMonitorConfig telemetry; LoggerConfig logging; diff --git a/src/app/RenderCadenceApp.h b/src/app/RenderCadenceApp.h index eed64f1..807dc19 100644 --- a/src/app/RenderCadenceApp.h +++ b/src/app/RenderCadenceApp.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,8 @@ public: mRenderThread(renderThread), mFrameExchange(frameExchange), mConfig(config), - mOutputThread(mOutput, mFrameExchange, VideoOutputThreadConfig{ + mOutput(std::make_unique()), + mOutputThread(*mOutput, mFrameExchange, VideoOutputThreadConfig{ mConfig.outputThread.targetBufferedFrames, mConfig.outputThread.idleSleep }), @@ -100,7 +102,7 @@ public: StartPreviewWindow(); StartOptionalVideoOutput(); - mTelemetryHealth.Start(mFrameExchange, mOutput, mOutputThread, mRenderThread); + mTelemetryHealth.Start(mFrameExchange, *mOutput, mOutputThread, mRenderThread); StartHttpServer(); Log("app", "RenderCadenceCompositor started."); mStarted = true; @@ -113,17 +115,17 @@ public: mTelemetryHealth.Stop(); mPreviewWindow.Stop(); mOutputThread.Stop(); - mOutput.Stop(); + mOutput->Stop(); mRuntimeLayers.Stop(); mRenderThread.Stop(); - mOutput.ReleaseResources(); + mOutput->ReleaseResources(); if (mStarted) Log("app", "RenderCadenceCompositor shutdown complete."); mStarted = false; } bool Started() const { return mStarted; } - const IVideoOutputEdge& Output() const { return mOutput; } + const IVideoOutputEdge& Output() const { return *mOutput; } void SetVideoInputMetricsProvider(std::function provider) { mVideoInputMetricsProvider = std::move(provider); @@ -134,7 +136,7 @@ private: { std::string outputError; Log("app", "Initializing optional DeckLink output."); - if (!mOutput.Initialize( + if (!mOutput->Initialize( mConfig.deckLink, [this](const VideoIOCompletion& completion) { mFrameExchange.ReleaseScheduledByBytes(completion.outputFrameBuffer); @@ -160,7 +162,7 @@ private: } Log("app", "Starting DeckLink scheduled playback."); - if (!mOutput.StartScheduledPlayback(outputError)) + if (!mOutput->StartScheduledPlayback(outputError)) { DisableVideoOutput("DeckLink scheduled playback failed: " + outputError); return; @@ -171,8 +173,8 @@ private: Log("app", mVideoOutputStatus); Log( "app", - "DeckLink output mode: " + mOutput.State().outputDisplayModeName + - ", frame budget " + std::to_string(mOutput.State().frameBudgetMilliseconds) + " ms."); + "DeckLink output mode: " + mOutput->State().outputDisplayModeName + + ", frame budget " + std::to_string(mOutput->State().frameBudgetMilliseconds) + " ms."); } bool BuildSettledOutputReserve(std::string& error) @@ -193,8 +195,8 @@ private: void DisableVideoOutput(const std::string& reason) { mOutputThread.Stop(); - mOutput.Stop(); - mOutput.ReleaseResources(); + mOutput->Stop(); + mOutput->ReleaseResources(); mFrameExchange.Clear(); mVideoOutputEnabled = false; mVideoOutputStatus = reason; @@ -254,7 +256,7 @@ private: std::string BuildStateJson() { - CadenceTelemetrySnapshot telemetry = mHttpTelemetry.Sample(mFrameExchange, mOutput, mOutputThread, mRenderThread); + CadenceTelemetrySnapshot telemetry = mHttpTelemetry.Sample(mFrameExchange, *mOutput, mOutputThread, mRenderThread); ApplyVideoInputMetrics(telemetry); RuntimeLayerModelSnapshot layerSnapshot = mRuntimeLayers.Snapshot(telemetry); return RuntimeStateToJson(RuntimeStateJsonInput{ @@ -300,7 +302,7 @@ private: RenderThread& mRenderThread; SystemFrameExchange& mFrameExchange; AppConfig mConfig; - DeckLinkOutput mOutput; + std::unique_ptr mOutput; VideoOutputThread mOutputThread; TelemetryHealthMonitor mTelemetryHealth; CadenceTelemetry mHttpTelemetry; diff --git a/src/video/core/VideoIOEdges.h b/src/video/core/VideoIOEdges.h index 5f52336..b89d684 100644 --- a/src/video/core/VideoIOEdges.h +++ b/src/video/core/VideoIOEdges.h @@ -52,6 +52,13 @@ struct VideoOutputEdgeMetrics uint64_t scheduleRealignmentCount = 0; }; +struct VideoOutputEdgeConfig +{ + VideoFormat outputVideoMode; + bool externalKeyingEnabled = false; + bool outputAlphaRequired = false; +}; + class IVideoOutputEdge { public: @@ -59,6 +66,7 @@ public: virtual ~IVideoOutputEdge() = default; + virtual bool Initialize(const VideoOutputEdgeConfig& config, CompletionCallback completionCallback, std::string& error) = 0; virtual bool StartScheduledPlayback(std::string& error) = 0; virtual bool ScheduleFrame(const VideoIOOutputFrame& frame) = 0; virtual void Stop() = 0; diff --git a/src/video/decklink/DeckLinkOutput.cpp b/src/video/decklink/DeckLinkOutput.cpp index 5212f8c..53dafeb 100644 --- a/src/video/decklink/DeckLinkOutput.cpp +++ b/src/video/decklink/DeckLinkOutput.cpp @@ -9,7 +9,7 @@ DeckLinkOutput::~DeckLinkOutput() ReleaseResources(); } -bool DeckLinkOutput::Initialize(const DeckLinkOutputConfig& config, CompletionCallback completionCallback, std::string& error) +bool DeckLinkOutput::Initialize(const VideoOutputEdgeConfig& config, CompletionCallback completionCallback, std::string& error) { mConfig = config; mCompletionCallback = completionCallback; diff --git a/src/video/decklink/DeckLinkOutput.h b/src/video/decklink/DeckLinkOutput.h index 066b9c6..5138c7b 100644 --- a/src/video/decklink/DeckLinkOutput.h +++ b/src/video/decklink/DeckLinkOutput.h @@ -12,13 +12,7 @@ namespace RenderCadenceCompositor { -struct DeckLinkOutputConfig -{ - VideoFormat outputVideoMode; - bool externalKeyingEnabled = false; - bool outputAlphaRequired = false; -}; - +using DeckLinkOutputConfig = VideoOutputEdgeConfig; using DeckLinkOutputMetrics = VideoOutputEdgeMetrics; class DeckLinkOutput : public IVideoOutputEdge @@ -31,7 +25,7 @@ public: DeckLinkOutput& operator=(const DeckLinkOutput&) = delete; ~DeckLinkOutput(); - bool Initialize(const DeckLinkOutputConfig& config, CompletionCallback completionCallback, std::string& error); + bool Initialize(const VideoOutputEdgeConfig& config, CompletionCallback completionCallback, std::string& error) override; bool StartScheduledPlayback(std::string& error) override; bool ScheduleFrame(const VideoIOOutputFrame& frame) override; void Stop() override; @@ -44,7 +38,7 @@ private: void HandleCompletion(const VideoIOCompletion& completion); DeckLinkSession mSession; - DeckLinkOutputConfig mConfig; + VideoOutputEdgeConfig mConfig; CompletionCallback mCompletionCallback; std::atomic mCompletions{ 0 }; std::atomic mDisplayedLate{ 0 }; diff --git a/tests/VideoOutputThreadTests.cpp b/tests/VideoOutputThreadTests.cpp index f1df8b5..db83474 100644 --- a/tests/VideoOutputThreadTests.cpp +++ b/tests/VideoOutputThreadTests.cpp @@ -68,6 +68,7 @@ private: class FakeOutputEdge final : public RenderCadenceCompositor::IVideoOutputEdge { public: + bool Initialize(const RenderCadenceCompositor::VideoOutputEdgeConfig&, CompletionCallback, std::string&) override { return true; } bool StartScheduledPlayback(std::string&) override { return true; } bool ScheduleFrame(const VideoIOOutputFrame& frame) override {