Rename setBandwidthByXHR to setBandwidth
Makes the function more generic. It just accepts an object with a 'bandwidth' property.
Showing
3 changed files
with
14 additions
and
7 deletions
... | @@ -58,7 +58,7 @@ | ... | @@ -58,7 +58,7 @@ |
58 | haveMetadata = function(error, xhr, url) { | 58 | haveMetadata = function(error, xhr, url) { |
59 | var parser, refreshDelay, update; | 59 | var parser, refreshDelay, update; |
60 | 60 | ||
61 | loader.setBandwidthByXHR(request || xhr); | 61 | loader.setBandwidth(request || xhr); |
62 | 62 | ||
63 | // any in-flight request is now finished | 63 | // any in-flight request is now finished |
64 | request = null; | 64 | request = null; |
... | @@ -202,7 +202,7 @@ | ... | @@ -202,7 +202,7 @@ |
202 | }); | 202 | }); |
203 | }; | 203 | }; |
204 | 204 | ||
205 | loader.setBandwidthByXHR = function(xhr) { | 205 | loader.setBandwidth = function(xhr) { |
206 | loader.bandwidth = xhr.bandwidth; | 206 | loader.bandwidth = xhr.bandwidth; |
207 | }; | 207 | }; |
208 | 208 | ... | ... |
... | @@ -448,13 +448,20 @@ videojs.Hls.prototype.fillBuffer = function(offset) { | ... | @@ -448,13 +448,20 @@ videojs.Hls.prototype.fillBuffer = function(offset) { |
448 | this.loadSegment(segmentUri, offset); | 448 | this.loadSegment(segmentUri, offset); |
449 | }; | 449 | }; |
450 | 450 | ||
451 | // Encapsulate the setBandwidth routine for future expansion | 451 | /* |
452 | videojs.Hls.prototype.setBandwidthByXHR = function(xhr) { | 452 | * Sets `bandwidth`, `segmentXhrTime`, and appends to the `bytesReceived. |
453 | * Expects an object with: | ||
454 | * * `roundTripTime` - the round trip time for the request we're setting the time for | ||
455 | * * `bandwidth` - the bandwidth we want to set | ||
456 | * * `bytesReceived` - amount of bytes downloaded | ||
457 | * `bandwidth` is the only required property. | ||
458 | */ | ||
459 | videojs.Hls.prototype.setBandwidth = function(xhr) { | ||
453 | var tech = this; | 460 | var tech = this; |
454 | // calculate the download bandwidth | 461 | // calculate the download bandwidth |
455 | tech.segmentXhrTime = xhr.roundTripTime; | 462 | tech.segmentXhrTime = xhr.roundTripTime; |
456 | tech.bandwidth = xhr.bandwidth; | 463 | tech.bandwidth = xhr.bandwidth; |
457 | tech.bytesReceived += xhr.bytesReceived; | 464 | tech.bytesReceived += xhr.bytesReceived || 0; |
458 | }; | 465 | }; |
459 | 466 | ||
460 | videojs.Hls.prototype.loadSegment = function(segmentUri, offset) { | 467 | videojs.Hls.prototype.loadSegment = function(segmentUri, offset) { |
... | @@ -495,7 +502,7 @@ videojs.Hls.prototype.loadSegment = function(segmentUri, offset) { | ... | @@ -495,7 +502,7 @@ videojs.Hls.prototype.loadSegment = function(segmentUri, offset) { |
495 | return; | 502 | return; |
496 | } | 503 | } |
497 | 504 | ||
498 | tech.setBandwidthByXHR(this); | 505 | tech.setBandwidth(this); |
499 | 506 | ||
500 | // package up all the work to append the segment | 507 | // package up all the work to append the segment |
501 | // if the segment is the start of a timestamp discontinuity, | 508 | // if the segment is the start of a timestamp discontinuity, | ... | ... |
... | @@ -377,7 +377,7 @@ test('downloads a second media playlist before playback, if bandwidth is high', | ... | @@ -377,7 +377,7 @@ test('downloads a second media playlist before playback, if bandwidth is high', |
377 | 377 | ||
378 | standardXHRResponse(requests[0]); | 378 | standardXHRResponse(requests[0]); |
379 | 379 | ||
380 | player.hls.playlists.setBandwidthByXHR = function() { | 380 | player.hls.playlists.setBandwidth = function() { |
381 | player.hls.playlists.bandwidth = 100000; | 381 | player.hls.playlists.bandwidth = 100000; |
382 | }; | 382 | }; |
383 | 383 | ... | ... |
-
Please register or sign in to post a comment