-
Notifications
You must be signed in to change notification settings - Fork 424
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
Fix video decode running before start time #4751
Conversation
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) |
There was a problem hiding this comment.
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
:
osu-framework/osu.Framework/Graphics/Animations/AnimationClockComposite.cs
Lines 86 to 87 in f2319e8
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this 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.
…running-before-start-time
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.