Skip to content

Commit

Permalink
memory recycle bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
soliton4 committed Jul 15, 2015
1 parent 0883ae0 commit 917bdef
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 28 deletions.
75 changes: 61 additions & 14 deletions Player/Decoder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 49 additions & 14 deletions Player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ p.decode(<binary>);

};

// provide size

if (!this._config.size){
this._config.size = {};
};
this._config.size.width = this._config.size.width || 200;
this._config.size.height = this._config.size.height || 200;

if (this._config.useWorker){
var worker = new Worker(this._config.workerFile);
Expand All @@ -139,22 +146,44 @@ p.decode(<binary>);
return;
};

onPictureDecoded.call(self, new Uint8Array(data.buf), data.width, data.height, data.infos);
onPictureDecoded.call(self, new Uint8Array(data.buf, 0, data.length), data.width, data.height, data.infos);

}, false);

worker.postMessage({type: "Broadway.js - Worker init", options: {
rgb: !webgl
rgb: !webgl,
memsize: this.memsize,
reuseMemory: this._config.reuseMemory ? true : false
}});

this.decode = function(parData, parInfo){
// Copy the sample so that we only do a structured clone of the
// region of interest
var copyU8 = new Uint8Array(parData.length);
copyU8.set( parData, 0, parData.length );
worker.postMessage({buf: copyU8.buffer, info: parInfo}, [copyU8.buffer]); // Send data to our worker.
if (this._config.transferMemory){
this.decode = function(parData, parInfo){
// no copy
// instead we are transfering the ownership of the buffer
// dangerous!!!

worker.postMessage({buf: parData.buffer, offset: parData.byteOffset, length: parData.length, info: parInfo}, [parData.buffer]); // Send data to our worker.
};

}else{
this.decode = function(parData, parInfo){
// Copy the sample so that we only do a structured clone of the
// region of interest
var copyU8 = new Uint8Array(parData.length);
copyU8.set( parData, 0, parData.length );
worker.postMessage({buf: copyU8.buffer, offset: 0, length: parData.length, info: parInfo}, [copyU8.buffer]); // Send data to our worker.
};

};

if (this._config.reuseMemory){
this.recycleMemory = function(parArray){
//this.beforeRecycle();
worker.postMessage({reuse: parArray.buffer}, [parArray.buffer]); // Send data to our worker.
//this.afterRecycle();
};
}

}else{

this.decoder = new Decoder({
Expand All @@ -169,11 +198,6 @@ p.decode(<binary>);
};


if (!this._config.size){
this._config.size = {};
};
this._config.size.width = this._config.size.width || 200;
this._config.size.height = this._config.size.height || 200;

if (this.render){
this.canvasObj = this.createCanvasObj({
Expand All @@ -193,6 +217,12 @@ p.decode(<binary>);

onPictureDecoded: function(buffer, width, height, infos){},

// call when memory of decoded frames is not used anymore
recycleMemory: function(buf){
},
/*beforeRecycle: function(){},
afterRecycle: function(){},*/

// for both functions options is:
//
// width
Expand Down Expand Up @@ -254,7 +284,10 @@ p.decode(<binary>);
width,
height,
null,
new Uint8Array(options.data));
options.data);
var self = this;
self.recycleMemory(options.data);


},
renderFrameRGB: function(options){
Expand All @@ -281,6 +314,8 @@ p.decode(<binary>);

imgData.data.set(options.data);
ctx.putImageData(imgData, 0, 0);
var self = this;
self.recycleMemory(options.data);

}

Expand Down
1 change: 1 addition & 0 deletions Player/mp4.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ var MP4Player = (function reader() {

this.avc = new Player({
useWorker: useWorkers,
reuseMemory: true,
webgl: webgl,
size: {
width: 640,
Expand Down

0 comments on commit 917bdef

Please sign in to comment.