Treat seeks in HLS live to be at t=0, as in ExtractorSampleSource.

This makes sense until we need to support seeking in the live window.

Issue: #676
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=112402026
This commit is contained in:
olly 2016-01-18 05:37:52 -08:00 committed by Oliver Woodman
parent cef0f7a0b1
commit a049382cd7
2 changed files with 15 additions and 0 deletions

View File

@ -260,6 +260,17 @@ public class HlsChunkSource implements HlsTrackSelector.Output {
return fatalError == null; return fatalError == null;
} }
/**
* Returns whether this is a live playback.
* <p>
* This method should only be called after the source has been prepared.
*
* @return True if this is a live playback. False otherwise.
*/
public boolean isLive() {
return live;
}
/** /**
* Returns the duration of the source, or {@link C#UNKNOWN_TIME_US} if the duration is unknown. * Returns the duration of the source, or {@link C#UNKNOWN_TIME_US} if the duration is unknown.
* <p> * <p>

View File

@ -206,6 +206,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
loadControl.register(this, bufferSizeContribution); loadControl.register(this, bufferSizeContribution);
loadControlRegistered = true; loadControlRegistered = true;
} }
// Treat enabling of a live stream as occurring at t=0 in both of the blocks below.
positionUs = chunkSource.isLive() ? 0 : positionUs;
int chunkSourceTrack = chunkSourceTrackIndices[track]; int chunkSourceTrack = chunkSourceTrackIndices[track];
if (chunkSourceTrack != -1 && chunkSourceTrack != chunkSource.getSelectedTrackIndex()) { if (chunkSourceTrack != -1 && chunkSourceTrack != chunkSource.getSelectedTrackIndex()) {
// This is a primary track whose corresponding chunk source track is different to the one // This is a primary track whose corresponding chunk source track is different to the one
@ -359,6 +361,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
public void seekToUs(long positionUs) { public void seekToUs(long positionUs) {
Assertions.checkState(prepared); Assertions.checkState(prepared);
Assertions.checkState(enabledTrackCount > 0); Assertions.checkState(enabledTrackCount > 0);
// Treat all seeks into live streams as being to t=0.
positionUs = chunkSource.isLive() ? 0 : positionUs;
// Ignore seeks to the current position. // Ignore seeks to the current position.
long currentPositionUs = isPendingReset() ? pendingResetPositionUs : downstreamPositionUs; long currentPositionUs = isPendingReset() ? pendingResetPositionUs : downstreamPositionUs;