Skip to content

Commit

Permalink
fix(HLS): Fix redirect management at media playlist level (#7944)
Browse files Browse the repository at this point in the history
Related to #7915
  • Loading branch information
avelad authored Jan 28, 2025
1 parent 52fb15d commit a38a810
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2438,21 +2438,11 @@ shaka.hls.HlsParser = class {
this.setFullTypeForStream_(stream);
}

const redirectUris = [];
const getUris = () => {
if (this.contentSteeringManager_ &&
verbatimMediaPlaylistUris.length > 1) {
return this.contentSteeringManager_.getLocations(streamId);
}
return redirectUris.concat(shaka.hls.Utils.constructUris(
[this.masterPlaylistUri_], verbatimMediaPlaylistUris,
this.globalVariables_));
};
const streamInfo = {
stream,
type,
redirectUris,
getUris,
redirectUris: [],
getUris: () => {},
// These values are filled out or updated after lazy-loading:
minTimestamp: 0,
maxTimestamp: 0,
Expand All @@ -2466,12 +2456,23 @@ shaka.hls.HlsParser = class {
loadedOnce: false,
};

const getUris = () => {
if (this.contentSteeringManager_ &&
verbatimMediaPlaylistUris.length > 1) {
return this.contentSteeringManager_.getLocations(streamId);
}
return streamInfo.redirectUris.concat(shaka.hls.Utils.constructUris(
[this.masterPlaylistUri_], verbatimMediaPlaylistUris,
this.globalVariables_));
};

streamInfo.getUris = getUris;

/** @param {!shaka.net.NetworkingEngine.PendingRequest} pendingRequest */
const downloadSegmentIndex = async (pendingRequest) => {
const ContentType = shaka.util.ManifestParserUtils.ContentType;

try {
const uris = streamInfo.getUris();
// Download the actual manifest.
const response = await pendingRequest.promise;
if (pendingRequest.aborted) {
Expand All @@ -2480,9 +2481,11 @@ shaka.hls.HlsParser = class {

// Record the final URI after redirects.
const responseUri = response.uri;
if (responseUri != response.originalUri &&
!uris.includes(responseUri)) {
redirectUris.push(responseUri);
if (responseUri != response.originalUri) {
const uris = streamInfo.getUris();
if (!uris.includes(responseUri)) {
streamInfo.redirectUris.push(responseUri);
}
}

// Record the redirected, final URI of this media playlist when we parse
Expand Down

0 comments on commit a38a810

Please sign in to comment.