From 2a9eeaa893c6275a74b1ad283a331452b1bf005d Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 12 Jan 2016 05:57:20 -0800 Subject: [PATCH] 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 --- .../android/exoplayer/hls/HlsSampleSource.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java index 3d651be73c..d69ba08519 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java @@ -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; } }