Search in sources :

Example 1 with FakeMediaChunk

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

the class AdaptiveTrackSelectionTest method updateSelectedTrack_withQueueOfUnknownFormats_doesntThrow.

@Test
public void updateSelectedTrack_withQueueOfUnknownFormats_doesntThrow() {
    Format format1 = videoFormat(/* bitrate= */
    500, /* width= */
    320, /* height= */
    240);
    Format format2 = videoFormat(/* bitrate= */
    1000, /* width= */
    640, /* height= */
    480);
    TrackGroup trackGroup = new TrackGroup(format1, format2);
    AdaptiveTrackSelection adaptiveTrackSelection = prepareTrackSelection(prepareAdaptiveTrackSelection(trackGroup));
    Format unknownFormat = videoFormat(/* bitrate= */
    42, /* width= */
    300, /* height= */
    123);
    FakeMediaChunk chunk = new FakeMediaChunk(unknownFormat, /* startTimeUs= */
    0, /* endTimeUs= */
    2_000_000);
    List<FakeMediaChunk> queue = ImmutableList.of(chunk);
    adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
    0, /* bufferedDurationUs= */
    2_000_000, /* availableDurationUs= */
    C.TIME_UNSET, queue, createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
    assertThat(adaptiveTrackSelection.getSelectedFormat()).isAnyOf(format1, format2);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeMediaChunk(com.google.android.exoplayer2.testutil.FakeMediaChunk) Test(org.junit.Test)

Example 2 with FakeMediaChunk

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

the class AdaptiveTrackSelectionTest method evaluateQueueSizeReturnQueueSizeIfBandwidthIsNotImproved.

@Test
public void evaluateQueueSizeReturnQueueSizeIfBandwidthIsNotImproved() {
    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 = prepareAdaptiveTrackSelection(trackGroup);
    int size = adaptiveTrackSelection.evaluateQueueSize(0, queue);
    assertThat(size).isEqualTo(3);
}
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)

Example 3 with FakeMediaChunk

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

the class AdaptiveTrackSelectionTest method evaluateQueueSizeDiscardChunksLessThanOrEqualToMaximumResolution.

@Test
public void evaluateQueueSizeDiscardChunksLessThanOrEqualToMaximumResolution() {
    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(format2, /* startTimeUs= */
    0, /* endTimeUs= */
    10_000_000);
    FakeMediaChunk chunk2 = new FakeMediaChunk(format2, /* startTimeUs= */
    10_000_000, /* endTimeUs= */
    20_000_000);
    FakeMediaChunk chunk3 = new FakeMediaChunk(format2, /* startTimeUs= */
    20_000_000, /* endTimeUs= */
    30_000_000);
    FakeMediaChunk chunk4 = new FakeMediaChunk(format2, /* startTimeUs= */
    30_000_000, /* endTimeUs= */
    40_000_000);
    FakeMediaChunk chunk5 = new FakeMediaChunk(format1, /* startTimeUs= */
    40_000_000, /* endTimeUs= */
    50_000_000);
    List<FakeMediaChunk> queue = ImmutableList.of(chunk1, chunk2, chunk3, chunk4, chunk5);
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
    AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMaxResolutionToDiscard(trackGroup, /* maxWidthToDiscard= */
    320, /* maxHeightToDiscard= */
    240);
    int initialQueueSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
    0, queue);
    assertThat(initialQueueSize).isEqualTo(5);
    fakeClock.advanceTime(2000);
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(2000L);
    // When bandwidth estimation is updated and time has advanced enough, we can discard chunks at
    // the end of the queue now.
    // In this case, only chunks less than or equal to width = 320 and height = 240 are discarded.
    int newSize = adaptiveTrackSelection.evaluateQueueSize(/* playbackPositionUs= */
    0, queue);
    assertThat(newSize).isEqualTo(4);
}
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)

Example 4 with FakeMediaChunk

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

the class AdaptiveTrackSelectionTest method updateSelectedTrack_usesFormatOfLastChunkInTheQueueForSelection.

@Test
public void updateSelectedTrack_usesFormatOfLastChunkInTheQueueForSelection() {
    Format format1 = videoFormat(/* bitrate= */
    500, /* width= */
    320, /* height= */
    240);
    Format format2 = videoFormat(/* bitrate= */
    1000, /* width= */
    640, /* height= */
    480);
    TrackGroup trackGroup = new TrackGroup(format1, format2);
    AdaptiveTrackSelection adaptiveTrackSelection = new AdaptiveTrackSelection.Factory(/* minDurationForQualityIncreaseMs= */
    10_000, /* maxDurationForQualityDecreaseMs= */
    10_000, /* minDurationToRetainAfterDiscardMs= */
    25_000, /* bandwidthFraction= */
    1f).createAdaptiveTrackSelection(trackGroup, /* tracks= */
    new int[] { 0, 1 }, /* type= */
    TrackSelection.TYPE_UNSET, mockBandwidthMeter, /* adaptationCheckpoints= */
    ImmutableList.of());
    // Make initial selection.
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
    prepareTrackSelection(adaptiveTrackSelection);
    assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
    assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
    // Ensure that track selection wants to switch down due to low bandwidth.
    FakeMediaChunk chunk1 = new FakeMediaChunk(format2, /* startTimeUs= */
    0, /* endTimeUs= */
    2_000_000, C.SELECTION_REASON_INITIAL);
    FakeMediaChunk chunk2 = new FakeMediaChunk(format2, /* startTimeUs= */
    2_000_000, /* endTimeUs= */
    4_000_000, C.SELECTION_REASON_INITIAL);
    List<FakeMediaChunk> queue = ImmutableList.of(chunk1, chunk2);
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(500L);
    adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
    0, /* bufferedDurationUs= */
    4_000_000, /* availableDurationUs= */
    C.TIME_UNSET, queue, createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
    assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
    assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_ADAPTIVE);
    // Assert that an improved bandwidth selects the last chunk's format and ignores the previous
    // decision. Switching up from the previous decision wouldn't be possible yet because the
    // buffered duration is less than minDurationForQualityIncreaseMs.
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
    adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
    0, /* bufferedDurationUs= */
    4_000_000, /* availableDurationUs= */
    C.TIME_UNSET, queue, createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
    assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format2);
    assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_INITIAL);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeMediaChunk(com.google.android.exoplayer2.testutil.FakeMediaChunk) Test(org.junit.Test)

Example 5 with FakeMediaChunk

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

the class AdaptiveTrackSelectionTest method evaluateQueueSizeRetainMoreThanMinimumDurationAfterDiscard.

@Test
public void evaluateQueueSizeRetainMoreThanMinimumDurationAfterDiscard() {
    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);
    assertThat(initialQueueSize).isEqualTo(3);
    fakeClock.advanceTime(2000);
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L);
    // When bandwidth estimation is updated and time has advanced enough, we can discard chunks at
    // the end of the queue now.
    // However, since duration to retain after discard = 15 000 ms, we need to retain at least the
    // first 2 chunks
    int newSize = adaptiveTrackSelection.evaluateQueueSize(0, queue);
    assertThat(newSize).isEqualTo(2);
}
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