shaka-player 4.12.8 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/AUTHORS +1 -0
  2. package/CONTRIBUTORS +4 -0
  3. package/README.md +22 -21
  4. package/cspell.config.yaml +18 -0
  5. package/dist/controls.css +1 -1
  6. package/dist/controls.css.map +1 -1
  7. package/dist/deps.js +29 -24
  8. package/dist/locales.js +33 -33
  9. package/dist/shaka-player.compiled.d.ts +138 -36
  10. package/dist/shaka-player.compiled.debug.d.ts +138 -36
  11. package/dist/shaka-player.compiled.debug.externs.js +367 -107
  12. package/dist/shaka-player.compiled.debug.js +828 -765
  13. package/dist/shaka-player.compiled.debug.map +4 -4
  14. package/dist/shaka-player.compiled.externs.js +367 -107
  15. package/dist/shaka-player.compiled.js +1451 -1416
  16. package/dist/shaka-player.compiled.map +4 -4
  17. package/dist/shaka-player.ui.d.ts +172 -38
  18. package/dist/shaka-player.ui.debug.d.ts +172 -38
  19. package/dist/shaka-player.ui.debug.externs.js +406 -113
  20. package/dist/shaka-player.ui.debug.js +842 -766
  21. package/dist/shaka-player.ui.debug.map +4 -4
  22. package/dist/shaka-player.ui.externs.js +406 -113
  23. package/dist/shaka-player.ui.js +1670 -1628
  24. package/dist/shaka-player.ui.map +4 -4
  25. package/eslint.config.mjs +343 -0
  26. package/externs/airplay.js +1 -1
  27. package/externs/audiotrack.js +1 -1
  28. package/externs/awesomplete.js +1 -1
  29. package/externs/cast-sdk-v2.js +2 -2
  30. package/externs/cmcd.js +16 -1
  31. package/externs/device_sensor_event.js +1 -1
  32. package/externs/ima.js +8 -8
  33. package/externs/isoboxer.js +31 -31
  34. package/externs/jwk_set.js +1 -1
  35. package/externs/lcevc.js +8 -8
  36. package/externs/mediakeys.js +1 -1
  37. package/externs/mediasession.js +3 -2
  38. package/externs/mediatailor.js +18 -18
  39. package/externs/pictureinpicture.js +41 -1
  40. package/externs/playstation.js +2 -2
  41. package/externs/prefixed_eme.js +1 -1
  42. package/externs/shaka/abortable.js +4 -4
  43. package/externs/shaka/abr_manager.js +1 -1
  44. package/externs/shaka/ads.js +45 -6
  45. package/externs/shaka/cea.js +2 -2
  46. package/externs/shaka/codecs.js +4 -4
  47. package/externs/shaka/drm_info.js +6 -6
  48. package/externs/shaka/error.js +5 -5
  49. package/externs/shaka/manifest.js +51 -56
  50. package/externs/shaka/manifest_parser.js +3 -9
  51. package/externs/shaka/net.js +23 -20
  52. package/externs/shaka/offline.js +37 -37
  53. package/externs/shaka/offline_compat_v1.js +10 -10
  54. package/externs/shaka/offline_compat_v2.js +10 -10
  55. package/externs/shaka/player.js +139 -109
  56. package/externs/shaka/text.js +10 -3
  57. package/externs/shaka/transmuxer.js +1 -1
  58. package/externs/videotrack.js +1 -1
  59. package/lib/abr/ewma.js +1 -1
  60. package/lib/abr/simple_abr_manager.js +70 -22
  61. package/lib/ads/ad_manager.js +43 -18
  62. package/lib/ads/ad_utils.js +160 -58
  63. package/lib/ads/ads_stats.js +1 -1
  64. package/lib/ads/client_side_ad_manager.js +2 -2
  65. package/lib/ads/interstitial_ad.js +16 -11
  66. package/lib/ads/interstitial_ad_manager.js +419 -72
  67. package/lib/ads/interstitial_static_ad.js +299 -0
  68. package/lib/ads/media_tailor_ad.js +1 -0
  69. package/lib/ads/media_tailor_ad_manager.js +37 -36
  70. package/lib/ads/server_side_ad_manager.js +7 -6
  71. package/lib/cast/cast_receiver.js +5 -3
  72. package/lib/cast/cast_sender.js +2 -2
  73. package/lib/cast/cast_utils.js +20 -13
  74. package/lib/cea/cea608_data_channel.js +53 -53
  75. package/lib/cea/cea708_service.js +42 -40
  76. package/lib/cea/cea708_window.js +5 -2
  77. package/lib/cea/cea_decoder.js +5 -7
  78. package/lib/cea/mp4_cea_parser.js +1 -1
  79. package/lib/cea/sei_processor.js +1 -1
  80. package/lib/dash/content_protection.js +62 -192
  81. package/lib/dash/dash_parser.js +119 -119
  82. package/lib/dash/mpd_utils.js +14 -13
  83. package/lib/dash/segment_base.js +5 -5
  84. package/lib/dash/segment_list.js +10 -10
  85. package/lib/dash/segment_template.js +55 -53
  86. package/lib/debug/log.js +2 -2
  87. package/lib/dependencies/all.js +2 -1
  88. package/lib/{media → drm}/drm_engine.js +274 -143
  89. package/lib/{util → drm}/drm_utils.js +20 -11
  90. package/lib/drm/playready.js +233 -0
  91. package/lib/hls/hls_classes.js +14 -14
  92. package/lib/hls/hls_parser.js +257 -196
  93. package/lib/hls/hls_utils.js +14 -14
  94. package/lib/hls/manifest_text_parser.js +10 -10
  95. package/lib/media/adaptation_set.js +6 -5
  96. package/lib/media/adaptation_set_criteria.js +51 -379
  97. package/lib/media/buffering_observer.js +5 -4
  98. package/lib/media/closed_caption_parser.js +2 -2
  99. package/lib/media/content_workarounds.js +2 -2
  100. package/lib/media/example_based_criteria.js +69 -0
  101. package/lib/media/gap_jumping_controller.js +14 -1
  102. package/lib/media/manifest_filterer.js +8 -8
  103. package/lib/media/manifest_parser.js +2 -2
  104. package/lib/media/media_source_capabilities.js +20 -1
  105. package/lib/media/media_source_engine.js +84 -35
  106. package/lib/media/mp4_segment_index_parser.js +5 -5
  107. package/lib/media/playhead.js +2 -8
  108. package/lib/media/playhead_observer.js +1 -1
  109. package/lib/media/preference_based_criteria.js +333 -0
  110. package/lib/media/preload_manager.js +53 -37
  111. package/lib/media/presentation_timeline.js +2 -2
  112. package/lib/media/quality_observer.js +35 -35
  113. package/lib/media/region_observer.js +2 -2
  114. package/lib/media/region_timeline.js +3 -3
  115. package/lib/media/segment_index.js +14 -14
  116. package/lib/media/segment_prefetch.js +17 -13
  117. package/lib/media/segment_reference.js +7 -7
  118. package/lib/media/segment_utils.js +9 -9
  119. package/lib/media/streaming_engine.js +77 -38
  120. package/lib/media/time_ranges_utils.js +1 -1
  121. package/lib/media/video_wrapper.js +1 -1
  122. package/lib/media/webm_segment_index_parser.js +4 -4
  123. package/lib/mss/content_protection.js +17 -222
  124. package/lib/mss/mss_parser.js +23 -24
  125. package/lib/net/data_uri_plugin.js +1 -0
  126. package/lib/net/http_fetch_plugin.js +8 -7
  127. package/lib/net/http_plugin_utils.js +5 -2
  128. package/lib/net/http_xhr_plugin.js +4 -3
  129. package/lib/net/networking_engine.js +72 -17
  130. package/lib/net/networking_utils.js +5 -2
  131. package/lib/offline/download_info.js +5 -1
  132. package/lib/offline/download_manager.js +15 -4
  133. package/lib/offline/download_progress_estimator.js +1 -1
  134. package/lib/offline/indexeddb/base_storage_cell.js +9 -9
  135. package/lib/offline/indexeddb/db_connection.js +1 -1
  136. package/lib/offline/indexeddb/db_operation.js +2 -2
  137. package/lib/offline/indexeddb/eme_session_storage_cell.js +1 -1
  138. package/lib/offline/indexeddb/storage_mechanism.js +1 -1
  139. package/lib/offline/indexeddb/v1_storage_cell.js +3 -3
  140. package/lib/offline/indexeddb/v2_storage_cell.js +2 -2
  141. package/lib/offline/manifest_converter.js +11 -12
  142. package/lib/offline/offline_scheme.js +8 -4
  143. package/lib/offline/session_deleter.js +11 -11
  144. package/lib/offline/storage.js +137 -88
  145. package/lib/offline/storage_muxer.js +8 -8
  146. package/lib/offline/stored_content_utils.js +3 -3
  147. package/lib/offline/stream_bandwidth_estimator.js +1 -1
  148. package/lib/player.js +291 -207
  149. package/lib/polyfill/all.js +1 -1
  150. package/lib/polyfill/media_capabilities.js +5 -5
  151. package/lib/polyfill/patchedmediakeys_apple.js +6 -6
  152. package/lib/polyfill/patchedmediakeys_webkit.js +8 -8
  153. package/lib/polyfill/video_play_promise.js +0 -1
  154. package/lib/text/cue.js +3 -2
  155. package/lib/text/lrc_text_parser.js +1 -1
  156. package/lib/text/mp4_ttml_parser.js +1 -1
  157. package/lib/text/mp4_vtt_parser.js +3 -3
  158. package/lib/text/sbv_text_parser.js +1 -1
  159. package/lib/text/simple_text_displayer.js +37 -10
  160. package/lib/text/ssa_text_parser.js +3 -1
  161. package/lib/text/stub_text_displayer.js +12 -5
  162. package/lib/text/text_engine.js +5 -4
  163. package/lib/text/text_utils.js +4 -4
  164. package/lib/text/ttml_text_parser.js +21 -20
  165. package/lib/text/ui_text_displayer.js +20 -13
  166. package/lib/text/vtt_text_parser.js +10 -10
  167. package/lib/text/web_vtt_generator.js +2 -2
  168. package/lib/transmuxer/aac_transmuxer.js +2 -2
  169. package/lib/transmuxer/ac3_transmuxer.js +2 -2
  170. package/lib/transmuxer/adts.js +2 -0
  171. package/lib/transmuxer/ec3.js +3 -3
  172. package/lib/transmuxer/ec3_transmuxer.js +2 -2
  173. package/lib/transmuxer/h264.js +5 -5
  174. package/lib/transmuxer/h265.js +3 -3
  175. package/lib/transmuxer/mp3_transmuxer.js +2 -2
  176. package/lib/transmuxer/mpeg_audio.js +6 -6
  177. package/lib/transmuxer/mss_transmuxer.js +2 -0
  178. package/lib/transmuxer/transmuxer_engine.js +1 -1
  179. package/lib/transmuxer/ts_transmuxer.js +10 -10
  180. package/lib/util/abortable_operation.js +10 -10
  181. package/lib/util/array_utils.js +6 -6
  182. package/lib/util/cmcd_manager.js +149 -18
  183. package/lib/util/cmsd_manager.js +11 -11
  184. package/lib/util/config_utils.js +3 -3
  185. package/lib/util/content_steering_manager.js +17 -17
  186. package/lib/util/data_view_reader.js +3 -3
  187. package/lib/util/ebml_parser.js +1 -1
  188. package/lib/util/error.js +11 -6
  189. package/lib/util/event_manager.js +1 -1
  190. package/lib/util/exp_golomb.js +1 -1
  191. package/lib/util/fairplay_utils.js +6 -1
  192. package/lib/util/fake_event.js +3 -2
  193. package/lib/util/fake_event_target.js +1 -1
  194. package/lib/util/functional.js +8 -8
  195. package/lib/util/id3_utils.js +1 -1
  196. package/lib/util/iterables.js +6 -6
  197. package/lib/util/language_utils.js +17 -17
  198. package/lib/util/manifest_parser_utils.js +13 -13
  199. package/lib/util/map_utils.js +6 -6
  200. package/lib/util/media_ready_state_utils.js +1 -1
  201. package/lib/util/mime_utils.js +15 -4
  202. package/lib/util/mp4_box_parsers.js +5 -5
  203. package/lib/util/mp4_generator.js +31 -30
  204. package/lib/util/mp4_parser.js +2 -2
  205. package/lib/util/multi_map.js +5 -5
  206. package/lib/util/mutex.js +1 -1
  207. package/lib/util/networking.js +1 -1
  208. package/lib/util/object_utils.js +5 -1
  209. package/lib/util/operation_manager.js +1 -1
  210. package/lib/util/periods.js +24 -24
  211. package/lib/util/platform.js +8 -4
  212. package/lib/util/player_configuration.js +50 -17
  213. package/lib/util/pssh.js +34 -6
  214. package/lib/util/public_promise.js +2 -2
  215. package/lib/util/state_history.js +2 -2
  216. package/lib/util/stream_utils.js +138 -120
  217. package/lib/util/string_utils.js +4 -3
  218. package/lib/util/switch_history.js +2 -2
  219. package/lib/util/tXml.js +22 -17
  220. package/lib/util/text_parser.js +2 -2
  221. package/lib/util/timer.js +1 -1
  222. package/lib/util/ts_parser.js +22 -22
  223. package/lib/util/xml_utils.js +1 -0
  224. package/package.json +7 -4
  225. package/project-words.txt +485 -0
  226. package/shaka-player.uncompiled.js +1 -1
  227. package/third_party/closure-uri/uri.js +2 -2
  228. package/third_party/closure-uri/utils.js +2 -2
  229. package/third_party/language-mapping-list/language-mapping-list.js +1 -1
  230. package/ui/ad_statistics_button.js +9 -5
  231. package/ui/airplay_button.js +1 -0
  232. package/ui/audio_language_selection.js +2 -1
  233. package/ui/context_menu.js +2 -2
  234. package/ui/controls.js +7 -7
  235. package/ui/externs/ui.js +29 -21
  236. package/ui/externs/watermark.js +64 -0
  237. package/ui/fast_forward_button.js +1 -1
  238. package/ui/gl_matrix/matrix_4x4.js +11 -5
  239. package/ui/hidden_fast_forward_button.js +1 -1
  240. package/ui/hidden_seek_button.js +1 -1
  241. package/ui/language_utils.js +27 -26
  242. package/ui/less/buttons.less +2 -2
  243. package/ui/localization.js +21 -21
  244. package/ui/loop_button.js +2 -2
  245. package/ui/overflow_menu.js +2 -2
  246. package/ui/playback_rate_selection.js +1 -1
  247. package/ui/presentation_time.js +4 -1
  248. package/ui/range_element.js +2 -2
  249. package/ui/resolution_selection.js +42 -6
  250. package/ui/rewind_button.js +1 -1
  251. package/ui/seek_bar.js +5 -5
  252. package/ui/statistics_button.js +8 -4
  253. package/ui/text_selection.js +3 -2
  254. package/ui/ui.js +32 -2
  255. package/ui/vr_manager.js +3 -3
  256. package/ui/vr_utils.js +14 -14
  257. package/ui/vr_webgl.js +5 -5
  258. package/ui/watermark.js +313 -0
  259. package/.eslintignore +0 -4
  260. package/.eslintrc.js +0 -310
  261. package/lib/polyfill/patchedmediakeys_nop.js +0 -148
@@ -188,7 +188,7 @@ shaka.cast.CastUtils = class {
188
188
  * @private
189
189
  */
190
190
  static makeUint8Array_(obj) {
191
- return new Uint8Array(/** @type {!Array.<number>} */ (obj['entries']));
191
+ return new Uint8Array(/** @type {!Array<number>} */ (obj['entries']));
192
192
  }
193
193
 
194
194
 
@@ -240,7 +240,7 @@ shaka.cast.CastUtils = class {
240
240
 
241
241
  /**
242
242
  * HTMLMediaElement events that are proxied while casting.
243
- * @const {!Array.<string>}
243
+ * @const {!Array<string>}
244
244
  */
245
245
  shaka.cast.CastUtils.VideoEvents = [
246
246
  'ended',
@@ -258,7 +258,7 @@ shaka.cast.CastUtils.VideoEvents = [
258
258
 
259
259
  /**
260
260
  * HTMLMediaElement attributes that are proxied while casting.
261
- * @const {!Array.<string>}
261
+ * @const {!Array<string>}
262
262
  */
263
263
  shaka.cast.CastUtils.VideoAttributes = [
264
264
  'buffered',
@@ -278,7 +278,7 @@ shaka.cast.CastUtils.VideoAttributes = [
278
278
 
279
279
  /**
280
280
  * HTMLMediaElement attributes that are transferred when casting begins.
281
- * @const {!Array.<string>}
281
+ * @const {!Array<string>}
282
282
  */
283
283
  shaka.cast.CastUtils.VideoInitStateAttributes = [
284
284
  'loop',
@@ -288,7 +288,7 @@ shaka.cast.CastUtils.VideoInitStateAttributes = [
288
288
 
289
289
  /**
290
290
  * HTMLMediaElement methods with no return value that are proxied while casting.
291
- * @const {!Array.<string>}
291
+ * @const {!Array<string>}
292
292
  */
293
293
  shaka.cast.CastUtils.VideoVoidMethods = [
294
294
  'pause',
@@ -300,7 +300,7 @@ shaka.cast.CastUtils.VideoVoidMethods = [
300
300
  * Player getter methods that are proxied while casting.
301
301
  * The key is the method, the value is the frequency of updates.
302
302
  * Frequency 1 translates to every update; frequency 2 to every 2 updates, etc.
303
- * @const {!Object.<string, number>}
303
+ * @const {!Object<string, number>}
304
304
  */
305
305
  shaka.cast.CastUtils.PlayerGetterMethods = {
306
306
  // NOTE: The 'drmInfo' property is not proxied, as it is very large.
@@ -337,12 +337,13 @@ shaka.cast.CastUtils.PlayerGetterMethods = {
337
337
  * Player getter methods with data large enough to be sent in their own update
338
338
  * messages, to reduce the size of each message. The format of this is
339
339
  * identical to PlayerGetterMethods.
340
- * @const {!Object.<string, number>}
340
+ * @const {!Object<string, number>}
341
341
  */
342
342
  shaka.cast.CastUtils.LargePlayerGetterMethods = {
343
343
  // NOTE: The 'getSharedConfiguration' property is not proxied as it would
344
344
  // not be possible to share a reference.
345
345
  'getConfiguration': 4,
346
+ 'getConfigurationForLowLatency': 4,
346
347
  'getStats': 5,
347
348
  'getTextTracks': 2,
348
349
  'getVariantTracks': 2,
@@ -354,7 +355,7 @@ shaka.cast.CastUtils.LargePlayerGetterMethods = {
354
355
  * a livestream.
355
356
  * The key is the method, the value is the frequency of updates.
356
357
  * Frequency 1 translates to every update; frequency 2 to every 2 updates, etc.
357
- * @const {!Object.<string, number>}
358
+ * @const {!Object<string, number>}
358
359
  */
359
360
  shaka.cast.CastUtils.PlayerGetterMethodsThatRequireLive = {
360
361
  'getPlayheadTimeAsDate': 1,
@@ -366,17 +367,22 @@ shaka.cast.CastUtils.PlayerGetterMethodsThatRequireLive = {
366
367
  /**
367
368
  * Player getter and setter methods that are used to transfer state when casting
368
369
  * begins.
369
- * @const {!Array.<!Array.<string>>}
370
+ * @const {!Array<!Array<string>>}
370
371
  */
371
372
  shaka.cast.CastUtils.PlayerInitState = [
372
- ['getConfiguration', 'configure'],
373
+ [
374
+ 'getConfiguration',
375
+ 'configure',
376
+ 'getConfigurationForLowLatency',
377
+ 'configurationForLowLatency',
378
+ ],
373
379
  ];
374
380
 
375
381
 
376
382
  /**
377
383
  * Player getter and setter methods that are used to transfer state after
378
384
  * load() is resolved.
379
- * @const {!Array.<!Array.<string>>}
385
+ * @const {!Array<!Array<string>>}
380
386
  */
381
387
  shaka.cast.CastUtils.PlayerInitAfterLoadState = [
382
388
  ['isTextTrackVisible', 'setTextTrackVisibility'],
@@ -385,7 +391,7 @@ shaka.cast.CastUtils.PlayerInitAfterLoadState = [
385
391
 
386
392
  /**
387
393
  * Player methods with no return value that are proxied while casting.
388
- * @const {!Array.<string>}
394
+ * @const {!Array<string>}
389
395
  */
390
396
  shaka.cast.CastUtils.PlayerVoidMethods = [
391
397
  'addChaptersTrack',
@@ -393,6 +399,7 @@ shaka.cast.CastUtils.PlayerVoidMethods = [
393
399
  'addThumbnailsTrack',
394
400
  'cancelTrickPlay',
395
401
  'configure',
402
+ 'configurationForLowLatency',
396
403
  'getChapters',
397
404
  'getChaptersTracks',
398
405
  'resetConfiguration',
@@ -411,7 +418,7 @@ shaka.cast.CastUtils.PlayerVoidMethods = [
411
418
 
412
419
  /**
413
420
  * Player methods returning a Promise that are proxied while casting.
414
- * @const {!Array.<string>}
421
+ * @const {!Array<string>}
415
422
  */
416
423
  shaka.cast.CastUtils.PlayerPromiseMethods = [
417
424
  'attach',
@@ -53,7 +53,7 @@ shaka.cea.Cea608DataChannel = class {
53
53
  * Points to current buffer.
54
54
  * @private {!shaka.cea.Cea608Memory}
55
55
  */
56
- this.curbuf_ = this.nonDisplayedMemory_;
56
+ this.curBuf_ = this.nonDisplayedMemory_;
57
57
 
58
58
  /**
59
59
  * End time of the previous caption, serves as start time of next caption.
@@ -65,7 +65,7 @@ shaka.cea.Cea608DataChannel = class {
65
65
  * Last control pair, 16 bits representing byte 1 and byte 2
66
66
  * @private {?number}
67
67
  */
68
- this.lastcp_ = null;
68
+ this.lastCp_ = null;
69
69
  }
70
70
 
71
71
  /**
@@ -73,8 +73,8 @@ shaka.cea.Cea608DataChannel = class {
73
73
  */
74
74
  reset() {
75
75
  this.type_ = shaka.cea.Cea608DataChannel.CaptionType.NONE;
76
- this.curbuf_ = this.nonDisplayedMemory_;
77
- this.lastcp_ = null;
76
+ this.curBuf_ = this.nonDisplayedMemory_;
77
+ this.lastCp_ = null;
78
78
  this.displayedMemory_.reset();
79
79
  this.nonDisplayedMemory_.reset();
80
80
  this.text_.reset();
@@ -99,7 +99,7 @@ shaka.cea.Cea608DataChannel = class {
99
99
  * @private
100
100
  */
101
101
  pacToRow_(b1, b2) {
102
- const ccrowtab = [
102
+ const ccRowTab = [
103
103
  11, 11, // 0x00 or 0x01
104
104
  1, 2, // 0x02 -> 0x03
105
105
  3, 4, // 0x04 -> 0x05
@@ -109,7 +109,7 @@ shaka.cea.Cea608DataChannel = class {
109
109
  7, 8, // 0x0C -> 0x0D
110
110
  9, 10, // 0x0E -> 0x0F
111
111
  ];
112
- return ccrowtab[((b1 & 0x07) << 1) | ((b2 >> 5) & 0x01)];
112
+ return ccRowTab[((b1 & 0x07) << 1) | ((b2 >> 5) & 0x01)];
113
113
  }
114
114
 
115
115
  /**
@@ -154,7 +154,7 @@ shaka.cea.Cea608DataChannel = class {
154
154
  }
155
155
 
156
156
  // Execute the PAC.
157
- const buf = this.curbuf_;
157
+ const buf = this.curBuf_;
158
158
 
159
159
  // Move entire scroll window to a new base in rollup mode.
160
160
  if (this.type_ === shaka.cea.Cea608DataChannel.CaptionType.ROLLUP &&
@@ -188,12 +188,12 @@ shaka.cea.Cea608DataChannel = class {
188
188
  */
189
189
  controlMidrow_(b2) {
190
190
  // Clear all pre-existing midrow style attributes.
191
- this.curbuf_.setUnderline(false);
192
- this.curbuf_.setItalics(false);
193
- this.curbuf_.setTextColor(shaka.cea.CeaUtils.DEFAULT_TXT_COLOR);
191
+ this.curBuf_.setUnderline(false);
192
+ this.curBuf_.setItalics(false);
193
+ this.curBuf_.setTextColor(shaka.cea.CeaUtils.DEFAULT_TXT_COLOR);
194
194
 
195
195
  // Mid-row attrs use a space.
196
- this.curbuf_.addChar(
196
+ this.curBuf_.addChar(
197
197
  shaka.cea.Cea608Memory.CharSet.BASIC_NORTH_AMERICAN, ' '.charCodeAt(0));
198
198
 
199
199
  let textColor = shaka.cea.CeaUtils.DEFAULT_TXT_COLOR;
@@ -209,9 +209,9 @@ shaka.cea.Cea608DataChannel = class {
209
209
  italics = true;
210
210
  }
211
211
 
212
- this.curbuf_.setUnderline(underline);
213
- this.curbuf_.setItalics(italics);
214
- this.curbuf_.setTextColor(textColor);
212
+ this.curBuf_.setUnderline(underline);
213
+ this.curBuf_.setItalics(italics);
214
+ this.curBuf_.setTextColor(textColor);
215
215
  }
216
216
 
217
217
  /**
@@ -226,7 +226,7 @@ shaka.cea.Cea608DataChannel = class {
226
226
  // If background provided, last 3 bits of b1 are |0|0|0|. Color is in b2.
227
227
  backgroundColor = shaka.cea.Cea608DataChannel.BG_COLORS[(b2 & 0xe) >> 1];
228
228
  }
229
- this.curbuf_.setBackgroundColor(backgroundColor);
229
+ this.curBuf_.setBackgroundColor(backgroundColor);
230
230
  }
231
231
 
232
232
  /**
@@ -302,7 +302,7 @@ shaka.cea.Cea608DataChannel = class {
302
302
  * @private
303
303
  */
304
304
  controlCr_(pts) {
305
- const buf = this.curbuf_;
305
+ const buf = this.curBuf_;
306
306
  // Only rollup and text mode is affected, but we don't emit text mode.
307
307
  if (this.type_ !== shaka.cea.Cea608DataChannel.CaptionType.ROLLUP) {
308
308
  return null;
@@ -311,13 +311,13 @@ shaka.cea.Cea608DataChannel = class {
311
311
  const parsedClosedCaption = buf.forceEmit(this.prevEndTime_, pts);
312
312
 
313
313
  // Calculate the top of the scroll window.
314
- const toprow = (buf.getRow() - buf.getScrollSize()) + 1;
314
+ const topRow = (buf.getRow() - buf.getScrollSize()) + 1;
315
315
 
316
316
  // Shift up the window one row higher.
317
- buf.moveRows(toprow - 1, toprow, buf.getScrollSize());
317
+ buf.moveRows(topRow - 1, topRow, buf.getScrollSize());
318
318
 
319
319
  // Clear out anything that's outside of our current scroll window.
320
- buf.resetRows(0, toprow - 1);
320
+ buf.resetRows(0, topRow - 1);
321
321
  buf.resetRows(buf.getRow(), shaka.cea.Cea608Memory.CC_ROWS - buf.getRow());
322
322
 
323
323
  // Update the end time so the next caption emits starting at this time.
@@ -335,8 +335,8 @@ shaka.cea.Cea608DataChannel = class {
335
335
  * @private
336
336
  */
337
337
  controlRu_(scrollSize, pts) {
338
- this.curbuf_ = this.displayedMemory_; // Point to displayed memory
339
- const buf = this.curbuf_;
338
+ this.curBuf_ = this.displayedMemory_; // Point to displayed memory
339
+ const buf = this.curBuf_;
340
340
  let parsedClosedCaption = null;
341
341
 
342
342
  // For any type except rollup and text mode, it should be emitted,
@@ -364,7 +364,7 @@ shaka.cea.Cea608DataChannel = class {
364
364
  * @private
365
365
  */
366
366
  controlFon_() {
367
- this.curbuf_.addChar(
367
+ this.curBuf_.addChar(
368
368
  shaka.cea.Cea608Memory.CharSet.BASIC_NORTH_AMERICAN,
369
369
  ' '.charCodeAt(0));
370
370
  }
@@ -399,10 +399,10 @@ shaka.cea.Cea608DataChannel = class {
399
399
  controlRdc_(pts) {
400
400
  this.type_ = shaka.cea.Cea608DataChannel.CaptionType.PAINTON;
401
401
  // Point to displayed memory.
402
- this.curbuf_ = this.displayedMemory_;
402
+ this.curBuf_ = this.displayedMemory_;
403
403
 
404
404
  // No scroll window now.
405
- this.curbuf_.setScrollSize(0);
405
+ this.curBuf_.setScrollSize(0);
406
406
 
407
407
  // The next paint-on caption needs this time as the start time.
408
408
  this.prevEndTime_ = pts;
@@ -451,9 +451,9 @@ shaka.cea.Cea608DataChannel = class {
451
451
  */
452
452
  controlRcl_() {
453
453
  this.type_ = shaka.cea.Cea608DataChannel.CaptionType.POPON;
454
- this.curbuf_ = this.nonDisplayedMemory_;
454
+ this.curBuf_ = this.nonDisplayedMemory_;
455
455
  // No scroll window now
456
- this.curbuf_.setScrollSize(0);
456
+ this.curBuf_.setScrollSize(0);
457
457
  }
458
458
 
459
459
 
@@ -462,7 +462,7 @@ shaka.cea.Cea608DataChannel = class {
462
462
  * @private
463
463
  */
464
464
  controlBs_() {
465
- this.curbuf_.eraseChar();
465
+ this.curBuf_.eraseChar();
466
466
  }
467
467
 
468
468
  /**
@@ -484,7 +484,7 @@ shaka.cea.Cea608DataChannel = class {
484
484
  controlRtd_() {
485
485
  shaka.log.warnOnce('Cea608DataChannel',
486
486
  'CEA-608 text mode entered, but is unsupported');
487
- this.curbuf_ = this.text_;
487
+ this.curBuf_ = this.text_;
488
488
  this.type_ = shaka.cea.Cea608DataChannel.CaptionType.TEXT;
489
489
  }
490
490
 
@@ -494,9 +494,9 @@ shaka.cea.Cea608DataChannel = class {
494
494
  * @param {number} b2 Byte 2.
495
495
  */
496
496
  handleBasicNorthAmericanChar(b1, b2) {
497
- this.curbuf_.addChar(
497
+ this.curBuf_.addChar(
498
498
  shaka.cea.Cea608Memory.CharSet.BASIC_NORTH_AMERICAN, b1);
499
- this.curbuf_.addChar(
499
+ this.curBuf_.addChar(
500
500
  shaka.cea.Cea608Memory.CharSet.BASIC_NORTH_AMERICAN, b2);
501
501
  }
502
502
 
@@ -512,7 +512,7 @@ shaka.cea.Cea608DataChannel = class {
512
512
  shaka.cea.Cea608Memory.CharSet.PORTUGUESE_GERMAN:
513
513
  shaka.cea.Cea608Memory.CharSet.SPANISH_FRENCH;
514
514
 
515
- this.curbuf_.addChar(charSet, b2);
515
+ this.curBuf_.addChar(charSet, b2);
516
516
  }
517
517
 
518
518
  /**
@@ -522,7 +522,7 @@ shaka.cea.Cea608DataChannel = class {
522
522
  * @private
523
523
  */
524
524
  handleOffset_(offset) {
525
- this.curbuf_.setOffset(offset);
525
+ this.curBuf_.setOffset(offset);
526
526
  }
527
527
 
528
528
  /**
@@ -540,13 +540,13 @@ shaka.cea.Cea608DataChannel = class {
540
540
  // seen in broadcast captures. If the very next frame has a duplicate
541
541
  // control code, that duplicate is ignored. Note that this only applies
542
542
  // to the very next frame, and only for one match.
543
- if (this.lastcp_ === ((b1 << 8) | b2)) {
544
- this.lastcp_ = null;
543
+ if (this.lastCp_ === ((b1 << 8) | b2)) {
544
+ this.lastCp_ = null;
545
545
  return null;
546
546
  }
547
547
 
548
548
  // Remember valid control code for checking in next frame!
549
- this.lastcp_ = (b1 << 8) | b2;
549
+ this.lastCp_ = (b1 << 8) | b2;
550
550
 
551
551
  if (this.isPAC_(b1, b2)) {
552
552
  this.controlPac_(b1, b2);
@@ -555,7 +555,7 @@ shaka.cea.Cea608DataChannel = class {
555
555
  } else if (this.isBackgroundAttribute_(b1, b2)) {
556
556
  this.controlBackgroundAttribute_(b1, b2);
557
557
  } else if (this.isSpecialNorthAmericanChar_(b1, b2)) {
558
- this.curbuf_.addChar(
558
+ this.curBuf_.addChar(
559
559
  shaka.cea.Cea608Memory.CharSet.SPECIAL_NORTH_AMERICAN, b2);
560
560
  } else if (this.isExtendedWesternEuropeanChar_(b1, b2)) {
561
561
  this.handleExtendedWesternEuropeanChar_(b1, b2);
@@ -794,21 +794,21 @@ shaka.cea.Cea608DataChannel.Style;
794
794
  /**
795
795
  * CEA closed captions packet.
796
796
  * @typedef {{
797
- * pts: number,
798
- * type: number,
799
- * ccData1: number,
800
- * ccData2: number,
801
- * order: number
802
- * }}
803
- *
804
- * @property {number} pts
805
- * Presentation timestamp (in second) at which this packet was received.
806
- * @property {number} type
807
- * Type of the packet. Either 0 or 1, representing the CEA-608 field.
808
- * @property {number} ccData1 CEA-608 byte 1.
809
- * @property {number} ccData2 CEA-608 byte 2.
810
- * @property {number} order
811
- * A number indicating the order this packet was received in a sequence
812
- * of packets. Used to break ties in a stable sorting algorithm
813
- */
797
+ * pts: number,
798
+ * type: number,
799
+ * ccData1: number,
800
+ * ccData2: number,
801
+ * order: number
802
+ * }}
803
+ *
804
+ * @property {number} pts
805
+ * Presentation timestamp (in second) at which this packet was received.
806
+ * @property {number} type
807
+ * Type of the packet. Either 0 or 1, representing the CEA-608 field.
808
+ * @property {number} ccData1 CEA-608 byte 1.
809
+ * @property {number} ccData2 CEA-608 byte 2.
810
+ * @property {number} order
811
+ * A number indicating the order this packet was received in a sequence
812
+ * of packets. Used to break ties in a stable sorting algorithm
813
+ */
814
814
  shaka.cea.Cea608DataChannel.Cea608Packet;
@@ -4,6 +4,8 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
+ // cspell:ignore PNSTY
8
+
7
9
  goog.provide('shaka.cea.Cea708Service');
8
10
 
9
11
  goog.require('shaka.cea.Cea708Window');
@@ -43,7 +45,7 @@ shaka.cea.Cea708Service = class {
43
45
  /**
44
46
  * Processes a CEA-708 control code.
45
47
  * @param {!shaka.cea.DtvccPacket} dtvccPacket
46
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
48
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
47
49
  * @throws {!shaka.util.Error}
48
50
  */
49
51
  handleCea708ControlCode(dtvccPacket) {
@@ -77,7 +79,7 @@ shaka.cea.Cea708Service = class {
77
79
  this.handleG3_(controlCode & 0xff);
78
80
  }
79
81
 
80
- return null;
82
+ return [];
81
83
  }
82
84
 
83
85
  /**
@@ -156,37 +158,29 @@ shaka.cea.Cea708Service = class {
156
158
  * @param {!shaka.cea.DtvccPacket} dtvccPacket
157
159
  * @param {number} controlCode
158
160
  * @param {number} pts
159
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
161
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
160
162
  * @private
161
163
  */
162
164
  handleC0_(dtvccPacket, controlCode, pts) {
163
165
  // All these commands pertain to the current window, so ensure it exists.
164
166
  if (!this.currentWindow_) {
165
- return null;
167
+ return [];
166
168
  }
167
169
 
168
170
  if (controlCode == 0x18) {
169
171
  const firstByte = dtvccPacket.readByte().value;
170
172
  const secondByte = dtvccPacket.readByte().value;
171
173
 
172
- const isTextBlock = (b) => {
173
- return (b >= 0x20 && b <= 0x7f) || (b >= 0xa0 && b <= 0xff);
174
+ const toHexString = (byteArray) => {
175
+ return byteArray.map((byte) => {
176
+ return ('0' + (byte & 0xFF).toString(16)).slice(-2);
177
+ }).join('');
174
178
  };
175
-
176
- if (isTextBlock(firstByte) && isTextBlock(secondByte)) {
177
- const toHexString = (byteArray) => {
178
- return byteArray.map((byte) => {
179
- return ('0' + (byte & 0xFF).toString(16)).slice(-2);
180
- }).join('');
181
- };
182
- const unicode = toHexString([firstByte, secondByte]);
183
- // Takes a unicode hex string and creates a single character.
184
- const char = String.fromCharCode(parseInt(unicode, 16));
185
- this.currentWindow_.setCharacter(char);
186
- return null;
187
- } else {
188
- dtvccPacket.rewind(2);
189
- }
179
+ const unicode = toHexString([firstByte, secondByte]);
180
+ // Takes a unicode hex string and creates a single character.
181
+ const char = String.fromCharCode(parseInt(unicode, 16));
182
+ this.currentWindow_.setCharacter(char);
183
+ return [];
190
184
  }
191
185
 
192
186
  const window = this.currentWindow_;
@@ -222,7 +216,7 @@ shaka.cea.Cea708Service = class {
222
216
  window.setPenLocation(0, 0);
223
217
  break;
224
218
  }
225
- return parsedClosedCaption;
219
+ return parsedClosedCaption ? [parsedClosedCaption] : [];
226
220
  }
227
221
 
228
222
  /**
@@ -231,7 +225,7 @@ shaka.cea.Cea708Service = class {
231
225
  * @param {!shaka.cea.DtvccPacket} dtvccPacket
232
226
  * @param {number} captionCommand
233
227
  * @param {number} pts in seconds
234
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
228
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
235
229
  * @throws {!shaka.util.Error} a possible out-of-range buffer read.
236
230
  * @private
237
231
  */
@@ -272,7 +266,7 @@ shaka.cea.Cea708Service = class {
272
266
  const windowNum = (captionCommand & 0x0f) - 8;
273
267
  this.defineWindow_(dtvccPacket, windowNum, pts);
274
268
  }
275
- return null;
269
+ return [];
276
270
  }
277
271
 
278
272
  /**
@@ -324,7 +318,7 @@ shaka.cea.Cea708Service = class {
324
318
  /**
325
319
  * Yields each non-null window specified in the 8-bit bitmap.
326
320
  * @param {number} bitmap 8 bits corresponding to each of the 8 windows.
327
- * @return {!Array.<number>}
321
+ * @return {!Array<number>}
328
322
  * @private
329
323
  */
330
324
  getSpecifiedWindowIds_(bitmap) {
@@ -342,22 +336,26 @@ shaka.cea.Cea708Service = class {
342
336
  /**
343
337
  * @param {number} windowsBitmap
344
338
  * @param {number} pts
345
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
339
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
346
340
  * @private
347
341
  */
348
342
  clearWindows_(windowsBitmap, pts) {
349
- let parsedClosedCaption = null;
343
+ const parsedClosedCaptions = [];
350
344
 
351
345
  // Clears windows from the 8 bit bitmap.
352
346
  for (const windowId of this.getSpecifiedWindowIds_(windowsBitmap)) {
353
347
  // If window visible and being cleared, emit buffer and reset start time!
354
348
  const window = this.windows_[windowId];
355
349
  if (window.isVisible()) {
356
- parsedClosedCaption = window.forceEmit(pts, this.serviceNumber_);
350
+ const newParsedClosedCaption =
351
+ window.forceEmit(pts, this.serviceNumber_);
352
+ if (newParsedClosedCaption) {
353
+ parsedClosedCaptions.push(newParsedClosedCaption);
354
+ }
357
355
  }
358
356
  window.resetMemory();
359
357
  }
360
- return parsedClosedCaption;
358
+ return parsedClosedCaptions;
361
359
  }
362
360
 
363
361
  /**
@@ -380,7 +378,7 @@ shaka.cea.Cea708Service = class {
380
378
  /**
381
379
  * @param {number} windowsBitmap
382
380
  * @param {number} pts
383
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
381
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
384
382
  * @private
385
383
  */
386
384
  hideWindows_(windowsBitmap, pts) {
@@ -395,13 +393,13 @@ shaka.cea.Cea708Service = class {
395
393
  }
396
394
  window.hide();
397
395
  }
398
- return parsedClosedCaption;
396
+ return parsedClosedCaption ? [parsedClosedCaption] : [];
399
397
  }
400
398
 
401
399
  /**
402
400
  * @param {number} windowsBitmap
403
401
  * @param {number} pts
404
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
402
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
405
403
  * @private
406
404
  */
407
405
  toggleWindows_(windowsBitmap, pts) {
@@ -420,42 +418,46 @@ shaka.cea.Cea708Service = class {
420
418
 
421
419
  window.toggle();
422
420
  }
423
- return parsedClosedCaption;
421
+ return parsedClosedCaption ? [parsedClosedCaption] : [];
424
422
  }
425
423
 
426
424
  /**
427
425
  * @param {number} windowsBitmap
428
426
  * @param {number} pts
429
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
427
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
430
428
  * @private
431
429
  */
432
430
  deleteWindows_(windowsBitmap, pts) {
433
- let parsedClosedCaption = null;
431
+ const parsedClosedCaptions = [];
434
432
  // Deletes windows from the 8 bit bitmap.
435
433
  for (const windowId of this.getSpecifiedWindowIds_(windowsBitmap)) {
436
434
  const window = this.windows_[windowId];
437
435
  if (window.isVisible()) {
438
436
  // We are turning off the visibility, emit!
439
- parsedClosedCaption = window.forceEmit(pts, this.serviceNumber_);
437
+ const newParsedClosedCaption =
438
+ window.forceEmit(pts, this.serviceNumber_);
439
+ if (newParsedClosedCaption) {
440
+ parsedClosedCaptions.push(newParsedClosedCaption);
441
+ }
440
442
  }
441
443
  // Delete the window from the list of windows
442
444
  this.windows_[windowId] = null;
443
445
  }
444
- return parsedClosedCaption;
446
+ return parsedClosedCaptions;
445
447
  }
446
448
 
447
449
  /**
448
450
  * Emits anything currently present in any of the windows, and then
449
451
  * deletes all windows, cancels all delays, reinitializes the service.
450
452
  * @param {number} pts
451
- * @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
453
+ * @return {!Array<shaka.extern.ICaptionDecoder.ClosedCaption>}
452
454
  * @private
453
455
  */
454
456
  reset_(pts) {
455
457
  const allWindowsBitmap = 0xff; // All windows should be deleted.
456
- const caption = this.deleteWindows_(allWindowsBitmap, pts);
458
+ const captions = this.deleteWindows_(allWindowsBitmap, pts);
457
459
  this.clear();
458
- return caption;
460
+ return captions;
459
461
  }
460
462
 
461
463
  /**
@@ -18,6 +18,7 @@ goog.require('shaka.text.CueRegion');
18
18
  shaka.cea.Cea708Window = class {
19
19
  /**
20
20
  * @param {number} windowNum
21
+ * @param {number} parentService
21
22
  */
22
23
  constructor(windowNum, parentService) {
23
24
  /**
@@ -229,6 +230,7 @@ shaka.cea.Cea708Window = class {
229
230
  }
230
231
 
231
232
  /**
233
+ * @return {boolean}
232
234
  * @private
233
235
  */
234
236
  isPenInBounds_() {
@@ -424,8 +426,9 @@ shaka.cea.Cea708Window = class {
424
426
  // WebVTT's region viewport anchors are technically always in percentages.
425
427
  // However, we don't know the aspect ratio of the video at this point,
426
428
  // which determines how we interpret the horizontal anchor.
427
- // So, we expose the additonal flag to reflect whether these viewport anchor
428
- // values can be used be used as is or should be converted to percentages.
429
+ // So, we expose the additional flag to reflect whether these viewport
430
+ // anchor values can be used as is or should be converted
431
+ // to percentages.
429
432
  region.viewportAnchorUnits = this.relativeToggle_ ?
430
433
  shaka.text.CueRegion.units.PERCENTAGE : shaka.text.CueRegion.units.LINES;
431
434
 
@@ -85,7 +85,7 @@ shaka.cea.CeaDecoder = class {
85
85
 
86
86
  /**
87
87
  * Set used to track available streams.
88
- * @private {!Set.<string>}
88
+ * @private {!Set<string>}
89
89
  */
90
90
  this.streams_ = new Set();
91
91
 
@@ -221,7 +221,7 @@ shaka.cea.CeaDecoder = class {
221
221
  * @override
222
222
  */
223
223
  decode() {
224
- /** @type {!Array.<!shaka.extern.ICaptionDecoder.ClosedCaption>} */
224
+ /** @type {!Array<!shaka.extern.ICaptionDecoder.ClosedCaption>} */
225
225
  const parsedClosedCaptions = [];
226
226
 
227
227
  // In some versions of Chrome, and other browsers, the default sorting
@@ -346,7 +346,7 @@ shaka.cea.CeaDecoder = class {
346
346
 
347
347
  // First 3 bits are service number, next 5 are block size,
348
348
  // representing the number of bytes coming in this block
349
- // (discluding a possible extended service block header byte)
349
+ // (excluding a possible extended service block header byte)
350
350
  let serviceNumber = (serviceBlockHeader & 0xe0) >> 5;
351
351
  const blockSize = serviceBlockHeader & 0x1f;
352
352
 
@@ -371,10 +371,8 @@ shaka.cea.CeaDecoder = class {
371
371
 
372
372
  // Execute this loop `blockSize` times, to decode the control codes.
373
373
  while (dtvccPacket.getPosition() - startPos < blockSize) {
374
- const closedCaption = service.handleCea708ControlCode(dtvccPacket);
375
- if (closedCaption) {
376
- parsedClosedCaptions.push(closedCaption);
377
- }
374
+ const closedCaptions = service.handleCea708ControlCode(dtvccPacket);
375
+ parsedClosedCaptions.push(...closedCaptions);
378
376
  } // position < end of block
379
377
  } // serviceNumber != 0
380
378
  } // hasMoreData