mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-17 16:26:39 +03:00
562a2d567b
This enables the eslint rule requiring jsdocs on all class
declarations, function declarations, and methods.
Unfortunately, there are two problems with this:
1. We don't use class _declarations_, we use class _expressions_,
which are not covered by this rule. So it does not enforce jsdoc at
the class level.
2. We tend to document a class at the class-level, rather than at the
constructor. But a constructor counts as a method for eslint, so it
requires docs on the constructor. There is no way to configure it to
make an exception for trivial constructors.
So for all trivial (no-argument) constructors, we add empty jsdocs:
/** */
constructor() {
This was quicker and easier than setting up some alternative plugin in
eslint to make an exception for us.
The good news is that this rule caught several undocumented parameters
and places where the jsdoc comment was malformed. So fixing those
also improves the compiler's ability to enforce types.
Change-Id: Icbc46ed690c94e53d354648a883119524f8fca45
104 lines
2.6 KiB
JavaScript
104 lines
2.6 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.media.IClosedCaptionParser');
|
|
goog.provide('shaka.media.ClosedCaptionParser');
|
|
|
|
goog.require('shaka.cea.CeaDecoder');
|
|
goog.require('shaka.cea.Mp4CeaParser');
|
|
goog.require('shaka.util.BufferUtils');
|
|
goog.requireType('shaka.cea.ICaptionDecoder');
|
|
goog.requireType('shaka.cea.ICaptionDecoder.ClosedCaption');
|
|
goog.requireType('shaka.cea.ICeaParser');
|
|
|
|
|
|
/**
|
|
* The IClosedCaptionParser defines the interface to provide all operations for
|
|
* parsing the closed captions embedded in Dash videos streams.
|
|
* TODO: Remove this interface and move method definitions
|
|
* directly to ClosedCaptonParser.
|
|
* @interface
|
|
*/
|
|
shaka.media.IClosedCaptionParser = class {
|
|
/**
|
|
* Initialize the caption parser. This should be called only once.
|
|
* @param {BufferSource} initSegment
|
|
*/
|
|
init(initSegment) {}
|
|
|
|
/**
|
|
* Parses embedded CEA closed captions and interacts with the underlying
|
|
* CaptionStream, and calls the callback function when there are closed
|
|
* captions.
|
|
*
|
|
* @param {BufferSource} mediaFragment
|
|
* @return {!Array<!shaka.cea.ICaptionDecoder.ClosedCaption>}
|
|
* An array of parsed closed captions.
|
|
*/
|
|
parseFrom(mediaFragment) {}
|
|
|
|
/**
|
|
* Resets the CaptionStream.
|
|
*/
|
|
reset() {}
|
|
};
|
|
|
|
/**
|
|
* Closed Caption Parser provides all operations for parsing the closed captions
|
|
* embedded in Dash videos streams.
|
|
*
|
|
* @implements {shaka.media.IClosedCaptionParser}
|
|
* @final
|
|
*/
|
|
shaka.media.ClosedCaptionParser = class {
|
|
/** */
|
|
constructor() {
|
|
/**
|
|
* MP4 Parser to extract closed caption packets from H.264 video.
|
|
* @private {!shaka.cea.ICeaParser}
|
|
*/
|
|
this.ceaParser_ = new shaka.cea.Mp4CeaParser();
|
|
|
|
/**
|
|
* Decoder for decoding CEA-X08 data from closed caption packets.
|
|
* @private {!shaka.cea.ICaptionDecoder}
|
|
*/
|
|
this.ceaDecoder_ = new shaka.cea.CeaDecoder();
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
*/
|
|
init(initSegment) {
|
|
this.ceaParser_.init(initSegment);
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
*/
|
|
parseFrom(mediaFragment) {
|
|
// Parse the fragment.
|
|
const captionPackets = this.ceaParser_.parse(mediaFragment);
|
|
|
|
// Extract the caption packets for decoding.
|
|
for (const captionPacket of captionPackets) {
|
|
const uint8ArrayData =
|
|
shaka.util.BufferUtils.toUint8(captionPacket.packet);
|
|
this.ceaDecoder_.extract(uint8ArrayData, captionPacket.pts);
|
|
}
|
|
|
|
// Decode and return the parsed captions.
|
|
return this.ceaDecoder_.decode();
|
|
}
|
|
|
|
/**
|
|
* @override
|
|
*/
|
|
reset() {
|
|
this.ceaDecoder_.clear();
|
|
}
|
|
};
|