Add support for #EXT-X-BYTERANGE tag
Ports #451 to the videojs-contrib-hls development branch
Showing
1 changed file
with
27 additions
and
3 deletions
... | @@ -894,7 +894,7 @@ videojs.HlsHandler.prototype.fillBuffer = function(mediaIndex) { | ... | @@ -894,7 +894,7 @@ videojs.HlsHandler.prototype.fillBuffer = function(mediaIndex) { |
894 | // we have entered a state where we are fetching the same segment, | 894 | // we have entered a state where we are fetching the same segment, |
895 | // try to walk forward | 895 | // try to walk forward |
896 | if (this.lastSegmentLoaded_ && | 896 | if (this.lastSegmentLoaded_ && |
897 | this.lastSegmentLoaded_ === this.playlistUriToUrl(segment.uri)) { | 897 | this.lastSegmentLoaded_ === segment) { |
898 | return this.fillBuffer(mediaIndex + 1); | 898 | return this.fillBuffer(mediaIndex + 1); |
899 | } | 899 | } |
900 | 900 | ||
... | @@ -961,6 +961,29 @@ videojs.HlsHandler.prototype.playlistUriToUrl = function(segmentRelativeUrl) { | ... | @@ -961,6 +961,29 @@ videojs.HlsHandler.prototype.playlistUriToUrl = function(segmentRelativeUrl) { |
961 | return playListUrl; | 961 | return playListUrl; |
962 | }; | 962 | }; |
963 | 963 | ||
964 | /* Turns segment byterange into a string suitable for use in | ||
965 | * HTTP Range requests | ||
966 | */ | ||
967 | videojs.HlsHandler.prototype.byterangeStr = function(byterange) { | ||
968 | var byterangeStart, byterangeEnd; | ||
969 | |||
970 | // `byterangeEnd` is one less than `offset + length` because the HTTP range | ||
971 | // header uses inclusive ranges | ||
972 | byterangeEnd = byterange.offset + byterange.length - 1; | ||
973 | byterangeStart = byterange.offset; | ||
974 | return "bytes=" + byterangeStart + "-" + byterangeEnd; | ||
975 | }; | ||
976 | |||
977 | /* Defines headers for use in the xhr request for a particular segment. | ||
978 | */ | ||
979 | videojs.HlsHandler.prototype.segmentXhrHeaders = function(segment) { | ||
980 | var headers = {}; | ||
981 | if ('byterange' in segment) { | ||
982 | headers['Range'] = this.byterangeStr(segment.byterange); | ||
983 | } | ||
984 | return headers; | ||
985 | }; | ||
986 | |||
964 | /* | 987 | /* |
965 | * Sets `bandwidth`, `segmentXhrTime`, and appends to the `bytesReceived. | 988 | * Sets `bandwidth`, `segmentXhrTime`, and appends to the `bytesReceived. |
966 | * Expects an object with: | 989 | * Expects an object with: |
... | @@ -1054,7 +1077,8 @@ videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) { | ... | @@ -1054,7 +1077,8 @@ videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) { |
1054 | // Set xhr timeout to 150% of the segment duration to allow us | 1077 | // Set xhr timeout to 150% of the segment duration to allow us |
1055 | // some time to switch renditions in the event of a catastrophic | 1078 | // some time to switch renditions in the event of a catastrophic |
1056 | // decrease in network performance or a server issue. | 1079 | // decrease in network performance or a server issue. |
1057 | timeout: (segment.duration * 1.5) * 1000 | 1080 | timeout: (segment.duration * 1.5) * 1000, |
1081 | headers: this.segmentXhrHeaders(segment) | ||
1058 | }, function(error, request) { | 1082 | }, function(error, request) { |
1059 | // This is a timeout of a previously aborted segment request | 1083 | // This is a timeout of a previously aborted segment request |
1060 | // so simply ignore it | 1084 | // so simply ignore it |
... | @@ -1085,7 +1109,7 @@ videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) { | ... | @@ -1085,7 +1109,7 @@ videojs.HlsHandler.prototype.loadSegment = function(segmentInfo) { |
1085 | return; | 1109 | return; |
1086 | } | 1110 | } |
1087 | 1111 | ||
1088 | self.lastSegmentLoaded_ = segmentInfo.uri; | 1112 | self.lastSegmentLoaded_ = segment; |
1089 | self.setBandwidth(request); | 1113 | self.setBandwidth(request); |
1090 | 1114 | ||
1091 | if (segment.key) { | 1115 | if (segment.key) { | ... | ... |
-
Please register or sign in to post a comment