Search in sources :

Example 11 with RangedUri

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

the class DashUtilTest method resolveCacheKey_representationCacheKeyIsNull_resolvesRangedUriWithFirstBaseUrl.

@Test
public void resolveCacheKey_representationCacheKeyIsNull_resolvesRangedUriWithFirstBaseUrl() {
    ImmutableList<BaseUrl> baseUrls = ImmutableList.of(new BaseUrl("http://www.google.com"), new BaseUrl("http://www.foo.com"));
    Representation.SingleSegmentRepresentation representation = new Representation.SingleSegmentRepresentation(/* revisionId= */
    1L, new Format.Builder().build(), baseUrls, new SingleSegmentBase(), /* inbandEventStreams= */
    null, /* essentialProperties= */
    ImmutableList.of(), /* supplementalProperties= */
    ImmutableList.of(), /* cacheKey= */
    null, /* contentLength= */
    1);
    RangedUri rangedUri = new RangedUri("path/to/resource", /* start= */
    0, /* length= */
    1);
    String cacheKey = DashUtil.resolveCacheKey(representation, rangedUri);
    assertThat(cacheKey).isEqualTo("http://www.google.com/path/to/resource");
}
Also used : SingleSegmentBase(com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) BaseUrl(com.google.android.exoplayer2.source.dash.manifest.BaseUrl) Test(org.junit.Test)

Example 12 with RangedUri

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

Example 13 with RangedUri

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

the class DashManifestParserTest method parseMediaPresentationDescription_segmentTemplate.

@Test
public void parseMediaPresentationDescription_segmentTemplate() throws IOException {
    DashManifestParser parser = new DashManifestParser();
    DashManifest manifest = parser.parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_SEGMENT_TEMPLATE));
    assertThat(manifest.getPeriodCount()).isEqualTo(1);
    Period period = manifest.getPeriod(0);
    assertThat(period).isNotNull();
    assertThat(period.adaptationSets).hasSize(2);
    for (AdaptationSet adaptationSet : period.adaptationSets) {
        assertThat(adaptationSet).isNotNull();
        for (Representation representation : adaptationSet.representations) {
            if (representation instanceof Representation.MultiSegmentRepresentation) {
                Representation.MultiSegmentRepresentation multiSegmentRepresentation = (Representation.MultiSegmentRepresentation) representation;
                long firstSegmentIndex = multiSegmentRepresentation.getFirstSegmentNum();
                RangedUri uri = multiSegmentRepresentation.getSegmentUrl(firstSegmentIndex);
                assertThat(uri.resolveUriString(representation.baseUrls.get(0).url)).contains("redirector.googlevideo.com");
            }
        }
    }
}
Also used : SingleSegmentRepresentation(com.google.android.exoplayer2.source.dash.manifest.Representation.SingleSegmentRepresentation) MultiSegmentRepresentation(com.google.android.exoplayer2.source.dash.manifest.Representation.MultiSegmentRepresentation) MultiSegmentRepresentation(com.google.android.exoplayer2.source.dash.manifest.Representation.MultiSegmentRepresentation) MultiSegmentRepresentation(com.google.android.exoplayer2.source.dash.manifest.Representation.MultiSegmentRepresentation) Test(org.junit.Test)

Example 14 with RangedUri

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

the class DashUtil method loadInitializationData.

/**
 * Loads initialization data for the {@code representation} and optionally index data then returns
 * a {@link BundledChunkExtractor} which contains the output.
 *
 * @param chunkExtractor The {@link ChunkExtractor} to use.
 * @param dataSource The source from which the data should be loaded.
 * @param representation The representation which initialization chunk belongs to.
 * @param baseUrlIndex The index of the base URL with which to resolve the request URI.
 * @param loadIndex Whether to load index data too.
 * @throws IOException Thrown when there is an error while loading.
 */
private static void loadInitializationData(ChunkExtractor chunkExtractor, DataSource dataSource, Representation representation, int baseUrlIndex, boolean loadIndex) throws IOException {
    RangedUri initializationUri = Assertions.checkNotNull(representation.getInitializationUri());
    @Nullable RangedUri requestUri;
    if (loadIndex) {
        @Nullable RangedUri indexUri = representation.getIndexUri();
        if (indexUri == null) {
            return;
        }
        // It's common for initialization and index data to be stored adjacently. Attempt to merge
        // the two requests together to request both at once.
        requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrls.get(baseUrlIndex).url);
        if (requestUri == null) {
            loadInitializationData(dataSource, representation, baseUrlIndex, chunkExtractor, initializationUri);
            requestUri = indexUri;
        }
    } else {
        requestUri = initializationUri;
    }
    loadInitializationData(dataSource, representation, baseUrlIndex, chunkExtractor, requestUri);
}
Also used : RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri) Nullable(androidx.annotation.Nullable)

Aggregations

RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)10 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)8 Nullable (androidx.annotation.Nullable)5 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)3 InitializationChunk (com.google.android.exoplayer2.source.chunk.InitializationChunk)3 SingleSampleMediaChunk (com.google.android.exoplayer2.source.chunk.SingleSampleMediaChunk)3 SingleSegmentBase (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase)3 Test (org.junit.Test)3 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)2 BaseUrl (com.google.android.exoplayer2.source.dash.manifest.BaseUrl)2 Format (com.google.android.exoplayer2.Format)1 DownloadException (com.google.android.exoplayer2.offline.DownloadException)1 BaseMediaChunkIterator (com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator)1 ChunkExtractorWrapper (com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper)1 MediaChunk (com.google.android.exoplayer2.source.chunk.MediaChunk)1 MediaChunkIterator (com.google.android.exoplayer2.source.chunk.MediaChunkIterator)1 DashSegmentIndex (com.google.android.exoplayer2.source.dash.DashSegmentIndex)1 MultiSegmentRepresentation (com.google.android.exoplayer2.source.dash.manifest.Representation.MultiSegmentRepresentation)1 SingleSegmentRepresentation (com.google.android.exoplayer2.source.dash.manifest.Representation.SingleSegmentRepresentation)1