+22
-13
osu.Framework/Graphics/Video/Video.cs
+22
-13
osu.Framework/Graphics/Video/Video.cs
···
127
127
}
128
128
}
129
129
130
-
var nextFrame = availableFrames.Count > 0 ? availableFrames.Peek() : null;
130
+
// if not looping and not yet having reached the start of the video, don't attempt to consume frames yet.
131
+
// if we begin consuming frames the decoder will be performing unnecessary work.
132
+
if (!Loop && PlaybackPosition < 0)
133
+
return;
134
+
135
+
var peekFrame = availableFrames.Count > 0 ? availableFrames.Peek() : null;
136
+
bool outOfSync = false;
131
137
132
-
if (nextFrame != null)
138
+
if (peekFrame != null)
133
139
{
134
-
bool tooFarBehind = Math.Abs(PlaybackPosition - nextFrame.Time) > lenience_before_seek &&
135
-
(!Loop ||
136
-
(Math.Abs(PlaybackPosition - decoder.Duration - nextFrame.Time) > lenience_before_seek &&
137
-
Math.Abs(PlaybackPosition + decoder.Duration - nextFrame.Time) > lenience_before_seek)
138
-
);
140
+
outOfSync = Math.Abs(PlaybackPosition - peekFrame.Time) > lenience_before_seek;
139
141
140
-
// we are too far ahead or too far behind
141
-
if (tooFarBehind && decoder.CanSeek)
142
+
if (Loop)
142
143
{
143
-
Logger.Log($"Video too far out of sync ({nextFrame.Time}), seeking to {PlaybackPosition}");
144
-
decoder.Seek(PlaybackPosition);
145
-
decoder.ReturnFrames(availableFrames);
146
-
availableFrames.Clear();
144
+
// handle looping bounds (as we could be in the roll-over process between loops).
145
+
outOfSync &= Math.Abs(PlaybackPosition - decoder.Duration - peekFrame.Time) > lenience_before_seek &&
146
+
Math.Abs(PlaybackPosition + decoder.Duration - peekFrame.Time) > lenience_before_seek;
147
147
}
148
+
}
149
+
150
+
// we are too far ahead or too far behind
151
+
if (outOfSync && decoder.CanSeek)
152
+
{
153
+
Logger.Log($"Video too far out of sync ({peekFrame.Time}), seeking to {PlaybackPosition}");
154
+
decoder.Seek(PlaybackPosition);
155
+
decoder.ReturnFrames(availableFrames);
156
+
availableFrames.Clear();
148
157
}
149
158
150
159
var frameTime = CurrentFrameTime;