Fix HlsSampleSource use of LoadControl.

There are multiple issues with HlsSampleSource's use of
LoadControl that become apparent when you attempt to use
the same LoadControl for loads by another source.

* In the "limbo" state HlsSampleSource doesn't start any
  new loads, but doesn't update the LoadControl to tell
  it that it doesn't want to load anything either. This
  can prevent another source from starting the loads that
  it needs to make to complete preparation, causing
  playback to become stuck.
* The LoadControl isn't updated properly when the EOS is
  reached. This can cause playback to become stuck near
  the end of the media.
* If HlsSampleSource is released from being in the "limbo"
  state, it doesn't unregister itself with the control.

Issue: #151
Issue: #676
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=111942009
This commit is contained in:
olly 2016-01-12 05:57:20 -08:00 committed by Oliver Woodman
parent 43fcb36924
commit 2a9eeaa893

View File

@ -162,8 +162,6 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
// We're not prepared and we haven't loaded what we need.
if (loader == null) {
loader = new Loader("Loader:HLS");
}
if (!loadControlRegistered) {
loadControl.register(this, bufferSizeContribution);
loadControlRegistered = true;
}
@ -249,10 +247,10 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
if (!extractors.isEmpty()) {
discardSamplesForDisabledTracks(getCurrentExtractor(), downstreamPositionUs);
}
maybeStartLoading();
if (loadingFinished) {
return true;
}
maybeStartLoading();
if (isPendingReset() || extractors.isEmpty()) {
return false;
}
@ -389,6 +387,10 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
public void release() {
Assertions.checkState(remainingReleaseCount > 0);
if (--remainingReleaseCount == 0 && loader != null) {
if (loadControlRegistered) {
loadControl.unregister(this);
loadControlRegistered = false;
}
loader.release();
loader = null;
}
@ -413,9 +415,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
currentLoadable.trigger, currentLoadable.format, -1, -1, now, loadDurationMs);
}
clearCurrentLoadable();
if (enabledTrackCount > 0 || !prepared) {
maybeStartLoading();
}
maybeStartLoading();
}
@Override
@ -537,7 +537,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
return;
}
if (loader.isLoading() || !nextLoader) {
if (loader.isLoading() || !nextLoader || (prepared && enabledTrackCount == 0)) {
return;
}
@ -550,6 +550,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
if (endOfStream) {
loadingFinished = true;
loadControl.update(this, downstreamPositionUs, -1, false);
return;
}
if (nextLoadable == null) {
@ -586,7 +587,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
if (isPendingReset()) {
return pendingResetPositionUs;
} else {
return loadingFinished ? -1
return loadingFinished || (prepared && enabledTrackCount == 0) ? -1
: currentTsLoadable != null ? currentTsLoadable.endTimeUs : previousTsLoadable.endTimeUs;
}
}