From 53d6378bac540af8e69522d1e22887b56b598bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 22 Jun 2023 12:49:26 +0200 Subject: [PATCH] feat(HLS): Optimize LL-HLS with byterange (#5342) - Mark the the full segment as preload if it has some partial preload segment - Request _HLS_part=0 when using LL-HLS byterange optimization --- lib/hls/hls_parser.js | 9 +++++++++ test/hls/hls_live_unit.js | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 277f7e8615..35451eb4d1 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -2360,6 +2360,9 @@ shaka.hls.HlsParser = class { const partialReferences = lastSegment.partialReferences; if (!lastSegment.partialReferences.length) { nextMediaSequence++; + if (lastSegment.hasByterangeOptimization()) { + nextPart = 0; + } return { nextMediaSequence, nextPart, @@ -2844,6 +2847,7 @@ shaka.hls.HlsParser = class { let segmentWithByteRangeOptimization = false; let getUrisOptimization = null; let somePartialSegmentWithGap = false; + let isPreloadSegment = false; if (this.lowLatencyMode_ && hlsSegment.partialSegments.length) { const byterangeOptimizationSupport = (mimeType == 'video/mp4' || @@ -2937,6 +2941,7 @@ shaka.hls.HlsParser = class { hlsAes128Key); if (item.name == 'EXT-X-PRELOAD-HINT') { partial.markAsPreload(); + isPreloadSegment = true; } // The spec doesn't say that we can assume INDEPENDENT=YES for the // first partial segment. It does call the flag "optional", though, and @@ -3043,6 +3048,10 @@ shaka.hls.HlsParser = class { if (segmentWithByteRangeOptimization) { reference.markAsByterangeOptimization(); + + if (isPreloadSegment) { + reference.markAsPreload(); + } } return reference; diff --git a/test/hls/hls_live_unit.js b/test/hls/hls_live_unit.js index 7e867ec33b..de6279371c 100644 --- a/test/hls/hls_live_unit.js +++ b/test/hls/hls_live_unit.js @@ -722,6 +722,7 @@ describe('HlsParser live', () => { /* baseUri= */ '', /* startByte= */ 0, /* endByte= */ null, /* timestampOffset= */ 0); ref2.markAsByterangeOptimization(); + ref2.markAsPreload(); await testInitialManifest(master, mediaWithPartialSegments, [ref, ref2]);