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