Search in sources :

Example 26 with TrackGroupArray

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

the class DefaultTrackSelector method getLegacyRendererOverride.

// Calling deprecated getSelectionOverride.
@SuppressWarnings("deprecation")
private ExoTrackSelection.@NullableType Definition getLegacyRendererOverride(MappedTrackInfo mappedTrackInfo, Parameters params, int rendererIndex) {
    TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
    @Nullable SelectionOverride override = params.getSelectionOverride(rendererIndex, rendererTrackGroups);
    if (override == null) {
        return null;
    }
    return new ExoTrackSelection.Definition(rendererTrackGroups.get(override.groupIndex), override.tracks, override.type);
}
Also used : TrackSelectionOverride(androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride) TrackGroupArray(androidx.media3.common.TrackGroupArray) Nullable(androidx.annotation.Nullable)

Example 27 with TrackGroupArray

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

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(androidx.media3.common.TrackGroupArray) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) TracksInfo(androidx.media3.common.TracksInfo) TrackGroup(androidx.media3.common.TrackGroup) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Capabilities(androidx.media3.exoplayer.RendererCapabilities.Capabilities) AdaptiveSupport(androidx.media3.exoplayer.RendererCapabilities.AdaptiveSupport)

Example 28 with TrackGroupArray

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

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(androidx.media3.common.TrackGroupArray) TracksInfo(androidx.media3.common.TracksInfo) FormatSupport(androidx.media3.common.C.FormatSupport) TrackGroup(androidx.media3.common.TrackGroup) TrackSelection(androidx.media3.common.TrackSelection) Nullable(androidx.annotation.Nullable) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 29 with TrackGroupArray

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

the class EventLogger method onTracksChanged.

@Override
public void onTracksChanged(EventTime eventTime, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    MappedTrackInfo mappedTrackInfo = trackSelector != null ? trackSelector.getCurrentMappedTrackInfo() : null;
    if (mappedTrackInfo == null) {
        logd(eventTime, "tracks", "[]");
        return;
    }
    logd("tracks [" + getEventTimeString(eventTime));
    // Log tracks associated to renderers.
    int rendererCount = mappedTrackInfo.getRendererCount();
    for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
        TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
        TrackSelection trackSelection = trackSelections.get(rendererIndex);
        if (rendererTrackGroups.length == 0) {
            logd("  " + mappedTrackInfo.getRendererName(rendererIndex) + " []");
        } else {
            logd("  " + mappedTrackInfo.getRendererName(rendererIndex) + " [");
            for (int groupIndex = 0; groupIndex < rendererTrackGroups.length; groupIndex++) {
                TrackGroup trackGroup = rendererTrackGroups.get(groupIndex);
                String adaptiveSupport = getAdaptiveSupportString(trackGroup.length, mappedTrackInfo.getAdaptiveSupport(rendererIndex, groupIndex, /* includeCapabilitiesExceededTracks= */
                false));
                logd("    Group:" + trackGroup.id + ", adaptive_supported=" + adaptiveSupport + " [");
                for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
                    String status = getTrackStatusString(trackSelection, trackGroup, trackIndex);
                    @Capabilities int capabilities = mappedTrackInfo.getCapabilities(rendererIndex, groupIndex, trackIndex);
                    String formatSupport = getFormatSupportString(getFormatSupport(capabilities));
                    String hardwareAccelerationSupport = getHardwareAccelerationSupport(capabilities) == HARDWARE_ACCELERATION_SUPPORTED ? ", accelerated=YES" : "";
                    String decoderSupport = getDecoderSupport(capabilities) == DECODER_SUPPORT_FALLBACK ? ", fallback=YES" : "";
                    logd("      " + status + " Track:" + trackIndex + ", " + Format.toLogString(trackGroup.getFormat(trackIndex)) + ", supported=" + formatSupport + hardwareAccelerationSupport + decoderSupport);
                }
                logd("    ]");
            }
            // Log metadata for at most one of the tracks selected for the renderer.
            if (trackSelection != null) {
                for (int selectionIndex = 0; selectionIndex < trackSelection.length(); selectionIndex++) {
                    Metadata metadata = trackSelection.getFormat(selectionIndex).metadata;
                    if (metadata != null) {
                        logd("    Metadata [");
                        printMetadata(metadata, "      ");
                        logd("    ]");
                        break;
                    }
                }
            }
            logd("  ]");
        }
    }
    // Log tracks not associated with a renderer.
    TrackGroupArray unassociatedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups();
    if (unassociatedTrackGroups.length > 0) {
        logd("  Unmapped [");
        for (int groupIndex = 0; groupIndex < unassociatedTrackGroups.length; groupIndex++) {
            logd("    Group:" + groupIndex + " [");
            TrackGroup trackGroup = unassociatedTrackGroups.get(groupIndex);
            for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
                String status = getTrackStatusString(false);
                String formatSupport = getFormatSupportString(C.FORMAT_UNSUPPORTED_TYPE);
                logd("      " + status + " Track:" + trackIndex + ", " + Format.toLogString(trackGroup.getFormat(trackIndex)) + ", supported=" + formatSupport);
            }
            logd("    ]");
        }
        logd("  ]");
    }
    logd("]");
}
Also used : TrackGroup(androidx.media3.common.TrackGroup) RendererCapabilities(androidx.media3.exoplayer.RendererCapabilities) Capabilities(androidx.media3.exoplayer.RendererCapabilities.Capabilities) TrackGroupArray(androidx.media3.common.TrackGroupArray) Metadata(androidx.media3.common.Metadata) Util.getFormatSupportString(androidx.media3.common.util.Util.getFormatSupportString) MappedTrackInfo(androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo) TrackSelection(androidx.media3.common.TrackSelection)

Example 30 with TrackGroupArray

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

the class DefaultTrackSelectorTest method selectTracksPreferHigherNumChannelBeforeSampleRate.

/**
 * Tests that track selector will prefer audio tracks with higher channel count over tracks with
 * higher sample rate when other factors are the same, and tracks are within renderer's
 * capabilities.
 */
@Test
public void selectTracksPreferHigherNumChannelBeforeSampleRate() throws Exception {
    Format.Builder formatBuilder = AUDIO_FORMAT.buildUpon();
    Format higherChannelLowerSampleRateFormat = formatBuilder.setChannelCount(6).setSampleRate(22050).build();
    Format lowerChannelHigherSampleRateFormat = formatBuilder.setChannelCount(2).setSampleRate(44100).build();
    TrackGroupArray trackGroups = wrapFormats(higherChannelLowerSampleRateFormat, lowerChannelHigherSampleRateFormat);
    TrackSelectorResult result = trackSelector.selectTracks(new RendererCapabilities[] { ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES }, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, higherChannelLowerSampleRateFormat);
}
Also used : Format(androidx.media3.common.Format) TrackGroupArray(androidx.media3.common.TrackGroupArray) Test(org.junit.Test)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)117 Test (org.junit.Test)92 Format (androidx.media3.common.Format)60 TrackGroup (androidx.media3.common.TrackGroup)40 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)36 Nullable (androidx.annotation.Nullable)18 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)17 FakeTimeline (androidx.media3.test.utils.FakeTimeline)17 TransferListener (androidx.media3.datasource.TransferListener)14 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)13 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)13 FakeMediaPeriod (androidx.media3.test.utils.FakeMediaPeriod)13 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)13 Allocator (androidx.media3.exoplayer.upstream.Allocator)12 MediaSource (androidx.media3.exoplayer.source.MediaSource)10 MediaItem (androidx.media3.common.MediaItem)9 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)9 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)9 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)9 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)9