From ba689405a465d2173cbb887a374f197e74afd7ed Mon Sep 17 00:00:00 2001 From: Blair MacIntyre Date: Mon, 19 Mar 2018 09:00:16 -0400 Subject: [PATCH] another attempt at workers. still not working. --- examples/simplecv/index.html | 10 ++++++++-- examples/simplecv/intensity.js | 8 +++++--- polyfill/XRSession.js | 12 ++++++++++++ polyfill/platform/ARKitWrapper.js | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/examples/simplecv/index.html b/examples/simplecv/index.html index e591a6b..6287d1e 100644 --- a/examples/simplecv/index.html +++ b/examples/simplecv/index.html @@ -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; diff --git a/examples/simplecv/intensity.js b/examples/simplecv/intensity.js index 0d714b8..530bdb2 100644 --- a/examples/simplecv/intensity.js +++ b/examples/simplecv/intensity.js @@ -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]) diff --git a/polyfill/XRSession.js b/polyfill/XRSession.js index fd37577..96f205b 100644 --- a/polyfill/XRSession.js +++ b/polyfill/XRSession.js @@ -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) } diff --git a/polyfill/platform/ARKitWrapper.js b/polyfill/platform/ARKitWrapper.js index 409875b..98fe693 100644 --- a/polyfill/platform/ARKitWrapper.js +++ b/polyfill/platform/ARKitWrapper.js @@ -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; }