Skip to content

Commit

Permalink
Merge pull request #8415 from TiVo:p-fix-cea708anchor
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 352783091
  • Loading branch information
kim-vde committed Jan 22, 2021
2 parents 2d3e6d4 + b534097 commit 26ea43d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@
containers.
* Fix CEA-708 anchor positioning
([#1807](https://github.com/google/ExoPlayer/issues/1807)).
* Fix CEA-708 sequence number discontinuity handling
([#1807](https://github.com/google/ExoPlayer/issues/1807)).
* Fix CEA-708 handling of unexpectedly small packets
([#1807](https://github.com/google/ExoPlayer/issues/1807)).
* Data sources:
* Use the user agent of the underlying network stack by default.
* Metadata retriever:
Expand Down
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 previousSequenceNumber;
// TODO: Use isWideAspectRatio in decoding.
@SuppressWarnings({"unused", "FieldCanBeLocal"})
private final boolean isWideAspectRatio;
Expand All @@ -162,6 +163,7 @@ public final class Cea708Decoder extends CeaDecoder {
public Cea708Decoder(int accessibilityChannel, @Nullable List<byte[]> initializationData) {
ccData = new ParsableByteArray();
serviceBlockPacket = new ParsableBitArray();
previousSequenceNumber = C.INDEX_UNSET;
selectedServiceNumber = accessibilityChannel == Format.NO_VALUE ? 1 : accessibilityChannel;
isWideAspectRatio =
initializationData != null
Expand Down Expand Up @@ -231,6 +233,18 @@ protected void decode(SubtitleInputBuffer inputBuffer) {
finalizeCurrentPacket();

int sequenceNumber = (ccData1 & 0xC0) >> 6; // first 2 bits
if (previousSequenceNumber != C.INDEX_UNSET
&& sequenceNumber != (previousSequenceNumber + 1) % 4) {
resetCueBuilders();
Log.w(
TAG,
"Sequence number discontinuity. previous="
+ previousSequenceNumber
+ " current="
+ sequenceNumber);
}
previousSequenceNumber = sequenceNumber;

int packetSize = ccData1 & 0x3F; // last 6 bits
if (packetSize == 0) {
packetSize = 64;
Expand Down Expand Up @@ -270,10 +284,18 @@ 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)
+ ", but current index is " + currentDtvCcPacket.currentIndex + " (sequence number "
+ currentDtvCcPacket.sequenceNumber + "); ignoring packet");
return;
Log.d(
TAG,
"DtvCcPacket ended prematurely; size is "
+ (currentDtvCcPacket.packetSize * 2 - 1)
+ ", but current index is "
+ currentDtvCcPacket.currentIndex
+ " (sequence number "
+ currentDtvCcPacket.sequenceNumber
+ ");");
// We've received cc_type=0x03 (packet start) before receiving packetSize byte pairs of data.
// This might indicate a byte pair has been lost, but we'll still attempt to process the data
// we have received.
}

serviceBlockPacket.reset(currentDtvCcPacket.packetData, currentDtvCcPacket.currentIndex);
Expand Down

0 comments on commit 26ea43d

Please sign in to comment.