another attempt at workers. still not working.

This commit is contained in:
Blair MacIntyre 2018-03-19 09:00:16 -04:00
Родитель edd62b810d
Коммит ba689405a4
4 изменённых файлов: 26 добавлений и 6 удалений

Просмотреть файл

@ -71,6 +71,12 @@
}
newSession() {
// this.worker = new Worker("intensity.js");
// var self = this;
// this.worker.onmessage = function(ev) {
// self.intensity = ev;
// }
// this.setVideoWorker(this.worker);
this.setVideoWorker(ev => { this.handleVideoFrame(ev) })
}
@ -103,7 +109,7 @@
var w = buffer.size.width;
var h = buffer.size.height;
var pad = buffer.size.bytesPerRow - w;
var pixels = buffer.buffer;
var pixels = new Uint8Array(buffer.buffer);
var intensity = 0.0;
var p = 0;
@ -128,7 +134,7 @@
var w = buffer.size.width;
var h = buffer.size.height;
var pixels = buffer.buffer;
var pixels = new Uint8Array(buffer.buffer);
var cx = w // it's w/2 but then *2 since it's two bytes per!
var cy = h / 2;

Просмотреть файл

@ -8,7 +8,7 @@ averageIntensity = function (buffer) {
var w = buffer.size.width;
var h = buffer.size.height;
var pad = buffer.size.bytesPerRow - w;
var pixels = buffer.buffer;
var pixels = new Uint8Array(buffer.buffer);
var intensity = 0.0;
var p = 0;
@ -29,8 +29,10 @@ averageIntensity = function (buffer) {
}
onMessage = function (ev) {
var frame = ev.detail.frame
var camera = ev.detail.camera
//postMessage (Math.random() * 255.0);
var frame = detail.frame
var camera = detail.camera
switch (frame.pixelFormat) {
case "YUV420P":
this.averageIntensity(frame.buffers[0])

Просмотреть файл

@ -71,6 +71,18 @@ export default class XRSession extends EventHandlerBase {
}
requestVideoFrames(callback) {
if (callback instanceof Worker) {
var worker = callback;
callback = (ev => {
var cv = ev.detail
var buffers = cv.frame.buffers
var buffs = []
for (var i = 0; i < buffers.length; i++) {
buffs.push(buffers[i].buffer)
}
worker.postMessage(cv, buffs);
})
}
this._display.addEventListener("videoFrame", callback)
}

Просмотреть файл

@ -884,7 +884,7 @@ export default class ARKitWrapper extends EventHandlerBase {
var buffers = detail.frame.buffers;
for (var i = 0; i < buffers.length; i++) {
var bufflen = buffers[i].buffer.length;
buffers[i].buffer = base64.decode(buffers[i].buffer);
buffers[i].buffer = base64.decodeArrayBuffer(buffers[i].buffer);
var buffersize = buffers[i].buffer.length;
var imagesize = buffers[i].size.height * buffers[i].size.bytesPerRow;
}