Source: externs/shaka/offline.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. /** @externs */
  18. /**
  19. * @typedef {{
  20. * basic: boolean,
  21. * encrypted: !Object.<string, boolean>
  22. * }}
  23. *
  24. * @property {boolean} basic
  25. * True if offline is usable at all.
  26. * @property {!Object.<string, boolean>} encrypted
  27. * A map of key system name to whether it supports offline playback.
  28. * @exportDoc
  29. */
  30. shakaExtern.OfflineSupport;
  31. /**
  32. * @typedef {{
  33. * trackSelectionCallback:
  34. * function(!Array.<shakaExtern.Track>):!Array.<shakaExtern.Track>,
  35. * progressCallback: function(shakaExtern.StoredContent,number),
  36. * usePersistentLicense: boolean
  37. * }}
  38. *
  39. * @property {function(!Array.<shakaExtern.Track>):!Array.<shakaExtern.Track>}
  40. * trackSelectionCallback
  41. * Called inside store() to determine which tracks to save from a manifest.
  42. * It is passed an array of Tracks from the manifest and it should return
  43. * an array of the tracks to store. This is called for each Period in the
  44. * manifest (in order).
  45. * @property {function(shakaExtern.StoredContent,number)} progressCallback
  46. * Called inside store() to give progress info back to the app. It is given
  47. * the current manifest being stored and the progress of it being stored.
  48. * @property {boolean} usePersistentLicense
  49. * If true, store protected content with a persistent license so that no
  50. * network is required to view.
  51. * If false, store protected content without a persistent license. A network
  52. * will be required to retrieve a temporary license to view.
  53. * Defaults to true.
  54. * @exportDoc
  55. */
  56. shakaExtern.OfflineConfiguration;
  57. /**
  58. * @typedef {{
  59. * offlineUri: ?string,
  60. * originalManifestUri: string,
  61. * duration: number,
  62. * size: number,
  63. * expiration: number,
  64. * tracks: !Array.<shakaExtern.Track>,
  65. * appMetadata: Object
  66. * }}
  67. *
  68. * @property {?string} offlineUri
  69. * An offline URI to access the content. This can be passed directly to
  70. * Player. If the uri is null, it means that the content has not finished
  71. * downloading and is not ready to play.
  72. * @property {string} originalManifestUri
  73. * The original manifest URI of the content stored.
  74. * @property {number} duration
  75. * The duration of the content, in seconds.
  76. * @property {number} size
  77. * The size of the content, in bytes.
  78. * @property {number} expiration
  79. * The time that the encrypted license expires, in milliseconds. If the media
  80. * is clear or the license never expires, this will equal Infinity.
  81. * @property {!Array.<shakaExtern.Track>} tracks
  82. * The tracks that are stored. This only lists those found in the first
  83. * Period.
  84. * @property {Object} appMetadata
  85. * The metadata passed to store().
  86. * @exportDoc
  87. */
  88. shakaExtern.StoredContent;
  89. /**
  90. * @typedef {{
  91. * originalManifestUri: string,
  92. * duration: number,
  93. * size: number,
  94. * expiration: number,
  95. * periods: !Array.<shakaExtern.PeriodDB>,
  96. * sessionIds: !Array.<string>,
  97. * drmInfo: ?shakaExtern.DrmInfo,
  98. * appMetadata: Object
  99. * }}
  100. *
  101. * @property {string} originalManifestUri
  102. * The URI that the manifest was originally loaded from.
  103. * @property {number} duration
  104. * The total duration of the media, in seconds.
  105. * @property {number} size
  106. * The total size of all stored segments, in bytes.
  107. * @property {number} expiration
  108. * The license expiration, in milliseconds; or Infinity if not applicable.
  109. * @property {!Array.<shakaExtern.PeriodDB>} periods
  110. * The Periods that are stored.
  111. * @property {!Array.<string>} sessionIds
  112. * The DRM offline session IDs for the media.
  113. * @property {?shakaExtern.DrmInfo} drmInfo
  114. * The DRM info used to initialize EME.
  115. * @property {Object} appMetadata
  116. * A metadata object passed from the application.
  117. */
  118. shakaExtern.ManifestDB;
  119. /**
  120. * @typedef {{
  121. * startTime: number,
  122. * streams: !Array.<shakaExtern.StreamDB>
  123. * }}
  124. *
  125. * @property {number} startTime
  126. * The start time of the period, in seconds.
  127. * @property {!Array.<shakaExtern.StreamDB>} streams
  128. * The streams that define the Period.
  129. */
  130. shakaExtern.PeriodDB;
  131. /**
  132. * @typedef {{
  133. * id: number,
  134. * primary: boolean,
  135. * presentationTimeOffset: number,
  136. * contentType: string,
  137. * mimeType: string,
  138. * codecs: string,
  139. * frameRate: (number|undefined),
  140. * kind: (string|undefined),
  141. * language: string,
  142. * label: ?string,
  143. * width: ?number,
  144. * height: ?number,
  145. * initSegmentKey: ?number,
  146. * encrypted: boolean,
  147. * keyId: ?string,
  148. * segments: !Array.<shakaExtern.SegmentDB>,
  149. * variantIds: !Array.<number>
  150. * }}
  151. *
  152. * @property {number} id
  153. * The unique id of the stream.
  154. * @property {boolean} primary
  155. * Whether the stream set was primary.
  156. * @property {number} presentationTimeOffset
  157. * The presentation time offset of the stream, in seconds.
  158. * @property {string} contentType
  159. * The type of the stream, 'audio', 'text', or 'video'.
  160. * @property {string} mimeType
  161. * The MIME type of the stream.
  162. * @property {string} codecs
  163. * The codecs of the stream.
  164. * @property {(number|undefined)} frameRate
  165. * The Stream's framerate in frames per second.
  166. * @property {(string|undefined)} kind
  167. * The kind of text stream; undefined for audio/video.
  168. * @property {string} language
  169. * The language of the stream; '' for video.
  170. * @property {?string} label
  171. * The label of the stream; '' for video.
  172. * @property {?number} width
  173. * The width of the stream; null for audio/text.
  174. * @property {?number} height
  175. * The height of the stream; null for audio/text.
  176. * @property {?number} initSegmentKey
  177. * The storage key where the init segment is found; null if no init segment.
  178. * @property {boolean} encrypted
  179. * Whether this stream is encrypted.
  180. * @property {?string} keyId
  181. * The key ID this stream is encrypted with.
  182. * @property {!Array.<shakaExtern.SegmentDB>} segments
  183. * An array of segments that make up the stream.
  184. * @property {!Array.<number>} variantIds
  185. * An array of ids of variants the stream is a part of.
  186. */
  187. shakaExtern.StreamDB;
  188. /**
  189. * @typedef {{
  190. * startTime: number,
  191. * endTime: number,
  192. * dataKey: number
  193. * }}
  194. *
  195. * @property {number} startTime
  196. * The start time of the segment, in seconds from the start of the Period.
  197. * @property {number} endTime
  198. * The end time of the segment, in seconds from the start of the Period.
  199. * @property {number} dataKey
  200. * The key to the data in storage.
  201. */
  202. shakaExtern.SegmentDB;
  203. /**
  204. * @typedef {{
  205. * data: !ArrayBuffer
  206. * }}
  207. *
  208. * @property {!ArrayBuffer} data
  209. * The data contents of the segment.
  210. */
  211. shakaExtern.SegmentDataDB;
  212. /**
  213. * An interface that defines access to collection of segments and manifests. All
  214. * methods are designed to be batched operations allowing the implementations to
  215. * optimize their operations based on how they store data.
  216. *
  217. * The storage cell is one of two exposed APIs used to control where and how
  218. * offline content is saved. The storage cell is responsible for converting
  219. * information between its internal structures and the external (library)
  220. * structures.
  221. *
  222. * @interface
  223. */
  224. shakaExtern.StorageCell = function() {};
  225. /**
  226. * Free all resources used by this cell. This should not affect the stored
  227. * content.
  228. *
  229. * @return {!Promise}
  230. */
  231. shakaExtern.StorageCell.prototype.destroy = function() {};
  232. /**
  233. * Check if the cell can support new keys. If a cell has a fixed key space,
  234. * then all add-operations will fail as no new keys can be added. All
  235. * remove-operations and update-operations should still work.
  236. *
  237. * @return {boolean}
  238. */
  239. shakaExtern.StorageCell.prototype.hasFixedKeySpace = function() {};
  240. /**
  241. * Add a group of segments. Will return a promise that resolves with a list
  242. * of keys for each segment. If one segment fails to be added, all segments
  243. * should fail to be added.
  244. *
  245. * @param {!Array.<shakaExtern.SegmentDataDB>} segments
  246. * @return {!Promise.<!Array.<number>>}
  247. */
  248. shakaExtern.StorageCell.prototype.addSegments = function(segments) {};
  249. /**
  250. * Remove a group of segments using their keys to identify them. If a key
  251. * is not found, then that removal should be considered successful.
  252. *
  253. * @param {!Array.<number>} keys
  254. * @param {function(number)} onRemove A callback for when a segment is removed
  255. * from the cell. The key of the segment
  256. * will be passed to the callback.
  257. * @return {!Promise}
  258. */
  259. shakaExtern.StorageCell.prototype.removeSegments = function(keys, onRemove) {};
  260. /**
  261. * Get a group of segments using their keys to identify them. If any key is
  262. * not found, the promise chain will be rejected.
  263. *
  264. * @param {!Array.<number>} keys
  265. * @return {!Promise.<!Array.<shakaExtern.SegmentDataDB>>}
  266. */
  267. shakaExtern.StorageCell.prototype.getSegments = function(keys) {};
  268. /**
  269. * Add a group of manifests. Will return a promise that resolves with a list
  270. * of keys for each manifest. If one manifest fails to be added, all manifests
  271. * should fail to be added.
  272. *
  273. * @param {!Array.<shakaExtern.ManifestDB>} manifests
  274. * @return {!Promise<!Array.<number>>} keys
  275. */
  276. shakaExtern.StorageCell.prototype.addManifests = function(manifests) {};
  277. /**
  278. * Replace the expiration time of the manifest stored under |key| with
  279. * |newExpiration|. If no manifest is found under |key| then this should
  280. * act as a no-op.
  281. *
  282. * @param {number} key
  283. * @param {number} expiration
  284. * @return {!Promise}
  285. */
  286. shakaExtern.StorageCell.prototype.updateManifestExpiration =
  287. function(key, expiration) {};
  288. /**
  289. * Remove a group of manifests using their keys to identify them. If a key
  290. * is not found, then that removal should be considered successful.
  291. *
  292. * @param {!Array.<number>} keys
  293. * @param {function(number)} onRemove A callback for when a manifest is removed
  294. * from the cell. The key of the manifest
  295. * will be passed to the callback.
  296. * @return {!Promise}
  297. */
  298. shakaExtern.StorageCell.prototype.removeManifests =
  299. function(keys, onRemove) {};
  300. /**
  301. * Get a group of manifests using their keys to identify them. If any key is
  302. * not found, the promise chain will be rejected.
  303. *
  304. * @param {!Array.<number>} keys
  305. * @return {!Promise<!Array.<shakaExtern.ManifestDB>>}
  306. */
  307. shakaExtern.StorageCell.prototype.getManifests = function(keys) {};
  308. /**
  309. * Get all manifests stored in this cell. Since manifests are small compared to
  310. * the asset they describe, it is assumed that it is feasible to have them all
  311. * in main memory at one time.
  312. *
  313. * @return {!Promise<!Object.<number, shakaExtern.ManifestDB>>}
  314. */
  315. shakaExtern.StorageCell.prototype.getAllManifests = function() {};
  316. /**
  317. * Storage mechanisms are one of two exported storage APIs. Storage mechanisms
  318. * are groups of storage cells (shakaExtern.StorageCell). Storage mechanisms
  319. * are responsible for managing the life cycle of resources shared between
  320. * storage cells in the same block.
  321. *
  322. * For example, a storage mechanism may manage a single database connection
  323. * while each cell would manage different tables in the database via the same
  324. * connection.
  325. *
  326. * @interface
  327. */
  328. shakaExtern.StorageMechanism = function() {};
  329. /**
  330. * Initialize the storage mechanism for first use. This should only be called
  331. * once. Calling |init| multiple times has an undefined behaviour.
  332. *
  333. * @return {!Promise}
  334. */
  335. shakaExtern.StorageMechanism.prototype.init = function() {};
  336. /**
  337. * Free all resources used by the storage mechanism and its cells. This should
  338. * not affect the stored content.
  339. *
  340. * @return {!Promise}
  341. */
  342. shakaExtern.StorageMechanism.prototype.destroy = function() {};
  343. /**
  344. * Get a map of all the cells managed by the storage mechanism. Editing the map
  345. * should have no effect on the storage mechanism. The map key is the cell's
  346. * address in the mechanism and should be consistent between calls to
  347. * |getCells|.
  348. *
  349. * @return {!Object.<string, !shakaExtern.StorageCell>}
  350. */
  351. shakaExtern.StorageMechanism.prototype.getCells = function() {};
  352. /**
  353. * Erase all content from storage and leave storage in an empty state. Erase may
  354. * be called with or without |init|. This allows for storage to be wiped in
  355. * case of a version mismatch.
  356. *
  357. * After calling |erase|, the mechanism will be in an initialized state.
  358. *
  359. * @return {!Promise}
  360. */
  361. shakaExtern.StorageMechanism.prototype.erase = function() {};