Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix errors with TS segments on Chromecast (#4543)
On Chromecast devices, TS-based streams tend to be more susceptible to failures related to the Cast platform's MSE implementation. One of these failures was observed when Shaka Player updates `SourceBuffer#timestampOffset` within `MediaSourceEngine#appendBuffer()`: 1. To extract a timestamp from `MediaSource` to align text segments: https://github.com/shaka-project/shaka-player/blob/3d0f752c7d0677f750dbbd9bcd2895358358628f/lib/media/media_source_engine.js#L657 2. To re-align segments as a result of an unbuffered seek or automatic adaptation: https://github.com/shaka-project/shaka-player/blob/3d0f752c7d0677f750dbbd9bcd2895358358628f/lib/media/media_source_engine.js#L684-L686 The Cast platform throws the following error: ``` ... "stack":"Error: Failed to set the 'timestampOffset' property on 'SourceBuffer': The timestamp offset may not be set while the SourceBuffer's append state is 'PARSING_MEDIA_SEGMENT'. ... ``` One way of resolving this is to reset the SourceBuffer's parser state, which in turn resets the append state from `PARSING_MEDIA_SEGMENT` => `WAITING_FOR_SEGMENT`: https://www.w3.org/TR/media-source-2/#sourcebuffer-reset-parser-state. On Cast devices, the issue is reproduced consistently when Shaka switches to a new variant. There are no internally queued MSE operations in `MediaSourceEngine` when the error is thrown. Based on these observations, the input buffer passed to `MediaSourceEngine` seems to be an "incomplete" media segment, meaning the `SourceBuffer#appendBuffer()` call exits when the append state is still `PARSING_MEDIA_SEGMENT` ([Step `6.4` in W3C specs](https://www.w3.org/TR/media-source-2/#sourcebuffer-segment-parser-loop)) hence the error. This is also suggested as a root cause from a Chromium engineer, with one suggested solution to call abort() beforehand ([source](https://bugs.chromium.org/p/chromium/issues/detail?id=766002#c3)). Since Shaka Player already does preemptive abort() calls when [setting stream properties](https://github.com/shaka-project/shaka-player/blob/3d0f752c7d0677f750dbbd9bcd2895358358628f/lib/media/media_source_engine.js#L836-L842), this will do the same thing. Co-authored-by: Joey Parrish <joeyparrish@users.noreply.github.com>
- Loading branch information