Skip to content

Commit

Permalink
fix: Use revokeObjectURL dispose for created MSE blob urls (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Jun 18, 2020
1 parent a77eacc commit ca73cac
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/videojs-http-streaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,9 @@ class VhsHandler extends Component {
return;
}

this.tech_.src(window.URL.createObjectURL(this.masterPlaylistController_.mediaSource));
this.mediaSourceUrl_ = window.URL.createObjectURL(this.masterPlaylistController_.mediaSource);

this.tech_.src(this.mediaSourceUrl_);
}

/**
Expand Down Expand Up @@ -852,6 +854,11 @@ class VhsHandler extends Component {
delete this.tech_.hls;
}

if (this.mediaSourceUrl_ && window.URL.revokeObjectURL) {
window.URL.revokeObjectURL(this.mediaSourceUrl_);
this.mediaSourceUrl_ = null;
}

super.dispose();
}

Expand Down
40 changes: 40 additions & 0 deletions test/videojs-http-streaming.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,46 @@ QUnit.module('VHS', {
}
});

QUnit.test('mse urls are created and revoked', function(assert) {
const old = {
createObjectURL: window.URL.createObjectURL,
revokeObjectURL: window.URL.revokeObjectURL
};
const ids = [];

window.URL.createObjectURL = (...args) => {
const id = old.createObjectURL.apply(window.URL, args);

ids.push(id);
return id;
};

window.URL.revokeObjectURL = (...args) => {
const index = ids.indexOf(args[0]);

if (index !== -1) {
ids.splice(index, 1);
}
return old.revokeObjectURL.apply(window.URL, args);
};

this.player.src({
src: 'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});

this.clock.tick(1);

assert.ok(ids.length > 0, 'object urls created');

this.player.dispose();

assert.equal(ids.length, 0, 'all object urls removed');

window.URL.createObjectURL = old.createObjectURL;
window.URL.revokeObjectURL = old.revokeObjectURL;
});

QUnit.test('version is exported', function(assert) {
this.player.src({
src: 'manifest/playlist.m3u8',
Expand Down

0 comments on commit ca73cac

Please sign in to comment.