Source: externs/shaka/manifest.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. * presentationTimeline: !shaka.media.PresentationTimeline,
  12. * variants: !Array<shaka.extern.Variant>,
  13. * textStreams: !Array<shaka.extern.Stream>,
  14. * imageStreams: !Array<shaka.extern.Stream>,
  15. * offlineSessionIds: !Array<string>,
  16. * sequenceMode: boolean,
  17. * ignoreManifestTimestampsInSegmentsMode: boolean,
  18. * type: string,
  19. * serviceDescription: ?shaka.extern.ServiceDescription,
  20. * nextUrl: ?string,
  21. * periodCount: number,
  22. * gapCount: number,
  23. * isLowLatency: boolean,
  24. * startTime: ?number
  25. * }}
  26. *
  27. * @description
  28. * <p>
  29. * A Manifest object describes a collection of streams (segmented audio, video,
  30. * or text data) that share a common timeline. We call the collection of
  31. * streams "the presentation" and their timeline "the presentation timeline".
  32. * A Manifest describes one of two types of presentations: live and
  33. * video-on-demand.
  34. * </p>
  35. *
  36. * <p>
  37. * A live presentation begins at some point in time and either continues
  38. * indefinitely or ends when the presentation stops broadcasting. For a live
  39. * presentation, wall-clock time maps onto the presentation timeline, and the
  40. * current wall-clock time maps to the live-edge (AKA "the current presentation
  41. * time"). In contrast, a video-on-demand presentation exists entirely
  42. * independent of wall-clock time.
  43. * </p>
  44. *
  45. * <p>
  46. * A variant is a combination of an audio and a video streams that can be played
  47. * together.
  48. * </p>
  49. *
  50. * <p>
  51. * A stream has the same logical content as another stream if the only
  52. * difference between the two is their quality. For example, an SD video stream
  53. * and an HD video stream that depict the same scene have the same logical
  54. * content; whereas an English audio stream and a French audio stream have
  55. * different logical contents. The player can automatically switch between
  56. * streams which have the same logical content to adapt to network conditions.
  57. * </p>
  58. *
  59. * @property {!shaka.media.PresentationTimeline} presentationTimeline
  60. * <i>Required.</i> <br>
  61. * The presentation timeline.
  62. * @property {!Array<shaka.extern.Variant>} variants
  63. * <i>Required.</i> <br>
  64. * The presentation's Variants. There must be at least one Variant.
  65. * @property {!Array<shaka.extern.Stream>} textStreams
  66. * <i>Required.</i> <br>
  67. * The presentation's text streams.
  68. * @property {!Array<shaka.extern.Stream>} imageStreams
  69. * <i>Required.</i> <br>
  70. * The presentation's image streams
  71. * @property {!Array<string>} offlineSessionIds
  72. * <i>Defaults to [].</i> <br>
  73. * An array of EME sessions to load for offline playback.
  74. * @property {boolean} sequenceMode
  75. * If true, we will append the media segments using sequence mode; that is to
  76. * say, ignoring any timestamps inside the media files.
  77. * @property {boolean} ignoreManifestTimestampsInSegmentsMode
  78. * If true, don't adjust the timestamp offset to account for manifest
  79. * segment durations being out of sync with segment durations. In other
  80. * words, assume that there are no gaps in the segments when appending
  81. * to the SourceBuffer, even if the manifest and segment times disagree.
  82. * Only applies when sequenceMode is <code>false</code>, and only for HLS
  83. * streams.
  84. * <i>Defaults to <code>false</code>.</i>
  85. * @property {string} type
  86. * Indicates the type of the manifest. It can be <code>'HLS'</code> or
  87. * <code>'DASH'</code>.
  88. * @property {?shaka.extern.ServiceDescription} serviceDescription
  89. * The service description for the manifest. Used to adapt playbackRate to
  90. * decrease latency.
  91. * @property {?string} nextUrl
  92. * The next url to play.
  93. * @property {number} periodCount
  94. * Number of periods found in a manifest. For DASH, it represents number of
  95. * Period elements in a manifest. If streaming protocol does not implement
  96. * period-like structure, it should be set to 1.
  97. * <i>Defaults to <code>1</code>.</i>
  98. * @property {number} gapCount
  99. * The amount of gaps found in a manifest. For DASH, it represents number of
  100. * discontinuities found between periods. For HLS, it is a number of EXT-X-GAP
  101. * and GAP=YES occurrences. For MSS, it is always set to 0.
  102. * If in src= mode or nothing is loaded, NaN.
  103. * @property {boolean} isLowLatency
  104. * If true, the manifest is Low Latency.
  105. * @property {?number} startTime
  106. * Indicate the startTime of the playback, when <code>startTime</code> is
  107. * <code>null</code>, playback will start at the default start time.
  108. * Note: It only overrides the load startTime when it is not defined.
  109. *
  110. * @exportDoc
  111. */
  112. shaka.extern.Manifest;
  113. /**
  114. * @typedef {{
  115. * id: string,
  116. * audioStreams: !Array<shaka.extern.Stream>,
  117. * videoStreams: !Array<shaka.extern.Stream>,
  118. * textStreams: !Array<shaka.extern.Stream>,
  119. * imageStreams: !Array<shaka.extern.Stream>
  120. * }}
  121. *
  122. * @description Contains the streams from one DASH period.
  123. * For use in {@link shaka.util.PeriodCombiner}.
  124. *
  125. * @property {string} id
  126. * The Period ID.
  127. * @property {!Array<shaka.extern.Stream>} audioStreams
  128. * The audio streams from one Period.
  129. * @property {!Array<shaka.extern.Stream>} videoStreams
  130. * The video streams from one Period.
  131. * @property {!Array<shaka.extern.Stream>} textStreams
  132. * The text streams from one Period.
  133. * @property {!Array<shaka.extern.Stream>} imageStreams
  134. * The image streams from one Period.
  135. *
  136. * @exportDoc
  137. */
  138. shaka.extern.Period;
  139. /**
  140. * @typedef {{
  141. * targetLatency:?number,
  142. * maxLatency: ?number,
  143. * maxPlaybackRate: ?number,
  144. * minLatency: ?number,
  145. * minPlaybackRate: ?number
  146. * }}
  147. *
  148. * @description
  149. * Maximum and minimum latency and playback rate for a manifest. When max
  150. * latency is reached playbackrate is updated to maxPlaybackRate to decrease
  151. * latency. When min latency is reached playbackrate is updated to
  152. * minPlaybackRate to increase latency.
  153. * More information {@link https://dashif.org/docs/CR-Low-Latency-Live-r8.pdf here}.
  154. *
  155. * @property {?number} targetLatency
  156. * The target latency to aim for.
  157. * @property {?number} maxLatency
  158. * Maximum latency in seconds.
  159. * @property {?number} maxPlaybackRate
  160. * Maximum playback rate.
  161. * @property {?number} minLatency
  162. * Minimum latency in seconds.
  163. * @property {?number} minPlaybackRate
  164. * Minimum playback rate.
  165. *
  166. * @exportDoc
  167. */
  168. shaka.extern.ServiceDescription;
  169. /**
  170. * @typedef {{
  171. * id: number,
  172. * language: string,
  173. * disabledUntilTime: number,
  174. * primary: boolean,
  175. * audio: ?shaka.extern.Stream,
  176. * video: ?shaka.extern.Stream,
  177. * bandwidth: number,
  178. * allowedByApplication: boolean,
  179. * allowedByKeySystem: boolean,
  180. * decodingInfos: !Array<MediaCapabilitiesDecodingInfo>
  181. * }}
  182. *
  183. * @description
  184. * A Variant describes a combination of an audio and video streams which
  185. * could be played together. It's possible to have a video/audio only
  186. * variant.
  187. *
  188. * @property {number} id
  189. * <i>Required.</i> <br>
  190. * A unique ID among all Variant objects within the same Manifest.
  191. * @property {string} language
  192. * <i>Defaults to '' (i.e., unknown).</i> <br>
  193. * The Variant's language, specified as a language code. <br>
  194. * See {@link https://tools.ietf.org/html/rfc5646} <br>
  195. * See {@link http://www.iso.org/iso/home/standards/language_codes.htm}
  196. * @property {number} disabledUntilTime
  197. * <i>Defaults to 0.</i> <br>
  198. * 0 means the variant is enabled. The Player will set this value to
  199. * "(Date.now() / 1000) + config.streaming.maxDisabledTime" and once this
  200. * maxDisabledTime has passed Player will set the value to 0 in order to
  201. * reenable the variant.
  202. * @property {boolean} primary
  203. * <i>Defaults to false.</i> <br>
  204. * True indicates that the player should use this Variant over others if user
  205. * preferences cannot be met. The player may still use another Variant to
  206. * meet user preferences.
  207. * @property {?shaka.extern.Stream} audio
  208. * The audio stream of the variant.
  209. * @property {?shaka.extern.Stream} video
  210. * The video stream of the variant.
  211. * @property {number} bandwidth
  212. * The variant's required bandwidth in bits per second.
  213. * @property {boolean} allowedByApplication
  214. * <i>Defaults to true.</i><br>
  215. * Set by the Player to indicate whether the variant is allowed to be played
  216. * by the application.
  217. * @property {boolean} allowedByKeySystem
  218. * <i>Defaults to true.</i><br>
  219. * Set by the Player to indicate whether the variant is allowed to be played
  220. * by the key system.
  221. * @property {!Array<MediaCapabilitiesDecodingInfo>} decodingInfos
  222. * <i>Defaults to [].</i><br>
  223. * Set by StreamUtils to indicate the results from MediaCapabilities
  224. * decodingInfo.
  225. *
  226. * @exportDoc
  227. */
  228. shaka.extern.Variant;
  229. /**
  230. * Creates a SegmentIndex; returns a Promise that resolves after the
  231. * SegmentIndex has been created.
  232. *
  233. * @typedef {function(): !Promise}
  234. * @exportDoc
  235. */
  236. shaka.extern.CreateSegmentIndexFunction;
  237. /**
  238. * @typedef {{
  239. * bitsKey: number,
  240. * blockCipherMode: string,
  241. * cryptoKey: (webCrypto.CryptoKey|undefined),
  242. * fetchKey: (shaka.extern.CreateSegmentIndexFunction|undefined),
  243. * iv: (!Uint8Array|undefined),
  244. * firstMediaSequenceNumber: number
  245. * }}
  246. *
  247. * @description
  248. * AES key and iv info from the manifest.
  249. *
  250. * @property {number} bitsKey
  251. * The number of the bit key (eg: 128, 256).
  252. * @property {string} blockCipherMode
  253. * The block cipher mode of operation. Possible values: 'CTR' or 'CBC'.
  254. * @property {webCrypto.CryptoKey|undefined} cryptoKey
  255. * Web crypto key object of the AES key. If unset, the "fetchKey"
  256. * property should be provided.
  257. * @property {shaka.extern.FetchCryptoKeysFunction|undefined} fetchKey
  258. * A function that fetches the key.
  259. * Should be provided if the "cryptoKey" property is unset.
  260. * Should update this object in-place, to set "cryptoKey".
  261. * @property {(!Uint8Array|undefined)} iv
  262. * The IV in the manifest, if defined. For HLS see HLS RFC 8216 Section 5.2
  263. * for handling undefined IV.
  264. * @property {number} firstMediaSequenceNumber
  265. * The starting Media Sequence Number of the playlist, used when IV is
  266. * undefined.
  267. *
  268. * @exportDoc
  269. */
  270. shaka.extern.aesKey;
  271. /**
  272. * A function that fetches the crypto keys for AES-128.
  273. * Returns a promise that resolves when the keys have been fetched.
  274. *
  275. * @typedef {function(): !Promise}
  276. * @exportDoc
  277. */
  278. shaka.extern.FetchCryptoKeysFunction;
  279. /**
  280. * SegmentIndex minimal API.
  281. * @interface
  282. * @exportDoc
  283. */
  284. shaka.extern.SegmentIndex = class {
  285. /**
  286. * Get number of references.
  287. * @return {number}
  288. * @exportDoc
  289. */
  290. getNumReferences() {}
  291. /**
  292. * Finds the position of the segment for the given time, in seconds, relative
  293. * to the start of the presentation. Returns the position of the segment
  294. * with the largest end time if more than one segment is known for the given
  295. * time.
  296. *
  297. * @param {number} time
  298. * @return {?number} The position of the segment, or null if the position of
  299. * the segment could not be determined.
  300. * @exportDoc
  301. */
  302. find(time) {}
  303. /**
  304. * Gets the SegmentReference for the segment at the given position.
  305. *
  306. * @param {number} position The position of the segment as returned by find().
  307. * @return {shaka.media.SegmentReference} The SegmentReference, or null if
  308. * no such SegmentReference exists.
  309. * @exportDoc
  310. */
  311. get(position) {}
  312. /**
  313. * Gets number of already evicted segments.
  314. * @return {number}
  315. * @exportDoc
  316. */
  317. getNumEvicted() {}
  318. };
  319. /**
  320. * @typedef {{
  321. * id: number,
  322. * originalId: ?string,
  323. * groupId: ?string,
  324. * createSegmentIndex: shaka.extern.CreateSegmentIndexFunction,
  325. * closeSegmentIndex: (function()|undefined),
  326. * segmentIndex: shaka.media.SegmentIndex,
  327. * mimeType: string,
  328. * codecs: string,
  329. * frameRate: (number|undefined),
  330. * pixelAspectRatio: (string|undefined),
  331. * hdr: (string|undefined),
  332. * colorGamut: (string|undefined),
  333. * videoLayout: (string|undefined),
  334. * bandwidth: (number|undefined),
  335. * width: (number|undefined),
  336. * height: (number|undefined),
  337. * kind: (string|undefined),
  338. * encrypted: boolean,
  339. * drmInfos: !Array<shaka.extern.DrmInfo>,
  340. * keyIds: !Set<string>,
  341. * language: string,
  342. * originalLanguage: ?string,
  343. * label: ?string,
  344. * type: string,
  345. * primary: boolean,
  346. * trickModeVideo: ?shaka.extern.Stream,
  347. * dependencyStream: ?shaka.extern.Stream,
  348. * emsgSchemeIdUris: ?Array<string>,
  349. * roles: !Array<string>,
  350. * accessibilityPurpose: ?shaka.media.ManifestParser.AccessibilityPurpose,
  351. * forced: boolean,
  352. * channelsCount: ?number,
  353. * audioSamplingRate: ?number,
  354. * spatialAudio: boolean,
  355. * closedCaptions: Map<string, string>,
  356. * tilesLayout: (string|undefined),
  357. * matchedStreams:
  358. * (!Array<shaka.extern.Stream>|!Array<shaka.extern.StreamDB>|
  359. * undefined),
  360. * mssPrivateData: (shaka.extern.MssPrivateData|undefined),
  361. * external: boolean,
  362. * fastSwitching: boolean,
  363. * fullMimeTypes: !Set<string>,
  364. * isAudioMuxedInVideo: boolean,
  365. * baseOriginalId: ?string
  366. * }}
  367. *
  368. * @description
  369. * A Stream object describes a single stream (segmented media data).
  370. *
  371. * @property {number} id
  372. * <i>Required.</i> <br>
  373. * A unique ID among all Stream objects within the same Manifest.
  374. * @property {?string} originalId
  375. * <i>Optional.</i> <br>
  376. * The original ID, if any, that appeared in the manifest. For example, in
  377. * DASH, this is the "id" attribute of the Representation element. In HLS,
  378. * this is the "NAME" attribute.
  379. * @property {?string} groupId
  380. * <i>Optional.</i> <br>
  381. * The ID of the stream's parent element. In DASH, this will be a unique
  382. * ID that represents the representation's parent adaptation element
  383. * @property {shaka.extern.CreateSegmentIndexFunction} createSegmentIndex
  384. * <i>Required.</i> <br>
  385. * Creates the Stream's segmentIndex (asynchronously).
  386. * @property {(function()|undefined)} closeSegmentIndex
  387. * <i>Optional.</i> <br>
  388. * Closes the Stream's segmentIndex.
  389. * @property {shaka.media.SegmentIndex} segmentIndex
  390. * <i>Required.</i> <br>
  391. * May be null until createSegmentIndex() is complete.
  392. * @property {string} mimeType
  393. * <i>Required.</i> <br>
  394. * The Stream's MIME type, e.g., 'audio/mp4', 'video/webm', or 'text/vtt'.
  395. * In the case of a stream that adapts between different periods with
  396. * different MIME types, this represents only the first period.
  397. * @property {string} codecs
  398. * <i>Defaults to '' (i.e., unknown / not needed).</i> <br>
  399. * The Stream's codecs, e.g., 'avc1.4d4015' or 'vp9', which must be
  400. * compatible with the Stream's MIME type. <br>
  401. * In the case of a stream that adapts between different periods with
  402. * different codecs, this represents only the first period.
  403. * See {@link https://tools.ietf.org/html/rfc6381}
  404. * @property {(number|undefined)} frameRate
  405. * <i>Video streams only.</i> <br>
  406. * The Stream's framerate in frames per second
  407. * @property {(string|undefined)} pixelAspectRatio
  408. * <i>Video streams only.</i> <br>
  409. * The Stream's pixel aspect ratio
  410. * @property {(string|undefined)} hdr
  411. * <i>Video streams only.</i> <br>
  412. * The Stream's HDR info
  413. * @property {(string|undefined)} colorGamut
  414. * <i>Video streams only.</i> <br>
  415. * The Stream's color gamut info
  416. * @property {(string|undefined)} videoLayout
  417. * <i>Video streams only.</i> <br>
  418. * The Stream's video layout info.
  419. * @property {(number|undefined)} bandwidth
  420. * <i>Audio and video streams only.</i> <br>
  421. * The stream's required bandwidth in bits per second.
  422. * @property {(number|undefined)} width
  423. * <i>Video streams only.</i> <br>
  424. * The stream's width in pixels.
  425. * @property {(number|undefined)} height
  426. * <i>Video streams only.</i> <br>
  427. * The stream's height in pixels.
  428. * @property {(string|undefined)} kind
  429. * <i>Text streams only.</i> <br>
  430. * The kind of text stream. For example, 'caption' or 'subtitle'.
  431. * @see https://bit.ly/TextKind
  432. * @property {boolean} encrypted
  433. * <i>Defaults to false.</i><br>
  434. * True if the stream is encrypted.
  435. * Note: DRM encryption only, so AES encryption is not taken into account.
  436. * @property {!Array<!shaka.extern.DrmInfo>} drmInfos
  437. * <i>Defaults to [] (i.e., no DRM).</i> <br>
  438. * An array of DrmInfo objects which describe DRM schemes are compatible with
  439. * the content.
  440. * @property {!Set<string>} keyIds
  441. * <i>Defaults to empty (i.e., unencrypted or key ID unknown).</i> <br>
  442. * The stream's key IDs as lowercase hex strings. These key IDs identify the
  443. * encryption keys that the browser (key system) can use to decrypt the
  444. * stream.
  445. * @property {string} language
  446. * The Stream's language, specified as a language code. <br>
  447. * Audio stream's language must be identical to the language of the containing
  448. * Variant.
  449. * @property {?string} originalLanguage
  450. * <i>Optional.</i> <br>
  451. * The original language, if any, that appeared in the manifest.
  452. * @property {?string} label
  453. * The Stream's label, unique text that should describe the audio/text track.
  454. * @property {string} type
  455. * <i>Required.</i> <br>
  456. * Content type (e.g. 'video', 'audio' or 'text', 'image')
  457. * @property {boolean} primary
  458. * <i>Defaults to false.</i> <br>
  459. * True indicates that the player should use this Stream over others if user
  460. * preferences cannot be met. The player may still use another Variant to
  461. * meet user preferences.
  462. * @property {?shaka.extern.Stream} trickModeVideo
  463. * <i>Video streams only.</i> <br>
  464. * An alternate video stream to use for trick mode playback.
  465. * @property {?shaka.extern.Stream} dependencyStream
  466. * <i>Video streams only.</i> <br>
  467. * Dependency stream to use for enhance the quality of the base stream.
  468. * @property {?Array<string>} emsgSchemeIdUris
  469. * <i>Defaults to empty.</i><br>
  470. * Array of registered emsg box scheme_id_uri that should result in
  471. * Player events.
  472. * @property {!Array<string>} roles
  473. * The roles of the stream as they appear on the manifest,
  474. * e.g. 'main', 'caption', or 'commentary'.
  475. * @property {?shaka.media.ManifestParser.AccessibilityPurpose
  476. * } accessibilityPurpose
  477. * The DASH accessibility descriptor, if one was provided for this stream.
  478. * @property {boolean} forced
  479. * <i>Defaults to false.</i> <br>
  480. * Whether the stream set was forced
  481. * @property {?number} channelsCount
  482. * The channel count information for the audio stream.
  483. * @property {?number} audioSamplingRate
  484. * Specifies the maximum sampling rate of the content.
  485. * @property {boolean} spatialAudio
  486. * <i>Defaults to false.</i> <br>
  487. * Whether the stream set has spatial audio
  488. * @property {Map<string, string>} closedCaptions
  489. * A map containing the description of closed captions, with the caption
  490. * channel number (CC1 | CC2 | CC3 | CC4) as the key and the language code
  491. * as the value. If the channel number is not provided by the description,
  492. * we'll set a 0-based index as the key. If the language code is not
  493. * provided by the description we'll set the same value as channel number.
  494. * Example: {'CC1': 'eng'; 'CC3': 'swe'}, or {'1', 'eng'; '2': 'swe'}, etc.
  495. * @property {(string|undefined)} tilesLayout
  496. * <i>Image streams only.</i> <br>
  497. * The value is a grid-item-dimension consisting of two positive decimal
  498. * integers in the format: column-x-row ('4x3'). It describes the arrangement
  499. * of Images in a Grid. The minimum valid LAYOUT is '1x1'.
  500. * @property {(!Array<shaka.extern.Stream>|!Array<shaka.extern.StreamDB>|
  501. * undefined)} matchedStreams
  502. * The streams in all periods which match the stream. Used for Dash.
  503. * @property {(shaka.extern.MssPrivateData|undefined)} mssPrivateData
  504. * <i>Microsoft Smooth Streaming only.</i> <br>
  505. * Private MSS data that is necessary to be able to do transmuxing.
  506. * @property {boolean} external
  507. * Indicate if the stream was added externally.
  508. * Eg: external text tracks.
  509. * @property {boolean} fastSwitching
  510. * Indicate if the stream should be used for fast switching.
  511. * @property {!Set<string>} fullMimeTypes
  512. * A set of full MIME types (e.g. MIME types plus codecs information), that
  513. * represents the types used in each period of the original manifest.
  514. * Meant for being used by compatibility checking, such as with
  515. * MediaSource.isTypeSupported.
  516. * @property {boolean} isAudioMuxedInVideo
  517. * Indicate if the audio of this stream is muxed in the video of other stream.
  518. * @property {?string} baseOriginalId
  519. * <i>Optional.</i> <br>
  520. * Indicate the original ID of the base stream, if any, that appeared in the
  521. * manifest. Only populated when the stream is included within another stream
  522. * using dependencyStream.
  523. *
  524. * @exportDoc
  525. */
  526. shaka.extern.Stream;
  527. /**
  528. * @typedef {{
  529. * duration: number,
  530. * timescale: number,
  531. * codecPrivateData: ?string
  532. * }}
  533. *
  534. * @description
  535. * Private MSS data that is necessary to be able to do transmuxing.
  536. *
  537. * @property {number} duration
  538. * <i>Required.</i> <br>
  539. * MSS Stream duration.
  540. * @property {number} timescale
  541. * <i>Required.</i> <br>
  542. * MSS timescale.
  543. * @property {?string} codecPrivateData
  544. * MSS codecPrivateData.
  545. *
  546. * @exportDoc
  547. */
  548. shaka.extern.MssPrivateData;
  549. /**
  550. * @typedef {{
  551. * height: number,
  552. * positionX: number,
  553. * positionY: number,
  554. * width: number
  555. * }}
  556. *
  557. * @property {number} height
  558. * The thumbnail height in px.
  559. * @property {number} positionX
  560. * The thumbnail left position in px.
  561. * @property {number} positionY
  562. * The thumbnail top position in px.
  563. * @property {number} width
  564. * The thumbnail width in px.
  565. *
  566. * @exportDoc
  567. */
  568. shaka.extern.ThumbnailSprite;