Skip to content

Commit

Permalink
fix(HLS): Fix uncaught error in slow network scenario (#7321)
Browse files Browse the repository at this point in the history
This case can occur with a live HLS in which the playlist timeout errors
and that playlist is deactivated and changed to another one and this
other one takes a long time to be received.
  • Loading branch information
avelad authored Sep 17, 2024
1 parent b4c00ad commit 68e579b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1519,9 +1519,11 @@ shaka.media.StreamingEngine = class {
logPrefix, 'looking up segment from new stream endTime:', time);

const reverse = this.playerInterface_.getPlaybackRate() < 0;
mediaState.segmentIterator =
mediaState.stream.segmentIndex.getIteratorForTime(
time, /* allowNonIndepedent= */ false, reverse);
if (mediaState.stream.segmentIndex) {
mediaState.segmentIterator =
mediaState.stream.segmentIndex.getIteratorForTime(
time, /* allowNonIndepedent= */ false, reverse);
}
const ref = mediaState.segmentIterator &&
mediaState.segmentIterator.next().value;
if (ref == null) {
Expand All @@ -1545,18 +1547,22 @@ shaka.media.StreamingEngine = class {
const reverse = this.playerInterface_.getPlaybackRate() < 0;
let ref = null;
if (inaccurateTolerance) {
mediaState.segmentIterator =
mediaState.stream.segmentIndex.getIteratorForTime(
lookupTime, /* allowNonIndepedent= */ false, reverse);
if (mediaState.stream.segmentIndex) {
mediaState.segmentIterator =
mediaState.stream.segmentIndex.getIteratorForTime(
lookupTime, /* allowNonIndepedent= */ false, reverse);
}
ref = mediaState.segmentIterator &&
mediaState.segmentIterator.next().value;
}
if (!ref) {
// If we can't find a valid segment with the drifted time, look for a
// segment with the presentation time.
mediaState.segmentIterator =
mediaState.stream.segmentIndex.getIteratorForTime(
presentationTime, /* allowNonIndepedent= */ false, reverse);
if (mediaState.stream.segmentIndex) {
mediaState.segmentIterator =
mediaState.stream.segmentIndex.getIteratorForTime(
presentationTime, /* allowNonIndepedent= */ false, reverse);
}
ref = mediaState.segmentIterator &&
mediaState.segmentIterator.next().value;
}
Expand Down

0 comments on commit 68e579b

Please sign in to comment.