Skip to content

Commit

Permalink
Fix HlsSampleSource use of LoadControl.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ojw28 committed Jan 14, 2016
1 parent 43fcb36 commit 2a9eeaa
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ public boolean prepare(long positionUs) {
// 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;
}
Expand Down Expand Up @@ -249,10 +247,10 @@ public boolean continueBuffering(int track, long playbackPositionUs) {
if (!extractors.isEmpty()) {
discardSamplesForDisabledTracks(getCurrentExtractor(), downstreamPositionUs);
}
maybeStartLoading();
if (loadingFinished) {
return true;
}
maybeStartLoading();
if (isPendingReset() || extractors.isEmpty()) {
return false;
}
Expand Down Expand Up @@ -389,6 +387,10 @@ public long getBufferedPositionUs() {
public void release() {
Assertions.checkState(remainingReleaseCount > 0);
if (--remainingReleaseCount == 0 && loader != null) {
if (loadControlRegistered) {
loadControl.unregister(this);
loadControlRegistered = false;
}
loader.release();
loader = null;
}
Expand All @@ -413,9 +415,7 @@ public void onLoadCompleted(Loadable loadable) {
currentLoadable.trigger, currentLoadable.format, -1, -1, now, loadDurationMs);
}
clearCurrentLoadable();
if (enabledTrackCount > 0 || !prepared) {
maybeStartLoading();
}
maybeStartLoading();
}

@Override
Expand Down Expand Up @@ -537,7 +537,7 @@ private void maybeStartLoading() {
return;
}

if (loader.isLoading() || !nextLoader) {
if (loader.isLoading() || !nextLoader || (prepared && enabledTrackCount == 0)) {
return;
}

Expand All @@ -550,6 +550,7 @@ private void maybeStartLoading() {

if (endOfStream) {
loadingFinished = true;
loadControl.update(this, downstreamPositionUs, -1, false);
return;
}
if (nextLoadable == null) {
Expand Down Expand Up @@ -586,7 +587,7 @@ private long getNextLoadPositionUs() {
if (isPendingReset()) {
return pendingResetPositionUs;
} else {
return loadingFinished ? -1
return loadingFinished || (prepared && enabledTrackCount == 0) ? -1
: currentTsLoadable != null ? currentTsLoadable.endTimeUs : previousTsLoadable.endTimeUs;
}
}
Expand Down

0 comments on commit 2a9eeaa

Please sign in to comment.