Search in sources :

Example 6 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class FlacExtractorSeekTest method flacExtractorReads_seekTable_returnSeekableSeekMap.

@Test
public void flacExtractorReads_seekTable_returnSeekableSeekMap() throws IOException {
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_SEEK_TABLE);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 7 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class DefaultDataSourceTest method openRtmpDataSpec_instantiatesRtmpDataSourceViaReflection.

@Test
public void openRtmpDataSpec_instantiatesRtmpDataSourceViaReflection() throws IOException {
    DefaultDataSource dataSource = new DefaultDataSource(ApplicationProvider.getApplicationContext(), "userAgent", /* allowCrossProtocolRedirects= */
    false);
    DataSpec dataSpec = new DataSpec(Uri.parse("rtmp://test.com/stream"));
    try {
        dataSource.open(dataSpec);
    } catch (UnsatisfiedLinkError e) {
    // RtmpDataSource was successfully instantiated (test run using Gradle).
    } catch (UnsupportedOperationException e) {
    // RtmpDataSource was successfully instantiated (test run using Blaze).
    }
}
Also used : DefaultDataSource(androidx.media3.datasource.DefaultDataSource) DataSpec(androidx.media3.datasource.DataSpec) Test(org.junit.Test)

Example 8 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekingBackward.

@Test
public void seeking_seekTable_handlesSeekingBackward() 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 = 1_234_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 987_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 9 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class FlacExtractorSeekTest method flacExtractorReads_binarySearch_returnSeekableSeekMap.

@Test
public void flacExtractorReads_binarySearch_returnSeekableSeekMap() throws IOException {
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE_BINARY_SEARCH);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 10 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class SingleSampleMediaPeriod method onLoadError.

@Override
public LoadErrorAction onLoadError(SourceLoadable loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error, int errorCount) {
    StatsDataSource dataSource = loadable.dataSource;
    LoadEventInfo loadEventInfo = new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, dataSource.getLastOpenedUri(), dataSource.getLastResponseHeaders(), elapsedRealtimeMs, loadDurationMs, dataSource.getBytesRead());
    MediaLoadData mediaLoadData = new MediaLoadData(C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeMs= */
    0, Util.usToMs(durationUs));
    long retryDelay = loadErrorHandlingPolicy.getRetryDelayMsFor(new LoadErrorInfo(loadEventInfo, mediaLoadData, error, errorCount));
    boolean errorCanBePropagated = retryDelay == C.TIME_UNSET || errorCount >= loadErrorHandlingPolicy.getMinimumLoadableRetryCount(C.DATA_TYPE_MEDIA);
    LoadErrorAction action;
    if (treatLoadErrorsAsEndOfStream && errorCanBePropagated) {
        Log.w(TAG, "Loading failed, treating as end-of-stream.", error);
        loadingFinished = true;
        action = Loader.DONT_RETRY;
    } else {
        action = retryDelay != C.TIME_UNSET ? Loader.createRetryAction(/* resetErrorCount= */
        false, retryDelay) : Loader.DONT_RETRY_FATAL;
    }
    boolean wasCanceled = !action.isRetry();
    eventDispatcher.loadError(loadEventInfo, C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, format, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeUs= */
    0, durationUs, error, wasCanceled);
    if (wasCanceled) {
        loadErrorHandlingPolicy.onLoadTaskConcluded(loadable.loadTaskId);
    }
    return action;
}
Also used : LoadErrorInfo(androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy.LoadErrorInfo) StatsDataSource(androidx.media3.datasource.StatsDataSource) LoadErrorAction(androidx.media3.exoplayer.upstream.Loader.LoadErrorAction)

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