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