@Test public void getBitratesUsingFutureInfo_noIterator_returnsEmptyArray() { assertThat( TrackSelectionUtil.getBitratesUsingFutureInfo( new MediaChunkIterator[0], new Format[0], MAX_DURATION_US, null)) .hasLength(0); }
@VisibleForTesting 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; }
TrackSelectionUtil { @VisibleForTesting 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; } }
TrackSelectionUtil { @VisibleForTesting 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(); }
TrackSelectionUtil { @VisibleForTesting 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(); static @NullableType TrackSelection[] createTrackSelectionsForDefinitions(
      @NullableType Definition[] definitions,
      AdaptiveTrackSelectionFactory adaptiveTrackSelectionFactory); static DefaultTrackSelector.Parameters updateParametersWithOverride(
      DefaultTrackSelector.Parameters parameters,
      int rendererIndex,
      TrackGroupArray trackGroupArray,
      boolean isDisabled,
      @Nullable SelectionOverride override); static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs); static int[] getBitratesUsingPastAndFutureInfo(
      Format[] formats,
      List<? extends MediaChunk> queue,
      long maxPastDurationUs,
      MediaChunkIterator[] iterators,
      long maxFutureDurationUs,
      boolean useFormatBitrateAsLowerBound,
      @Nullable int[] bitrates); static int[] getFormatBitrates(Format[] formats, @Nullable int[] bitrates); }
TrackSelectionUtil { @VisibleForTesting 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(); static @NullableType TrackSelection[] createTrackSelectionsForDefinitions(
      @NullableType Definition[] definitions,
      AdaptiveTrackSelectionFactory adaptiveTrackSelectionFactory); static DefaultTrackSelector.Parameters updateParametersWithOverride(
      DefaultTrackSelector.Parameters parameters,
      int rendererIndex,
      TrackGroupArray trackGroupArray,
      boolean isDisabled,
      @Nullable SelectionOverride override); static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs); static int[] getBitratesUsingPastAndFutureInfo(
      Format[] formats,
      List<? extends MediaChunk> queue,
      long maxPastDurationUs,
      MediaChunkIterator[] iterators,
      long maxFutureDurationUs,
      boolean useFormatBitrateAsLowerBound,
      @Nullable int[] bitrates); static int[] getFormatBitrates(Format[] formats, @Nullable int[] bitrates);  }