Search in sources :

Example 26 with AdaptationSet

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

the class DashDownloader method getSegments.

@Override
protected List<Segment> getSegments(DataSource dataSource, DashManifest manifest, boolean removing) throws IOException, InterruptedException {
    ArrayList<Segment> segments = new ArrayList<>();
    for (int i = 0; i < manifest.getPeriodCount(); i++) {
        Period period = manifest.getPeriod(i);
        long periodStartUs = Util.msToUs(period.startMs);
        long periodDurationUs = manifest.getPeriodDurationUs(i);
        List<AdaptationSet> adaptationSets = period.adaptationSets;
        for (int j = 0; j < adaptationSets.size(); j++) {
            addSegmentsForAdaptationSet(dataSource, adaptationSets.get(j), periodStartUs, periodDurationUs, removing, segments);
        }
    }
    return segments;
}
Also used : ArrayList(java.util.ArrayList) Period(com.google.android.exoplayer2.source.dash.manifest.Period) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)

Example 27 with AdaptationSet

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

the class DashDownloader method addSegmentsForAdaptationSet.

private void addSegmentsForAdaptationSet(DataSource dataSource, AdaptationSet adaptationSet, long periodStartUs, long periodDurationUs, boolean removing, ArrayList<Segment> out) throws IOException, InterruptedException {
    for (int i = 0; i < adaptationSet.representations.size(); i++) {
        Representation representation = adaptationSet.representations.get(i);
        DashSegmentIndex index;
        try {
            index = getSegmentIndex(dataSource, adaptationSet.type, representation, removing);
            if (index == null) {
                // Loading succeeded but there was no index.
                throw new DownloadException("Missing segment index");
            }
        } catch (IOException e) {
            if (!removing) {
                throw e;
            }
            // Generating an incomplete segment list is allowed. Advance to the next representation.
            continue;
        }
        long segmentCount = index.getSegmentCount(periodDurationUs);
        if (segmentCount == DashSegmentIndex.INDEX_UNBOUNDED) {
            throw new DownloadException("Unbounded segment index");
        }
        String baseUrl = castNonNull(baseUrlExclusionList.selectBaseUrl(representation.baseUrls)).url;
        @Nullable RangedUri initializationUri = representation.getInitializationUri();
        if (initializationUri != null) {
            out.add(createSegment(representation, baseUrl, periodStartUs, initializationUri));
        }
        @Nullable RangedUri indexUri = representation.getIndexUri();
        if (indexUri != null) {
            out.add(createSegment(representation, baseUrl, periodStartUs, indexUri));
        }
        long firstSegmentNum = index.getFirstSegmentNum();
        long lastSegmentNum = firstSegmentNum + segmentCount - 1;
        for (long j = firstSegmentNum; j <= lastSegmentNum; j++) {
            out.add(createSegment(representation, baseUrl, periodStartUs + index.getTimeUs(j), index.getSegmentUrl(j)));
        }
    }
}
Also used : DownloadException(com.google.android.exoplayer2.offline.DownloadException) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) IOException(java.io.IOException) DashSegmentIndex(com.google.android.exoplayer2.source.dash.DashSegmentIndex) Nullable(androidx.annotation.Nullable)

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