Skip to content

Commit

Permalink
fix(text): Skip append if switching to a new stream
Browse files Browse the repository at this point in the history
StreamingEngine takes the following steps to fetch and append a
segment:
1. Fetch and append the init segment, and initializes the source
buffer;
2. Fetch the segment;
3. Append the segment.

When StreamingEngine switches to a new text stream, it:
1. initializes a new text parser
2. If there's a fetchAndAppend_() call in the process, waits until
   that is finished
3. Otherwise, clears the buffer, and schedules an update to call
   fetchAndAppend_().

If switching the text stream gets called in the middle of a
fetchAndAppend_() process, the stream of the mediaState
can be changed between fetch_() and append_().
The new text parser is intialized, but the new init segment is not
fetched yet, however StreamingEngine tries to append the old segment.
That would cause an error in TextParser.parseMedia().

After a segment is fetched, we can check if the current stream is
switched. If so, the mediaState is waiting to clear buffer. We can
skip append, and schedule a new update for the new stream.

b/168253400

Change-Id: If8eebeb9a8e459baf0ff34748d77020098a9468e
  • Loading branch information
michellezhuogg committed Dec 21, 2020
1 parent c9ac5d0 commit 3ad70b4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,17 @@ shaka.media.StreamingEngine = class {
if (this.fatalError_) {
return;
}

// If the text stream gets switched between fetch_() and append_(), the
// new text parser is initialized, but the new init segment is not
// fetched yet. That would cause an error in TextParser.parseMedia().
// See http://b/168253400
if (mediaState.waitingToClearBuffer) {
shaka.log.info(logPrefix, 'waitingToClearBuffer, skip append');
mediaState.performingUpdate = false;
this.scheduleUpdate_(mediaState, 0);
return;
}
await this.append_(
mediaState, presentationTime, stream, reference, results[1]);
}
Expand Down

0 comments on commit 3ad70b4

Please sign in to comment.