Source: lib/polyfill/videoplaybackquality.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.polyfill.VideoPlaybackQuality');
  7. goog.require('shaka.polyfill');
  8. goog.require('shaka.util.Dom');
  9. /**
  10. * @summary A polyfill to provide MSE VideoPlaybackQuality metrics.
  11. * Many browsers do not yet provide this API, and Chrome currently provides
  12. * similar data through individual prefixed attributes on HTMLVideoElement.
  13. * @export
  14. */
  15. shaka.polyfill.VideoPlaybackQuality = class {
  16. /**
  17. * Install the polyfill if needed.
  18. * @export
  19. */
  20. static install() {
  21. if (!window.HTMLVideoElement) {
  22. // Avoid errors on very old browsers.
  23. return;
  24. }
  25. // eslint-disable-next-line no-restricted-syntax
  26. const proto = HTMLVideoElement.prototype;
  27. if (proto.getVideoPlaybackQuality) {
  28. // No polyfill needed.
  29. return;
  30. }
  31. if ('webkitDroppedFrameCount' in proto ||
  32. typeof shaka.util.Dom.anyMediaElement().webkitDroppedFrameCount ===
  33. 'number') {
  34. proto.getVideoPlaybackQuality =
  35. shaka.polyfill.VideoPlaybackQuality.webkit_;
  36. }
  37. }
  38. /**
  39. * @this {HTMLVideoElement}
  40. * @return {!VideoPlaybackQuality}
  41. * @private
  42. */
  43. static webkit_() {
  44. return {
  45. 'droppedVideoFrames': this.webkitDroppedFrameCount,
  46. 'totalVideoFrames': this.webkitDecodedFrameCount,
  47. // Not provided by this polyfill:
  48. 'corruptedVideoFrames': 0,
  49. 'creationTime': NaN,
  50. 'totalFrameDelay': 0,
  51. };
  52. }
  53. };
  54. shaka.polyfill.register(shaka.polyfill.VideoPlaybackQuality.install);