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. * Request that this object release all internal references.
  42. * @exportDoc
  43. */
  44. release() {}
  45. /**
  46. * Updates manager's variants collection.
  47. *
  48. * @param {!Array.<!shaka.extern.Variant>} variants
  49. * @exportDoc
  50. */
  51. setVariants(variants) {}
  52. /**
  53. * Chooses one variant to switch to. Called by the Player.
  54. * @param {boolean=} preferFastSwitching If not provided meant "avoid fast
  55. * switching if possible".
  56. * @return {shaka.extern.Variant}
  57. * @exportDoc
  58. */
  59. chooseVariant(preferFastSwitching) {}
  60. /**
  61. * Enables automatic Variant choices from the last ones passed to setVariants.
  62. * After this, the AbrManager may call switchCallback() at any time.
  63. *
  64. * @exportDoc
  65. */
  66. enable() {}
  67. /**
  68. * Disables automatic Stream suggestions. After this, the AbrManager may not
  69. * call switchCallback().
  70. *
  71. * @exportDoc
  72. */
  73. disable() {}
  74. /**
  75. * Notifies the AbrManager that a segment has been downloaded (includes MP4
  76. * SIDX data, WebM Cues data, initialization segments, and media segments).
  77. *
  78. * @param {number} deltaTimeMs The duration, in milliseconds, that the request
  79. * took to complete.
  80. * @param {number} numBytes The total number of bytes transferred.
  81. * @param {boolean} allowSwitch Indicate if the segment is allowed to switch
  82. * to another stream.
  83. * @param {shaka.extern.Request=} request
  84. * A reference to the request
  85. * @exportDoc
  86. */
  87. segmentDownloaded(deltaTimeMs, numBytes, allowSwitch, request) {}
  88. /**
  89. * Notifies the ABR that it is a time to suggest new streams. This is used by
  90. * the Player when it finishes adding the last partial segment of a fast
  91. * switching stream.
  92. *
  93. * @exportDoc
  94. */
  95. trySuggestStreams() {}
  96. /**
  97. * Gets an estimate of the current bandwidth in bit/sec. This is used by the
  98. * Player to generate stats.
  99. *
  100. * @return {number}
  101. * @exportDoc
  102. */
  103. getBandwidthEstimate() {}
  104. /**
  105. * Updates manager playback rate.
  106. *
  107. * @param {number} rate
  108. * @exportDoc
  109. */
  110. playbackRateChanged(rate) {}
  111. /**
  112. * Set media element.
  113. *
  114. * @param {HTMLMediaElement} mediaElement
  115. * @exportDoc
  116. */
  117. setMediaElement(mediaElement) {}
  118. /**
  119. * Set CMSD manager.
  120. *
  121. * @param {shaka.util.CmsdManager} cmsdManager
  122. * @exportDoc
  123. */
  124. setCmsdManager(cmsdManager) {}
  125. /**
  126. * Sets the ABR configuration.
  127. *
  128. * It is the responsibility of the AbrManager implementation to implement the
  129. * restrictions behavior described in shaka.extern.AbrConfiguration.
  130. *
  131. * @param {shaka.extern.AbrConfiguration} config
  132. * @exportDoc
  133. */
  134. configure(config) {}
  135. };
  136. /**
  137. * A callback into the Player that should be called when the AbrManager decides
  138. * it's time to change to a different variant.
  139. *
  140. * The first argument is a variant to switch to.
  141. *
  142. * The second argument is an optional boolean. If true, all data will be removed
  143. * from the buffer, which will result in a buffering event. Unless a third
  144. * argument is passed.
  145. *
  146. * The third argument in an optional number that specifies how much data (in
  147. * seconds) should be retained when clearing the buffer. This can help achieve
  148. * a fast switch that doesn't involve a buffering event. A minimum of two video
  149. * segments should always be kept buffered to avoid temporary hiccups.
  150. *
  151. * @typedef {function(shaka.extern.Variant, boolean=, number=)}
  152. * @exportDoc
  153. */
  154. shaka.extern.AbrManager.SwitchCallback;
  155. /**
  156. * A factory for creating the abr manager.
  157. *
  158. * @typedef {function():!shaka.extern.AbrManager}
  159. * @exportDoc
  160. */
  161. shaka.extern.AbrManager.Factory;