Skip to content

Commit

Permalink
fix(cea): Fix not rendering CEA-608 on encrypted mp4 segments
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Dec 1, 2022
1 parent a652207 commit cc8c047
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 33 deletions.
43 changes: 13 additions & 30 deletions lib/cea/mp4_cea_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ goog.require('shaka.util.Mp4BoxParsers');
* @implements {shaka.cea.ICeaParser}
*/
shaka.cea.Mp4CeaParser = class {
/**
* @param {string} mimeType
*/
constructor(mimeType) {
/**
* @private {string}
*/
this.mimeType_ = mimeType;

/** */
constructor() {
/**
* SEI data processor.
* @private
Expand Down Expand Up @@ -82,8 +75,6 @@ shaka.cea.Mp4CeaParser = class {
};
};

let encrypted = false;

new Mp4Parser()
.box('moov', Mp4Parser.children)
.box('mvex', Mp4Parser.children)
Expand Down Expand Up @@ -116,10 +107,6 @@ shaka.cea.Mp4CeaParser = class {
.box('stbl', Mp4Parser.children)
.fullBox('stsd', Mp4Parser.sampleDescription)

.box('encv', () => {
encrypted = true;
})

// These are the various boxes that signal a codec.
// Use these to set bistreamFormat_.
.box('avc1', bitstreamFormatSetter(BitstreamFormat.H264))
Expand All @@ -130,6 +117,17 @@ shaka.cea.Mp4CeaParser = class {
.box('dvh1', bitstreamFormatSetter(BitstreamFormat.H265))
.box('dvhe', bitstreamFormatSetter(BitstreamFormat.H265))

.box('encv', Mp4Parser.children)
// These are the various boxes that signal a codec in
// encrypted segments
// Use these to set bistreamFormat_.
.box('avcC', bitstreamFormatSetter(BitstreamFormat.H264))
.box('hvcE', bitstreamFormatSetter(BitstreamFormat.H265))
.box('hvcC', bitstreamFormatSetter(BitstreamFormat.H265))
// Dobly vision is also H265.
.box('dvcC', bitstreamFormatSetter(BitstreamFormat.H265))
.box('dvvC', bitstreamFormatSetter(BitstreamFormat.H265))

.parse(initSegment, /* partialOkay= */ true);

// At least one track should exist, and each track should have a
Expand All @@ -142,21 +140,6 @@ shaka.cea.Mp4CeaParser = class {
shaka.util.Error.Code.INVALID_MP4_CEA);
}

// If the content is encrypted we have no way of knowing the
// bitstreamformat, so we try to get it from the mimetype.
if (encrypted && this.bitstreamFormat_ == BitstreamFormat.UNKNOWN) {
if (this.mimeType_.includes('avc1.') ||
this.mimeType_.includes('avc3.')) {
this.bitstreamFormat_ = BitstreamFormat.H264;
}
if (this.mimeType_.includes('hev1.') ||
this.mimeType_.includes('hvc1.') ||
this.mimeType_.includes('dvh1.') ||
this.mimeType_.includes('dvhe.')) {
this.bitstreamFormat_ = BitstreamFormat.H265;
}
}

if (this.bitstreamFormat_ == BitstreamFormat.UNKNOWN) {
shaka.log.alwaysWarn(
'Unable to determine bitstream format for CEA parsing!');
Expand Down
2 changes: 1 addition & 1 deletion lib/media/closed_caption_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ shaka.media.ClosedCaptionParser = class {

if (mimeType.toLowerCase().includes('video/mp4')) {
// MP4 Parser to extract closed caption packets from H.264/H.265 video.
this.ceaParser_ = new shaka.cea.Mp4CeaParser(mimeType);
this.ceaParser_ = new shaka.cea.Mp4CeaParser();
}
if (mimeType.toLowerCase().includes('video/mp2t')) {
// TS Parser to extract closed caption packets from H.264 video.
Expand Down
4 changes: 2 additions & 2 deletions test/cea/mp4_cea_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Mp4CeaParser', () => {
});

it('parses cea data from mp4 stream', () => {
const cea708Parser = new shaka.cea.Mp4CeaParser('video/mp4');
const cea708Parser = new shaka.cea.Mp4CeaParser();

const expectedCea708Packet = new Uint8Array([
0xb5, 0x00, 0x31, 0x47, 0x41, 0x39, 0x34, 0x03,
Expand All @@ -71,7 +71,7 @@ describe('Mp4CeaParser', () => {
});

it('parses an invalid init segment', () => {
const cea708Parser = new shaka.cea.Mp4CeaParser('video/mp4');
const cea708Parser = new shaka.cea.Mp4CeaParser();

const expected = Util.jasmineError(new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
Expand Down

0 comments on commit cc8c047

Please sign in to comment.