Skip to content

Commit

Permalink
This pull request is for issue#1807. Refactoring the PR #8356
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sneelavara committed Dec 31, 2020
1 parent b70f08b commit b534097
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b534097

Please sign in to comment.