Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix video stopping playback permanent when reaching end of stream #4750

Merged
merged 4 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions osu.Framework.Tests/Visual/Sprites/TestSceneVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ public void TestJumpBack()
AddUntilStep("Video seeked", () => video.PlaybackPosition < 30000);
}

[Test]
public void TestJumpBackAfterEndOfPlayback()
{
AddStep("Jump ahead by 60 seconds", () => clock.CurrentTime += 60000);

AddUntilStep("Video seeked", () => video.PlaybackPosition >= 30000);
AddUntilStep("Reached end", () => video.State == VideoDecoder.DecoderState.EndOfStream);
AddStep("reset decode state", () => didDecode = false);

AddStep("Jump back to valid time", () => clock.CurrentTime = 20000);
AddUntilStep("decoding ran", () => didDecode);
}

[Test]
public void TestVideoDoesNotLoopIfDisabled()
{
Expand Down
18 changes: 15 additions & 3 deletions osu.Framework/Graphics/Video/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ protected override void Update()
{
base.Update();

if (decoder.State == VideoDecoder.DecoderState.EndOfStream)
{
// if at the end of the stream but our playback enters a valid time region again, a seek operation is required to get the decoder back on track.
if (PlaybackPosition < decoder.Duration)
seekIntoSync();
}

var nextFrame = availableFrames.Count > 0 ? availableFrames.Peek() : null;

if (nextFrame != null)
Expand All @@ -131,9 +138,7 @@ protected override void Update()
if (tooFarBehind && decoder.CanSeek)
{
Logger.Log($"Video too far out of sync ({nextFrame.Time}), seeking to {PlaybackPosition}");
decoder.Seek(PlaybackPosition);
decoder.ReturnFrames(availableFrames);
availableFrames.Clear();
seekIntoSync();
}
}

Expand Down Expand Up @@ -164,6 +169,13 @@ protected override void Update()

if (frameTime != CurrentFrameTime)
FramesProcessed++;

void seekIntoSync()
{
decoder.Seek(PlaybackPosition);
decoder.ReturnFrames(availableFrames);
availableFrames.Clear();
}
}

private bool checkNextFrameValid(DecodedFrame frame)
Expand Down