From 7a45a57d639f254dd8ed78a43dadd2494860a587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 24 Oct 2024 10:00:36 +0200 Subject: [PATCH] fix(MSS): Fix timeline repetitions (#7484) Fixes https://github.com/shaka-project/shaka-player/issues/7483 --- lib/mss/mss_parser.js | 6 ++++++ test/mss/mss_parser_unit.js | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/mss/mss_parser.js b/lib/mss/mss_parser.js index e259cc406c..940e5df16b 100644 --- a/lib/mss/mss_parser.js +++ b/lib/mss/mss_parser.js @@ -954,6 +954,12 @@ shaka.mss.MssParser = class { let startTime = t != null ? t : lastEndTime; let repeat = r || 0; + // Unlike in DASH, in MSS r does not start counting repetitions at 0 but + // at 1, to maintain the code equivalent to DASH if r exists we + // subtract 1. + if (repeat) { + repeat--; + } if (repeat < 0) { if (next) { const nextStartTime = diff --git a/test/mss/mss_parser_unit.js b/test/mss/mss_parser_unit.js index 699f31bb0e..8ab210ed1e 100644 --- a/test/mss/mss_parser_unit.js +++ b/test/mss/mss_parser_unit.js @@ -256,6 +256,27 @@ describe('MssParser Manifest', () => { expect(stream).toBeUndefined(); }); + it('support for repetitions', async () => { + const manifestText = [ + '', + ' ', + ' ', + ' ', + ' ', + '', + ].join('\n'); + + fakeNetEngine.setResponseText('dummy://foo', manifestText); + + const manifest = await parser.start('dummy://foo', playerInterface); + expect(manifest.variants.length).toBe(1); + await manifest.variants[0].audio.createSegmentIndex(); + const segmentIndex = manifest.variants[0].audio.segmentIndex; + expect(segmentIndex.getNumReferences()).toBe(12); + }); + it('generate a fake init segment', async () => { const manifestText = [ '',