Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Clear the blacklist for other playlists if final rendition errors #1083

Closed
wants to merge 17 commits into from

Conversation

zhuangs
Copy link
Contributor

@zhuangs zhuangs commented Apr 11, 2017

Description

Before the behavior is we never blacklist the final request and wait up to 5 minutes for other playlists' blacklist duration to be cleared. Change the behavior as follow:

  • If there is only one rendition and it errors, never blacklist it
  • if there are multiple renditions and we are down to the last one (the previous renditions are all blacklisted) and it errors, we clear the blacklist duration for the other playlists, and retry the best available playlist after a delay.

@zhuangs zhuangs force-pushed the feature/un-blacklist-playlist branch from 3fabb71 to cbffa84 Compare April 11, 2017 22:23
@@ -1064,14 +1064,22 @@ export class MasterPlaylistController extends videojs.EventTarget {
}

let isFinalRendition = this.masterPlaylistLoader_.isFinalRendition_();
let playlists = this.tech_.hls.playlists.master.playlists;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be this.masterPlaylistLoader_.master.playlists

@zhuangs zhuangs force-pushed the feature/un-blacklist-playlist branch from b384f69 to f81badf Compare April 19, 2017 14:49
mediaUpdateTimeout = window.setTimeout(loader.media.bind(loader, playlist, false), refreshDelay);
return;
}

// setter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be moved up

'log specific error message for final playlist');
assert.equal(retryplaylist, 1, 'retried final playlist for once');
assert.equal(blacklistplaylist, 1, 'there is one blacklisted playlist');
'Problem encountered with the current HLS playlist. HLS playlist request error at URL: media1.m3u8 Switching to another playlist.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also just realized that there is no period between media1.m3u8 Switching (from before, but might be nice to fix.

@@ -1153,9 +1152,11 @@ QUnit.test('playlist 404 should blacklist media', function(assert) {
this.clock.tick(3 * 1000);
// continue loading the final remaining playlist after it wasn't blacklisted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, I think this comment might need to change

@@ -1531,13 +1532,14 @@ QUnit.test('playlist blacklisting duration is set through options', function(ass
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 takes one millisecond
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this new response need to be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the new response didn't be added here, it will error for the second(final) rendition. Since we clear blacklist duration for the first rendition when final rendition errors, we can't test if the blacklist duration is set through option successfully.

playlists.forEach((playlist) => {
// clear the blacklist duration for the other playlists when
// the final playlist errors
playlist.excludeUntil = Date.now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be clearer to delete playlist.excludeUntil for each.

@@ -1529,15 +1532,16 @@ QUnit.test('playlist blacklisting duration is set through options', function(ass
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.',
'Problem encountered with the current HLS playlist. HLS playlist request error at URL: media.m3u8. Switching to another playlist.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long line.

'Switching to another playlist.',
'log generic error message');
assert.equal(retryplaylist, 0, 'haven\'t retried any playlist');
assert.equal(blacklistplaylist, 2, 'media1 is blacklisted');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this may be true, since it's only testing that it got a blacklist event, maybe it is worth having two different checks, one for getting the blacklist event, the other checking for the excludeUntil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have that excludeUntil check in line 1141?


this.clock.tick(2 * 1000);
// no new request was made since it hasn't been half the segment duration
assert.strictEqual(3, this.requests.length, 'no new request was made');

this.clock.tick(3 * 1000);
// continue loading the final remaining playlist after it wasn't blacklisted
// loading the first playlist since the blacklist duration is cleared
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was

assert.strictEqual(4, this.requests.length, 'one more request was made');
// the first media was unblacklisted after a refresh delay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to check excludeUntil was deleted


this.tech_.trigger('retryplaylist');
return this.masterPlaylistLoader_.load(isFinalRendition);
}
if (isFinalRendition) {
playlists.forEach((playlist) => {
// clear the blacklist duration for the other playlists when
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than describing what the code is doing, it might make more sense to have a comment about the reason we are doing it. Something like Since we're on the final non-blacklisted playlist, and we're about to blacklist it, instead of erring the player or retrying this playlist, we clear out the current blacklist so the other playlists may be attempted in case any have been fixed.

media = this.player.tech_.hls.playlists.master.playlists[url];

// the first media was unblacklisted after a refresh delay
assert.ok(!media.excludeUntil, 'excludeUntil was deleted after cleared the blacklist duration for the first media');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just be removed first media from blacklist


this.tech_.trigger('retryplaylist');
return this.masterPlaylistLoader_.load(isFinalRendition);
}
if (isFinalRendition) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a warning log here with something like Clearing blacklist because last rendition is about to be blacklisted.

// Since we're on the final non-blacklisted playlist, and we're about to blacklist it,
// instead of erring the player or retrying this playlist, we clear out the current blacklist
// so the other playlists may be attempted in case any have been fixed.
videojs.log.warn('Clearing blacklist because last rendition is about to be blacklisted.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get logged for every playlist. May just want to log it once.


this.tech_.trigger('retryplaylist');
return this.masterPlaylistLoader_.load(isFinalRendition);
}
if (isFinalRendition) {
playlists.forEach((playlist) => {
// Since we're on the final non-blacklisted playlist, and we're about to blacklist it,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want this comment outside of the loop as well.

@zhuangs zhuangs force-pushed the feature/un-blacklist-playlist branch from fd5548f to f6a5b61 Compare June 16, 2017 17:47
playlists.forEach((playlist) => {
delete playlist.excludeUntil;
});
videojs.log.warn('Clearing blacklist for every playlist because last rendition ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but putting it just before the loop might be better for a couple reasons: (1) if something breaks (throws an exception) during the loop, we know the last warning log and it can help us determine what broke and (2) we already cleared everything, so Clearing might be more accurate before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Changed as suggested

@zhuangs zhuangs force-pushed the feature/un-blacklist-playlist branch from 5a70507 to b1443be Compare June 16, 2017 20:49
@andybarron
Copy link

Any updates on this PR? The blacklisting is actively affecting a project I'm working on, would love to see this fixed :)

window.clearTimeout(this.mediaUpdateTimeout);

if (isFinalRendition) {
const delay = (playlist.targetDuration / 2) * 1000 || 5 * 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we will encounter this because of when this is called with isFinalRendition === true, playlist is an object, but we support playlist being a string as you can see just below this, so it may be better to move this block below the string check

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 updated

@forbesjo
Copy link
Contributor

Let's open this against VHS

@forbesjo
Copy link
Contributor

Closing and opening against VHS in the future

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants