use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.
the class DefaultLoadErrorHandlingPolicyTest method getDefaultPolicyFallbackSelection.
@Nullable
private static LoadErrorHandlingPolicy.FallbackSelection getDefaultPolicyFallbackSelection(IOException exception, int numberOfLocations, int numberOfExcludedLocations, int numberOfTracks, int numberOfExcludedTracks) {
LoadErrorInfo loadErrorInfo = new LoadErrorInfo(PLACEHOLDER_LOAD_EVENT_INFO, PLACEHOLDER_MEDIA_LOAD_DATA, exception, /* errorCount= */
1);
LoadErrorHandlingPolicy.FallbackOptions fallbackOptions = new LoadErrorHandlingPolicy.FallbackOptions(numberOfLocations, numberOfExcludedLocations, numberOfTracks, numberOfExcludedTracks);
return new DefaultLoadErrorHandlingPolicy().getFallbackSelectionFor(fallbackOptions, loadErrorInfo);
}
use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.
the class FakeAdaptiveMediaPeriod method selectTracks.
// Casting sample streams created by this class.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
assertThat(prepared).isTrue();
int rendererCount = selections.length;
for (int i = 0; i < rendererCount; i++) {
if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
((ChunkSampleStream<FakeChunkSource>) streams[i]).release();
sampleStreams.remove(streams[i]);
streams[i] = null;
}
if (streams[i] == null && selections[i] != null) {
ExoTrackSelection selection = selections[i];
assertThat(selection.length()).isAtLeast(1);
TrackGroup trackGroup = selection.getTrackGroup();
assertThat(trackGroupArray.indexOf(trackGroup)).isNotEqualTo(C.INDEX_UNSET);
int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
assertThat(indexInTrackGroup).isAtLeast(0);
assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
FakeChunkSource chunkSource = chunkSourceFactory.createChunkSource(selection, durationUs, transferListener);
ChunkSampleStream<FakeChunkSource> sampleStream = new ChunkSampleStream<>(MimeTypes.getTrackType(selection.getSelectedFormat().sampleMimeType), /* embeddedTrackTypes= */
null, /* embeddedTrackFormats= */
null, chunkSource, /* callback= */
this, allocator, positionUs, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */
3), mediaSourceEventDispatcher);
streams[i] = sampleStream;
sampleStreams.add(sampleStream);
streamResetFlags[i] = true;
}
}
sequenceableLoader = new CompositeSequenceableLoader(sampleStreams.toArray(new ChunkSampleStream[0]));
return seekToUs(positionUs);
}
use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.
the class ProgressiveMediaPeriodTest method testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback.
private static void testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(ProgressiveMediaExtractor extractor) throws TimeoutException {
AtomicBoolean sourceInfoRefreshCalled = new AtomicBoolean(false);
ProgressiveMediaPeriod.Listener sourceInfoRefreshListener = (durationUs, isSeekable, isLive) -> sourceInfoRefreshCalled.set(true);
MediaPeriodId mediaPeriodId = new MediaPeriodId(/* periodUid= */
new Object());
ProgressiveMediaPeriod mediaPeriod = new ProgressiveMediaPeriod(Uri.parse("asset://android_asset/media/mp4/sample.mp4"), new AssetDataSource(ApplicationProvider.getApplicationContext()), extractor, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId), new DefaultLoadErrorHandlingPolicy(), new MediaSourceEventListener.EventDispatcher().withParameters(/* windowIndex= */
0, mediaPeriodId, /* mediaTimeOffsetMs= */
0), sourceInfoRefreshListener, new DefaultAllocator(/* trimOnReset= */
true, C.DEFAULT_BUFFER_SEGMENT_SIZE), /* customCacheKey= */
null, ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES);
AtomicBoolean prepareCallbackCalled = new AtomicBoolean(false);
AtomicBoolean sourceInfoRefreshCalledBeforeOnPrepared = new AtomicBoolean(false);
mediaPeriod.prepare(new MediaPeriod.Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
sourceInfoRefreshCalledBeforeOnPrepared.set(sourceInfoRefreshCalled.get());
prepareCallbackCalled.set(true);
}
@Override
public void onContinueLoadingRequested(MediaPeriod source) {
source.continueLoading(/* positionUs= */
0);
}
}, /* positionUs= */
0);
runMainLooperUntil(prepareCallbackCalled::get);
mediaPeriod.release();
assertThat(sourceInfoRefreshCalledBeforeOnPrepared.get()).isTrue();
}
use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.
the class DefaultDashChunkSourceTest method getNextChunk_onChunkLoadErrorTrackExclusionEnabled_correctFallbackBehavior.
@Test
public void getNextChunk_onChunkLoadErrorTrackExclusionEnabled_correctFallbackBehavior() throws Exception {
DefaultLoadErrorHandlingPolicy loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy() {
@Override
public FallbackSelection getFallbackSelectionFor(FallbackOptions fallbackOptions, LoadErrorInfo loadErrorInfo) {
// Exclude tracks only.
return new FallbackSelection(FALLBACK_TYPE_TRACK, DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_EXCLUSION_MS);
}
};
DashChunkSource chunkSource = createDashChunkSource(/* numberOfTracks= */
4);
ChunkHolder output = new ChunkHolder();
List<Chunk> chunks = new ArrayList<>();
boolean requestReplacementChunk = true;
while (requestReplacementChunk) {
chunkSource.getNextChunk(/* playbackPositionUs= */
0, /* loadPositionUs= */
0, /* queue= */
ImmutableList.of(), output);
chunks.add(output.chunk);
requestReplacementChunk = chunkSource.onChunkLoadError(checkNotNull(output.chunk), /* cancelable= */
true, createFakeLoadErrorInfo(output.chunk.dataSpec, /* httpResponseCode= */
404, /* errorCount= */
1), loadErrorHandlingPolicy);
}
assertThat(Lists.transform(chunks, (chunk) -> chunk.dataSpec.uri.toString())).containsExactly("http://video.com/baseUrl/a/video/video_0_700000.m4s", "http://video.com/baseUrl/a/video/video_0_452000.m4s", "http://video.com/baseUrl/a/video/video_0_250000.m4s", "http://video.com/baseUrl/a/video/video_0_1300000.m4s").inOrder();
}
use of androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy in project media by androidx.
the class DefaultDashChunkSourceTest method getNextChunk_onChunkLoadErrorExclusionDisabled_neverRequestReplacementChunk.
@Test
public void getNextChunk_onChunkLoadErrorExclusionDisabled_neverRequestReplacementChunk() throws Exception {
DefaultLoadErrorHandlingPolicy loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy() {
@Override
@Nullable
public FallbackSelection getFallbackSelectionFor(FallbackOptions fallbackOptions, LoadErrorInfo loadErrorInfo) {
// Never exclude, neither tracks nor locations.
return null;
}
};
DashChunkSource chunkSource = createDashChunkSource(/* numberOfTracks= */
2);
ChunkHolder output = new ChunkHolder();
chunkSource.getNextChunk(/* playbackPositionUs= */
0, /* loadPositionUs= */
0, /* queue= */
ImmutableList.of(), output);
boolean requestReplacementChunk = chunkSource.onChunkLoadError(checkNotNull(output.chunk), /* cancelable= */
true, createFakeLoadErrorInfo(output.chunk.dataSpec, /* httpResponseCode= */
404, /* errorCount= */
1), loadErrorHandlingPolicy);
assertThat(requestReplacementChunk).isFalse();
}
Aggregations