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(HLS): Support request byterange on media playlist detection #6629

Merged
merged 1 commit into from
May 17, 2024
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
26 changes: 17 additions & 9 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -928,13 +928,12 @@ shaka.hls.HlsParser = class {
if (!playlist.segments.length) {
return defaultBasicInfo;
}
const middleSegmentIdx = Math.trunc((playlist.segments.length - 1) / 2);
const middleSegment = playlist.segments[middleSegmentIdx];
const middleSegmentUris = shaka.hls.Utils.constructSegmentUris(
const firstSegment = playlist.segments[0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

The change in which we started looking for a segment in the middle of the playlist, instead of the first one, was originally written by you.
In all honesty I don't remember why we were doing it before. I suppose I'll have to take your word that it is no longer necessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not really necessary anymore and it also causes problems with byterange (we would have to look at all the previous segments to calculate the range).

const firstSegmentUris = shaka.hls.Utils.constructSegmentUris(
getUris(),
playlist.segments[0].verbatimSegmentUri);
const middleSegmentUri = middleSegmentUris[0];
const parsedUri = new goog.Uri(middleSegmentUri);
firstSegment.verbatimSegmentUri);
const firstSegmentUri = firstSegmentUris[0];
const parsedUri = new goog.Uri(firstSegmentUri);
const extension = parsedUri.getPath().split('.').pop();
const rawMimeType = HlsParser.RAW_FORMATS_TO_MIME_TYPES_[extension];
if (rawMimeType) {
Expand All @@ -946,7 +945,7 @@ shaka.hls.HlsParser = class {

let initData = null;
const initSegmentRef = this.getInitSegmentReference_(
playlist, middleSegment.tags, getUris);
playlist, firstSegment.tags, getUris);
this.mapTagToInitSegmentRefMap_.clear();
if (initSegmentRef) {
const initSegmentRequest = shaka.util.Networking.createSegmentRequest(
Expand All @@ -961,8 +960,17 @@ shaka.hls.HlsParser = class {
initData = initResponse.data;
}

const segmentRequest = shaka.net.NetworkingEngine.makeRequest(
middleSegmentUris, this.config_.retryParameters);
let startByte = 0;
let endByte = null;
const byterangeTag = shaka.hls.Utils.getFirstTagWithName(
firstSegment.tags, 'EXT-X-BYTERANGE');
if (byterangeTag) {
[startByte, endByte] = this.parseByteRange_(
/* previousReference= */ null, byterangeTag.value);
}

const segmentRequest = shaka.util.Networking.createSegmentRequest(
firstSegmentUris, startByte, endByte, this.config_.retryParameters);
const type = shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT;
const response = await this.makeNetworkRequest_(
segmentRequest, requestType, {type});
Expand Down
Loading