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