Browse Source

Add option to modify blacklist duration (#1076)

pull/6/head
zhuangs 8 years ago
committed by Matthew Neil
parent
commit
eaf6b817c6
  1. 10
      README.md
  2. 9
      src/master-playlist-controller.js
  3. 4
      src/videojs-contrib-hls.js
  4. 42
      test/videojs-contrib-hls.test.js

10
README.md

@ -32,6 +32,7 @@ Maintenance Status: Stable
- [withCredentials](#withcredentials)
- [useCueTags](#usecuetags)
- [overrideNative](#overridenative)
- [blacklistDuration](#blacklistduration)
- [Runtime Properties](#runtime-properties)
- [hls.playlists.master](#hlsplaylistsmaster)
- [hls.playlists.media](#hlsplaylistsmedia)
@ -273,6 +274,15 @@ is true, if the platform supports Media Source Extensions
videojs-contrib-hls will take over HLS playback to provide a more
consistent experience.
##### blacklistDuration
* Type: `Number`
* can be used as an initialization option
When the `blacklistDuration` property is set to a time duration in seconds,
if a playlist is blacklisted, it will be blacklisted for a period of that
customized duration. This enables the blacklist duration to be configurable
by the user.
__NOTE__: If you use this option, you must also set
`videojs.options.html5.nativeAudioTracks` and
`videojs.options.html5.nativeVideoTracks` to

9
src/master-playlist-controller.js

@ -12,8 +12,6 @@ import { translateLegacyCodecs } from 'videojs-contrib-media-sources/es5/codec-u
import worker from 'webworkify';
import Decrypter from './decrypter-worker';
// 5 minute blacklist
const BLACKLIST_DURATION = 5 * 60 * 1000;
let Hls;
// SegmentLoader stats that need to have each loader's
@ -212,7 +210,8 @@ export class MasterPlaylistController extends videojs.EventTarget {
tech,
bandwidth,
externHls,
useCueTags
useCueTags,
blacklistDuration
} = options;
if (!url) {
@ -226,6 +225,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
this.hls_ = tech.hls;
this.mode_ = mode;
this.useCueTags_ = useCueTags;
this.blacklistDuration = blacklistDuration;
if (this.useCueTags_) {
this.cueTagsTrack_ = this.tech_.addTextTrack('metadata',
'ad-cues');
@ -1073,11 +1073,10 @@ export class MasterPlaylistController extends videojs.EventTarget {
return this.masterPlaylistLoader_.load(isFinalRendition);
}
// Blacklist this playlist
currentPlaylist.excludeUntil = Date.now() + BLACKLIST_DURATION;
currentPlaylist.excludeUntil = Date.now() + this.blacklistDuration * 1000;
// Select a new playlist
nextPlaylist = this.selectPlaylist();
videojs.log.warn('Problem encountered with the current HLS playlist.' +
(error.message ? ' ' + error.message : '') +
' Switching to another playlist.');

4
src/videojs-contrib-hls.js

@ -388,6 +388,10 @@ class HlsHandler extends Component {
// defaults
this.options_.withCredentials = this.options_.withCredentials || false;
if (typeof this.options_.blacklistDuration !== 'number') {
this.options_.blacklistDuration = 5 * 60;
}
// start playlist selection at a reasonable bandwidth for
// broadband internet
// 0.5 MB/s

42
test/videojs-contrib-hls.test.js

@ -1490,6 +1490,48 @@ QUnit.test('the withCredentials option overrides the global default', function(a
videojs.options.hls = hlsOptions;
});
QUnit.test('playlist blacklisting duration is set through options', function(assert) {
let hlsOptions = videojs.options.hls;
let url;
let media;
this.player.dispose();
videojs.options.hls = {
blacklistDuration: 3 * 60
};
this.player = createPlayer();
this.player.src({
src: 'http://example.com/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
this.player.tech_.triggerReady();
openMediaSource(this.player, this.clock);
this.requests[0].respond(200, null,
'#EXTM3U\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1000\n' +
'media.m3u8\n' +
'#EXT-X-STREAM-INF:BANDWIDTH=1\n' +
'media1.m3u8\n');
this.requests[1].respond(404);
// media
url = this.requests[1].url.slice(this.requests[1].url.lastIndexOf('/') + 1);
media = this.player.tech_.hls.playlists.master.playlists[url];
assert.ok(media.excludeUntil > 0, 'original media blacklisted for some time');
assert.equal(this.env.log.warn.calls, 1, 'warning logged for blacklist');
assert.equal(this.env.log.warn.args[0],
'Problem encountered with the current HLS playlist. HLS playlist request error at URL: media.m3u8 Switching to another playlist.',
'log generic error message');
this.clock.tick(2 * 60 * 1000);
assert.ok(media.excludeUntil - Date.now() > 0, 'original media still be blacklisted');
this.clock.tick(1 * 60 * 1000);
assert.equal(media.excludeUntil, Date.now(), 'media\'s exclude time reach to the current time');
assert.equal(this.env.log.warn.calls, 3, 'warning logged for blacklist');
videojs.options.hls = hlsOptions;
});
QUnit.test('if mode global option is used, mode is set to global option', function(assert) {
let hlsOptions = videojs.options.hls;

Loading…
Cancel
Save