Skip to content

Commit

Permalink
Code changes suggested by tonihei
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmatyas committed Apr 29, 2019
1 parent 2f356ba commit 3e14ce1
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ public final class Cea608Decoder extends CeaDecoder {

private static final byte CTRL_BACKSPACE = 0x21;

@SuppressWarnings("unused")
private static final byte CTRL_ALARM_OFF= 0x22; // not supported any more

@SuppressWarnings("unused")
private static final byte CTRL_ALARM_ON= 0x23; // not supported any more

private static final byte CTRL_DELETE_TO_END_OF_ROW = 0x24;

/**
Expand Down Expand Up @@ -258,7 +252,7 @@ public final class Cea608Decoder extends CeaDecoder {
// The incoming characters may belong to 3 different services based on the last received control
// codes. The 3 services are Captioning, Text and XDS. In this decoder we only intend to process
// bytes belonging to the Captioning service.
private boolean isInCaptionMode = true;
private boolean isInCaptionMode;

public Cea608Decoder(String mimeType, int accessibilityChannel) {
ccData = new ParsableByteArray();
Expand Down Expand Up @@ -291,6 +285,7 @@ public Cea608Decoder(String mimeType, int accessibilityChannel) {

setCaptionMode(CC_MODE_UNKNOWN);
resetCueBuilders();
isInCaptionMode = true;
}

@Override
Expand Down Expand Up @@ -330,23 +325,28 @@ protected Subtitle createSubtitle() {
return new CeaSubtitle(cues);
}

private boolean isCodeForUnsupportedMode(byte cc1, byte cc2) {
private static boolean isCodeForUnsupportedMode(byte cc1, byte cc2) {
// Control codes from 0x01 to 0x0F indicate the beginning of XDS Data
if (0x01 <= cc1 && cc1 <= 0x0F) {
return true;
}

// 2 commands switch to TEXT mode.
if (((cc1 & 0xF7) == 0x14) // first byte must be 0x14 or 0x1C based on channel
if ((isModeSwitchCommand(cc1))
&& (cc2 == CTRL_TEXT_RESTART || cc2 == CTRL_RESUME_TEXT_DISPLAY)) {
return true;
}

return false;
}

// first byte of these commands must be 0x14 or 0x1C based on channel
private static boolean isModeSwitchCommand(byte cc1) {
return (cc1 & 0xF7) == 0x14;
}

private static boolean isControlCodeSwitchingToCaptionMode(byte cc1, byte cc2) {
if ((cc1 & 0xF7) != 0x14) { // Matching commands must have the CC1 value: 0|0|0|1|CH|1|0|0 where CH is the channel bit
if (!isModeSwitchCommand(cc1)) {
return false;
}

Expand Down

0 comments on commit 3e14ce1

Please sign in to comment.