Search in sources :

Example 6 with FakeMediaChunk

use of com.google.android.exoplayer2.testutil.FakeMediaChunk in project ExoPlayer by google.

the class AdaptiveTrackSelectionTest method evaluateQueueSizeDoNotReevaluateUntilAfterMinTimeBetweenBufferReevaluation.

@Test
public void evaluateQueueSizeDoNotReevaluateUntilAfterMinTimeBetweenBufferReevaluation() {
    Format format1 = videoFormat(/* bitrate= */
    500, /* width= */
    320, /* height= */
    240);
    Format format2 = videoFormat(/* bitrate= */
    1000, /* width= */
    640, /* height= */
    480);
    Format format3 = videoFormat(/* bitrate= */
    2000, /* width= */
    960, /* height= */
    720);
    TrackGroup trackGroup = new TrackGroup(format1, format2, format3);
    FakeMediaChunk chunk1 = new FakeMediaChunk(format1, /* startTimeUs= */
    0, /* endTimeUs= */
    10_000_000);
    FakeMediaChunk chunk2 = new FakeMediaChunk(format1, /* startTimeUs= */
    10_000_000, /* endTimeUs= */
    20_000_000);
    FakeMediaChunk chunk3 = new FakeMediaChunk(format1, /* startTimeUs= */
    20_000_000, /* endTimeUs= */
    30_000_000);
    List<FakeMediaChunk> queue = ImmutableList.of(chunk1, chunk2, chunk3);
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
    AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMinTimeBetweenBufferReevaluationMs(trackGroup, /* durationToRetainAfterDiscardMs= */
    15_000);
    int initialQueueSize = adaptiveTrackSelection.evaluateQueueSize(0, queue);
    fakeClock.advanceTime(999);
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
    // When the bandwidth estimation is updated, we should be able to discard chunks from the end of
    // the queue. However, since the duration since the last evaluation (999ms) is less than 1000ms,
    // we will not reevaluate the queue size and should not discard chunks.
    int newSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
    0, queue);
    assertThat(newSize).isEqualTo(initialQueueSize);
    // Verify that the comment above is correct.
    fakeClock.advanceTime(1);
    newSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
    0, queue);
    assertThat(newSize).isLessThan(initialQueueSize);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeMediaChunk(com.google.android.exoplayer2.testutil.FakeMediaChunk) AdaptationCheckpoint(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) Test(org.junit.Test)

Aggregations

Format (com.google.android.exoplayer2.Format)6 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)6 FakeMediaChunk (com.google.android.exoplayer2.testutil.FakeMediaChunk)6 Test (org.junit.Test)6 AdaptationCheckpoint (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint)4