From 97d6fd8c948ee9999de2633913d4f987f7a0f57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Tyczy=C5=84ski?= Date: Thu, 29 Aug 2024 09:04:50 +0200 Subject: [PATCH] fix(DASH): Fix creation of multiperiod trickmode streams (#7229) --- lib/util/periods.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/util/periods.js b/lib/util/periods.js index 7945c899d5..3d75ad10c9 100644 --- a/lib/util/periods.js +++ b/lib/util/periods.js @@ -890,26 +890,33 @@ shaka.util.PeriodCombiner = class { // Create a fresh output stream for trick-mode playback. output.trickModeVideo = shaka.util.PeriodCombiner.cloneStream_( input.trickModeVideo); - // TODO: fix the createSegmentIndex function for trickModeVideo. - // The trick-mode tracks in multi-period content should have trick-mode - // segment indexes whenever available, rather than only regular-mode - // segment indexes. + output.trickModeVideo.matchedStreams = []; output.trickModeVideo.createSegmentIndex = () => { - // Satisfy the compiler about the type. - goog.asserts.assert( - output.segmentIndex instanceof shaka.media.MetaSegmentIndex, - 'The stream should have a MetaSegmentIndex.'); - output.trickModeVideo.segmentIndex = output.segmentIndex.clone(); + if (output.trickModeVideo.segmentIndex) { + return Promise.resolve(); + } + const segmentIndex = new shaka.media.MetaSegmentIndex(); + goog.asserts.assert(output.trickModeVideo.matchedStreams, + 'trickmode matched streams should exist'); + for (const stream of output.trickModeVideo.matchedStreams) { + goog.asserts.assert(stream.segmentIndex, + 'trickmode segment index should exist'); + segmentIndex.appendSegmentIndex(stream.segmentIndex); + } + output.trickModeVideo.segmentIndex = segmentIndex; + return Promise.resolve(); }; } // Concatenate the trick mode input onto the trick mode output. + output.trickModeVideo.matchedStreams.push(input.trickModeVideo); shaka.util.PeriodCombiner.concatenateStreams_( output.trickModeVideo, input.trickModeVideo); } else if (output.trickModeVideo) { // We have a trick mode output, but no input from this Period. Fill it in // from the standard input Stream. + output.trickModeVideo.matchedStreams.push(input); shaka.util.PeriodCombiner.concatenateStreams_( output.trickModeVideo, input); }