Simplify ownership/lifetime
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:57:59 +10:00
parent 1b67777c4a
commit bbbc678c83
4 changed files with 109 additions and 52 deletions

View File

@@ -32,10 +32,10 @@ OpenGLDeckLinkBridge::OpenGLDeckLinkBridge(
void OpenGLDeckLinkBridge::VideoFrameArrived(IDeckLinkVideoInputFrame* inputFrame, bool hasNoInputSource)
{
mDeckLink.hasNoInputSource = hasNoInputSource;
mRuntimeHost.SetSignalStatus(!hasNoInputSource, mDeckLink.inputFrameWidth, mDeckLink.inputFrameHeight, mDeckLink.inputDisplayModeName);
mDeckLink.SetInputSourceMissing(hasNoInputSource);
mRuntimeHost.SetSignalStatus(!hasNoInputSource, mDeckLink.InputFrameWidth(), mDeckLink.InputFrameHeight(), mDeckLink.InputDisplayModeName());
if (mDeckLink.hasNoInputSource)
if (!mDeckLink.HasInputSource())
return; // don't transfer texture when there's no input
long textureSize = inputFrame->GetRowBytes() * inputFrame->GetHeight();
@@ -72,7 +72,7 @@ void OpenGLDeckLinkBridge::VideoFrameArrived(IDeckLinkVideoInputFrame* inputFram
glBindTexture(GL_TEXTURE_2D, mRenderer.CaptureTexture());
// NULL for last arg indicates use current GL_PIXEL_UNPACK_BUFFER target as texture data
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mDeckLink.inputFrameWidth / 2, mDeckLink.inputFrameHeight, 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);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
@@ -93,9 +93,7 @@ void OpenGLDeckLinkBridge::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedF
EnterCriticalSection(&mMutex);
// Get the first frame from the queue
IDeckLinkMutableVideoFrame* outputVideoFrame = mDeckLink.outputVideoFrameQueue.front();
mDeckLink.outputVideoFrameQueue.push_back(outputVideoFrame);
mDeckLink.outputVideoFrameQueue.pop_front();
IDeckLinkMutableVideoFrame* outputVideoFrame = mDeckLink.RotateOutputFrame();
// make GL context current in this thread
wglMakeCurrent(mHdc, mHglrc);
@@ -108,15 +106,13 @@ void OpenGLDeckLinkBridge::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedF
mRenderEffect();
glBindFramebuffer(GL_READ_FRAMEBUFFER, mRenderer.CompositeFramebuffer());
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, mRenderer.OutputFramebuffer());
glBlitFramebuffer(0, 0, mDeckLink.inputFrameWidth, mDeckLink.inputFrameHeight, 0, 0, mDeckLink.outputFrameWidth, mDeckLink.outputFrameHeight, 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.OutputFramebuffer());
glFlush();
if (mRenderer.FastTransferAvailable())
VideoFrameTransfer::endTextureInUse(VideoFrameTransfer::GPUtoCPU);
const auto renderEndTime = std::chrono::steady_clock::now();
const double frameBudgetMilliseconds = mDeckLink.frameTimescale != 0
? (static_cast<double>(mDeckLink.frameDuration) * 1000.0) / static_cast<double>(mDeckLink.frameTimescale)
: 0.0;
const double frameBudgetMilliseconds = mDeckLink.FrameBudgetMilliseconds();
const double renderMilliseconds = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(renderEndTime - renderStartTime).count();
mRuntimeHost.SetPerformanceStats(frameBudgetMilliseconds, renderMilliseconds);
mRuntimeHost.AdvanceFrame();
@@ -141,35 +137,31 @@ void OpenGLDeckLinkBridge::PlayoutFrameCompleted(IDeckLinkVideoFrame* completedF
if (mRenderer.FastTransferAvailable())
{
// Finished sampling the capture texture for this frame.
if (!mDeckLink.hasNoInputSource)
if (mDeckLink.HasInputSource())
VideoFrameTransfer::endTextureInUse(VideoFrameTransfer::CPUtoGPU);
if (!mDeckLink.playoutAllocator->transferFrame(pFrame, mRenderer.OutputTexture()))
if (!mDeckLink.TransferPlayoutFrame(pFrame, mRenderer.OutputTexture()))
OutputDebugStringA("Playback: transferFrame() failed\n");
mPaint();
// Wait for transfer to system memory to complete
mDeckLink.playoutAllocator->waitForTransferComplete(pFrame);
mDeckLink.WaitForPlayoutTransferComplete(pFrame);
}
else
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, mRenderer.OutputFramebuffer());
glReadPixels(0, 0, mDeckLink.outputFrameWidth, mDeckLink.outputFrameHeight, 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);
mPaint();
}
outputVideoFrameBuffer->EndAccess(bmdBufferAccessWrite);
outputVideoFrameBuffer->Release();
// If the last completed frame was late or dropped, bump the scheduled time further into the future
if (completionResult == bmdOutputFrameDisplayedLate || completionResult == bmdOutputFrameDropped)
mDeckLink.totalPlayoutFrames += 2;
mDeckLink.AccountForCompletionResult(completionResult);
// Schedule the next frame for playout
HRESULT hr = mDeckLink.output->ScheduleVideoFrame(outputVideoFrame, (mDeckLink.totalPlayoutFrames * mDeckLink.frameDuration), mDeckLink.frameDuration, mDeckLink.frameTimescale);
if (SUCCEEDED(hr))
mDeckLink.totalPlayoutFrames++;
mDeckLink.ScheduleOutputFrame(outputVideoFrame);
wglMakeCurrent(NULL, NULL);