-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cea): Add CEA parser for TS (#4697)
Closes #3674 Co-authored-by: Joey Parrish <[email protected]>
- Loading branch information
1 parent
a61c084
commit 70fad8d
Showing
15 changed files
with
367 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*! @license | ||
* Shaka Player | ||
* Copyright 2016 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
goog.provide('shaka.cea.TsCeaParser'); | ||
|
||
goog.require('shaka.cea.ICeaParser'); | ||
goog.require('shaka.cea.SeiProcessor'); | ||
goog.require('shaka.util.BufferUtils'); | ||
goog.require('shaka.util.TsParser'); | ||
|
||
/** | ||
* MPEG TS CEA parser. | ||
* @implements {shaka.cea.ICeaParser} | ||
*/ | ||
shaka.cea.TsCeaParser = class { | ||
/** */ | ||
constructor() { | ||
/** | ||
* SEI data processor. | ||
* @private | ||
* @const {!shaka.cea.SeiProcessor} | ||
*/ | ||
this.seiProcessor_ = new shaka.cea.SeiProcessor(); | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
init(initSegment) { | ||
// TS hasn't init segment | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
parse(mediaSegment) { | ||
const ICeaParser = shaka.cea.ICeaParser; | ||
|
||
/** @type {!Array<!shaka.cea.ICeaParser.CaptionPacket>} **/ | ||
const captionPackets = []; | ||
|
||
const uint8ArrayData = shaka.util.BufferUtils.toUint8(mediaSegment); | ||
if (!shaka.util.TsParser.probe(uint8ArrayData)) { | ||
return captionPackets; | ||
} | ||
const tsParser = new shaka.util.TsParser().parse(uint8ArrayData); | ||
const videoNalus = tsParser.getVideoNalus(); | ||
for (const nalu of videoNalus) { | ||
if (nalu.type == ICeaParser.H264_NALU_TYPE_SEI && | ||
nalu.time != null) { | ||
for (const packet of this.seiProcessor_.process(nalu.data)) { | ||
captionPackets.push({ | ||
packet: packet, | ||
pts: nalu.time, | ||
}); | ||
} | ||
} | ||
} | ||
return captionPackets; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.