Track sourceended event and handle ManagedMediaSource recovery #7697
+24
−1
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.
This PR will...
Fix ManagedMediaSource cold start bug on iOS 26.2 by detecting the broken state and triggering immediate recovery.
Why is this Pull Request needed?
On iOS 26.2 real devices, the first ManagedMediaSource instance after a browser cold start fails when concurrent
appendBuffer()calls are made. iOS 26.0 and 26.1 are not affected.Bug behavior:
readyStatereportsendedeven though it's not truly endedsourceendedevent never fires (unlike legitimate ends)WebKit Bug: https://bugs.webkit.org/show_bug.cgi?id=305712
Stuck vs Non-Stuck Randomness:
The bug causes one of two SourceBuffer appends to fail randomly. Whether playback gets stuck depends on which append succeeds:
4.223s(keyframe)0.023scurrentTime=0but buffer starts at 4.2sLog Excerpts
STUCK Case (audio error, video succeeded first):
NOT STUCK Case (video error, audio succeeded first):
With Fix (expected behavior):
Fix approach:
sourceendedevent has firedreadyState === "ended"butsourceendednever fired -> bug detectedrecoverMediaError()at the source, before the error propagates through error-controller_onMediaSourceClose)Note
Without this fix, error-controller attempts level switching before eventually calling
recoverMediaError(). Since the MediaSource itself is broken, early detection allows faster recovery.Screencasts
Before (bug):
no_fix.mp4
After (fix):
with_fix.mp4
Are there any points in the code the reviewer needs to double check?
The detection logic in
onSBUpdateError:This should only trigger when:
this.appendSource)readyStateisendedsourceendedevent never fired (!this.sourceEnded)Resolves issues:
Fixes #7687
Checklist