Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Decoder.js #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Player/Decoder.js

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

78 changes: 70 additions & 8 deletions Player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ p.decode(<binary>);
var lastWidth;
var lastHeight;
var onPictureDecoded = function(buffer, width, height) {
self.onPictureDecoded(buffer, width, height);

//setTimeout(function(){ self.onPictureDecoded(buffer, width, height); }, 33.333);
self.onPictureDecoded(buffer, width, height);
if (!buffer || !self.render) {
return;
};
Expand All @@ -128,8 +128,7 @@ p.decode(<binary>);
self.webGLCanvas.drawScene();
};

if (!webgl){

if (!webgl){
onPictureDecoded = function(buffer, width, height){
self.onPictureDecoded(buffer, width, height);

Expand Down Expand Up @@ -157,8 +156,71 @@ p.decode(<binary>);
};

};



this.bufferAr = [];

var concatUint8 = function(parAr) {
if (!parAr || !parAr.length){
return new Uint8Array(0);
};
var completeLength = 0;
var i = 0;
var l = parAr.length;
for (i; i < l; ++i){
completeLength += parAr[i].byteLength;
};

var res = new Uint8Array(completeLength);
var filledLength = 0;

for (i = 0; i < l; ++i){
res.set(new Uint8Array(parAr[i]), filledLength);
filledLength += parAr[i].byteLength;
};

return res;

};

this.decodeRaw = function(parData){
if (!(parData && parData.length)){
return;
};

var self = this;
var foundHit = false;
var hit = function(offset){
foundHit = true;
self.bufferAr.push(parData.subarray(0, offset));
self.decode( concatUint8(self.bufferAr) );
self.bufferAr = [];
self.bufferAr.push(parData.subarray(offset));
};

var b = 0;
var l = parData.length;
var zeroCnt = 0;
for (b; b < l; ++b){
if (parData[b] === 0){
zeroCnt++;
}else{
if (parData[b] == 1){
if (zeroCnt >= 3){
hit(b - 3);
break;
};
};
zeroCnt = 0;
};
};
if (!foundHit){
this.bufferAr.push(parData);
};
};

if (this._config.useWorker){

var worker = new Worker(this._config.workerFile);
this.worker = worker;
worker.addEventListener('message', function(e) {
Expand All @@ -178,10 +240,10 @@ p.decode(<binary>);
rgb: !webgl
}});

this.decode = function(parData){
// Copy the sample so that we only do a structured clone of the
// region of interest
// region of interest
var copyU8 = new Uint8Array(parData.length);
copyU8.set( parData, 0, parData.length );
worker.postMessage(copyU8.buffer, [copyU8.buffer]); // Send data to our worker.
Expand All @@ -200,6 +262,7 @@ p.decode(<binary>);

};



if (!this._config.size){
this._config.size = {};
Expand Down Expand Up @@ -229,4 +292,3 @@ p.decode(<binary>);
return Player;

}));