From 94fbcee23dbf49bea5d43ce12d0377e57d2b7207 Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Tue, 6 Jun 2023 16:34:07 +0200 Subject: [PATCH 1/2] feat: Improve parsing time in DASH and HLS --- lib/dash/segment_list.js | 7 +++---- lib/hls/hls_parser.js | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/dash/segment_list.js b/lib/dash/segment_list.js index 81dd7fe56f..7e3269541f 100644 --- a/lib/dash/segment_list.js +++ b/lib/dash/segment_list.js @@ -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; @@ -243,7 +240,9 @@ shaka.dash.SegmentList = class { endTime = startTime + periodDuration; } - const getUris = () => mediaUri; + const getUris = () => { + return ManifestParserUtils.resolveUris(baseUris, [segment.mediaUri]); + }; references.push( new shaka.media.SegmentReference( periodStart + startTime, diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 035dc988ea..c731039544 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -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'); @@ -2754,18 +2752,23 @@ 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; } + const getPartialUris = () => { + goog.asserts.assert(pUri, 'Partial uri should be defined!'); + const pAbsoluteUri = shaka.hls.Utils.constructAbsoluteUri( + absoluteMediaPlaylistUri, pUri); + return [pAbsoluteUri]; + }; + const partial = new shaka.media.SegmentReference( pStartTime, pEndTime, - () => [pAbsoluteUri], + getPartialUris, pStartByte, pEndByte, initSegmentReference, @@ -2829,10 +2832,16 @@ shaka.hls.HlsParser = class { } } + const getUris = () => { + const absoluteSegmentUri = this.variableSubstitution_( + hlsSegment.absoluteUri, variables); + return absoluteSegmentUri.length ? [absoluteSegmentUri] : []; + }; + return new shaka.media.SegmentReference( startTime, endTime, - () => absoluteSegmentUri.length ? [absoluteSegmentUri] : [], + getUris, startByte, endByte, initSegmentReference, From 76a1cc21295f44fc48c99171acebbed6522f6f5f Mon Sep 17 00:00:00 2001 From: Alvaro Velad Galvan Date: Wed, 7 Jun 2023 08:27:32 +0200 Subject: [PATCH 2/2] Add cache --- lib/dash/segment_list.js | 6 +++++- lib/hls/hls_parser.js | 16 +++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/dash/segment_list.js b/lib/dash/segment_list.js index 7e3269541f..9412f4d8e6 100644 --- a/lib/dash/segment_list.js +++ b/lib/dash/segment_list.js @@ -240,8 +240,12 @@ shaka.dash.SegmentList = class { endTime = startTime + periodDuration; } + let uris = null; const getUris = () => { - return ManifestParserUtils.resolveUris(baseUris, [segment.mediaUri]); + if (uris == null) { + uris = ManifestParserUtils.resolveUris(baseUris, [segment.mediaUri]); + } + return uris; }; references.push( new shaka.media.SegmentReference( diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index c731039544..d3c1245104 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -2758,10 +2758,13 @@ shaka.hls.HlsParser = class { partialStatus = shaka.media.SegmentReference.Status.MISSING; } + let pAbsoluteUri = null; const getPartialUris = () => { - goog.asserts.assert(pUri, 'Partial uri should be defined!'); - const pAbsoluteUri = shaka.hls.Utils.constructAbsoluteUri( - absoluteMediaPlaylistUri, pUri); + if (pAbsoluteUri == null) { + goog.asserts.assert(pUri, 'Partial uri should be defined!'); + pAbsoluteUri = shaka.hls.Utils.constructAbsoluteUri( + absoluteMediaPlaylistUri, pUri); + } return [pAbsoluteUri]; }; @@ -2832,9 +2835,12 @@ shaka.hls.HlsParser = class { } } + let absoluteSegmentUri = null; const getUris = () => { - const absoluteSegmentUri = this.variableSubstitution_( - hlsSegment.absoluteUri, variables); + if (absoluteSegmentUri == null) { + absoluteSegmentUri = this.variableSubstitution_( + hlsSegment.absoluteUri, variables); + } return absoluteSegmentUri.length ? [absoluteSegmentUri] : []; };