Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix potential AV sync issues after seek or adaptation #4886

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ shaka.media.StreamingEngine = class {
// The playhead might be seeking on startup, if a start time is set, so
// start "seeked" as true.
seeked: true,
needsResync: false,
recovering: false,
hasError: false,
operation: null,
Expand Down Expand Up @@ -1157,6 +1158,11 @@ shaka.media.StreamingEngine = class {
shaka.log.v1(
logPrefix, 'looking up segment from new stream endTime:', time);

// Using a new iterator means we need to resync the stream in sequence
// mode. The buffered range might not align perfectly with the last
// segment end time, so we may end up repeating a segment. Resyncing
// makes this safe to do.
mediaState.needsResync = true;
mediaState.segmentIterator =
mediaState.stream.segmentIndex.getIteratorForTime(time);
const ref = mediaState.segmentIterator &&
Expand Down Expand Up @@ -1674,7 +1680,9 @@ shaka.media.StreamingEngine = class {
const lastDiscontinuitySequence =
mediaState.lastSegmentReference ?
mediaState.lastSegmentReference.discontinuitySequence : null;
if (reference.discontinuitySequence != lastDiscontinuitySequence) {
if (reference.discontinuitySequence != lastDiscontinuitySequence ||
mediaState.needsResync) {
mediaState.needsResync = false;
operations.push(this.playerInterface_.mediaSourceEngine.resync(
mediaState.type, reference.startTime));
}
Expand Down Expand Up @@ -2279,6 +2287,7 @@ shaka.media.StreamingEngine.PlayerInterface;
* clearBufferSafeMargin: number,
* clearingBuffer: boolean,
* seeked: boolean,
* needsResync: boolean,
* adaptation: boolean,
* recovering: boolean,
* hasError: boolean,
Expand Down Expand Up @@ -2324,10 +2333,13 @@ shaka.media.StreamingEngine.PlayerInterface;
* The amount of buffer to retain when clearing the buffer after the update.
* @property {boolean} clearingBuffer
* True indicates that the buffer is being cleared.
* @property {boolean} seeked
* @property {boolean} seeked
* True indicates that the presentation just seeked.
* @property {boolean} adaptation
* @property {boolean} adaptation
* True indicates that the presentation just automatically switched variants.
* @property {boolean} needsResync
* True indicates that the stream needs to be resynced in sequence mode,
* regardless of discontinuity sequence.
* @property {boolean} recovering
* True indicates that the last segment was not appended because it could not
* fit in the buffer.
Expand Down