Commit faecef0b by Oliver Woodman

Merge pull request #5807 from zsmatyas:dev-v2

PiperOrigin-RevId: 246132620
parents f8cd770d 3e14ce10
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
### dev-v2 (not yet released) ### ### dev-v2 (not yet released) ###
* Decoders: prefer codecs that advertise format support over ones that do not, * Decoders:
even if they are listed lower in the `MediaCodecList`. * Prefer codecs that advertise format support over ones that do not, even if
they are listed lower in the `MediaCodecList`.
* CEA-608: Handle XDS and TEXT modes
([5807](https://github.com/google/ExoPlayer/pull/5807)).
* Audio: fix an issue where not all audio was played out when the configuration * Audio: fix an issue where not all audio was played out when the configuration
for the underlying track was changing (e.g., at some period transitions). for the underlying track was changing (e.g., at some period transitions).
* UI: Change playback controls toggle from touch down to touch up events * UI: Change playback controls toggle from touch down to touch up events
......
...@@ -80,6 +80,11 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -80,6 +80,11 @@ public final class Cea608Decoder extends CeaDecoder {
* at which point the non-displayed memory becomes the displayed memory (and vice versa). * at which point the non-displayed memory becomes the displayed memory (and vice versa).
*/ */
private static final byte CTRL_RESUME_CAPTION_LOADING = 0x20; private static final byte CTRL_RESUME_CAPTION_LOADING = 0x20;
private static final byte CTRL_BACKSPACE = 0x21;
private static final byte CTRL_DELETE_TO_END_OF_ROW = 0x24;
/** /**
* Command initiating roll-up style captioning, with the maximum of 2 rows displayed * Command initiating roll-up style captioning, with the maximum of 2 rows displayed
* simultaneously. * simultaneously.
...@@ -95,25 +100,31 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -95,25 +100,31 @@ public final class Cea608Decoder extends CeaDecoder {
* simultaneously. * simultaneously.
*/ */
private static final byte CTRL_ROLL_UP_CAPTIONS_4_ROWS = 0x27; private static final byte CTRL_ROLL_UP_CAPTIONS_4_ROWS = 0x27;
/** /**
* Command initiating paint-on style captioning. Subsequent data should be addressed immediately * Command initiating paint-on style captioning. Subsequent data should be addressed immediately
* to displayed memory without need for the {@link #CTRL_RESUME_CAPTION_LOADING} command. * to displayed memory without need for the {@link #CTRL_RESUME_CAPTION_LOADING} command.
*/ */
private static final byte CTRL_RESUME_DIRECT_CAPTIONING = 0x29; private static final byte CTRL_RESUME_DIRECT_CAPTIONING = 0x29;
/** /**
* Command indicating the end of a pop-on style caption. At this point the caption loaded in * TEXT commands are switching to TEXT service. All consecutive incoming data must be filtered out
* non-displayed memory should be swapped with the one in displayed memory. If no * until a command is received that switches back to the CAPTION service.
* {@link #CTRL_RESUME_CAPTION_LOADING} command has been received, this command forces the
* receiver into pop-on style.
*/ */
private static final byte CTRL_END_OF_CAPTION = 0x2F; private static final byte CTRL_TEXT_RESTART = 0x2A;
private static final byte CTRL_RESUME_TEXT_DISPLAY = 0x2B;
private static final byte CTRL_ERASE_DISPLAYED_MEMORY = 0x2C; private static final byte CTRL_ERASE_DISPLAYED_MEMORY = 0x2C;
private static final byte CTRL_CARRIAGE_RETURN = 0x2D; private static final byte CTRL_CARRIAGE_RETURN = 0x2D;
private static final byte CTRL_ERASE_NON_DISPLAYED_MEMORY = 0x2E; private static final byte CTRL_ERASE_NON_DISPLAYED_MEMORY = 0x2E;
private static final byte CTRL_DELETE_TO_END_OF_ROW = 0x24;
private static final byte CTRL_BACKSPACE = 0x21; /**
* Command indicating the end of a pop-on style caption. At this point the caption loaded in
* non-displayed memory should be swapped with the one in displayed memory. If no {@link
* #CTRL_RESUME_CAPTION_LOADING} command has been received, this command forces the receiver into
* pop-on style.
*/
private static final byte CTRL_END_OF_CAPTION = 0x2F;
// Basic North American 608 CC char set, mostly ASCII. Indexed by (char-0x20). // Basic North American 608 CC char set, mostly ASCII. Indexed by (char-0x20).
private static final int[] BASIC_CHARACTER_SET = new int[] { private static final int[] BASIC_CHARACTER_SET = new int[] {
...@@ -237,6 +248,11 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -237,6 +248,11 @@ public final class Cea608Decoder extends CeaDecoder {
private byte repeatableControlCc2; private byte repeatableControlCc2;
private int currentChannel; private int currentChannel;
// The incoming characters may belong to 3 different services based on the last received control
// codes. The 3 services are Captioning, Text and XDS. The decoder only processes Captioning
// service bytes and drops the rest.
private boolean isInCaptionService;
public Cea608Decoder(String mimeType, int accessibilityChannel) { public Cea608Decoder(String mimeType, int accessibilityChannel) {
ccData = new ParsableByteArray(); ccData = new ParsableByteArray();
cueBuilders = new ArrayList<>(); cueBuilders = new ArrayList<>();
...@@ -268,6 +284,7 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -268,6 +284,7 @@ public final class Cea608Decoder extends CeaDecoder {
setCaptionMode(CC_MODE_UNKNOWN); setCaptionMode(CC_MODE_UNKNOWN);
resetCueBuilders(); resetCueBuilders();
isInCaptionService = true;
} }
@Override @Override
...@@ -288,6 +305,7 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -288,6 +305,7 @@ public final class Cea608Decoder extends CeaDecoder {
repeatableControlCc1 = 0; repeatableControlCc1 = 0;
repeatableControlCc2 = 0; repeatableControlCc2 = 0;
currentChannel = NTSC_CC_CHANNEL_1; currentChannel = NTSC_CC_CHANNEL_1;
isInCaptionService = true;
} }
@Override @Override
...@@ -363,6 +381,12 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -363,6 +381,12 @@ public final class Cea608Decoder extends CeaDecoder {
continue; continue;
} }
maybeUpdateIsInCaptionService(ccData1, ccData2);
if (!isInCaptionService) {
// Only the Captioning service is supported. Drop all other bytes.
continue;
}
// Special North American character set. // Special North American character set.
// ccData1 - 0|0|0|1|C|0|0|1 // ccData1 - 0|0|0|1|C|0|0|1
// ccData2 - 0|0|1|1|X|X|X|X // ccData2 - 0|0|1|1|X|X|X|X
...@@ -629,6 +653,29 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -629,6 +653,29 @@ public final class Cea608Decoder extends CeaDecoder {
cueBuilders.add(currentCueBuilder); cueBuilders.add(currentCueBuilder);
} }
private void maybeUpdateIsInCaptionService(byte cc1, byte cc2) {
if (isXdsControlCode(cc1)) {
isInCaptionService = false;
} else if (isServiceSwitchCommand(cc1)) {
switch (cc2) {
case CTRL_TEXT_RESTART:
case CTRL_RESUME_TEXT_DISPLAY:
isInCaptionService = false;
break;
case CTRL_END_OF_CAPTION:
case CTRL_RESUME_CAPTION_LOADING:
case CTRL_RESUME_DIRECT_CAPTIONING:
case CTRL_ROLL_UP_CAPTIONS_2_ROWS:
case CTRL_ROLL_UP_CAPTIONS_3_ROWS:
case CTRL_ROLL_UP_CAPTIONS_4_ROWS:
isInCaptionService = true;
break;
default:
// No update.
}
}
}
private static char getChar(byte ccData) { private static char getChar(byte ccData) {
int index = (ccData & 0x7F) - 0x20; int index = (ccData & 0x7F) - 0x20;
return (char) BASIC_CHARACTER_SET[index]; return (char) BASIC_CHARACTER_SET[index];
...@@ -683,6 +730,15 @@ public final class Cea608Decoder extends CeaDecoder { ...@@ -683,6 +730,15 @@ public final class Cea608Decoder extends CeaDecoder {
return (cc1 & 0xF0) == 0x10; return (cc1 & 0xF0) == 0x10;
} }
private static boolean isXdsControlCode(byte cc1) {
return 0x01 <= cc1 && cc1 <= 0x0F;
}
private static boolean isServiceSwitchCommand(byte cc1) {
// cc1 - 0|0|0|1|C|1|0|0
return (cc1 & 0xF7) == 0x14;
}
private static class CueBuilder { private static class CueBuilder {
// 608 captions define a 15 row by 32 column screen grid. These constants convert from 608 // 608 captions define a 15 row by 32 column screen grid. These constants convert from 608
......
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