From 0cb9802e1bc16ec73bf63c0aacaad9bf6ef050b1 Mon Sep 17 00:00:00 2001 From: cdrolle Date: Thu, 9 Mar 2017 12:10:30 -0800 Subject: [PATCH] Fixed CEA-708 issues Caption characters weren't being assigned to the correct window and the lack of pen location support was causing multiple lines (and words) to be concatenated. As per the CEA-708-B specification, section 8.10.5, when we encounter a DefineWindow command, we're also supposed to update the current window to the newly defined one. We were not doing this previously, resulting in text that should have been in separate windows being combined into one. Furthermore, some content uses the SetPenLocation command to move the cursor down a line instead of appending a new line. As we don't currently support SetPenLocation, this resulted in multiple lines (and words) being concatenated together, potentially causing the text to extend past the edge of the window/screen. This change implements a workaround (until SetPenLocation is properly supported) for this issue in which setting the pen location to a new row will append a new-line to that window. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=149679613 --- .../exoplayer2/text/cea/Cea708Decoder.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 62ffa03bf9..740fd17013 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 @@ -470,6 +470,11 @@ public final class Cea708Decoder extends CeaDecoder { case COMMAND_DF7: window = (command - COMMAND_DF0); handleDefineWindow(window); + // We also set the current window to the newly defined window. + if (currentWindow != window) { + currentWindow = window; + currentCueBuilder = cueBuilders[window]; + } break; default: Log.w(TAG, "Invalid C1 command: " + command); @@ -871,6 +876,7 @@ public final class Cea708Decoder extends CeaDecoder { private int foregroundColor; private int backgroundColorStartPosition; private int backgroundColor; + private int row; public CueBuilder() { rolledUpCaptions = new LinkedList<>(); @@ -910,6 +916,7 @@ public final class Cea708Decoder extends CeaDecoder { underlineStartPosition = C.POSITION_UNSET; foregroundColorStartPosition = C.POSITION_UNSET; backgroundColorStartPosition = C.POSITION_UNSET; + row = 0; } public boolean isDefined() { @@ -1044,7 +1051,16 @@ public final class Cea708Decoder extends CeaDecoder { } public void setPenLocation(int row, int column) { - // TODO: Support moving the pen location with a window. + // TODO: Support moving the pen location with a window properly. + + // Until we support proper pen locations, if we encounter a row that's different from the + // previous one, we should append a new line. Otherwise, we'll see strings that should be + // on new lines concatenated with the previous, resulting in 2 words being combined, as + // well as potentially drawing beyond the width of the window/screen. + if (this.row != row) { + append('\n'); + } + this.row = row; } public void backspace() {