Commit 9e3ef818 by bachinger Committed by Oliver Woodman

Select base URL on demand when a new chunk is created

Instead of selecting the base URL initially or when a load error occurs, it is now selected when a chunk or initialization chunk is created. The selected base URL is then assigned to `RepresentationHolder.lastUsedBaseUrl` that is excluded in case of a load error. For a next chunk another base URL will be selected by using the `BaseUrlExclusionList`.

#minor-release #exo-fixit

PiperOrigin-RevId: 395721221
parent 0c4bb23d
......@@ -51,6 +51,8 @@
* DASH
* Use identical cache keys for downloading and playing DASH segments
([#9370](https://github.com/google/ExoPlayer/issues/9370)).
* Fix base URL selection and load error handling when base URLs are shared
across adaptation sets.
* Remove deprecated symbols:
* Remove `Renderer.VIDEO_SCALING_MODE_*` constants. Use identically named
constants in `C` instead.
......
......@@ -338,6 +338,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
if (segmentNum < firstAvailableSegmentNum) {
chunkIterators[i] = MediaChunkIterator.EMPTY;
} else {
representationHolder = updateSelectedBaseUrl(/* trackIndex= */ i);
chunkIterators[i] =
new RepresentationSegmentIterator(
representationHolder, segmentNum, lastAvailableSegmentNum, nowPeriodTimeUs);
......@@ -350,12 +351,11 @@ public class DefaultDashChunkSource implements DashChunkSource {
playbackPositionUs, bufferedDurationUs, availableLiveDurationUs, queue, chunkIterators);
RepresentationHolder representationHolder =
representationHolders[trackSelection.getSelectedIndex()];
updateSelectedBaseUrl(trackSelection.getSelectedIndex());
if (representationHolder.chunkExtractor != null) {
Representation selectedRepresentation = representationHolder.representation;
RangedUri pendingInitializationUri = null;
RangedUri pendingIndexUri = null;
@Nullable RangedUri pendingInitializationUri = null;
@Nullable RangedUri pendingIndexUri = null;
if (representationHolder.chunkExtractor.getSampleFormats() == null) {
pendingInitializationUri = selectedRepresentation.getInitializationUri();
}
......@@ -495,18 +495,26 @@ public class DefaultDashChunkSource implements DashChunkSource {
int trackIndex = trackSelection.indexOf(chunk.trackFormat);
RepresentationHolder representationHolder = representationHolders[trackIndex];
@Nullable
BaseUrl newBaseUrl =
baseUrlExclusionList.selectBaseUrl(representationHolder.representation.baseUrls);
if (newBaseUrl != null && !representationHolder.selectedBaseUrl.equals(newBaseUrl)) {
// The base URL has changed since the failing chunk was created. Request a replacement chunk,
// which will use the new base URL.
return true;
}
LoadErrorHandlingPolicy.FallbackOptions fallbackOptions =
createFallbackOptions(trackSelection, representationHolder.representation.baseUrls);
if (!fallbackOptions.isFallbackAvailable(LoadErrorHandlingPolicy.FALLBACK_TYPE_TRACK)
&& !fallbackOptions.isFallbackAvailable(LoadErrorHandlingPolicy.FALLBACK_TYPE_LOCATION)) {
// No more alternatives remaining.
return false;
}
@Nullable
LoadErrorHandlingPolicy.FallbackSelection fallbackSelection =
loadErrorHandlingPolicy.getFallbackSelectionFor(fallbackOptions, loadErrorInfo);
if (fallbackSelection == null) {
// Policy indicated to not use any fallback.
if (fallbackSelection == null || !fallbackOptions.isFallbackAvailable(fallbackSelection.type)) {
// Policy indicated to not use any fallback or a fallback type that is not available.
return false;
}
......@@ -518,17 +526,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
} else if (fallbackSelection.type == LoadErrorHandlingPolicy.FALLBACK_TYPE_LOCATION) {
baseUrlExclusionList.exclude(
representationHolder.selectedBaseUrl, fallbackSelection.exclusionDurationMs);
for (int i = 0; i < representationHolders.length; i++) {
@Nullable
BaseUrl baseUrl =
baseUrlExclusionList.selectBaseUrl(representationHolders[i].representation.baseUrls);
if (baseUrl != null) {
if (i == trackIndex) {
cancelLoad = true;
}
representationHolders[i] = representationHolders[i].copyWithNewSelectedBaseUrl(baseUrl);
}
}
cancelLoad = true;
}
return cancelLoad;
}
......@@ -610,9 +608,9 @@ public class DefaultDashChunkSource implements DashChunkSource {
DataSource dataSource,
Format trackFormat,
@C.SelectionReason int trackSelectionReason,
Object trackSelectionData,
@Nullable Object trackSelectionData,
@Nullable RangedUri initializationUri,
RangedUri indexUri) {
@Nullable RangedUri indexUri) {
Representation representation = representationHolder.representation;
@Nullable RangedUri requestUri;
if (initializationUri != null) {
......@@ -719,6 +717,18 @@ public class DefaultDashChunkSource implements DashChunkSource {
}
}
private RepresentationHolder updateSelectedBaseUrl(int trackIndex) {
RepresentationHolder representationHolder = representationHolders[trackIndex];
@Nullable
BaseUrl selectedBaseUrl =
baseUrlExclusionList.selectBaseUrl(representationHolder.representation.baseUrls);
if (selectedBaseUrl != null && !selectedBaseUrl.equals(representationHolder.selectedBaseUrl)) {
representationHolder = representationHolder.copyWithNewSelectedBaseUrl(selectedBaseUrl);
representationHolders[trackIndex] = representationHolder;
}
return representationHolder;
}
// Protected classes.
/** {@link MediaChunkIterator} wrapping a {@link RepresentationHolder}. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment