createNewOutputStream_(
      stream, streamsPerPeriod, clone, concat, unusedStreamsPerPeriod) {
    // Check do we want to create output stream from dummy stream
    // and if so, return quickly.
    if (shaka.util.PeriodCombiner.isDummy_(stream)) {
      return null;
    }
    // Start by cloning the stream without segments, key IDs, etc.
    const outputStream = clone(stream);

    // Find best-matching streams in all periods.
    this.findMatchesInAllPeriods_(streamsPerPeriod, outputStream);

    // This only exists where T == Stream.
    if (outputStream.createSegmentIndex) {
      // Override the createSegmentIndex function of the outputStream.
      outputStream.createSegmentIndex = async () => {
        if (!outputStream.segmentIndex) {
          outputStream.segmentIndex = new shaka.media.MetaSegmentIndex();
          await shaka.util.PeriodCombiner.extendOutputSegmentIndex_(
              outputStream, /* firstNewPeriodIndex= */ 0);
        }
      };
      // For T == Stream, we need to create all the per-period segment indexes
      // in advance.  concat() will add them to the output's MetaSegmentIndex.
    }

    if (!outputStream.matchedStreams || !outputStream.matchedStreams.length) {
      // This is not a stream we can build output from, but it may become part
      // of another output based on another period's stream.
      return null;
    }
    shaka.util.PeriodCombiner.extendOutputStream_(outputStream,
        /* firstNewPeriodIndex= */ 0, concat, unusedStreamsPerPeriod,
        /* periodsMissing= */ 0);

    return outputStream;
  }
Create a new output Stream based on a particular input Stream.  Locates
matching Streams in all other periods and combines them into an output
Stream.
Templatized to handle both DASH Streams and offline StreamDBs.

@param {T} stream An input stream on which to base the output stream.
@param {!Array<!Map<string, T>>} streamsPerPeriod A list of maps of Streams
  from each period.
@param {function(T):T} clone Make a clone of an input stream.
@param {function(T, T)} concat Concatenate the second stream onto the end
  of the first.
@param {!Array<!Set<T>>} unusedStreamsPerPeriod An array of sets of
  unused streams from each period.

@return {?T} A newly-created output Stream, or null if matches
  could not be found.`

@template T
Accepts either a StreamDB or Stream type.

@private