Simplify some buffered position related code.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215704344
This commit is contained in:
tonihei 2018-10-04 02:06:32 -07:00 committed by Oliver Woodman
parent 7849a5eb52
commit 9ca6544311
2 changed files with 21 additions and 19 deletions

View File

@ -496,10 +496,8 @@ import java.util.Collections;
// Update the buffered position and total buffered duration. // Update the buffered position and total buffered duration.
MediaPeriodHolder loadingPeriod = queue.getLoadingPeriod(); MediaPeriodHolder loadingPeriod = queue.getLoadingPeriod();
playbackInfo.bufferedPositionUs = playbackInfo.bufferedPositionUs = loadingPeriod.getBufferedPositionUs();
loadingPeriod.getBufferedPositionUs(/* convertEosToDuration= */ true); playbackInfo.totalBufferedDurationUs = getTotalBufferedDurationUs();
playbackInfo.totalBufferedDurationUs =
playbackInfo.bufferedPositionUs - loadingPeriod.toPeriodTime(rendererPositionUs);
} }
private void doSomeWork() throws ExoPlaybackException, IOException { private void doSomeWork() throws ExoPlaybackException, IOException {
@ -1097,12 +1095,10 @@ import java.util.Collections;
} }
// Renderers are ready and we're loading. Ask the LoadControl whether to transition. // Renderers are ready and we're loading. Ask the LoadControl whether to transition.
MediaPeriodHolder loadingHolder = queue.getLoadingPeriod(); MediaPeriodHolder loadingHolder = queue.getLoadingPeriod();
long bufferedPositionUs = loadingHolder.getBufferedPositionUs(!loadingHolder.info.isFinal); boolean bufferedToEnd = loadingHolder.isFullyBuffered() && loadingHolder.info.isFinal;
return bufferedPositionUs == C.TIME_END_OF_SOURCE return bufferedToEnd
|| loadControl.shouldStartPlayback( || loadControl.shouldStartPlayback(
bufferedPositionUs - loadingHolder.toPeriodTime(rendererPositionUs), getTotalBufferedDurationUs(), mediaClock.getPlaybackParameters().speed, rebuffering);
mediaClock.getPlaybackParameters().speed,
rebuffering);
} }
private boolean isTimelineReady() { private boolean isTimelineReady() {
@ -1574,7 +1570,7 @@ import java.util.Collections;
return; return;
} }
long bufferedDurationUs = long bufferedDurationUs =
nextLoadPositionUs - loadingPeriodHolder.toPeriodTime(rendererPositionUs); getTotalBufferedDurationUs(/* bufferedPositionInLoadingPeriodUs= */ nextLoadPositionUs);
boolean continueLoading = boolean continueLoading =
loadControl.shouldContinueLoading( loadControl.shouldContinueLoading(
bufferedDurationUs, mediaClock.getPlaybackParameters().speed); bufferedDurationUs, mediaClock.getPlaybackParameters().speed);
@ -1680,6 +1676,17 @@ import java.util.Collections;
} }
} }
private long getTotalBufferedDurationUs() {
return getTotalBufferedDurationUs(playbackInfo.bufferedPositionUs);
}
private long getTotalBufferedDurationUs(long bufferedPositionInLoadingPeriodUs) {
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
return loadingPeriodHolder == null
? 0
: bufferedPositionInLoadingPeriodUs - loadingPeriodHolder.toPeriodTime(rendererPositionUs);
}
private void updateLoadControlTrackSelection( private void updateLoadControlTrackSelection(
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) { TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections); loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections);

View File

@ -133,23 +133,18 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} }
/** /**
* Returns the buffered position in microseconds. If the period is buffered to the end then * Returns the buffered position in microseconds. If the period is buffered to the end, then the
* {@link C#TIME_END_OF_SOURCE} is returned unless {@code convertEosToDuration} is true, in which * period duration is returned.
* case the period duration is returned.
* *
* @param convertEosToDuration Whether to return the period duration rather than
* {@link C#TIME_END_OF_SOURCE} if the period is fully buffered.
* @return The buffered position in microseconds. * @return The buffered position in microseconds.
*/ */
public long getBufferedPositionUs(boolean convertEosToDuration) { public long getBufferedPositionUs() {
if (!prepared) { if (!prepared) {
return info.startPositionUs; return info.startPositionUs;
} }
long bufferedPositionUs = long bufferedPositionUs =
hasEnabledTracks ? mediaPeriod.getBufferedPositionUs() : C.TIME_END_OF_SOURCE; hasEnabledTracks ? mediaPeriod.getBufferedPositionUs() : C.TIME_END_OF_SOURCE;
return bufferedPositionUs == C.TIME_END_OF_SOURCE && convertEosToDuration return bufferedPositionUs == C.TIME_END_OF_SOURCE ? info.durationUs : bufferedPositionUs;
? info.durationUs
: bufferedPositionUs;
} }
/** /**