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);
}
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);
}
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;
}
}
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;
}
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();
}
Aggregations