Source: externs/shaka/player.js

  1. /**
  2. * @license
  3. * Copyright 2016 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /** @externs */
  18. /**
  19. * @typedef {{
  20. * timestamp: number,
  21. * id: number,
  22. * type: string,
  23. * fromAdaptation: boolean
  24. * }}
  25. *
  26. * @property {number} timestamp
  27. * The timestamp the choice was made, in seconds since 1970
  28. * (i.e. Date.now() / 1000).
  29. * @property {number} id
  30. * The id of the stream that was chosen.
  31. * @property {string} type
  32. * The type of stream chosen ('audio', 'text', or 'video')
  33. * @property {boolean} fromAdaptation
  34. * True if the choice was made by AbrManager for adaptation; false if it
  35. * was made by the application through selectTrack.
  36. * @exportDoc
  37. */
  38. shakaExtern.StreamChoice;
  39. /**
  40. * @typedef {{
  41. * width: number,
  42. * height: number,
  43. * streamBandwidth: number,
  44. *
  45. * decodedFrames: number,
  46. * droppedFrames: number,
  47. * estimatedBandwidth: number,
  48. * playTime: number,
  49. * bufferingTime: number,
  50. *
  51. * switchHistory: !Array.<shakaExtern.StreamChoice>
  52. * }}
  53. *
  54. * @description
  55. * Contains statistics and information about the current state of the player.
  56. * This is meant for applications that want to log quality-of-experience (QoE)
  57. * or other stats. These values will reset when load() is called again.
  58. *
  59. * @property {number} width
  60. * The width of the current video track.
  61. * @property {number} height
  62. * The height of the current video track.
  63. * @property {number} streamBandwidth
  64. * The bandwidth required for the current streams (total, in bit/sec).
  65. *
  66. * @property {number} decodedFrames
  67. * The total number of frames decoded by the Player. This may be NaN if this
  68. * is not supported by the browser.
  69. * @property {number} droppedFrames
  70. * The total number of frames dropped by the Player. This may be NaN if this
  71. * is not supported by the browser.
  72. * @property {number} estimatedBandwidth
  73. * The current estimated network bandwidth (in bit/sec).
  74. * @property {number} playTime
  75. * The total time spent in a playing state in seconds.
  76. * @property {number} bufferingTime
  77. * The total time spent in a buffering state in seconds.
  78. *
  79. * @property {!Array.<shakaExtern.StreamChoice>} switchHistory
  80. * A history of the stream changes.
  81. * @exportDoc
  82. */
  83. shakaExtern.Stats;
  84. /**
  85. * @typedef {{
  86. * id: number,
  87. * active: boolean,
  88. *
  89. * type: string,
  90. * bandwidth: number,
  91. *
  92. * language: string,
  93. * kind: ?string,
  94. * width: ?number,
  95. * height: ?number
  96. * }}
  97. *
  98. * @description
  99. * An object describing a media track. This object should be treated as
  100. * read-only as changing any values does not have any effect. This is the
  101. * public view of the Stream type.
  102. *
  103. * @property {number} id
  104. * The unique ID of the track.
  105. * @property {boolean} active
  106. * If true, this is the track is being streamed (another track may be
  107. * visible/audible in the buffer).
  108. *
  109. * @property {string} type
  110. * The type of track, one of 'audio', 'text', or 'video'.
  111. * @property {number} bandwidth
  112. * The bandwidth required to play the track, in bits/sec.
  113. *
  114. * @property {string} language
  115. * The language of the track, or '' for video tracks. This is the exact
  116. * value provided in the manifest; it may need to be normalized.
  117. * @property {?string} kind
  118. * (only for text tracks) The kind of text track, either 'captions' or
  119. * 'subtitles'.
  120. * @property {?number} width
  121. * (only for video tracks) The width of the track in pixels.
  122. * @property {?number} height
  123. * (only for video tracks) The height of the track in pixels.
  124. * @exportDoc
  125. */
  126. shakaExtern.Track;
  127. /**
  128. * @typedef {{
  129. * minWidth: number,
  130. * maxWidth: number,
  131. * minHeight: number,
  132. * maxHeight: number,
  133. * minPixels: number,
  134. * maxPixels: number,
  135. *
  136. * minAudioBandwidth: number,
  137. * maxAudioBandwidth: number,
  138. * minVideoBandwidth: number,
  139. * maxVideoBandwidth: number
  140. * }}
  141. *
  142. * @description
  143. * An object describing application restrictions on what tracks can play. All
  144. * restrictions must be fulfilled for a track to be playable. If a track does
  145. * not meet the restrictions, it will not appear in the track list and it will
  146. * not be played.
  147. *
  148. * @property {number} minWidth
  149. * The minimum width of a video track, in pixels.
  150. * @property {number} maxWidth
  151. * The maximum width of a video track, in pixels.
  152. * @property {number} minHeight
  153. * The minimum height of a video track, in pixels.
  154. * @property {number} maxHeight
  155. * The maximum height of a video track, in pixels.
  156. * @property {number} minPixels
  157. * The minimum number of total pixels in a video track (i.e. width * height).
  158. * @property {number} maxPixels
  159. * The maximum number of total pixels in a video track (i.e. width * height).
  160. *
  161. * @property {number} minAudioBandwidth
  162. * The minimum bandwidth of an audio track, in bit/sec.
  163. * @property {number} maxAudioBandwidth
  164. * The maximum bandwidth of an audio track, in bit/sec.
  165. * @property {number} minVideoBandwidth
  166. * The minimum bandwidth of a video track, in bit/sec.
  167. * @property {number} maxVideoBandwidth
  168. * The maximum bandwidth of a video track, in bit/sec.
  169. * @exportDoc
  170. */
  171. shakaExtern.Restrictions;
  172. /**
  173. * @typedef {{
  174. * persistentState: boolean
  175. * }}
  176. *
  177. * @property {boolean} persistentState
  178. * Whether this key system supports persistent state.
  179. */
  180. shakaExtern.DrmSupportType;
  181. /**
  182. * @typedef {{
  183. * manifest: !Object.<string, boolean>,
  184. * media: !Object.<string, boolean>,
  185. * drm: !Object.<string, ?shakaExtern.DrmSupportType>
  186. * }}
  187. *
  188. * @description
  189. * An object detailing browser support for various features.
  190. *
  191. * @property {!Object.<string, boolean>} manifest
  192. * A map of supported manifest types.
  193. * The keys are manifest MIME types and file extensions.
  194. * @property {!Object.<string, boolean>} media
  195. * A map of supported media types.
  196. * The keys are media MIME types.
  197. * @property {!Object.<string, ?shakaExtern.DrmSupportType>} drm
  198. * A map of supported key systems.
  199. * The keys are the key system names. The value is null if it is not
  200. * supported. Key systems not probed will not be in this dictionary.
  201. *
  202. * @exportDoc
  203. */
  204. shakaExtern.SupportType;
  205. /**
  206. * @typedef {function(!Element):Array.<shakaExtern.DrmInfo>}
  207. * @see shakaExtern.DashManifestConfiguration
  208. * @exportDoc
  209. */
  210. shakaExtern.DashContentProtectionCallback;
  211. /**
  212. * @typedef {{
  213. * distinctiveIdentifierRequired: boolean,
  214. * persistentStateRequired: boolean,
  215. * videoRobustness: string,
  216. * audioRobustness: string,
  217. * serverCertificate: Uint8Array
  218. * }}
  219. *
  220. * @property {boolean} distinctiveIdentifierRequired
  221. * <i>Defaults to false.</i> <br>
  222. * True if the application requires the key system to support distinctive
  223. * identifiers.
  224. * @property {boolean} persistentStateRequired
  225. * <i>Defaults to false.</i> <br>
  226. * True if the application requires the key system to support persistent
  227. * state, e.g., for persistent license storage.
  228. * @property {string} videoRobustness
  229. * A key-system-specific string that specifies a required security level for
  230. * video.
  231. * <i>Defaults to '', i.e., no specific robustness required.</i> <br>
  232. * @property {string} audioRobustness
  233. * A key-system-specific string that specifies a required security level for
  234. * audio.
  235. * <i>Defaults to '', i.e., no specific robustness required.</i> <br>
  236. * @property {Uint8Array} serverCertificate
  237. * <i>Defaults to null, i.e., certificate will be requested from the license
  238. * server if required.</i> <br>
  239. * A key-system-specific server certificate used to encrypt license requests.
  240. * Its use is optional and is meant as an optimization to avoid a round-trip
  241. * to request a certificate.
  242. *
  243. * @exportDoc
  244. */
  245. shakaExtern.AdvancedDrmConfiguration;
  246. /**
  247. * @typedef {{
  248. * retryParameters: shakaExtern.RetryParameters,
  249. * servers: !Object.<string, string>,
  250. * clearKeys: !Object.<string, string>,
  251. * advanced: Object.<string, shakaExtern.AdvancedDrmConfiguration>
  252. * }}
  253. *
  254. * @property {shakaExtern.RetryParameters} retryParameters
  255. * Retry parameters for license requests.
  256. * @property {!Object.<string, string>} servers
  257. * <i>Required for all but the clear key CDM.</i> <br>
  258. * A dictionary which maps key system IDs to their license servers.
  259. * For example, {'com.widevine.alpha': 'http://example.com/drm'}.
  260. * @property {!Object.<string, string>} clearKeys
  261. * <i>Forces the use of the Clear Key CDM.</i>
  262. * A map of key IDs (hex) to keys (hex).
  263. * @property {Object.<string, shakaExtern.AdvancedDrmConfiguration>} advanced
  264. * <i>Optional.</i> <br>
  265. * A dictionary which maps key system IDs to advanced DRM configuration for
  266. * those key systems.
  267. *
  268. * @exportDoc
  269. */
  270. shakaExtern.DrmConfiguration;
  271. /**
  272. * @typedef {{
  273. * customScheme: shakaExtern.DashContentProtectionCallback,
  274. * clockSyncUri: string
  275. * }}
  276. *
  277. * @property {shakaExtern.DashContentProtectionCallback} customScheme
  278. * If given, invoked by a DASH manifest parser to interpret custom or
  279. * non-standard DRM schemes found in the manifest. The argument is a
  280. * ContentProtection node. Return null if not recognized.
  281. * @property {string} clockSyncUri
  282. * A default clock sync URI to be used with live streams which do not
  283. * contain any clock sync information. The "Date" header from this URI
  284. * will be used to determine the current time.
  285. *
  286. * @exportDoc
  287. */
  288. shakaExtern.DashManifestConfiguration;
  289. /**
  290. * @typedef {{
  291. * retryParameters: shakaExtern.RetryParameters,
  292. * dash: shakaExtern.DashManifestConfiguration
  293. * }}
  294. *
  295. * @property {shakaExtern.RetryParameters} retryParameters
  296. * Retry parameters for manifest requests.
  297. * @property {shakaExtern.DashManifestConfiguration} dash
  298. * Advanced parameters used by the DASH manifest parser.
  299. *
  300. * @exportDoc
  301. */
  302. shakaExtern.ManifestConfiguration;
  303. /**
  304. * @typedef {{
  305. * retryParameters: shakaExtern.RetryParameters,
  306. * rebufferingGoal: number,
  307. * bufferingGoal: number,
  308. * bufferBehind: number,
  309. * ignoreTextStreamFailures: boolean
  310. * }}
  311. *
  312. * @description
  313. * The StreamingEngine's configuration options.
  314. *
  315. * @property {shakaExtern.RetryParameters} retryParameters
  316. * Retry parameters for segment requests.
  317. * @property {number} rebufferingGoal
  318. * The minimum number of seconds of content that the StreamingEngine must
  319. * buffer before it can begin playback or can continue playback after it has
  320. * entered into a buffering state (i.e., after it has depleted one more
  321. * more of its buffers).
  322. * @property {number} bufferingGoal
  323. * The number of seconds of content that the StreamingEngine will attempt to
  324. * buffer ahead of the playhead. This value must be greater than or equal to
  325. * the rebuffering goal.
  326. * @property {number} bufferBehind
  327. * The maximum number of seconds of content that the StreamingEngine will keep
  328. * in buffer behind the playhead when it appends a new media segment.
  329. * The StreamingEngine will evict content to meet this limit.
  330. * @property {boolean} ignoreTextStreamFailures
  331. * If true, the player will ignore text stream failures and proceed to play
  332. * other streams.
  333. * @exportDoc
  334. */
  335. shakaExtern.StreamingConfiguration;
  336. /**
  337. * @typedef {{
  338. * manager: shakaExtern.AbrManager,
  339. * enabled: boolean,
  340. * defaultBandwidthEstimate: number
  341. * }}
  342. *
  343. * @property {shakaExtern.AbrManager} manager
  344. * The AbrManager instance.
  345. * @property {boolean} enabled
  346. * If true, enable adaptation by the current AbrManager. Defaults to true.
  347. * @property {number} defaultBandwidthEstimate
  348. * The default bandwidth estimate to use if there is not enough data, in
  349. * bit/sec.
  350. * @exportDoc
  351. */
  352. shakaExtern.AbrConfiguration;
  353. /**
  354. * @typedef {{
  355. * drm: shakaExtern.DrmConfiguration,
  356. * manifest: shakaExtern.ManifestConfiguration,
  357. * streaming: shakaExtern.StreamingConfiguration,
  358. * abr: shakaExtern.AbrConfiguration,
  359. * preferredAudioLanguage: string,
  360. * preferredTextLanguage: string,
  361. * restrictions: shakaExtern.Restrictions
  362. * }}
  363. *
  364. * @property {shakaExtern.DrmConfiguration} drm
  365. * DRM configuration and settings.
  366. * @property {shakaExtern.ManifestConfiguration} manifest
  367. * Manifest configuration and settings.
  368. * @property {shakaExtern.StreamingConfiguration} streaming
  369. * Streaming configuration and settings.
  370. * @property {shakaExtern.AbrConfiguration} abr
  371. * ABR configuration and settings.
  372. * @property {string} preferredAudioLanguage
  373. * The preferred language to use for audio tracks. If not given it will use
  374. * the 'main' track.
  375. * Changing this during playback will cause the language selection algorithm
  376. * to run again, and may change the active audio track.
  377. * @property {string} preferredTextLanguage
  378. * The preferred language to use for text tracks. If a matching text track
  379. * is found, and the selected audio and text tracks have different languages,
  380. * the text track will be shown.
  381. * Changing this during playback will cause the language selection algorithm
  382. * to run again, and may change the active text track.
  383. * @property {shakaExtern.Restrictions} restrictions
  384. * The application restrictions to apply to the tracks. The track must
  385. * meet all the restrictions to be playable.
  386. * @exportDoc
  387. */
  388. shakaExtern.PlayerConfiguration;