class TrackSelectionUtil {

  @VisibleForTesting
  /* package */ static int[] getBitratesUsingFutureInfo(
      MediaChunkIterator[] iterators,
      Format[] formats,
      long maxDurationUs,
      @Nullable int[] bitrates) {
    int trackCount = iterators.length;
    Assertions.checkArgument(trackCount == formats.length);
    if (trackCount == 0) {
      return new int[0];
    }
    if (bitrates == null) {
      bitrates = new int[trackCount];
    }
    if (maxDurationUs == 0) {
      Arrays.fill(bitrates, Format.NO_VALUE);
      return bitrates;
    }

    int[] formatBitrates = new int[trackCount];
    float[] bitrateRatios = new float[trackCount];
    boolean needEstimateBitrate = false;
    boolean canEstimateBitrate = false;
    for (int i = 0; i < trackCount; i++) {
      int bitrate = getAverageBitrate(iterators[i], maxDurationUs);
      if (bitrate != Format.NO_VALUE) {
        int formatBitrate = formats[i].bitrate;
        formatBitrates[i] = formatBitrate;
        if (formatBitrate != Format.NO_VALUE) {
          bitrateRatios[i] = ((float) bitrate) / formatBitrate;
          canEstimateBitrate = true;
        }
      } else {
        needEstimateBitrate = true;
        formatBitrates[i] = Format.NO_VALUE;
      }
      bitrates[i] = bitrate;
    }

    if (needEstimateBitrate && canEstimateBitrate) {
      estimateBitrates(bitrates, formats, formatBitrates, bitrateRatios);
    }
    return bitrates;
  }

  private  TrackSelectionUtil();

}