Skip to content

Commit

Permalink
Fix switching text on an edge case.
Browse files Browse the repository at this point in the history
When switch() is called, it checks for what segment/period the media
state will need to fetch next. As text is much smaller than audio/
video, it might be the case that text has all the segments in
period i while audio and video are still in the process of fetching
them.
Thus, the next period needed for text will be i+1, while for other
media states it will be i.
Switch() assumes that if the period needed is not the same as
current period, a perios transition is about to happen and there's
no point in switching streams now since they're about to change on
the next update anyway.
However, the period transition only happenes if all the media
states require it. In our edge case, only text is ready for the
next period, so transition will not happen.
This change corrects the assumption "if a media state is ready
for the new period, don't switch" to assumption "if ALL media
states are ready for the new period, don't switch."

Issue #1774

Change-Id: I35f1b7ae10704922fb5692e02fc5f2edc6982575
  • Loading branch information
ismena committed Jun 18, 2019
1 parent 424f21c commit d1c8eb7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/media/streaming_engine.js
Expand Up @@ -543,7 +543,12 @@ shaka.media.StreamingEngine = class {
// handle a Period transition. Simply ignore the given stream, assuming that
// Player will select the same track in onChooseStreams.
const periodIndex = this.findPeriodContainingStream_(stream);
if (clearBuffer && periodIndex != mediaState.needPeriodIndex) {
const mediaStates = Array.from(this.mediaStates_.values());
const needSamePeriod = mediaStates.every((ms) => {
return ms.needPeriodIndex == mediaState.needPeriodIndex;
});
if (clearBuffer && periodIndex != mediaState.needPeriodIndex &&
needSamePeriod) {
shaka.log.debug('switch: switching to stream in another Period; ' +
'clearing buffer and changing Periods');
// handlePeriodTransition_ will be called on the next update because the
Expand Down

0 comments on commit d1c8eb7

Please sign in to comment.