Phase 7 step 2
This commit is contained in:
@@ -7,4 +7,3 @@ constexpr GLuint kDecodedVideoTextureUnit = 1;
|
||||
constexpr GLuint kSourceHistoryTextureUnitBase = 2;
|
||||
constexpr GLuint kPackedVideoTextureUnit = 2;
|
||||
constexpr GLuint kGlobalParamsBindingPoint = 0;
|
||||
constexpr unsigned kPrerollFrameCount = 12;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
enum class VideoUnderrunBehavior
|
||||
{
|
||||
ReuseLastCompletedFrame,
|
||||
BlackFrame
|
||||
};
|
||||
|
||||
struct VideoPlayoutPolicy
|
||||
{
|
||||
unsigned outputFramePoolSize = 10;
|
||||
unsigned targetPrerollFrames = 12;
|
||||
unsigned targetReadyFrames = 2;
|
||||
unsigned maxReadyFrames = 4;
|
||||
unsigned minimumSpareDeviceFrames = 1;
|
||||
uint64_t lateOrDropCatchUpFrames = 2;
|
||||
VideoUnderrunBehavior underrunBehavior = VideoUnderrunBehavior::ReuseLastCompletedFrame;
|
||||
bool adaptiveHeadroomEnabled = false;
|
||||
};
|
||||
|
||||
inline VideoPlayoutPolicy NormalizeVideoPlayoutPolicy(VideoPlayoutPolicy policy)
|
||||
{
|
||||
if (policy.outputFramePoolSize == 0)
|
||||
policy.outputFramePoolSize = 1;
|
||||
if (policy.targetPrerollFrames == 0)
|
||||
policy.targetPrerollFrames = 1;
|
||||
if (policy.targetReadyFrames == 0)
|
||||
policy.targetReadyFrames = 1;
|
||||
if (policy.maxReadyFrames < policy.targetReadyFrames)
|
||||
policy.maxReadyFrames = policy.targetReadyFrames;
|
||||
return policy;
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
#include "VideoPlayoutScheduler.h"
|
||||
|
||||
void VideoPlayoutScheduler::Configure(int64_t frameDuration, int64_t timeScale)
|
||||
{
|
||||
Configure(frameDuration, timeScale, VideoPlayoutPolicy());
|
||||
}
|
||||
|
||||
void VideoPlayoutScheduler::Configure(int64_t frameDuration, int64_t timeScale, const VideoPlayoutPolicy& policy)
|
||||
{
|
||||
mFrameDuration = frameDuration;
|
||||
mTimeScale = timeScale;
|
||||
mPolicy = NormalizeVideoPlayoutPolicy(policy);
|
||||
Reset();
|
||||
}
|
||||
|
||||
@@ -26,7 +32,7 @@ VideoIOScheduleTime VideoPlayoutScheduler::NextScheduleTime()
|
||||
void VideoPlayoutScheduler::AccountForCompletionResult(VideoIOCompletionResult result)
|
||||
{
|
||||
if (result == VideoIOCompletionResult::DisplayedLate || result == VideoIOCompletionResult::Dropped)
|
||||
mScheduledFrameIndex += 2;
|
||||
mScheduledFrameIndex += mPolicy.lateOrDropCatchUpFrames;
|
||||
}
|
||||
|
||||
double VideoPlayoutScheduler::FrameBudgetMilliseconds() const
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "VideoIOTypes.h"
|
||||
#include "VideoPlayoutPolicy.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
@@ -8,15 +9,18 @@ class VideoPlayoutScheduler
|
||||
{
|
||||
public:
|
||||
void Configure(int64_t frameDuration, int64_t timeScale);
|
||||
void Configure(int64_t frameDuration, int64_t timeScale, const VideoPlayoutPolicy& policy);
|
||||
void Reset();
|
||||
VideoIOScheduleTime NextScheduleTime();
|
||||
void AccountForCompletionResult(VideoIOCompletionResult result);
|
||||
double FrameBudgetMilliseconds() const;
|
||||
uint64_t ScheduledFrameIndex() const { return mScheduledFrameIndex; }
|
||||
int64_t TimeScale() const { return mTimeScale; }
|
||||
const VideoPlayoutPolicy& Policy() const { return mPolicy; }
|
||||
|
||||
private:
|
||||
int64_t mFrameDuration = 0;
|
||||
int64_t mTimeScale = 0;
|
||||
uint64_t mScheduledFrameIndex = 0;
|
||||
VideoPlayoutPolicy mPolicy;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "DeckLinkSession.h"
|
||||
|
||||
#include "GlRenderConstants.h"
|
||||
|
||||
#include <atlbase.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@@ -210,7 +208,7 @@ bool DeckLinkSession::DiscoverDevicesAndModes(const VideoFormatSelection& videoM
|
||||
BMDTimeValue frameDuration = 0;
|
||||
BMDTimeScale frameTimescale = 0;
|
||||
outputMode->GetFrameRate(&frameDuration, &frameTimescale);
|
||||
mScheduler.Configure(frameDuration, frameTimescale);
|
||||
mScheduler.Configure(frameDuration, frameTimescale, mPlayoutPolicy);
|
||||
mState.frameBudgetMilliseconds = mScheduler.FrameBudgetMilliseconds();
|
||||
|
||||
mState.inputFrameRowBytes = mState.inputFrameSize.width * 2u;
|
||||
@@ -379,7 +377,9 @@ bool DeckLinkSession::ConfigureOutput(OutputFrameCallback callback, const VideoF
|
||||
mState.statusMessage = "Selected DeckLink output supports external keying. Set enableExternalKeying to true in runtime-host.json to request it.";
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
const VideoPlayoutPolicy policy = NormalizeVideoPlayoutPolicy(mPlayoutPolicy);
|
||||
mPlayoutPolicy = policy;
|
||||
for (unsigned i = 0; i < policy.outputFramePoolSize; i++)
|
||||
{
|
||||
CComPtr<IDeckLinkMutableVideoFrame> outputFrame;
|
||||
|
||||
@@ -523,7 +523,9 @@ bool DeckLinkSession::Start()
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < kPrerollFrameCount; i++)
|
||||
const VideoPlayoutPolicy policy = NormalizeVideoPlayoutPolicy(mPlayoutPolicy);
|
||||
mPlayoutPolicy = policy;
|
||||
for (unsigned i = 0; i < policy.targetPrerollFrames; i++)
|
||||
{
|
||||
CComPtr<IDeckLinkMutableVideoFrame> outputVideoFrame;
|
||||
if (!AcquireNextOutputVideoFrame(outputVideoFrame))
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "DeckLinkVideoIOFormat.h"
|
||||
#include "VideoIOFormat.h"
|
||||
#include "VideoIOTypes.h"
|
||||
#include "VideoPlayoutPolicy.h"
|
||||
#include "VideoPlayoutScheduler.h"
|
||||
|
||||
#include <atlbase.h>
|
||||
@@ -79,6 +80,7 @@ private:
|
||||
CComPtr<IDeckLinkKeyer> keyer;
|
||||
std::deque<CComPtr<IDeckLinkMutableVideoFrame>> outputVideoFrameQueue;
|
||||
VideoIOState mState;
|
||||
VideoPlayoutPolicy mPlayoutPolicy;
|
||||
VideoPlayoutScheduler mScheduler;
|
||||
InputFrameCallback mInputFrameCallback;
|
||||
OutputFrameCallback mOutputFrameCallback;
|
||||
|
||||
Reference in New Issue
Block a user