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
33b4f3ac
authored
2015-04-16 16:06:06 -0400
by
David LaPalomento
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #243 from videojs/resolution-plus-one
Resolution best variant plus one.
2 parents
4624510d
8ad068fe
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
7 deletions
src/videojs-hls.js
test/videojs-hls_test.js
src/videojs-hls.js
View file @
33b4f3a
...
...
@@ -424,7 +424,9 @@ videojs.Hls.prototype.selectPlaylist = function () {
bandwidthPlaylists
=
[],
i
=
sortedPlaylists
.
length
,
variant
,
oldvariant
,
bandwidthBestVariant
,
resolutionPlusOne
,
resolutionBestVariant
;
sortedPlaylists
.
sort
(
videojs
.
Hls
.
comparePlaylistBandwidth
);
...
...
@@ -460,6 +462,7 @@ videojs.Hls.prototype.selectPlaylist = function () {
// iterate through the bandwidth-filtered playlists and find
// best rendition by player dimension
while
(
i
--
)
{
oldvariant
=
variant
;
variant
=
bandwidthPlaylists
[
i
];
// ignore playlists without resolution information
...
...
@@ -470,18 +473,29 @@ videojs.Hls.prototype.selectPlaylist = function () {
continue
;
}
// since the playlists are sorted, the first variant that has
// dimensions less than or equal to the player size is the
// best
if
(
variant
.
attributes
.
RESOLUTION
.
width
<=
player
.
width
()
&&
variant
.
attributes
.
RESOLUTION
.
height
<=
player
.
height
())
{
// dimensions less than or equal to the player size is the best
if
(
variant
.
attributes
.
RESOLUTION
.
width
===
player
.
width
()
&&
variant
.
attributes
.
RESOLUTION
.
height
===
player
.
height
())
{
// if we have the exact resolution as the player use it
resolutionPlusOne
=
null
;
resolutionBestVariant
=
variant
;
break
;
}
else
if
(
variant
.
attributes
.
RESOLUTION
.
width
<
player
.
width
()
&&
variant
.
attributes
.
RESOLUTION
.
height
<
player
.
height
())
{
// if we don't have an exact match, see if we have a good higher quality variant to use
if
(
oldvariant
.
attributes
&&
oldvariant
.
attributes
.
RESOLUTION
&&
oldvariant
.
attributes
.
RESOLUTION
.
width
&&
oldvariant
.
attributes
.
RESOLUTION
.
height
)
{
resolutionPlusOne
=
oldvariant
;
}
resolutionBestVariant
=
variant
;
break
;
}
}
// fallback chain of variants
return
resolutionBestVariant
||
bandwidthBestVariant
||
sortedPlaylists
[
0
];
return
resolution
PlusOne
||
resolution
BestVariant
||
bandwidthBestVariant
||
sortedPlaylists
[
0
];
};
/**
...
...
test/videojs-hls_test.js
View file @
33b4f3a
...
...
@@ -831,8 +831,8 @@ test('selects the correct rendition by player dimensions', function() {
playlist
=
player
.
hls
.
selectPlaylist
();
deepEqual
(
playlist
.
attributes
.
RESOLUTION
,
{
width
:
396
,
height
:
224
},
'should return the correct resolution by player dimensions'
);
equal
(
playlist
.
attributes
.
BANDWIDTH
,
440
000
,
'should have the expected bandwidth in case of multiple'
);
deepEqual
(
playlist
.
attributes
.
RESOLUTION
,
{
width
:
960
,
height
:
540
},
'should return the correct resolution by player dimensions'
);
equal
(
playlist
.
attributes
.
BANDWIDTH
,
1928
000
,
'should have the expected bandwidth in case of multiple'
);
player
.
width
(
1920
);
player
.
height
(
1080
);
...
...
@@ -843,6 +843,13 @@ test('selects the correct rendition by player dimensions', function() {
deepEqual
(
playlist
.
attributes
.
RESOLUTION
,
{
width
:
960
,
height
:
540
},
'should return the correct resolution by player dimensions'
);
equal
(
playlist
.
attributes
.
BANDWIDTH
,
1928000
,
'should have the expected bandwidth in case of multiple'
);
player
.
width
(
396
);
player
.
height
(
224
);
playlist
=
player
.
hls
.
selectPlaylist
();
deepEqual
(
playlist
.
attributes
.
RESOLUTION
,
{
width
:
396
,
height
:
224
},
'should return the correct resolution by player dimensions, if exact match'
);
equal
(
playlist
.
attributes
.
BANDWIDTH
,
440000
,
'should have the expected bandwidth in case of multiple, if exact match'
);
});
...
...
Please
register
or
sign in
to post a comment