Search in sources :

Example 1 with TrackGroupInfo

use of androidx.media3.common.TracksInfo.TrackGroupInfo in project media by androidx.

the class DashMediaPeriod method buildManifestEventTrackGroupInfos.

private static void buildManifestEventTrackGroupInfos(List<EventStream> eventStreams, TrackGroup[] trackGroups, TrackGroupInfo[] trackGroupInfos, int existingTrackGroupCount) {
    for (int i = 0; i < eventStreams.size(); i++) {
        EventStream eventStream = eventStreams.get(i);
        Format format = new Format.Builder().setId(eventStream.id()).setSampleMimeType(MimeTypes.APPLICATION_EMSG).build();
        String uniqueTrackGroupId = eventStream.id() + ":" + i;
        trackGroups[existingTrackGroupCount] = new TrackGroup(uniqueTrackGroupId, format);
        trackGroupInfos[existingTrackGroupCount++] = TrackGroupInfo.mpdEventTrack(i);
    }
}
Also used : Format(androidx.media3.common.Format) EventStream(androidx.media3.exoplayer.dash.manifest.EventStream) TrackGroup(androidx.media3.common.TrackGroup)

Example 2 with TrackGroupInfo

use of androidx.media3.common.TracksInfo.TrackGroupInfo in project media by androidx.

the class PlayerControlView method gatherSupportedTrackInfosOfType.

private ImmutableList<TrackInformation> gatherSupportedTrackInfosOfType(TracksInfo tracksInfo, @C.TrackType int trackType) {
    ImmutableList.Builder<TrackInformation> tracks = new ImmutableList.Builder<>();
    List<TrackGroupInfo> trackGroupInfos = tracksInfo.getTrackGroupInfos();
    for (int trackGroupIndex = 0; trackGroupIndex < trackGroupInfos.size(); trackGroupIndex++) {
        TrackGroupInfo trackGroupInfo = trackGroupInfos.get(trackGroupIndex);
        if (trackGroupInfo.getTrackType() != trackType) {
            continue;
        }
        TrackGroup trackGroup = trackGroupInfo.getTrackGroup();
        for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
            if (!trackGroupInfo.isTrackSupported(trackIndex)) {
                continue;
            }
            String trackName = trackNameProvider.getTrackName(trackGroup.getFormat(trackIndex));
            tracks.add(new TrackInformation(tracksInfo, trackGroupIndex, trackIndex, trackName));
        }
    }
    return tracks.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TrackGroup(androidx.media3.common.TrackGroup) TrackGroupInfo(androidx.media3.common.TracksInfo.TrackGroupInfo) SuppressLint(android.annotation.SuppressLint)

Example 3 with TrackGroupInfo

use of androidx.media3.common.TracksInfo.TrackGroupInfo in project media by androidx.

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(androidx.media3.common.TrackGroup) TrackGroupArray(androidx.media3.common.TrackGroupArray) TrackGroupInfo(androidx.media3.common.TracksInfo.TrackGroupInfo) TrackSelection(androidx.media3.common.TrackSelection) TracksInfo(androidx.media3.common.TracksInfo) Test(org.junit.Test)

Example 4 with TrackGroupInfo

use of androidx.media3.common.TracksInfo.TrackGroupInfo in project media by androidx.

the class DashMediaPeriod method buildSampleStream.

private ChunkSampleStream<DashChunkSource> buildSampleStream(TrackGroupInfo trackGroupInfo, ExoTrackSelection selection, long positionUs) {
    int embeddedTrackCount = 0;
    boolean enableEventMessageTrack = trackGroupInfo.embeddedEventMessageTrackGroupIndex != C.INDEX_UNSET;
    TrackGroup embeddedEventMessageTrackGroup = null;
    if (enableEventMessageTrack) {
        embeddedEventMessageTrackGroup = trackGroups.get(trackGroupInfo.embeddedEventMessageTrackGroupIndex);
        embeddedTrackCount++;
    }
    boolean enableClosedCaptionTrack = trackGroupInfo.embeddedClosedCaptionTrackGroupIndex != C.INDEX_UNSET;
    TrackGroup embeddedClosedCaptionTrackGroup = null;
    if (enableClosedCaptionTrack) {
        embeddedClosedCaptionTrackGroup = trackGroups.get(trackGroupInfo.embeddedClosedCaptionTrackGroupIndex);
        embeddedTrackCount += embeddedClosedCaptionTrackGroup.length;
    }
    Format[] embeddedTrackFormats = new Format[embeddedTrackCount];
    int[] embeddedTrackTypes = new int[embeddedTrackCount];
    embeddedTrackCount = 0;
    if (enableEventMessageTrack) {
        embeddedTrackFormats[embeddedTrackCount] = embeddedEventMessageTrackGroup.getFormat(0);
        embeddedTrackTypes[embeddedTrackCount] = C.TRACK_TYPE_METADATA;
        embeddedTrackCount++;
    }
    List<Format> embeddedClosedCaptionTrackFormats = new ArrayList<>();
    if (enableClosedCaptionTrack) {
        for (int i = 0; i < embeddedClosedCaptionTrackGroup.length; i++) {
            embeddedTrackFormats[embeddedTrackCount] = embeddedClosedCaptionTrackGroup.getFormat(i);
            embeddedTrackTypes[embeddedTrackCount] = C.TRACK_TYPE_TEXT;
            embeddedClosedCaptionTrackFormats.add(embeddedTrackFormats[embeddedTrackCount]);
            embeddedTrackCount++;
        }
    }
    PlayerTrackEmsgHandler trackPlayerEmsgHandler = manifest.dynamic && enableEventMessageTrack ? playerEmsgHandler.newPlayerTrackEmsgHandler() : null;
    DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(manifestLoaderErrorThrower, manifest, baseUrlExclusionList, periodIndex, trackGroupInfo.adaptationSetIndices, selection, trackGroupInfo.trackType, elapsedRealtimeOffsetMs, enableEventMessageTrack, embeddedClosedCaptionTrackFormats, trackPlayerEmsgHandler, transferListener, playerId);
    ChunkSampleStream<DashChunkSource> stream = new ChunkSampleStream<>(trackGroupInfo.trackType, embeddedTrackTypes, embeddedTrackFormats, chunkSource, this, allocator, positionUs, drmSessionManager, drmEventDispatcher, loadErrorHandlingPolicy, mediaSourceEventDispatcher);
    synchronized (this) {
        // The map is also accessed on the loading thread so synchronize access.
        trackEmsgHandlerBySampleStream.put(stream, trackPlayerEmsgHandler);
    }
    return stream;
}
Also used : Format(androidx.media3.common.Format) ChunkSampleStream(androidx.media3.exoplayer.source.chunk.ChunkSampleStream) TrackGroup(androidx.media3.common.TrackGroup) ArrayList(java.util.ArrayList) PlayerTrackEmsgHandler(androidx.media3.exoplayer.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler)

Example 5 with TrackGroupInfo

use of androidx.media3.common.TracksInfo.TrackGroupInfo in project media by androidx.

the class DashMediaPeriod method buildTrackGroups.

private static Pair<TrackGroupArray, TrackGroupInfo[]> buildTrackGroups(DrmSessionManager drmSessionManager, List<AdaptationSet> adaptationSets, List<EventStream> eventStreams) {
    int[][] groupedAdaptationSetIndices = getGroupedAdaptationSetIndices(adaptationSets);
    int primaryGroupCount = groupedAdaptationSetIndices.length;
    boolean[] primaryGroupHasEventMessageTrackFlags = new boolean[primaryGroupCount];
    Format[][] primaryGroupClosedCaptionTrackFormats = new Format[primaryGroupCount][];
    int totalEmbeddedTrackGroupCount = identifyEmbeddedTracks(primaryGroupCount, adaptationSets, groupedAdaptationSetIndices, primaryGroupHasEventMessageTrackFlags, primaryGroupClosedCaptionTrackFormats);
    int totalGroupCount = primaryGroupCount + totalEmbeddedTrackGroupCount + eventStreams.size();
    TrackGroup[] trackGroups = new TrackGroup[totalGroupCount];
    TrackGroupInfo[] trackGroupInfos = new TrackGroupInfo[totalGroupCount];
    int trackGroupCount = buildPrimaryAndEmbeddedTrackGroupInfos(drmSessionManager, adaptationSets, groupedAdaptationSetIndices, primaryGroupCount, primaryGroupHasEventMessageTrackFlags, primaryGroupClosedCaptionTrackFormats, trackGroups, trackGroupInfos);
    buildManifestEventTrackGroupInfos(eventStreams, trackGroups, trackGroupInfos, trackGroupCount);
    return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos);
}
Also used : Format(androidx.media3.common.Format) TrackGroup(androidx.media3.common.TrackGroup) TrackGroupArray(androidx.media3.common.TrackGroupArray)

Aggregations

TrackGroup (androidx.media3.common.TrackGroup)6 Format (androidx.media3.common.Format)5 ArrayList (java.util.ArrayList)3 TrackGroupArray (androidx.media3.common.TrackGroupArray)2 TrackGroupInfo (androidx.media3.common.TracksInfo.TrackGroupInfo)2 AdaptationSet (androidx.media3.exoplayer.dash.manifest.AdaptationSet)2 EventStream (androidx.media3.exoplayer.dash.manifest.EventStream)2 ChunkSampleStream (androidx.media3.exoplayer.source.chunk.ChunkSampleStream)2 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)2 SuppressLint (android.annotation.SuppressLint)1 StreamKey (androidx.media3.common.StreamKey)1 TrackSelection (androidx.media3.common.TrackSelection)1 TracksInfo (androidx.media3.common.TracksInfo)1 PlayerTrackEmsgHandler (androidx.media3.exoplayer.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler)1 Representation (androidx.media3.exoplayer.dash.manifest.Representation)1 EmptySampleStream (androidx.media3.exoplayer.source.EmptySampleStream)1 ImmutableList (com.google.common.collect.ImmutableList)1 Test (org.junit.Test)1