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