findBestMatchInPeriod_(streams, outputStream) {
    const getKey = {
      'audio': shaka.util.PeriodCombiner.generateAudioKey_,
      'video': shaka.util.PeriodCombiner.generateVideoKey_,
      'text': shaka.util.PeriodCombiner.generateTextKey_,
      'image': shaka.util.PeriodCombiner.generateImageKey_,
    }[outputStream.type];

    let best = null;
    const key = getKey(outputStream);
    if (streams.has(key)) {
      // We've found exact match by hashing.
      best = streams.get(key);
    } else {
      // We haven't found exact match, try to find the best one via
      // linear search.
      const areCompatible = {
        'audio': (os, s) => this.areAVStreamsCompatible_(os, s),
        'video': (os, s) => this.areAVStreamsCompatible_(os, s),
        'text': shaka.util.PeriodCombiner.areTextStreamsCompatible_,
        'image': shaka.util.PeriodCombiner.areImageStreamsCompatible_,
      }[outputStream.type];
      const isBetterMatch = {
        'audio': shaka.util.PeriodCombiner.isAudioStreamBetterMatch_,
        'video': shaka.util.PeriodCombiner.isVideoStreamBetterMatch_,
        'text': shaka.util.PeriodCombiner.isTextStreamBetterMatch_,
        'image': shaka.util.PeriodCombiner.isImageStreamBetterMatch_,
      }[outputStream.type];

      for (const stream of streams.values()) {
        if (!areCompatible(outputStream, stream)) {
          continue;
        }

        if (outputStream.fastSwitching != stream.fastSwitching) {
          continue;
        }

        if (!best || isBetterMatch(outputStream, best, stream)) {
          best = stream;
        }
      }
    }

    // Remove just found stream if configured to, so possible future linear
    // searches can be faster.
    if (this.useStreamOnce_ && !shaka.util.PeriodCombiner.isDummy_(best)) {
      streams.delete(getKey(best));
    }

    return best;
  }
Find the best match for the output stream.

@param {!Map<string, T>} streams
@param {T} outputStream
@return {?T}  Returns null if no match can be found.

@template T
Accepts either a StreamDB or Stream type.

@private