From b534097d1c01b7b811763cbc07d3df0fbb660dcc Mon Sep 17 00:00:00 2001 From: sneelavara Date: Wed, 30 Dec 2020 17:35:44 -0800 Subject: [PATCH] This pull request is for issue#1807. Refactoring the PR #8356 In this change - Handling the sequence number discontinuity in caption channel packet header. The processCurrentPacket returns if the packet length does not match with the currentIndex. That assumption is wrong. As per spec the the packet can end on reception of next cc_type = 0x3. --- .../exoplayer2/text/cea/Cea708Decoder.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java b/library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java index 56dd4ebef27..286b6bbaea5 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java @@ -145,6 +145,7 @@ public final class Cea708Decoder extends CeaDecoder { private final ParsableByteArray ccData; private final ParsableBitArray serviceBlockPacket; + private int lastSequenceNo = -1; // TODO: Use isWideAspectRatio in decoding. @SuppressWarnings({"unused", "FieldCanBeLocal"}) private final boolean isWideAspectRatio; @@ -231,6 +232,13 @@ protected void decode(SubtitleInputBuffer inputBuffer) { finalizeCurrentPacket(); int sequenceNumber = (ccData1 & 0xC0) >> 6; // first 2 bits + if (lastSequenceNo != -1 && sequenceNumber != (lastSequenceNo + 1) % 4) { + resetCueBuilders(); + Log.w(TAG, "discontinuity in sequence number detected : lastSequenceNo = " + + lastSequenceNo + " sequenceNumber = " + sequenceNumber); + } + lastSequenceNo = sequenceNumber; + int packetSize = ccData1 & 0x3F; // last 6 bits if (packetSize == 0) { packetSize = 64; @@ -270,10 +278,11 @@ private void finalizeCurrentPacket() { @RequiresNonNull("currentDtvCcPacket") private void processCurrentPacket() { if (currentDtvCcPacket.currentIndex != (currentDtvCcPacket.packetSize * 2 - 1)) { - Log.w(TAG, "DtvCcPacket ended prematurely; size is " + (currentDtvCcPacket.packetSize * 2 - 1) + Log.d(TAG, "DtvCcPacket ended prematurely; size is " + (currentDtvCcPacket.packetSize * 2 - 1) + ", but current index is " + currentDtvCcPacket.currentIndex + " (sequence number " - + currentDtvCcPacket.sequenceNumber + "); ignoring packet"); - return; + + currentDtvCcPacket.sequenceNumber + ");"); + // This is not invalid packet. As per CEA-708 section 4.4.1.1, the Packect end can happen + // when the reception of cc_type = 0x03 (binary 11). } serviceBlockPacket.reset(currentDtvCcPacket.packetData, currentDtvCcPacket.currentIndex);