Skip to content

Commit

Permalink
aggregate buffers before starting to submit them to aurora
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@15711 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 25, 2017
1 parent 8a42771 commit 56d21bf
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ XpraClient.prototype._send_sound_start = function() {
}

XpraClient.prototype._sound_start_aurora = function() {
this.audio_buffers = [];
this.audio_aurora_ctx = AV.Player.fromXpraSource();
this.audio_aurora_ctx.play();
this._send_sound_start();
Expand Down Expand Up @@ -1893,14 +1894,44 @@ XpraClient.prototype._process_sound_data_aurora = function(packet) {
this.warn("audio aurora context is closed already, dropping sound buffer");
return;
}
var MIN_START_BUFFERS = 4;
var buf = packet[2];
var metadata = packet[4];
if(metadata) {
//push metadata first:
for(var i = 0; i < metadata.length; i++) {
this.audio_aurora_ctx.asset.source._on_data(Utilities.StringToUint8(metadata[i]));
//console.log("metadata", i, "length=", metadata[i].length, jQuery.type(metadata[i]), Object.prototype.toString.call(metadata[i]));
this.audio_buffers.push(Utilities.StringToUint8(metadata[i]));
}
//since we have the metadata, we should be good to go:
MIN_START_BUFFERS = 1;
}
//console.log("buffer length=", buf.length, jQuery.type(buf), Object.prototype.toString.call(buf));
this.audio_buffers.push(buf);
var ab = this.audio_buffers;
//not needed for all codecs / browsers!
if(ab.length >= MIN_START_BUFFERS || this.audio_buffers_count>0){
if (ab.length==1) {
//shortcut
buf = ab[0];
}
else {
//concatenate all pending buffers into one:
var size = 0;
for (var i=0,j=ab.length;i<j;++i) {
size += ab[i].length;
}
buf = new Uint8Array(size);
size = 0;
for (var i=0,j=ab.length;i<j;++i) {
buf.set(ab[i], size);
size += ab[i].length;
}
}
this.audio_buffers_count += 1;
this.audio_aurora_ctx.asset.source._on_data(buf);
this.audio_buffers = [];
}
this.audio_aurora_ctx.asset.source._on_data(buf);
}

XpraClient.prototype._process_sound_data_mediasource = function(packet) {
Expand Down

0 comments on commit 56d21bf

Please sign in to comment.