Search in sources :

Example 1 with DataSource

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) OkHttpClient(okhttp3.OkHttpClient) HashMap(java.util.HashMap) Headers(okhttp3.Headers) MockWebServer(okhttp3.mockwebserver.MockWebServer) DataSpec(androidx.media3.datasource.DataSpec) HttpDataSource(androidx.media3.datasource.HttpDataSource) Test(org.junit.Test)

Example 2 with DataSource

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);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 3 with DataSource

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);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 4 with DataSource

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);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 5 with DataSource

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);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)101 Uri (android.net.Uri)72 SeekMap (androidx.media3.extractor.SeekMap)65 DataSpec (androidx.media3.datasource.DataSpec)56 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)50 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)29 DataSource (androidx.media3.datasource.DataSource)25 Nullable (androidx.annotation.Nullable)13 IOException (java.io.IOException)13 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)12 ExtractorInput (androidx.media3.extractor.ExtractorInput)10 FakeDataSource (androidx.media3.test.utils.FakeDataSource)10 StatsDataSource (androidx.media3.datasource.StatsDataSource)8 FakeDataSet (androidx.media3.test.utils.FakeDataSet)7 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)5 Representation (androidx.media3.exoplayer.dash.manifest.Representation)5 Before (org.junit.Before)5 Format (androidx.media3.common.Format)3 DataSourceInputStream (androidx.media3.datasource.DataSourceInputStream)3 FileDataSource (androidx.media3.datasource.FileDataSource)3