Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
videojs-contrib-hls
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
5aec30b9
authored
2014-10-01 12:39:23 -0700
by
Tom Johnson
Committed by
Gary Katsevman
2014-10-27 14:43:11 -0400
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
encapsultate bandwidth routine
1 parent
de317697
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
6 deletions
src/playlist-loader.js
src/videojs-hls.js
src/xhr.js
src/playlist-loader.js
View file @
5aec30b
...
...
@@ -58,6 +58,8 @@
haveMetadata
=
function
(
error
,
xhr
,
url
)
{
var
parser
,
refreshDelay
,
update
;
loader
.
bandwidth
=
request
.
bandwidth
||
xhr
.
bandwidth
;
// any in-flight request is now finished
request
=
null
;
...
...
src/videojs-hls.js
View file @
5aec30b
...
...
@@ -409,12 +409,20 @@ videojs.Hls.prototype.fillBuffer = function(offset) {
this
.
loadSegment
(
segmentUri
,
offset
);
};
// Encapsulate the setBandwidth routine for future expansion
videojs
.
Hls
.
prototype
.
setBandwidthByXHR
=
function
(
xhr
)
{
var
tech
=
this
;
// calculate the download bandwidth
tech
.
segmentXhrTime
=
xhr
.
roundTripTime
;
tech
.
bandwidth
=
xhr
.
bandwidth
;
tech
.
bytesReceived
+=
xhr
.
bytesReceived
;
};
videojs
.
Hls
.
prototype
.
loadSegment
=
function
(
segmentUri
,
offset
)
{
var
tech
=
this
,
player
=
this
.
player
(),
settings
=
player
.
options
().
hls
||
{},
startTime
=
+
new
Date
();
settings
=
player
.
options
().
hls
||
{};
// request the next segment
this
.
segmentXhr_
=
videojs
.
Hls
.
xhr
({
...
...
@@ -448,10 +456,7 @@ videojs.Hls.prototype.loadSegment = function(segmentUri, offset) {
return
;
}
// calculate the download bandwidth
tech
.
segmentXhrTime
=
(
+
new
Date
())
-
startTime
;
tech
.
bandwidth
=
(
this
.
response
.
byteLength
/
tech
.
segmentXhrTime
)
*
8
*
1000
;
tech
.
bytesReceived
+=
this
.
response
.
byteLength
;
tech
.
setBandwidthByXHR
(
this
);
// package up all the work to append the segment
// if the segment is the start of a timestamp discontinuity,
...
...
src/xhr.js
View file @
5aec30b
...
...
@@ -34,6 +34,7 @@
request
=
new
window
.
XMLHttpRequest
();
request
.
open
(
options
.
method
,
url
);
request
.
url
=
url
;
request
.
requestTime
=
new
Date
().
getTime
();
if
(
options
.
responseType
)
{
request
.
responseType
=
options
.
responseType
;
...
...
@@ -69,6 +70,13 @@
return
callback
.
call
(
this
,
true
,
url
);
}
if
(
this
.
response
)
{
this
.
responseTime
=
new
Date
().
getTime
();
this
.
roundTripTime
=
this
.
responseTime
-
this
.
requestTime
;
this
.
bytesReceived
=
this
.
response
.
byteLength
||
this
.
response
.
length
;
this
.
bandwidth
=
parseInt
((
this
.
bytesReceived
/
this
.
roundTripTime
)
*
8
*
1000
,
10
);
}
return
callback
.
call
(
this
,
false
,
url
);
};
request
.
send
(
null
);
...
...
Please
register
or
sign in
to post a comment