use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DataSourceContractTest method getUri_resourceNotFound_returnsNullIfNotOpened.
@Test
public void getUri_resourceNotFound_returnsNullIfNotOpened() throws Exception {
DataSource dataSource = createDataSource();
assertThat(dataSource.getUri()).isNull();
assertThrows(IOException.class, () -> dataSource.open(new DataSpec(getNotFoundUri())));
dataSource.close();
assertThat(dataSource.getUri()).isNull();
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DashUtil method loadInitializationData.
private static void loadInitializationData(DataSource dataSource, Representation representation, int baseUrlIndex, ChunkExtractor chunkExtractor, RangedUri requestUri) throws IOException {
DataSpec dataSpec = DashUtil.buildDataSpec(representation, representation.baseUrls.get(baseUrlIndex).url, requestUri, /* flags= */
0);
InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec, representation.format, C.SELECTION_REASON_UNKNOWN, null, /* trackSelectionData */
chunkExtractor);
initializationChunk.load();
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DefaultDashChunkSource method newMediaChunk.
protected Chunk newMediaChunk(RepresentationHolder representationHolder, DataSource dataSource, @C.TrackType int trackType, Format trackFormat, @C.SelectionReason int trackSelectionReason, Object trackSelectionData, long firstSegmentNum, int maxSegmentCount, long seekTimeUs, long nowPeriodTimeUs) {
Representation representation = representationHolder.representation;
long startTimeUs = representationHolder.getSegmentStartTimeUs(firstSegmentNum);
RangedUri segmentUri = representationHolder.getSegmentUrl(firstSegmentNum);
if (representationHolder.chunkExtractor == null) {
long endTimeUs = representationHolder.getSegmentEndTimeUs(firstSegmentNum);
int flags = representationHolder.isSegmentAvailableAtFullNetworkSpeed(firstSegmentNum, nowPeriodTimeUs) ? 0 : DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED;
DataSpec dataSpec = DashUtil.buildDataSpec(representation, representationHolder.selectedBaseUrl.url, segmentUri, flags);
return new SingleSampleMediaChunk(dataSource, dataSpec, trackFormat, trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, firstSegmentNum, trackType, trackFormat);
} else {
int segmentCount = 1;
for (int i = 1; i < maxSegmentCount; i++) {
RangedUri nextSegmentUri = representationHolder.getSegmentUrl(firstSegmentNum + i);
@Nullable RangedUri mergedSegmentUri = segmentUri.attemptMerge(nextSegmentUri, representationHolder.selectedBaseUrl.url);
if (mergedSegmentUri == null) {
// Unable to merge segment fetches because the URIs do not merge.
break;
}
segmentUri = mergedSegmentUri;
segmentCount++;
}
long segmentNum = firstSegmentNum + segmentCount - 1;
long endTimeUs = representationHolder.getSegmentEndTimeUs(segmentNum);
long periodDurationUs = representationHolder.periodDurationUs;
long clippedEndTimeUs = periodDurationUs != C.TIME_UNSET && periodDurationUs <= endTimeUs ? periodDurationUs : C.TIME_UNSET;
int flags = representationHolder.isSegmentAvailableAtFullNetworkSpeed(segmentNum, nowPeriodTimeUs) ? 0 : DataSpec.FLAG_MIGHT_NOT_USE_FULL_NETWORK_SPEED;
DataSpec dataSpec = DashUtil.buildDataSpec(representation, representationHolder.selectedBaseUrl.url, segmentUri, flags);
long sampleOffsetUs = -representation.presentationTimeOffsetUs;
return new ContainerMediaChunk(dataSource, dataSpec, trackFormat, trackSelectionReason, trackSelectionData, startTimeUs, endTimeUs, seekTimeUs, clippedEndTimeUs, firstSegmentNum, segmentCount, sampleOffsetUs, representationHolder.chunkExtractor);
}
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DefaultDashChunkSource method newInitializationChunk.
protected Chunk newInitializationChunk(RepresentationHolder representationHolder, DataSource dataSource, Format trackFormat, @C.SelectionReason int trackSelectionReason, @Nullable Object trackSelectionData, @Nullable RangedUri initializationUri, @Nullable RangedUri indexUri) {
Representation representation = representationHolder.representation;
@Nullable RangedUri requestUri;
if (initializationUri != 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, representationHolder.selectedBaseUrl.url);
if (requestUri == null) {
requestUri = initializationUri;
}
} else {
requestUri = indexUri;
}
DataSpec dataSpec = DashUtil.buildDataSpec(representation, representationHolder.selectedBaseUrl.url, requestUri, /* flags= */
0);
return new InitializationChunk(dataSource, dataSpec, trackFormat, trackSelectionReason, trackSelectionData, representationHolder.chunkExtractor);
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class Aes128DataSource method open.
@Override
public final long open(DataSpec dataSpec) throws IOException {
Cipher cipher;
try {
cipher = getCipherInstance();
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
throw new RuntimeException(e);
}
Key cipherKey = new SecretKeySpec(encryptionKey, "AES");
AlgorithmParameterSpec cipherIV = new IvParameterSpec(encryptionIv);
try {
cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherIV);
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
throw new RuntimeException(e);
}
DataSourceInputStream inputStream = new DataSourceInputStream(upstream, dataSpec);
cipherInputStream = new CipherInputStream(inputStream, cipher);
inputStream.open();
return C.LENGTH_UNSET;
}
Aggregations