mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
970d7756ea
The goal is to simplify and abstract feature logic detection. Currently lots of places depend on various calls to `shaka.util.Platform` and mainteinance of this is hard & not easy to read. By introducing device API ideally rest of the player logic would look into device features instead of directly checking platform. Additionally we can more easily cache needed values, so we won't have to parse user agent several times anymore. --------- Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.polyfill.VideoPlaybackQuality');
|
|
|
|
goog.require('shaka.polyfill');
|
|
goog.require('shaka.util.Dom');
|
|
|
|
|
|
/**
|
|
* @summary A polyfill to provide MSE VideoPlaybackQuality metrics.
|
|
* Many browsers do not yet provide this API, and Chrome currently provides
|
|
* similar data through individual prefixed attributes on HTMLVideoElement.
|
|
* @export
|
|
*/
|
|
shaka.polyfill.VideoPlaybackQuality = class {
|
|
/**
|
|
* Install the polyfill if needed.
|
|
* @export
|
|
*/
|
|
static install() {
|
|
if (!window.HTMLVideoElement) {
|
|
// Avoid errors on very old browsers.
|
|
return;
|
|
}
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
const proto = HTMLVideoElement.prototype;
|
|
if (proto.getVideoPlaybackQuality) {
|
|
// No polyfill needed.
|
|
return;
|
|
}
|
|
|
|
if ('webkitDroppedFrameCount' in proto ||
|
|
typeof shaka.util.Dom.anyMediaElement().webkitDroppedFrameCount ===
|
|
'number') {
|
|
proto.getVideoPlaybackQuality =
|
|
shaka.polyfill.VideoPlaybackQuality.webkit_;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @this {HTMLVideoElement}
|
|
* @return {!VideoPlaybackQuality}
|
|
* @private
|
|
*/
|
|
static webkit_() {
|
|
return {
|
|
'droppedVideoFrames': this.webkitDroppedFrameCount,
|
|
'totalVideoFrames': this.webkitDecodedFrameCount,
|
|
// Not provided by this polyfill:
|
|
'corruptedVideoFrames': 0,
|
|
'creationTime': NaN,
|
|
'totalFrameDelay': 0,
|
|
};
|
|
}
|
|
};
|
|
|
|
|
|
shaka.polyfill.register(shaka.polyfill.VideoPlaybackQuality.install);
|