From 0756c3d28c33026a90be6dff88a2b9806e16be30 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 19 Dec 2014 12:11:17 +0000 Subject: [PATCH] Relax assertion. We've seen a few streams where this assertion fails. If you just skip the packet, things appear to recover correctly in all cases I've seen, so replacing failure with a warning. --- .../android/exoplayer/hls/TsExtractor.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/hls/TsExtractor.java b/library/src/main/java/com/google/android/exoplayer/hls/TsExtractor.java index 52a746ae27..3429ec337b 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/TsExtractor.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/TsExtractor.java @@ -427,10 +427,17 @@ public final class TsExtractor { @Override public void read(BitArray tsBuffer, boolean payloadUnitStartIndicator) { if (payloadUnitStartIndicator && !pesBuffer.isEmpty()) { - // We've encountered the start of the next packet, but haven't yet read the body. Read it. - // Note that this should only happen if the packet length was unspecified. - Assertions.checkState(packetLength == 0); - readPacketBody(); + if (packetLength == 0) { + // The length of the previous packet was unspecified. We've now seen the start of the + // next one, so consume the previous packet's body. + readPacketBody(); + } else { + // Either we didn't have enough data to read the length of the previous packet, or we + // did read the length but didn't receive that amount of data. Neither case is expected. + Log.w(TAG, "Unexpected packet fragment of length " + pesBuffer.bytesLeft()); + pesBuffer.reset(); + packetLength = -1; + } } pesBuffer.append(tsBuffer, tsBuffer.bytesLeft()); @@ -448,7 +455,7 @@ public final class TsExtractor { private void readPacketStart() { int startCodePrefix = pesBuffer.readBits(24); if (startCodePrefix != 0x000001) { - Log.e(TAG, "Unexpected start code prefix: " + startCodePrefix); + Log.w(TAG, "Unexpected start code prefix: " + startCodePrefix); pesBuffer.reset(); packetLength = -1; } else {