Source: lib/media/media_source_capabilities.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.media.Capabilities');
  7. /**
  8. * @summary
  9. * This is for capturing all media source capabilities on current platform.
  10. * And this is for static check and can not be constructed.
  11. */
  12. shaka.media.Capabilities = class {
  13. /**
  14. * Cache browser engine call to improve performance on some poor platforms
  15. *
  16. * @param {string} type
  17. * @return {boolean}
  18. */
  19. static isTypeSupported(type) {
  20. const supportMap = shaka.media.Capabilities.MediaSourceTypeSupportMap;
  21. if (supportMap.has(type)) {
  22. return supportMap.get(type);
  23. }
  24. const mediaSource = window.ManagedMediaSource || window.MediaSource;
  25. if (mediaSource) {
  26. const currentSupport = mediaSource.isTypeSupported(type);
  27. supportMap.set(type, currentSupport);
  28. return currentSupport;
  29. }
  30. return false;
  31. }
  32. /**
  33. * Determine support for SourceBuffer.changeType
  34. * @return {boolean}
  35. */
  36. static isChangeTypeSupported() {
  37. const sourceBuffer = window.ManagedSourceBuffer || window.SourceBuffer;
  38. return !!sourceBuffer &&
  39. // eslint-disable-next-line no-restricted-syntax
  40. !!sourceBuffer.prototype && !!sourceBuffer.prototype.changeType;
  41. }
  42. /**
  43. * Determine support for MediaSource.setLiveSeekableRange and
  44. * MediaSource.clearLiveSeekableRange, which can allow for a media element
  45. * duration of Infinite by providing a non-infinite seekable range.
  46. *
  47. * @return {boolean}
  48. */
  49. static isInfiniteLiveStreamDurationSupported() {
  50. const mediaSource = window.ManagedMediaSource || window.MediaSource;
  51. // eslint-disable-next-line no-restricted-syntax
  52. if (mediaSource && mediaSource.prototype) {
  53. // eslint-disable-next-line no-restricted-syntax
  54. return !!mediaSource.prototype.setLiveSeekableRange &&
  55. // eslint-disable-next-line no-restricted-syntax
  56. !!mediaSource.prototype.clearLiveSeekableRange;
  57. }
  58. return false;
  59. }
  60. };
  61. /**
  62. * Public it for unit test, and developer could also check the support map.
  63. * @type {!Map<string, boolean>}
  64. */
  65. shaka.media.Capabilities.MediaSourceTypeSupportMap = new Map();