Skip to content

Commit

Permalink
fix: fix handling of multiple CC tracks (#6076)
Browse files Browse the repository at this point in the history
Due to issue around channel calculation, shaka was never using CC4 track
and data from there were landing in CC2 track.
  • Loading branch information
tykus160 authored and avelad committed Jan 11, 2024
1 parent e32c4bb commit e657960
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cea/cea608_memory.js
Expand Up @@ -79,7 +79,7 @@ shaka.cea.Cea608Memory = class {
* @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
*/
forceEmit(startTime, endTime) {
const stream = `CC${(this.fieldNum_<< 1) | this.channelNum_ +1}`;
const stream = `CC${((this.fieldNum_<< 1) | this.channelNum_) + 1}`;
const topLevelCue = new shaka.text.Cue(
startTime, endTime, /* payload= */ '');
topLevelCue.lineInterpretation =
Expand Down
2 changes: 1 addition & 1 deletion lib/cea/cea_decoder.js
Expand Up @@ -283,7 +283,7 @@ shaka.cea.CeaDecoder = class {
// Get the correct stream for this caption packet (CC1, ..., CC4)
const selectedChannel = fieldNum ?
this.currentField2Channel_ : this.currentField1Channel_;
const selectedMode = `CC${(fieldNum << 1) | selectedChannel + 1}`;
const selectedMode = `CC${((fieldNum << 1) | selectedChannel) + 1}`;
const selectedStream = this.cea608ModeToStream_.get(selectedMode);

// Check for bad frames (bad pairs). This can be two 0xff, two 0x00, or any
Expand Down
36 changes: 36 additions & 0 deletions test/cea/cea_decoder_unit.js
Expand Up @@ -44,6 +44,42 @@ describe('CeaDecoder', () => {
decoder.clear();
});

it('painton captions on CC4', () => {
const controlCount = 0x03;
const captionData = 0xc0 | controlCount;
const paintonCaptionCC4Packet = new Uint8Array([
...atscCaptionInitBytes, captionData, /* padding= */ 0xff,
0xfd, 0x9d, 0x29, // Paint-on mode (RDC control code).
0xfd, 0xf4, 0xe5, // t, e
0xfd, 0x73, 0xf4, // s, t
]);

const startTimeCaption1 = 1;
const startTimeCaption2 = 2;
const expectedText = 'test';

const topLevelCue = new shaka.text.Cue(startTimeCaption1,
startTimeCaption2, '');
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
CeaUtils.createDefaultCue(
startTimeCaption1, startTimeCaption2, expectedText),
];

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

decoder.extract(paintonCaptionCC4Packet, startTimeCaption1);
decoder.extract(eraseDisplayedMemory, startTimeCaption2);
const captions = decoder.decode();

expect(captions).toEqual(expectedCaptions);
});

it('green and underlined popon caption data on CC3', () => {
const controlCount = 0x08;
const captionData = 0xc0 | controlCount;
Expand Down

0 comments on commit e657960

Please sign in to comment.