From f0910842116157d71b10cd737d5f9f99354d5670 Mon Sep 17 00:00:00 2001 From: Theodore Abshire Date: Tue, 25 May 2021 01:52:00 -0700 Subject: [PATCH] fix: Fixes bug in trick mode stream concatenation When concatenating trick mode streams, at the moment, the period combiner assumes that the streams already have segment indexes. However, we never actually make those segment indexes in the period combiner, causing it to break in that situation. This modifies the period combiner to also create the segment index of a video stream's trick mode stream when creating the main segment index of the stream. Fixes #3423 Change-Id: I4ca6f14879b7a5d3dae735e931d2fb1f8d1673be --- lib/util/periods.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/util/periods.js b/lib/util/periods.js index 4a4fd1fc20..2472d1f1d9 100644 --- a/lib/util/periods.js +++ b/lib/util/periods.js @@ -573,7 +573,7 @@ shaka.util.PeriodCombiner = class { // We need to create all the per-period segment indexes and append them to // the output's MetaSegmentIndex. - await Promise.all(matches.map((match) => match.createSegmentIndex())); + await shaka.util.PeriodCombiner.createSegmentIndexes_(matches); // Assure the compiler that matches didn't become null during the async // operation above. @@ -585,6 +585,25 @@ shaka.util.PeriodCombiner = class { return true; } + /** + * Creates all segment indexes for an array of streams. Returns once every + * segment index is created. + * + * @param {!Array.} streams + * @return {!Promise} + * @private + */ + static createSegmentIndexes_(streams) { + const operations = []; + for (const stream of streams) { + operations.push(stream.createSegmentIndex()); + if (stream.trickModeVideo && !stream.trickModeVideo.segmentIndex) { + operations.push(stream.trickModeVideo.createSegmentIndex()); + } + } + return Promise.all(operations); + } + /** * Create a new output Stream based on a particular input Stream. Locates * matching Streams in all other periods and combines them into an output @@ -627,7 +646,7 @@ shaka.util.PeriodCombiner = class { if (outputStream.createSegmentIndex) { // For T == Stream, we need to create all the per-period segment indexes // in advance. concat() will add them to the output's MetaSegmentIndex. - await Promise.all(matches.map((match) => match.createSegmentIndex())); + await shaka.util.PeriodCombiner.createSegmentIndexes_(matches); } // Assure the compiler that matches didn't become null during the async