use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DefaultSsChunkSource method newMediaChunk.
// Private methods.
private static MediaChunk newMediaChunk(Format format, DataSource dataSource, Uri uri, int chunkIndex, long chunkStartTimeUs, long chunkEndTimeUs, long chunkSeekTimeUs, @C.SelectionReason int trackSelectionReason, @Nullable Object trackSelectionData, ChunkExtractor chunkExtractor) {
DataSpec dataSpec = new DataSpec(uri);
// In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
// To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
long sampleOffsetUs = chunkStartTimeUs;
return new ContainerMediaChunk(dataSource, dataSpec, format, trackSelectionReason, trackSelectionData, chunkStartTimeUs, chunkEndTimeUs, chunkSeekTimeUs, /* clippedEndTimeUs= */
C.TIME_UNSET, chunkIndex, /* chunkCount= */
1, sampleOffsetUs, chunkExtractor);
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DataSourceContractTest method dataSpecWithEndPositionOutOfRange_readsToEnd.
@Test
public void dataSpecWithEndPositionOutOfRange_readsToEnd() throws Exception {
ImmutableList<TestResource> resources = getTestResources();
Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
for (int i = 0; i < resources.size(); i++) {
additionalFailureInfo.setInfo(getFailureLabel(resources, i));
TestResource resource = resources.get(i);
int resourceLength = resource.getExpectedBytes().length;
DataSource dataSource = createDataSource();
DataSpec dataSpec = new DataSpec.Builder().setUri(resource.getUri()).setPosition(resourceLength - 1).setLength(2).build();
try {
long length = dataSource.open(dataSpec);
byte[] data = DataSourceUtil.readExactly(dataSource, /* length= */
1);
// TODO: Decide what the allowed behavior should be for the next read, and assert it.
// The DataSource.open() contract requires the returned length to equal the length in the
// DataSpec if set. This is true even though the DataSource implementation may know that
// fewer bytes will be read in this case.
assertThat(length).isEqualTo(2);
byte[] expectedData = Arrays.copyOfRange(resource.getExpectedBytes(), resourceLength - 1, resourceLength);
assertThat(data).isEqualTo(expectedData);
} finally {
dataSource.close();
}
additionalFailureInfo.setInfo(null);
}
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DataSourceContractTest method dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException.
@Test
public void dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException() throws Exception {
ImmutableList<TestResource> resources = getTestResources();
Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
for (int i = 0; i < resources.size(); i++) {
additionalFailureInfo.setInfo(getFailureLabel(resources, i));
TestResource resource = resources.get(i);
int resourceLength = resource.getExpectedBytes().length;
DataSource dataSource = createDataSource();
DataSpec dataSpec = new DataSpec.Builder().setUri(resource.getUri()).setPosition(resourceLength + 1).build();
try {
IOException exception = assertThrows(IOException.class, () -> dataSource.open(dataSpec));
assertThat(DataSourceException.isCausedByPositionOutOfRange(exception)).isTrue();
} finally {
dataSource.close();
}
additionalFailureInfo.setInfo(null);
}
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DataSourceContractTest method getUri_returnsNonNullValueOnlyWhileOpen.
@Test
public void getUri_returnsNonNullValueOnlyWhileOpen() throws Exception {
ImmutableList<TestResource> resources = getTestResources();
Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
for (int i = 0; i < resources.size(); i++) {
additionalFailureInfo.setInfo(getFailureLabel(resources, i));
TestResource resource = resources.get(i);
DataSource dataSource = createDataSource();
try {
assertThat(dataSource.getUri()).isNull();
dataSource.open(new DataSpec(resource.getUri()));
assertThat(dataSource.getUri()).isNotNull();
} finally {
dataSource.close();
}
assertThat(dataSource.getUri()).isNull();
additionalFailureInfo.setInfo(null);
}
}
use of com.google.android.exoplayer2.upstream.DataSpec in project ExoPlayer by google.
the class DataSourceContractTest method getResponseHeaders_noNullKeysOrValues.
@Test
public void getResponseHeaders_noNullKeysOrValues() throws Exception {
ImmutableList<TestResource> resources = getTestResources();
Assertions.checkArgument(!resources.isEmpty(), "Must provide at least one test resource.");
for (int i = 0; i < resources.size(); i++) {
additionalFailureInfo.setInfo(getFailureLabel(resources, i));
TestResource resource = resources.get(i);
DataSource dataSource = createDataSource();
try {
dataSource.open(new DataSpec(resource.getUri()));
Map<String, List<String>> responseHeaders = dataSource.getResponseHeaders();
assertThat(responseHeaders).doesNotContainKey(null);
assertThat(responseHeaders.values()).doesNotContain(null);
for (List<String> value : responseHeaders.values()) {
assertThat(value).doesNotContain(null);
}
} finally {
dataSource.close();
}
additionalFailureInfo.setInfo(null);
}
}
Aggregations