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. * emsgSchemeIdUris: ?Array<string>,
  348. * roles: !Array<string>,
  349. * accessibilityPurpose: ?shaka.media.ManifestParser.AccessibilityPurpose,
  350. * forced: boolean,
  351. * channelsCount: ?number,
  352. * audioSamplingRate: ?number,
  353. * spatialAudio: boolean,
  354. * closedCaptions: Map<string, string>,
  355. * tilesLayout: (string|undefined),
  356. * matchedStreams:
  357. * (!Array<shaka.extern.Stream>|!Array<shaka.extern.StreamDB>|
  358. * undefined),
  359. * mssPrivateData: (shaka.extern.MssPrivateData|undefined),
  360. * external: boolean,
  361. * fastSwitching: boolean,
  362. * fullMimeTypes: !Set<string>,
  363. * isAudioMuxedInVideo: boolean
  364. * }}
  365. *
  366. * @description
  367. * A Stream object describes a single stream (segmented media data).
  368. *
  369. * @property {number} id
  370. * <i>Required.</i> <br>
  371. * A unique ID among all Stream objects within the same Manifest.
  372. * @property {?string} originalId
  373. * <i>Optional.</i> <br>
  374. * The original ID, if any, that appeared in the manifest. For example, in
  375. * DASH, this is the "id" attribute of the Representation element. In HLS,
  376. * this is the "NAME" attribute.
  377. * @property {?string} groupId
  378. * <i>Optional.</i> <br>
  379. * The ID of the stream's parent element. In DASH, this will be a unique
  380. * ID that represents the representation's parent adaptation element
  381. * @property {shaka.extern.CreateSegmentIndexFunction} createSegmentIndex
  382. * <i>Required.</i> <br>
  383. * Creates the Stream's segmentIndex (asynchronously).
  384. * @property {(function()|undefined)} closeSegmentIndex
  385. * <i>Optional.</i> <br>
  386. * Closes the Stream's segmentIndex.
  387. * @property {shaka.media.SegmentIndex} segmentIndex
  388. * <i>Required.</i> <br>
  389. * May be null until createSegmentIndex() is complete.
  390. * @property {string} mimeType
  391. * <i>Required.</i> <br>
  392. * The Stream's MIME type, e.g., 'audio/mp4', 'video/webm', or 'text/vtt'.
  393. * In the case of a stream that adapts between different periods with
  394. * different MIME types, this represents only the first period.
  395. * @property {string} codecs
  396. * <i>Defaults to '' (i.e., unknown / not needed).</i> <br>
  397. * The Stream's codecs, e.g., 'avc1.4d4015' or 'vp9', which must be
  398. * compatible with the Stream's MIME type. <br>
  399. * In the case of a stream that adapts between different periods with
  400. * different codecs, this represents only the first period.
  401. * See {@link https://tools.ietf.org/html/rfc6381}
  402. * @property {(number|undefined)} frameRate
  403. * <i>Video streams only.</i> <br>
  404. * The Stream's framerate in frames per second
  405. * @property {(string|undefined)} pixelAspectRatio
  406. * <i>Video streams only.</i> <br>
  407. * The Stream's pixel aspect ratio
  408. * @property {(string|undefined)} hdr
  409. * <i>Video streams only.</i> <br>
  410. * The Stream's HDR info
  411. * @property {(string|undefined)} colorGamut
  412. * <i>Video streams only.</i> <br>
  413. * The Stream's color gamut info
  414. * @property {(string|undefined)} videoLayout
  415. * <i>Video streams only.</i> <br>
  416. * The Stream's video layout info.
  417. * @property {(number|undefined)} bandwidth
  418. * <i>Audio and video streams only.</i> <br>
  419. * The stream's required bandwidth in bits per second.
  420. * @property {(number|undefined)} width
  421. * <i>Video streams only.</i> <br>
  422. * The stream's width in pixels.
  423. * @property {(number|undefined)} height
  424. * <i>Video streams only.</i> <br>
  425. * The stream's height in pixels.
  426. * @property {(string|undefined)} kind
  427. * <i>Text streams only.</i> <br>
  428. * The kind of text stream. For example, 'caption' or 'subtitle'.
  429. * @see https://bit.ly/TextKind
  430. * @property {boolean} encrypted
  431. * <i>Defaults to false.</i><br>
  432. * True if the stream is encrypted.
  433. * Note: DRM encryption only, so AES encryption is not taken into account.
  434. * @property {!Array<!shaka.extern.DrmInfo>} drmInfos
  435. * <i>Defaults to [] (i.e., no DRM).</i> <br>
  436. * An array of DrmInfo objects which describe DRM schemes are compatible with
  437. * the content.
  438. * @property {!Set<string>} keyIds
  439. * <i>Defaults to empty (i.e., unencrypted or key ID unknown).</i> <br>
  440. * The stream's key IDs as lowercase hex strings. These key IDs identify the
  441. * encryption keys that the browser (key system) can use to decrypt the
  442. * stream.
  443. * @property {string} language
  444. * The Stream's language, specified as a language code. <br>
  445. * Audio stream's language must be identical to the language of the containing
  446. * Variant.
  447. * @property {?string} originalLanguage
  448. * <i>Optional.</i> <br>
  449. * The original language, if any, that appeared in the manifest.
  450. * @property {?string} label
  451. * The Stream's label, unique text that should describe the audio/text track.
  452. * @property {string} type
  453. * <i>Required.</i> <br>
  454. * Content type (e.g. 'video', 'audio' or 'text', 'image')
  455. * @property {boolean} primary
  456. * <i>Defaults to false.</i> <br>
  457. * True indicates that the player should use this Stream over others if user
  458. * preferences cannot be met. The player may still use another Variant to
  459. * meet user preferences.
  460. * @property {?shaka.extern.Stream} trickModeVideo
  461. * <i>Video streams only.</i> <br>
  462. * An alternate video stream to use for trick mode playback.
  463. * @property {?Array<string>} emsgSchemeIdUris
  464. * <i>Defaults to empty.</i><br>
  465. * Array of registered emsg box scheme_id_uri that should result in
  466. * Player events.
  467. * @property {!Array<string>} roles
  468. * The roles of the stream as they appear on the manifest,
  469. * e.g. 'main', 'caption', or 'commentary'.
  470. * @property {?shaka.media.ManifestParser.AccessibilityPurpose
  471. * } accessibilityPurpose
  472. * The DASH accessibility descriptor, if one was provided for this stream.
  473. * @property {boolean} forced
  474. * <i>Defaults to false.</i> <br>
  475. * Whether the stream set was forced
  476. * @property {?number} channelsCount
  477. * The channel count information for the audio stream.
  478. * @property {?number} audioSamplingRate
  479. * Specifies the maximum sampling rate of the content.
  480. * @property {boolean} spatialAudio
  481. * <i>Defaults to false.</i> <br>
  482. * Whether the stream set has spatial audio
  483. * @property {Map<string, string>} closedCaptions
  484. * A map containing the description of closed captions, with the caption
  485. * channel number (CC1 | CC2 | CC3 | CC4) as the key and the language code
  486. * as the value. If the channel number is not provided by the description,
  487. * we'll set a 0-based index as the key. If the language code is not
  488. * provided by the description we'll set the same value as channel number.
  489. * Example: {'CC1': 'eng'; 'CC3': 'swe'}, or {'1', 'eng'; '2': 'swe'}, etc.
  490. * @property {(string|undefined)} tilesLayout
  491. * <i>Image streams only.</i> <br>
  492. * The value is a grid-item-dimension consisting of two positive decimal
  493. * integers in the format: column-x-row ('4x3'). It describes the arrangement
  494. * of Images in a Grid. The minimum valid LAYOUT is '1x1'.
  495. * @property {(!Array<shaka.extern.Stream>|!Array<shaka.extern.StreamDB>|
  496. * undefined)} matchedStreams
  497. * The streams in all periods which match the stream. Used for Dash.
  498. * @property {(shaka.extern.MssPrivateData|undefined)} mssPrivateData
  499. * <i>Microsoft Smooth Streaming only.</i> <br>
  500. * Private MSS data that is necessary to be able to do transmuxing.
  501. * @property {boolean} external
  502. * Indicate if the stream was added externally.
  503. * Eg: external text tracks.
  504. * @property {boolean} fastSwitching
  505. * Indicate if the stream should be used for fast switching.
  506. * @property {!Set<string>} fullMimeTypes
  507. * A set of full MIME types (e.g. MIME types plus codecs information), that
  508. * represents the types used in each period of the original manifest.
  509. * Meant for being used by compatibility checking, such as with
  510. * MediaSource.isTypeSupported.
  511. * @property {boolean} isAudioMuxedInVideo
  512. * Indicate if the audio of this stream is muxed in the video of other stream.
  513. *
  514. * @exportDoc
  515. */
  516. shaka.extern.Stream;
  517. /**
  518. * @typedef {{
  519. * duration: number,
  520. * timescale: number,
  521. * codecPrivateData: ?string
  522. * }}
  523. *
  524. * @description
  525. * Private MSS data that is necessary to be able to do transmuxing.
  526. *
  527. * @property {number} duration
  528. * <i>Required.</i> <br>
  529. * MSS Stream duration.
  530. * @property {number} timescale
  531. * <i>Required.</i> <br>
  532. * MSS timescale.
  533. * @property {?string} codecPrivateData
  534. * MSS codecPrivateData.
  535. *
  536. * @exportDoc
  537. */
  538. shaka.extern.MssPrivateData;
  539. /**
  540. * @typedef {{
  541. * height: number,
  542. * positionX: number,
  543. * positionY: number,
  544. * width: number
  545. * }}
  546. *
  547. * @property {number} height
  548. * The thumbnail height in px.
  549. * @property {number} positionX
  550. * The thumbnail left position in px.
  551. * @property {number} positionY
  552. * The thumbnail top position in px.
  553. * @property {number} width
  554. * The thumbnail width in px.
  555. *
  556. * @exportDoc
  557. */
  558. shaka.extern.ThumbnailSprite;