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