[Spice-devel] [PATCH spice-html5] Condense the playback queue before adding to the Media Buffer.

Jeremy White jwhite at codeweavers.com
Thu Dec 15 19:06:19 UTC 2016


This helps Firefox in situations where the incoming traffic
is preventing the audio element from processing data quickly enough.

Signed-off-by: Jeremy White <jwhite at codeweavers.com>
---
 playback.js | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/playback.js b/playback.js
index 48d4cdd..5af9233 100644
--- a/playback.js
+++ b/playback.js
@@ -289,6 +289,28 @@ function handle_source_closed(e)
     p.log_err('Audio source unexpectedly closed.');
 }
 
+function condense_playback_queue(queue)
+{
+    if (queue.length == 1)
+        return queue.shift();
+
+    var len = 0;
+    var i = 0;
+    for (i = 0; i < queue.length; i++)
+        len += queue[i].byteLength;
+
+    var mb = new ArrayBuffer(len);
+    var tmp = new Uint8Array(mb);
+    len = 0;
+    for (i = 0; i < queue.length; i++)
+    {
+        tmp.set(new Uint8Array(queue[i]), len);
+        len += queue[i].byteLength;
+    }
+    queue.length = 0;
+    return mb;
+}
+
 function handle_append_buffer_done(e)
 {
     var p = this.spiceconn;
@@ -298,7 +320,7 @@ function handle_append_buffer_done(e)
 
     if (p.queue.length > 0)
     {
-        var mb = p.queue.shift();
+        var mb = condense_playback_queue(p.queue);
         playback_append_buffer(p, mb);
     }
     else
-- 
2.1.4



More information about the Spice-devel mailing list