Stage 1 rewrite
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <atlbase.h>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
@@ -526,8 +527,20 @@ bool DeckLinkSession::PopulateOutputFrame(IDeckLinkMutableVideoFrame* outputVide
|
||||
bool DeckLinkSession::ScheduleFrame(IDeckLinkMutableVideoFrame* outputVideoFrame)
|
||||
{
|
||||
const VideoIOScheduleTime scheduleTime = mScheduler.NextScheduleTime();
|
||||
return outputVideoFrame != nullptr &&
|
||||
output->ScheduleVideoFrame(outputVideoFrame, scheduleTime.streamTime, scheduleTime.duration, scheduleTime.timeScale) == S_OK;
|
||||
if (outputVideoFrame == nullptr || output == nullptr)
|
||||
{
|
||||
++mState.deckLinkScheduleFailureCount;
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto scheduleStart = std::chrono::steady_clock::now();
|
||||
const HRESULT result = output->ScheduleVideoFrame(outputVideoFrame, scheduleTime.streamTime, scheduleTime.duration, scheduleTime.timeScale);
|
||||
const auto scheduleEnd = std::chrono::steady_clock::now();
|
||||
mState.deckLinkScheduleCallMilliseconds = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(scheduleEnd - scheduleStart).count();
|
||||
if (result != S_OK)
|
||||
++mState.deckLinkScheduleFailureCount;
|
||||
RefreshBufferedVideoFrameCount();
|
||||
return result == S_OK;
|
||||
}
|
||||
|
||||
bool DeckLinkSession::ScheduleSystemMemoryFrame(const VideoIOOutputFrame& frame)
|
||||
@@ -592,6 +605,26 @@ bool DeckLinkSession::ScheduleBlackFrame(IDeckLinkMutableVideoFrame* outputVideo
|
||||
return ScheduleFrame(outputVideoFrame);
|
||||
}
|
||||
|
||||
void DeckLinkSession::RefreshBufferedVideoFrameCount()
|
||||
{
|
||||
if (output == nullptr)
|
||||
{
|
||||
mState.actualDeckLinkBufferedFramesAvailable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int bufferedFrameCount = 0;
|
||||
if (output->GetBufferedVideoFrameCount(&bufferedFrameCount) == S_OK)
|
||||
{
|
||||
mState.actualDeckLinkBufferedFrames = bufferedFrameCount;
|
||||
mState.actualDeckLinkBufferedFramesAvailable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mState.actualDeckLinkBufferedFramesAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool DeckLinkSession::BeginOutputFrame(VideoIOOutputFrame& frame)
|
||||
{
|
||||
CComPtr<IDeckLinkMutableVideoFrame> outputVideoFrame;
|
||||
@@ -736,6 +769,8 @@ void DeckLinkSession::HandleVideoInputFrame(IDeckLinkVideoInputFrame* inputFrame
|
||||
|
||||
void DeckLinkSession::HandlePlayoutFrameCompleted(IDeckLinkVideoFrame* completedFrame, BMDOutputFrameCompletionResult completionResult)
|
||||
{
|
||||
RefreshBufferedVideoFrameCount();
|
||||
|
||||
void* completedSystemBuffer = nullptr;
|
||||
if (completedFrame != nullptr)
|
||||
{
|
||||
|
||||
@@ -74,6 +74,7 @@ private:
|
||||
bool ScheduleFrame(IDeckLinkMutableVideoFrame* outputVideoFrame);
|
||||
bool ScheduleSystemMemoryFrame(const VideoIOOutputFrame& frame);
|
||||
bool ScheduleBlackFrame(IDeckLinkMutableVideoFrame* outputVideoFrame);
|
||||
void RefreshBufferedVideoFrameCount();
|
||||
static VideoIOCompletionResult TranslateCompletionResult(BMDOutputFrameCompletionResult completionResult);
|
||||
|
||||
CComPtr<CaptureDelegate> captureDelegate;
|
||||
|
||||
Reference in New Issue
Block a user