From 88c0695bd001501381c739018bd8f9d11a8a0cdd Mon Sep 17 00:00:00 2001 From: cdrolle Date: Mon, 5 Dec 2016 11:42:52 -0800 Subject: [PATCH] Added safe-area adjustment (i.e. padding) to CEA-608 captions and fixed minor issue with rollup. CEA-608 specifies a "safe-area" in which the captions should be rendered. This change adjusts all of the cue positions so they are within that safe area. It also fixes a minor issue in which roll up captions would drift towards the last row if a preamble address code had the "next row toggle" bit set. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=141077433 --- .../exoplayer2/text/cea/Cea608Decoder.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea608Decoder.java b/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea608Decoder.java index 05324e29fe..dfa0dcf8f5 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea608Decoder.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/cea/Cea608Decoder.java @@ -15,8 +15,6 @@ */ package com.google.android.exoplayer2.text.cea; -import static com.google.android.exoplayer2.text.Cue.TYPE_UNSET; - import android.graphics.Color; import android.graphics.Typeface; import android.text.Layout.Alignment; @@ -406,8 +404,8 @@ public final class Cea608Decoder extends CeaDecoder { // cc2 - 0|1|N|ATTRBTE|U // N is the next row down toggle, ATTRBTE is the 4-byte encoded attribute, and U is the - // underline toggle - boolean nextRowDown = (cc2 & 0x20) != 0; + // underline toggle. The next row down toggle isn't applicable for roll-up captions. + boolean nextRowDown = captionMode != CC_MODE_ROLL_UP && (cc2 & 0x20) != 0; if (row != currentCueBuilder.getRow() || nextRowDown) { if (captionMode != CC_MODE_ROLL_UP && !currentCueBuilder.isEmpty()) { currentCueBuilder = new CueBuilder(captionMode, captionRowCount); @@ -740,19 +738,25 @@ public final class Cea608Decoder extends CeaDecoder { cueString.append(buildSpannableString()); float position = (float) (indent + tabOffset) / SCREEN_CHARWIDTH; + // adjust the position to fit within the safe area + position = position * 0.8f + 0.1f; float line; int lineType; if (captionMode == CC_MODE_ROLL_UP) { - line = (row - 1) - BASE_ROW; lineType = Cue.LINE_TYPE_NUMBER; + line = row - BASE_ROW; + // adjust the line to fit within the safe area + line--; } else { - line = (float) (row - 1) / BASE_ROW; lineType = Cue.LINE_TYPE_FRACTION; + line = (float) row / BASE_ROW; + // adjust the line to fit within the safe area + line = line * 0.8f + 0.1f; } - return new Cue(cueString, Alignment.ALIGN_NORMAL, line, lineType, TYPE_UNSET, position, - TYPE_UNSET, 0.8f); + return new Cue(cueString, Alignment.ALIGN_NORMAL, line, lineType, Cue.ANCHOR_TYPE_END, + position, Cue.ANCHOR_TYPE_START, Cue.DIMEN_UNSET); } @Override