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