Source: externs/shaka/manifest_parser.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @externs
  19. */
  20. /**
  21. * Parses media manifests and handles manifest updates.
  22. *
  23. * Given a URI where the initial manifest is found, a parser will request the
  24. * manifest, parse it, and return the resulting Manifest object.
  25. *
  26. * If the manifest requires updates (e.g. for live media), the parser will use
  27. * background timers to update the same Manifest object.
  28. *
  29. * There are many ways for |start| and |stop| to be called. Implementations
  30. * should support all cases:
  31. *
  32. * BASIC
  33. * await parser.start(uri, playerInterface);
  34. * await parser.stop();
  35. *
  36. * INTERRUPTING
  37. * const p = parser.start(uri, playerInterface);
  38. * await parser.stop();
  39. * await p;
  40. *
  41. * |p| should be rejected with an OPERATION_ABORTED error.
  42. *
  43. * STOPPED BEFORE STARTING
  44. * await parser.stop();
  45. *
  46. * @interface
  47. * @exportDoc
  48. */
  49. shaka.extern.ManifestParser = function() {};
  50. /**
  51. * @typedef {{
  52. * networkingEngine: !shaka.net.NetworkingEngine,
  53. * filterNewPeriod: function(shaka.extern.Period),
  54. * filterAllPeriods: function(!Array.<!shaka.extern.Period>),
  55. * onTimelineRegionAdded: function(shaka.extern.TimelineRegionInfo),
  56. * onEvent: function(!Event),
  57. * onError: function(!shaka.util.Error)
  58. * }}
  59. *
  60. * @description
  61. * Defines the interface of the Player to the manifest parser. This defines
  62. * fields and callback methods that the parser will use to interact with the
  63. * Player. The callback methods do not need to be called as member functions
  64. * (i.e. they can be called as "free" functions).
  65. *
  66. * @property {!shaka.net.NetworkingEngine} networkingEngine
  67. * The networking engine to use for network requests.
  68. * @property {function(shaka.extern.Period)} filterNewPeriod
  69. * Should be called on a new Period so that it can be filtered.
  70. * @property {function(!Array.<!shaka.extern.Period>)} filterAllPeriods
  71. * Should be called on all Periods so that they can be filtered.
  72. * @property {function(shaka.extern.TimelineRegionInfo)} onTimelineRegionAdded
  73. * Should be called when a new timeline region is added.
  74. * @property {function(!Event)} onEvent
  75. * Should be called to raise events.
  76. * @property {function(!shaka.util.Error)} onError
  77. * Should be called when an error occurs.
  78. * @exportDoc
  79. */
  80. shaka.extern.ManifestParser.PlayerInterface;
  81. /**
  82. * A factory for creating the manifest parser. This will be called with 'new'.
  83. * This function is registered with shaka.media.ManifestParser to create parser
  84. * instances.
  85. *
  86. * @typedef {function(new:shaka.extern.ManifestParser)}
  87. * @exportDoc
  88. */
  89. shaka.extern.ManifestParser.Factory;
  90. /**
  91. * Called by the Player to provide an updated configuration any time the
  92. * configuration changes. Will be called at least once before start().
  93. *
  94. * @param {shaka.extern.ManifestConfiguration} config
  95. * @exportDoc
  96. */
  97. shaka.extern.ManifestParser.prototype.configure = function(config) {};
  98. /**
  99. * Initialize and start the parser. When |start| resolves, it should return the
  100. * initial version of the manifest. |start| will only be called once. If |stop|
  101. * is called while |start| is pending, |start| should reject.
  102. *
  103. * @param {string} uri The URI of the manifest.
  104. * @param {shaka.extern.ManifestParser.PlayerInterface} playerInterface
  105. * The player interface contains the callbacks and members that the parser
  106. * can use to communicate with the player and outside world.
  107. * @return {!Promise.<shaka.extern.Manifest>}
  108. * @exportDoc
  109. */
  110. shaka.extern.ManifestParser.prototype.start = function(uri, playerInterface) {};
  111. /**
  112. * Tell the parser that it must stop and free all internal resources as soon as
  113. * possible. Only once all internal resources are stopped and freed will the
  114. * promise resolve. Once stopped a parser will not be started again.
  115. *
  116. * The parser should support having |stop| called multiple times and the promise
  117. * should always resolve.
  118. *
  119. * @return {!Promise}
  120. * @exportDoc
  121. */
  122. shaka.extern.ManifestParser.prototype.stop = function() {};
  123. /**
  124. * Tells the parser to do a manual manifest update. Implementing this is
  125. * optional. This is only called when 'emsg' boxes are present.
  126. * @exportDoc
  127. */
  128. shaka.extern.ManifestParser.prototype.update = function() {};
  129. /**
  130. * Tells the parser that the expiration time of an EME session has changed.
  131. * Implementing this is optional.
  132. *
  133. * @param {string} sessionId
  134. * @param {number} expiration
  135. * @exportDoc
  136. */
  137. shaka.extern.ManifestParser.prototype.onExpirationUpdated = function(
  138. sessionId, expiration) {};