Skip to content

Commit

Permalink
fix: Fixes bug in trick mode stream concatenation
Browse files Browse the repository at this point in the history
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 shaka-project#3423

Change-Id: I4ca6f14879b7a5d3dae735e931d2fb1f8d1673be
  • Loading branch information
theodab committed May 25, 2021
1 parent 9709086 commit f091084
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/util/periods.js
Expand Up @@ -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.
Expand All @@ -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.<!shaka.extern.Stream>} 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f091084

Please sign in to comment.