private void InternalFillFramesCache(TimeSpan timeout)
{
var startTime = DateTime.UtcNow;
while (LeadingFramesCache.IsFull == false && IsAtEndOfStream == false)
{
if (DateTime.UtcNow.Subtract(startTime).Ticks > timeout.Ticks)
{
ErrorOccurredCallback(this, new MediaPlaybackException(MediaPlaybackErrorSources.InternalFillFamesCache, MediaPlaybackErrorCode.FillFramesFailed,
string.Format("Fill Frames Cache = Failed to fill cache in {0}; Leading Frames: {1}; Lagging Frames: {2}",
timeout, LeadingFramesCache.Count, LaggingFramesCache.Count)));
return;
}
var frame = this.PullMediaFrame();
if (frame != null)
{
// reset the start time because we are in fact getting frames.
startTime = DateTime.UtcNow;
if (frame.Type == LeadingFramesCache.Type)
{
LeadingFramesCache.Add(frame);
}
else if (frame.Type == LaggingFramesCache.Type)
{
if (LaggingFramesCache.IsFull)
{
LaggingFramesCache.RemoveFirst();
}
LaggingFramesCache.Add(frame);
}
}
}
}