Search in sources :

Example 6 with TracksInfo

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

the class StyledPlayerControlView method initTrackSelectionAdapter.

private void initTrackSelectionAdapter() {
    textTrackSelectionAdapter.clear();
    audioTrackSelectionAdapter.clear();
    if (player == null || !player.isCommandAvailable(Player.COMMAND_GET_TRACK_INFOS) || !player.isCommandAvailable(Player.COMMAND_SET_TRACK_SELECTION_PARAMETERS)) {
        return;
    }
    TracksInfo tracksInfo = player.getCurrentTracksInfo();
    audioTrackSelectionAdapter.init(gatherSupportedTrackInfosOfType(tracksInfo, C.TRACK_TYPE_AUDIO));
    if (controlViewLayoutManager.getShowButton(subtitleButton)) {
        textTrackSelectionAdapter.init(gatherSupportedTrackInfosOfType(tracksInfo, C.TRACK_TYPE_TEXT));
    } else {
        textTrackSelectionAdapter.init(ImmutableList.of());
    }
}
Also used : TracksInfo(com.google.android.exoplayer2.TracksInfo)

Example 7 with TracksInfo

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

the class MediaMetricsListener method maybeReportTrackChanges.

private void maybeReportTrackChanges(Player player, Events events, long realtimeMs) {
    if (events.contains(EVENT_TRACKS_CHANGED)) {
        TracksInfo tracksInfo = player.getCurrentTracksInfo();
        boolean isVideoSelected = tracksInfo.isTypeSelected(C.TRACK_TYPE_VIDEO);
        boolean isAudioSelected = tracksInfo.isTypeSelected(C.TRACK_TYPE_AUDIO);
        boolean isTextSelected = tracksInfo.isTypeSelected(C.TRACK_TYPE_TEXT);
        if (isVideoSelected || isAudioSelected || isTextSelected) {
            // Ignore updates with insufficient information where no tracks are selected.
            if (!isVideoSelected) {
                maybeUpdateVideoFormat(realtimeMs, /* videoFormat= */
                null, C.SELECTION_REASON_UNKNOWN);
            }
            if (!isAudioSelected) {
                maybeUpdateAudioFormat(realtimeMs, /* audioFormat= */
                null, C.SELECTION_REASON_UNKNOWN);
            }
            if (!isTextSelected) {
                maybeUpdateTextFormat(realtimeMs, /* textFormat= */
                null, C.SELECTION_REASON_UNKNOWN);
            }
        }
    }
    if (canReportPendingFormatUpdate(pendingVideoFormat) && pendingVideoFormat.format.height != Format.NO_VALUE) {
        maybeUpdateVideoFormat(realtimeMs, pendingVideoFormat.format, pendingVideoFormat.selectionReason);
        pendingVideoFormat = null;
    }
    if (canReportPendingFormatUpdate(pendingAudioFormat)) {
        maybeUpdateAudioFormat(realtimeMs, pendingAudioFormat.format, pendingAudioFormat.selectionReason);
        pendingAudioFormat = null;
    }
    if (canReportPendingFormatUpdate(pendingTextFormat)) {
        maybeUpdateTextFormat(realtimeMs, pendingTextFormat.format, pendingTextFormat.selectionReason);
        pendingTextFormat = null;
    }
}
Also used : TracksInfo(com.google.android.exoplayer2.TracksInfo)

Example 8 with TracksInfo

use of com.google.android.exoplayer2.TracksInfo 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)

Example 9 with TracksInfo

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

the class TracksInfoTest method tracksInfoGetters_ofComplexTracksInfo_returnExpectedValues.

@Test
public void tracksInfoGetters_ofComplexTracksInfo_returnExpectedValues() {
    TracksInfo.TrackGroupInfo trackGroupInfo0 = new TracksInfo.TrackGroupInfo(new TrackGroup(new Format.Builder().build()), new int[] { C.FORMAT_EXCEEDS_CAPABILITIES }, C.TRACK_TYPE_AUDIO, /* tracksSelected= */
    new boolean[] { false });
    TracksInfo.TrackGroupInfo trackGroupInfo1 = new TracksInfo.TrackGroupInfo(new TrackGroup(new Format.Builder().build(), new Format.Builder().build()), new int[] { C.FORMAT_UNSUPPORTED_DRM, C.FORMAT_HANDLED }, C.TRACK_TYPE_VIDEO, /* tracksSelected= */
    new boolean[] { false, true });
    TracksInfo tracksInfo = new TracksInfo(ImmutableList.of(trackGroupInfo0, trackGroupInfo1));
    assertThat(tracksInfo.isTypeSupportedOrEmpty(C.TRACK_TYPE_AUDIO)).isFalse();
    assertThat(tracksInfo.isTypeSupportedOrEmpty(C.TRACK_TYPE_VIDEO)).isTrue();
    assertThat(tracksInfo.isTypeSupportedOrEmpty(C.TRACK_TYPE_TEXT)).isTrue();
    assertThat(tracksInfo.isTypeSelected(C.TRACK_TYPE_AUDIO)).isFalse();
    assertThat(tracksInfo.isTypeSelected(C.TRACK_TYPE_VIDEO)).isTrue();
    ImmutableList<TracksInfo.TrackGroupInfo> trackGroupInfos = tracksInfo.getTrackGroupInfos();
    assertThat(trackGroupInfos).hasSize(2);
    assertThat(trackGroupInfos.get(0)).isSameInstanceAs(trackGroupInfo0);
    assertThat(trackGroupInfos.get(1)).isSameInstanceAs(trackGroupInfo1);
    assertThat(trackGroupInfos.get(0).isTrackSupported(0)).isFalse();
    assertThat(trackGroupInfos.get(1).isTrackSupported(0)).isFalse();
    assertThat(trackGroupInfos.get(1).isTrackSupported(1)).isTrue();
    assertThat(trackGroupInfos.get(0).getTrackSupport(0)).isEqualTo(C.FORMAT_EXCEEDS_CAPABILITIES);
    assertThat(trackGroupInfos.get(1).getTrackSupport(0)).isEqualTo(C.FORMAT_UNSUPPORTED_DRM);
    assertThat(trackGroupInfos.get(1).getTrackSupport(1)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(trackGroupInfos.get(0).isTrackSelected(0)).isFalse();
    assertThat(trackGroupInfos.get(1).isTrackSelected(0)).isFalse();
    assertThat(trackGroupInfos.get(1).isTrackSelected(1)).isTrue();
    assertThat(trackGroupInfos.get(0).getTrackType()).isEqualTo(C.TRACK_TYPE_AUDIO);
    assertThat(trackGroupInfos.get(1).getTrackType()).isEqualTo(C.TRACK_TYPE_VIDEO);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) Test(org.junit.Test)

Example 10 with TracksInfo

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

the class MappingTrackSelectorTest method buildTrackInfos_withTestValues_isAsExpected.

@Test
public void buildTrackInfos_withTestValues_isAsExpected() {
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo = new MappingTrackSelector.MappedTrackInfo(new String[] { "1", "2" }, new int[] { C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_VIDEO }, new TrackGroupArray[] { new TrackGroupArray(new TrackGroup("0", new Format.Builder().build()), new TrackGroup("1", new Format.Builder().build())), new TrackGroupArray(new TrackGroup("2", new Format.Builder().build(), new Format.Builder().build())) }, new int[] { RendererCapabilities.ADAPTIVE_SEAMLESS, RendererCapabilities.ADAPTIVE_NOT_SUPPORTED }, new int[][][] { new int[][] { new int[] { C.FORMAT_HANDLED }, new int[] { C.FORMAT_UNSUPPORTED_SUBTYPE } }, new int[][] { new int[] { C.FORMAT_UNSUPPORTED_DRM, C.FORMAT_EXCEEDS_CAPABILITIES } } }, new TrackGroupArray(new TrackGroup(new Format.Builder().build())));
    TrackSelection[] selections = new TrackSelection[] { new FixedTrackSelection(mappedTrackInfo.getTrackGroups(0).get(1), 0), new FixedTrackSelection(mappedTrackInfo.getTrackGroups(1).get(0), 1) };
    TracksInfo tracksInfo = MappingTrackSelector.buildTracksInfo(selections, mappedTrackInfo);
    ImmutableList<TrackGroupInfo> trackGroupInfos = tracksInfo.getTrackGroupInfos();
    assertThat(trackGroupInfos).hasSize(4);
    assertThat(trackGroupInfos.get(0).getTrackGroup()).isEqualTo(mappedTrackInfo.getTrackGroups(0).get(0));
    assertThat(trackGroupInfos.get(1).getTrackGroup()).isEqualTo(mappedTrackInfo.getTrackGroups(0).get(1));
    assertThat(trackGroupInfos.get(2).getTrackGroup()).isEqualTo(mappedTrackInfo.getTrackGroups(1).get(0));
    assertThat(trackGroupInfos.get(3).getTrackGroup()).isEqualTo(mappedTrackInfo.getUnmappedTrackGroups().get(0));
    assertThat(trackGroupInfos.get(0).getTrackSupport(0)).isEqualTo(C.FORMAT_HANDLED);
    assertThat(trackGroupInfos.get(1).getTrackSupport(0)).isEqualTo(C.FORMAT_UNSUPPORTED_SUBTYPE);
    assertThat(trackGroupInfos.get(2).getTrackSupport(0)).isEqualTo(C.FORMAT_UNSUPPORTED_DRM);
    assertThat(trackGroupInfos.get(2).getTrackSupport(1)).isEqualTo(C.FORMAT_EXCEEDS_CAPABILITIES);
    assertThat(trackGroupInfos.get(3).getTrackSupport(0)).isEqualTo(C.FORMAT_UNSUPPORTED_TYPE);
    assertThat(trackGroupInfos.get(0).isTrackSelected(0)).isFalse();
    assertThat(trackGroupInfos.get(1).isTrackSelected(0)).isTrue();
    assertThat(trackGroupInfos.get(2).isTrackSelected(0)).isFalse();
    assertThat(trackGroupInfos.get(2).isTrackSelected(1)).isTrue();
    assertThat(trackGroupInfos.get(3).isTrackSelected(0)).isFalse();
    assertThat(trackGroupInfos.get(0).getTrackType()).isEqualTo(C.TRACK_TYPE_AUDIO);
    assertThat(trackGroupInfos.get(1).getTrackType()).isEqualTo(C.TRACK_TYPE_AUDIO);
    assertThat(trackGroupInfos.get(2).getTrackType()).isEqualTo(C.TRACK_TYPE_VIDEO);
    assertThat(trackGroupInfos.get(3).getTrackType()).isEqualTo(C.TRACK_TYPE_UNKNOWN);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) TrackGroupInfo(com.google.android.exoplayer2.TracksInfo.TrackGroupInfo) TracksInfo(com.google.android.exoplayer2.TracksInfo) 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