Search in sources :

Example 66 with Format

use of com.google.android.exoplayer2.Format 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 67 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints.

@Test
public void builderCreateTrackSelections_withMultipleAdaptiveGroups_usesCorrectAdaptationCheckpoints() {
    Format group1Format1 = new Format.Builder().setAverageBitrate(500).build();
    Format group1Format2 = new Format.Builder().setAverageBitrate(1000).build();
    Format group2Format1 = new Format.Builder().setAverageBitrate(250).build();
    Format group2Format2 = new Format.Builder().setAverageBitrate(500).build();
    Format group2Format3 = new Format.Builder().setAverageBitrate(1250).build();
    Format group2UnusedFormat = new Format.Builder().setAverageBitrate(2000).build();
    Format fixedFormat = new Format.Builder().setAverageBitrate(5000).build();
    TrackGroup trackGroup1 = new TrackGroup(group1Format1, group1Format2);
    TrackGroup trackGroup2 = new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat);
    TrackGroup fixedGroup = new TrackGroup(fixedFormat);
    Definition definition1 = new Definition(trackGroup1, /* tracks...= */
    0, 1);
    Definition definition2 = new Definition(trackGroup2, /* tracks...= */
    0, 1, 2);
    Definition fixedDefinition = new Definition(fixedGroup, /* tracks...= */
    0);
    List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
    AdaptiveTrackSelection.Factory factory = new AdaptiveTrackSelection.Factory() {

        @Override
        protected AdaptiveTrackSelection createAdaptiveTrackSelection(TrackGroup group, int[] tracks, int type, BandwidthMeter bandwidthMeter, ImmutableList<AdaptationCheckpoint> adaptationCheckpoints) {
            checkPoints.add(adaptationCheckpoints);
            return super.createAdaptiveTrackSelection(group, tracks, TrackSelection.TYPE_UNSET, bandwidthMeter, adaptationCheckpoints);
        }
    };
    Timeline timeline = new FakeTimeline();
    factory.createTrackSelections(new Definition[] { null, definition1, fixedDefinition, definition2, null }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0)), timeline);
    assertThat(checkPoints).hasSize(2);
    assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1000), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2000)).inOrder();
    assertThat(checkPoints.get(1)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    5750, /* allocatedBandwidth= */
    250), new AdaptationCheckpoint(/* totalBandwidth= */
    6000, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    500), new AdaptationCheckpoint(/* totalBandwidth= */
    7250, /* allocatedBandwidth= */
    1250), new AdaptationCheckpoint(/* totalBandwidth= */
    9500, /* allocatedBandwidth= */
    2500)).inOrder();
}
Also used : AdaptationCheckpoint(com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint) ImmutableList(com.google.common.collect.ImmutableList) Definition(com.google.android.exoplayer2.trackselection.ExoTrackSelection.Definition) ArrayList(java.util.ArrayList) Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) Format(com.google.android.exoplayer2.Format) MediaSource(com.google.android.exoplayer2.source.MediaSource) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) BandwidthMeter(com.google.android.exoplayer2.upstream.BandwidthMeter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 68 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class AdaptiveTrackSelectionTest method updateSelectedTrackSwitchDownIfNotBufferedEnough.

@Test
public void updateSelectedTrackSwitchDownIfNotBufferedEnough() {
    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);
    // The second measurement onward returns 500L, which prompts the track selection to switch down
    // if necessary.
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 500L);
    AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(trackGroup, /* maxDurationForQualityDecreaseMs= */
    25_000);
    adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
    0, /* bufferedDurationUs= */
    24_999_000, /* availableDurationUs= */
    C.TIME_UNSET, /* queue= */
    Collections.emptyList(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
    // When bandwidth estimation is updated to 500L, we should switch down to use a lower bitrate
    // format. When we don't have enough buffer at higher quality (24_999_000 us is smaller than
    // maxDurationForQualityDecreaseMs), we should switch down now.
    assertThat(adaptiveTrackSelection.getSelectedFormat()).isEqualTo(format1);
    assertThat(adaptiveTrackSelection.getSelectionReason()).isEqualTo(C.SELECTION_REASON_ADAPTIVE);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Test(org.junit.Test)

Example 69 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class AdaptiveTrackSelectionTest method updateSelectedTrackDoNotSwitchUpIfNotBufferedEnough.

@Test
public void updateSelectedTrackDoNotSwitchUpIfNotBufferedEnough() {
    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);
    // The second measurement onward returns 2000L, which prompts the track selection to switch up
    // if possible.
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 2000L);
    AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMinDurationForQualityIncreaseMs(trackGroup, /* minDurationForQualityIncreaseMs= */
    10_000);
    adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
    0, /* bufferedDurationUs= */
    9_999_000, /* availableDurationUs= */
    C.TIME_UNSET, /* queue= */
    Collections.emptyList(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
    // When bandwidth estimation is updated to 2000L, we can switch up to use a higher bitrate
    // format. However, since we only buffered 9_999_000 us, which is smaller than
    // minDurationForQualityIncreaseMs, we should defer switch up.
    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) Test(org.junit.Test)

Example 70 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class AdaptiveTrackSelectionTest method updateSelectedTrackDoNotSwitchDownIfBufferedEnough.

@Test
public void updateSelectedTrackDoNotSwitchDownIfBufferedEnough() {
    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);
    // The second measurement onward returns 500L, which prompts the track selection to switch down
    // if necessary.
    when(mockBandwidthMeter.getBitrateEstimate()).thenReturn(1000L, 500L);
    AdaptiveTrackSelection adaptiveTrackSelection = prepareAdaptiveTrackSelectionWithMaxDurationForQualityDecreaseMs(trackGroup, /* maxDurationForQualityDecreaseMs= */
    25_000);
    adaptiveTrackSelection.updateSelectedTrack(/* playbackPositionUs= */
    0, /* bufferedDurationUs= */
    25_000_000, /* availableDurationUs= */
    C.TIME_UNSET, /* queue= */
    Collections.emptyList(), createMediaChunkIterators(trackGroup, TEST_CHUNK_DURATION_US));
    // When bandwidth estimation is updated to 500L, we should switch down to use a lower bitrate
    // format. However, since we have enough buffer at higher quality (25_000_000 us, which is equal
    // to maxDurationForQualityDecreaseMs), we should defer switch down.
    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) Test(org.junit.Test)

Aggregations

Format (com.google.android.exoplayer2.Format)245 Test (org.junit.Test)178 Nullable (androidx.annotation.Nullable)65 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)62 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)55 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)35 ArrayList (java.util.ArrayList)32 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)26 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)26 MediaFormat (android.media.MediaFormat)22 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)22 SuppressLint (android.annotation.SuppressLint)18 Metadata (com.google.android.exoplayer2.metadata.Metadata)18 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)18 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)16 ImmutableList (com.google.common.collect.ImmutableList)16 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)15 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)15 SurfaceTexture (android.graphics.SurfaceTexture)14 Surface (android.view.Surface)14