Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CEA): Fix multi byte language support in CEA-708 #7929

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions lib/cea/cea708_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,16 @@ shaka.cea.Cea708Service = class {
const firstByte = dtvccPacket.readByte().value;
const secondByte = dtvccPacket.readByte().value;

const isTextBlock = (b) => {
return (b >= 0x20 && b <= 0x7f) || (b >= 0xa0 && b <= 0xff);
const toHexString = (byteArray) => {
return byteArray.map((byte) => {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('');
};

if (isTextBlock(firstByte) && isTextBlock(secondByte)) {
const toHexString = (byteArray) => {
return byteArray.map((byte) => {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('');
};
const unicode = toHexString([firstByte, secondByte]);
// Takes a unicode hex string and creates a single character.
const char = String.fromCharCode(parseInt(unicode, 16));
this.currentWindow_.setCharacter(char);
return [];
} else {
dtvccPacket.rewind(2);
}
const unicode = toHexString([firstByte, secondByte]);
// Takes a unicode hex string and creates a single character.
const char = String.fromCharCode(parseInt(unicode, 16));
this.currentWindow_.setCharacter(char);
return [];
}

const window = this.currentWindow_;
Expand Down
31 changes: 29 additions & 2 deletions test/cea/cea708_service_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ describe('Cea708Service', () => {
expect(captions).toEqual(expectedCaptions);
});


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

it('decodes multibyte unstyled caption text (Polish)', () => {
const controlCodes = [
...defineWindow,
// Series of C0 control codes that add multi-byte text.
0x18, 0x01, 0x7c, 0xF3, 0x18, 0x01, 0x42, 0x18, 0x01, 0x07, // ż, ó, ł, ć
];

const packet1 = createCea708PacketFromBytes(controlCodes, startTime);
const packet2 = createCea708PacketFromBytes(hideWindow, endTime);

const text = 'żółć'; // cspell:ignore żółć
const topLevelCue = CeaUtils.createWindowedCue(startTime, endTime, '',
serviceNumber, windowId, rowCount, colCount, anchorId);
topLevelCue.nestedCues = [
CeaUtils.createDefaultCue(startTime, endTime, /* payload= */ text),
];

const expectedCaptions = [
{
stream,
cue: topLevelCue,
},
];

const captions = getCaptionsFromPackets(service, packet1, packet2);
expect(captions).toEqual(expectedCaptions);
});

it('setPenLocation sets the pen location correctly', () => {
const controlCodes = [
...defineWindow,
Expand Down
Loading