mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-07-02 18:49:36 +03:00
64896d70b0
This reflects changes in Google's policy on JavaScript license headers, which should be smaller to avoid increasing the size of the binary unnecessarily. This also updates the company name from "Google, Inc" to "Google LLC". Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
152 lines
3.5 KiB
JavaScript
152 lines
3.5 KiB
JavaScript
/** @license
|
|
* 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.loadLatencySeconds_ = NaN;
|
|
|
|
/** @private {number} */
|
|
this.variantBandwidth_ = 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;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* @param {number} bandwidth
|
|
*/
|
|
setVariantBandwidth(bandwidth) {
|
|
this.variantBandwidth_ = 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.variantBandwidth_,
|
|
decodedFrames: this.totalDecodedFrames_,
|
|
droppedFrames: this.totalDroppedFrames_,
|
|
estimatedBandwidth: this.bandwidthEstimate_,
|
|
loadLatency: this.loadLatencySeconds_,
|
|
playTime: this.stateHistory_.getTimeSpentIn('playing'),
|
|
pauseTime: this.stateHistory_.getTimeSpentIn('paused'),
|
|
bufferingTime: this.stateHistory_.getTimeSpentIn('buffering'),
|
|
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,
|
|
estimatedBandwidth: NaN,
|
|
loadLatency: NaN,
|
|
playTime: NaN,
|
|
pauseTime: NaN,
|
|
bufferingTime: NaN,
|
|
switchHistory: [],
|
|
stateHistory: [],
|
|
};
|
|
}
|
|
};
|