From f5ebcb8d043292e3e9aad190900e9bcfc2f52296 Mon Sep 17 00:00:00 2001 From: cdrolle Date: Mon, 26 Sep 2016 11:03:37 -0700 Subject: [PATCH] Modified the default position parameters of the Cue objects created by Eia608Decoder. Full preamble positioning will be provided in a subsequent CL. This CL also contains some minor cleanup in Eia608Decoder and adds some TODOs to handle the second channel. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=134299337 --- .../exoplayer2/text/eia608/Eia608Decoder.java | 68 +++++++++++++------ .../text/eia608/Eia608Subtitle.java | 20 +++--- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java b/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java index b5249cde78..50c6d4f6b0 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java @@ -15,8 +15,10 @@ */ package com.google.android.exoplayer2.text.eia608; +import android.text.Layout.Alignment; import android.text.TextUtils; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.SubtitleDecoder; import com.google.android.exoplayer2.text.SubtitleDecoderException; import com.google.android.exoplayer2.text.SubtitleInputBuffer; @@ -159,6 +161,14 @@ public final class Eia608Decoder implements SubtitleDecoder { 0xC5, 0xE5, 0xD8, 0xF8, 0x250C, 0x2510, 0x2514, 0x2518 }; + private static final Alignment CUE_TEXT_ALIGNMENT = Alignment.ALIGN_NORMAL; + private static final float CUE_LINE = Cue.DIMEN_UNSET; + private static final int CUE_LINE_TYPE = Cue.TYPE_UNSET; + private static final int CUE_LINE_ANCHOR = Cue.TYPE_UNSET; + private static final float CUE_POSITION = 0.1f; + private static final int CUE_POSITION_ANCHOR = Cue.TYPE_UNSET; + private static final float CUE_SIZE = 0.8f; + private final LinkedList availableInputBuffers; private final LinkedList availableOutputBuffers; private final TreeSet queuedInputBuffers; @@ -256,8 +266,13 @@ public final class Eia608Decoder implements SubtitleDecoder { if (!TextUtils.equals(captionString, lastCaptionString)) { lastCaptionString = captionString; if (!inputBuffer.isDecodeOnly()) { + Cue cue = null; + if (!TextUtils.isEmpty(captionString)) { + cue = new Cue(captionString, CUE_TEXT_ALIGNMENT, CUE_LINE, CUE_LINE_TYPE, + CUE_LINE_ANCHOR, CUE_POSITION, CUE_POSITION_ANCHOR, CUE_SIZE); + } SubtitleOutputBuffer outputBuffer = availableOutputBuffers.pollFirst(); - outputBuffer.setContent(inputBuffer.timeUs, new Eia608Subtitle(captionString), 0); + outputBuffer.setContent(inputBuffer.timeUs, new Eia608Subtitle(cue), 0); releaseInputBuffer(inputBuffer); return outputBuffer; } @@ -320,26 +335,33 @@ public final class Eia608Decoder implements SubtitleDecoder { captionDataProcessed = true; // Special North American character set. + // ccData1 - P|0|0|1|C|0|0|1 // ccData2 - P|0|1|1|X|X|X|X if ((ccData1 == 0x11 || ccData1 == 0x19) && ((ccData2 & 0x70) == 0x30)) { + // TODO: Make use of the channel bit captionStringBuilder.append(getSpecialChar(ccData2)); continue; } - // Extended Spanish/Miscellaneous and French character set. + // Extended Western European character set. + // ccData1 - P|0|0|1|C|0|1|S // ccData2 - P|0|1|X|X|X|X|X - if ((ccData1 == 0x12 || ccData1 == 0x1A) && ((ccData2 & 0x60) == 0x20)) { - backspace(); // Remove standard equivalent of the special extended char. - captionStringBuilder.append(getExtendedEsFrChar(ccData2)); - continue; - } + if ((ccData2 & 0x60) == 0x20) { + // Extended Spanish/Miscellaneous and French character set (S = 0). + if (ccData1 == 0x12 || ccData1 == 0x1A) { + // TODO: Make use of the channel bit + backspace(); // Remove standard equivalent of the special extended char. + captionStringBuilder.append(getExtendedEsFrChar(ccData2)); + continue; + } - // Extended Portuguese and German/Danish character set. - // ccData2 - P|0|1|X|X|X|X|X - if ((ccData1 == 0x13 || ccData1 == 0x1B) && ((ccData2 & 0x60) == 0x20)) { - backspace(); // Remove standard equivalent of the special extended char. - captionStringBuilder.append(getExtendedPtDeChar(ccData2)); - continue; + // Extended Portuguese and German/Danish character set (S = 1). + if (ccData1 == 0x13 || ccData1 == 0x1B) { + // TODO: Make use of the channel bit + backspace(); // Remove standard equivalent of the special extended char. + captionStringBuilder.append(getExtendedPtDeChar(ccData2)); + continue; + } } // Control character. @@ -367,15 +389,17 @@ public final class Eia608Decoder implements SubtitleDecoder { private boolean handleCtrl(byte cc1, byte cc2) { boolean isRepeatableControl = isRepeatable(cc1); - if (isRepeatableControl && repeatableControlSet - && repeatableControlCc1 == cc1 - && repeatableControlCc2 == cc2) { - repeatableControlSet = false; - return true; - } else if (isRepeatableControl) { - repeatableControlSet = true; - repeatableControlCc1 = cc1; - repeatableControlCc2 = cc2; + if (isRepeatableControl) { + if (repeatableControlSet + && repeatableControlCc1 == cc1 + && repeatableControlCc2 == cc2) { + repeatableControlSet = false; + return true; + } else { + repeatableControlSet = true; + repeatableControlCc1 = cc1; + repeatableControlCc2 = cc2; + } } if (isMiscCode(cc1, cc2)) { handleMiscCode(cc2); diff --git a/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Subtitle.java b/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Subtitle.java index 6b27004174..5ec8ca6d95 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Subtitle.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Subtitle.java @@ -15,7 +15,6 @@ */ package com.google.android.exoplayer2.text.eia608; -import android.text.TextUtils; import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Subtitle; import java.util.Collections; @@ -26,13 +25,17 @@ import java.util.List; */ /* package */ final class Eia608Subtitle implements Subtitle { - private final String text; + private final List cues; /** - * @param text The subtitle text. + * @param cue The subtitle cue. */ - public Eia608Subtitle(String text) { - this.text = text; + public Eia608Subtitle(Cue cue) { + if (cue == null) { + cues = Collections.emptyList(); + } else { + cues = Collections.singletonList(cue); + } } @Override @@ -52,11 +55,8 @@ import java.util.List; @Override public List getCues(long timeUs) { - if (TextUtils.isEmpty(text)) { - return Collections.emptyList(); - } else { - return Collections.singletonList(new Cue(text)); - } + return cues; + } }