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 decode running before start time #4751

Merged
merged 7 commits into from
Sep 6, 2021

Conversation

peppy
Copy link
Member

@peppy peppy commented Sep 2, 2021

Noticed that we were continuously decoding frames before a video started due to no checks in place.

Note that I did some code quality improvements around the outOfSync logic but the only part which matters is the early return.

var nextFrame = availableFrames.Count > 0 ? availableFrames.Peek() : null;
// if not looping and not yet having reached the start of the video, don't attempt to consume frames yet.
// if we begin consuming frames the decoder will be performing unnecessary work.
if (!Loop && PlaybackPosition < 0)
Copy link
Collaborator

@bdach bdach Sep 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the loop exception here is to make sure that even with negative time the video can loop. Which would be fine, aside from the fact that as far as I can see, looping in negative time is completely busted right now.

With this branch as-is, when I run the TestDecodingContinuesBeforeStartTimeIfLooping I get a bunch of Video too far out of sync log messages. Which is because of this code in AnimationClockComposite:

if (Loop)
return manualClock.CurrentTime % Duration;

The % is, unfortunately, not the nice math modulo (which guarantees that the result is in the interval [0, $right_operand]). It can be a signed value. In particular, e.g. -1000 % 600 = -400. Which cannot be seeked to as there are physically no frames with that time.

But even with that fixed the animation doesn't play properly for reasons that I'm not entirely sure of yet (still spews Video too far out of sync, albeit at a lesser rate). But, the bigger point is, if PlaybackPosition was properly fixed to never return anything outside of the [0, $duration] range, this guard wouldn't be needed anymore, I don't think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, that didn't happen when i tested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually based on how things are written, I don't think looping before zero time is even correct. I'll update the logic to align with this expectation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated PlaybackPosition to be clamped as proposed. Seems to work well, and avoid the negative effect of the early return (potentially not buffering the initial frames of the video as early as possible).

bdach
bdach previously approved these changes Sep 4, 2021
Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can get behind not looping before time 0, but I'll wait for opinions from others as to whether that's a behaviour that makes sense.

@smoogipoo smoogipoo merged commit 87a5e20 into ppy:master Sep 6, 2021
@peppy peppy deleted the fix-decode-running-before-start-time branch September 7, 2021 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants