Commit dfdb3bbc by andrewlewis Committed by Oliver Woodman

Count buffer ahead periods rather than using their indices.

This is in preparation for allowing MediaSources to skip over periods when one
period ends, which is needed for starting to play a multi-period live stream
that is concatenated on to another period at the live edge.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128674659
parent 5818409f
...@@ -612,6 +612,8 @@ import java.util.ArrayList; ...@@ -612,6 +612,8 @@ import java.util.ArrayList;
public boolean isReady; public boolean isReady;
public boolean isEnded; public boolean isEnded;
private int bufferAheadPeriodCount;
private Period playingPeriod; private Period playingPeriod;
private Period readingPeriod; private Period readingPeriod;
private Period loadingPeriod; private Period loadingPeriod;
...@@ -693,6 +695,7 @@ import java.util.ArrayList; ...@@ -693,6 +695,7 @@ import java.util.ArrayList;
Period previousPeriod = playingPeriod; Period previousPeriod = playingPeriod;
boolean seenReadingPeriod = false; boolean seenReadingPeriod = false;
bufferAheadPeriodCount = 0;
while (previousPeriod.nextPeriod != null) { while (previousPeriod.nextPeriod != null) {
Period period = previousPeriod.nextPeriod; Period period = previousPeriod.nextPeriod;
index++; index++;
...@@ -716,6 +719,7 @@ import java.util.ArrayList; ...@@ -716,6 +719,7 @@ import java.util.ArrayList;
break; break;
} }
bufferAheadPeriodCount++;
period.index = index; period.index = index;
period.isLast = timeline.isFinal() && index == periodCount - 1; period.isLast = timeline.isFinal() && index == periodCount - 1;
if (period == readingPeriod) { if (period == readingPeriod) {
...@@ -729,6 +733,7 @@ import java.util.ArrayList; ...@@ -729,6 +733,7 @@ import java.util.ArrayList;
if (index == Timeline.NO_PERIOD_INDEX) { if (index == Timeline.NO_PERIOD_INDEX) {
loadingPeriod.release(); loadingPeriod.release();
loadingPeriod = null; loadingPeriod = null;
bufferAheadPeriodCount = 0;
} else { } else {
int periodCount = timeline.getPeriodCount(); int periodCount = timeline.getPeriodCount();
loadingPeriod.index = index; loadingPeriod.index = index;
...@@ -758,8 +763,7 @@ import java.util.ArrayList; ...@@ -758,8 +763,7 @@ import java.util.ArrayList;
// Update the loading period. // Update the loading period.
if (loadingPeriod == null || (loadingPeriod.isFullyBuffered() && !loadingPeriod.isLast if (loadingPeriod == null || (loadingPeriod.isFullyBuffered() && !loadingPeriod.isLast
&& (playingPeriod == null || loadingPeriod.index - playingPeriod.index && bufferAheadPeriodCount < MAXIMUM_BUFFER_AHEAD_PERIODS)) {
< MAXIMUM_BUFFER_AHEAD_PERIODS))) {
// Try to obtain the next period to start loading. // Try to obtain the next period to start loading.
int periodIndex = loadingPeriod == null ? playbackInfo.periodIndex int periodIndex = loadingPeriod == null ? playbackInfo.periodIndex
: loadingPeriod.index + 1; : loadingPeriod.index + 1;
...@@ -772,6 +776,7 @@ import java.util.ArrayList; ...@@ -772,6 +776,7 @@ import java.util.ArrayList;
if (loadingPeriod != null) { if (loadingPeriod != null) {
loadingPeriod.setNextPeriod(newPeriod); loadingPeriod.setNextPeriod(newPeriod);
} }
bufferAheadPeriodCount++;
loadingPeriod = newPeriod; loadingPeriod = newPeriod;
long startPositionUs = playingPeriod == null ? playbackInfo.positionUs : 0; long startPositionUs = playingPeriod == null ? playbackInfo.positionUs : 0;
setIsLoading(true); setIsLoading(true);
...@@ -802,6 +807,7 @@ import java.util.ArrayList; ...@@ -802,6 +807,7 @@ import java.util.ArrayList;
// reached the end of the playing period, so advance playback to the next period. // reached the end of the playing period, so advance playback to the next period.
playingPeriod.release(); playingPeriod.release();
setPlayingPeriod(playingPeriod.nextPeriod); setPlayingPeriod(playingPeriod.nextPeriod);
bufferAheadPeriodCount--;
playbackInfo = new PlaybackInfo(playingPeriod.index); playbackInfo = new PlaybackInfo(playingPeriod.index);
updatePlaybackPositions(); updatePlaybackPositions();
eventHandler.obtainMessage(MSG_PERIOD_CHANGED, playbackInfo).sendToTarget(); eventHandler.obtainMessage(MSG_PERIOD_CHANGED, playbackInfo).sendToTarget();
...@@ -903,6 +909,7 @@ import java.util.ArrayList; ...@@ -903,6 +909,7 @@ import java.util.ArrayList;
period = period.nextPeriod; period = period.nextPeriod;
} }
bufferAheadPeriodCount = 0;
if (newPlayingPeriod != null) { if (newPlayingPeriod != null) {
newPlayingPeriod.nextPeriod = null; newPlayingPeriod.nextPeriod = null;
setPlayingPeriod(newPlayingPeriod); setPlayingPeriod(newPlayingPeriod);
...@@ -957,6 +964,7 @@ import java.util.ArrayList; ...@@ -957,6 +964,7 @@ import java.util.ArrayList;
readingPeriod = playingPeriod; readingPeriod = playingPeriod;
loadingPeriod = playingPeriod; loadingPeriod = playingPeriod;
playingPeriodEndPositionUs = C.UNSET_TIME_US; playingPeriodEndPositionUs = C.UNSET_TIME_US;
bufferAheadPeriodCount = 0;
// Update streams for the new selection, recreating all streams if reading ahead. // Update streams for the new selection, recreating all streams if reading ahead.
boolean recreateStreams = readingPeriod != playingPeriod; boolean recreateStreams = readingPeriod != playingPeriod;
...@@ -1000,6 +1008,7 @@ import java.util.ArrayList; ...@@ -1000,6 +1008,7 @@ import java.util.ArrayList;
while (period != null) { while (period != null) {
period.release(); period.release();
period = period.nextPeriod; period = period.nextPeriod;
bufferAheadPeriodCount--;
} }
loadingPeriod.nextPeriod = null; loadingPeriod.nextPeriod = null;
long positionUs = Math.max(0, internalPositionUs - loadingPeriod.offsetUs); long positionUs = Math.max(0, internalPositionUs - loadingPeriod.offsetUs);
...@@ -1017,6 +1026,7 @@ import java.util.ArrayList; ...@@ -1017,6 +1026,7 @@ import java.util.ArrayList;
readingPeriod = null; readingPeriod = null;
loadingPeriod = null; loadingPeriod = null;
timeline = null; timeline = null;
bufferAheadPeriodCount = 0;
} }
private void releasePeriodsFrom(Period period) { private void releasePeriodsFrom(Period period) {
......
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