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. * minBufferTime: number,
  17. * sequenceMode: boolean,
  18. * ignoreManifestTimestampsInSegmentsMode: boolean,
  19. * type: string,
  20. * serviceDescription: ?shaka.extern.ServiceDescription,
  21. * nextUrl: ?string,
  22. * periodCount: number,
  23. * gapCount: number,
  24. * isLowLatency: boolean
  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 {number} minBufferTime
  75. * <i>Defaults to 0.</i> <br>
  76. * The minimum number of seconds of content that must be buffered before
  77. * playback can begin. Can be overridden by a higher value from the Player
  78. * configuration.
  79. * @property {boolean} sequenceMode
  80. * If true, we will append the media segments using sequence mode; that is to
  81. * say, ignoring any timestamps inside the media files.
  82. * @property {boolean} ignoreManifestTimestampsInSegmentsMode
  83. * If true, don't adjust the timestamp offset to account for manifest
  84. * segment durations being out of sync with segment durations. In other
  85. * words, assume that there are no gaps in the segments when appending
  86. * to the SourceBuffer, even if the manifest and segment times disagree.
  87. * Only applies when sequenceMode is <code>false</code>, and only for HLS
  88. * streams.
  89. * <i>Defaults to <code>false</code>.</i>
  90. * @property {string} type
  91. * Indicates the type of the manifest. It can be <code>'HLS'</code> or
  92. * <code>'DASH'</code>.
  93. * @property {?shaka.extern.ServiceDescription} serviceDescription
  94. * The service description for the manifest. Used to adapt playbackRate to
  95. * decrease latency.
  96. * @property {?string} nextUrl
  97. * The next url to play.
  98. * @property {number} periodCount
  99. * Number of periods found in a manifest. For DASH, it represents number of
  100. * Period elements in a manifest. If streaming protocol does not implement
  101. * period-like structure, it should be set to 1.
  102. * <i>Defaults to <code>1</code>.</i>
  103. * @property {number} gapCount
  104. * The amount of gaps found in a manifest. For DASH, it represents number of
  105. * discontinuities found between periods. For HLS, it is a number of EXT-X-GAP
  106. * and GAP=YES occurrences. For MSS, it is always set to 0.
  107. * If in src= mode or nothing is loaded, NaN.
  108. * @property {bolean} isLowLatency
  109. * If true, the manifest is Low Latency.
  110. *
  111. * @exportDoc
  112. */
  113. shaka.extern.Manifest;
  114. /**
  115. * @typedef {{
  116. * id: string,
  117. * audioStreams: !Array.<shaka.extern.Stream>,
  118. * videoStreams: !Array.<shaka.extern.Stream>,
  119. * textStreams: !Array.<shaka.extern.Stream>,
  120. * imageStreams: !Array.<shaka.extern.Stream>
  121. * }}
  122. *
  123. * @description Contains the streams from one DASH period.
  124. * For use in {@link shaka.util.PeriodCombiner}.
  125. *
  126. * @property {string} id
  127. * The Period ID.
  128. * @property {!Array.<shaka.extern.Stream>} audioStreams
  129. * The audio streams from one Period.
  130. * @property {!Array.<shaka.extern.Stream>} videoStreams
  131. * The video streams from one Period.
  132. * @property {!Array.<shaka.extern.Stream>} textStreams
  133. * The text streams from one Period.
  134. * @property {!Array.<shaka.extern.Stream>} imageStreams
  135. * The image streams from one Period.
  136. *
  137. * @exportDoc
  138. */
  139. shaka.extern.Period;
  140. /**
  141. * @typedef {{
  142. * targetLatency:?number,
  143. * maxLatency: ?number,
  144. * maxPlaybackRate: ?number,
  145. * minLatency: ?number,
  146. * minPlaybackRate: ?number
  147. * }}
  148. *
  149. * @description
  150. * Maximum and minimum latency and playback rate for a manifest. When max
  151. * latency is reached playbackrate is updated to maxPlaybackRate to decrease
  152. * latency. When min latency is reached playbackrate is updated to
  153. * minPlaybackRate to increase latency.
  154. * More information {@link https://dashif.org/docs/CR-Low-Latency-Live-r8.pdf here}.
  155. *
  156. * @property {?number} targetLatency
  157. * The target latency to aim for.
  158. * @property {?number} maxLatency
  159. * Maximum latency in seconds.
  160. * @property {?number} maxPlaybackRate
  161. * Maximum playback rate.
  162. * @property {?number} minLatency
  163. * Minimum latency in seconds.
  164. * @property {?number} minPlaybackRate
  165. * Minimum playback rate.
  166. *
  167. * @exportDoc
  168. */
  169. shaka.extern.ServiceDescription;
  170. /**
  171. * @typedef {{
  172. * id: number,
  173. * language: string,
  174. * disabledUntilTime: number,
  175. * primary: boolean,
  176. * audio: ?shaka.extern.Stream,
  177. * video: ?shaka.extern.Stream,
  178. * bandwidth: number,
  179. * allowedByApplication: boolean,
  180. * allowedByKeySystem: boolean,
  181. * decodingInfos: !Array.<MediaCapabilitiesDecodingInfo>
  182. * }}
  183. *
  184. * @description
  185. * A Variant describes a combination of an audio and video streams which
  186. * could be played together. It's possible to have a video/audio only
  187. * variant.
  188. *
  189. * @property {number} id
  190. * <i>Required.</i> <br>
  191. * A unique ID among all Variant objects within the same Manifest.
  192. * @property {string} language
  193. * <i>Defaults to '' (i.e., unknown).</i> <br>
  194. * The Variant's language, specified as a language code. <br>
  195. * See {@link https://tools.ietf.org/html/rfc5646} <br>
  196. * See {@link http://www.iso.org/iso/home/standards/language_codes.htm}
  197. * @property {number} disabledUntilTime
  198. * <i>Defaults to 0.</i> <br>
  199. * 0 means the variant is enabled. The Player will set this value to
  200. * "(Date.now() / 1000) + config.streaming.maxDisabledTime" and once this
  201. * maxDisabledTime has passed Player will set the value to 0 in order to
  202. * reenable the variant.
  203. * @property {boolean} primary
  204. * <i>Defaults to false.</i> <br>
  205. * True indicates that the player should use this Variant over others if user
  206. * preferences cannot be met. The player may still use another Variant to
  207. * meet user preferences.
  208. * @property {?shaka.extern.Stream} audio
  209. * The audio stream of the variant.
  210. * @property {?shaka.extern.Stream} video
  211. * The video stream of the variant.
  212. * @property {number} bandwidth
  213. * The variant's required bandwidth in bits per second.
  214. * @property {boolean} allowedByApplication
  215. * <i>Defaults to true.</i><br>
  216. * Set by the Player to indicate whether the variant is allowed to be played
  217. * by the application.
  218. * @property {boolean} allowedByKeySystem
  219. * <i>Defaults to true.</i><br>
  220. * Set by the Player to indicate whether the variant is allowed to be played
  221. * by the key system.
  222. * @property {!Array.<MediaCapabilitiesDecodingInfo>} decodingInfos
  223. * <i>Defaults to [].</i><br>
  224. * Set by StreamUtils to indicate the results from MediaCapabilities
  225. * decodingInfo.
  226. *
  227. * @exportDoc
  228. */
  229. shaka.extern.Variant;
  230. /**
  231. * Creates a SegmentIndex; returns a Promise that resolves after the
  232. * SegmentIndex has been created.
  233. *
  234. * @typedef {function(): !Promise}
  235. * @exportDoc
  236. */
  237. shaka.extern.CreateSegmentIndexFunction;
  238. /**
  239. * @typedef {{
  240. * bitsKey: number,
  241. * blockCipherMode: string,
  242. * cryptoKey: (webCrypto.CryptoKey|undefined),
  243. * fetchKey: (shaka.extern.CreateSegmentIndexFunction|undefined),
  244. * iv: (!Uint8Array|undefined),
  245. * firstMediaSequenceNumber: number
  246. * }}
  247. *
  248. * @description
  249. * AES key and iv info from the manifest.
  250. *
  251. * @property {number} bitsKey
  252. * The number of the bit key (eg: 128, 256).
  253. * @property {string} blockCipherMode
  254. * The block cipher mode of operation. Possible values: 'CTR' or 'CBC'.
  255. * @property {webCrypto.CryptoKey|undefined} cryptoKey
  256. * Web crypto key object of the AES key. If unset, the "fetchKey"
  257. * property should be provided.
  258. * @property {shaka.extern.FetchCryptoKeysFunction|undefined} fetchKey
  259. * A function that fetches the key.
  260. * Should be provided if the "cryptoKey" property is unset.
  261. * Should update this object in-place, to set "cryptoKey".
  262. * @property {(!Uint8Array|undefined)} iv
  263. * The IV in the manifest, if defined. For HLS see HLS RFC 8216 Section 5.2
  264. * for handling undefined IV.
  265. * @property {number} firstMediaSequenceNumber
  266. * The starting Media Sequence Number of the playlist, used when IV is
  267. * undefined.
  268. *
  269. * @exportDoc
  270. */
  271. shaka.extern.aesKey;
  272. /**
  273. * A function that fetches the crypto keys for AES-128.
  274. * Returns a promise that resolves when the keys have been fetched.
  275. *
  276. * @typedef {function(): !Promise}
  277. * @exportDoc
  278. */
  279. shaka.extern.FetchCryptoKeysFunction;
  280. /**
  281. * SegmentIndex minimal API.
  282. * @interface
  283. * @exportDoc
  284. */
  285. shaka.extern.SegmentIndex = class {
  286. /**
  287. * Get number of references.
  288. * @return {number}
  289. * @exportDoc
  290. */
  291. getNumReferences() {}
  292. /**
  293. * Finds the position of the segment for the given time, in seconds, relative
  294. * to the start of the presentation. Returns the position of the segment
  295. * with the largest end time if more than one segment is known for the given
  296. * time.
  297. *
  298. * @param {number} time
  299. * @return {?number} The position of the segment, or null if the position of
  300. * the segment could not be determined.
  301. * @exportDoc
  302. */
  303. find(time) {}
  304. /**
  305. * Gets the SegmentReference for the segment at the given position.
  306. *
  307. * @param {number} position The position of the segment as returned by find().
  308. * @return {shaka.media.SegmentReference} The SegmentReference, or null if
  309. * no such SegmentReference exists.
  310. * @exportDoc
  311. */
  312. get(position) {}
  313. /**
  314. * Gets number of already evicted segments.
  315. * @return {number}
  316. * @exportDoc
  317. */
  318. getNumEvicted() {}
  319. };
  320. /**
  321. * @typedef {{
  322. * id: number,
  323. * originalId: ?string,
  324. * groupId: ?string,
  325. * createSegmentIndex: shaka.extern.CreateSegmentIndexFunction,
  326. * closeSegmentIndex: (function()|undefined),
  327. * segmentIndex: shaka.media.SegmentIndex,
  328. * mimeType: string,
  329. * codecs: string,
  330. * frameRate: (number|undefined),
  331. * pixelAspectRatio: (string|undefined),
  332. * hdr: (string|undefined),
  333. * colorGamut: (string|undefined),
  334. * videoLayout: (string|undefined),
  335. * bandwidth: (number|undefined),
  336. * width: (number|undefined),
  337. * height: (number|undefined),
  338. * kind: (string|undefined),
  339. * encrypted: boolean,
  340. * drmInfos: !Array.<shaka.extern.DrmInfo>,
  341. * keyIds: !Set.<string>,
  342. * language: string,
  343. * originalLanguage: ?string,
  344. * label: ?string,
  345. * type: string,
  346. * primary: boolean,
  347. * trickModeVideo: ?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. * }}
  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. * @property {!Array.<!shaka.extern.DrmInfo>} drmInfos
  434. * <i>Defaults to [] (i.e., no DRM).</i> <br>
  435. * An array of DrmInfo objects which describe DRM schemes are compatible with
  436. * the content.
  437. * @property {!Set.<string>} keyIds
  438. * <i>Defaults to empty (i.e., unencrypted or key ID unknown).</i> <br>
  439. * The stream's key IDs as lowercase hex strings. These key IDs identify the
  440. * encryption keys that the browser (key system) can use to decrypt the
  441. * stream.
  442. * @property {string} language
  443. * The Stream's language, specified as a language code. <br>
  444. * Audio stream's language must be identical to the language of the containing
  445. * Variant.
  446. * @property {?string} originalLanguage
  447. * <i>Optional.</i> <br>
  448. * The original language, if any, that appeared in the manifest.
  449. * @property {?string} label
  450. * The Stream's label, unique text that should describe the audio/text track.
  451. * @property {string} type
  452. * <i>Required.</i> <br>
  453. * Content type (e.g. 'video', 'audio' or 'text', 'image')
  454. * @property {boolean} primary
  455. * <i>Defaults to false.</i> <br>
  456. * True indicates that the player should use this Stream over others if user
  457. * preferences cannot be met. The player may still use another Variant to
  458. * meet user preferences.
  459. * @property {?shaka.extern.Stream} trickModeVideo
  460. * <i>Video streams only.</i> <br>
  461. * An alternate video stream to use for trick mode playback.
  462. * @property {?Array.<string>} emsgSchemeIdUris
  463. * <i>Defaults to empty.</i><br>
  464. * Array of registered emsg box scheme_id_uri that should result in
  465. * Player events.
  466. * @property {!Array.<string>} roles
  467. * The roles of the stream as they appear on the manifest,
  468. * e.g. 'main', 'caption', or 'commentary'.
  469. * @property {?shaka.media.ManifestParser.AccessibilityPurpose}
  470. * accessibilityPurpose
  471. * The DASH accessibility descriptor, if one was provided for this stream.
  472. * @property {boolean} forced
  473. * <i>Defaults to false.</i> <br>
  474. * Whether the stream set was forced
  475. * @property {?number} channelsCount
  476. * The channel count information for the audio stream.
  477. * @property {?number} audioSamplingRate
  478. * Specifies the maximum sampling rate of the content.
  479. * @property {boolean} spatialAudio
  480. * <i>Defaults to false.</i> <br>
  481. * Whether the stream set has spatial audio
  482. * @property {Map.<string, string>} closedCaptions
  483. * A map containing the description of closed captions, with the caption
  484. * channel number (CC1 | CC2 | CC3 | CC4) as the key and the language code
  485. * as the value. If the channel number is not provided by the description,
  486. * we'll set a 0-based index as the key. If the language code is not
  487. * provided by the description we'll set the same value as channel number.
  488. * Example: {'CC1': 'eng'; 'CC3': 'swe'}, or {'1', 'eng'; '2': 'swe'}, etc.
  489. * @property {(string|undefined)} tilesLayout
  490. * <i>Image streams only.</i> <br>
  491. * The value is a grid-item-dimension consisting of two positive decimal
  492. * integers in the format: column-x-row ('4x3'). It describes the arrangement
  493. * of Images in a Grid. The minimum valid LAYOUT is '1x1'.
  494. * @property {(!Array.<shaka.extern.Stream>|!Array.<shaka.extern.StreamDB>|
  495. * undefined)} matchedStreams
  496. * The streams in all periods which match the stream. Used for Dash.
  497. * @property {(shaka.extern.MssPrivateData|undefined)} mssPrivateData
  498. * <i>Microsoft Smooth Streaming only.</i> <br>
  499. * Private MSS data that is necessary to be able to do transmuxing.
  500. * @property {boolean} external
  501. * Indicate if the stream was added externally.
  502. * Eg: external text tracks.
  503. * @property {boolean} fastSwitching
  504. * Indicate if the stream should be used for fast switching.
  505. * @property {!Set.<string>} fullMimeTypes
  506. * A set of full MIME types (e.g. MIME types plus codecs information), that
  507. * represents the types used in each period of the original manifest.
  508. * Meant for being used by compatibility checking, such as with
  509. * MediaSource.isTypeSupported.
  510. *
  511. * @exportDoc
  512. */
  513. shaka.extern.Stream;
  514. /**
  515. * @typedef {{
  516. * duration: number,
  517. * timescale: number,
  518. * codecPrivateData: ?string
  519. * }}
  520. *
  521. * @description
  522. * Private MSS data that is necessary to be able to do transmuxing.
  523. *
  524. * @property {number} duration
  525. * <i>Required.</i> <br>
  526. * MSS Stream duration.
  527. * @property {number} timescale
  528. * <i>Required.</i> <br>
  529. * MSS timescale.
  530. * @property {?string} codecPrivateData
  531. * MSS codecPrivateData.
  532. *
  533. * @exportDoc
  534. */
  535. shaka.extern.MssPrivateData;