Skip to content

Commit

Permalink
fix: Fix MediaSourceEngine reset operation (#5576)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored and joeyparrish committed Sep 2, 2023
1 parent 58e6627 commit 8c66b7a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/media/media_source_engine.js
Expand Up @@ -1562,16 +1562,34 @@ shaka.media.MediaSourceEngine = class {
* @private
*/
async reset_(streamsByType) {
const Functional = shaka.util.Functional;
this.reloadingMediaSource_ = true;
const currentTime = this.video_.currentTime;
try {
this.eventManager_.removeAll();
this.sourceBuffers_ = {};

const cleanup = [];
for (const contentType in this.transmuxers_) {
cleanup.push(this.transmuxers_[contentType].destroy());
}
for (const contentType in this.queues_) {
// Make a local copy of the queue and the first item.
const q = this.queues_[contentType];
const inProgress = q[0];

// Drop everything else out of the original queue.
this.queues_[contentType] = q.slice(0, 1);

// We will wait for this item to complete/fail.
if (inProgress) {
cleanup.push(inProgress.p.catch(Functional.noop));
}

// The rest will be rejected silently if possible.
for (const item of q.slice(1)) {
item.p.reject(shaka.util.Destroyer.destroyedError());
}
}
for (const contentType in this.sourceBuffers_) {
const sourceBuffer = this.sourceBuffers_[contentType];
try {
Expand All @@ -1580,6 +1598,8 @@ shaka.media.MediaSourceEngine = class {
}
await Promise.all(cleanup);
this.transmuxers_ = {};
this.queues_ = {};
this.sourceBuffers_ = {};

const previousDuration = this.mediaSource_.duration;
this.mediaSourceOpen_ = new shaka.util.PublicPromise();
Expand Down

0 comments on commit 8c66b7a

Please sign in to comment.