get = (type, position, mimeType, codecs, altAudioVariant = false) => {
      if (position > 50) {
        // Terminate so it doesn't go on forever when iterating over the
        // references.
        return null;
      }

      // Note that we don't just directly compute the segment position because
      // a period start time could be in the middle of the previous period's
      // last segment.
      let periodFirstPosition = 0;
      let i;
      for (i = 0; i < periodStartTimes.length; ++i) {
        const startTime = periodStartTimes[i];
        const nextStartTime = i < periodStartTimes.length - 1 ?
            periodStartTimes[i + 1] :
            presentationDuration;

        // Count up the number of segments in this period.
        const periodDuration = nextStartTime - startTime;
        const numSegments = Math.ceil(periodDuration / segmentDurations[type]);

        const nextPeriodFirstPosition = periodFirstPosition + numSegments;

        if (nextPeriodFirstPosition > position) {
          // This is the period in which we would find the requested position.
          break;
        }

        periodFirstPosition = nextPeriodFirstPosition;
      }
      if (i == periodStartTimes.length) {
        return null;
      }

      const periodIndex = i;  // 0-based
      const positionWithinPeriod = position - periodFirstPosition;

      const initSegmentUri = periodIndex + '_' + type + '_init' +
          (altAudioVariant ? '_secondaryAudioVariant' : '');

      // The type can be 'text', 'audio', 'video', or 'trickvideo',
      // but we pull video init segment metadata from the 'video' part of the
      // structure for trick-mode videos.  Here we normalize the type so that
      // 'trickvideo' becomes 'video' when we access the init segment range.
      const normalizedType = type == 'trickvideo' ? 'video' : type;
      const initRange = initSegmentRanges[normalizedType];

      let initSegmentReference = null;
      if (initRange) {
        initSegmentReference = new shaka.media.InitSegmentReference(
            () => [initSegmentUri], initRange[0], initRange[1]);
      }

      const d = segmentDurations[type];
      const getUris = () => [periodIndex + '_' + type + '_' + position +
          (altAudioVariant ? '_secondaryAudioVariant' : '')];
      const periodStart = periodStartTimes[periodIndex];
      const timestampOffset = (timestampOffsets && timestampOffsets[type]) || 0;
      const appendWindowStart = periodStartTimes[periodIndex];
      const appendWindowEnd = periodIndex == periodStartTimes.length - 1?
          presentationDuration : periodStartTimes[periodIndex + 1];

      const refKey = [periodStart,
        getUris()[0],
        timestampOffset,
        appendWindowStart,
        appendWindowEnd].join();

      let ref = getMap.get(refKey);

      if (!ref) {
        ref = new shaka.media.SegmentReference(
            /* startTime= */ periodStart + positionWithinPeriod * d,
            /* endTime= */ periodStart + (positionWithinPeriod + 1) * d,
            getUris,
            /* startByte= */ 0,
            /* endByte= */ null,
            initSegmentReference,
            timestampOffset,
            appendWindowStart,
            appendWindowEnd);
        ref.mimeType = mimeType;
        ref.codecs = codecs;
        const ContentType = shaka.util.ManifestParserUtils.ContentType;
        if (aesKey &&
            (type == ContentType.AUDIO || type == ContentType.VIDEO)) {
          ref.aesKey = aesKey;
        }
        getMap.set(refKey, ref);
      }

      return ref;
    }
@param {string} type
@param {number} position
@param {string} mimeType
@param {string} codecs
@param {boolean} altAudioVariant
@return {shaka.media.SegmentReference} A SegmentReference.