Skip to content

Commit

Permalink
Testing with studio data
Browse files Browse the repository at this point in the history
  • Loading branch information
twojtasz committed Dec 12, 2020
1 parent 0889eb1 commit 258b841
Show file tree
Hide file tree
Showing 9 changed files with 609 additions and 6 deletions.
3 changes: 1 addition & 2 deletions examples/get-started/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const TIMEFORMAT_SCALE = getXVIZConfig().TIMESTAMP_FORMAT === 'seconds' ? 1000 :

// __IS_STREAMING__ and __IS_LIVE__ are defined in webpack.config.js
const exampleLog = require(__IS_STREAMING__
? './log-from-stream'
? './log-from-scc'
: __IS_LIVE__
? './log-from-live'
: './log-from-file').default;
Expand Down Expand Up @@ -83,7 +83,6 @@ class Example extends PureComponent {
values={this.state.settings}
onChange={this._onSettingsChange}
/>
<StreamSettingsPanel log={log} />
</div>
<div id="log-panel">
<div id="map-view">
Expand Down
5 changes: 4 additions & 1 deletion examples/get-started/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const MAPBOX_TOKEN = process.env.MapboxAccessToken; // eslint-disable-lin
export const MAP_STYLE = 'mapbox://styles/mapbox/light-v9';

export const XVIZ_CONFIG = {
PLAYBACK_FRAME_RATE: 10
currentMajorVersion: 2,
PLAYBACK_FRAME_RATE: 10,
DYNAMIC_STREAM_METADATA: true,
PRIMARY_POSE_STREAM: "/vehicle/LoggedContinuousPose"
};

export const CAR = CarMesh.sedan({
Expand Down
27 changes: 27 additions & 0 deletions examples/get-started/src/log-from-scc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import {StudioFileLoader} from './studio-file-loader';

export default new StudioFileLoader({
url: 'http://192.168.1.7:4080/rvt-1-3000.scc',
worker: true,
maxConcurrency: 4
});
32 changes: 32 additions & 0 deletions examples/get-started/src/log-from-studio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import {StudioLoader} from './studio-loader';

export default new StudioLoader({
logGuid: 'mock',
// bufferLength: 15,
serverConfig: {
defaultLogLength: 30,
serverUrl: 'ws://atg1-vdi-ngpu-twojtasz:4080'
},
worker: true,
maxConcurrency: 4
});
192 changes: 192 additions & 0 deletions examples/get-started/src/studio-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
const COMMS_CACHE_HEADER_VERSION = 0x033b0002;
const MESSAGE_HEADER = 8;
/* SCC Binary Layout
* [----] 4 magic
* [----] 4 size of header
* [*] header
* messages
*
* Message Binary Layout
* [----] 4 size
* [----] 4 timestamp_ms
* [*] data
*/

export class SCCLog {
constructor(onMessage) {
this.array = null; // for slicing data
this.buffer = null; // for appending data
this.view = null; // for reading data
this.limit = 0;

this.mark = 0;
this.onMessage = onMessage;
}

open(url) {
fetch(url)
.then(response => {
if (!response.ok) {
this.console.log(response.statusText);
return;
}

const reader = response.body.getReader();
const self = this;
return new ReadableStream({
start() {
return pump();

function pump() {
reader.read().then(({ done, value }) => {
if (!done) {
self._addChunk(response, value);
return pump();
}
});
}
}
});
})
.catch(error => {
console.log("Error fetching log: " + error);
});
}

_addChunk(response, data) {
if (this.limit === 0) {
const length = response.headers.get("content-length");

this.array = new ArrayBuffer(length);

this.buffer = new Uint8Array(this.array);
this.buffer.set(data, 0);
this.limit = data.length;

this.view = new DataView(this.array);
} else {
this.buffer.set(data, this.limit);
this.limit += data.length;
}

this.publishMessages();
}

publishMessages() {
if (!this.message) {
const startOffset = this._readHeader();
if (startOffset) {
this.message = new SCCMessage(this.array, this.view, startOffset, this.limit);
} else {
return;
}
} else {
this.message.setLimit(this.limit);
}

while (this.message.available()) {
this.onMessage(this.message.data(), this.message.timestamp);
this.message.next();
}
}

_readHeader() {
const magic = this.view.getUint32(0, true);
if (magic !== COMMS_CACHE_HEADER_VERSION) {
throw new Error("File does not start with the expected signature.");
}

const headerSize = this.view.getUint32(4, true);
if (headerSize + 8 > this.limit) {
throw new Error("Header is larger than file");
}

return headerSize + 8;
}
}

class SCCMessage {
constructor(array, view, start, limit) {
this.array = array;
this.view = view;
this.start = start;
this.limit = limit;
this.mark = start;

this._size = undefined;
this._timestamp = undefined;
}

_sizeCheck(nBytes) {
return this.mark + nBytes < this.limit;
}

setLimit(end) {
this.limit = end;
}

data() {
return this.array.slice(this.mark + MESSAGE_HEADER, this._endOffset);
}

get size() {
if (this._size === undefined && this._sizeCheck(4)) {
this._size = this.view.getUint32(this.mark, true);
}

return this._size;
}

get _endOffset() {
if (this.size) {
return this.mark + MESSAGE_HEADER + this.size;
}
return undefined
}

get timestamp() {
if (this._timestamp === undefined && this._sizeCheck(4 + 4)) {
this._timestamp = this.view.getUint32(this.mark + 4, true);
}

return this._timestamp;
}

available() {
if (this._endOffset) {
return this._endOffset < this.limit;
}

return false;
}

next() {
if (this.available()) {
this.mark = this._endOffset;

this._size = undefined
this._timestamp = undefined
return true;
}
return false;
}
}

0 comments on commit 258b841

Please sign in to comment.