Commit 2a9eeaa8 by olly Committed by Oliver Woodman

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