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. /**
  9. * @summary A polyfill to provide MSE VideoPlaybackQuality metrics.
  10. * Many browsers do not yet provide this API, and Chrome currently provides
  11. * similar data through individual prefixed attributes on HTMLVideoElement.
  12. * @export
  13. */
  14. shaka.polyfill.VideoPlaybackQuality = class {
  15. /**
  16. * Install the polyfill if needed.
  17. * @export
  18. */
  19. static install() {
  20. if (!window.HTMLVideoElement) {
  21. // Avoid errors on very old browsers.
  22. return;
  23. }
  24. // eslint-disable-next-line no-restricted-syntax
  25. const proto = HTMLVideoElement.prototype;
  26. if (proto.getVideoPlaybackQuality) {
  27. // No polyfill needed.
  28. return;
  29. }
  30. if ('webkitDroppedFrameCount' in proto) {
  31. proto.getVideoPlaybackQuality =
  32. shaka.polyfill.VideoPlaybackQuality.webkit_;
  33. }
  34. }
  35. /**
  36. * @this {HTMLVideoElement}
  37. * @return {!VideoPlaybackQuality}
  38. * @private
  39. */
  40. static webkit_() {
  41. return {
  42. 'droppedVideoFrames': this.webkitDroppedFrameCount,
  43. 'totalVideoFrames': this.webkitDecodedFrameCount,
  44. // Not provided by this polyfill:
  45. 'corruptedVideoFrames': 0,
  46. 'creationTime': NaN,
  47. 'totalFrameDelay': 0,
  48. };
  49. }
  50. };
  51. shaka.polyfill.register(shaka.polyfill.VideoPlaybackQuality.install);