Search in sources :

Example 1 with TrackGroup

use of androidx.media3.common.TrackGroup in project media by androidx.

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(androidx.media3.common.TrackGroupArray) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) TracksInfo(androidx.media3.common.TracksInfo) TrackSelectionArray(androidx.media3.common.TrackSelectionArray) MediaTrack(com.google.android.gms.cast.MediaTrack) MediaInfo(com.google.android.gms.cast.MediaInfo) TrackGroup(androidx.media3.common.TrackGroup) TrackSelection(androidx.media3.common.TrackSelection) MediaStatus(com.google.android.gms.cast.MediaStatus)

Example 2 with TrackGroup

use of androidx.media3.common.TrackGroup in project media by androidx.

the class TrackSelectionOverridesTest method addOverride_onDifferentGroups_addsOverride.

@Test
public void addOverride_onDifferentGroups_addsOverride() {
    TrackSelectionOverride override1 = new TrackSelectionOverride(newTrackGroupWithIds(1));
    TrackSelectionOverride override2 = new TrackSelectionOverride(newTrackGroupWithIds(2));
    TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(override1).addOverride(override2).build();
    assertThat(trackSelectionOverrides.asList()).containsExactly(override1, override2);
    assertThat(trackSelectionOverrides.getOverride(override1.trackGroup)).isEqualTo(override1);
    assertThat(trackSelectionOverrides.getOverride(override2.trackGroup)).isEqualTo(override2);
}
Also used : TrackSelectionOverride(androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 3 with TrackGroup

use of androidx.media3.common.TrackGroup in project media by androidx.

the class TrackSelectionOverridesTest method setOverrideForType_onSameType_replacesOverride.

@Test
public void setOverrideForType_onSameType_replacesOverride() {
    TrackSelectionOverride override1 = new TrackSelectionOverride(newTrackGroupWithIds(1));
    TrackSelectionOverride override2 = new TrackSelectionOverride(newTrackGroupWithIds(2));
    TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().setOverrideForType(override1).setOverrideForType(override2).build();
    assertThat(trackSelectionOverrides.asList()).containsExactly(override2);
    assertThat(trackSelectionOverrides.getOverride(override2.trackGroup)).isEqualTo(override2);
}
Also used : TrackSelectionOverride(androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 4 with TrackGroup

use of androidx.media3.common.TrackGroup in project media by androidx.

the class DefaultTrackSelector method getMaxVideoPixelsToRetainForViewport.

private static int getMaxVideoPixelsToRetainForViewport(TrackGroup group, int viewportWidth, int viewportHeight, boolean orientationMayChange) {
    if (viewportWidth == Integer.MAX_VALUE || viewportHeight == Integer.MAX_VALUE) {
        return Integer.MAX_VALUE;
    }
    int maxVideoPixelsToRetain = Integer.MAX_VALUE;
    for (int i = 0; i < group.length; i++) {
        Format format = group.getFormat(i);
        // smallest to exceed the maximum size at which it can be displayed within the viewport.
        if (format.width > 0 && format.height > 0) {
            Point maxVideoSizeInViewport = getMaxVideoSizeInViewport(orientationMayChange, viewportWidth, viewportHeight, format.width, format.height);
            int videoPixels = format.width * format.height;
            if (format.width >= (int) (maxVideoSizeInViewport.x * FRACTION_TO_CONSIDER_FULLSCREEN) && format.height >= (int) (maxVideoSizeInViewport.y * FRACTION_TO_CONSIDER_FULLSCREEN) && videoPixels < maxVideoPixelsToRetain) {
                maxVideoPixelsToRetain = videoPixels;
            }
        }
    }
    return maxVideoPixelsToRetain;
}
Also used : Format(androidx.media3.common.Format) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 5 with TrackGroup

use of androidx.media3.common.TrackGroup in project media by androidx.

the class DefaultTrackSelector method selectOtherTrack.

// Generic track selection methods.
/**
 * Called by {@link #selectAllTracks(MappedTrackInfo, int[][][], int[], Parameters)} to create a
 * {@link ExoTrackSelection} for a renderer whose type is neither video, audio or text.
 *
 * @param trackType The type of the renderer.
 * @param groups The {@link TrackGroupArray} mapped to the renderer.
 * @param formatSupport The {@link Capabilities} for each mapped track, indexed by track group and
 *     track (in that order).
 * @param params The selector's current constraint parameters.
 * @return The {@link ExoTrackSelection} for the renderer, or null if no selection was made.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
@Nullable
protected ExoTrackSelection.Definition selectOtherTrack(int trackType, TrackGroupArray groups, @Capabilities int[][] formatSupport, Parameters params) throws ExoPlaybackException {
    @Nullable TrackGroup selectedGroup = null;
    int selectedTrackIndex = 0;
    @Nullable OtherTrackScore selectedTrackScore = null;
    for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
        TrackGroup trackGroup = groups.get(groupIndex);
        @Capabilities int[] trackFormatSupport = formatSupport[groupIndex];
        for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
            if (isSupported(trackFormatSupport[trackIndex], params.exceedRendererCapabilitiesIfNecessary)) {
                Format format = trackGroup.getFormat(trackIndex);
                OtherTrackScore trackScore = new OtherTrackScore(format, trackFormatSupport[trackIndex]);
                if (selectedTrackScore == null || trackScore.compareTo(selectedTrackScore) > 0) {
                    selectedGroup = trackGroup;
                    selectedTrackIndex = trackIndex;
                    selectedTrackScore = trackScore;
                }
            }
        }
    }
    return selectedGroup == null ? null : new ExoTrackSelection.Definition(selectedGroup, selectedTrackIndex);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Capabilities(androidx.media3.exoplayer.RendererCapabilities.Capabilities) Nullable(androidx.annotation.Nullable) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Nullable(androidx.annotation.Nullable)

Aggregations

TrackGroup (androidx.media3.common.TrackGroup)72 Test (org.junit.Test)47 Format (androidx.media3.common.Format)41 TrackGroupArray (androidx.media3.common.TrackGroupArray)36 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)13 TrackSelectionOverride (androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride)10 ArrayList (java.util.ArrayList)9 DashManifest (androidx.media3.exoplayer.dash.manifest.DashManifest)8 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)8 AdaptationCheckpoint (androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection.AdaptationCheckpoint)7 ImmutableList (com.google.common.collect.ImmutableList)7 Nullable (androidx.annotation.Nullable)6 AdaptationSet (androidx.media3.exoplayer.dash.manifest.AdaptationSet)6 FakeMediaChunk (androidx.media3.test.utils.FakeMediaChunk)6 FakeTimeline (androidx.media3.test.utils.FakeTimeline)6 Timeline (androidx.media3.common.Timeline)5 TrackSelection (androidx.media3.common.TrackSelection)5 MediaSource (androidx.media3.exoplayer.source.MediaSource)5 ParametersBuilder (androidx.media3.exoplayer.trackselection.DefaultTrackSelector.ParametersBuilder)5 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)5