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. * @exportDoc
  85. */
  86. segmentDownloaded(deltaTimeMs, numBytes, allowSwitch, request) {}
  87. /**
  88. * Notifies the ABR that it is a time to suggest new streams. This is used by
  89. * the Player when it finishes adding the last partial segment of a fast
  90. * switching stream.
  91. *
  92. * @exportDoc
  93. */
  94. trySuggestStreams() {}
  95. /**
  96. * Gets an estimate of the current bandwidth in bit/sec. This is used by the
  97. * Player to generate stats.
  98. *
  99. * @return {number}
  100. * @exportDoc
  101. */
  102. getBandwidthEstimate() {}
  103. /**
  104. * Updates manager playback rate.
  105. *
  106. * @param {number} rate
  107. * @exportDoc
  108. */
  109. playbackRateChanged(rate) {}
  110. /**
  111. * Set media element.
  112. *
  113. * @param {HTMLMediaElement} mediaElement
  114. * @exportDoc
  115. */
  116. setMediaElement(mediaElement) {}
  117. /**
  118. * Set CMSD manager.
  119. *
  120. * @param {shaka.util.CmsdManager} cmsdManager
  121. * @exportDoc
  122. */
  123. setCmsdManager(cmsdManager) {}
  124. /**
  125. * Sets the ABR configuration.
  126. *
  127. * It is the responsibility of the AbrManager implementation to implement the
  128. * restrictions behavior described in shaka.extern.AbrConfiguration.
  129. *
  130. * @param {shaka.extern.AbrConfiguration} config
  131. * @exportDoc
  132. */
  133. configure(config) {}
  134. };
  135. /**
  136. * A callback into the Player that should be called when the AbrManager decides
  137. * it's time to change to a different variant.
  138. *
  139. * The first argument is a variant to switch to.
  140. *
  141. * The second argument is an optional boolean. If true, all data will be removed
  142. * from the buffer, which will result in a buffering event. Unless a third
  143. * argument is passed.
  144. *
  145. * The third argument in an optional number that specifies how much data (in
  146. * seconds) should be retained when clearing the buffer. This can help achieve
  147. * a fast switch that doesn't involve a buffering event. A minimum of two video
  148. * segments should always be kept buffered to avoid temporary hiccups.
  149. *
  150. * @typedef {function(shaka.extern.Variant, boolean=, number=)}
  151. * @exportDoc
  152. */
  153. shaka.extern.AbrManager.SwitchCallback;
  154. /**
  155. * A factory for creating the abr manager.
  156. *
  157. * @typedef {function():!shaka.extern.AbrManager}
  158. * @exportDoc
  159. */
  160. shaka.extern.AbrManager.Factory;