async fetchAndAppendDependency_(mediaState, segmentTime, bufferingGoal) {
    const dependencyStream = mediaState.stream;
    const segmentIndex = dependencyStream.segmentIndex;
    const iterator =
        segmentIndex && segmentIndex.getIteratorForTime(segmentTime);
    let reference = iterator && iterator.next().value;

    // If the reference has already been requested, advance to the next one
    // to avoid requesting the same segment multiple times
    while (reference && this.requestedDependencySegments_.includes(
        reference.startTime)) {
      reference = iterator && iterator.next().value;
    }

    if (reference) {
      const initSegmentReference = reference.initSegmentReference;
      if (initSegmentReference && !shaka.media.InitSegmentReference.equal(
          initSegmentReference, mediaState.lastInitSegmentReference)) {
        mediaState.lastInitSegmentReference = initSegmentReference;
        try {
          const init = await this.fetch_(mediaState, initSegmentReference);
          this.playerInterface_.mediaSourceEngine.appendDependency(
              init, 0, dependencyStream);
          this.requestedDependencySegments_ = [];
        } catch (e) {
          mediaState.lastInitSegmentReference = null;
          throw e;
        }
      }
      if (!mediaState.lastSegmentReference ||
          mediaState.lastSegmentReference != reference) {
        mediaState.lastSegmentReference = reference;
        try {
          const result = await this.fetch_(mediaState, reference);
          this.playerInterface_.mediaSourceEngine.appendDependency(
              result, 0, dependencyStream);
          this.requestedDependencySegments_.push(reference.startTime);
        } catch (e) {
          mediaState.lastSegmentReference = null;
          throw e;
        }

        const newestRequestedSegment =
            Math.max(0, ...this.requestedDependencySegments_);
        const presentationTime = this.playerInterface_.getPresentationTime();

        // Prefetch dependency segments if the segments we have buffered so far
        // are behind the buffering goal
        if (presentationTime + bufferingGoal > newestRequestedSegment) {
          await this.fetchAndAppendDependency_(mediaState, reference.startTime,
              bufferingGoal);
        }
      }
    }
  }
Fetches and appends a dependency media state

@param {!shaka.media.StreamingEngine.MediaState_} mediaState
@param {number} segmentTime
@param {number} bufferingGoal
@private