use of androidx.media3.datasource.DataSource in project media by androidx.
the class OkHttpDataSourceTest method open_setsCorrectHeaders.
/**
* This test will set HTTP default request parameters (1) in the OkHttpDataSource, (2) via
* OkHttpDataSource.setRequestProperty() and (3) in the DataSpec instance according to the table
* below. Values wrapped in '*' are the ones that should be set in the connection request.
*
* <pre>{@code
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | | Header Key |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | Location | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | Constructor | *Y* | Y | Y | | Y | | |
* | Setter | | *Y* | Y | Y | | *Y* | |
* | DataSpec | | | *Y* | *Y* | *Y* | | *Y* |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* }</pre>
*/
@Test
public void open_setsCorrectHeaders() throws Exception {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.enqueue(new MockResponse());
String propertyFromFactory = "fromFactory";
Map<String, String> defaultRequestProperties = new HashMap<>();
defaultRequestProperties.put("0", propertyFromFactory);
defaultRequestProperties.put("1", propertyFromFactory);
defaultRequestProperties.put("2", propertyFromFactory);
defaultRequestProperties.put("4", propertyFromFactory);
HttpDataSource dataSource = new OkHttpDataSource.Factory(new OkHttpClient()).setDefaultRequestProperties(defaultRequestProperties).createDataSource();
String propertyFromSetter = "fromSetter";
dataSource.setRequestProperty("1", propertyFromSetter);
dataSource.setRequestProperty("2", propertyFromSetter);
dataSource.setRequestProperty("3", propertyFromSetter);
dataSource.setRequestProperty("5", propertyFromSetter);
String propertyFromDataSpec = "fromDataSpec";
Map<String, String> dataSpecRequestProperties = new HashMap<>();
dataSpecRequestProperties.put("2", propertyFromDataSpec);
dataSpecRequestProperties.put("3", propertyFromDataSpec);
dataSpecRequestProperties.put("4", propertyFromDataSpec);
dataSpecRequestProperties.put("6", propertyFromDataSpec);
DataSpec dataSpec = new DataSpec.Builder().setUri(mockWebServer.url("/test-path").toString()).setHttpRequestHeaders(dataSpecRequestProperties).build();
dataSource.open(dataSpec);
Headers headers = mockWebServer.takeRequest(10, SECONDS).getHeaders();
assertThat(headers.get("0")).isEqualTo(propertyFromFactory);
assertThat(headers.get("1")).isEqualTo(propertyFromSetter);
assertThat(headers.get("2")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("3")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("4")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("5")).isEqualTo(propertyFromSetter);
assertThat(headers.get("6")).isEqualTo(propertyFromDataSpec);
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekToZero.
@Test
public void seeking_seekTable_handlesSeekToZero() throws IOException {
String fileName = TEST_FILE_SEEK_TABLE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = 0;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekingForward.
@Test
public void seeking_seekTable_handlesSeekingForward() throws IOException {
String fileName = TEST_FILE_SEEK_TABLE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 987_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 1_234_000;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class FlacExtractorSeekTest method seeking_binarySearch_handlesSeekingForward.
@Test
public void seeking_binarySearch_handlesSeekingForward() throws IOException {
String fileName = TEST_FILE_BINARY_SEARCH;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 987_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 1_234_000;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekContainsTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of androidx.media3.datasource.DataSource in project media by androidx.
the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekToEoF.
@Test
public void seeking_seekTable_handlesSeekToEoF() throws IOException {
String fileName = TEST_FILE_SEEK_TABLE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = seekMap.getDurationUs();
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Aggregations