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: Use middle segment when guessing MIME type on HLS #4270

Merged
Changes from all 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
12 changes: 8 additions & 4 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2267,12 +2267,16 @@ shaka.hls.HlsParser = class {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const requestType = shaka.net.NetworkingEngine.RequestType.SEGMENT;

// If you wait long enough, requesting the first segment can fail
// because it has fallen off the left edge of DVR, so to be safer,
// let's request the middle segment.
goog.asserts.assert(playlist.segments.length,
'Playlist should have segments!');
const firstSegmentUri = this.variableSubstitution_(
playlist.segments[0].absoluteUri, variables);
const middleSegmentIdx = Math.trunc((playlist.segments.length - 1) / 2);
const middleSegmentUri = this.variableSubstitution_(
playlist.segments[middleSegmentIdx].absoluteUri, variables);

const parsedUri = new goog.Uri(firstSegmentUri);
const parsedUri = new goog.Uri(middleSegmentUri);
const extension = parsedUri.getPath().split('.').pop();
const map = HlsParser.EXTENSION_MAP_BY_CONTENT_TYPE_[contentType];

Expand Down Expand Up @@ -2302,7 +2306,7 @@ shaka.hls.HlsParser = class {
// If unable to guess mime type, request a segment and try getting it
// from the response.
const headRequest = shaka.net.NetworkingEngine.makeRequest(
[firstSegmentUri], this.config_.retryParameters);
[middleSegmentUri], this.config_.retryParameters);
headRequest.method = 'HEAD';

const response = await this.makeNetworkRequest_(
Expand Down