From c62e535cf047c43a122a11c675413d7efa920a0b Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 27 Nov 2015 15:57:20 +0000 Subject: [PATCH] Make HLS behind-live-window behavior consistent. - Propagate BehindLiveWindowException if we fall off the back of an HLS live stream. - Consolidate seekPositionUs and playbackPositionUs into a single parameter. Issue: #765 --- .../android/exoplayer/hls/HlsChunkSource.java | 26 +++++++------------ .../exoplayer/hls/HlsSampleSource.java | 5 ++-- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java index e051c1c875..9e305d5969 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsChunkSource.java @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer.hls; +import com.google.android.exoplayer.BehindLiveWindowException; import com.google.android.exoplayer.C; import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.chunk.BaseChunkSampleSourceEventListener; @@ -249,14 +250,14 @@ public class HlsChunkSource { * be performed by the calling {@link HlsSampleSource}. * * @param previousTsChunk The previously loaded chunk that the next chunk should follow. - * @param seekPositionUs If there is no previous chunk, this parameter must specify the seek - * position. If there is a previous chunk then this parameter is ignored. - * @param playbackPositionUs The current playback position. + * @param playbackPositionUs The current playback position. If previousTsChunk is null then this + * parameter is the position from which playback is expected to start (or restart) and hence + * should be interpreted as a seek position. * @param out The holder to populate with the result. {@link ChunkOperationHolder#queueSize} is * unused. */ - public void getChunkOperation(TsChunk previousTsChunk, long seekPositionUs, - long playbackPositionUs, ChunkOperationHolder out) { + public void getChunkOperation(TsChunk previousTsChunk, long playbackPositionUs, + ChunkOperationHolder out) { int nextVariantIndex; boolean switchingVariantSpliced; if (adaptiveMode == ADAPTIVE_MODE_NONE) { @@ -286,22 +287,15 @@ public class HlsChunkSource { chunkMediaSequence = switchingVariantSpliced ? previousTsChunk.chunkIndex : previousTsChunk.chunkIndex + 1; if (chunkMediaSequence < mediaPlaylist.mediaSequence) { - // TODO: Decide what we want to do with: https://github.com/google/ExoPlayer/issues/765 - // if (allowSkipAhead) { - // If the chunk is no longer in the playlist. Skip ahead and start again. - chunkMediaSequence = getLiveStartChunkMediaSequence(nextVariantIndex); - liveDiscontinuity = true; - // } else { - // fatalError = new BehindLiveWindowException(); - // return null; - // } + fatalError = new BehindLiveWindowException(); + return; } } } else { // Not live. if (previousTsChunk == null) { - chunkMediaSequence = Util.binarySearchFloor(mediaPlaylist.segments, seekPositionUs, true, - true) + mediaPlaylist.mediaSequence; + chunkMediaSequence = Util.binarySearchFloor(mediaPlaylist.segments, playbackPositionUs, + true, true) + mediaPlaylist.mediaSequence; } else { chunkMediaSequence = switchingVariantSpliced ? previousTsChunk.chunkIndex : previousTsChunk.chunkIndex + 1; 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 9667427dee..f29eb095c4 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 @@ -538,8 +538,9 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader, return; } - chunkSource.getChunkOperation(previousTsLoadable, pendingResetPositionUs, - downstreamPositionUs, chunkOperationHolder); + chunkSource.getChunkOperation(previousTsLoadable, + pendingResetPositionUs != NO_RESET_PENDING ? pendingResetPositionUs : downstreamPositionUs, + chunkOperationHolder); boolean endOfStream = chunkOperationHolder.endOfStream; Chunk nextLoadable = chunkOperationHolder.chunk; chunkOperationHolder.clear();