@Test public void getAverageBitrate_firstChunkLengthUnset_returnsNoValue() { long[] chunkTimeBoundariesSec = {0, 5, 15, 30}; long[] chunkLengths = {C.LENGTH_UNSET, 20, 30}; FakeMediaChunkIterator iterator = new FakeMediaChunkIterator(chunkTimeBoundariesSec, chunkLengths); assertThat(TrackSelectionUtil.getAverageBitrate(iterator, MAX_DURATION_US)) .isEqualTo(Format.NO_VALUE); }
public static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs) { long totalDurationUs = 0; long totalLength = 0; while (iterator.next()) { long chunkLength = iterator.getDataSpec().length; if (chunkLength == C.LENGTH_UNSET) { break; } long chunkDurationUs = iterator.getChunkEndTimeUs() - iterator.getChunkStartTimeUs(); if (totalDurationUs + chunkDurationUs >= maxDurationUs) { totalLength += chunkLength * (maxDurationUs - totalDurationUs) / chunkDurationUs; totalDurationUs = maxDurationUs; break; } totalDurationUs += chunkDurationUs; totalLength += chunkLength; } return totalDurationUs == 0 ? Format.NO_VALUE : (int) (totalLength * C.BITS_PER_BYTE * C.MICROS_PER_SECOND / totalDurationUs); }
TrackSelectionUtil { public static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs) { long totalDurationUs = 0; long totalLength = 0; while (iterator.next()) { long chunkLength = iterator.getDataSpec().length; if (chunkLength == C.LENGTH_UNSET) { break; } long chunkDurationUs = iterator.getChunkEndTimeUs() - iterator.getChunkStartTimeUs(); if (totalDurationUs + chunkDurationUs >= maxDurationUs) { totalLength += chunkLength * (maxDurationUs - totalDurationUs) / chunkDurationUs; totalDurationUs = maxDurationUs; break; } totalDurationUs += chunkDurationUs; totalLength += chunkLength; } return totalDurationUs == 0 ? Format.NO_VALUE : (int) (totalLength * C.BITS_PER_BYTE * C.MICROS_PER_SECOND / totalDurationUs); } }
TrackSelectionUtil { public static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs) { long totalDurationUs = 0; long totalLength = 0; while (iterator.next()) { long chunkLength = iterator.getDataSpec().length; if (chunkLength == C.LENGTH_UNSET) { break; } long chunkDurationUs = iterator.getChunkEndTimeUs() - iterator.getChunkStartTimeUs(); if (totalDurationUs + chunkDurationUs >= maxDurationUs) { totalLength += chunkLength * (maxDurationUs - totalDurationUs) / chunkDurationUs; totalDurationUs = maxDurationUs; break; } totalDurationUs += chunkDurationUs; totalLength += chunkLength; } return totalDurationUs == 0 ? Format.NO_VALUE : (int) (totalLength * C.BITS_PER_BYTE * C.MICROS_PER_SECOND / totalDurationUs); } private  TrackSelectionUtil(); }
TrackSelectionUtil { public static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs) { long totalDurationUs = 0; long totalLength = 0; while (iterator.next()) { long chunkLength = iterator.getDataSpec().length; if (chunkLength == C.LENGTH_UNSET) { break; } long chunkDurationUs = iterator.getChunkEndTimeUs() - iterator.getChunkStartTimeUs(); if (totalDurationUs + chunkDurationUs >= maxDurationUs) { totalLength += chunkLength * (maxDurationUs - totalDurationUs) / chunkDurationUs; totalDurationUs = maxDurationUs; break; } totalDurationUs += chunkDurationUs; totalLength += chunkLength; } return totalDurationUs == 0 ? Format.NO_VALUE : (int) (totalLength * C.BITS_PER_BYTE * C.MICROS_PER_SECOND / totalDurationUs); } 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 { public static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs) { long totalDurationUs = 0; long totalLength = 0; while (iterator.next()) { long chunkLength = iterator.getDataSpec().length; if (chunkLength == C.LENGTH_UNSET) { break; } long chunkDurationUs = iterator.getChunkEndTimeUs() - iterator.getChunkStartTimeUs(); if (totalDurationUs + chunkDurationUs >= maxDurationUs) { totalLength += chunkLength * (maxDurationUs - totalDurationUs) / chunkDurationUs; totalDurationUs = maxDurationUs; break; } totalDurationUs += chunkDurationUs; totalLength += chunkLength; } return totalDurationUs == 0 ? Format.NO_VALUE : (int) (totalLength * C.BITS_PER_BYTE * C.MICROS_PER_SECOND / totalDurationUs); } 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);  }