Search in sources :

Example 86 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class DownloadHelperTest method staticSetUp.

@BeforeClass
public static void staticSetUp() {
    Format audioFormatUs = createAudioFormat(/* language= */
    "US");
    Format audioFormatZh = createAudioFormat(/* language= */
    "ZH");
    Format textFormatUs = createTextFormat(/* language= */
    "US");
    Format textFormatZh = createTextFormat(/* language= */
    "ZH");
    trackGroupAudioUs = new TrackGroup(audioFormatUs);
    trackGroupAudioZh = new TrackGroup(audioFormatZh);
    trackGroupTextUs = new TrackGroup(textFormatUs);
    trackGroupTextZh = new TrackGroup(textFormatZh);
    TrackGroupArray trackGroupArrayAll = new TrackGroupArray(TRACK_GROUP_VIDEO_BOTH, trackGroupAudioUs, trackGroupAudioZh, trackGroupTextUs, trackGroupTextZh);
    TrackGroupArray trackGroupArraySingle = new TrackGroupArray(TRACK_GROUP_VIDEO_SINGLE, trackGroupAudioUs);
    trackGroupArrays = new TrackGroupArray[] { trackGroupArrayAll, trackGroupArraySingle };
    testMediaItem = new MediaItem.Builder().setUri("http://test.uri").setCustomCacheKey("cacheKey").build();
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) BeforeClass(org.junit.BeforeClass)

Example 87 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class HlsMediaPeriod method getStreamKeys.

// TODO: When the multivariant playlist does not de-duplicate variants by URL and allows
// Renditions with null URLs, this method must be updated to calculate stream keys that are
// compatible with those that may already be persisted for offline.
@Override
public List<StreamKey> getStreamKeys(List<ExoTrackSelection> trackSelections) {
    // See HlsMultivariantPlaylist.copy for interpretation of StreamKeys.
    HlsMultivariantPlaylist multivariantPlaylist = Assertions.checkNotNull(playlistTracker.getMultivariantPlaylist());
    boolean hasVariants = !multivariantPlaylist.variants.isEmpty();
    int audioWrapperOffset = hasVariants ? 1 : 0;
    // Subtitle sample stream wrappers are held last.
    int subtitleWrapperOffset = sampleStreamWrappers.length - multivariantPlaylist.subtitles.size();
    TrackGroupArray mainWrapperTrackGroups;
    int mainWrapperPrimaryGroupIndex;
    int[] mainWrapperVariantIndices;
    if (hasVariants) {
        HlsSampleStreamWrapper mainWrapper = sampleStreamWrappers[0];
        mainWrapperVariantIndices = manifestUrlIndicesPerWrapper[0];
        mainWrapperTrackGroups = mainWrapper.getTrackGroups();
        mainWrapperPrimaryGroupIndex = mainWrapper.getPrimaryTrackGroupIndex();
    } else {
        mainWrapperVariantIndices = new int[0];
        mainWrapperTrackGroups = TrackGroupArray.EMPTY;
        mainWrapperPrimaryGroupIndex = 0;
    }
    List<StreamKey> streamKeys = new ArrayList<>();
    boolean needsPrimaryTrackGroupSelection = false;
    boolean hasPrimaryTrackGroupSelection = false;
    for (ExoTrackSelection trackSelection : trackSelections) {
        TrackGroup trackSelectionGroup = trackSelection.getTrackGroup();
        int mainWrapperTrackGroupIndex = mainWrapperTrackGroups.indexOf(trackSelectionGroup);
        if (mainWrapperTrackGroupIndex != C.INDEX_UNSET) {
            if (mainWrapperTrackGroupIndex == mainWrapperPrimaryGroupIndex) {
                // Primary group in main wrapper.
                hasPrimaryTrackGroupSelection = true;
                for (int i = 0; i < trackSelection.length(); i++) {
                    int variantIndex = mainWrapperVariantIndices[trackSelection.getIndexInTrackGroup(i)];
                    streamKeys.add(new StreamKey(HlsMultivariantPlaylist.GROUP_INDEX_VARIANT, variantIndex));
                }
            } else {
                // Embedded group in main wrapper.
                needsPrimaryTrackGroupSelection = true;
            }
        } else {
            // Audio or subtitle group.
            for (int i = audioWrapperOffset; i < sampleStreamWrappers.length; i++) {
                TrackGroupArray wrapperTrackGroups = sampleStreamWrappers[i].getTrackGroups();
                int selectedTrackGroupIndex = wrapperTrackGroups.indexOf(trackSelectionGroup);
                if (selectedTrackGroupIndex != C.INDEX_UNSET) {
                    int groupIndexType = i < subtitleWrapperOffset ? HlsMultivariantPlaylist.GROUP_INDEX_AUDIO : HlsMultivariantPlaylist.GROUP_INDEX_SUBTITLE;
                    int[] selectedWrapperUrlIndices = manifestUrlIndicesPerWrapper[i];
                    for (int trackIndex = 0; trackIndex < trackSelection.length(); trackIndex++) {
                        int renditionIndex = selectedWrapperUrlIndices[trackSelection.getIndexInTrackGroup(trackIndex)];
                        streamKeys.add(new StreamKey(groupIndexType, renditionIndex));
                    }
                    break;
                }
            }
        }
    }
    if (needsPrimaryTrackGroupSelection && !hasPrimaryTrackGroupSelection) {
        // A track selection includes a variant-embedded track, but no variant is added yet. We use
        // the valid variant with the lowest bitrate to reduce overhead.
        int lowestBitrateIndex = mainWrapperVariantIndices[0];
        int lowestBitrate = multivariantPlaylist.variants.get(mainWrapperVariantIndices[0]).format.bitrate;
        for (int i = 1; i < mainWrapperVariantIndices.length; i++) {
            int variantBitrate = multivariantPlaylist.variants.get(mainWrapperVariantIndices[i]).format.bitrate;
            if (variantBitrate < lowestBitrate) {
                lowestBitrate = variantBitrate;
                lowestBitrateIndex = mainWrapperVariantIndices[i];
            }
        }
        streamKeys.add(new StreamKey(HlsMultivariantPlaylist.GROUP_INDEX_VARIANT, lowestBitrateIndex));
    }
    return streamKeys;
}
Also used : ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) ArrayList(java.util.ArrayList) HlsMultivariantPlaylist(com.google.android.exoplayer2.source.hls.playlist.HlsMultivariantPlaylist) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Example 88 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class ExoPlayerTest method infiniteLoading_withSmallAllocations_oomIsPreventedByLoadControl_andThrowsStuckBufferingIllegalStateException.

@Test
public void infiniteLoading_withSmallAllocations_oomIsPreventedByLoadControl_andThrowsStuckBufferingIllegalStateException() {
    DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setTargetBufferBytes(10 * C.DEFAULT_BUFFER_SEGMENT_SIZE).build();
    // Return no end of stream signal to prevent playback from ending.
    FakeMediaPeriod.TrackDataFactory trackDataWithoutEos = (format, periodId) -> ImmutableList.of();
    MediaSource continuouslyAllocatingMediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            return new FakeMediaPeriod(trackGroupArray, allocator, trackDataWithoutEos, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            false) {

                private final List<Allocation> allocations = new ArrayList<>();

                private Callback callback;

                @Override
                public synchronized void prepare(Callback callback, long positionUs) {
                    this.callback = callback;
                    super.prepare(callback, positionUs);
                }

                @Override
                public long getBufferedPositionUs() {
                    // Pretend not to make loading progress, so that continueLoading keeps being called.
                    return 0;
                }

                @Override
                public long getNextLoadPositionUs() {
                    // Pretend not to make loading progress, so that continueLoading keeps being called.
                    return 0;
                }

                @Override
                public boolean continueLoading(long positionUs) {
                    allocations.add(allocator.allocate());
                    callback.onContinueLoadingRequested(this);
                    return true;
                }
            };
        }
    };
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(continuouslyAllocatingMediaSource).setLoadControl(loadControl).build();
    ExoPlaybackException exception = assertThrows(ExoPlaybackException.class, () -> testRunner.start().blockUntilEnded(TIMEOUT_MS));
    assertThat(exception.type).isEqualTo(ExoPlaybackException.TYPE_UNEXPECTED);
    assertThat(exception.getUnexpectedException()).isInstanceOf(IllegalStateException.class);
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) COMMAND_SEEK_TO_NEXT_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Uri(android.net.Uri) BinaryFrame(com.google.android.exoplayer2.metadata.id3.BinaryFrame) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeTrackSelector(com.google.android.exoplayer2.testutil.FakeTrackSelector) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) COMMAND_SEEK_TO_PREVIOUS(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) TestPlayerRunHelper.runUntilTimelineChanged(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilTimelineChanged) MimeTypes(com.google.android.exoplayer2.util.MimeTypes) TestPlayerRunHelper.playUntilStartOfMediaItem(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem) COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM) Looper(android.os.Looper) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) COMMAND_GET_TRACK_INFOS(com.google.android.exoplayer2.Player.COMMAND_GET_TRACK_INFOS) TextInformationFrame(com.google.android.exoplayer2.metadata.id3.TextInformationFrame) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) Surface(android.view.Surface) DEFAULT_WINDOW_DURATION_US(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_DURATION_US) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Range(com.google.common.collect.Range) FakeClock(com.google.android.exoplayer2.testutil.FakeClock) CountDownLatch(java.util.concurrent.CountDownLatch) COMMAND_STOP(com.google.android.exoplayer2.Player.COMMAND_STOP) Nullable(androidx.annotation.Nullable) ArgumentMatchers.anyFloat(org.mockito.ArgumentMatchers.anyFloat) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) COMMAND_GET_TEXT(com.google.android.exoplayer2.Player.COMMAND_GET_TEXT) Mockito.mock(org.mockito.Mockito.mock) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPendingCommandsAreFullyHandled) Iterables(com.google.common.collect.Iterables) COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_IN_CURRENT_MEDIA_ITEM) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) Listener(com.google.android.exoplayer2.Player.Listener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TestPlayerRunHelper.runUntilPositionDiscontinuity(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPositionDiscontinuity) FakeChunkSource(com.google.android.exoplayer2.testutil.FakeChunkSource) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) Before(org.junit.Before) DiscontinuityReason(com.google.android.exoplayer2.Player.DiscontinuityReason) COMMAND_GET_CURRENT_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_GET_CURRENT_MEDIA_ITEM) Clock(com.google.android.exoplayer2.util.Clock) ShadowLooper(org.robolectric.shadows.ShadowLooper) COMMAND_GET_TIMELINE(com.google.android.exoplayer2.Player.COMMAND_GET_TIMELINE) PlayerTarget(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerTarget) COMMAND_SET_TRACK_SELECTION_PARAMETERS(com.google.android.exoplayer2.Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS) TestPlayerRunHelper.runUntilReceiveOffloadSchedulingEnabledNewState(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilReceiveOffloadSchedulingEnabledNewState) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray) TestUtil.assertTimelinesSame(com.google.android.exoplayer2.testutil.TestUtil.assertTimelinesSame) TestPlayerRunHelper(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito.never(org.mockito.Mockito.never) COMMAND_SEEK_TO_DEFAULT_POSITION(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_DEFAULT_POSITION) COMMAND_GET_AUDIO_ATTRIBUTES(com.google.android.exoplayer2.Player.COMMAND_GET_AUDIO_ATTRIBUTES) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) Loader(com.google.android.exoplayer2.upstream.Loader) FakeShuffleOrder(com.google.android.exoplayer2.testutil.FakeShuffleOrder) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) Mockito.reset(org.mockito.Mockito.reset) COMMAND_PREPARE(com.google.android.exoplayer2.Player.COMMAND_PREPARE) Assertions(com.google.android.exoplayer2.util.Assertions) COMMAND_CHANGE_MEDIA_ITEMS(com.google.android.exoplayer2.Player.COMMAND_CHANGE_MEDIA_ITEMS) Util(com.google.android.exoplayer2.util.Util) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) FakeMediaClockRenderer(com.google.android.exoplayer2.testutil.FakeMediaClockRenderer) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) COMMAND_SEEK_TO_NEXT(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_NEXT) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) Random(java.util.Random) TestPlayerRunHelper.playUntilPosition(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilPosition) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) ApplicationProvider(androidx.test.core.app.ApplicationProvider) ArgumentMatcher(org.mockito.ArgumentMatcher) Allocation(com.google.android.exoplayer2.upstream.Allocation) COMMAND_SET_VOLUME(com.google.android.exoplayer2.Player.COMMAND_SET_VOLUME) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) Mockito.atLeast(org.mockito.Mockito.atLeast) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) Assert.fail(org.junit.Assert.fail) COMMAND_SEEK_BACK(com.google.android.exoplayer2.Player.COMMAND_SEEK_BACK) MediaSource(com.google.android.exoplayer2.source.MediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) COMMAND_GET_MEDIA_ITEMS_METADATA(com.google.android.exoplayer2.Player.COMMAND_GET_MEDIA_ITEMS_METADATA) RobolectricUtil.runMainLooperUntil(com.google.android.exoplayer2.robolectric.RobolectricUtil.runMainLooperUntil) TestPlayerRunHelper.runUntilPlaybackState(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilPlaybackState) END_OF_STREAM_ITEM(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.END_OF_STREAM_ITEM) COMMAND_ADJUST_DEVICE_VOLUME(com.google.android.exoplayer2.Player.COMMAND_ADJUST_DEVICE_VOLUME) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Collectors(java.util.stream.Collectors) COMMAND_SET_REPEAT_MODE(com.google.android.exoplayer2.Player.COMMAND_SET_REPEAT_MODE) COMMAND_SET_SHUFFLE_MODE(com.google.android.exoplayer2.Player.COMMAND_SET_SHUFFLE_MODE) FakeSampleStreamItem.oneByteSample(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem.oneByteSample) List(java.util.List) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) COMMAND_GET_VOLUME(com.google.android.exoplayer2.Player.COMMAND_GET_VOLUME) Mockito.inOrder(org.mockito.Mockito.inOrder) FakeVideoRenderer(com.google.android.exoplayer2.testutil.FakeVideoRenderer) FakeAdaptiveDataSet(com.google.android.exoplayer2.testutil.FakeAdaptiveDataSet) COMMAND_PLAY_PAUSE(com.google.android.exoplayer2.Player.COMMAND_PLAY_PAUSE) Action(com.google.android.exoplayer2.testutil.Action) AdditionalMatchers.not(org.mockito.AdditionalMatchers.not) AudioAttributes(com.google.android.exoplayer2.audio.AudioAttributes) Metadata(com.google.android.exoplayer2.metadata.Metadata) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) COMMAND_GET_DEVICE_VOLUME(com.google.android.exoplayer2.Player.COMMAND_GET_DEVICE_VOLUME) COMMAND_SEEK_FORWARD(com.google.android.exoplayer2.Player.COMMAND_SEEK_FORWARD) Context(android.content.Context) COMMAND_SEEK_TO_MEDIA_ITEM(com.google.android.exoplayer2.Player.COMMAND_SEEK_TO_MEDIA_ITEM) COMMAND_SET_MEDIA_ITEMS_METADATA(com.google.android.exoplayer2.Player.COMMAND_SET_MEDIA_ITEMS_METADATA) DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) Assert.assertThrows(org.junit.Assert.assertThrows) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) AtomicReference(java.util.concurrent.atomic.AtomicReference) STATE_ENDED(com.google.android.exoplayer2.Player.STATE_ENDED) Shadows.shadowOf(org.robolectric.Shadows.shadowOf) AudioManager(android.media.AudioManager) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) ShadowAudioManager(org.robolectric.shadows.ShadowAudioManager) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ImmutableList(com.google.common.collect.ImmutableList) TestPlayerRunHelper.runUntilSleepingForOffload(com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.runUntilSleepingForOffload) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) COMMAND_SET_DEVICE_VOLUME(com.google.android.exoplayer2.Player.COMMAND_SET_DEVICE_VOLUME) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) COMMAND_SET_SPEED_AND_PITCH(com.google.android.exoplayer2.Player.COMMAND_SET_SPEED_AND_PITCH) Allocator(com.google.android.exoplayer2.upstream.Allocator) SurfaceTexture(android.graphics.SurfaceTexture) COMMAND_SET_VIDEO_SURFACE(com.google.android.exoplayer2.Player.COMMAND_SET_VIDEO_SURFACE) Window(com.google.android.exoplayer2.Timeline.Window) FakeSampleStreamItem(com.google.android.exoplayer2.testutil.FakeSampleStream.FakeSampleStreamItem) InOrder(org.mockito.InOrder) PositionInfo(com.google.android.exoplayer2.Player.PositionInfo) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) Mockito.verify(org.mockito.Mockito.verify) FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSourceFactory(com.google.android.exoplayer2.testutil.FakeMediaSourceFactory) Mockito(org.mockito.Mockito) FakeTrackSelection(com.google.android.exoplayer2.testutil.FakeTrackSelection) Collections(java.util.Collections) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 89 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class ExoPlayerTest method setPlaybackSpeedBeforePreparationCompletesSucceeds.

@Test
public void setPlaybackSpeedBeforePreparationCompletesSucceeds() throws Exception {
    // Test that no exception is thrown when playback parameters are updated between creating a
    // period and preparation of the period completing.
    final CountDownLatch createPeriodCalledCountDownLatch = new CountDownLatch(1);
    final FakeMediaPeriod[] fakeMediaPeriodHolder = new FakeMediaPeriod[1];
    MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            // Defer completing preparation of the period until playback parameters have been set.
            fakeMediaPeriodHolder[0] = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            true);
            createPeriodCalledCountDownLatch.countDown();
            return fakeMediaPeriodHolder[0];
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_BUFFERING).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            try {
                player.getClock().onThreadBlocked();
                createPeriodCalledCountDownLatch.await();
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        }
    }).setPlaybackParameters(new PlaybackParameters(/* speed= */
    2f)).executeRunnable(() -> fakeMediaPeriodHolder[0].setPreparationComplete()).build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) CountDownLatch(java.util.concurrent.CountDownLatch) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 90 with TrackGroupArray

use of com.google.android.exoplayer2.source.TrackGroupArray in project ExoPlayer by google.

the class MappingTrackSelector method selectTracks.

@Override
public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCapabilities, TrackGroupArray trackGroups, MediaPeriodId periodId, Timeline timeline) throws ExoPlaybackException {
    // Structures into which data will be written during the selection. The extra item at the end
    // of each array is to store data associated with track groups that cannot be associated with
    // any renderer.
    int[] rendererTrackGroupCounts = new int[rendererCapabilities.length + 1];
    TrackGroup[][] rendererTrackGroups = new TrackGroup[rendererCapabilities.length + 1][];
    @Capabilities int[][][] rendererFormatSupports = new int[rendererCapabilities.length + 1][][];
    for (int i = 0; i < rendererTrackGroups.length; i++) {
        rendererTrackGroups[i] = new TrackGroup[trackGroups.length];
        rendererFormatSupports[i] = new int[trackGroups.length][];
    }
    // Determine the extent to which each renderer supports mixed mimeType adaptation.
    @AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports = getMixedMimeTypeAdaptationSupports(rendererCapabilities);
    // renderer provides for each track in the group.
    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        TrackGroup group = trackGroups.get(groupIndex);
        // Associate the group to a preferred renderer.
        boolean preferUnassociatedRenderer = MimeTypes.getTrackType(group.getFormat(0).sampleMimeType) == C.TRACK_TYPE_METADATA;
        int rendererIndex = findRenderer(rendererCapabilities, group, rendererTrackGroupCounts, preferUnassociatedRenderer);
        // Evaluate the support that the renderer provides for each track in the group.
        @Capabilities int[] rendererFormatSupport = rendererIndex == rendererCapabilities.length ? new int[group.length] : getFormatSupport(rendererCapabilities[rendererIndex], group);
        // Stash the results.
        int rendererTrackGroupCount = rendererTrackGroupCounts[rendererIndex];
        rendererTrackGroups[rendererIndex][rendererTrackGroupCount] = group;
        rendererFormatSupports[rendererIndex][rendererTrackGroupCount] = rendererFormatSupport;
        rendererTrackGroupCounts[rendererIndex]++;
    }
    // Create a track group array for each renderer, and trim each rendererFormatSupports entry.
    TrackGroupArray[] rendererTrackGroupArrays = new TrackGroupArray[rendererCapabilities.length];
    String[] rendererNames = new String[rendererCapabilities.length];
    int[] rendererTrackTypes = new int[rendererCapabilities.length];
    for (int i = 0; i < rendererCapabilities.length; i++) {
        int rendererTrackGroupCount = rendererTrackGroupCounts[i];
        rendererTrackGroupArrays[i] = new TrackGroupArray(Util.nullSafeArrayCopy(rendererTrackGroups[i], rendererTrackGroupCount));
        rendererFormatSupports[i] = Util.nullSafeArrayCopy(rendererFormatSupports[i], rendererTrackGroupCount);
        rendererNames[i] = rendererCapabilities[i].getName();
        rendererTrackTypes[i] = rendererCapabilities[i].getTrackType();
    }
    // Create a track group array for track groups not mapped to a renderer.
    int unmappedTrackGroupCount = rendererTrackGroupCounts[rendererCapabilities.length];
    TrackGroupArray unmappedTrackGroupArray = new TrackGroupArray(Util.nullSafeArrayCopy(rendererTrackGroups[rendererCapabilities.length], unmappedTrackGroupCount));
    // Package up the track information and selections.
    MappedTrackInfo mappedTrackInfo = new MappedTrackInfo(rendererNames, rendererTrackTypes, rendererTrackGroupArrays, rendererMixedMimeTypeAdaptationSupports, rendererFormatSupports, unmappedTrackGroupArray);
    Pair<@NullableType RendererConfiguration[], @NullableType ExoTrackSelection[]> result = selectTracks(mappedTrackInfo, rendererFormatSupports, rendererMixedMimeTypeAdaptationSupports, periodId, timeline);
    TracksInfo tracksInfo = buildTracksInfo(result.second, mappedTrackInfo);
    return new TrackSelectorResult(result.first, result.second, tracksInfo, mappedTrackInfo);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) TracksInfo(com.google.android.exoplayer2.TracksInfo) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) AdaptiveSupport(com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport)

Aggregations

TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)126 Test (org.junit.Test)92 Format (com.google.android.exoplayer2.Format)67 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)50 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)36 Nullable (androidx.annotation.Nullable)18 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)17 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)17 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)14 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)13 MediaSource (com.google.android.exoplayer2.source.MediaSource)13 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)13 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)13 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)13 Allocator (com.google.android.exoplayer2.upstream.Allocator)12 ArrayList (java.util.ArrayList)11 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)9 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)9 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)9 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)9