Skip to content

Commit 3856c58

Browse files
authored
fix(CEA): Fix multi byte language support in CEA-708 (#7929)
Fixes #7926
1 parent c75ebd7 commit 3856c58

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

lib/cea/cea708_service.js

+9-17
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,16 @@ shaka.cea.Cea708Service = class {
171171
const firstByte = dtvccPacket.readByte().value;
172172
const secondByte = dtvccPacket.readByte().value;
173173

174-
const isTextBlock = (b) => {
175-
return (b >= 0x20 && b <= 0x7f) || (b >= 0xa0 && b <= 0xff);
174+
const toHexString = (byteArray) => {
175+
return byteArray.map((byte) => {
176+
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
177+
}).join('');
176178
};
177-
178-
if (isTextBlock(firstByte) && isTextBlock(secondByte)) {
179-
const toHexString = (byteArray) => {
180-
return byteArray.map((byte) => {
181-
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
182-
}).join('');
183-
};
184-
const unicode = toHexString([firstByte, secondByte]);
185-
// Takes a unicode hex string and creates a single character.
186-
const char = String.fromCharCode(parseInt(unicode, 16));
187-
this.currentWindow_.setCharacter(char);
188-
return [];
189-
} else {
190-
dtvccPacket.rewind(2);
191-
}
179+
const unicode = toHexString([firstByte, secondByte]);
180+
// Takes a unicode hex string and creates a single character.
181+
const char = String.fromCharCode(parseInt(unicode, 16));
182+
this.currentWindow_.setCharacter(char);
183+
return [];
192184
}
193185

194186
const window = this.currentWindow_;

test/cea/cea708_service_unit.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ describe('Cea708Service', () => {
130130
expect(captions).toEqual(expectedCaptions);
131131
});
132132

133-
134-
it('decodes multibyte unstyled caption text', () => {
133+
it('decodes multibyte unstyled caption text (Korean)', () => {
135134
const controlCodes = [
136135
...defineWindow,
137136
// Series of C0 control codes that add multi-byte text.
@@ -159,6 +158,34 @@ describe('Cea708Service', () => {
159158
expect(captions).toEqual(expectedCaptions);
160159
});
161160

161+
it('decodes multibyte unstyled caption text (Polish)', () => {
162+
const controlCodes = [
163+
...defineWindow,
164+
// Series of C0 control codes that add multi-byte text.
165+
0x18, 0x01, 0x7c, 0xF3, 0x18, 0x01, 0x42, 0x18, 0x01, 0x07, // ż, ó, ł, ć
166+
];
167+
168+
const packet1 = createCea708PacketFromBytes(controlCodes, startTime);
169+
const packet2 = createCea708PacketFromBytes(hideWindow, endTime);
170+
171+
const text = 'żółć'; // cspell:ignore żółć
172+
const topLevelCue = CeaUtils.createWindowedCue(startTime, endTime, '',
173+
serviceNumber, windowId, rowCount, colCount, anchorId);
174+
topLevelCue.nestedCues = [
175+
CeaUtils.createDefaultCue(startTime, endTime, /* payload= */ text),
176+
];
177+
178+
const expectedCaptions = [
179+
{
180+
stream,
181+
cue: topLevelCue,
182+
},
183+
];
184+
185+
const captions = getCaptionsFromPackets(service, packet1, packet2);
186+
expect(captions).toEqual(expectedCaptions);
187+
});
188+
162189
it('setPenLocation sets the pen location correctly', () => {
163190
const controlCodes = [
164191
...defineWindow,

0 commit comments

Comments
 (0)