#pragma once

#include <cstdint>

enum class VideoUnderrunBehavior
{
	ReuseLastCompletedFrame,
	BlackFrame
};

struct VideoPlayoutPolicy
{
	unsigned outputFramePoolSize = 10;
	unsigned targetPrerollFrames = 4;
	unsigned targetReadyFrames = 2;
	unsigned maxReadyFrames = 4;
	unsigned minimumSpareDeviceFrames = 1;
	uint64_t lateOrDropCatchUpFrames = 0;
	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;
	const unsigned minimumOutputFramePoolSize = policy.targetPrerollFrames + policy.maxReadyFrames + policy.minimumSpareDeviceFrames;
	if (policy.outputFramePoolSize < minimumOutputFramePoolSize)
		policy.outputFramePoolSize = minimumOutputFramePoolSize;
	return policy;
}
