From 2d65d27709df1ce36a0433d6deac417fb608ea6e Mon Sep 17 00:00:00 2001 From: Sami Spets <savasp@utu.fi> Date: Fri, 13 Dec 2019 07:02:28 +0000 Subject: [PATCH] Fixes bug in video decoding (cherry picked from commit 75b9f6b314481c5ddaecb9caa7f109e683a549fe) --- web-service/public/js/bundle.js | 171 ++++++++++++++++---------------- web-service/public/js/index.js | 5 +- web-service/server/src/index.js | 7 +- 3 files changed, 91 insertions(+), 92 deletions(-) diff --git a/web-service/public/js/bundle.js b/web-service/public/js/bundle.js index 3ad7e375c..df7eec769 100644 --- a/web-service/public/js/bundle.js +++ b/web-service/public/js/bundle.js @@ -76,15 +76,12 @@ renderThumbnails = async () => { for(var i=0; i<thumbnails.length; i++){ const encodedURI = encodeURIComponent(thumbnails[i]) current_data.uri = thumbnails[i] - console.log("URI to be added", thumbnails[i]) try{ const someData = await fetch(`./stream/rgb?uri=${encodedURI}`) - console.log('SOME DATA', someData) if(!someData.ok){ throw new Error('Image not found') } const myBlob = await someData.blob(); - console.log('BLOB', myBlob) const objectURL = URL.createObjectURL(myBlob); // containerDiv.innerHTML += createCard() containerDiv.innerHTML += createCard(objectURL, i+4) @@ -110,7 +107,9 @@ createCard = (url, viewers) => { createPeer = () => { + // FOR PRODUCTION const ws = new WebSocket("ws://" + location.host + ":" + (location.port == "" ? "80" : location.port) + location.pathname); + // const ws = new WebSocket("ws://localhost:8080") ws.binaryType = "arraybuffer"; peer = new Peer(ws) } @@ -1915,7 +1914,7 @@ BufferList.prototype._match = function(offset, search) { module.exports = BufferList -},{"readable-stream":27,"safe-buffer":28,"util":53}],11:[function(require,module,exports){ +},{"readable-stream":28,"safe-buffer":29,"util":53}],11:[function(require,module,exports){ (function (Buffer){ // Copyright Joyent, Inc. and other Node contributors. // @@ -2025,8 +2024,8 @@ function objectToString(o) { return Object.prototype.toString.call(o); } -}).call(this,{"isBuffer":require("../../../../../../../../../../../usr/lib/node_modules/browserify/node_modules/is-buffer/index.js")}) -},{"../../../../../../../../../../../usr/lib/node_modules/browserify/node_modules/is-buffer/index.js":47}],12:[function(require,module,exports){ +}).call(this,{"isBuffer":require("../../../../../../../../../usr/local/lib/node_modules/browserify/node_modules/is-buffer/index.js")}) +},{"../../../../../../../../../usr/local/lib/node_modules/browserify/node_modules/is-buffer/index.js":47}],12:[function(require,module,exports){ if (typeof Object.create === 'function') { // implementation from standard node.js 'util' module module.exports = function inherits(ctor, superCtor) { @@ -2145,7 +2144,7 @@ function msgpack (options) { module.exports = msgpack -},{"./lib/decoder":15,"./lib/encoder":16,"./lib/streams":17,"assert":38,"bl":10,"safe-buffer":28}],15:[function(require,module,exports){ +},{"./lib/decoder":15,"./lib/encoder":16,"./lib/streams":17,"assert":38,"bl":10,"safe-buffer":29}],15:[function(require,module,exports){ 'use strict' var bl = require('bl') @@ -2928,7 +2927,7 @@ function encodeFloat (obj, forceFloat64) { return buf } -},{"bl":10,"safe-buffer":28}],17:[function(require,module,exports){ +},{"bl":10,"safe-buffer":29}],17:[function(require,module,exports){ 'use strict' var Transform = require('readable-stream').Transform @@ -3020,7 +3019,7 @@ Decoder.prototype._transform = function (buf, enc, done) { module.exports.decoder = Decoder module.exports.encoder = Encoder -},{"bl":10,"inherits":12,"readable-stream":27}],18:[function(require,module,exports){ +},{"bl":10,"inherits":12,"readable-stream":28}],18:[function(require,module,exports){ (function (process){ 'use strict'; @@ -4271,7 +4270,7 @@ function indexOf(xs, x) { return -1; } }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./_stream_duplex":19,"./internal/streams/BufferList":24,"./internal/streams/destroy":25,"./internal/streams/stream":26,"_process":49,"core-util-is":11,"events":45,"inherits":12,"isarray":13,"process-nextick-args":18,"safe-buffer":28,"string_decoder/":29,"util":43}],22:[function(require,module,exports){ +},{"./_stream_duplex":19,"./internal/streams/BufferList":24,"./internal/streams/destroy":25,"./internal/streams/stream":26,"_process":49,"core-util-is":11,"events":45,"inherits":12,"isarray":13,"process-nextick-args":18,"safe-buffer":29,"string_decoder/":27,"util":43}],22:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -5176,7 +5175,7 @@ Writable.prototype._destroy = function (err, cb) { cb(err); }; }).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate) -},{"./_stream_duplex":19,"./internal/streams/destroy":25,"./internal/streams/stream":26,"_process":49,"core-util-is":11,"inherits":12,"process-nextick-args":18,"safe-buffer":28,"timers":50,"util-deprecate":30}],24:[function(require,module,exports){ +},{"./_stream_duplex":19,"./internal/streams/destroy":25,"./internal/streams/stream":26,"_process":49,"core-util-is":11,"inherits":12,"process-nextick-args":18,"safe-buffer":29,"timers":50,"util-deprecate":30}],24:[function(require,module,exports){ 'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -5256,7 +5255,7 @@ if (util && util.inspect && util.inspect.custom) { return this.constructor.name + ' ' + obj; }; } -},{"safe-buffer":28,"util":43}],25:[function(require,module,exports){ +},{"safe-buffer":29,"util":43}],25:[function(require,module,exports){ 'use strict'; /*<replacement>*/ @@ -5335,79 +5334,6 @@ module.exports = { module.exports = require('events').EventEmitter; },{"events":45}],27:[function(require,module,exports){ -exports = module.exports = require('./lib/_stream_readable.js'); -exports.Stream = exports; -exports.Readable = exports; -exports.Writable = require('./lib/_stream_writable.js'); -exports.Duplex = require('./lib/_stream_duplex.js'); -exports.Transform = require('./lib/_stream_transform.js'); -exports.PassThrough = require('./lib/_stream_passthrough.js'); - -},{"./lib/_stream_duplex.js":19,"./lib/_stream_passthrough.js":20,"./lib/_stream_readable.js":21,"./lib/_stream_transform.js":22,"./lib/_stream_writable.js":23}],28:[function(require,module,exports){ -/* eslint-disable node/no-deprecated-api */ -var buffer = require('buffer') -var Buffer = buffer.Buffer - -// alternative to using Object.keys for old browsers -function copyProps (src, dst) { - for (var key in src) { - dst[key] = src[key] - } -} -if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - module.exports = buffer -} else { - // Copy properties from require('buffer') - copyProps(buffer, exports) - exports.Buffer = SafeBuffer -} - -function SafeBuffer (arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length) -} - -// Copy static methods from Buffer -copyProps(Buffer, SafeBuffer) - -SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === 'number') { - throw new TypeError('Argument must not be a number') - } - return Buffer(arg, encodingOrOffset, length) -} - -SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - var buf = Buffer(size) - if (fill !== undefined) { - if (typeof encoding === 'string') { - buf.fill(fill, encoding) - } else { - buf.fill(fill) - } - } else { - buf.fill(0) - } - return buf -} - -SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return Buffer(size) -} - -SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== 'number') { - throw new TypeError('Argument must be a number') - } - return buffer.SlowBuffer(size) -} - -},{"buffer":44}],29:[function(require,module,exports){ // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -5704,7 +5630,80 @@ function simpleWrite(buf) { function simpleEnd(buf) { return buf && buf.length ? this.write(buf) : ''; } -},{"safe-buffer":28}],30:[function(require,module,exports){ +},{"safe-buffer":29}],28:[function(require,module,exports){ +exports = module.exports = require('./lib/_stream_readable.js'); +exports.Stream = exports; +exports.Readable = exports; +exports.Writable = require('./lib/_stream_writable.js'); +exports.Duplex = require('./lib/_stream_duplex.js'); +exports.Transform = require('./lib/_stream_transform.js'); +exports.PassThrough = require('./lib/_stream_passthrough.js'); + +},{"./lib/_stream_duplex.js":19,"./lib/_stream_passthrough.js":20,"./lib/_stream_readable.js":21,"./lib/_stream_transform.js":22,"./lib/_stream_writable.js":23}],29:[function(require,module,exports){ +/* eslint-disable node/no-deprecated-api */ +var buffer = require('buffer') +var Buffer = buffer.Buffer + +// alternative to using Object.keys for old browsers +function copyProps (src, dst) { + for (var key in src) { + dst[key] = src[key] + } +} +if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + module.exports = buffer +} else { + // Copy properties from require('buffer') + copyProps(buffer, exports) + exports.Buffer = SafeBuffer +} + +function SafeBuffer (arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length) +} + +// Copy static methods from Buffer +copyProps(Buffer, SafeBuffer) + +SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === 'number') { + throw new TypeError('Argument must not be a number') + } + return Buffer(arg, encodingOrOffset, length) +} + +SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') + } + var buf = Buffer(size) + if (fill !== undefined) { + if (typeof encoding === 'string') { + buf.fill(fill, encoding) + } else { + buf.fill(fill) + } + } else { + buf.fill(0) + } + return buf +} + +SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') + } + return Buffer(size) +} + +SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== 'number') { + throw new TypeError('Argument must be a number') + } + return buffer.SlowBuffer(size) +} + +},{"buffer":44}],30:[function(require,module,exports){ (function (global){ /** diff --git a/web-service/public/js/index.js b/web-service/public/js/index.js index 2f8c10613..8ea42a108 100644 --- a/web-service/public/js/index.js +++ b/web-service/public/js/index.js @@ -75,15 +75,12 @@ renderThumbnails = async () => { for(var i=0; i<thumbnails.length; i++){ const encodedURI = encodeURIComponent(thumbnails[i]) current_data.uri = thumbnails[i] - console.log("URI to be added", thumbnails[i]) try{ const someData = await fetch(`./stream/rgb?uri=${encodedURI}`) - console.log('SOME DATA', someData) if(!someData.ok){ throw new Error('Image not found') } const myBlob = await someData.blob(); - console.log('BLOB', myBlob) const objectURL = URL.createObjectURL(myBlob); // containerDiv.innerHTML += createCard() containerDiv.innerHTML += createCard(objectURL, i+4) @@ -109,7 +106,9 @@ createCard = (url, viewers) => { createPeer = () => { + // FOR PRODUCTION const ws = new WebSocket("ws://" + location.host + ":" + (location.port == "" ? "80" : location.port) + location.pathname); + // const ws = new WebSocket("ws://localhost:8080") ws.binaryType = "arraybuffer"; peer = new Peer(ws) } diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index a89006de0..c4664d272 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -105,7 +105,7 @@ RGBDStream.prototype.addClient = function(peer, N, rate, dest) { } this.clients.push(new RGBDClient(peer, N, rate, dest)); - + console.log("MINMAX", this.rxcount, this.rxmax); if (this.rxcount >= this.rxmax) { this.subscribe(); } @@ -161,7 +161,7 @@ app.get('/streams', (req, res) => { app.get('/stream/rgb', (req, res) => { let uri = req.query.uri; if (uri_data.hasOwnProperty(uri)) { - uri_data[uri].peer.send("get_stream", uri, 3, 0, [Peer.uuid], uri); + uri_data[uri].peer.send("get_stream", uri, 3, 9, [Peer.uuid], uri); res.writeHead(200, {'Content-Type': 'image/jpeg'}); res.end(uri_data[uri].rgb); } @@ -389,8 +389,9 @@ app.ws('/', (ws, req) => { let peer = uri_data[uri].peer console.log(peer) if (peer) { - console.log("GET_STREAM IS WORKING VERY WELL") + console.log("THIS GETS LOGGED") uri_data[uri].addClient(p, N, rate, dest); + console.log("SO DOES THIS") //peer.send("get_stream", uri, N, rate, [Peer.uuid], dest); } }else{ -- GitLab