Search in sources :

Example 76 with Timeline

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

the class AdaptiveTrackSelectionTest method builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints.

@Test
public void builderCreateTrackSelections_withSingleAdaptiveGroup_usesCorrectAdaptationCheckpoints() {
    Format formatFixed1 = new Format.Builder().setAverageBitrate(500).build();
    Format formatFixed2 = new Format.Builder().setAverageBitrate(1000).build();
    Format formatAdaptive1 = new Format.Builder().setAverageBitrate(2000).build();
    Format formatAdaptive2 = new Format.Builder().setAverageBitrate(3000).build();
    Format formatAdaptive3 = new Format.Builder().setAverageBitrate(4000).build();
    Format formatAdaptive4 = new Format.Builder().setAverageBitrate(5000).build();
    TrackGroup trackGroupMultipleFixed = new TrackGroup(formatFixed1, formatFixed2);
    TrackGroup trackGroupAdaptive = new TrackGroup(formatAdaptive1, formatAdaptive2, formatAdaptive3, formatAdaptive4);
    Definition definitionFixed1 = new Definition(trackGroupMultipleFixed, /* tracks...= */
    0);
    Definition definitionFixed2 = new Definition(trackGroupMultipleFixed, /* tracks...= */
    1);
    Definition definitionAdaptive = new Definition(trackGroupAdaptive, /* tracks...= */
    1, 2, 3);
    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, definitionFixed1, null, definitionFixed2, definitionAdaptive }, mockBandwidthMeter, new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
    0)), timeline);
    assertThat(checkPoints).hasSize(1);
    assertThat(checkPoints.get(0)).containsExactly(new AdaptationCheckpoint(/* totalBandwidth= */
    0, /* allocatedBandwidth= */
    0), new AdaptationCheckpoint(/* totalBandwidth= */
    4500, /* allocatedBandwidth= */
    3000), new AdaptationCheckpoint(/* totalBandwidth= */
    5500, /* allocatedBandwidth= */
    4000), new AdaptationCheckpoint(/* totalBandwidth= */
    6500, /* allocatedBandwidth= */
    5000), new AdaptationCheckpoint(/* totalBandwidth= */
    11500, /* allocatedBandwidth= */
    10000)).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 77 with Timeline

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

the class MappingTrackSelectorTest method selectTracks_audioAndVideo_sameOrderAsRenderers_mappedToCorrectRenderer.

@Test
public void selectTracks_audioAndVideo_sameOrderAsRenderers_mappedToCorrectRenderer() throws ExoPlaybackException {
    FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
    RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { VIDEO_CAPABILITIES, AUDIO_CAPABILITIES };
    TrackGroupArray trackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
    trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    0, VIDEO_TRACK_GROUP);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    1, AUDIO_TRACK_GROUP);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 78 with Timeline

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

the class MappingTrackSelectorTest method selectTracks_audioAndVideo_reverseOrderToRenderers_mappedToCorrectRenderer.

@Test
public void selectTracks_audioAndVideo_reverseOrderToRenderers_mappedToCorrectRenderer() throws ExoPlaybackException {
    FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
    TrackGroupArray trackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
    RendererCapabilities[] reverseOrderRendererCapabilities = new RendererCapabilities[] { AUDIO_CAPABILITIES, VIDEO_CAPABILITIES };
    trackSelector.selectTracks(reverseOrderRendererCapabilities, trackGroups, periodId, TIMELINE);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    0, AUDIO_TRACK_GROUP);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    1, VIDEO_TRACK_GROUP);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 79 with Timeline

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

the class ConcatenatingMediaSourceTest method periodCreationWithAds.

@Test
public void periodCreationWithAds() throws IOException, InterruptedException {
    // Create concatenated media source with ad child source.
    Timeline timelineContentOnly = new FakeTimeline(new TimelineWindowDefinition(2, 111, true, false, 10 * C.MICROS_PER_SECOND));
    Timeline timelineWithAds = new FakeTimeline(new TimelineWindowDefinition(2, 222, true, false, 10 * C.MICROS_PER_SECOND, FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    1, /* adGroupTimesUs=... */
    0)));
    FakeMediaSource mediaSourceContentOnly = new FakeMediaSource(timelineContentOnly);
    FakeMediaSource mediaSourceWithAds = new FakeMediaSource(timelineWithAds);
    mediaSource.addMediaSource(mediaSourceContentOnly);
    mediaSource.addMediaSource(mediaSourceWithAds);
    Timeline timeline = testRunner.prepareSource();
    // Assert the timeline contains ad groups.
    TimelineAsserts.assertAdGroupCounts(timeline, 0, 0, 1, 1);
    // Create all periods and assert period creation of child media sources has been called.
    testRunner.assertPrepareAndReleaseAllPeriods();
    Object timelineContentOnlyPeriodUid0 = timelineContentOnly.getUidOfPeriod(/* periodIndex= */
    0);
    Object timelineContentOnlyPeriodUid1 = timelineContentOnly.getUidOfPeriod(/* periodIndex= */
    1);
    Object timelineWithAdsPeriodUid0 = timelineWithAds.getUidOfPeriod(/* periodIndex= */
    0);
    Object timelineWithAdsPeriodUid1 = timelineWithAds.getUidOfPeriod(/* periodIndex= */
    1);
    mediaSourceContentOnly.assertMediaPeriodCreated(new MediaPeriodId(timelineContentOnlyPeriodUid0, /* windowSequenceNumber= */
    0));
    mediaSourceContentOnly.assertMediaPeriodCreated(new MediaPeriodId(timelineContentOnlyPeriodUid1, /* windowSequenceNumber= */
    0));
    mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid0, /* windowSequenceNumber= */
    1));
    mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid1, /* windowSequenceNumber= */
    1));
    mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid0, /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    1));
    mediaSourceWithAds.assertMediaPeriodCreated(new MediaPeriodId(timelineWithAdsPeriodUid1, /* adGroupIndex= */
    0, /* adIndexInAdGroup= */
    0, /* windowSequenceNumber= */
    1));
    testRunner.assertCompletedManifestLoads(0, 1);
    assertCompletedAllMediaPeriodLoads(timeline);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 80 with Timeline

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

the class ConcatenatingMediaSourceTest method playlistChangesBeforePreparation.

@Test
public void playlistChangesBeforePreparation() throws IOException, InterruptedException {
    FakeMediaSource[] childSources = createMediaSources(4);
    mediaSource.addMediaSource(childSources[0]);
    mediaSource.addMediaSource(childSources[1]);
    mediaSource.addMediaSource(0, childSources[2]);
    mediaSource.moveMediaSource(0, 2);
    mediaSource.removeMediaSource(0);
    mediaSource.moveMediaSource(1, 0);
    mediaSource.addMediaSource(1, childSources[3]);
    testRunner.assertNoTimelineChange();
    Timeline timeline = testRunner.prepareSource();
    TimelineAsserts.assertPeriodCounts(timeline, 3, 4, 2);
    TimelineAsserts.assertWindowTags(timeline, 333, 444, 222);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 1, 2, C.INDEX_UNSET);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET, 0, 1);
    TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, C.INDEX_UNSET, 0, 1);
    TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, 1, 2, C.INDEX_UNSET);
    testRunner.assertPrepareAndReleaseAllPeriods();
    testRunner.assertCompletedManifestLoads(0, 1, 2);
    assertCompletedAllMediaPeriodLoads(timeline);
    testRunner.releaseSource();
    for (int i = 1; i < 4; i++) {
        childSources[i].assertReleased();
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)347 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)246 Timeline (com.google.android.exoplayer2.Timeline)163 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)140 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)125 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)110 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)109 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)89 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)85 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)79 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)74 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)60 Format (com.google.android.exoplayer2.Format)49 MediaSource (com.google.android.exoplayer2.source.MediaSource)47 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)44 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)38 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)36 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)35 MediaItem (com.google.android.exoplayer2.MediaItem)34 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)33