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.Platform');
  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. shaka.util.Platform.isWebOS3()) {
  33. proto.getVideoPlaybackQuality =
  34. shaka.polyfill.VideoPlaybackQuality.webkit_;
  35. }
  36. }
  37. /**
  38. * @this {HTMLVideoElement}
  39. * @return {!VideoPlaybackQuality}
  40. * @private
  41. */
  42. static webkit_() {
  43. return {
  44. 'droppedVideoFrames': this.webkitDroppedFrameCount,
  45. 'totalVideoFrames': this.webkitDecodedFrameCount,
  46. // Not provided by this polyfill:
  47. 'corruptedVideoFrames': 0,
  48. 'creationTime': NaN,
  49. 'totalFrameDelay': 0,
  50. };
  51. }
  52. };
  53. shaka.polyfill.register(shaka.polyfill.VideoPlaybackQuality.install);