Skip to content

Commit

Permalink
According to the spec, when cloning a typed array that is a view of a…
Browse files Browse the repository at this point in the history
… larger buffer, the entire buffer should be cloned and then the view recreated on that buffer. Firefox used to copy only the portion within the view, which observably differs from the spec. Its behavior is changing, which can result in hugely inflated memory usage.
  • Loading branch information
hotsphink committed Jun 11, 2013
1 parent f3871c8 commit 1c500d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Player/avc-worker.js
Expand Up @@ -17,6 +17,11 @@ avc.onPictureDecoded = function (buffer, width, height) {
if (config && config.sendBufferOnPictureDecoded !== undefined) {
buffer = config.sendBufferOnPictureDecoded ? buffer : null;
}
// 'buffer' is a view of a large ArrayBuffer. Only clone the portion in the
// view.
if (buffer) {
buffer = Uint8Array(buffer);
}
socket.sendMessage("on-picture-decoded", {picture: buffer, width: width, height: height});
}

Expand Down
4 changes: 3 additions & 1 deletion Player/mp4.js
Expand Up @@ -866,7 +866,9 @@ var MP4Player = (function reader() {
if (this.useWorkers) {
var avcWorker = this.avcWorker;
video.getSampleNALUnits(pic).forEach(function (nal) {
avcWorker.sendMessage("decode-sample", nal);
// Copy the sample so that we only do a structured clone of the
// region of interest
avcWorker.sendMessage("decode-sample", Uint8Array(nal));
});
} else {
var avc = this.avc;
Expand Down

0 comments on commit 1c500d6

Please sign in to comment.