Source: externs/shaka/offline.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. * @typedef {{
  11. * basic: boolean,
  12. * encrypted: !Object.<string, boolean>
  13. * }}
  14. *
  15. * @property {boolean} basic
  16. * True if offline is usable at all.
  17. * @property {!Object.<string, boolean>} encrypted
  18. * A map of key system name to whether it supports offline playback.
  19. * @exportDoc
  20. */
  21. shaka.extern.OfflineSupport;
  22. /**
  23. * @typedef {{
  24. * offlineUri: ?string,
  25. * originalManifestUri: string,
  26. * duration: number,
  27. * size: number,
  28. * expiration: number,
  29. * tracks: !Array.<shaka.extern.Track>,
  30. * appMetadata: Object,
  31. * isIncomplete: boolean
  32. * }}
  33. *
  34. * @property {?string} offlineUri
  35. * An offline URI to access the content. This can be passed directly to
  36. * Player. If the uri is null, it means that the content has not finished
  37. * downloading and is not ready to play.
  38. * @property {string} originalManifestUri
  39. * The original manifest URI of the content stored.
  40. * @property {number} duration
  41. * The duration of the content, in seconds.
  42. * @property {number} size
  43. * The size of the content, in bytes.
  44. * @property {number} expiration
  45. * The time that the encrypted license expires, in milliseconds. If the media
  46. * is clear or the license never expires, this will equal Infinity.
  47. * @property {!Array.<shaka.extern.Track>} tracks
  48. * The tracks that are stored.
  49. * @property {Object} appMetadata
  50. * The metadata passed to store().
  51. * @property {boolean} isIncomplete
  52. * If true, the content is still downloading. Manifests with this set cannot
  53. * be played yet.
  54. * @exportDoc
  55. */
  56. shaka.extern.StoredContent;
  57. /**
  58. * @typedef {{
  59. * creationTime: number,
  60. * originalManifestUri: string,
  61. * duration: number,
  62. * size: number,
  63. * expiration: number,
  64. * streams: !Array.<shaka.extern.StreamDB>,
  65. * sessionIds: !Array.<string>,
  66. * drmInfo: ?shaka.extern.DrmInfo,
  67. * appMetadata: Object,
  68. * isIncomplete: (boolean|undefined),
  69. * sequenceMode: (boolean|undefined),
  70. * type: (string|undefined)
  71. * }}
  72. *
  73. * @property {number} creationTime
  74. * The date time when the asset was created.
  75. * @property {string} originalManifestUri
  76. * The URI that the manifest was originally loaded from.
  77. * @property {number} duration
  78. * The total duration of the media, in seconds.
  79. * @property {number} size
  80. * The total size of all stored segments, in bytes.
  81. * @property {number} expiration
  82. * The license expiration, in milliseconds; or Infinity if not applicable.
  83. * Note that upon JSON serialization, Infinity becomes null, and must be
  84. * converted back upon loading from storage.
  85. * @property {!Array.<shaka.extern.StreamDB>} streams
  86. * The Streams that are stored.
  87. * @property {!Array.<string>} sessionIds
  88. * The DRM offline session IDs for the media.
  89. * @property {?shaka.extern.DrmInfo} drmInfo
  90. * The DRM info used to initialize EME.
  91. * @property {Object} appMetadata
  92. * A metadata object passed from the application.
  93. * @property {(boolean|undefined)} isIncomplete
  94. * If true, the content is still downloading.
  95. * @property {(boolean|undefined)} sequenceMode
  96. * If true, we will append the media segments using sequence mode; that is to
  97. * say, ignoring any timestamps inside the media files.
  98. * @property {(string|undefined)} type
  99. * Indicates the type of the manifest. It can be <code>'HLS'</code> or
  100. * <code>'DASH'</code>.
  101. */
  102. shaka.extern.ManifestDB;
  103. /**
  104. * @typedef {{
  105. * id: number,
  106. * originalId: ?string,
  107. * groupId: ?string,
  108. * primary: boolean,
  109. * type: string,
  110. * mimeType: string,
  111. * codecs: string,
  112. * frameRate: (number|undefined),
  113. * pixelAspectRatio: (string|undefined),
  114. * hdr: (string|undefined),
  115. * kind: (string|undefined),
  116. * language: string,
  117. * originalLanguage: (?string|undefined),
  118. * label: ?string,
  119. * width: ?number,
  120. * height: ?number,
  121. * encrypted: boolean,
  122. * keyIds: !Set.<string>,
  123. * segments: !Array.<shaka.extern.SegmentDB>,
  124. * variantIds: !Array.<number>,
  125. * roles: !Array.<string>,
  126. * forced: boolean,
  127. * channelsCount: ?number,
  128. * audioSamplingRate: ?number,
  129. * spatialAudio: boolean,
  130. * closedCaptions: Map.<string, string>,
  131. * tilesLayout: (string|undefined),
  132. * external: boolean
  133. * }}
  134. *
  135. * @property {number} id
  136. * The unique id of the stream.
  137. * @property {?string} originalId
  138. * The original ID, if any, that appeared in the manifest. For example, in
  139. * DASH, this is the "id" attribute of the Representation element.
  140. * @property {?string} groupId
  141. * The ID of the stream's parent element. In DASH, this will be a unique
  142. * ID that represents the representation's parent adaptation element
  143. * @property {boolean} primary
  144. * Whether the stream set was primary.
  145. * @property {string} type
  146. * The type of the stream, 'audio', 'text', or 'video'.
  147. * @property {string} mimeType
  148. * The MIME type of the stream.
  149. * @property {string} codecs
  150. * The codecs of the stream.
  151. * @property {(number|undefined)} frameRate
  152. * The Stream's framerate in frames per second.
  153. * @property {(string|undefined)} pixelAspectRatio
  154. * The Stream's pixel aspect ratio
  155. * @property {(string|undefined)} hdr
  156. * The Stream's HDR info
  157. * @property {(string|undefined)} kind
  158. * The kind of text stream; undefined for audio/video.
  159. * @property {string} language
  160. * The language of the stream; '' for video.
  161. * @property {(?string|undefined)} originalLanguage
  162. * The original language, if any, that appeared in the manifest.
  163. * @property {?string} label
  164. * The label of the stream; '' for video.
  165. * @property {?number} width
  166. * The width of the stream; null for audio/text.
  167. * @property {?number} height
  168. * The height of the stream; null for audio/text.
  169. * @property {boolean} encrypted
  170. * Whether this stream is encrypted.
  171. * @property {!Set.<string>} keyIds
  172. * The key IDs this stream is encrypted with.
  173. * @property {!Array.<shaka.extern.SegmentDB>} segments
  174. * An array of segments that make up the stream.
  175. * @property {!Array.<number>} variantIds
  176. * An array of ids of variants the stream is a part of.
  177. * @property {!Array.<string>} roles
  178. * The roles of the stream as they appear on the manifest,
  179. * e.g. 'main', 'caption', or 'commentary'.
  180. * @property {boolean} forced
  181. * Whether the stream set was forced.
  182. * @property {?number} channelsCount
  183. * The channel count information for the audio stream.
  184. * @property {?number} audioSamplingRate
  185. * Specifies the maximum sampling rate of the content.
  186. * @property {boolean} spatialAudio
  187. * Whether the stream set has spatial audio.
  188. * @property {Map.<string, string>} closedCaptions
  189. * A map containing the description of closed captions, with the caption
  190. * channel number (CC1 | CC2 | CC3 | CC4) as the key and the language code
  191. * as the value. If the channel number is not provided by the description,
  192. * we'll set an 0-based index as the key.
  193. * Example: {'CC1': 'eng'; 'CC3': 'swe'}, or {'1', 'eng'; '2': 'swe'}, etc.
  194. * @property {(string|undefined)} tilesLayout
  195. * The value is a grid-item-dimension consisting of two positive decimal
  196. * integers in the format: column-x-row ('4x3'). It describes the arrangement
  197. * of Images in a Grid. The minimum valid LAYOUT is '1x1'.
  198. * @property {boolean} external
  199. * Indicate if the stream was added externally.
  200. * Eg: external text tracks.
  201. */
  202. shaka.extern.StreamDB;
  203. /**
  204. * @typedef {{
  205. * initSegmentKey: ?number,
  206. * startTime: number,
  207. * endTime: number,
  208. * appendWindowStart: number,
  209. * appendWindowEnd: number,
  210. * timestampOffset: number,
  211. * tilesLayout: ?string,
  212. * pendingSegmentRefId: (string|undefined),
  213. * pendingInitSegmentRefId: (string|undefined),
  214. * dataKey: number
  215. * }}
  216. *
  217. * @property {?number} initSegmentKey
  218. * The storage key where the init segment is found; null if no init segment.
  219. * @property {number} startTime
  220. * The start time of the segment in the presentation timeline.
  221. * @property {number} endTime
  222. * The end time of the segment in the presentation timeline.
  223. * @property {number} appendWindowStart
  224. * A start timestamp before which media samples will be truncated.
  225. * @property {number} appendWindowEnd
  226. * An end timestamp beyond which media samples will be truncated.
  227. * @property {number} timestampOffset
  228. * An offset which MediaSource will add to the segment's media timestamps
  229. * during ingestion, to align to the presentation timeline.
  230. * @property {?string} tilesLayout
  231. * The value is a grid-item-dimension consisting of two positive decimal
  232. * integers in the format: column-x-row ('4x3'). It describes the
  233. * arrangement of Images in a Grid. The minimum valid LAYOUT is '1x1'.
  234. * @property {(string|undefined)} pendingSegmentRefId
  235. * Contains an id that identifies what the segment was, originally. Used to
  236. * coordinate where segments are stored, during the downloading process.
  237. * If this field is non-null, it's assumed that the segment is not fully
  238. * downloaded.
  239. * @property {(string|undefined)} pendingInitSegmentRefId
  240. * Contains an id that identifies what the init segment was, originally.
  241. * Used to coordinate where init segments are stored, during the downloading
  242. * process.
  243. * If this field is non-null, it's assumed that the init segment is not fully
  244. * downloaded.
  245. * @property {number} dataKey
  246. * The key to the data in storage.
  247. */
  248. shaka.extern.SegmentDB;
  249. /**
  250. * @typedef {{
  251. * data: !ArrayBuffer
  252. * }}
  253. *
  254. * @property {!ArrayBuffer} data
  255. * The data contents of the segment.
  256. */
  257. shaka.extern.SegmentDataDB;
  258. /**
  259. * @typedef {{
  260. * sessionId: string,
  261. * keySystem: string,
  262. * licenseUri: string,
  263. * serverCertificate: Uint8Array,
  264. * audioCapabilities: !Array.<MediaKeySystemMediaCapability>,
  265. * videoCapabilities: !Array.<MediaKeySystemMediaCapability>
  266. * }}
  267. *
  268. * @property {string} sessionId
  269. * The EME session ID.
  270. * @property {string} keySystem
  271. * The EME key system string the session belongs to.
  272. * @property {string} licenseUri
  273. * The URI for the license server.
  274. * @property {Uint8Array} serverCertificate
  275. * A key-system-specific server certificate used to encrypt license requests.
  276. * Its use is optional and is meant as an optimization to avoid a round-trip
  277. * to request a certificate.
  278. * @property {!Array.<MediaKeySystemMediacapability>} audioCapabilities
  279. * The EME audio capabilities used to create the session.
  280. * @property {!Array.<MediaKeySystemMediacapability>} videoCapabilities
  281. * The EME video capabilities used to create the session.
  282. */
  283. shaka.extern.EmeSessionDB;
  284. /**
  285. * An interface that defines access to collection of segments and manifests. All
  286. * methods are designed to be batched operations allowing the implementations to
  287. * optimize their operations based on how they store data.
  288. *
  289. * The storage cell is one of two exposed APIs used to control where and how
  290. * offline content is saved. The storage cell is responsible for converting
  291. * information between its internal structures and the external (library)
  292. * structures.
  293. *
  294. * @interface
  295. */
  296. shaka.extern.StorageCell = class {
  297. constructor() {}
  298. /**
  299. * Free all resources used by this cell. This should not affect the stored
  300. * content.
  301. *
  302. * @return {!Promise}
  303. */
  304. destroy() {}
  305. /**
  306. * Check if the cell can support new keys. If a cell has a fixed key space,
  307. * then all add-operations will fail as no new keys can be added. All
  308. * remove-operations and update-operations should still work.
  309. *
  310. * @return {boolean}
  311. */
  312. hasFixedKeySpace() {}
  313. /**
  314. * Add a group of segments. Will return a promise that resolves with a list
  315. * of keys for each segment. If one segment fails to be added, all segments
  316. * should fail to be added.
  317. *
  318. * @param {!Array.<shaka.extern.SegmentDataDB>} segments
  319. * @return {!Promise.<!Array.<number>>}
  320. */
  321. addSegments(segments) {}
  322. /**
  323. * Remove a group of segments using their keys to identify them. If a key
  324. * is not found, then that removal should be considered successful.
  325. *
  326. * @param {!Array.<number>} keys
  327. * @param {function(number)} onRemove A callback for when a segment is removed
  328. * from the cell. The key of the segment
  329. * will be passed to the callback.
  330. * @return {!Promise}
  331. */
  332. removeSegments(keys, onRemove) {}
  333. /**
  334. * Get a group of segments using their keys to identify them. If any key is
  335. * not found, the promise chain will be rejected.
  336. *
  337. * @param {!Array.<number>} keys
  338. * @return {!Promise.<!Array.<shaka.extern.SegmentDataDB>>}
  339. */
  340. getSegments(keys) {}
  341. /**
  342. * Add a group of manifests. Will return a promise that resolves with a list
  343. * of keys for each manifest. If one manifest fails to be added, all manifests
  344. * should fail to be added.
  345. *
  346. * @param {!Array.<shaka.extern.ManifestDB>} manifests
  347. * @return {!Promise<!Array.<number>>} keys
  348. */
  349. addManifests(manifests) {}
  350. /**
  351. * Updates the given manifest, stored at the given key.
  352. *
  353. * @param {number} key
  354. * @param {!shaka.extern.ManifestDB} manifest
  355. * @return {!Promise}
  356. */
  357. updateManifest(key, manifest) {}
  358. /**
  359. * Replace the expiration time of the manifest stored under |key| with
  360. * |newExpiration|. If no manifest is found under |key| then this should
  361. * act as a no-op.
  362. *
  363. * @param {number} key
  364. * @param {number} expiration
  365. * @return {!Promise}
  366. */
  367. updateManifestExpiration(key, expiration) {}
  368. /**
  369. * Remove a group of manifests using their keys to identify them. If a key
  370. * is not found, then that removal should be considered successful.
  371. *
  372. * @param {!Array.<number>} keys
  373. * @param {function(number)} onRemove A callback for when a manifest is
  374. * removed from the cell. The key of the
  375. * manifest will be passed to the callback.
  376. * @return {!Promise}
  377. */
  378. removeManifests(keys, onRemove) {}
  379. /**
  380. * Get a group of manifests using their keys to identify them. If any key is
  381. * not found, the promise chain will be rejected.
  382. *
  383. * @param {!Array.<number>} keys
  384. * @return {!Promise<!Array.<shaka.extern.ManifestDB>>}
  385. */
  386. getManifests(keys) {}
  387. /**
  388. * Get all manifests stored in this cell. Since manifests are small compared
  389. * to the asset they describe, it is assumed that it is feasible to have them
  390. * all in main memory at one time.
  391. *
  392. * @return {!Promise<!Map.<number, shaka.extern.ManifestDB>>}
  393. */
  394. getAllManifests() {}
  395. };
  396. /**
  397. * Similar to storage cells (shaka.extern.StorageCell), an EmeSessionStorageCell
  398. * stores data persistently. This only stores the license's session info, not
  399. * the license itself. The license itself is stored using EME.
  400. *
  401. * @interface
  402. */
  403. shaka.extern.EmeSessionStorageCell = class {
  404. constructor() {}
  405. /**
  406. * Free all resources used by this cell. This won't affect the stored content.
  407. * @return {!Promise}
  408. */
  409. destroy() {}
  410. /**
  411. * Gets the currently stored sessions.
  412. * @return {!Promise.<!Array.<shaka.extern.EmeSessionDB>>}
  413. */
  414. getAll() {}
  415. /**
  416. * Adds the given sessions to the store.
  417. * @param {!Array.<shaka.extern.EmeSessionDB>} sessions
  418. * @return {!Promise}
  419. */
  420. add(sessions) {}
  421. /**
  422. * Removes the given session IDs from the store.
  423. * @param {!Array.<string>} sessionIds
  424. * @return {!Promise}
  425. */
  426. remove(sessionIds) {}
  427. };
  428. /**
  429. * Storage mechanisms are one of two exported storage APIs. Storage mechanisms
  430. * are groups of storage cells (shaka.extern.StorageCell). Storage mechanisms
  431. * are responsible for managing the life cycle of resources shared between
  432. * storage cells in the same block.
  433. *
  434. * For example, a storage mechanism may manage a single database connection
  435. * while each cell would manage different tables in the database via the same
  436. * connection.
  437. *
  438. * @interface
  439. */
  440. shaka.extern.StorageMechanism = class {
  441. constructor() {}
  442. /**
  443. * Initialize the storage mechanism for first use. This should only be called
  444. * once. Calling |init| multiple times has an undefined behaviour.
  445. *
  446. * @return {!Promise}
  447. */
  448. init() {}
  449. /**
  450. * Free all resources used by the storage mechanism and its cells. This should
  451. * not affect the stored content.
  452. *
  453. * @return {!Promise}
  454. */
  455. destroy() {}
  456. /**
  457. * Get a map of all the cells managed by the storage mechanism. Editing the
  458. * map should have no effect on the storage mechanism. The map key is the
  459. * cell's address in the mechanism and should be consistent between calls to
  460. * |getCells|.
  461. *
  462. * @return {!Map.<string, !shaka.extern.StorageCell>}
  463. */
  464. getCells() {}
  465. /**
  466. * Get the current EME session storage cell.
  467. * @return {!shaka.extern.EmeSessionStorageCell}
  468. */
  469. getEmeSessionCell() {}
  470. /**
  471. * Erase all content from storage and leave storage in an empty state. Erase
  472. * may be called with or without |init|. This allows for storage to be wiped
  473. * in case of a version mismatch.
  474. *
  475. * After calling |erase|, the mechanism will be in an initialized state.
  476. *
  477. * @return {!Promise}
  478. */
  479. erase() {}
  480. };