Signed-off-by: Jeremy White <jwhite@xxxxxxxxxxxxxxx> --- playback.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- utils.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/playback.js b/playback.js index 36e6611..96efb08 100644 --- a/playback.js +++ b/playback.js @@ -72,6 +72,7 @@ SpicePlaybackConn.prototype.process_channel_message = function(msg) this.media_source.spiceconn = this; this.audio = document.createElement("audio"); + this.audio.spiceconn = this; this.audio.setAttribute('autoplay', true); this.audio.src = window.URL.createObjectURL(this.media_source); document.getElementById(this.parent.screen_id).appendChild(this.audio); @@ -240,6 +241,12 @@ function handle_source_open(e) p.log_err('Codec ' + SPICE_PLAYBACK_CODEC + ' not available.'); return; } + + if (PLAYBACK_DEBUG > 0) + playback_handle_event_debug.call(this, e); + + listen_for_audio_events(p); + p.source_buffer.spiceconn = p; p.source_buffer.mode = "segments"; @@ -263,9 +270,13 @@ function handle_source_closed(e) p.log_err('Audio source unexpectedly closed.'); } -function handle_append_buffer_done(b) +function handle_append_buffer_done(e) { var p = this.spiceconn; + + if (PLAYBACK_DEBUG > 1) + playback_handle_event_debug.call(this, e); + if (p.queue.length > 0) { var mb = p.queue.shift(); @@ -294,3 +305,53 @@ function playback_append_buffer(p, b) p.log_err("Error invoking appendBuffer: " + e.message); } } + +function playback_handle_event_debug(e) +{ + var p = this.spiceconn; + if (p.audio) + { + if (PLAYBACK_DEBUG > 0 || p.audio.buffered.len > 1) + console.log(p.audio.currentTime + ": event " + e.type + + dump_media_element(p.audio)); + } + + if (PLAYBACK_DEBUG > 1 && p.media_source) + console.log(" media_source " + dump_media_source(p.media_source)); + + if (PLAYBACK_DEBUG > 1 && p.source_buffer) + console.log(" source_buffer " + dump_source_buffer(p.source_buffer)); + + if (PLAYBACK_DEBUG > 0 || p.queue.length > 1) + console.log(' queue len ' + p.queue.length + '; append_okay: ' + p.append_okay); +} + +function playback_debug_listen_for_one_event(name) +{ + this.addEventListener(name, playback_handle_event_debug); +} + +function listen_for_audio_events(spiceconn) +{ + var audio_0_events = [ + "abort", "error" + ]; + + var audio_1_events = [ + "loadstart", "suspend", "emptied", "stalled", "loadedmetadata", "loadeddata", "canplay", + "canplaythrough", "playing", "waiting", "seeking", "seeked", "ended", "durationchange", + "timeupdate", "play", "pause", "ratechange" + ]; + + var audio_2_events = [ + "progress", + "resize", + "volumechange" + ]; + + audio_0_events.forEach(playback_debug_listen_for_one_event, spiceconn.audio); + if (PLAYBACK_DEBUG > 0) + audio_1_events.forEach(playback_debug_listen_for_one_event, spiceconn.audio); + if (PLAYBACK_DEBUG > 1) + audio_2_events.forEach(playback_debug_listen_for_one_event, spiceconn.audio); +} diff --git a/utils.js b/utils.js index 44f9679..2583666 100644 --- a/utils.js +++ b/utils.js @@ -264,3 +264,56 @@ function keycode_to_end_scan(code) return 0x80e0 | ((scancode - 0x100) << 8); } } + +function dump_media_element(m) +{ + var ret = + "[networkState " + m.networkState + + "|readyState " + m.readyState + + "|error " + m.error + + "|seeking " + m.seeking + + "|duration " + m.duration + + "|paused " + m.paused + + "|ended " + m.error + + "|buffered " + dump_timerange(m.buffered) + + "]"; + return ret; +} + +function dump_media_source(ms) +{ + var ret = + "[duration " + ms.duration + + "|readyState " + ms.readyState + "]"; + return ret; +} + +function dump_source_buffer(sb) +{ + var ret = + "[appendWindowStart " + sb.appendWindowStart + + "|appendWindowEnd " + sb.appendWindowEnd + + "|buffered " + dump_timerange(sb.buffered) + + "|timeStampOffset " + sb.timeStampOffset + + "|updating " + sb.updating + + "]"; + return ret; +} + +function dump_timerange(tr) +{ + var ret; + + if (tr) + { + var i = tr.length; + ret = "{len " + i; + if (i > 0) + ret += "; start " + tr.start(0) + "; end " + tr.end(i - 1); + ret += "}"; + } + else + ret = "N/A"; + + return ret; +} -- 2.1.4 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel