From 5c52915f0c50330085caefb38146a33bff032cbd Mon Sep 17 00:00:00 2001 From: tonihei Date: Thu, 28 May 2020 16:47:46 +0100 Subject: [PATCH] Don't splice in if segments don't overlap and segments are independent. If the sample times don't overlap and are independent, splicing makes no difference because all samples (starting from the first one, which must be a keyframe) will be appended to the end of the queue anyway. PiperOrigin-RevId: 313594372 --- .../android/exoplayer2/source/hls/HlsMediaChunk.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java index 7a5fade817..85f30986ef 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaChunk.java @@ -62,6 +62,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; * @param format The chunk format. * @param startOfPlaylistInPeriodUs The position of the playlist in the period in microseconds. * @param mediaPlaylist The media playlist from which this chunk was obtained. + * @param segmentIndexInPlaylist The index of the segment in the media playlist. * @param playlistUrl The url of the playlist from which this chunk was obtained. * @param muxedCaptionFormats List of muxed caption {@link Format}s. Null if no closed caption * information is available in the master playlist. @@ -137,8 +138,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; if (previousChunk != null) { id3Decoder = previousChunk.id3Decoder; scratchId3Data = previousChunk.scratchId3Data; - shouldSpliceIn = - !playlistUrl.equals(previousChunk.playlistUrl) || !previousChunk.loadCompleted; + boolean canContinueWithoutSplice = + (playlistUrl.equals(previousChunk.playlistUrl) && previousChunk.loadCompleted) + || (mediaPlaylist.hasIndependentSegments + && segmentStartTimeInPeriodUs >= previousChunk.endTimeUs); + shouldSpliceIn = !canContinueWithoutSplice; if (shouldSpliceIn) { sampleQueueDiscardFromIndices = previousChunk.sampleQueueDiscardFromIndices; }