From b84c84cc765cd6b2d27e20330735b2d866d310b2 Mon Sep 17 00:00:00 2001 From: cdrolle Date: Thu, 9 Mar 2017 11:18:15 -0800 Subject: [PATCH] Fixed CEA-708 issue where cues weren't updated at the appropriate times As per the CEA-708-B specification, section 8.10.4, cues don't necessarily need either an ETX command or any of the C1 commands before being updated with the latest buffered content. While those commands do indicate that the cues should be updated immediately, the cues can also be updated after a service block has been processed if it appended text to the buffer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=149673162 --- .../exoplayer2/text/cea/Cea708Decoder.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java b/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java index e04c246ea0..62ffa03bf9 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea708Decoder.java @@ -285,19 +285,26 @@ public final class Cea708Decoder extends CeaDecoder { return; } + // The cues should be updated if we receive a C0 ETX command, any C1 command, or if after + // processing the service block any text has been added to the buffer. See CEA-708-B Section + // 8.10.4 for more details. + boolean cuesNeedUpdate = false; + while (serviceBlockPacket.bitsLeft() > 0) { int command = serviceBlockPacket.readBits(8); if (command != COMMAND_EXT1) { if (command <= GROUP_C0_END) { handleC0Command(command); + // If the C0 command was an ETX command, the cues are updated in handleC0Command. } else if (command <= GROUP_G0_END) { handleG0Character(command); + cuesNeedUpdate = true; } else if (command <= GROUP_C1_END) { handleC1Command(command); - // Cues are always updated after a C1 command - cues = getDisplayCues(); + cuesNeedUpdate = true; } else if (command <= GROUP_G1_END) { handleG1Character(command); + cuesNeedUpdate = true; } else { Log.w(TAG, "Invalid base command: " + command); } @@ -308,15 +315,21 @@ public final class Cea708Decoder extends CeaDecoder { handleC2Command(command); } else if (command <= GROUP_G2_END) { handleG2Character(command); + cuesNeedUpdate = true; } else if (command <= GROUP_C3_END) { handleC3Command(command); } else if (command <= GROUP_G3_END) { handleG3Character(command); + cuesNeedUpdate = true; } else { Log.w(TAG, "Invalid extended command: " + command); } } } + + if (cuesNeedUpdate) { + cues = getDisplayCues(); + } } private void handleC0Command(int command) {