Repository navigation
fix(core): Safari audio frozen after its cut is pulled onto the playhead at 0.5 s behind, not 1 s - #7082
Conversation
… the playhead in 0.4 s, not 1 s
There was a problem hiding this comment.
Requesting changes at 9b1b6d08. CI is red, and the failure comes from this change.
Blocker: init.buffering.test.ts fails because of this change.
resumes for a held clip with data buffered ahead that reports only its current frame, as WebKit's do (line 148) fails in both Test (runtime) and Test: runtime contract: expected { isPlaying: true, buffering: true } to deeply equal { isPlaying: true, buffering: false }. Locally, with only media.ts reverted to main (d89bf35), it passes 3/3; at this head it fails 3/3.
That scenario is a WebKit <audio> at readyState 2 with data buffered ahead. The film resumes, but the element hasn't moved yet. The new frozen rule sees a playing, non-seeking element whose currentTime hasn't changed for 0.4 s of film time and counts it as catastrophicDrift. The resulting hard sync re-seeks an element that is waiting for data, not stuck, and the film drops back into buffering. This is the "do not force cold audio forward while it buffers" case. frozenAudioFor needs to leave alone any element that the buffering hold is waiting on or that is still filling, and still catch the post-cut freeze from the device runs.
What checks out:
- Fails without the fix: confirmed. With
media.tsreverted,pulls a WebKit audio element that sits frozen 0.4 s…fails (1 failed / 181 passed). At head,media.test.tsandpreloadMedia.test.tsgive 208 passed. - The moving-element test and the existing 1 s valve are intact.
Non-blocking notes for the next push:
- Hard sync is still gated on
drift > MEDIA_HARD_SYNC_SECONDS(0.5), so a frozen element is actually pulled once it is more than 0.5 s behind, at 0.6 s in the new test, not at 0.4 s. The title and description overstate this. lastMovedisn't cleared when a clip deactivates, unlikelastOffset. On re-entry, an element that hasn't moved since the last pass inherits a staleatand can count as frozen immediately. This is minor because the 0.5 s drift gate still applies, but clearing it alongsidelastOffsetwould keep it consistent.
…t of the frozen rule
There was a problem hiding this comment.
Approved at 1db307e6. My earlier blocker is resolved.
- Blocker fixed:
frozenAudioFornow skips WebKit audio atreadyState < 3, so audio that is still filling data is no longer re-seeked.init.buffering.test.tspasses again. - Eviction:
lastMovedis now cleared inevictMediaSyncState, which runs on proxy swaps and when a clip leaves its window. - Verified locally at this head:
- The whole
src/runtimesuite passes: 117 files, 2756 tests. - With only
media.tsreverted tomain, the frozen-audio test fails (1 failed / 182 passed), so the "fails without the fix" line holds. - With only the
readyStateguard removed, the new "still filling data" test and theinit.bufferingWebKit test both fail, as the description says.
- The whole
- CI: green at this head. One
PR capturesrun was cancelled as a superseded duplicate; its rerun passed. - Description: now says correctly that the hard sync also needs the audio to be more than 0.5 s behind.
Non-blocking risk: the readyState >= 3 gate assumes the frozen-after-cut audio on the phone reports HAVE_FUTURE_DATA. init.buffering.test.ts notes that WebKit audio can report only its current frame (readyState 2) even with data buffered ahead. If the frozen elements on iPhone look like that, this rule won't fire on the device and the 1 s valve still handles them. That is safe, but the gain may be smaller than the 27→18 run suggests. When you re-check on the device (the open box), it's worth logging readyState on a frozen cut.
What
In Safari and on iPhone, a clip's audio that freezes at its in-point right after the cut is now pulled onto the playhead once it is frozen for 0.4 s and more than 0.5 s behind, instead of waiting until it is 1 s behind.
Why
On an iPhone, a pre-seeked audio element was started at a cut, reported playing, and then sat at its in-point for about 1 s until the 1 s valve from #7024 seeked it. That is a late sound of 600 ms or more at about 1 cut in 7 to 1 in 4 in the bad-phone runs.
Related work
Follows #7024 (WebKit audio in-point preparation and the 1 s valve) and #7012.
How
One place routes all media sync:
syncRuntimeMediainmedia.ts. A WebKit<audio>that is playing, not seeking, reports it can play (readyState3 or more) and whosecurrentTimehas not moved for 0.4 s of film time now counts as stuck and takes the existing hard sync, which still needs it to be more than 0.5 s behind (the 1 s lag valve stays). An element still filling data (readyStatebelow 3) is waiting, not stuck, and is left alone; its state is dropped when the clip leaves its window. WebKit starts audio about 150 ms afterplay(), so 0.4 s leaves room for a slow start; a moving element is never touched.Other arms measured on the phone and dropped: a fresh seek of the pre-seeked audio at the cut, and a silent warm-up play after the pre-seek. Both cost start time.
Test plan
Fails without the fix: with only
media.tsreverted, the new frozen-audio test fails (1 failed, 181 passed inmedia.test.ts); with the fix the wholesrc/runtimesuite gives 2756 passed, exit 0. Two more new tests: a moving WebKit element at the same lag is not seeked, and one still filling data is not seeked (it fails, withinit.buffering.test.ts, when thereadyStateguard is removed).Start cost on an iPhone, 30 plays per arm, 60 cuts each (hold / first sound / holds of 1 s or more):
Size
A lone about 70-line fix: one condition in the single media sync path plus its tests; no other open PR touches it.