Source: lib/polyfill/videoplaybackquality.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. goog.provide('shaka.polyfill.VideoPlaybackQuality');
  18. goog.require('shaka.polyfill.register');
  19. /**
  20. * @namespace shaka.polyfill.VideoPlaybackQuality
  21. *
  22. * @summary A polyfill to provide MSE VideoPlaybackQuality metrics.
  23. * Many browsers do not yet provide this API, and Chrome currently provides
  24. * similar data through individual prefixed attributes on HTMLVideoElement.
  25. */
  26. /**
  27. * Install the polyfill if needed.
  28. */
  29. shaka.polyfill.VideoPlaybackQuality.install = function() {
  30. if (!window.HTMLVideoElement) {
  31. // Avoid errors on very old browsers.
  32. return;
  33. }
  34. var proto = HTMLVideoElement.prototype;
  35. if (proto.getVideoPlaybackQuality) {
  36. // No polyfill needed.
  37. return;
  38. }
  39. if ('webkitDroppedFrameCount' in proto) {
  40. proto.getVideoPlaybackQuality =
  41. shaka.polyfill.VideoPlaybackQuality.webkit_;
  42. }
  43. };
  44. /**
  45. * @this {HTMLVideoElement}
  46. * @return {!VideoPlaybackQuality}
  47. * @private
  48. */
  49. shaka.polyfill.VideoPlaybackQuality.webkit_ = function() {
  50. return {
  51. 'droppedVideoFrames': this.webkitDroppedFrameCount,
  52. 'totalVideoFrames': this.webkitDecodedFrameCount,
  53. // Not provided by this polyfill:
  54. 'corruptedVideoFrames': 0,
  55. 'creationTime': NaN,
  56. 'totalFrameDelay': 0
  57. };
  58. };
  59. shaka.polyfill.register(shaka.polyfill.VideoPlaybackQuality.install);