提交 1a3de408 编写于 作者: O olly 提交者: Oliver Woodman

A few bug fixes.

1. Suppress onContinueLoadingRequested until a source is
   prepared (since such calls are not supposed to be made
   until after preparation has completed).
2. Don't use the format evaluator in HlsChunkSource prior
   to prepration completing.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=126794616
上级 8c0e0b69
......@@ -192,6 +192,10 @@ public final class MultiSampleSource implements SampleSource, SampleSource.Callb
@Override
public void onContinueLoadingRequested(SampleSource ignored) {
if (trackGroups == null) {
// Still preparing.
return;
}
callback.onContinueLoadingRequested(this);
}
......
......@@ -75,7 +75,6 @@ public class HlsChunkSource {
private final Variant[] variants;
private final HlsMediaPlaylist[] variantPlaylists;
private final long[] variantLastPlaylistLoadTimesMs;
private final int initialEnabledVariantIndex;
private boolean seenFirstExternalTrackSelection;
private byte[] scratchSpace;
......@@ -119,7 +118,6 @@ public class HlsChunkSource {
initialTrackSelection[i] = i;
}
selectTracksInternal(initialTrackSelection, false);
initialEnabledVariantIndex = getEnabledVariantIndex(variants[0].format);
}
/**
......@@ -440,6 +438,10 @@ public class HlsChunkSource {
enabledVariantBlacklistTimes = new long[enabledVariants.length];
enabledVariantBlacklistFlags = new boolean[enabledVariants.length];
if (!isExternal) {
return;
}
if (enabledVariants.length > 1) {
Format[] formats = new Format[enabledVariants.length];
for (int i = 0; i < formats.length; i++) {
......@@ -458,24 +460,36 @@ public class HlsChunkSource {
private void updateFormatEvaluation(HlsMediaChunk previous, long playbackPositionUs) {
clearStaleBlacklistedVariants();
if (!seenFirstExternalTrackSelection
&& !enabledVariantBlacklistFlags[initialEnabledVariantIndex]) {
// Use the first variant prior to external track selection, unless it's been blacklisted.
evaluation.format = variants[0].format;
} else if (enabledVariants.length > 1) {
long bufferedDurationUs;
if (previous != null) {
// Use start time of the previous chunk rather than its end time because switching format
// will require downloading overlapping segments.
bufferedDurationUs = Math.max(0, previous.startTimeUs - playbackPositionUs);
} else {
bufferedDurationUs = 0;
if (!seenFirstExternalTrackSelection) {
if (!enabledVariantBlacklistFlags[getEnabledVariantIndex(variants[0].format)]) {
// Use the first variant prior to external track selection, unless it's been blacklisted.
evaluation.format = variants[0].format;
return;
}
adaptiveFormatEvaluator.evaluateFormat(bufferedDurationUs, enabledVariantBlacklistFlags,
evaluation);
} else {
// Try from lowest bitrate to highest.
for (int i = enabledVariants.length - 1; i >= 0; i--) {
if (!enabledVariantBlacklistFlags[i]) {
evaluation.format = enabledVariants[i].format;
return;
}
}
// Should never happen.
throw new IllegalStateException();
}
if (enabledVariants.length == 1) {
evaluation.format = enabledVariants[0].format;
return;
}
long bufferedDurationUs;
if (previous != null) {
// Use start time of the previous chunk rather than its end time because switching format
// will require downloading overlapping segments.
bufferedDurationUs = Math.max(0, previous.startTimeUs - playbackPositionUs);
} else {
bufferedDurationUs = 0;
}
adaptiveFormatEvaluator.evaluateFormat(bufferedDurationUs, enabledVariantBlacklistFlags,
evaluation);
}
private boolean shouldRerequestLiveMediaPlaylist(int variantIndex) {
......
......@@ -284,6 +284,10 @@ public final class HlsSampleSource implements SampleSource,
@Override
public void onContinueLoadingRequested(HlsTrackStreamWrapper trackStreamWrapper) {
if (trackGroups == null) {
// Still preparing.
return;
}
callback.onContinueLoadingRequested(this);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册