Search in sources :

Example 31 with Representation

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

Example 32 with Representation

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

the class DashUtil method loadFormatWithDrmInitData.

/**
 * Loads a {@link Format} for acquiring keys for a given period in a DASH manifest.
 *
 * @param dataSource The {@link HttpDataSource} from which data should be loaded.
 * @param period The {@link Period}.
 * @return The loaded {@link Format}, or null if none is defined.
 * @throws IOException Thrown when there is an error while loading.
 */
@Nullable
public static Format loadFormatWithDrmInitData(DataSource dataSource, Period period) throws IOException {
    @C.TrackType int primaryTrackType = C.TRACK_TYPE_VIDEO;
    Representation representation = getFirstRepresentation(period, primaryTrackType);
    if (representation == null) {
        primaryTrackType = C.TRACK_TYPE_AUDIO;
        representation = getFirstRepresentation(period, primaryTrackType);
        if (representation == null) {
            return null;
        }
    }
    Format manifestFormat = representation.format;
    @Nullable Format sampleFormat = DashUtil.loadSampleFormat(dataSource, primaryTrackType, representation);
    return sampleFormat == null ? manifestFormat : sampleFormat.withManifestFormatInfo(manifestFormat);
}
Also used : Format(com.google.android.exoplayer2.Format) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) Nullable(androidx.annotation.Nullable) Nullable(androidx.annotation.Nullable)

Example 33 with Representation

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

the class DefaultDashChunkSource method updateManifest.

@Override
public void updateManifest(DashManifest newManifest, int newPeriodIndex) {
    try {
        manifest = newManifest;
        periodIndex = newPeriodIndex;
        long periodDurationUs = manifest.getPeriodDurationUs(periodIndex);
        List<Representation> representations = getRepresentations();
        for (int i = 0; i < representationHolders.length; i++) {
            Representation representation = representations.get(trackSelection.getIndexInTrackGroup(i));
            representationHolders[i] = representationHolders[i].copyWithNewRepresentation(periodDurationUs, representation);
        }
    } catch (BehindLiveWindowException e) {
        fatalError = e;
    }
}
Also used : BehindLiveWindowException(com.google.android.exoplayer2.source.BehindLiveWindowException) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation)

Example 34 with Representation

use of com.google.android.exoplayer2.source.dash.manifest.Representation 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 ChunkExtractorWrapper} which contains the output.
   *
   * @param dataSource The source from which the data should be loaded.
   * @param representation The representation which initialization chunk belongs to.
   * @param loadIndex Whether to load index data too.
   * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
   *     initialization or (if requested) index data exists.
   * @throws IOException Thrown when there is an error while loading.
   * @throws InterruptedException Thrown if the thread was interrupted.
   */
private static ChunkExtractorWrapper loadInitializationData(DataSource dataSource, Representation representation, boolean loadIndex) throws IOException, InterruptedException {
    RangedUri initializationUri = representation.getInitializationUri();
    if (initializationUri == null) {
        return null;
    }
    ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(representation.format);
    RangedUri requestUri;
    if (loadIndex) {
        RangedUri indexUri = representation.getIndexUri();
        if (indexUri == null) {
            return null;
        }
        // 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.baseUrl);
        if (requestUri == null) {
            loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
            requestUri = indexUri;
        }
    } else {
        requestUri = initializationUri;
    }
    loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
    return extractorWrapper;
}
Also used : ChunkExtractorWrapper(com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri)

Example 35 with Representation

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

the class DashUtil method loadInitializationData.

private static void loadInitializationData(DataSource dataSource, Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri) throws IOException, InterruptedException {
    DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl), requestUri.start, requestUri.length, representation.getCacheKey());
    InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec, representation.format, C.SELECTION_REASON_UNKNOWN, null, /* trackSelectionData */
    extractorWrapper);
    initializationChunk.load();
}
Also used : InitializationChunk(com.google.android.exoplayer2.source.chunk.InitializationChunk) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Aggregations

Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)18 Nullable (androidx.annotation.Nullable)12 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)10 Format (com.google.android.exoplayer2.Format)9 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)7 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)6 ArrayList (java.util.ArrayList)6 SingleSegmentBase (com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase)5 Test (org.junit.Test)5 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)4 StreamKey (com.google.android.exoplayer2.offline.StreamKey)3 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)3 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 MultiSegmentRepresentation (com.google.android.exoplayer2.source.dash.manifest.Representation.MultiSegmentRepresentation)3 IOException (java.io.IOException)3 DrmInitData (com.google.android.exoplayer2.drm.DrmInitData)2 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)2 DashSegmentIndex (com.google.android.exoplayer2.source.dash.DashSegmentIndex)2