Commit f5ebcb8d by cdrolle Committed by Oliver Woodman

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
parent 7273237b
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
*/ */
package com.google.android.exoplayer2.text.eia608; package com.google.android.exoplayer2.text.eia608;
import android.text.Layout.Alignment;
import android.text.TextUtils; import android.text.TextUtils;
import com.google.android.exoplayer2.C; 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.SubtitleDecoder;
import com.google.android.exoplayer2.text.SubtitleDecoderException; import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.google.android.exoplayer2.text.SubtitleInputBuffer; import com.google.android.exoplayer2.text.SubtitleInputBuffer;
...@@ -159,6 +161,14 @@ public final class Eia608Decoder implements SubtitleDecoder { ...@@ -159,6 +161,14 @@ public final class Eia608Decoder implements SubtitleDecoder {
0xC5, 0xE5, 0xD8, 0xF8, 0x250C, 0x2510, 0x2514, 0x2518 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<SubtitleInputBuffer> availableInputBuffers; private final LinkedList<SubtitleInputBuffer> availableInputBuffers;
private final LinkedList<SubtitleOutputBuffer> availableOutputBuffers; private final LinkedList<SubtitleOutputBuffer> availableOutputBuffers;
private final TreeSet<SubtitleInputBuffer> queuedInputBuffers; private final TreeSet<SubtitleInputBuffer> queuedInputBuffers;
...@@ -256,8 +266,13 @@ public final class Eia608Decoder implements SubtitleDecoder { ...@@ -256,8 +266,13 @@ public final class Eia608Decoder implements SubtitleDecoder {
if (!TextUtils.equals(captionString, lastCaptionString)) { if (!TextUtils.equals(captionString, lastCaptionString)) {
lastCaptionString = captionString; lastCaptionString = captionString;
if (!inputBuffer.isDecodeOnly()) { 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(); SubtitleOutputBuffer outputBuffer = availableOutputBuffers.pollFirst();
outputBuffer.setContent(inputBuffer.timeUs, new Eia608Subtitle(captionString), 0); outputBuffer.setContent(inputBuffer.timeUs, new Eia608Subtitle(cue), 0);
releaseInputBuffer(inputBuffer); releaseInputBuffer(inputBuffer);
return outputBuffer; return outputBuffer;
} }
...@@ -320,26 +335,33 @@ public final class Eia608Decoder implements SubtitleDecoder { ...@@ -320,26 +335,33 @@ public final class Eia608Decoder implements SubtitleDecoder {
captionDataProcessed = true; captionDataProcessed = true;
// Special North American character set. // Special North American character set.
// ccData1 - P|0|0|1|C|0|0|1
// ccData2 - P|0|1|1|X|X|X|X // ccData2 - P|0|1|1|X|X|X|X
if ((ccData1 == 0x11 || ccData1 == 0x19) && ((ccData2 & 0x70) == 0x30)) { if ((ccData1 == 0x11 || ccData1 == 0x19) && ((ccData2 & 0x70) == 0x30)) {
// TODO: Make use of the channel bit
captionStringBuilder.append(getSpecialChar(ccData2)); captionStringBuilder.append(getSpecialChar(ccData2));
continue; 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 // ccData2 - P|0|1|X|X|X|X|X
if ((ccData1 == 0x12 || ccData1 == 0x1A) && ((ccData2 & 0x60) == 0x20)) { if ((ccData2 & 0x60) == 0x20) {
backspace(); // Remove standard equivalent of the special extended char. // Extended Spanish/Miscellaneous and French character set (S = 0).
captionStringBuilder.append(getExtendedEsFrChar(ccData2)); if (ccData1 == 0x12 || ccData1 == 0x1A) {
continue; // 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. // Extended Portuguese and German/Danish character set (S = 1).
// ccData2 - P|0|1|X|X|X|X|X if (ccData1 == 0x13 || ccData1 == 0x1B) {
if ((ccData1 == 0x13 || ccData1 == 0x1B) && ((ccData2 & 0x60) == 0x20)) { // TODO: Make use of the channel bit
backspace(); // Remove standard equivalent of the special extended char. backspace(); // Remove standard equivalent of the special extended char.
captionStringBuilder.append(getExtendedPtDeChar(ccData2)); captionStringBuilder.append(getExtendedPtDeChar(ccData2));
continue; continue;
}
} }
// Control character. // Control character.
...@@ -367,15 +389,17 @@ public final class Eia608Decoder implements SubtitleDecoder { ...@@ -367,15 +389,17 @@ public final class Eia608Decoder implements SubtitleDecoder {
private boolean handleCtrl(byte cc1, byte cc2) { private boolean handleCtrl(byte cc1, byte cc2) {
boolean isRepeatableControl = isRepeatable(cc1); boolean isRepeatableControl = isRepeatable(cc1);
if (isRepeatableControl && repeatableControlSet if (isRepeatableControl) {
&& repeatableControlCc1 == cc1 if (repeatableControlSet
&& repeatableControlCc2 == cc2) { && repeatableControlCc1 == cc1
repeatableControlSet = false; && repeatableControlCc2 == cc2) {
return true; repeatableControlSet = false;
} else if (isRepeatableControl) { return true;
repeatableControlSet = true; } else {
repeatableControlCc1 = cc1; repeatableControlSet = true;
repeatableControlCc2 = cc2; repeatableControlCc1 = cc1;
repeatableControlCc2 = cc2;
}
} }
if (isMiscCode(cc1, cc2)) { if (isMiscCode(cc1, cc2)) {
handleMiscCode(cc2); handleMiscCode(cc2);
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.text.eia608; package com.google.android.exoplayer2.text.eia608;
import android.text.TextUtils;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.Subtitle; import com.google.android.exoplayer2.text.Subtitle;
import java.util.Collections; import java.util.Collections;
...@@ -26,13 +25,17 @@ import java.util.List; ...@@ -26,13 +25,17 @@ import java.util.List;
*/ */
/* package */ final class Eia608Subtitle implements Subtitle { /* package */ final class Eia608Subtitle implements Subtitle {
private final String text; private final List<Cue> cues;
/** /**
* @param text The subtitle text. * @param cue The subtitle cue.
*/ */
public Eia608Subtitle(String text) { public Eia608Subtitle(Cue cue) {
this.text = text; if (cue == null) {
cues = Collections.emptyList();
} else {
cues = Collections.singletonList(cue);
}
} }
@Override @Override
...@@ -52,11 +55,8 @@ import java.util.List; ...@@ -52,11 +55,8 @@ import java.util.List;
@Override @Override
public List<Cue> getCues(long timeUs) { public List<Cue> getCues(long timeUs) {
if (TextUtils.isEmpty(text)) { return cues;
return Collections.emptyList();
} else {
return Collections.singletonList(new Cue(text));
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment