mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-24 17:35:10 +03:00
7bda65dcc7
Fixes #5178
Changes included:
- converted CEA parsers to externs
- added API to register/unregister CEA parsers
- TextEngine now checks is CEA decoder registered
- excluded CEA plugin from core build
- added lcevc plugin to core build
Bundle size results (all in KB, compared to
bf4b4a54cc):
| core | complete - ui | complete - ui - cea
-- | -- | -- | --
before | 246 | 473 | 473
after | 231 | 474 | 459
70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.cea.TsCeaParser');
|
|
|
|
goog.require('shaka.cea.CeaUtils');
|
|
goog.require('shaka.cea.SeiProcessor');
|
|
goog.require('shaka.media.ClosedCaptionParser');
|
|
goog.require('shaka.util.BufferUtils');
|
|
goog.require('shaka.util.TsParser');
|
|
|
|
/**
|
|
* MPEG TS CEA parser.
|
|
* @implements {shaka.extern.ICeaParser}
|
|
* @export
|
|
*/
|
|
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 CeaUtils = shaka.cea.CeaUtils;
|
|
|
|
/** @type {!Array<!shaka.extern.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 == CeaUtils.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;
|
|
}
|
|
};
|
|
|
|
shaka.media.ClosedCaptionParser.registerParser('video/mp2t',
|
|
() => new shaka.cea.TsCeaParser());
|