Source: externs/shaka/manifest_parser.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. * Parses media manifests and handles manifest updates.
  11. *
  12. * Given a URI where the initial manifest is found, a parser will request the
  13. * manifest, parse it, and return the resulting Manifest object.
  14. *
  15. * If the manifest requires updates (e.g. for live media), the parser will use
  16. * background timers to update the same Manifest object.
  17. *
  18. * There are many ways for |start| and |stop| to be called. Implementations
  19. * should support all cases:
  20. *
  21. * BASIC
  22. * await parser.start(uri, playerInterface);
  23. * await parser.stop();
  24. *
  25. * INTERRUPTING
  26. * const p = parser.start(uri, playerInterface);
  27. * await parser.stop();
  28. * await p;
  29. *
  30. * |p| should be rejected with an OPERATION_ABORTED error.
  31. *
  32. * STOPPED BEFORE STARTING
  33. * await parser.stop();
  34. *
  35. * @interface
  36. * @exportDoc
  37. */
  38. shaka.extern.ManifestParser = class {
  39. constructor() {}
  40. /**
  41. * Called by the Player to provide an updated configuration any time the
  42. * configuration changes. Will be called at least once before start().
  43. *
  44. * @param {shaka.extern.ManifestConfiguration} config
  45. * @param {(function():boolean)=} isPreloadFn
  46. * @exportDoc
  47. */
  48. configure(config, isPreloadFn) {}
  49. /**
  50. * Initialize and start the parser. When |start| resolves, it should return
  51. * the initial version of the manifest. |start| will only be called once. If
  52. * |stop| is called while |start| is pending, |start| should reject.
  53. *
  54. * @param {string} uri The URI of the manifest.
  55. * @param {shaka.extern.ManifestParser.PlayerInterface} playerInterface
  56. * The player interface contains the callbacks and members that the parser
  57. * can use to communicate with the player and outside world.
  58. * @return {!Promise<shaka.extern.Manifest>}
  59. * @exportDoc
  60. */
  61. start(uri, playerInterface) {}
  62. /**
  63. * Tell the parser that it must stop and free all internal resources as soon
  64. * as possible. Only once all internal resources are stopped and freed will
  65. * the promise resolve. Once stopped a parser will not be started again.
  66. *
  67. * The parser should support having |stop| called multiple times and the
  68. * promise should always resolve.
  69. *
  70. * @return {!Promise}
  71. * @exportDoc
  72. */
  73. stop() {}
  74. /**
  75. * Tells the parser to do a manual manifest update. Implementing this is
  76. * optional. This is only called when 'emsg' boxes are present.
  77. * @exportDoc
  78. */
  79. update() {}
  80. /**
  81. * Tells the parser that the expiration time of an EME session has changed.
  82. * Implementing this is optional.
  83. *
  84. * @param {string} sessionId
  85. * @param {number} expiration
  86. * @exportDoc
  87. */
  88. onExpirationUpdated(sessionId, expiration) {}
  89. /**
  90. * Tells the parser that the initial variant has been chosen.
  91. *
  92. * @param {shaka.extern.Variant} variant
  93. * @exportDoc
  94. */
  95. onInitialVariantChosen(variant) {}
  96. /**
  97. * Tells the parser that a location should be banned. This is called on
  98. * retry.
  99. *
  100. * @param {string} uri
  101. * @exportDoc
  102. */
  103. banLocation(uri) {}
  104. /**
  105. * Set media element.
  106. *
  107. * @param {HTMLMediaElement} mediaElement
  108. * @exportDoc
  109. */
  110. setMediaElement(mediaElement) {}
  111. };
  112. /**
  113. * @typedef {{
  114. * networkingEngine: !shaka.net.NetworkingEngine,
  115. * filter: function(shaka.extern.Manifest):!Promise,
  116. * makeTextStreamsForClosedCaptions: function(shaka.extern.Manifest),
  117. * onTimelineRegionAdded: function(shaka.extern.TimelineRegionInfo),
  118. * onEvent: function(!Event),
  119. * onError: function(!shaka.util.Error),
  120. * isLowLatencyMode: function():boolean,
  121. * updateDuration: function(),
  122. * newDrmInfo: function(shaka.extern.Stream),
  123. * onManifestUpdated: function(),
  124. * getBandwidthEstimate: function():number,
  125. * onMetadata: function(string, number, ?number,
  126. * !Array<shaka.extern.MetadataFrame>),
  127. * disableStream: function(!shaka.extern.Stream),
  128. * addFont: function(string, string)
  129. * }}
  130. *
  131. * @description
  132. * Defines the interface of the Player to the manifest parser. This defines
  133. * fields and callback methods that the parser will use to interact with the
  134. * Player. The callback methods do not need to be called as member functions
  135. * (i.e. they can be called as "free" functions).
  136. *
  137. * @property {!shaka.net.NetworkingEngine} networkingEngine
  138. * The networking engine to use for network requests.
  139. * @property {function(shaka.extern.Manifest):!Promise} filter
  140. * Should be called when new variants or text streams are added to the
  141. * Manifest. Note that this operation is asynchronous.
  142. * @property {function(shaka.extern.Manifest)} makeTextStreamsForClosedCaptions
  143. * A callback that adds text streams to represent the closed captions of the
  144. * video streams in the Manifest. Should be called whenever new video streams
  145. * are added to the Manifest.
  146. * @property {function(shaka.extern.TimelineRegionInfo)} onTimelineRegionAdded
  147. * Should be called when a new timeline region is added.
  148. * @property {function(!Event)} onEvent
  149. * Should be called to raise events.
  150. * @property {function(!shaka.util.Error)} onError
  151. * Should be called when an error occurs.
  152. * @property {function():boolean} isLowLatencyMode
  153. * Return true if low latency streaming mode is enabled.
  154. * @property {function()} updateDuration
  155. * Update the presentation duration based on PresentationTimeline.
  156. * @property {function(shaka.extern.Stream)} newDrmInfo
  157. * Inform the player of new DRM info that needs to be processed for the given
  158. * stream.
  159. * @property {function()} onManifestUpdated
  160. * Should be called when the manifest is updated.
  161. * @property {function():number} getBandwidthEstimate
  162. * Get the estimated bandwidth in bits per second.
  163. * @property {function(string, number, ?number,
  164. * !Array<shaka.extern.MetadataFrame>)} onMetadata
  165. * Called when an metadata is found in the manifest.
  166. * @property {function(!shaka.extern.Stream)} disableStream
  167. * Called to temporarily disable a stream i.e. disabling all variant
  168. * containing said stream.
  169. * @property {function(string, string)} addFont
  170. * Called when a new font needs to be added.
  171. * @exportDoc
  172. */
  173. shaka.extern.ManifestParser.PlayerInterface;
  174. /**
  175. * A factory for creating the manifest parser. This function is registered with
  176. * shaka.media.ManifestParser to create parser instances.
  177. *
  178. * @typedef {function():!shaka.extern.ManifestParser}
  179. * @exportDoc
  180. */
  181. shaka.extern.ManifestParser.Factory;