Highlight times when buffer hits zero
Place a semi-transparent rectangle over any time interval where the buffer is totally empty.
Showing
2 changed files
with
44 additions
and
2 deletions
... | @@ -432,6 +432,11 @@ form label { | ... | @@ -432,6 +432,11 @@ form label { |
432 | stroke-dasharray: 5, 5; | 432 | stroke-dasharray: 5, 5; |
433 | } | 433 | } |
434 | 434 | ||
435 | .buffer-empty { | ||
436 | fill: #e44d26; | ||
437 | opacity: 0.4; | ||
438 | } | ||
439 | |||
435 | .timeline { | 440 | .timeline { |
436 | color: #888; | 441 | color: #888; |
437 | height: 500px; | 442 | height: 500px; | ... | ... |
... | @@ -143,7 +143,7 @@ | ... | @@ -143,7 +143,7 @@ |
143 | buffered = 0, | 143 | buffered = 0, |
144 | currentTime = 0; | 144 | currentTime = 0; |
145 | 145 | ||
146 | // mock out buffered and currentTime | 146 | // simulate buffered and currentTime during playback |
147 | player.buffered = function() { | 147 | player.buffered = function() { |
148 | return videojs.createTimeRange(0, currentTime + buffered); | 148 | return videojs.createTimeRange(0, currentTime + buffered); |
149 | }; | 149 | }; |
... | @@ -204,10 +204,13 @@ | ... | @@ -204,10 +204,13 @@ |
204 | if (remaining - value.bandwidth <= 0) { | 204 | if (remaining - value.bandwidth <= 0) { |
205 | // send the response body once all bytes have been delivered | 205 | // send the response body once all bytes have been delivered |
206 | setTimeout(function() { | 206 | setTimeout(function() { |
207 | buffered += segmentDuration; | ||
208 | request.status = 200; | 207 | request.status = 200; |
209 | request.response = new Uint8Array(segmentSize * 0.125); | 208 | request.response = new Uint8Array(segmentSize * 0.125); |
210 | request.setResponseBody(''); | 209 | request.setResponseBody(''); |
210 | |||
211 | buffered += segmentDuration; | ||
212 | // update the buffered value | ||
213 | results.buffered[results.buffered.length - 1].buffered = buffered; | ||
211 | results.effectiveBandwidth.push({ | 214 | results.effectiveBandwidth.push({ |
212 | time: Math.ceil(+new Date() * 0.001), | 215 | time: Math.ceil(+new Date() * 0.001), |
213 | bandwidth: player.hls.bandwidth | 216 | bandwidth: player.hls.bandwidth |
... | @@ -368,6 +371,40 @@ | ... | @@ -368,6 +371,40 @@ |
368 | .attr('cy', function(playlist) { | 371 | .attr('cy', function(playlist) { |
369 | return y(playlist.bitrate); | 372 | return y(playlist.bitrate); |
370 | }); | 373 | }); |
374 | |||
375 | // highlight intervals when the buffer is empty | ||
376 | svg.selectAll('.buffer-empty').remove(); | ||
377 | svg.selectAll('.buffer-empty') | ||
378 | .data(data.buffered.reduce(function(result, sample) { | ||
379 | var last = result[result.length - 1]; | ||
380 | if (sample.buffered === 0) { | ||
381 | if (last && sample.time === last.end + 1) { | ||
382 | // add this sample to the interval we're accumulating | ||
383 | return result.slice(0, result.length - 1).concat({ | ||
384 | start: last.start, | ||
385 | end: sample.time | ||
386 | }); | ||
387 | } else { | ||
388 | // this sample starts a new interval | ||
389 | return result.concat({ | ||
390 | start: sample.time, | ||
391 | end: sample.time | ||
392 | }); | ||
393 | } | ||
394 | } | ||
395 | // filter out time periods where the buffer isn't empty | ||
396 | return result; | ||
397 | }, [])) | ||
398 | .enter().append('rect') | ||
399 | .attr('class', 'buffer-empty') | ||
400 | .attr('x', function(data) { | ||
401 | return x(data.start); | ||
402 | }) | ||
403 | .attr('width', function(data) { | ||
404 | return x(1 + data.end - data.start); | ||
405 | }) | ||
406 | .attr('y', 0) | ||
407 | .attr('height', y(height)); | ||
371 | }; | 408 | }; |
372 | })(); | 409 | })(); |
373 | 410 | ... | ... |
-
Please register or sign in to post a comment