Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/llhls query #1199

Merged
merged 6 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import {getKnownPartCount} from './playlist.js';
const { mergeOptions, EventTarget } = videojs;

const addLLHLSQueryDirectives = (uri, media) => {
if (media.endList) {
if (media.endList || !media.serverControl) {
return uri;
}
const query = [];

if (media.serverControl && media.serverControl.canBlockReload) {
const parameters = {};

if (media.serverControl.canBlockReload) {
const {preloadSegment} = media;
// next msn is a zero based value, length is not.
let nextMSN = media.mediaSequence + media.segments.length;
Expand All @@ -44,7 +45,8 @@ const addLLHLSQueryDirectives = (uri, media) => {
// and we need to add the _HLS_part= query
if (nextPart > -1 && nextPart !== (parts.length - 1)) {
// add existing parts to our preload hints
query.push(`_HLS_part=${nextPart}`);
// eslint-disable-next-line
parameters._HLS_part = nextPart;
}

// this if statement makes sure that we request the msn
Expand All @@ -62,19 +64,29 @@ const addLLHLSQueryDirectives = (uri, media) => {
}

// add _HLS_msn= in front of any _HLS_part query
query.unshift(`_HLS_msn=${nextMSN}`);
// eslint-disable-next-line
parameters._HLS_msn = nextMSN;
}

if (media.serverControl && media.serverControl.canSkipUntil) {
// add _HLS_skip= infront of all other queries.
query.unshift('_HLS_skip=' + (media.serverControl.canSkipDateranges ? 'v2' : 'YES'));
// eslint-disable-next-line
parameters._HLS_skip = (media.serverControl.canSkipDateranges ? 'v2' : 'YES');
}

query.forEach(function(str, i) {
const symbol = i === 0 ? '?' : '&';
if (Object.keys(parameters).length) {
const parsedUri = new window.URL(uri);

uri += `${symbol}${str}`;
});
['_HLS_skip', '_HLS_msn', '_HLS_part'].forEach(function(name) {
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 wanted to make sure that we keep the parameters in an expected order of skip, msn, and part as it makes reading the urls much easier.

if (!parameters.hasOwnProperty(name)) {
return;
}

parsedUri.searchParams.set(name, parameters[name]);
});

uri = parsedUri.toString();
}

return uri;
};
Expand Down Expand Up @@ -385,6 +397,11 @@ export default class PlaylistLoader extends EventTarget {
this.customTagMappers = (vhsOptions && vhsOptions.customTagMappers) || [];
this.experimentalLLHLS = (vhsOptions && vhsOptions.experimentalLLHLS) || false;

// force experimentalLLHLS for IE 11
if (videojs.browser.IE_VERSION) {
this.experimentalLLHLS = false;
}

// initialize the loader state
this.state = 'HAVE_NOTHING';

Expand Down
9 changes: 5 additions & 4 deletions test/loader-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,12 @@ export const LoaderCommonFactory = ({
this.clock.tick(1);
return Promise.resolve();
}).then(() => new Promise((resolve, reject) => {
loader.on('playlistupdate', () => {
this.clock.tick(1);
resolve();
});
loader.on('trackinfo', () => {
loader.on('playlistupdate', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixes the race condition that currently causes ie 11 to fail

this.clock.tick(1);
resolve();
});

loader.playlist(playlistWithDuration(50, {
uri: 'bar-1080.m3u8',
mediaSequence: 0,
Expand Down
Loading