static extendOutputStream_(
      outputStream, firstNewPeriodIndex, concat, unusedStreamsPerPeriod,
      periodsMissing) {
    const ContentType = shaka.util.ManifestParserUtils.ContentType;
    const LanguageUtils = shaka.util.LanguageUtils;
    const matches = outputStream.matchedStreams;

    // Assure the compiler that matches didn't become null during the async
    // operation before.
    goog.asserts.assert(outputStream.matchedStreams,
        'matchedStreams should be non-null');

    // Concatenate the new matches onto the stream, starting at the first new
    // period.
    const start = firstNewPeriodIndex + periodsMissing;
    for (let i = start; i < matches.length; i++) {
      const match = matches[i];
      concat(outputStream, match);

      // We only consider an audio stream "used" if its language is related to
      // the output language.  There are scenarios where we want to generate
      // separate tracks for each language, even when we are forced to connect
      // unrelated languages across periods.
      let used = true;
      if (outputStream.type == ContentType.AUDIO) {
        const relatedness = LanguageUtils.relatedness(
            outputStream.language, match.language);
        if (relatedness == 0) {
          used = false;
        }
      }

      if (used) {
        unusedStreamsPerPeriod[i - periodsMissing].delete(match);
        // Add the full mimetypes to the stream.
        if (match.fullMimeTypes) {
          for (const fullMimeType of match.fullMimeTypes.values()) {
            outputStream.fullMimeTypes.add(fullMimeType);
          }
        }
      }
    }
  }
@param {T} outputStream An existing output stream which needs to be
  extended into new periods.
@param {number} firstNewPeriodIndex An index into streamsPerPeriod which
  represents the first new period that hasn't been processed yet.
@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.
@param {number} periodsMissing How many periods are missing in this update

@template T
Accepts either a StreamDB or Stream type.

@private