decklink separation
Some checks failed
CI / Native Windows Build And Tests (push) Has been cancelled
CI / React UI Build (push) Has been cancelled
CI / Windows Release Package (push) Has been cancelled

This commit is contained in:
2026-05-06 10:31:21 +10:00
parent 8ec87685b8
commit 6918306336
7 changed files with 319 additions and 298 deletions

View File

@@ -47,6 +47,8 @@ set(APP_SOURCES
"${APP_DIR}/decklink/DeckLinkDisplayMode.h" "${APP_DIR}/decklink/DeckLinkDisplayMode.h"
"${APP_DIR}/decklink/DeckLinkFrameTransfer.cpp" "${APP_DIR}/decklink/DeckLinkFrameTransfer.cpp"
"${APP_DIR}/decklink/DeckLinkFrameTransfer.h" "${APP_DIR}/decklink/DeckLinkFrameTransfer.h"
"${APP_DIR}/decklink/DeckLinkSession.cpp"
"${APP_DIR}/decklink/DeckLinkSession.h"
"${APP_DIR}/gl/GLExtensions.cpp" "${APP_DIR}/gl/GLExtensions.cpp"
"${APP_DIR}/gl/GLExtensions.h" "${APP_DIR}/gl/GLExtensions.h"
"${APP_DIR}/gl/GlRenderConstants.h" "${APP_DIR}/gl/GlRenderConstants.h"

View File

@@ -207,6 +207,7 @@
</ClCompile> </ClCompile>
<ClCompile Include="gl\VideoFrameTransfer.cpp" /> <ClCompile Include="gl\VideoFrameTransfer.cpp" />
<ClCompile Include="DeckLinkAPI_i.c" /> <ClCompile Include="DeckLinkAPI_i.c" />
<ClCompile Include="decklink\DeckLinkSession.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="gl\GLExtensions.h" /> <ClInclude Include="gl\GLExtensions.h" />
@@ -220,6 +221,7 @@
<ClInclude Include="stdafx.h" /> <ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" /> <ClInclude Include="targetver.h" />
<ClInclude Include="gl\VideoFrameTransfer.h" /> <ClInclude Include="gl\VideoFrameTransfer.h" />
<ClInclude Include="decklink\DeckLinkSession.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="LoopThroughWithOpenGLCompositing.ico" /> <Image Include="LoopThroughWithOpenGLCompositing.ico" />

View File

@@ -48,6 +48,9 @@
<ClCompile Include="DeckLinkAPI_i.c"> <ClCompile Include="DeckLinkAPI_i.c">
<Filter>DeckLink API</Filter> <Filter>DeckLink API</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="decklink\DeckLinkSession.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="gl\GLExtensions.h"> <ClInclude Include="gl\GLExtensions.h">
@@ -83,6 +86,9 @@
<ClInclude Include="gl\VideoFrameTransfer.h"> <ClInclude Include="gl\VideoFrameTransfer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="decklink\DeckLinkSession.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="LoopThroughWithOpenGLCompositing.ico"> <Image Include="LoopThroughWithOpenGLCompositing.ico">

View File

@@ -0,0 +1,148 @@
#include "DeckLinkSession.h"
#include "GlRenderConstants.h"
#include <cstring>
DeckLinkSession::~DeckLinkSession()
{
ReleaseResources();
}
void DeckLinkSession::ReleaseResources()
{
if (input != nullptr)
{
input->SetCallback(nullptr);
if (captureDelegate != nullptr)
{
captureDelegate->Release();
captureDelegate = nullptr;
}
input->Release();
input = nullptr;
}
while (!outputVideoFrameQueue.empty())
{
IDeckLinkMutableVideoFrame* frameToRelease = outputVideoFrameQueue.front();
if (frameToRelease != nullptr)
frameToRelease->Release();
outputVideoFrameQueue.pop_front();
}
if (output != nullptr)
{
if (keyer != nullptr)
{
keyer->Disable();
keyer->Release();
keyer = nullptr;
externalKeyingActive = false;
}
output->SetScheduledFrameCompletionCallback(nullptr);
if (playoutDelegate != nullptr)
{
playoutDelegate->Release();
playoutDelegate = nullptr;
}
output->Release();
output = nullptr;
}
if (playoutAllocator != nullptr)
{
playoutAllocator->Release();
playoutAllocator = nullptr;
}
}
bool DeckLinkSession::Start(unsigned outputHeight)
{
totalPlayoutFrames = 0;
if (!output)
{
MessageBoxA(NULL, "Cannot start playout because no DeckLink output device is available.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
if (outputVideoFrameQueue.empty())
{
MessageBoxA(NULL, "Cannot start playout because the output frame queue is empty.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
for (unsigned i = 0; i < kPrerollFrameCount; i++)
{
IDeckLinkMutableVideoFrame* outputVideoFrame = outputVideoFrameQueue.front();
outputVideoFrameQueue.push_back(outputVideoFrame);
outputVideoFrameQueue.pop_front();
IDeckLinkVideoBuffer* outputVideoFrameBuffer;
if (outputVideoFrame->QueryInterface(IID_IDeckLinkVideoBuffer, (void**)&outputVideoFrameBuffer) != S_OK)
{
MessageBoxA(NULL, "Could not query the preroll output frame buffer.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
if (outputVideoFrameBuffer->StartAccess(bmdBufferAccessWrite) != S_OK)
{
outputVideoFrameBuffer->Release();
MessageBoxA(NULL, "Could not write to the preroll output frame buffer.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
void* pFrame;
outputVideoFrameBuffer->GetBytes((void**)&pFrame);
memset(pFrame, 0, outputVideoFrame->GetRowBytes() * outputHeight);
outputVideoFrameBuffer->EndAccess(bmdBufferAccessWrite);
outputVideoFrameBuffer->Release();
if (output->ScheduleVideoFrame(outputVideoFrame, (totalPlayoutFrames * frameDuration), frameDuration, frameTimescale) != S_OK)
{
MessageBoxA(NULL, "Could not schedule a preroll output frame.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
totalPlayoutFrames++;
}
if (input)
{
if (input->StartStreams() != S_OK)
{
MessageBoxA(NULL, "Could not start the DeckLink input stream.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
}
if (output->StartScheduledPlayback(0, frameTimescale, 1.0) != S_OK)
{
MessageBoxA(NULL, "Could not start DeckLink scheduled playback.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
return true;
}
bool DeckLinkSession::Stop()
{
if (keyer != nullptr)
{
keyer->Disable();
externalKeyingActive = false;
}
if (input)
{
input->StopStreams();
input->DisableVideoInput();
}
if (output)
{
output->StopScheduledPlayback(0, NULL, 0);
output->DisableVideoOutput();
}
return true;
}

View File

@@ -0,0 +1,44 @@
#pragma once
#include "DeckLinkAPI_h.h"
#include "DeckLinkFrameTransfer.h"
#include <deque>
#include <string>
class OpenGLComposite;
class DeckLinkSession
{
public:
DeckLinkSession() = default;
~DeckLinkSession();
void ReleaseResources();
bool Start(unsigned outputFrameHeight);
bool Stop();
CaptureDelegate* captureDelegate = nullptr;
PlayoutDelegate* playoutDelegate = nullptr;
IDeckLinkInput* input = nullptr;
IDeckLinkOutput* output = nullptr;
IDeckLinkKeyer* keyer = nullptr;
std::deque<IDeckLinkMutableVideoFrame*> outputVideoFrameQueue;
PinnedMemoryAllocator* playoutAllocator = nullptr;
BMDTimeValue frameDuration = 0;
BMDTimeScale frameTimescale = 0;
unsigned totalPlayoutFrames = 0;
unsigned inputFrameWidth = 0;
unsigned inputFrameHeight = 0;
unsigned outputFrameWidth = 0;
unsigned outputFrameHeight = 0;
std::string inputDisplayModeName = "1080p59.94";
std::string outputDisplayModeName = "1080p59.94";
bool hasNoInputSource = true;
std::string outputModelName;
bool supportsInternalKeying = false;
bool supportsExternalKeying = false;
bool keyerInterfaceAvailable = false;
bool externalKeyingActive = false;
std::string statusMessage;
};

View File

@@ -41,6 +41,7 @@
#include "ControlServer.h" #include "ControlServer.h"
#include "DeckLinkDisplayMode.h" #include "DeckLinkDisplayMode.h"
#include "DeckLinkFrameTransfer.h" #include "DeckLinkFrameTransfer.h"
#include "DeckLinkSession.h"
#include "OpenGLComposite.h" #include "OpenGLComposite.h"
#include "GLExtensions.h" #include "GLExtensions.h"
#include "GlRenderConstants.h" #include "GlRenderConstants.h"
@@ -55,18 +56,7 @@
OpenGLComposite::OpenGLComposite(HWND hWnd, HDC hDC, HGLRC hRC) : OpenGLComposite::OpenGLComposite(HWND hWnd, HDC hDC, HGLRC hRC) :
hGLWnd(hWnd), hGLDC(hDC), hGLRC(hRC), hGLWnd(hWnd), hGLDC(hDC), hGLRC(hRC),
mCaptureDelegate(NULL), mPlayoutDelegate(NULL), mDeckLink(std::make_unique<DeckLinkSession>()),
mDLInput(NULL), mDLOutput(NULL), mDLKeyer(NULL),
mPlayoutAllocator(NULL),
mInputFrameWidth(0), mInputFrameHeight(0),
mOutputFrameWidth(0), mOutputFrameHeight(0),
mInputDisplayModeName("1080p59.94"),
mOutputDisplayModeName("1080p59.94"),
mHasNoInputSource(true),
mDeckLinkSupportsInternalKeying(false),
mDeckLinkSupportsExternalKeying(false),
mDeckLinkKeyerInterfaceAvailable(false),
mDeckLinkExternalKeyingActive(false),
mRenderer(std::make_unique<OpenGLRenderer>()) mRenderer(std::make_unique<OpenGLRenderer>())
{ {
InitializeCriticalSection(&pMutex); InitializeCriticalSection(&pMutex);
@@ -79,60 +69,7 @@ OpenGLComposite::OpenGLComposite(HWND hWnd, HDC hDC, HGLRC hRC) :
OpenGLComposite::~OpenGLComposite() OpenGLComposite::~OpenGLComposite()
{ {
// Cleanup for Capture mDeckLink->ReleaseResources();
if (mDLInput != NULL)
{
mDLInput->SetCallback(NULL);
mDLInput->Release();
mDLInput = NULL;
}
if (mCaptureDelegate != NULL)
{
mCaptureDelegate->Release();
mCaptureDelegate = NULL;
}
// Cleanup for Playout
while (!mDLOutputVideoFrameQueue.empty())
{
IDeckLinkMutableVideoFrame* frameToRelease = mDLOutputVideoFrameQueue.front();
if (frameToRelease != NULL)
{
frameToRelease->Release();
frameToRelease = NULL;
}
mDLOutputVideoFrameQueue.pop_front();
}
if (mDLOutput != NULL)
{
if (mDLKeyer != NULL)
{
mDLKeyer->Disable();
mDLKeyer->Release();
mDLKeyer = NULL;
}
mDLOutput->SetScheduledFrameCompletionCallback(NULL);
mDLOutput->Release();
mDLOutput = NULL;
}
if (mPlayoutDelegate != NULL)
{
mPlayoutDelegate->Release();
mPlayoutDelegate = NULL;
}
if (mPlayoutAllocator != NULL)
{
mPlayoutAllocator->Release();
mPlayoutAllocator = NULL;
}
mRenderer->DestroyResources(); mRenderer->DestroyResources();
if (mOscServer) if (mOscServer)
mOscServer->Stop(); mOscServer->Stop();
@@ -187,8 +124,8 @@ bool OpenGLComposite::InitDeckLink()
return false; return false;
} }
} }
mInputDisplayModeName = inputDisplayModeName; mDeckLink->inputDisplayModeName = inputDisplayModeName;
mOutputDisplayModeName = outputDisplayModeName; mDeckLink->outputDisplayModeName = outputDisplayModeName;
result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&pDLIterator); result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&pDLIterator);
if (FAILED(result)) if (FAILED(result))
@@ -244,41 +181,41 @@ bool OpenGLComposite::InitDeckLink()
// Preserve the original input-then-output selection for half-duplex cards. // Preserve the original input-then-output selection for half-duplex cards.
// Input is optional later, but choosing output first can pick the wrong card. // Input is optional later, but choosing output first can pick the wrong card.
bool inputUsed = false; bool inputUsed = false;
if (!mDLInput && pDL->QueryInterface(IID_IDeckLinkInput, (void**)&mDLInput) == S_OK) if (!mDeckLink->input && pDL->QueryInterface(IID_IDeckLinkInput, (void**)&mDeckLink->input) == S_OK)
inputUsed = true; inputUsed = true;
if (!mDLOutput && (!inputUsed || (duplexMode == bmdDuplexFull))) if (!mDeckLink->output && (!inputUsed || (duplexMode == bmdDuplexFull)))
{ {
if (pDL->QueryInterface(IID_IDeckLinkOutput, (void**)&mDLOutput) != S_OK) if (pDL->QueryInterface(IID_IDeckLinkOutput, (void**)&mDeckLink->output) != S_OK)
mDLOutput = NULL; mDeckLink->output = NULL;
else else
{ {
mDeckLinkOutputModelName = modelName; mDeckLink->outputModelName = modelName;
mDeckLinkSupportsInternalKeying = supportsInternalKeying; mDeckLink->supportsInternalKeying = supportsInternalKeying;
mDeckLinkSupportsExternalKeying = supportsExternalKeying; mDeckLink->supportsExternalKeying = supportsExternalKeying;
} }
} }
pDL->Release(); pDL->Release();
pDL = NULL; pDL = NULL;
if (mDLOutput && mDLInput) if (mDeckLink->output && mDeckLink->input)
break; break;
} }
if (!mDLOutput) if (!mDeckLink->output)
{ {
MessageBox(NULL, _T("Expected an Output DeckLink device"), _T("This application requires a DeckLink output device."), MB_OK); MessageBox(NULL, _T("Expected an Output DeckLink device"), _T("This application requires a DeckLink output device."), MB_OK);
goto error; goto error;
} }
if (mDLInput && mDLInput->GetDisplayModeIterator(&pDLInputDisplayModeIterator) != S_OK) if (mDeckLink->input && mDeckLink->input->GetDisplayModeIterator(&pDLInputDisplayModeIterator) != S_OK)
{ {
MessageBox(NULL, _T("Cannot get input Display Mode Iterator."), _T("DeckLink error."), MB_OK); MessageBox(NULL, _T("Cannot get input Display Mode Iterator."), _T("DeckLink error."), MB_OK);
goto error; goto error;
} }
if (mDLInput && !FindDeckLinkDisplayMode(pDLInputDisplayModeIterator, inputDisplayMode, &pDLInputDisplayMode)) if (mDeckLink->input && !FindDeckLinkDisplayMode(pDLInputDisplayModeIterator, inputDisplayMode, &pDLInputDisplayMode))
{ {
const std::string error = "Cannot get specified input BMDDisplayMode for configured mode: " + inputDisplayModeName; const std::string error = "Cannot get specified input BMDDisplayMode for configured mode: " + inputDisplayModeName;
MessageBoxA(NULL, error.c_str(), "DeckLink input error.", MB_OK); MessageBoxA(NULL, error.c_str(), "DeckLink input error.", MB_OK);
@@ -290,7 +227,7 @@ bool OpenGLComposite::InitDeckLink()
pDLInputDisplayModeIterator = NULL; pDLInputDisplayModeIterator = NULL;
} }
if (mDLOutput->GetDisplayModeIterator(&pDLOutputDisplayModeIterator) != S_OK) if (mDeckLink->output->GetDisplayModeIterator(&pDLOutputDisplayModeIterator) != S_OK)
{ {
MessageBox(NULL, _T("Cannot get output Display Mode Iterator."), _T("DeckLink error."), MB_OK); MessageBox(NULL, _T("Cannot get output Display Mode Iterator."), _T("DeckLink error."), MB_OK);
goto error; goto error;
@@ -305,19 +242,19 @@ bool OpenGLComposite::InitDeckLink()
pDLOutputDisplayModeIterator->Release(); pDLOutputDisplayModeIterator->Release();
pDLOutputDisplayModeIterator = NULL; pDLOutputDisplayModeIterator = NULL;
mOutputFrameWidth = pDLOutputDisplayMode->GetWidth(); mDeckLink->outputFrameWidth = pDLOutputDisplayMode->GetWidth();
mOutputFrameHeight = pDLOutputDisplayMode->GetHeight(); mDeckLink->outputFrameHeight = pDLOutputDisplayMode->GetHeight();
mInputFrameWidth = pDLInputDisplayMode ? pDLInputDisplayMode->GetWidth() : mOutputFrameWidth; mDeckLink->inputFrameWidth = pDLInputDisplayMode ? pDLInputDisplayMode->GetWidth() : mDeckLink->outputFrameWidth;
mInputFrameHeight = pDLInputDisplayMode ? pDLInputDisplayMode->GetHeight() : mOutputFrameHeight; mDeckLink->inputFrameHeight = pDLInputDisplayMode ? pDLInputDisplayMode->GetHeight() : mDeckLink->outputFrameHeight;
if (!mDLInput) if (!mDeckLink->input)
mInputDisplayModeName = "No input - black frame"; mDeckLink->inputDisplayModeName = "No input - black frame";
if (! CheckOpenGLExtensions()) if (! CheckOpenGLExtensions())
{ {
initFailureReason = "OpenGL extension checks failed."; initFailureReason = "OpenGL extension checks failed.";
goto error; goto error;
} }
if (mInputFrameWidth != mOutputFrameWidth || mInputFrameHeight != mOutputFrameHeight) if (mDeckLink->inputFrameWidth != mDeckLink->outputFrameWidth || mDeckLink->inputFrameHeight != mDeckLink->outputFrameHeight)
{ {
mRenderer->mFastTransferExtensionAvailable = false; mRenderer->mFastTransferExtensionAvailable = false;
OutputDebugStringA("Input/output dimensions differ; using regular OpenGL transfer fallback instead of fast transfer.\n"); OutputDebugStringA("Input/output dimensions differ; using regular OpenGL transfer fallback instead of fast transfer.\n");
@@ -331,58 +268,58 @@ bool OpenGLComposite::InitDeckLink()
if (mRuntimeHost) if (mRuntimeHost)
{ {
mDeckLinkStatusMessage = mDeckLinkOutputModelName.empty() mDeckLink->statusMessage = mDeckLink->outputModelName.empty()
? "DeckLink output device selected." ? "DeckLink output device selected."
: ("Selected output device: " + mDeckLinkOutputModelName); : ("Selected output device: " + mDeckLink->outputModelName);
mRuntimeHost->SetDeckLinkOutputStatus( mRuntimeHost->SetDeckLinkOutputStatus(
mDeckLinkOutputModelName, mDeckLink->outputModelName,
mDeckLinkSupportsInternalKeying, mDeckLink->supportsInternalKeying,
mDeckLinkSupportsExternalKeying, mDeckLink->supportsExternalKeying,
mDeckLinkKeyerInterfaceAvailable, mDeckLink->keyerInterfaceAvailable,
mRuntimeHost->ExternalKeyingEnabled(), mRuntimeHost->ExternalKeyingEnabled(),
mDeckLinkExternalKeyingActive, mDeckLink->externalKeyingActive,
mDeckLinkStatusMessage); mDeckLink->statusMessage);
} }
pDLOutputDisplayMode->GetFrameRate(&mFrameDuration, &mFrameTimescale); pDLOutputDisplayMode->GetFrameRate(&mDeckLink->frameDuration, &mDeckLink->frameTimescale);
// Resize window to match output video frame, but scale large formats down by half for viewing. // Resize window to match output video frame, but scale large formats down by half for viewing.
if (mOutputFrameWidth < 1920) if (mDeckLink->outputFrameWidth < 1920)
resizeWindow(mOutputFrameWidth, mOutputFrameHeight); resizeWindow(mDeckLink->outputFrameWidth, mDeckLink->outputFrameHeight);
else else
resizeWindow(mOutputFrameWidth / 2, mOutputFrameHeight / 2); resizeWindow(mDeckLink->outputFrameWidth / 2, mDeckLink->outputFrameHeight / 2);
if (mRenderer->mFastTransferExtensionAvailable) if (mRenderer->mFastTransferExtensionAvailable)
{ {
// Initialize fast video frame transfers // Initialize fast video frame transfers
if (! VideoFrameTransfer::initialize(mInputFrameWidth, mInputFrameHeight, mRenderer->mCaptureTexture, mRenderer->mOutputTexture)) if (! VideoFrameTransfer::initialize(mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, mRenderer->mCaptureTexture, mRenderer->mOutputTexture))
{ {
MessageBox(NULL, _T("Cannot initialize video transfers."), _T("VideoFrameTransfer error."), MB_OK); MessageBox(NULL, _T("Cannot initialize video transfers."), _T("VideoFrameTransfer error."), MB_OK);
goto error; goto error;
} }
} }
if (mDLInput) if (mDeckLink->input)
{ {
// Use custom allocators so we pin only once then recycle them // Use custom allocators so we pin only once then recycle them
CComPtr<IDeckLinkVideoBufferAllocatorProvider> captureAllocator(new (std::nothrow) InputAllocatorPool(hGLDC, hGLRC)); CComPtr<IDeckLinkVideoBufferAllocatorProvider> captureAllocator(new (std::nothrow) InputAllocatorPool(hGLDC, hGLRC));
if (mDLInput->EnableVideoInputWithAllocatorProvider(inputDisplayMode, bmdFormat8BitYUV, bmdVideoInputFlagDefault, captureAllocator) != S_OK) if (mDeckLink->input->EnableVideoInputWithAllocatorProvider(inputDisplayMode, bmdFormat8BitYUV, bmdVideoInputFlagDefault, captureAllocator) != S_OK)
{ {
OutputDebugStringA("DeckLink input could not be enabled; continuing in output-only black-frame mode.\n"); OutputDebugStringA("DeckLink input could not be enabled; continuing in output-only black-frame mode.\n");
mDLInput->Release(); mDeckLink->input->Release();
mDLInput = NULL; mDeckLink->input = NULL;
mHasNoInputSource = true; mDeckLink->hasNoInputSource = true;
mInputDisplayModeName = "No input - black frame"; mDeckLink->inputDisplayModeName = "No input - black frame";
if (mRuntimeHost) if (mRuntimeHost)
mRuntimeHost->SetSignalStatus(false, mInputFrameWidth, mInputFrameHeight, mInputDisplayModeName); mRuntimeHost->SetSignalStatus(false, mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, mDeckLink->inputDisplayModeName);
} }
} }
if (mDLInput) if (mDeckLink->input)
{ {
mCaptureDelegate = new CaptureDelegate(this); mDeckLink->captureDelegate = new CaptureDelegate(this);
if (mDLInput->SetCallback(mCaptureDelegate) != S_OK) if (mDeckLink->input->SetCallback(mDeckLink->captureDelegate) != S_OK)
{ {
initFailureReason = "DeckLink input setup failed while installing the capture callback."; initFailureReason = "DeckLink input setup failed while installing the capture callback.";
goto error; goto error;
@@ -390,62 +327,62 @@ bool OpenGLComposite::InitDeckLink()
} }
else if (mRuntimeHost) else if (mRuntimeHost)
{ {
mRuntimeHost->SetSignalStatus(false, mInputFrameWidth, mInputFrameHeight, mInputDisplayModeName); mRuntimeHost->SetSignalStatus(false, mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, mDeckLink->inputDisplayModeName);
} }
if (mDLOutput->RowBytesForPixelFormat(bmdFormat8BitBGRA, mOutputFrameWidth, &outputFrameRowBytes) != S_OK) if (mDeckLink->output->RowBytesForPixelFormat(bmdFormat8BitBGRA, mDeckLink->outputFrameWidth, &outputFrameRowBytes) != S_OK)
{ {
initFailureReason = "DeckLink output setup failed while calculating BGRA row bytes."; initFailureReason = "DeckLink output setup failed while calculating BGRA row bytes.";
goto error; goto error;
} }
// Use a custom allocator so we pin only once then recycle them // Use a custom allocator so we pin only once then recycle them
mPlayoutAllocator = new PinnedMemoryAllocator(hGLDC, hGLRC, VideoFrameTransfer::GPUtoCPU, 1, outputFrameRowBytes * mOutputFrameHeight); mDeckLink->playoutAllocator = new PinnedMemoryAllocator(hGLDC, hGLRC, VideoFrameTransfer::GPUtoCPU, 1, outputFrameRowBytes * mDeckLink->outputFrameHeight);
if (mDLOutput->EnableVideoOutput(outputDisplayMode, bmdVideoOutputFlagDefault) != S_OK) if (mDeckLink->output->EnableVideoOutput(outputDisplayMode, bmdVideoOutputFlagDefault) != S_OK)
{ {
initFailureReason = "DeckLink output setup failed while enabling video output."; initFailureReason = "DeckLink output setup failed while enabling video output.";
goto error; goto error;
} }
if (mDLOutput->QueryInterface(IID_IDeckLinkKeyer, (void**)&mDLKeyer) == S_OK && mDLKeyer != NULL) if (mDeckLink->output->QueryInterface(IID_IDeckLinkKeyer, (void**)&mDeckLink->keyer) == S_OK && mDeckLink->keyer != NULL)
mDeckLinkKeyerInterfaceAvailable = true; mDeckLink->keyerInterfaceAvailable = true;
if (mRuntimeHost && mRuntimeHost->ExternalKeyingEnabled()) if (mRuntimeHost && mRuntimeHost->ExternalKeyingEnabled())
{ {
if (!mDeckLinkSupportsExternalKeying) if (!mDeckLink->supportsExternalKeying)
{ {
mDeckLinkStatusMessage = "External keying was requested, but the selected DeckLink output does not report external keying support."; mDeckLink->statusMessage = "External keying was requested, but the selected DeckLink output does not report external keying support.";
} }
else if (!mDeckLinkKeyerInterfaceAvailable) else if (!mDeckLink->keyerInterfaceAvailable)
{ {
mDeckLinkStatusMessage = "External keying was requested, but the selected DeckLink output does not expose the IDeckLinkKeyer interface."; mDeckLink->statusMessage = "External keying was requested, but the selected DeckLink output does not expose the IDeckLinkKeyer interface.";
} }
else if (mDLKeyer->Enable(TRUE) != S_OK || mDLKeyer->SetLevel(255) != S_OK) else if (mDeckLink->keyer->Enable(TRUE) != S_OK || mDeckLink->keyer->SetLevel(255) != S_OK)
{ {
mDeckLinkStatusMessage = "External keying was requested, but enabling the DeckLink keyer failed."; mDeckLink->statusMessage = "External keying was requested, but enabling the DeckLink keyer failed.";
} }
else else
{ {
mDeckLinkExternalKeyingActive = true; mDeckLink->externalKeyingActive = true;
mDeckLinkStatusMessage = "External keying is active on the selected DeckLink output."; mDeckLink->statusMessage = "External keying is active on the selected DeckLink output.";
} }
} }
else if (mDeckLinkSupportsExternalKeying) else if (mDeckLink->supportsExternalKeying)
{ {
mDeckLinkStatusMessage = "Selected DeckLink output supports external keying. Set enableExternalKeying to true in runtime-host.json to request it."; mDeckLink->statusMessage = "Selected DeckLink output supports external keying. Set enableExternalKeying to true in runtime-host.json to request it.";
} }
if (mRuntimeHost) if (mRuntimeHost)
{ {
mRuntimeHost->SetDeckLinkOutputStatus( mRuntimeHost->SetDeckLinkOutputStatus(
mDeckLinkOutputModelName, mDeckLink->outputModelName,
mDeckLinkSupportsInternalKeying, mDeckLink->supportsInternalKeying,
mDeckLinkSupportsExternalKeying, mDeckLink->supportsExternalKeying,
mDeckLinkKeyerInterfaceAvailable, mDeckLink->keyerInterfaceAvailable,
mRuntimeHost->ExternalKeyingEnabled(), mRuntimeHost->ExternalKeyingEnabled(),
mDeckLinkExternalKeyingActive, mDeckLink->externalKeyingActive,
mDeckLinkStatusMessage); mDeckLink->statusMessage);
} }
// Create a queue of 10 IDeckLinkMutableVideoFrame objects to use for scheduling output video frames. // Create a queue of 10 IDeckLinkMutableVideoFrame objects to use for scheduling output video frames.
@@ -460,29 +397,29 @@ bool OpenGLComposite::InitDeckLink()
IDeckLinkMutableVideoFrame* outputFrame; IDeckLinkMutableVideoFrame* outputFrame;
IDeckLinkVideoBuffer* outputFrameBuffer = NULL; IDeckLinkVideoBuffer* outputFrameBuffer = NULL;
if (mPlayoutAllocator->AllocateVideoBuffer(&outputFrameBuffer) != S_OK) if (mDeckLink->playoutAllocator->AllocateVideoBuffer(&outputFrameBuffer) != S_OK)
{ {
initFailureReason = "DeckLink output setup failed while allocating an output frame buffer."; initFailureReason = "DeckLink output setup failed while allocating an output frame buffer.";
goto error; goto error;
} }
if (mDLOutput->CreateVideoFrameWithBuffer(mOutputFrameWidth, mOutputFrameHeight, outputFrameRowBytes, bmdFormat8BitBGRA, bmdFrameFlagFlipVertical, outputFrameBuffer, &outputFrame) != S_OK) if (mDeckLink->output->CreateVideoFrameWithBuffer(mDeckLink->outputFrameWidth, mDeckLink->outputFrameHeight, outputFrameRowBytes, bmdFormat8BitBGRA, bmdFrameFlagFlipVertical, outputFrameBuffer, &outputFrame) != S_OK)
{ {
initFailureReason = "DeckLink output setup failed while creating an output video frame."; initFailureReason = "DeckLink output setup failed while creating an output video frame.";
goto error; goto error;
} }
mDLOutputVideoFrameQueue.push_back(outputFrame); mDeckLink->outputVideoFrameQueue.push_back(outputFrame);
} }
mPlayoutDelegate = new PlayoutDelegate(this); mDeckLink->playoutDelegate = new PlayoutDelegate(this);
if (mPlayoutDelegate == NULL) if (mDeckLink->playoutDelegate == NULL)
{ {
initFailureReason = "DeckLink output setup failed while creating the playout callback."; initFailureReason = "DeckLink output setup failed while creating the playout callback.";
goto error; goto error;
} }
if (mDLOutput->SetScheduledFrameCompletionCallback(mPlayoutDelegate) != S_OK) if (mDeckLink->output->SetScheduledFrameCompletionCallback(mDeckLink->playoutDelegate) != S_OK)
{ {
initFailureReason = "DeckLink output setup failed while installing the scheduled-frame callback."; initFailureReason = "DeckLink output setup failed while installing the scheduled-frame callback.";
goto error; goto error;
@@ -496,23 +433,7 @@ error:
if (!initFailureReason.empty()) if (!initFailureReason.empty())
MessageBoxA(NULL, initFailureReason.c_str(), "DeckLink initialization failed", MB_OK | MB_ICONERROR); MessageBoxA(NULL, initFailureReason.c_str(), "DeckLink initialization failed", MB_OK | MB_ICONERROR);
if (mDLKeyer != NULL) mDeckLink->ReleaseResources();
{
mDLKeyer->Disable();
mDLKeyer->Release();
mDLKeyer = NULL;
mDeckLinkExternalKeyingActive = false;
}
if (mDLInput != NULL)
{
mDLInput->Release();
mDLInput = NULL;
}
if (mDLOutput != NULL)
{
mDLOutput->Release();
mDLOutput = NULL;
}
} }
if (pDL != NULL) if (pDL != NULL)
@@ -562,7 +483,7 @@ void OpenGLComposite::paintGL()
return; return;
} }
mRenderer->PresentToWindow(hGLDC, mOutputFrameWidth, mOutputFrameHeight); mRenderer->PresentToWindow(hGLDC, mDeckLink->outputFrameWidth, mDeckLink->outputFrameHeight);
ValidateRect(hGLWnd, NULL); ValidateRect(hGLWnd, NULL);
LeaveCriticalSection(&pMutex); LeaveCriticalSection(&pMutex);
} }
@@ -609,7 +530,7 @@ bool OpenGLComposite::InitOpenGLState()
return false; return false;
} }
if (!mShaderPrograms->CompileLayerPrograms(mInputFrameWidth, mInputFrameHeight, sizeof(compilerErrorMessage), compilerErrorMessage)) if (!mShaderPrograms->CompileLayerPrograms(mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, sizeof(compilerErrorMessage), compilerErrorMessage))
{ {
MessageBoxA(NULL, compilerErrorMessage, "OpenGL shader failed to load or compile", MB_OK); MessageBoxA(NULL, compilerErrorMessage, "OpenGL shader failed to load or compile", MB_OK);
return false; return false;
@@ -617,7 +538,7 @@ bool OpenGLComposite::InitOpenGLState()
mShaderPrograms->ResetTemporalHistoryState(); mShaderPrograms->ResetTemporalHistoryState();
std::string rendererError; std::string rendererError;
if (!mRenderer->InitializeResources(mInputFrameWidth, mInputFrameHeight, mOutputFrameWidth, mOutputFrameHeight, rendererError)) if (!mRenderer->InitializeResources(mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, mDeckLink->outputFrameWidth, mDeckLink->outputFrameHeight, rendererError))
{ {
MessageBoxA(NULL, rendererError.c_str(), "OpenGL initialization error.", MB_OK); MessageBoxA(NULL, rendererError.c_str(), "OpenGL initialization error.", MB_OK);
return false; return false;
@@ -632,11 +553,11 @@ bool OpenGLComposite::InitOpenGLState()
// //
void OpenGLComposite::VideoFrameArrived(IDeckLinkVideoInputFrame* inputFrame, bool hasNoInputSource) void OpenGLComposite::VideoFrameArrived(IDeckLinkVideoInputFrame* inputFrame, bool hasNoInputSource)
{ {
mHasNoInputSource = hasNoInputSource; mDeckLink->hasNoInputSource = hasNoInputSource;
if (mRuntimeHost) if (mRuntimeHost)
mRuntimeHost->SetSignalStatus(!hasNoInputSource, mInputFrameWidth, mInputFrameHeight, mInputDisplayModeName); mRuntimeHost->SetSignalStatus(!hasNoInputSource, mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, mDeckLink->inputDisplayModeName);
if (mHasNoInputSource) if (mDeckLink->hasNoInputSource)
return; // don't transfer texture when there's no input return; // don't transfer texture when there's no input
long textureSize = inputFrame->GetRowBytes() * inputFrame->GetHeight(); long textureSize = inputFrame->GetRowBytes() * inputFrame->GetHeight();
@@ -673,7 +594,7 @@ void OpenGLComposite::VideoFrameArrived(IDeckLinkVideoInputFrame* inputFrame, bo
glBindTexture(GL_TEXTURE_2D, mRenderer->mCaptureTexture); glBindTexture(GL_TEXTURE_2D, mRenderer->mCaptureTexture);
// NULL for last arg indicates use current GL_PIXEL_UNPACK_BUFFER target as texture data // NULL for last arg indicates use current GL_PIXEL_UNPACK_BUFFER target as texture data
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mInputFrameWidth / 2, mInputFrameHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mDeckLink->inputFrameWidth / 2, mDeckLink->inputFrameHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
@@ -694,9 +615,9 @@ void OpenGLComposite::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame,
EnterCriticalSection(&pMutex); EnterCriticalSection(&pMutex);
// Get the first frame from the queue // Get the first frame from the queue
IDeckLinkMutableVideoFrame* outputVideoFrame = mDLOutputVideoFrameQueue.front(); IDeckLinkMutableVideoFrame* outputVideoFrame = mDeckLink->outputVideoFrameQueue.front();
mDLOutputVideoFrameQueue.push_back(outputVideoFrame); mDeckLink->outputVideoFrameQueue.push_back(outputVideoFrame);
mDLOutputVideoFrameQueue.pop_front(); mDeckLink->outputVideoFrameQueue.pop_front();
// make GL context current in this thread // make GL context current in this thread
wglMakeCurrent( hGLDC, hGLRC ); wglMakeCurrent( hGLDC, hGLRC );
@@ -709,7 +630,7 @@ void OpenGLComposite::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame,
renderEffect(); renderEffect();
glBindFramebuffer(GL_READ_FRAMEBUFFER, mRenderer->mIdFrameBuf); glBindFramebuffer(GL_READ_FRAMEBUFFER, mRenderer->mIdFrameBuf);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mRenderer->mOutputFrameBuf); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mRenderer->mOutputFrameBuf);
glBlitFramebuffer(0, 0, mInputFrameWidth, mInputFrameHeight, 0, 0, mOutputFrameWidth, mOutputFrameHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR); glBlitFramebuffer(0, 0, mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, 0, 0, mDeckLink->outputFrameWidth, mDeckLink->outputFrameHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_FRAMEBUFFER, mRenderer->mOutputFrameBuf); glBindFramebuffer(GL_FRAMEBUFFER, mRenderer->mOutputFrameBuf);
glFlush(); glFlush();
if (mRenderer->mFastTransferExtensionAvailable) if (mRenderer->mFastTransferExtensionAvailable)
@@ -717,8 +638,8 @@ void OpenGLComposite::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame,
const auto renderEndTime = std::chrono::steady_clock::now(); const auto renderEndTime = std::chrono::steady_clock::now();
if (mRuntimeHost) if (mRuntimeHost)
{ {
const double frameBudgetMilliseconds = mFrameTimescale != 0 const double frameBudgetMilliseconds = mDeckLink->frameTimescale != 0
? (static_cast<double>(mFrameDuration) * 1000.0) / static_cast<double>(mFrameTimescale) ? (static_cast<double>(mDeckLink->frameDuration) * 1000.0) / static_cast<double>(mDeckLink->frameTimescale)
: 0.0; : 0.0;
const double renderMilliseconds = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(renderEndTime - renderStartTime).count(); const double renderMilliseconds = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(renderEndTime - renderStartTime).count();
mRuntimeHost->SetPerformanceStats(frameBudgetMilliseconds, renderMilliseconds); mRuntimeHost->SetPerformanceStats(frameBudgetMilliseconds, renderMilliseconds);
@@ -746,21 +667,21 @@ void OpenGLComposite::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame,
if (mRenderer->mFastTransferExtensionAvailable) if (mRenderer->mFastTransferExtensionAvailable)
{ {
// Finished with mRenderer->mCaptureTexture // Finished with mRenderer->mCaptureTexture
if (!mHasNoInputSource) if (!mDeckLink->hasNoInputSource)
VideoFrameTransfer::endTextureInUse(VideoFrameTransfer::CPUtoGPU); VideoFrameTransfer::endTextureInUse(VideoFrameTransfer::CPUtoGPU);
if (! mPlayoutAllocator->transferFrame(pFrame, mRenderer->mOutputTexture)) if (! mDeckLink->playoutAllocator->transferFrame(pFrame, mRenderer->mOutputTexture))
OutputDebugStringA("Playback: transferFrame() failed\n"); OutputDebugStringA("Playback: transferFrame() failed\n");
paintGL(); paintGL();
// Wait for transfer to system memory to complete // Wait for transfer to system memory to complete
mPlayoutAllocator->waitForTransferComplete(pFrame); mDeckLink->playoutAllocator->waitForTransferComplete(pFrame);
} }
else else
{ {
glBindFramebuffer(GL_READ_FRAMEBUFFER, mRenderer->mOutputFrameBuf); glBindFramebuffer(GL_READ_FRAMEBUFFER, mRenderer->mOutputFrameBuf);
glReadPixels(0, 0, mOutputFrameWidth, mOutputFrameHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pFrame); glReadPixels(0, 0, mDeckLink->outputFrameWidth, mDeckLink->outputFrameHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pFrame);
paintGL(); paintGL();
} }
@@ -769,12 +690,12 @@ void OpenGLComposite::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame,
// If the last completed frame was late or dropped, bump the scheduled time further into the future // If the last completed frame was late or dropped, bump the scheduled time further into the future
if (completionResult == bmdOutputFrameDisplayedLate || completionResult == bmdOutputFrameDropped) if (completionResult == bmdOutputFrameDisplayedLate || completionResult == bmdOutputFrameDropped)
mTotalPlayoutFrames += 2; mDeckLink->totalPlayoutFrames += 2;
// Schedule the next frame for playout // Schedule the next frame for playout
HRESULT hr = mDLOutput->ScheduleVideoFrame(outputVideoFrame, (mTotalPlayoutFrames * mFrameDuration), mFrameDuration, mFrameTimescale); HRESULT hr = mDeckLink->output->ScheduleVideoFrame(outputVideoFrame, (mDeckLink->totalPlayoutFrames * mDeckLink->frameDuration), mDeckLink->frameDuration, mDeckLink->frameTimescale);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
mTotalPlayoutFrames++; mDeckLink->totalPlayoutFrames++;
wglMakeCurrent( NULL, NULL ); wglMakeCurrent( NULL, NULL );
@@ -783,72 +704,7 @@ void OpenGLComposite::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame,
bool OpenGLComposite::Start() bool OpenGLComposite::Start()
{ {
mTotalPlayoutFrames = 0; return mDeckLink->Start(mDeckLink->outputFrameHeight);
if (!mDLOutput)
{
MessageBoxA(NULL, "Cannot start playout because no DeckLink output device is available.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
if (mDLOutputVideoFrameQueue.empty())
{
MessageBoxA(NULL, "Cannot start playout because the output frame queue is empty.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
// Preroll frames
for (unsigned i = 0; i < kPrerollFrameCount; i++)
{
// Take each video frame from the front of the queue and move it to the back
IDeckLinkMutableVideoFrame* outputVideoFrame = mDLOutputVideoFrameQueue.front();
mDLOutputVideoFrameQueue.push_back(outputVideoFrame);
mDLOutputVideoFrameQueue.pop_front();
// Start with a black frame for playout
IDeckLinkVideoBuffer* outputVideoFrameBuffer;
if (outputVideoFrame->QueryInterface(IID_IDeckLinkVideoBuffer, (void**)&outputVideoFrameBuffer) != S_OK)
{
MessageBoxA(NULL, "Could not query the preroll output frame buffer.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
if (outputVideoFrameBuffer->StartAccess(bmdBufferAccessWrite) != S_OK)
{
outputVideoFrameBuffer->Release();
MessageBoxA(NULL, "Could not write to the preroll output frame buffer.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
void* pFrame;
outputVideoFrameBuffer->GetBytes((void**)&pFrame);
memset(pFrame, 0, outputVideoFrame->GetRowBytes() * mOutputFrameHeight); // 0 is black in BGRA format
outputVideoFrameBuffer->EndAccess(bmdBufferAccessWrite);
outputVideoFrameBuffer->Release();
if (mDLOutput->ScheduleVideoFrame(outputVideoFrame, (mTotalPlayoutFrames * mFrameDuration), mFrameDuration, mFrameTimescale) != S_OK)
{
MessageBoxA(NULL, "Could not schedule a preroll output frame.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
mTotalPlayoutFrames++;
}
if (mDLInput)
{
if (mDLInput->StartStreams() != S_OK)
{
MessageBoxA(NULL, "Could not start the DeckLink input stream.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
}
if (mDLOutput->StartScheduledPlayback(0, mFrameTimescale, 1.0) != S_OK)
{
MessageBoxA(NULL, "Could not start DeckLink scheduled playback.", "DeckLink start failed", MB_OK | MB_ICONERROR);
return false;
}
return true;
} }
bool OpenGLComposite::Stop() bool OpenGLComposite::Stop()
@@ -859,34 +715,19 @@ bool OpenGLComposite::Stop()
if (mControlServer) if (mControlServer)
mControlServer->Stop(); mControlServer->Stop();
if (mDLKeyer != NULL) const bool wasExternalKeyingActive = mDeckLink->externalKeyingActive;
{ mDeckLink->Stop();
mDLKeyer->Disable(); if (wasExternalKeyingActive && mRuntimeHost)
mDeckLinkExternalKeyingActive = false;
if (mRuntimeHost)
{ {
mRuntimeHost->SetDeckLinkOutputStatus( mRuntimeHost->SetDeckLinkOutputStatus(
mDeckLinkOutputModelName, mDeckLink->outputModelName,
mDeckLinkSupportsInternalKeying, mDeckLink->supportsInternalKeying,
mDeckLinkSupportsExternalKeying, mDeckLink->supportsExternalKeying,
mDeckLinkKeyerInterfaceAvailable, mDeckLink->keyerInterfaceAvailable,
mRuntimeHost->ExternalKeyingEnabled(), mRuntimeHost->ExternalKeyingEnabled(),
mDeckLinkExternalKeyingActive, mDeckLink->externalKeyingActive,
"External keying has been disabled."); "External keying has been disabled.");
} }
}
if (mDLInput)
{
mDLInput->StopStreams();
mDLInput->DisableVideoInput();
}
if (mDLOutput)
{
mDLOutput->StopScheduledPlayback(0, NULL, 0);
mDLOutput->DisableVideoOutput();
}
return true; return true;
} }
@@ -898,7 +739,7 @@ bool OpenGLComposite::ReloadShader()
EnterCriticalSection(&pMutex); EnterCriticalSection(&pMutex);
wglMakeCurrent(hGLDC, hGLRC); wglMakeCurrent(hGLDC, hGLRC);
bool success = mShaderPrograms->CompileLayerPrograms(mInputFrameWidth, mInputFrameHeight, sizeof(compilerErrorMessage), compilerErrorMessage); bool success = mShaderPrograms->CompileLayerPrograms(mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, sizeof(compilerErrorMessage), compilerErrorMessage);
if (mRuntimeHost) if (mRuntimeHost)
mRuntimeHost->ClearReloadRequest(); mRuntimeHost->ClearReloadRequest();
@@ -925,14 +766,14 @@ void OpenGLComposite::renderEffect()
{ {
PollRuntimeChanges(); PollRuntimeChanges();
const bool hasInputSource = !mHasNoInputSource; const bool hasInputSource = !mDeckLink->hasNoInputSource;
const std::vector<RuntimeRenderState> layerStates = mRuntimeHost ? mRuntimeHost->GetLayerRenderStates(mInputFrameWidth, mInputFrameHeight) : std::vector<RuntimeRenderState>(); const std::vector<RuntimeRenderState> layerStates = mRuntimeHost ? mRuntimeHost->GetLayerRenderStates(mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight) : std::vector<RuntimeRenderState>();
const unsigned historyCap = mRuntimeHost ? mRuntimeHost->GetMaxTemporalHistoryFrames() : 0; const unsigned historyCap = mRuntimeHost ? mRuntimeHost->GetMaxTemporalHistoryFrames() : 0;
mRenderPass->Render( mRenderPass->Render(
hasInputSource, hasInputSource,
layerStates, layerStates,
mInputFrameWidth, mDeckLink->inputFrameWidth,
mInputFrameHeight, mDeckLink->inputFrameHeight,
historyCap, historyCap,
[this](const RuntimeRenderState& state, LayerProgram::TextBinding& textBinding, std::string& error) { [this](const RuntimeRenderState& state, LayerProgram::TextBinding& textBinding, std::string& error) {
return mShaderPrograms->UpdateTextBindingTexture(state, textBinding, error); return mShaderPrograms->UpdateTextBindingTexture(state, textBinding, error);
@@ -964,7 +805,7 @@ bool OpenGLComposite::PollRuntimeChanges()
return true; return true;
char compilerErrorMessage[1024] = {}; char compilerErrorMessage[1024] = {};
if (!mShaderPrograms->CompileLayerPrograms(mInputFrameWidth, mInputFrameHeight, sizeof(compilerErrorMessage), compilerErrorMessage)) if (!mShaderPrograms->CompileLayerPrograms(mDeckLink->inputFrameWidth, mDeckLink->inputFrameHeight, sizeof(compilerErrorMessage), compilerErrorMessage))
{ {
mRuntimeHost->SetCompileStatus(false, compilerErrorMessage); mRuntimeHost->SetCompileStatus(false, compilerErrorMessage);
mRuntimeHost->ClearReloadRequest(); mRuntimeHost->ClearReloadRequest();
@@ -1000,3 +841,4 @@ bool OpenGLComposite::CheckOpenGLExtensions()
//////////////////////////////////////////// ////////////////////////////////////////////

View File

@@ -67,6 +67,7 @@ class PlayoutDelegate;
class CaptureDelegate; class CaptureDelegate;
class PinnedMemoryAllocator; class PinnedMemoryAllocator;
class ControlServer; class ControlServer;
class DeckLinkSession;
class OscServer; class OscServer;
class OpenGLRenderPass; class OpenGLRenderPass;
class OpenGLShaderPrograms; class OpenGLShaderPrograms;
@@ -106,36 +107,12 @@ private:
bool CheckOpenGLExtensions(); bool CheckOpenGLExtensions();
using LayerProgram = OpenGLRenderer::LayerProgram; using LayerProgram = OpenGLRenderer::LayerProgram;
CaptureDelegate* mCaptureDelegate;
PlayoutDelegate* mPlayoutDelegate;
HWND hGLWnd; HWND hGLWnd;
HDC hGLDC; HDC hGLDC;
HGLRC hGLRC; HGLRC hGLRC;
CRITICAL_SECTION pMutex; CRITICAL_SECTION pMutex;
// DeckLink std::unique_ptr<DeckLinkSession> mDeckLink;
IDeckLinkInput* mDLInput;
IDeckLinkOutput* mDLOutput;
IDeckLinkKeyer* mDLKeyer;
std::deque<IDeckLinkMutableVideoFrame*> mDLOutputVideoFrameQueue;
PinnedMemoryAllocator* mPlayoutAllocator;
BMDTimeValue mFrameDuration;
BMDTimeScale mFrameTimescale;
unsigned mTotalPlayoutFrames;
unsigned mInputFrameWidth;
unsigned mInputFrameHeight;
unsigned mOutputFrameWidth;
unsigned mOutputFrameHeight;
std::string mInputDisplayModeName;
std::string mOutputDisplayModeName;
bool mHasNoInputSource;
std::string mDeckLinkOutputModelName;
bool mDeckLinkSupportsInternalKeying;
bool mDeckLinkSupportsExternalKeying;
bool mDeckLinkKeyerInterfaceAvailable;
bool mDeckLinkExternalKeyingActive;
std::string mDeckLinkStatusMessage;
std::unique_ptr<OpenGLRenderer> mRenderer; std::unique_ptr<OpenGLRenderer> mRenderer;
std::unique_ptr<RuntimeHost> mRuntimeHost; std::unique_ptr<RuntimeHost> mRuntimeHost;
std::unique_ptr<OpenGLRenderPass> mRenderPass; std::unique_ptr<OpenGLRenderPass> mRenderPass;