Search in sources :

Example 1 with TracksInfo

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

the class DefaultAnalyticsCollector method onTracksInfoChanged.

@Override
public void onTracksInfoChanged(TracksInfo tracksInfo) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_TRACKS_CHANGED, listener -> listener.onTracksInfoChanged(eventTime, tracksInfo));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 2 with TracksInfo

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

the class CastPlayer method updateTracksAndSelectionsAndNotifyIfChanged.

/**
 * Updates the internal tracks and selection and returns whether they have changed.
 */
private boolean updateTracksAndSelectionsAndNotifyIfChanged() {
    if (remoteMediaClient == null) {
        // There is no session. We leave the state of the player as it is now.
        return false;
    }
    MediaStatus mediaStatus = getMediaStatus();
    MediaInfo mediaInfo = mediaStatus != null ? mediaStatus.getMediaInfo() : null;
    List<MediaTrack> castMediaTracks = mediaInfo != null ? mediaInfo.getMediaTracks() : null;
    if (castMediaTracks == null || castMediaTracks.isEmpty()) {
        boolean hasChanged = !currentTrackGroups.isEmpty();
        currentTrackGroups = TrackGroupArray.EMPTY;
        currentTrackSelection = EMPTY_TRACK_SELECTION_ARRAY;
        currentTracksInfo = TracksInfo.EMPTY;
        return hasChanged;
    }
    long[] activeTrackIds = mediaStatus.getActiveTrackIds();
    if (activeTrackIds == null) {
        activeTrackIds = EMPTY_TRACK_ID_ARRAY;
    }
    TrackGroup[] trackGroups = new TrackGroup[castMediaTracks.size()];
    @NullableType TrackSelection[] trackSelections = new TrackSelection[RENDERER_COUNT];
    TracksInfo.TrackGroupInfo[] trackGroupInfos = new TracksInfo.TrackGroupInfo[castMediaTracks.size()];
    for (int i = 0; i < castMediaTracks.size(); i++) {
        MediaTrack mediaTrack = castMediaTracks.get(i);
        trackGroups[i] = new TrackGroup(/* id= */
        Integer.toString(i), CastUtils.mediaTrackToFormat(mediaTrack));
        long id = mediaTrack.getId();
        @C.TrackType int trackType = MimeTypes.getTrackType(mediaTrack.getContentType());
        int rendererIndex = getRendererIndexForTrackType(trackType);
        boolean supported = rendererIndex != C.INDEX_UNSET;
        boolean selected = isTrackActive(id, activeTrackIds) && supported && trackSelections[rendererIndex] == null;
        if (selected) {
            trackSelections[rendererIndex] = new CastTrackSelection(trackGroups[i]);
        }
        @C.FormatSupport int[] trackSupport = new int[] { supported ? C.FORMAT_HANDLED : C.FORMAT_UNSUPPORTED_TYPE };
        final boolean[] trackSelected = new boolean[] { selected };
        trackGroupInfos[i] = new TracksInfo.TrackGroupInfo(trackGroups[i], trackSupport, trackType, trackSelected);
    }
    TrackGroupArray newTrackGroups = new TrackGroupArray(trackGroups);
    TrackSelectionArray newTrackSelections = new TrackSelectionArray(trackSelections);
    TracksInfo newTracksInfo = new TracksInfo(ImmutableList.copyOf(trackGroupInfos));
    if (!newTrackGroups.equals(currentTrackGroups) || !newTrackSelections.equals(currentTrackSelection) || !newTracksInfo.equals(currentTracksInfo)) {
        currentTrackSelection = newTrackSelections;
        currentTrackGroups = newTrackGroups;
        currentTracksInfo = newTracksInfo;
        return true;
    }
    return false;
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) TracksInfo(com.google.android.exoplayer2.TracksInfo) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray) MediaTrack(com.google.android.gms.cast.MediaTrack) MediaInfo(com.google.android.gms.cast.MediaInfo) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) MediaStatus(com.google.android.gms.cast.MediaStatus)

Example 3 with TracksInfo

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

the class TracksInfoTest method roundTripViaBundle_ofTracksInfo_yieldsEqualInstance.

@Test
public void roundTripViaBundle_ofTracksInfo_yieldsEqualInstance() {
    TracksInfo before = new TracksInfo(ImmutableList.of(new TracksInfo.TrackGroupInfo(new TrackGroup(new Format.Builder().build()), new int[] { C.FORMAT_EXCEEDS_CAPABILITIES }, C.TRACK_TYPE_AUDIO, new boolean[] { true }), new TracksInfo.TrackGroupInfo(new TrackGroup(new Format.Builder().build(), new Format.Builder().build()), new int[] { C.FORMAT_UNSUPPORTED_DRM, C.FORMAT_UNSUPPORTED_TYPE }, C.TRACK_TYPE_VIDEO, new boolean[] { false, true })));
    TracksInfo after = TracksInfo.CREATOR.fromBundle(before.toBundle());
    assertThat(after).isEqualTo(before);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Test(org.junit.Test)

Example 4 with TracksInfo

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

the class MappingTrackSelector method buildTracksInfo.

@VisibleForTesting
static /* package */
TracksInfo buildTracksInfo(@NullableType TrackSelection[] selections, MappedTrackInfo mappedTrackInfo) {
    ImmutableList.Builder<TracksInfo.TrackGroupInfo> builder = new ImmutableList.Builder<>();
    for (int rendererIndex = 0; rendererIndex < mappedTrackInfo.getRendererCount(); rendererIndex++) {
        TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(rendererIndex);
        @Nullable TrackSelection trackSelection = selections[rendererIndex];
        for (int groupIndex = 0; groupIndex < trackGroupArray.length; groupIndex++) {
            TrackGroup trackGroup = trackGroupArray.get(groupIndex);
            @C.FormatSupport int[] trackSupport = new int[trackGroup.length];
            boolean[] selected = new boolean[trackGroup.length];
            for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
                trackSupport[trackIndex] = mappedTrackInfo.getTrackSupport(rendererIndex, groupIndex, trackIndex);
                boolean isTrackSelected = trackSelection != null && trackSelection.getTrackGroup().equals(trackGroup) && trackSelection.indexOf(trackIndex) != C.INDEX_UNSET;
                selected[trackIndex] = isTrackSelected;
            }
            @C.TrackType int trackGroupType = mappedTrackInfo.getRendererType(rendererIndex);
            builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
        }
    }
    TrackGroupArray unmappedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups();
    for (int groupIndex = 0; groupIndex < unmappedTrackGroups.length; groupIndex++) {
        TrackGroup trackGroup = unmappedTrackGroups.get(groupIndex);
        @C.FormatSupport int[] trackSupport = new int[trackGroup.length];
        Arrays.fill(trackSupport, C.FORMAT_UNSUPPORTED_TYPE);
        // A track group only contains tracks of the same type, thus only consider the first track.
        @C.TrackType int trackGroupType = MimeTypes.getTrackType(trackGroup.getFormat(0).sampleMimeType);
        // Initialized to false.
        boolean[] selected = new boolean[trackGroup.length];
        builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
    }
    return new TracksInfo(builder.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TracksInfo(com.google.android.exoplayer2.TracksInfo) FormatSupport(com.google.android.exoplayer2.C.FormatSupport) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Nullable(androidx.annotation.Nullable) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 5 with TracksInfo

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

the class ExoPlayerTest method errorThrownDuringPlaylistUpdate_keepsConsistentPlayerState.

@Test
public void errorThrownDuringPlaylistUpdate_keepsConsistentPlayerState() {
    FakeMediaSource source1 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT);
    FakeMediaSource source2 = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.AUDIO_FORMAT);
    AtomicInteger audioRendererEnableCount = new AtomicInteger(0);
    FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO) {

        @Override
        protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException {
            if (audioRendererEnableCount.incrementAndGet() == 2) {
                // Fail when enabling the renderer for the second time during the playlist update.
                throw createRendererException(new IllegalStateException(), ExoPlayerTestRunner.AUDIO_FORMAT, PlaybackException.ERROR_CODE_UNSPECIFIED);
            }
        }
    };
    AtomicReference<Timeline> timelineAfterError = new AtomicReference<>();
    AtomicReference<TracksInfo> trackInfosAfterError = new AtomicReference<>();
    AtomicReference<TrackSelectionArray> trackSelectionsAfterError = new AtomicReference<>();
    AtomicInteger mediaItemIndexAfterError = new AtomicInteger();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).executeRunnable(new PlayerRunnable() {

        @Override
        public void run(ExoPlayer player) {
            player.addAnalyticsListener(new AnalyticsListener() {

                @Override
                public void onPlayerError(EventTime eventTime, PlaybackException error) {
                    timelineAfterError.set(player.getCurrentTimeline());
                    trackInfosAfterError.set(player.getCurrentTracksInfo());
                    trackSelectionsAfterError.set(player.getCurrentTrackSelections());
                    mediaItemIndexAfterError.set(player.getCurrentMediaItemIndex());
                }
            });
        }
    }).pause().waitForIsLoading(true).waitForIsLoading(false).removeMediaItem(0).build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(source1, source2).setActionSchedule(actionSchedule).setRenderers(videoRenderer, audioRenderer).build();
    assertThrows(ExoPlaybackException.class, () -> testRunner.start(/* doPrepare= */
    true).blockUntilActionScheduleFinished(TIMEOUT_MS).blockUntilEnded(TIMEOUT_MS));
    assertThat(timelineAfterError.get().getWindowCount()).isEqualTo(1);
    assertThat(mediaItemIndexAfterError.get()).isEqualTo(0);
    assertThat(trackInfosAfterError.get().getTrackGroupInfos()).hasSize(1);
    assertThat(trackInfosAfterError.get().getTrackGroupInfos().get(0).getTrackGroup().getFormat(0)).isEqualTo(ExoPlayerTestRunner.AUDIO_FORMAT);
    // Video renderer.
    assertThat(trackSelectionsAfterError.get().get(0)).isNull();
    // Audio renderer.
    assertThat(trackSelectionsAfterError.get().get(1)).isNotNull();
}
Also used : AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) PlayerRunnable(com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) TrackSelectionArray(com.google.android.exoplayer2.trackselection.TrackSelectionArray) FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Aggregations

TrackGroup (com.google.android.exoplayer2.source.TrackGroup)7 TracksInfo (com.google.android.exoplayer2.TracksInfo)6 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)4 Test (org.junit.Test)4 TrackGroupInfo (com.google.android.exoplayer2.TracksInfo.TrackGroupInfo)2 TrackSelectionArray (com.google.android.exoplayer2.trackselection.TrackSelectionArray)2 ImmutableList (com.google.common.collect.ImmutableList)2 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)2 SuppressLint (android.annotation.SuppressLint)1 Nullable (androidx.annotation.Nullable)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 FormatSupport (com.google.android.exoplayer2.C.FormatSupport)1 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)1 AdaptiveSupport (com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport)1 Capabilities (com.google.android.exoplayer2.RendererCapabilities.Capabilities)1 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)1 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)1 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)1 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)1 PlayerRunnable (com.google.android.exoplayer2.testutil.ActionSchedule.PlayerRunnable)1