Search in sources :

Example 21 with AdaptationSet

use of com.google.android.exoplayer2.source.dash.manifest.AdaptationSet in project ExoPlayer by google.

the class DashMediaPeriodTest method cea608AccessibilityDescriptor_createsCea608TrackGroup.

@Test
public void cea608AccessibilityDescriptor_createsCea608TrackGroup() throws IOException {
    DashManifest manifest = parseManifest("media/mpd/sample_mpd_cea_608_accessibility");
    DashMediaPeriod dashMediaPeriod = createDashMediaPeriod(manifest, 0);
    List<AdaptationSet> adaptationSets = manifest.getPeriod(0).adaptationSets;
    // We expect two adaptation sets. The first containing the video representations, and the second
    // containing the embedded CEA-608 tracks.
    Format.Builder cea608FormatBuilder = new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_CEA608);
    TrackGroupArray expectedTrackGroups = new TrackGroupArray(new TrackGroup(/* id= */
    "123", adaptationSets.get(0).representations.get(0).format, adaptationSets.get(0).representations.get(1).format), new TrackGroup(/* id= */
    "123:cc", cea608FormatBuilder.setId("123:cea608:1").setLanguage("eng").setAccessibilityChannel(1).build(), cea608FormatBuilder.setId("123:cea608:3").setLanguage("deu").setAccessibilityChannel(3).build()));
    MediaPeriodAsserts.assertTrackGroups(dashMediaPeriod, expectedTrackGroups);
}
Also used : Format(com.google.android.exoplayer2.Format) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) DashManifest(com.google.android.exoplayer2.source.dash.manifest.DashManifest) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet) Test(org.junit.Test)

Example 22 with AdaptationSet

use of com.google.android.exoplayer2.source.dash.manifest.AdaptationSet 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)

Example 23 with AdaptationSet

use of com.google.android.exoplayer2.source.dash.manifest.AdaptationSet in project ExoPlayer by google.

the class DashMediaPeriod method getClosedCaptionTrackFormats.

private static Format[] getClosedCaptionTrackFormats(List<AdaptationSet> adaptationSets, int[] adaptationSetIndices) {
    for (int i : adaptationSetIndices) {
        AdaptationSet adaptationSet = adaptationSets.get(i);
        List<Descriptor> descriptors = adaptationSets.get(i).accessibilityDescriptors;
        for (int j = 0; j < descriptors.size(); j++) {
            Descriptor descriptor = descriptors.get(j);
            if ("urn:scte:dash:cc:cea-608:2015".equals(descriptor.schemeIdUri)) {
                Format cea608Format = new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_CEA608).setId(adaptationSet.id + ":cea608").build();
                return parseClosedCaptionDescriptor(descriptor, CEA608_SERVICE_DESCRIPTOR_REGEX, cea608Format);
            } else if ("urn:scte:dash:cc:cea-708:2015".equals(descriptor.schemeIdUri)) {
                Format cea708Format = new Format.Builder().setSampleMimeType(MimeTypes.APPLICATION_CEA708).setId(adaptationSet.id + ":cea708").build();
                return parseClosedCaptionDescriptor(descriptor, CEA708_SERVICE_DESCRIPTOR_REGEX, cea708Format);
            }
        }
    }
    return new Format[0];
}
Also used : Format(com.google.android.exoplayer2.Format) Descriptor(com.google.android.exoplayer2.source.dash.manifest.Descriptor) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)

Example 24 with AdaptationSet

use of com.google.android.exoplayer2.source.dash.manifest.AdaptationSet in project ExoPlayer by google.

the class DashManifest method copyAdaptationSets.

private static ArrayList<AdaptationSet> copyAdaptationSets(List<AdaptationSet> adaptationSets, LinkedList<StreamKey> keys) {
    StreamKey key = keys.poll();
    int periodIndex = key.periodIndex;
    ArrayList<AdaptationSet> copyAdaptationSets = new ArrayList<>();
    do {
        int adaptationSetIndex = key.groupIndex;
        AdaptationSet adaptationSet = adaptationSets.get(adaptationSetIndex);
        List<Representation> representations = adaptationSet.representations;
        ArrayList<Representation> copyRepresentations = new ArrayList<>();
        do {
            Representation representation = representations.get(key.streamIndex);
            copyRepresentations.add(representation);
            key = keys.poll();
        } while (key.periodIndex == periodIndex && key.groupIndex == adaptationSetIndex);
        copyAdaptationSets.add(new AdaptationSet(adaptationSet.id, adaptationSet.type, copyRepresentations, adaptationSet.accessibilityDescriptors, adaptationSet.essentialProperties, adaptationSet.supplementalProperties));
    } while (key.periodIndex == periodIndex);
    // Add back the last key which doesn't belong to the period being processed
    keys.addFirst(key);
    return copyAdaptationSets;
}
Also used : ArrayList(java.util.ArrayList) StreamKey(com.google.android.exoplayer2.offline.StreamKey)

Example 25 with AdaptationSet

use of com.google.android.exoplayer2.source.dash.manifest.AdaptationSet in project ExoPlayer by google.

the class DashManifest method copy.

@Override
public final DashManifest copy(List<StreamKey> streamKeys) {
    LinkedList<StreamKey> keys = new LinkedList<>(streamKeys);
    Collections.sort(keys);
    // Add a stopper key to the end
    keys.add(new StreamKey(-1, -1, -1));
    ArrayList<Period> copyPeriods = new ArrayList<>();
    long shiftMs = 0;
    for (int periodIndex = 0; periodIndex < getPeriodCount(); periodIndex++) {
        if (keys.peek().periodIndex != periodIndex) {
            // No representations selected in this period.
            long periodDurationMs = getPeriodDurationMs(periodIndex);
            if (periodDurationMs != C.TIME_UNSET) {
                shiftMs += periodDurationMs;
            }
        } else {
            Period period = getPeriod(periodIndex);
            ArrayList<AdaptationSet> copyAdaptationSets = copyAdaptationSets(period.adaptationSets, keys);
            Period copiedPeriod = new Period(period.id, period.startMs - shiftMs, copyAdaptationSets, period.eventStreams);
            copyPeriods.add(copiedPeriod);
        }
    }
    long newDuration = durationMs != C.TIME_UNSET ? durationMs - shiftMs : C.TIME_UNSET;
    return new DashManifest(availabilityStartTimeMs, newDuration, minBufferTimeMs, dynamic, minUpdatePeriodMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, publishTimeMs, programInformation, utcTiming, serviceDescription, location, copyPeriods);
}
Also used : ArrayList(java.util.ArrayList) StreamKey(com.google.android.exoplayer2.offline.StreamKey) LinkedList(java.util.LinkedList)

Aggregations

AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)16 Format (com.google.android.exoplayer2.Format)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)8 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)7 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)7 DashManifest (com.google.android.exoplayer2.source.dash.manifest.DashManifest)6 Nullable (androidx.annotation.Nullable)5 StreamKey (com.google.android.exoplayer2.offline.StreamKey)4 MultiSegmentRepresentation (com.google.android.exoplayer2.source.dash.manifest.Representation.MultiSegmentRepresentation)3 SingleSegmentRepresentation (com.google.android.exoplayer2.source.dash.manifest.Representation.SingleSegmentRepresentation)3 Descriptor (com.google.android.exoplayer2.source.dash.manifest.Descriptor)2 Period (com.google.android.exoplayer2.source.dash.manifest.Period)2 SingleSegmentBase (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase)2 SparseArray (android.util.SparseArray)1 SparseIntArray (android.util.SparseIntArray)1 DownloadException (com.google.android.exoplayer2.offline.DownloadException)1 ChunkSampleStream (com.google.android.exoplayer2.source.chunk.ChunkSampleStream)1 DashSegmentIndex (com.google.android.exoplayer2.source.dash.DashSegmentIndex)1