46460d84 by Gary Katsevman

Delay fillBuffer. Upshift if dl time less than 1s.

Only set up timeupdate and waiting event listeners for fillBuffer and
drainBuffer after we have upshifted. This is so that we would download
the first segment of the new playlist if the player is setup with
autoplay or a user clicks play too early.
Also, we should only upshift if our estimated download time for the new
segment is less than one second. This is done by estimating the duration
length of the segment of the new playlist with the duration of the
current segment in the current playlist.
1 parent 9d190d3e
......@@ -109,41 +109,40 @@ videojs.Hls.prototype.handleSourceOpen = function() {
this.playlists = new videojs.Hls.PlaylistLoader(this.src_, settings.withCredentials);
this.playlists.on('loadedmetadata', videojs.bind(this, function() {
var selectedPlaylist, loaderHandler;
var selectedPlaylist, loaderHandler, newBitrate, segmentDuration,
segmentDlTime, setupEvents;
oldMediaPlaylist = this.playlists.media();
setupEvents = function() {
this.fillBuffer();
if (this.bandwidth !== this.playlists.bandwidth) {
if (this.bandwidth === undefined || this.bandwidth !== undefined && this.bandwidth < this.playlists.bandwidth) {
this.bandwidth = this.playlists.bandwidth;
// periodically check if new data needs to be downloaded or
// buffered data should be appended to the source buffer
player.on('timeupdate', videojs.bind(this, this.fillBuffer));
player.on('timeupdate', videojs.bind(this, this.drainBuffer));
player.on('waiting', videojs.bind(this, this.drainBuffer));
player.trigger('loadedmetadata');
};
oldMediaPlaylist = this.playlists.media();
this.bandwidth = this.playlists.bandwidth;
selectedPlaylist = this.selectPlaylist();
if (selectedPlaylist === oldMediaPlaylist) {
this.fillBuffer();
} else {
newBitrate = selectedPlaylist.attributes && selectedPlaylist.attributes.BANDWIDTH;
segmentDuration = oldMediaPlaylist.segments[this.mediaIndex].duration ||
oldMediaPlaylist.targetDuration;
segmentDlTime = (segmentDuration * newBitrate) / this.bandwidth;
if (segmentDlTime <= 1) {
this.playlists.media(selectedPlaylist);
loaderHandler = videojs.bind(this, function() {
this.fillBuffer();
setupEvents.call(this);
this.playlists.off('loadedplaylist', loaderHandler);
});
this.playlists.on('loadedplaylist', loaderHandler);
}
} else {
this.fillBuffer();
}
} else {
this.fillBuffer();
setupEvents.call(this);
}
player.one('play', videojs.bind(this, this.fillBuffer));
// periodically check if new data needs to be downloaded or
// buffered data should be appended to the source buffer
player.on('timeupdate', videojs.bind(this, this.fillBuffer));
player.on('timeupdate', videojs.bind(this, this.drainBuffer));
player.on('waiting', videojs.bind(this, this.drainBuffer));
player.trigger('loadedmetadata');
}));
this.playlists.on('error', videojs.bind(this, function() {
......