Skip to content

Commit

Permalink
feat: Improve parsing time in DASH and HLS (#5261)
Browse files Browse the repository at this point in the history
This PR improve the parsing time for DASH and HLS changing when the uris
of the segments are constructed. Now the uris are constructed on demand.
  • Loading branch information
avelad authored Jun 7, 2023
1 parent 5175e88 commit f1e35fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
11 changes: 7 additions & 4 deletions lib/dash/segment_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ shaka.dash.SegmentList = class {
let prevEndTime = info.startTime;
for (let i = 0; i < max; i++) {
const segment = info.mediaSegments[i];
const mediaUri = ManifestParserUtils.resolveUris(
baseUris, [segment.mediaUri]);

const startTime = prevEndTime;
let endTime;

Expand All @@ -243,7 +240,13 @@ shaka.dash.SegmentList = class {
endTime = startTime + periodDuration;
}

const getUris = () => mediaUri;
let uris = null;
const getUris = () => {
if (uris == null) {
uris = ManifestParserUtils.resolveUris(baseUris, [segment.mediaUri]);
}
return uris;
};
references.push(
new shaka.media.SegmentReference(
periodStart + startTime,
Expand Down
27 changes: 21 additions & 6 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2669,8 +2669,6 @@ shaka.hls.HlsParser = class {
variables, absoluteMediaPlaylistUri, type, timestampOffset,
hlsAes128Key) {
const tags = hlsSegment.tags;
const absoluteSegmentUri = this.variableSubstitution_(
hlsSegment.absoluteUri, variables);
const extinfTag =
shaka.hls.Utils.getFirstTagWithName(tags, 'EXTINF');

Expand Down Expand Up @@ -2754,18 +2752,26 @@ shaka.hls.HlsParser = class {
if (!pUri) {
continue;
}
const pAbsoluteUri = shaka.hls.Utils.constructAbsoluteUri(
absoluteMediaPlaylistUri, pUri);

let partialStatus = shaka.media.SegmentReference.Status.AVAILABLE;
if (item.getAttributeValue('GAP') == 'YES') {
partialStatus = shaka.media.SegmentReference.Status.MISSING;
}

let pAbsoluteUri = null;
const getPartialUris = () => {
if (pAbsoluteUri == null) {
goog.asserts.assert(pUri, 'Partial uri should be defined!');
pAbsoluteUri = shaka.hls.Utils.constructAbsoluteUri(
absoluteMediaPlaylistUri, pUri);
}
return [pAbsoluteUri];
};

const partial = new shaka.media.SegmentReference(
pStartTime,
pEndTime,
() => [pAbsoluteUri],
getPartialUris,
pStartByte,
pEndByte,
initSegmentReference,
Expand Down Expand Up @@ -2829,10 +2835,19 @@ shaka.hls.HlsParser = class {
}
}

let absoluteSegmentUri = null;
const getUris = () => {
if (absoluteSegmentUri == null) {
absoluteSegmentUri = this.variableSubstitution_(
hlsSegment.absoluteUri, variables);
}
return absoluteSegmentUri.length ? [absoluteSegmentUri] : [];
};

return new shaka.media.SegmentReference(
startTime,
endTime,
() => absoluteSegmentUri.length ? [absoluteSegmentUri] : [],
getUris,
startByte,
endByte,
initSegmentReference,
Expand Down

0 comments on commit f1e35fd

Please sign in to comment.