Skip to content

Commit

Permalink
#20 count decode time from the moment we process the draw packet
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Oct 25, 2021
1 parent 558bbe2 commit c5e6415
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
21 changes: 11 additions & 10 deletions html5/js/Client.js
Expand Up @@ -425,7 +425,7 @@ XpraClient.prototype.initialize_workers = function() {
decode_worker.addEventListener('message', function(e) {
const data = e.data;
if (data['draw']) {
me.do_process_draw(data['draw']);
me.do_process_draw(data['draw'], data['start']);
return;
}
if (data['error']) {
Expand Down Expand Up @@ -2881,6 +2881,7 @@ XpraClient.prototype._process_draw = function(packet, ctx) {
const coding = packet[6];
let img_data = packet[7];
const raw_buffers = [];
const now = Utilities.monotonicTime();
if (coding!="scroll") {
if (!(img_data instanceof Uint8Array)) {
//the legacy bencoder can give us a string here
Expand All @@ -2890,16 +2891,16 @@ XpraClient.prototype._process_draw = function(packet, ctx) {
raw_buffers.push(img_data.buffer);
}
if (ctx.decode_worker) {
ctx.decode_worker.postMessage({'cmd': 'decode', 'packet' : packet}, raw_buffers);
ctx.decode_worker.postMessage({'cmd': 'decode', 'packet' : packet, 'start' : now}, raw_buffers);
//the worker draw event will call do_process_draw
}
else {
ctx.do_process_draw(packet);
ctx.do_process_draw(packet, now);
}
}

XpraClient.prototype._process_eos = function(packet, ctx) {
ctx.do_process_draw(packet);
ctx.do_process_draw(packet, 0);
const wid = packet[1];
ctx.decode_worker_eos(wid);
};
Expand Down Expand Up @@ -2948,10 +2949,11 @@ XpraClient.prototype.do_send_damage_sequence = function(packet_sequence, wid, wi
if (!protocol) {
return;
}
protocol.send(["damage-sequence", packet_sequence, wid, width, height, decode_time, message]);
const packet = ["damage-sequence", packet_sequence, wid, width, height, decode_time, message];
protocol.send(packet);
}

XpraClient.prototype.do_process_draw = function(packet) {
XpraClient.prototype.do_process_draw = function(packet, start) {
if(!packet){
//no valid draw packet, likely handle errors for that here
return;
Expand All @@ -2967,8 +2969,7 @@ XpraClient.prototype.do_process_draw = function(packet) {
return;
}

const start = Utilities.monotonicTime(),
x = packet[2],
const x = packet[2],
y = packet[3],
width = packet[4],
height = packet[5],
Expand Down Expand Up @@ -3002,11 +3003,11 @@ XpraClient.prototype.do_process_draw = function(packet) {
if(flush==0) {
me.request_redraw(win);
}
if (error) {
if (error || start==0) {
me.request_redraw(win);
}
else {
decode_time = Math.round(Utilities.monotonicTime() - start);
decode_time = 1000*Math.round(Utilities.monotonicTime() - start);
}
me.debug("draw", "decode time for ", coding, " sequence ", packet_sequence, ": ", decode_time, ", flush=", flush);
send_damage_sequence(decode_time, error || "");
Expand Down
12 changes: 6 additions & 6 deletions html5/js/DecodeWorker.js
Expand Up @@ -105,13 +105,13 @@ function decode_eos(wid) {
}
}

function decode_draw_packet(packet) {
function decode_draw_packet(packet, start) {
const wid = packet[1],
width = packet[4],
height = packet[5],
coding = packet[6],
packet_sequence = packet[8];
//console.log("packet to decode:", data.packet);
//console.log("decode worker sequence "+packet_sequence+": start="+start);
function send_back(raw_buffers) {
//console.log("send_back: wid_hold=", wid_hold);
const wid_hold = on_hold.get(wid);
Expand All @@ -131,13 +131,13 @@ function decode_draw_packet(packet) {
}
}
}
self.postMessage({'draw': packet}, raw_buffers);
do_send_back(packet, raw_buffers);
}
function do_send_back(p, raw_buffers) {
self.postMessage({'draw': p}, raw_buffers);
self.postMessage({'draw': p, 'start' : start}, raw_buffers);
}
function decode_error(msg) {
self.postMessage({'error': ""+msg, 'packet' : packet});
self.postMessage({'error': ""+msg, 'packet' : packet, 'start' : start});
}

function hold() {
Expand Down Expand Up @@ -344,7 +344,7 @@ onmessage = function(e) {
decode_eos(data.wid);
break;
case 'decode':
decode_draw_packet(data.packet);
decode_draw_packet(data.packet, data.start);
break
default:
console.error("decode worker got unknown message: "+data.cmd);
Expand Down

0 comments on commit c5e6415

Please sign in to comment.