CEA608: no-op readability clean-up
PiperOrigin-RevId: 256676196
This commit is contained in:
parent
fbb76243bd
commit
d66f0c51a4
@ -387,45 +387,27 @@ public final class Cea608Decoder extends CeaDecoder {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special North American character set.
|
if (!updateAndVerifyCurrentChannel(ccData1)) {
|
||||||
// ccData1 - 0|0|0|1|C|0|0|1
|
// Wrong channel.
|
||||||
// ccData2 - 0|0|1|1|X|X|X|X
|
continue;
|
||||||
if (((ccData1 & 0xF7) == 0x11) && ((ccData2 & 0xF0) == 0x30)) {
|
}
|
||||||
if (getChannel(ccData1) == selectedChannel) {
|
|
||||||
|
if (isCtrlCode(ccData1)) {
|
||||||
|
if (isSpecialChar(ccData1, ccData2)) {
|
||||||
|
// Special North American character.
|
||||||
currentCueBuilder.append(getSpecialChar(ccData2));
|
currentCueBuilder.append(getSpecialChar(ccData2));
|
||||||
}
|
} else if (isExtendedWestEuropeanChar(ccData1, ccData2)) {
|
||||||
continue;
|
// Extended West European character.
|
||||||
}
|
// Remove standard equivalent of the special extended char before appending new one.
|
||||||
|
|
||||||
// Extended Western European character set.
|
|
||||||
// ccData1 - 0|0|0|1|C|0|1|S
|
|
||||||
// ccData2 - 0|0|1|X|X|X|X|X
|
|
||||||
if (((ccData1 & 0xF6) == 0x12) && (ccData2 & 0xE0) == 0x20) {
|
|
||||||
if (getChannel(ccData1) == selectedChannel) {
|
|
||||||
// Remove standard equivalent of the special extended char before appending new one
|
|
||||||
currentCueBuilder.backspace();
|
currentCueBuilder.backspace();
|
||||||
if ((ccData1 & 0x01) == 0x00) {
|
currentCueBuilder.append(getExtendedWestEuropeanChar(ccData1, ccData2));
|
||||||
// Extended Spanish/Miscellaneous and French character set (S = 0).
|
} else {
|
||||||
currentCueBuilder.append(getExtendedEsFrChar(ccData2));
|
// Non-character control code.
|
||||||
} else {
|
handleCtrl(ccData1, ccData2, repeatedControlPossible);
|
||||||
// Extended Portuguese and German/Danish character set (S = 1).
|
|
||||||
currentCueBuilder.append(getExtendedPtDeChar(ccData2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Control character.
|
|
||||||
// ccData1 - 0|0|0|X|X|X|X|X
|
|
||||||
if ((ccData1 & 0xE0) == 0x00) {
|
|
||||||
handleCtrl(ccData1, ccData2, repeatedControlPossible);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentChannel != selectedChannel) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Basic North American character set.
|
// Basic North American character set.
|
||||||
currentCueBuilder.append(getChar(ccData1));
|
currentCueBuilder.append(getChar(ccData1));
|
||||||
if ((ccData2 & 0xE0) != 0x00) {
|
if ((ccData2 & 0xE0) != 0x00) {
|
||||||
@ -440,8 +422,14 @@ public final class Cea608Decoder extends CeaDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean updateAndVerifyCurrentChannel(byte cc1) {
|
||||||
|
if (isCtrlCode(cc1)) {
|
||||||
|
currentChannel = getChannel(cc1);
|
||||||
|
}
|
||||||
|
return currentChannel == selectedChannel;
|
||||||
|
}
|
||||||
|
|
||||||
private void handleCtrl(byte cc1, byte cc2, boolean repeatedControlPossible) {
|
private void handleCtrl(byte cc1, byte cc2, boolean repeatedControlPossible) {
|
||||||
currentChannel = getChannel(cc1);
|
|
||||||
// Most control commands are sent twice in succession to ensure they are received properly. We
|
// Most control commands are sent twice in succession to ensure they are received properly. We
|
||||||
// don't want to process duplicate commands, so if we see the same repeatable command twice in a
|
// don't want to process duplicate commands, so if we see the same repeatable command twice in a
|
||||||
// row then we ignore the second one.
|
// row then we ignore the second one.
|
||||||
@ -459,10 +447,6 @@ public final class Cea608Decoder extends CeaDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentChannel != selectedChannel) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMidrowCtrlCode(cc1, cc2)) {
|
if (isMidrowCtrlCode(cc1, cc2)) {
|
||||||
handleMidrowCtrl(cc2);
|
handleMidrowCtrl(cc2);
|
||||||
} else if (isPreambleAddressCode(cc1, cc2)) {
|
} else if (isPreambleAddressCode(cc1, cc2)) {
|
||||||
@ -681,11 +665,33 @@ public final class Cea608Decoder extends CeaDecoder {
|
|||||||
return (char) BASIC_CHARACTER_SET[index];
|
return (char) BASIC_CHARACTER_SET[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isSpecialChar(byte cc1, byte cc2) {
|
||||||
|
// cc1 - 0|0|0|1|C|0|0|1
|
||||||
|
// cc2 - 0|0|1|1|X|X|X|X
|
||||||
|
return ((cc1 & 0xF7) == 0x11) && ((cc2 & 0xF0) == 0x30);
|
||||||
|
}
|
||||||
|
|
||||||
private static char getSpecialChar(byte ccData) {
|
private static char getSpecialChar(byte ccData) {
|
||||||
int index = ccData & 0x0F;
|
int index = ccData & 0x0F;
|
||||||
return (char) SPECIAL_CHARACTER_SET[index];
|
return (char) SPECIAL_CHARACTER_SET[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isExtendedWestEuropeanChar(byte cc1, byte cc2) {
|
||||||
|
// cc1 - 0|0|0|1|C|0|1|S
|
||||||
|
// cc2 - 0|0|1|X|X|X|X|X
|
||||||
|
return ((cc1 & 0xF6) == 0x12) && ((cc2 & 0xE0) == 0x20);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static char getExtendedWestEuropeanChar(byte cc1, byte cc2) {
|
||||||
|
if ((cc1 & 0x01) == 0x00) {
|
||||||
|
// Extended Spanish/Miscellaneous and French character set (S = 0).
|
||||||
|
return getExtendedEsFrChar(cc2);
|
||||||
|
} else {
|
||||||
|
// Extended Portuguese and German/Danish character set (S = 1).
|
||||||
|
return getExtendedPtDeChar(cc2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static char getExtendedEsFrChar(byte ccData) {
|
private static char getExtendedEsFrChar(byte ccData) {
|
||||||
int index = ccData & 0x1F;
|
int index = ccData & 0x1F;
|
||||||
return (char) SPECIAL_ES_FR_CHARACTER_SET[index];
|
return (char) SPECIAL_ES_FR_CHARACTER_SET[index];
|
||||||
@ -696,6 +702,11 @@ public final class Cea608Decoder extends CeaDecoder {
|
|||||||
return (char) SPECIAL_PT_DE_CHARACTER_SET[index];
|
return (char) SPECIAL_PT_DE_CHARACTER_SET[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isCtrlCode(byte cc1) {
|
||||||
|
// cc1 - 0|0|0|X|X|X|X|X
|
||||||
|
return (cc1 & 0xE0) == 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
private static int getChannel(byte cc1) {
|
private static int getChannel(byte cc1) {
|
||||||
// cc1 - X|X|X|X|C|X|X|X
|
// cc1 - X|X|X|X|C|X|X|X
|
||||||
return (cc1 >> 3) & 0x1;
|
return (cc1 >> 3) & 0x1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user