Step 3
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#include "RenderOutputQueue.h"
|
||||
|
||||
RenderOutputQueue::RenderOutputQueue(const VideoPlayoutPolicy& policy) :
|
||||
mPolicy(NormalizeVideoPlayoutPolicy(policy))
|
||||
{
|
||||
}
|
||||
|
||||
void RenderOutputQueue::Configure(const VideoPlayoutPolicy& policy)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
mPolicy = NormalizeVideoPlayoutPolicy(policy);
|
||||
while (mReadyFrames.size() > CapacityLocked())
|
||||
{
|
||||
mReadyFrames.pop_front();
|
||||
++mDroppedCount;
|
||||
}
|
||||
}
|
||||
|
||||
bool RenderOutputQueue::Push(RenderOutputFrame frame)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mReadyFrames.size() >= CapacityLocked())
|
||||
{
|
||||
mReadyFrames.pop_front();
|
||||
++mDroppedCount;
|
||||
}
|
||||
|
||||
mReadyFrames.push_back(frame);
|
||||
++mPushedCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderOutputQueue::TryPop(RenderOutputFrame& frame)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mReadyFrames.empty())
|
||||
{
|
||||
++mUnderrunCount;
|
||||
return false;
|
||||
}
|
||||
|
||||
frame = mReadyFrames.front();
|
||||
mReadyFrames.pop_front();
|
||||
++mPoppedCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderOutputQueue::Clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
mReadyFrames.clear();
|
||||
}
|
||||
|
||||
RenderOutputQueueMetrics RenderOutputQueue::GetMetrics() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
RenderOutputQueueMetrics metrics;
|
||||
metrics.depth = mReadyFrames.size();
|
||||
metrics.capacity = CapacityLocked();
|
||||
metrics.pushedCount = mPushedCount;
|
||||
metrics.poppedCount = mPoppedCount;
|
||||
metrics.droppedCount = mDroppedCount;
|
||||
metrics.underrunCount = mUnderrunCount;
|
||||
return metrics;
|
||||
}
|
||||
|
||||
std::size_t RenderOutputQueue::CapacityLocked() const
|
||||
{
|
||||
return static_cast<std::size_t>(mPolicy.maxReadyFrames);
|
||||
}
|
||||
Reference in New Issue
Block a user