mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +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
257 lines
6.0 KiB
JavaScript
257 lines
6.0 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.util.Stats');
|
|
|
|
goog.require('shaka.util.StateHistory');
|
|
goog.require('shaka.util.SwitchHistory');
|
|
|
|
|
|
/**
|
|
* This class tracks all the various components (some optional) that are used to
|
|
* populate |shaka.extern.Stats| which is passed to the app.
|
|
*
|
|
* @final
|
|
*/
|
|
shaka.util.Stats = class {
|
|
/** */
|
|
constructor() {
|
|
/** @private {number} */
|
|
this.width_ = NaN;
|
|
/** @private {number} */
|
|
this.height_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.totalDroppedFrames_ = NaN;
|
|
/** @private {number} */
|
|
this.totalDecodedFrames_ = NaN;
|
|
/** @private {number} */
|
|
this.totalCorruptedFrames_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.completionPercent_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.loadLatencySeconds_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.manifestTimeSeconds_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.drmTimeSeconds_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.licenseTimeSeconds_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.liveLatencySeconds_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.maxSegmentDurationSeconds_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.currentStreamBandwidth_ = NaN;
|
|
/** @private {number} */
|
|
this.bandwidthEstimate_ = NaN;
|
|
|
|
/** @private {!shaka.util.StateHistory} */
|
|
this.stateHistory_ = new shaka.util.StateHistory();
|
|
|
|
/** @private {!shaka.util.SwitchHistory} */
|
|
this.switchHistory_ = new shaka.util.SwitchHistory();
|
|
}
|
|
|
|
/**
|
|
* Update the ratio of dropped frames to total frames. This will replace the
|
|
* previous values.
|
|
*
|
|
* @param {number} dropped
|
|
* @param {number} decoded
|
|
*/
|
|
setDroppedFrames(dropped, decoded) {
|
|
this.totalDroppedFrames_ = dropped;
|
|
this.totalDecodedFrames_ = decoded;
|
|
}
|
|
|
|
|
|
/**
|
|
* Update corrupted frames. This will replace the previous values.
|
|
*
|
|
* @param {number} corrupted
|
|
*/
|
|
setCorruptedFrames(corrupted) {
|
|
this.totalCorruptedFrames_ = corrupted;
|
|
}
|
|
|
|
/**
|
|
* Set the width and height of the video we are currently playing.
|
|
*
|
|
* @param {number} width
|
|
* @param {number} height
|
|
*/
|
|
setResolution(width, height) {
|
|
this.width_ = width;
|
|
this.height_ = height;
|
|
}
|
|
|
|
/**
|
|
* Record the time it took between the user signalling "I want to play this"
|
|
* to "I am now seeing this".
|
|
*
|
|
* @param {number} seconds
|
|
*/
|
|
setLoadLatency(seconds) {
|
|
this.loadLatencySeconds_ = seconds;
|
|
}
|
|
|
|
/**
|
|
* Record the time it took to download and parse the manifest.
|
|
*
|
|
* @param {number} seconds
|
|
*/
|
|
setManifestTime(seconds) {
|
|
this.manifestTimeSeconds_ = seconds;
|
|
}
|
|
|
|
/**
|
|
* Record the current completion percent. This is the "high water mark", so it
|
|
* will store the highest provided completion percent.
|
|
*
|
|
* @param {number} percent
|
|
*/
|
|
setCompletionPercent(percent) {
|
|
if (isNaN(this.completionPercent_)) {
|
|
this.completionPercent_ = percent;
|
|
} else {
|
|
this.completionPercent_ = Math.max(this.completionPercent_, percent);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Record the time it took to download the first drm key.
|
|
*
|
|
* @param {number} seconds
|
|
*/
|
|
setDrmTime(seconds) {
|
|
this.drmTimeSeconds_ = seconds;
|
|
}
|
|
|
|
/**
|
|
* Record the cumulative time spent on license requests during this session.
|
|
*
|
|
* @param {number} seconds
|
|
*/
|
|
setLicenseTime(seconds) {
|
|
this.licenseTimeSeconds_ = seconds;
|
|
}
|
|
|
|
/**
|
|
* Record the latency in live streams.
|
|
*
|
|
* @param {number} seconds
|
|
*/
|
|
setLiveLatency(seconds) {
|
|
this.liveLatencySeconds_ = seconds;
|
|
}
|
|
|
|
/**
|
|
* Record the presentation's max segment duration.
|
|
*
|
|
* @param {number} seconds
|
|
*/
|
|
setMaxSegmentDuration(seconds) {
|
|
this.maxSegmentDurationSeconds_ = seconds;
|
|
}
|
|
|
|
/**
|
|
* @param {number} bandwidth
|
|
*/
|
|
setCurrentStreamBandwidth(bandwidth) {
|
|
this.currentStreamBandwidth_ = bandwidth;
|
|
}
|
|
|
|
/**
|
|
* @param {number} bandwidth
|
|
*/
|
|
setBandwidthEstimate(bandwidth) {
|
|
this.bandwidthEstimate_ = bandwidth;
|
|
}
|
|
|
|
/**
|
|
* @return {!shaka.util.StateHistory}
|
|
*/
|
|
getStateHistory() {
|
|
return this.stateHistory_;
|
|
}
|
|
|
|
/**
|
|
* @return {!shaka.util.SwitchHistory}
|
|
*/
|
|
getSwitchHistory() {
|
|
return this.switchHistory_;
|
|
}
|
|
|
|
/**
|
|
* Create a stats blob that we can pass up to the app. This blob will not
|
|
* reference any internal data.
|
|
*
|
|
* @return {shaka.extern.Stats}
|
|
*/
|
|
getBlob() {
|
|
return {
|
|
width: this.width_,
|
|
height: this.height_,
|
|
streamBandwidth: this.currentStreamBandwidth_,
|
|
decodedFrames: this.totalDecodedFrames_,
|
|
droppedFrames: this.totalDroppedFrames_,
|
|
corruptedFrames: this.totalCorruptedFrames_,
|
|
estimatedBandwidth: this.bandwidthEstimate_,
|
|
completionPercent: this.completionPercent_,
|
|
loadLatency: this.loadLatencySeconds_,
|
|
manifestTimeSeconds: this.manifestTimeSeconds_,
|
|
drmTimeSeconds: this.drmTimeSeconds_,
|
|
playTime: this.stateHistory_.getTimeSpentIn('playing'),
|
|
pauseTime: this.stateHistory_.getTimeSpentIn('paused'),
|
|
bufferingTime: this.stateHistory_.getTimeSpentIn('buffering'),
|
|
licenseTime: this.licenseTimeSeconds_,
|
|
liveLatency: this.liveLatencySeconds_,
|
|
maxSegmentDuration: this.maxSegmentDurationSeconds_,
|
|
stateHistory: this.stateHistory_.getCopy(),
|
|
switchHistory: this.switchHistory_.getCopy(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Create an empty stats blob. This resembles the stats when we are not
|
|
* playing any content.
|
|
*
|
|
* @return {shaka.extern.Stats}
|
|
*/
|
|
static getEmptyBlob() {
|
|
return {
|
|
width: NaN,
|
|
height: NaN,
|
|
streamBandwidth: NaN,
|
|
decodedFrames: NaN,
|
|
droppedFrames: NaN,
|
|
corruptedFrames: NaN,
|
|
estimatedBandwidth: NaN,
|
|
completionPercent: NaN,
|
|
loadLatency: NaN,
|
|
manifestTimeSeconds: NaN,
|
|
drmTimeSeconds: NaN,
|
|
playTime: NaN,
|
|
pauseTime: NaN,
|
|
bufferingTime: NaN,
|
|
licenseTime: NaN,
|
|
liveLatency: NaN,
|
|
maxSegmentDuration: NaN,
|
|
switchHistory: [],
|
|
stateHistory: [],
|
|
};
|
|
}
|
|
};
|