Skip to content

Commit

Permalink
fix(HLS): Support request byterange on media playlist detection (#6629)
Browse files Browse the repository at this point in the history
Fixes #6627
  • Loading branch information
avelad committed May 17, 2024
1 parent 92c195b commit ac3797e
Showing 1 changed file with 17 additions and 9 deletions.
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];
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

0 comments on commit ac3797e

Please sign in to comment.