Repository navigation
fix(player): join the sound once the window shows again - #35
Merged
Merged
Conversation
On macOS the window reports itself shown a frame or more after the app is back, and VideoPlayer only counts time and starts decoding from then. The picture handed over from the background stood on its first frame through that, for its whole length again, then skipped the frames it was late on and trailed the sound by the time the window took to show (about 50ms). Coming back took about 110ms before the picture moved, against about 60ms for a window showing again with no handover at all. The handed-over frame now lasts 1ms, so VideoPlayer asks for the next one as soon as the window shows, and frameDecoder then gives the frame the sound is in, for what is left of it. On the real app the picture now moves about 56ms after the window appears, the same as with no handover, and frames follow the sound clock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #32, which was merged before this commit was pushed to its branch.
Coming back to the app after its window was hidden still made the picture stop for a moment. On macOS a window coming back reports itself shown a frame or more after the app is active, and VideoPlayer only counts time and starts decoding from then. The picture #32 hands over at activation stood on its first frame through that and then for its whole length again. It then skipped the frames it was late on, and trailed the sound by about 50ms from then on.
frameDecoderthen gives the frame the sound is in at that moment, for what is left of it (frameDecoder.sound, set bytakeBackgroundPicture), so from the first moving frame the picture follows the sound clock.Screenshots
The real app ran with a fake HOME and a test clip that has a seconds counter. The app was hidden for about 4s and then brought back. The pair shows the first frame after the window appears and the frame 100ms later, at full size. The handover happened at 35.67s, so the first frame is already at 35, and the gradient strip has moved on 100ms later.
Before this change, timing logs from the same scenario show the playhead standing still and then skipping three frames at once: 9.001s → 9.001s → 9.101s → 9.134s. Still images can't show that, so there is no before image.
Verification
Hidden for about 4s, then brought back. Each run was recorded with
screencapture, and per-frame change in the moving gradient strip gives the time from the window appearing to the picture moving:With this PR, 5 of 6 runs had no gap over 60ms in the 2s after the return. One run had gaps of 66–78ms, which steady playback with no switching shows too: two to five per 2s, from the screen recording's timing. Timing logs from a local build show the decoder joining the sound 15–30ms after the handover, as the window shows, on the frame the sound is in, and every frame after it following the sound.
Tests:
TestHandedOverPictureJoinsTheSound: with real ffmpeg on a 10fps clip, the held frame lasts 1ms. With the sound at 450ms, the next frame given is the one from 400 to 500ms, lasting 50ms, and the frames after it last their full length.make test,go vet, and the player and volume tests with-race.