Skip to content

Commit

Permalink
fix: Fix reset MSE to last independent segment (#7494)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored and joeyparrish committed Nov 12, 2024
1 parent ad69e08 commit d666fbf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/media/segment_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,26 @@ shaka.media.SegmentIterator = class {
'done': !res,
};
}

/**
* @export
*/
resetToLastIndependent() {
const current = this.current();
if (current.isPartial() && !current.isIndependent()) {
const ref = this.segmentIndex_.get(this.currentPosition_);
if (ref && ref.hasPartialSegments()) {
let partial = ref.partialReferences[this.currentPartialPosition_];
while (partial.isIndependent()) {
if (this.currentPartialPosition_ <= 0) {
break;
}
this.currentPartialPosition_--;
partial = ref.partialReferences[this.currentPartialPosition_];
}
}
}
}
};


Expand Down
6 changes: 6 additions & 0 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2871,12 +2871,18 @@ shaka.media.StreamingEngine = class {
audioMediaState.lastInitSegmentReference = null;
this.forceClearBuffer_(audioMediaState);
this.abortOperations_(audioMediaState).catch(() => {});
if (audioMediaState.segmentIterator) {
audioMediaState.segmentIterator.resetToLastIndependent();
}
}
const videoMediaState = this.mediaStates_.get(ContentType.VIDEO);
if (videoMediaState) {
videoMediaState.lastInitSegmentReference = null;
this.forceClearBuffer_(videoMediaState);
this.abortOperations_(videoMediaState).catch(() => {});
if (videoMediaState.segmentIterator) {
videoMediaState.segmentIterator.resetToLastIndependent();
}
}
/**
* @type {!Map.<shaka.util.ManifestParserUtils.ContentType,
Expand Down
2 changes: 2 additions & 0 deletions test/test/util/simple_fakes.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ shaka.test.FakeSegmentIndex = class {
},

setReverse: () => {},

resetToLastIndependent: () => {},
};
});
}
Expand Down

0 comments on commit d666fbf

Please sign in to comment.