Skip to content

Commit

Permalink
Merge pull request #677 from CendioOssman/perf
Browse files Browse the repository at this point in the history
Support older base64 recordings
  • Loading branch information
samhed committed Oct 20, 2016
2 parents c7f2f11 + d951b40 commit a249579
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
32 changes: 23 additions & 9 deletions tests/playback.js
Expand Up @@ -9,7 +9,7 @@
/*global Util, VNC_frame_data, finish */

var rfb, mode, test_state, frame_idx, frame_length,
iteration, iterations, istart_time,
iteration, iterations, istart_time, encoding,

// Pre-declarations for jslint
send_array, next_iteration, queue_next_packet, do_packet, enable_test_mode;
Expand All @@ -20,7 +20,6 @@ send_array = function (arr) {
};

enable_test_mode = function () {
rfb._sock._mode = VNC_frame_encoding;
rfb._sock.send = send_array;
rfb._sock.close = function () {};
rfb._sock.flush = function () {};
Expand All @@ -40,6 +39,19 @@ next_iteration = function () {
'onUpdateState': updateState});
enable_test_mode();

// Missing in older recordings
if (typeof VNC_frame_encoding === 'undefined') {
var frame = VNC_frame_data[0];
var start = frame.indexOf('{', 1) + 1;
if (frame.slice(start).startsWith('UkZC')) {
encoding = 'base64';
} else {
encoding = 'binary';
}
} else {
encoding = VNC_frame_encoding;
}

if (iteration === 0) {
frame_length = VNC_frame_data.length;
test_state = 'running';
Expand Down Expand Up @@ -93,7 +105,7 @@ queue_next_packet = function () {

setTimeout(do_packet, delay);
} else {
setTimeout(do_packet, 1);
setTimeout(do_packet, 0);
}
};

Expand All @@ -103,16 +115,18 @@ do_packet = function () {
//Util.Debug("Processing frame: " + frame_idx);
var frame = VNC_frame_data[frame_idx],
start = frame.indexOf('{', 1) + 1;
bytes_processed += frame.length - start;
if (VNC_frame_encoding === 'binary') {
var u8 = new Uint8Array(frame.length - start);
var u8;
if (encoding === 'base64') {
u8 = Base64.decode(frame.slice(start));
start = 0;
} else {
u8 = new Uint8Array(frame.length - start);
for (var i = 0; i < frame.length - start; i++) {
u8[i] = frame.charCodeAt(start + i);
}
rfb._sock._recv_message({'data' : u8});
} else {
rfb._sock._recv_message({'data' : frame.slice(start)});
}
bytes_processed += u8.length;
rfb._sock._recv_message({'data' : u8});
frame_idx += 1;

queue_next_packet();
Expand Down
2 changes: 0 additions & 2 deletions tests/vnc_perf.html
Expand Up @@ -37,8 +37,6 @@

<script type="text/javascript">
var INCLUDE_URI= "../";
// TODO: Data file should override
var VNC_frame_encoding = "binary";
</script>
<script src="../core/util.js"></script>
<script src="../app/webutil.js"></script>
Expand Down
2 changes: 0 additions & 2 deletions tests/vnc_playback.html
Expand Up @@ -39,8 +39,6 @@

<script type="text/javascript">
var INCLUDE_URI= "../";
// TODO: Data file should override
var VNC_frame_encoding = "binary";
</script>
<script src="../core/util.js"></script>
<script src="../app/webutil.js"></script>
Expand Down

0 comments on commit a249579

Please sign in to comment.