Source: externs/shaka/abr_manager.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2016 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @externs
  8. */
  9. /**
  10. * An object which selects Streams from a set of possible choices. This also
  11. * watches for system changes to automatically adapt for the current streaming
  12. * requirements. For example, when the network slows down, this class is in
  13. * charge of telling the Player which streams to switch to in order to reduce
  14. * the required bandwidth.
  15. *
  16. * This class is given a set of streams to choose from when the Player starts
  17. * up. This class should store these and use them to make future decisions
  18. * about ABR. It is up to this class how those decisions are made. All the
  19. * Player will do is tell this class what streams to choose from.
  20. *
  21. * @interface
  22. * @exportDoc
  23. */
  24. shaka.extern.AbrManager = class {
  25. constructor() {}
  26. /**
  27. * Initializes the AbrManager.
  28. *
  29. * @param {shaka.extern.AbrManager.SwitchCallback} switchCallback
  30. * @exportDoc
  31. */
  32. init(switchCallback) {}
  33. /**
  34. * Stops any background timers and frees any objects held by this instance.
  35. * This will only be called after a call to init.
  36. *
  37. * @exportDoc
  38. */
  39. stop() {}
  40. /**
  41. * Updates manager's variants collection.
  42. *
  43. * @param {!Array.<!shaka.extern.Variant>} variants
  44. * @exportDoc
  45. */
  46. setVariants(variants) {}
  47. /**
  48. * Chooses one variant to switch to. Called by the Player.
  49. * @return {shaka.extern.Variant}
  50. * @exportDoc
  51. */
  52. chooseVariant() {}
  53. /**
  54. * Enables automatic Variant choices from the last ones passed to setVariants.
  55. * After this, the AbrManager may call switchCallback() at any time.
  56. *
  57. * @exportDoc
  58. */
  59. enable() {}
  60. /**
  61. * Disables automatic Stream suggestions. After this, the AbrManager may not
  62. * call switchCallback().
  63. *
  64. * @exportDoc
  65. */
  66. disable() {}
  67. /**
  68. * Notifies the AbrManager that a segment has been downloaded (includes MP4
  69. * SIDX data, WebM Cues data, initialization segments, and media segments).
  70. *
  71. * @param {number} deltaTimeMs The duration, in milliseconds, that the request
  72. * took to complete.
  73. * @param {number} numBytes The total number of bytes transferred.
  74. * @exportDoc
  75. */
  76. segmentDownloaded(deltaTimeMs, numBytes) {}
  77. /**
  78. * Gets an estimate of the current bandwidth in bit/sec. This is used by the
  79. * Player to generate stats.
  80. *
  81. * @return {number}
  82. * @exportDoc
  83. */
  84. getBandwidthEstimate() {}
  85. /**
  86. * Updates manager playback rate.
  87. *
  88. * @param {number} rate
  89. * @exportDoc
  90. */
  91. playbackRateChanged(rate) {}
  92. /**
  93. * Set media element.
  94. *
  95. * @param {HTMLMediaElement} mediaElement
  96. * @exportDoc
  97. */
  98. setMediaElement(mediaElement) {}
  99. /**
  100. * Sets the ABR configuration.
  101. *
  102. * It is the responsibility of the AbrManager implementation to implement the
  103. * restrictions behavior described in shaka.extern.AbrConfiguration.
  104. *
  105. * @param {shaka.extern.AbrConfiguration} config
  106. * @exportDoc
  107. */
  108. configure(config) {}
  109. };
  110. /**
  111. * A callback into the Player that should be called when the AbrManager decides
  112. * it's time to change to a different variant.
  113. *
  114. * The first argument is a variant to switch to.
  115. *
  116. * The second argument is an optional boolean. If true, all data will be removed
  117. * from the buffer, which will result in a buffering event. Unless a third
  118. * argument is passed.
  119. *
  120. * The third argument in an optional number that specifies how much data (in
  121. * seconds) should be retained when clearing the buffer. This can help achieve
  122. * a fast switch that doesn't involve a buffering event. A minimum of two video
  123. * segments should always be kept buffered to avoid temporary hiccups.
  124. *
  125. * @typedef {function(shaka.extern.Variant, boolean=, number=)}
  126. * @exportDoc
  127. */
  128. shaka.extern.AbrManager.SwitchCallback;
  129. /**
  130. * A factory for creating the abr manager.
  131. *
  132. * @typedef {function():!shaka.extern.AbrManager}
  133. * @exportDoc
  134. */
  135. shaka.extern.AbrManager.Factory;