Repository navigation
fix(gl): prevent periodic PTS jumps from 33ms MAX_DRIFT clamp in GlTi… - #2235
Open
Mike-the-one wants to merge 1 commit into
Open
Mike-the-one wants to merge 1 commit into
Mike-the-one wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Problem
In
GlTimestamp,setFps(fps)shrinksdriftdown to1_000_000_000L / fps(33.3msat 30fps). BecausesourceTimestamp(SurfaceTexture.getTimestamp()) is driven by the camera sensor clock whileclockTimestampcomes fromSystem.nanoTime(), two issues occur:HandlerThreadscheduling jitter causescurrentTimestampto hitclockTimestamp ± 33.3msevery ~9.5 seconds, clamping back to wall-clock time and producing 40–70ms PTS jumps (plus occasional ~5ms catch-up steps).sourceTimestamp <= lastSourceTimestamp),GlTimestampadvances byclockDeltawithout deducting that credit from the next realsourceTimestampdelta, causing a jump when real frames resume.Fix
MAX_DRIFT = 500_000_000L(500ms) instead of shrinking it to 1 frame insetFps(fps)so Camera2 preserves smooth sensor deltas while still staying bounded against wall clock.forcedAdvanceNswheneversourceTimestamp <= lastSourceTimestampand deduct it from the next realsourceDelta.Verification
Tested on Samsung Galaxy S25+ (1080p @ 30fps MP4 recording checked with
ffprobe):2.8.2): 22 PTS jumps (40–71ms/5.17ms) over ~178s (~every 9.5s).>40msor<10ms) over a full live recording.Before the fix