fix(macos): correct video aspect ratio and rewrite frame pipeline to fix tearing, stalls and frozen playback#231
Open
Buffersolve wants to merge 3 commits into
Open
Conversation
Derive the display aspect ratio from AVPlayerItem.presentationSize (pixel aspect ratio and clean aperture applied) and re-sync it per published frame. The dimensions known at open time can be wrong or stale — HLS reports a default/early-variant size and anamorphic content has non-square pixels — so stretching the full bitmap into a Canvas sized from those dimensions distorted the image. presentationSize is cached from a KVO observer so it can be read off the main thread.
Replace the timer-driven frame/position loops with a producer/consumer coroutine pipeline backed by a drop-oldest channel, content-hash dedup, and triple-buffered Skia bitmaps to fix tearing and stalls. Drive the timeline from a dedicated AVPlayer clock poll since AVFoundation reuses CVPixelBuffers and frame-derived position freezes on low-motion content. Honor row padding in calculateFrameHash so true pixels are sampled, and correct display aspect ratio for anamorphic content.
…ayer The frame-hash sampling step could land on a single x column (step multiple of width), freezing dedup on static edges; the triple-buffer round-robin could write into the displayed or in-flight bitmap and tear; and several stale-state races caused wrong behavior across media loads: - Bump the hash sampling step when it is a multiple of the frame width - Skip the displayed and last-sent bitmaps when picking a write target, and never close the bitmap Compose is still bound to - Clear pendingSeekTarget when opening new media so an old seek target cannot be applied to the new video - Drain didPlayToEnd after a native seek and ignore it mid-drag to prevent spurious end-of-playback - Keep the frame producer alive after playback ends so resume/seek can relaunch the pipeline - Don't reload media when position observation is cancelled by dispose() - Serialize stop()'s nSeekTo behind videoReaderMutex - Rewrite checkExistsIfLocalFile with java.net.URI to accept all file-URI forms and percent-encoded paths Adds tests for row-padding-aware hashing and the single-column step case.
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
Fixes several long-standing macOS playback bugs and rewrites
MacVideoPlayerStateto use the same producer/consumer frame pipeline as Windows.Fixes
AVPlayerItem.presentationSize(handles HLS and anamorphic content) instead of raw decoded frame size, and updates live on HLS quality switches.file:/pathURIs and percent-encoded paths are now accepted.