From d1c8eb7d5eba9d13b7ad972750c3bf4c071cbebb Mon Sep 17 00:00:00 2001 From: Sandra Lokshina Date: Fri, 14 Jun 2019 15:32:00 -0700 Subject: [PATCH] Fix switching text on an edge case. 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 --- lib/media/streaming_engine.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 3b549b345..0428587ba 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -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