Search in sources :

Example 1 with TrackGroupInfo

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

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(com.google.android.exoplayer2.Format) ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ArrayList(java.util.ArrayList) PlayerTrackEmsgHandler(com.google.android.exoplayer2.source.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler)

Example 2 with TrackGroupInfo

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

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(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray)

Example 3 with TrackGroupInfo

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

the class DashMediaPeriod method buildPrimaryAndEmbeddedTrackGroupInfos.

private static int buildPrimaryAndEmbeddedTrackGroupInfos(DrmSessionManager drmSessionManager, List<AdaptationSet> adaptationSets, int[][] groupedAdaptationSetIndices, int primaryGroupCount, boolean[] primaryGroupHasEventMessageTrackFlags, Format[][] primaryGroupClosedCaptionTrackFormats, TrackGroup[] trackGroups, TrackGroupInfo[] trackGroupInfos) {
    int trackGroupCount = 0;
    for (int i = 0; i < primaryGroupCount; i++) {
        int[] adaptationSetIndices = groupedAdaptationSetIndices[i];
        List<Representation> representations = new ArrayList<>();
        for (int adaptationSetIndex : adaptationSetIndices) {
            representations.addAll(adaptationSets.get(adaptationSetIndex).representations);
        }
        Format[] formats = new Format[representations.size()];
        for (int j = 0; j < formats.length; j++) {
            Format format = representations.get(j).format;
            formats[j] = format.copyWithCryptoType(drmSessionManager.getCryptoType(format));
        }
        AdaptationSet firstAdaptationSet = adaptationSets.get(adaptationSetIndices[0]);
        String trackGroupId = firstAdaptationSet.id != AdaptationSet.ID_UNSET ? Integer.toString(firstAdaptationSet.id) : ("unset:" + i);
        int primaryTrackGroupIndex = trackGroupCount++;
        int eventMessageTrackGroupIndex = primaryGroupHasEventMessageTrackFlags[i] ? trackGroupCount++ : C.INDEX_UNSET;
        int closedCaptionTrackGroupIndex = primaryGroupClosedCaptionTrackFormats[i].length != 0 ? trackGroupCount++ : C.INDEX_UNSET;
        trackGroups[primaryTrackGroupIndex] = new TrackGroup(trackGroupId, formats);
        trackGroupInfos[primaryTrackGroupIndex] = TrackGroupInfo.primaryTrack(firstAdaptationSet.type, adaptationSetIndices, primaryTrackGroupIndex, eventMessageTrackGroupIndex, closedCaptionTrackGroupIndex);
        if (eventMessageTrackGroupIndex != C.INDEX_UNSET) {
            String eventMessageTrackGroupId = trackGroupId + ":emsg";
            Format format = new Format.Builder().setId(eventMessageTrackGroupId).setSampleMimeType(MimeTypes.APPLICATION_EMSG).build();
            trackGroups[eventMessageTrackGroupIndex] = new TrackGroup(eventMessageTrackGroupId, format);
            trackGroupInfos[eventMessageTrackGroupIndex] = TrackGroupInfo.embeddedEmsgTrack(adaptationSetIndices, primaryTrackGroupIndex);
        }
        if (closedCaptionTrackGroupIndex != C.INDEX_UNSET) {
            String closedCaptionTrackGroupId = trackGroupId + ":cc";
            trackGroups[closedCaptionTrackGroupIndex] = new TrackGroup(closedCaptionTrackGroupId, primaryGroupClosedCaptionTrackFormats[i]);
            trackGroupInfos[closedCaptionTrackGroupIndex] = TrackGroupInfo.embeddedClosedCaptionTrack(adaptationSetIndices, primaryTrackGroupIndex);
        }
    }
    return trackGroupCount;
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) ArrayList(java.util.ArrayList) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)

Example 4 with TrackGroupInfo

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

the class DashMediaPeriod method selectNewStreams.

private void selectNewStreams(ExoTrackSelection[] selections, SampleStream[] streams, boolean[] streamResetFlags, long positionUs, int[] streamIndexToTrackGroupIndex) {
    // Create newly selected primary and event streams.
    for (int i = 0; i < selections.length; i++) {
        ExoTrackSelection selection = selections[i];
        if (selection == null) {
            continue;
        }
        if (streams[i] == null) {
            // Create new stream for selection.
            streamResetFlags[i] = true;
            int trackGroupIndex = streamIndexToTrackGroupIndex[i];
            TrackGroupInfo trackGroupInfo = trackGroupInfos[trackGroupIndex];
            if (trackGroupInfo.trackGroupCategory == TrackGroupInfo.CATEGORY_PRIMARY) {
                streams[i] = buildSampleStream(trackGroupInfo, selection, positionUs);
            } else if (trackGroupInfo.trackGroupCategory == TrackGroupInfo.CATEGORY_MANIFEST_EVENTS) {
                EventStream eventStream = eventStreams.get(trackGroupInfo.eventStreamGroupIndex);
                Format format = selection.getTrackGroup().getFormat(0);
                streams[i] = new EventSampleStream(eventStream, format, manifest.dynamic);
            }
        } else if (streams[i] instanceof ChunkSampleStream) {
            // Update selection in existing stream.
            @SuppressWarnings("unchecked") ChunkSampleStream<DashChunkSource> stream = (ChunkSampleStream<DashChunkSource>) streams[i];
            stream.getChunkSource().updateTrackSelection(selection);
        }
    }
    // pass if the index of the primary stream is greater than the index of the embedded stream.
    for (int i = 0; i < selections.length; i++) {
        if (streams[i] == null && selections[i] != null) {
            int trackGroupIndex = streamIndexToTrackGroupIndex[i];
            TrackGroupInfo trackGroupInfo = trackGroupInfos[trackGroupIndex];
            if (trackGroupInfo.trackGroupCategory == TrackGroupInfo.CATEGORY_EMBEDDED) {
                int primaryStreamIndex = getPrimaryStreamIndex(i, streamIndexToTrackGroupIndex);
                if (primaryStreamIndex == C.INDEX_UNSET) {
                    // If an embedded track is selected without the corresponding primary track, create an
                    // empty sample stream instead.
                    streams[i] = new EmptySampleStream();
                } else {
                    streams[i] = ((ChunkSampleStream) streams[primaryStreamIndex]).selectEmbeddedTrack(positionUs, trackGroupInfo.trackType);
                }
            }
        }
    }
}
Also used : Format(com.google.android.exoplayer2.Format) EmptySampleStream(com.google.android.exoplayer2.source.EmptySampleStream) ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) EventStream(com.google.android.exoplayer2.source.dash.manifest.EventStream)

Example 5 with TrackGroupInfo

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

the class DashMediaPeriod method getStreamKeys.

@Override
public List<StreamKey> getStreamKeys(List<ExoTrackSelection> trackSelections) {
    List<AdaptationSet> manifestAdaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
    List<StreamKey> streamKeys = new ArrayList<>();
    for (ExoTrackSelection trackSelection : trackSelections) {
        int trackGroupIndex = trackGroups.indexOf(trackSelection.getTrackGroup());
        TrackGroupInfo trackGroupInfo = trackGroupInfos[trackGroupIndex];
        if (trackGroupInfo.trackGroupCategory != TrackGroupInfo.CATEGORY_PRIMARY) {
            // Ignore non-primary tracks.
            continue;
        }
        int[] adaptationSetIndices = trackGroupInfo.adaptationSetIndices;
        int[] trackIndices = new int[trackSelection.length()];
        for (int i = 0; i < trackSelection.length(); i++) {
            trackIndices[i] = trackSelection.getIndexInTrackGroup(i);
        }
        Arrays.sort(trackIndices);
        int currentAdaptationSetIndex = 0;
        int totalTracksInPreviousAdaptationSets = 0;
        int tracksInCurrentAdaptationSet = manifestAdaptationSets.get(adaptationSetIndices[0]).representations.size();
        for (int trackIndex : trackIndices) {
            while (trackIndex >= totalTracksInPreviousAdaptationSets + tracksInCurrentAdaptationSet) {
                currentAdaptationSetIndex++;
                totalTracksInPreviousAdaptationSets += tracksInCurrentAdaptationSet;
                tracksInCurrentAdaptationSet = manifestAdaptationSets.get(adaptationSetIndices[currentAdaptationSetIndex]).representations.size();
            }
            streamKeys.add(new StreamKey(periodIndex, adaptationSetIndices[currentAdaptationSetIndex], trackIndex - totalTracksInPreviousAdaptationSets));
        }
    }
    return streamKeys;
}
Also used : ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) ArrayList(java.util.ArrayList) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Aggregations

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