shaka-player 4.3.9 → 4.4.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 (321) hide show
  1. package/.github/workflows/build-and-test.yaml +11 -18
  2. package/.github/workflows/compute-incremental-coverage.py +3 -0
  3. package/.github/workflows/release-please.yaml +7 -0
  4. package/.github/workflows/selenium-lab-tests.yaml +45 -10
  5. package/AUTHORS +9 -0
  6. package/CHANGELOG.md +295 -190
  7. package/CONTRIBUTORS +8 -0
  8. package/LICENSE +32 -0
  9. package/README.md +63 -10
  10. package/demo/autoTemplate.txt +40 -5
  11. package/demo/close_button.js +11 -0
  12. package/demo/common/asset.js +13 -1
  13. package/demo/common/assets.js +112 -28
  14. package/demo/common/message_ids.js +25 -1
  15. package/demo/config.js +69 -10
  16. package/demo/customWarning.txt +2 -2
  17. package/demo/index.html +3 -1
  18. package/demo/locales/en.json +26 -2
  19. package/demo/locales/source.json +105 -9
  20. package/demo/main.js +57 -9
  21. package/demo/search.js +3 -1
  22. package/demo/service_worker.js +3 -0
  23. package/dist/controls.css +1 -1
  24. package/dist/controls.css.map +1 -1
  25. package/dist/demo.compiled.debug.js +132 -118
  26. package/dist/demo.compiled.debug.map +3 -3
  27. package/dist/demo.compiled.js +132 -118
  28. package/dist/demo.compiled.map +3 -3
  29. package/dist/deps.js +46 -28
  30. package/dist/locales.js +31 -31
  31. package/dist/receiver.compiled.debug.js +60 -52
  32. package/dist/receiver.compiled.debug.map +3 -3
  33. package/dist/receiver.compiled.js +60 -52
  34. package/dist/receiver.compiled.map +3 -3
  35. package/dist/shaka-player.compiled.d.ts +676 -391
  36. package/dist/shaka-player.compiled.debug.d.ts +676 -391
  37. package/dist/shaka-player.compiled.debug.externs.js +1188 -616
  38. package/dist/shaka-player.compiled.debug.js +1046 -700
  39. package/dist/shaka-player.compiled.debug.map +4 -4
  40. package/dist/shaka-player.compiled.externs.js +1188 -616
  41. package/dist/shaka-player.compiled.js +1094 -933
  42. package/dist/shaka-player.compiled.map +4 -4
  43. package/dist/shaka-player.ui.d.ts +677 -392
  44. package/dist/shaka-player.ui.debug.d.ts +677 -392
  45. package/dist/shaka-player.ui.debug.externs.js +1023 -451
  46. package/dist/shaka-player.ui.debug.js +1101 -738
  47. package/dist/shaka-player.ui.debug.map +4 -4
  48. package/dist/shaka-player.ui.externs.js +1023 -451
  49. package/dist/shaka-player.ui.js +1244 -1071
  50. package/dist/shaka-player.ui.map +4 -4
  51. package/docs/tutorials/ad_monetization.md +15 -1
  52. package/docs/tutorials/application-level-redirects.md +1 -1
  53. package/docs/tutorials/config.md +9 -5
  54. package/docs/tutorials/drm-config.md +61 -0
  55. package/docs/tutorials/fairplay.md +19 -4
  56. package/docs/tutorials/license-server-auth.md +4 -4
  57. package/docs/tutorials/license-wrapping.md +2 -2
  58. package/docs/tutorials/ui-customization.md +7 -3
  59. package/docs/tutorials/ui.md +7 -7
  60. package/docs/tutorials/upgrade.md +3 -0
  61. package/externs/ima.js +123 -2
  62. package/externs/isoboxer.js +217 -0
  63. package/externs/mediakeys.js +18 -0
  64. package/externs/mux.js +1 -105
  65. package/externs/pictureinpicture.js +48 -0
  66. package/externs/shaka/ads.js +61 -1
  67. package/externs/shaka/cea.js +110 -0
  68. package/externs/shaka/codecs.js +32 -0
  69. package/externs/shaka/manifest.js +101 -1
  70. package/externs/shaka/manifest_parser.js +0 -10
  71. package/externs/shaka/net.js +36 -7
  72. package/externs/shaka/offline.js +8 -1
  73. package/externs/shaka/player.js +220 -21
  74. package/externs/shaka/text.js +1 -382
  75. package/externs/shaka/transmuxer.js +59 -0
  76. package/karma.conf.js +15 -0
  77. package/lib/abr/simple_abr_manager.js +6 -3
  78. package/lib/ads/ad_manager.js +60 -2
  79. package/lib/ads/client_side_ad.js +86 -0
  80. package/lib/ads/client_side_ad_manager.js +93 -5
  81. package/lib/ads/server_side_ad.js +86 -0
  82. package/lib/ads/server_side_ad_manager.js +13 -0
  83. package/lib/cast/cast_utils.js +1 -0
  84. package/lib/cea/cea608_data_channel.js +24 -14
  85. package/lib/cea/cea608_memory.js +5 -2
  86. package/lib/cea/cea708_service.js +8 -9
  87. package/lib/cea/cea708_window.js +1 -2
  88. package/lib/cea/cea_decoder.js +23 -6
  89. package/lib/cea/cea_utils.js +25 -2
  90. package/lib/cea/dummy_caption_decoder.js +21 -0
  91. package/lib/cea/dummy_cea_parser.js +1 -3
  92. package/lib/cea/mp4_cea_parser.js +15 -10
  93. package/lib/cea/ts_cea_parser.js +69 -0
  94. package/lib/dash/content_protection.js +32 -2
  95. package/lib/dash/dash_parser.js +93 -31
  96. package/lib/dash/mpd_utils.js +6 -25
  97. package/lib/dash/segment_base.js +12 -14
  98. package/lib/dash/segment_list.js +10 -6
  99. package/lib/dash/segment_template.js +349 -32
  100. package/lib/dependencies/all.js +8 -0
  101. package/lib/hls/hls_classes.js +33 -8
  102. package/lib/hls/hls_parser.js +805 -191
  103. package/lib/hls/manifest_text_parser.js +4 -14
  104. package/lib/media/adaptation_set_criteria.js +43 -3
  105. package/lib/media/closed_caption_parser.js +74 -12
  106. package/lib/media/drm_engine.js +189 -49
  107. package/lib/media/gap_jumping_controller.js +1 -1
  108. package/lib/media/manifest_parser.js +34 -0
  109. package/lib/media/media_source_capabilities.js +10 -0
  110. package/lib/media/media_source_engine.js +475 -231
  111. package/lib/media/playhead.js +1 -1
  112. package/lib/media/presentation_timeline.js +62 -0
  113. package/lib/media/segment_index.js +50 -14
  114. package/lib/media/segment_prefetch.js +277 -0
  115. package/lib/media/segment_reference.js +70 -4
  116. package/lib/media/streaming_engine.js +258 -81
  117. package/lib/media/video_wrapper.js +15 -7
  118. package/lib/mss/content_protection.js +353 -0
  119. package/lib/mss/mss_parser.js +1081 -0
  120. package/lib/net/networking_engine.js +60 -10
  121. package/lib/offline/indexeddb/v1_storage_cell.js +1 -0
  122. package/lib/offline/indexeddb/v2_storage_cell.js +1 -0
  123. package/lib/offline/manifest_converter.js +6 -0
  124. package/lib/offline/storage.js +2 -4
  125. package/lib/player.js +309 -105
  126. package/lib/polyfill/media_capabilities.js +43 -3
  127. package/lib/polyfill/patchedmediakeys_apple.js +5 -0
  128. package/lib/polyfill/patchedmediakeys_nop.js +5 -0
  129. package/lib/polyfill/patchedmediakeys_webkit.js +5 -0
  130. package/lib/text/cue.js +208 -130
  131. package/lib/text/lrc_text_parser.js +2 -2
  132. package/lib/text/mp4_vtt_parser.js +2 -2
  133. package/lib/text/sbv_text_parser.js +1 -1
  134. package/lib/text/simple_text_displayer.js +2 -1
  135. package/lib/text/srt_text_parser.js +9 -1
  136. package/lib/text/ssa_text_parser.js +2 -2
  137. package/lib/text/text_engine.js +3 -21
  138. package/lib/text/text_utils.js +71 -20
  139. package/lib/text/ui_text_displayer.js +14 -14
  140. package/lib/text/vtt_text_parser.js +22 -14
  141. package/lib/transmuxer/aac_transmuxer.js +224 -0
  142. package/lib/transmuxer/ac3.js +142 -0
  143. package/lib/transmuxer/ac3_transmuxer.js +212 -0
  144. package/lib/transmuxer/adts.js +232 -0
  145. package/lib/transmuxer/ec3.js +103 -0
  146. package/lib/transmuxer/ec3_transmuxer.js +212 -0
  147. package/lib/transmuxer/h264.js +324 -0
  148. package/lib/transmuxer/mp3_transmuxer.js +204 -0
  149. package/lib/transmuxer/mpeg_audio.js +196 -0
  150. package/lib/transmuxer/mpeg_ts_transmuxer.js +182 -0
  151. package/lib/transmuxer/mss_transmuxer.js +389 -0
  152. package/lib/{media/transmuxer.js → transmuxer/muxjs_transmuxer.js} +34 -80
  153. package/lib/transmuxer/transmuxer_engine.js +161 -0
  154. package/lib/transmuxer/ts_transmuxer.js +738 -0
  155. package/lib/util/cmcd_manager.js +131 -71
  156. package/lib/util/error.js +62 -26
  157. package/lib/util/exp_golomb.js +220 -0
  158. package/lib/util/fairplay_utils.js +64 -13
  159. package/lib/util/id3_utils.js +56 -3
  160. package/lib/util/language_utils.js +11 -8
  161. package/lib/util/manifest_parser_utils.js +3 -0
  162. package/lib/util/mime_utils.js +44 -7
  163. package/lib/util/mp4_box_parsers.js +233 -5
  164. package/lib/util/mp4_generator.js +1381 -0
  165. package/lib/util/periods.js +40 -34
  166. package/lib/util/platform.js +25 -3
  167. package/lib/util/player_configuration.js +38 -1
  168. package/lib/util/stream_utils.js +138 -27
  169. package/lib/util/text_parser.js +1 -1
  170. package/lib/util/ts_parser.js +470 -47
  171. package/lib/util/xml_utils.js +16 -3
  172. package/maintained-branches.md +2 -2
  173. package/package.json +4 -2
  174. package/roadmap.md +21 -6
  175. package/shaka-player.uncompiled.js +18 -0
  176. package/test/abr/simple_abr_manager_unit.js +32 -4
  177. package/test/ads/ad_manager_unit.js +18 -2
  178. package/test/cast/cast_utils_unit.js +7 -2
  179. package/test/cea/cea608_memory_unit.js +24 -0
  180. package/test/cea/cea_decoder_unit.js +33 -0
  181. package/test/dash/dash_parser_content_protection_unit.js +93 -3
  182. package/test/dash/dash_parser_live_unit.js +56 -13
  183. package/test/dash/dash_parser_manifest_unit.js +70 -2
  184. package/test/dash/dash_parser_segment_base_unit.js +14 -9
  185. package/test/dash/dash_parser_segment_template_unit.js +286 -6
  186. package/test/demo/demo_unit.js +5 -1
  187. package/test/hls/hls_live_unit.js +188 -28
  188. package/test/hls/hls_parser_unit.js +250 -109
  189. package/test/hls/manifest_text_parser_unit.js +18 -13
  190. package/test/media/adaptation_set_criteria_unit.js +46 -14
  191. package/test/media/adaptation_set_unit.js +2 -0
  192. package/test/media/drm_engine_integration.js +11 -8
  193. package/test/media/drm_engine_unit.js +220 -7
  194. package/test/media/media_source_engine_integration.js +122 -38
  195. package/test/media/media_source_engine_unit.js +133 -153
  196. package/test/media/playhead_unit.js +3 -0
  197. package/test/media/presentation_timeline_unit.js +51 -0
  198. package/test/media/segment_index_unit.js +52 -0
  199. package/test/media/segment_prefetch_unit.js +243 -0
  200. package/test/media/streaming_engine_integration.js +9 -3
  201. package/test/media/streaming_engine_unit.js +440 -59
  202. package/test/mss/mss_parser_content_protection_unit.js +49 -0
  203. package/test/mss/mss_parser_unit.js +472 -0
  204. package/test/mss/mss_player_integration.js +123 -0
  205. package/test/offline/manifest_convert_unit.js +9 -0
  206. package/test/offline/storage_integration.js +6 -1
  207. package/test/player_integration.js +4 -1
  208. package/test/player_unit.js +386 -133
  209. package/test/polyfill/media_capabilities_unit.js +18 -0
  210. package/test/test/assets/hls-raw-aac/fileSequence0.aac +0 -0
  211. package/test/test/assets/hls-raw-aac/fileSequence1.aac +0 -0
  212. package/test/test/assets/hls-raw-aac/fileSequence2.aac +0 -0
  213. package/test/test/assets/hls-raw-aac/fileSequence3.aac +0 -0
  214. package/test/test/assets/hls-raw-aac/manifest.m3u8 +4 -0
  215. package/test/test/assets/hls-raw-aac/stream.m4a.m3u8 +14 -0
  216. package/test/test/assets/hls-raw-ac3/fileSequence0.ac3 +0 -0
  217. package/test/test/assets/hls-raw-ac3/fileSequence1.ac3 +0 -0
  218. package/test/test/assets/hls-raw-ac3/fileSequence2.ac3 +0 -0
  219. package/test/test/assets/hls-raw-ac3/fileSequence3.ac3 +0 -0
  220. package/test/test/assets/hls-raw-ac3/fileSequence4.ac3 +0 -0
  221. package/test/test/assets/hls-raw-ac3/fileSequence5.ac3 +0 -0
  222. package/test/test/assets/hls-raw-ac3/fileSequence6.ac3 +0 -0
  223. package/test/test/assets/hls-raw-ac3/fileSequence7.ac3 +0 -0
  224. package/test/test/assets/hls-raw-ac3/prog_index.m3u8 +31 -0
  225. package/test/test/assets/hls-raw-ec3/fileSequence0.ec3 +0 -0
  226. package/test/test/assets/hls-raw-ec3/fileSequence1.ec3 +0 -0
  227. package/test/test/assets/hls-raw-ec3/fileSequence2.ec3 +0 -0
  228. package/test/test/assets/hls-raw-ec3/fileSequence3.ec3 +0 -0
  229. package/test/test/assets/hls-raw-ec3/fileSequence4.ec3 +0 -0
  230. package/test/test/assets/hls-raw-ec3/fileSequence5.ec3 +0 -0
  231. package/test/test/assets/hls-raw-ec3/fileSequence6.ec3 +0 -0
  232. package/test/test/assets/hls-raw-ec3/fileSequence7.ec3 +0 -0
  233. package/test/test/assets/hls-raw-ec3/prog_index.m3u8 +31 -0
  234. package/test/test/assets/hls-raw-mp3/chunklist_w905519204.m3u8 +13 -0
  235. package/test/test/assets/hls-raw-mp3/media_w905519204_0.mp3 +0 -0
  236. package/test/test/assets/hls-raw-mp3/media_w905519204_1.mp3 +0 -0
  237. package/test/test/assets/hls-raw-mp3/media_w905519204_2.mp3 +0 -0
  238. package/test/test/assets/hls-raw-mp3/media_w905519204_3.mp3 +0 -0
  239. package/test/test/assets/hls-raw-mp3/playlist.m3u8 +4 -0
  240. package/test/test/assets/hls-ts-aac/playlist.m3u8 +23 -0
  241. package/test/test/assets/hls-ts-aac/segment_0.ts +0 -0
  242. package/test/test/assets/hls-ts-aac/segment_1.ts +0 -0
  243. package/test/test/assets/hls-ts-aac/segment_2.ts +0 -0
  244. package/test/test/assets/hls-ts-aac/segment_3.ts +0 -0
  245. package/test/test/assets/hls-ts-aac/segment_4.ts +0 -0
  246. package/test/test/assets/hls-ts-aac/segment_5.ts +0 -0
  247. package/test/test/assets/hls-ts-aac/segment_6.ts +0 -0
  248. package/test/test/assets/hls-ts-aac/segment_7.ts +0 -0
  249. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0000.ts +0 -0
  250. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0001.ts +0 -0
  251. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0002.ts +0 -0
  252. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0003.ts +0 -0
  253. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0004.ts +0 -0
  254. package/test/test/assets/hls-ts-ac3/ChID_voices_6ch_640kbps_dd_sub_0005.ts +0 -0
  255. package/test/test/assets/hls-ts-ac3/prog_index.m3u8 +19 -0
  256. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0000.ts +0 -0
  257. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0001.ts +0 -0
  258. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0002.ts +0 -0
  259. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0003.ts +0 -0
  260. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0004.ts +0 -0
  261. package/test/test/assets/hls-ts-ec3/ChID_voices_6ch_256kbps_ddp_sub_0005.ts +0 -0
  262. package/test/test/assets/hls-ts-ec3/prog_index.m3u8 +19 -0
  263. package/test/test/assets/hls-ts-h264/fileSequence0.ts +0 -0
  264. package/test/test/assets/hls-ts-h264/fileSequence1.ts +0 -0
  265. package/test/test/assets/hls-ts-h264/fileSequence2.ts +0 -0
  266. package/test/test/assets/hls-ts-h264/fileSequence3.ts +0 -0
  267. package/test/test/assets/hls-ts-h264/fileSequence4.ts +0 -0
  268. package/test/test/assets/hls-ts-h264/fileSequence5.ts +0 -0
  269. package/test/test/assets/hls-ts-h264/prog_index.m3u8 +25 -0
  270. package/test/test/assets/hls-ts-mp3/manifest.m3u8 +13 -0
  271. package/test/test/assets/hls-ts-mp3/media_w239891843_0.ts +0 -0
  272. package/test/test/assets/hls-ts-mp3/media_w239891843_1.ts +0 -0
  273. package/test/test/assets/hls-ts-mp3/media_w239891843_2.ts +0 -0
  274. package/test/test/assets/hls-ts-mp3/media_w239891843_3.ts +0 -0
  275. package/test/test/assets/hls-ts-muxed-aac-h264/chunk.m3u8 +17 -0
  276. package/test/test/assets/hls-ts-muxed-aac-h264/n_0_0_0.ts +0 -0
  277. package/test/test/assets/hls-ts-muxed-aac-h264/n_1_0_0.ts +0 -0
  278. package/test/test/assets/hls-ts-muxed-aac-h264/n_2_0_0.ts +0 -0
  279. package/test/test/assets/hls-ts-muxed-aac-h264/n_3_0_0.ts +0 -0
  280. package/test/test/assets/hls-ts-muxed-aac-h264/n_4_0_0.ts +0 -0
  281. package/test/test/assets/hls-ts-muxed-aac-h264/n_5_0_0.ts +0 -0
  282. package/test/test/assets/hls-ts-muxed-aac-h264/playlist.m3u8 +4 -0
  283. package/test/test/boot.js +7 -2
  284. package/test/test/util/fake_ad.js +99 -0
  285. package/test/test/util/fake_ad_manager.js +7 -1
  286. package/test/test/util/fake_networking_engine.js +41 -14
  287. package/test/test/util/fake_segment_prefetch.js +81 -0
  288. package/test/test/util/manifest_generator.js +19 -5
  289. package/test/test/util/mss_parser_util.js +115 -0
  290. package/test/test/util/offline_utils.js +1 -0
  291. package/test/test/util/simple_fakes.js +12 -3
  292. package/test/test/util/streaming_engine_util.js +14 -4
  293. package/test/test/util/ttml_utils.js +2 -2
  294. package/test/test/util/ui_utils.js +5 -1
  295. package/test/text/cue_integration.js +1 -1
  296. package/test/text/srt_text_parser_unit.js +78 -0
  297. package/test/text/text_engine_unit.js +17 -8
  298. package/test/text/ui_text_displayer_unit.js +4 -4
  299. package/test/text/vtt_text_parser_unit.js +59 -40
  300. package/test/text/web_vtt_generator_unit.js +9 -3
  301. package/test/{media/transmuxer_integration.js → transmuxer/muxjs_transmuxer_integration.js} +30 -33
  302. package/test/transmuxer/transmuxer_engine_integration.js +60 -0
  303. package/test/transmuxer/transmuxer_integration.js +296 -0
  304. package/test/util/cmcd_manager_unit.js +162 -13
  305. package/test/util/language_utils_unit.js +9 -2
  306. package/test/util/mp4_box_parsers_unit.js +39 -4
  307. package/test/util/periods_unit.js +34 -26
  308. package/test/util/stream_utils_unit.js +60 -107
  309. package/ui/controls.js +19 -1
  310. package/ui/controls.less +1 -0
  311. package/ui/externs/ui.js +13 -3
  312. package/ui/language_utils.js +15 -0
  313. package/ui/less/thumbnails.less +26 -0
  314. package/ui/locales/oc.json +42 -0
  315. package/ui/pip_button.js +83 -2
  316. package/ui/range_element.js +15 -0
  317. package/ui/resolution_selection.js +9 -2
  318. package/ui/seek_bar.js +230 -1
  319. package/ui/ui.js +5 -0
  320. package/lib/cea/i_caption_decoder.js +0 -51
  321. package/lib/cea/i_cea_parser.js +0 -68
@@ -8,7 +8,7 @@ goog.provide('shaka.util.CmcdManager');
8
8
 
9
9
  goog.require('goog.Uri');
10
10
  goog.require('shaka.log');
11
-
11
+ goog.require('shaka.net.NetworkingEngine');
12
12
 
13
13
  /**
14
14
  * @summary
@@ -57,6 +57,16 @@ shaka.util.CmcdManager = class {
57
57
  this.starved_ = false;
58
58
  }
59
59
 
60
+ /**
61
+ * Called by the Player to provide an updated configuration any time it
62
+ * changes.
63
+ *
64
+ * @param {shaka.extern.CmcdConfiguration} config
65
+ */
66
+ configure(config) {
67
+ this.config_ = config;
68
+ }
69
+
60
70
  /**
61
71
  * Set the buffering state
62
72
  *
@@ -74,21 +84,67 @@ shaka.util.CmcdManager = class {
74
84
  this.buffering_ = buffering;
75
85
  }
76
86
 
87
+ /**
88
+ * Apply CMCD data to a request.
89
+ *
90
+ * @param {!shaka.net.NetworkingEngine.RequestType} type
91
+ * The request type
92
+ * @param {!shaka.extern.Request} request
93
+ * The request to apply CMCD data to
94
+ * @param {shaka.extern.RequestContext=} context
95
+ * The request context
96
+ */
97
+ applyData(type, request, context = {}) {
98
+ if (!this.config_.enabled) {
99
+ return;
100
+ }
101
+
102
+ if (request.method === 'HEAD') {
103
+ this.apply_(request);
104
+ return;
105
+ }
106
+
107
+ const RequestType = shaka.net.NetworkingEngine.RequestType;
108
+ const ObjectType = shaka.util.CmcdManager.ObjectType;
109
+
110
+ switch (type) {
111
+ case RequestType.MANIFEST:
112
+ this.applyManifestData(request, context);
113
+ break;
114
+
115
+ case RequestType.SEGMENT:
116
+ this.applySegmentData(request, context);
117
+ break;
118
+
119
+ case RequestType.LICENSE:
120
+ case RequestType.SERVER_CERTIFICATE:
121
+ case RequestType.KEY:
122
+ this.apply_(request, {ot: ObjectType.KEY});
123
+ break;
124
+
125
+ case RequestType.TIMING:
126
+ this.apply_(request, {ot: ObjectType.OTHER});
127
+ break;
128
+ }
129
+ }
130
+
77
131
  /**
78
132
  * Apply CMCD data to a manifest request.
79
133
  *
80
134
  * @param {!shaka.extern.Request} request
81
135
  * The request to apply CMCD data to
82
- * @param {shaka.util.CmcdManager.ManifestInfo} manifestInfo
83
- * The manifest format
136
+ * @param {shaka.extern.RequestContext} context
137
+ * The request context
84
138
  */
85
- applyManifestData(request, manifestInfo) {
139
+ applyManifestData(request, context) {
86
140
  try {
87
141
  if (!this.config_.enabled) {
88
142
  return;
89
143
  }
90
144
 
91
- this.sf_ = manifestInfo.format;
145
+ if (context.type) {
146
+ this.sf_ = this.getStreamFormat_(context.type);
147
+ }
92
148
 
93
149
  this.apply_(request, {
94
150
  ot: shaka.util.CmcdManager.ObjectType.MANIFEST,
@@ -104,33 +160,44 @@ shaka.util.CmcdManager = class {
104
160
  * Apply CMCD data to a segment request
105
161
  *
106
162
  * @param {!shaka.extern.Request} request
107
- * @param {shaka.util.CmcdManager.SegmentInfo} segmentInfo
163
+ * @param {shaka.extern.RequestContext} context
164
+ * The request context
108
165
  */
109
- applySegmentData(request, segmentInfo) {
166
+ applySegmentData(request, context) {
110
167
  try {
111
168
  if (!this.config_.enabled) {
112
169
  return;
113
170
  }
114
171
 
172
+ const segment = context.segment;
173
+
174
+ let duration = 0;
175
+ if (segment) {
176
+ duration = segment.endTime - segment.startTime;
177
+ }
178
+
115
179
  const data = {
116
- d: segmentInfo.duration * 1000,
180
+ d: duration * 1000,
117
181
  st: this.getStreamType_(),
118
182
  };
119
183
 
120
- data.ot = this.getObjectType_(segmentInfo);
184
+ data.ot = this.getObjectType_(context);
121
185
 
122
186
  const ObjectType = shaka.util.CmcdManager.ObjectType;
123
187
  const isMedia = data.ot === ObjectType.VIDEO ||
124
- data.ot === ObjectType.AUDIO ||
125
- data.ot === ObjectType.MUXED ||
126
- data.ot === ObjectType.TIMED_TEXT;
127
-
128
- if (isMedia) {
129
- data.bl = this.getBufferLength_(segmentInfo.type);
130
- }
131
-
132
- if (segmentInfo.bandwidth) {
133
- data.br = segmentInfo.bandwidth / 1000;
188
+ data.ot === ObjectType.AUDIO ||
189
+ data.ot === ObjectType.MUXED ||
190
+ data.ot === ObjectType.TIMED_TEXT;
191
+
192
+ const stream = context.stream;
193
+ if (stream) {
194
+ if (isMedia) {
195
+ data.bl = this.getBufferLength_(stream.type);
196
+ }
197
+
198
+ if (stream.bandwidth) {
199
+ data.br = stream.bandwidth / 1000;
200
+ }
134
201
  }
135
202
 
136
203
  if (isMedia && data.ot !== ObjectType.TIMED_TEXT) {
@@ -256,7 +323,7 @@ shaka.util.CmcdManager = class {
256
323
  data.pr = this.playerInterface_.getPlaybackRate();
257
324
 
258
325
  const isVideo = data.ot === shaka.util.CmcdManager.ObjectType.VIDEO ||
259
- data.ot === shaka.util.CmcdManager.ObjectType.MUXED;
326
+ data.ot === shaka.util.CmcdManager.ObjectType.MUXED;
260
327
 
261
328
  if (this.starved_ && isVideo) {
262
329
  data.bs = true;
@@ -292,18 +359,26 @@ shaka.util.CmcdManager = class {
292
359
  /**
293
360
  * The CMCD object type.
294
361
  *
295
- * @param {shaka.util.CmcdManager.SegmentInfo} segmentInfo
362
+ * @param {shaka.extern.RequestContext} context
363
+ * The request context
296
364
  * @private
297
365
  */
298
- getObjectType_(segmentInfo) {
299
- const type = segmentInfo.type;
300
-
301
- if (segmentInfo.init) {
366
+ getObjectType_(context) {
367
+ if (context.type ===
368
+ shaka.net.NetworkingEngine.AdvancedRequestType.INIT_SEGMENT) {
302
369
  return shaka.util.CmcdManager.ObjectType.INIT;
303
370
  }
304
371
 
372
+ const stream = context.stream;
373
+
374
+ if (!stream) {
375
+ return undefined;
376
+ }
377
+
378
+ const type = stream.type;
379
+
305
380
  if (type == 'video') {
306
- if (segmentInfo.codecs.includes(',')) {
381
+ if (stream.codecs && stream.codecs.includes(',')) {
307
382
  return shaka.util.CmcdManager.ObjectType.MUXED;
308
383
  }
309
384
  return shaka.util.CmcdManager.ObjectType.VIDEO;
@@ -314,7 +389,7 @@ shaka.util.CmcdManager = class {
314
389
  }
315
390
 
316
391
  if (type == 'text') {
317
- if (segmentInfo.mimeType === 'application/mp4') {
392
+ if (stream.mimeType === 'application/mp4') {
318
393
  return shaka.util.CmcdManager.ObjectType.TIMED_TEXT;
319
394
  }
320
395
  return shaka.util.CmcdManager.ObjectType.CAPTION;
@@ -368,6 +443,32 @@ shaka.util.CmcdManager = class {
368
443
  return (range.end - start) * 1000;
369
444
  }
370
445
 
446
+ /**
447
+ * Get the stream format
448
+ *
449
+ * @param {shaka.net.NetworkingEngine.AdvancedRequestType} type
450
+ * The request's advanced type
451
+ * @return {(shaka.util.CmcdManager.StreamingFormat|undefined)}
452
+ * @private
453
+ */
454
+ getStreamFormat_(type) {
455
+ const AdvancedRequestType = shaka.net.NetworkingEngine.AdvancedRequestType;
456
+
457
+ switch (type) {
458
+ case AdvancedRequestType.MPD:
459
+ return shaka.util.CmcdManager.StreamingFormat.DASH;
460
+
461
+ case AdvancedRequestType.MASTER_PLAYLIST:
462
+ case AdvancedRequestType.MEDIA_PLAYLIST:
463
+ return shaka.util.CmcdManager.StreamingFormat.HLS;
464
+
465
+ case AdvancedRequestType.MSS:
466
+ return shaka.util.CmcdManager.StreamingFormat.SMOOTH;
467
+ }
468
+
469
+ return undefined;
470
+ }
471
+
371
472
  /**
372
473
  * Get the stream type
373
474
  *
@@ -566,8 +667,8 @@ shaka.util.CmcdManager = class {
566
667
  * getBandwidthEstimate: function():number,
567
668
  * getBufferedInfo: function():shaka.extern.BufferedInfo,
568
669
  * getCurrentTime: function():number,
569
- * getVariantTracks: function():Array.<shaka.extern.Track>,
570
670
  * getPlaybackRate: function():number,
671
+ * getVariantTracks: function():Array.<shaka.extern.Track>,
571
672
  * isLive: function():boolean
572
673
  * }}
573
674
  *
@@ -577,57 +678,16 @@ shaka.util.CmcdManager = class {
577
678
  * Get information about what the player has buffered.
578
679
  * @property {function():number} getCurrentTime
579
680
  * Get the current time
580
- * @property {function():Array.<shaka.extern.Track>} getVariantTracks
581
- * Get the variant tracks
582
681
  * @property {function():number} getPlaybackRate
583
682
  * Get the playback rate
683
+ * @property {function():Array.<shaka.extern.Track>} getVariantTracks
684
+ * Get the variant tracks
584
685
  * @property {function():boolean} isLive
585
686
  * Get if the player is playing live content.
586
687
  */
587
688
  shaka.util.CmcdManager.PlayerInterface;
588
689
 
589
690
 
590
- /**
591
- * @typedef {{
592
- * type: string,
593
- * init: boolean,
594
- * duration: number,
595
- * mimeType: string,
596
- * codecs: string,
597
- * bandwidth: (number|undefined)
598
- * }}
599
- *
600
- * @property {string} type
601
- * The media type
602
- * @property {boolean} init
603
- * Flag indicating whether the segment is an init segment
604
- * @property {number} duration
605
- * The duration of the segment in seconds
606
- * @property {string} mimeType
607
- * The segment's mime type
608
- * @property {string} codecs
609
- * The segment's codecs
610
- * @property {(number|undefined)} bandwidth
611
- * The segment's variation bandwidth
612
- *
613
- * @export
614
- */
615
- shaka.util.CmcdManager.SegmentInfo;
616
-
617
-
618
- /**
619
- * @typedef {{
620
- * format: shaka.util.CmcdManager.StreamingFormat
621
- * }}
622
- *
623
- * @property {shaka.util.CmcdManager.StreamingFormat} format
624
- * The manifest's stream format
625
- *
626
- * @export
627
- */
628
- shaka.util.CmcdManager.ManifestInfo;
629
-
630
-
631
691
  /**
632
692
  * @enum {string}
633
693
  */
package/lib/util/error.js CHANGED
@@ -88,20 +88,19 @@ shaka.util.Error = class {
88
88
  */
89
89
  this.message = 'Shaka Error ' + categoryName + '.' + codeName +
90
90
  ' (' + this.data.toString() + ')';
91
+ }
91
92
 
92
- if (shaka.util.Error.createStack) {
93
- try {
94
- throw new Error(this.message);
95
- } catch (e) {
96
- /**
97
- * A stack-trace showing where the error occurred.
98
- * <i>(Only available in uncompiled mode.)</i>
99
- *
100
- * @const {string}
101
- * @exportDoc
102
- */
103
- this.stack = e.stack;
104
- }
93
+ if (shaka.util.Error.createStack) {
94
+ try {
95
+ throw new Error(this.message || 'Shaka Error');
96
+ } catch (e) {
97
+ /**
98
+ * A stack-trace showing where the error occurred.
99
+ *
100
+ * @const {string}
101
+ * @exportDoc
102
+ */
103
+ this.stack = e.stack;
105
104
  }
106
105
  }
107
106
  }
@@ -117,18 +116,15 @@ shaka.util.Error = class {
117
116
  };
118
117
 
119
118
 
120
- if (goog.DEBUG) {
121
- /**
122
- * If true, create a stack trace in Error objects.
123
- *
124
- * Only available in uncompiled mode, and disabled in tests to avoid issues
125
- * with karma-jasmine. See comments in test/test/boot.js for details.
126
- *
127
- * @type {boolean}
128
- */
129
- shaka.util.Error.createStack = true;
130
- }
131
-
119
+ /**
120
+ * If true, create a stack trace in Error objects.
121
+ *
122
+ * Disabled in tests to avoid issues with karma-jasmine.
123
+ * See comments in test/test/boot.js for details.
124
+ *
125
+ * @type {boolean}
126
+ */
127
+ shaka.util.Error.createStack = true;
132
128
 
133
129
  /**
134
130
  * @enum {number}
@@ -462,6 +458,7 @@ shaka.util.Error.Code = {
462
458
  /**
463
459
  * A MediaSource operation threw an exception.
464
460
  * <br> error.data[0] is the exception that was thrown.
461
+ * <br> error.data[1] is the error object from the video element.
465
462
  */
466
463
  'MEDIA_SOURCE_OPERATION_THREW': 3015,
467
464
 
@@ -496,6 +493,22 @@ shaka.util.Error.Code = {
496
493
  */
497
494
  'CONTENT_TRANSFORMATION_FAILED': 3019,
498
495
 
496
+ /**
497
+ * Important data is missing to be able to do the transmuxing of MSS.
498
+ */
499
+ 'MSS_MISSING_DATA_FOR_TRANSMUXING': 3020,
500
+
501
+ /**
502
+ * MSS transmuing failed for unknown codec.
503
+ * <br> error.data[0] is a unknown codec.
504
+ */
505
+ 'MSS_TRANSMUXING_CODEC_UNKNOWN': 3021,
506
+
507
+ /**
508
+ * MSS transmuing failed for unknown reason.
509
+ */
510
+ 'MSS_TRANSMUXING_FAILED': 3022,
511
+
499
512
 
500
513
  /**
501
514
  * The Player was unable to guess the manifest type based on file extension
@@ -724,6 +737,17 @@ shaka.util.Error.Code = {
724
737
  */
725
738
  'CANNOT_ADD_EXTERNAL_THUMBNAILS_TO_LIVE_STREAM': 4045,
726
739
 
740
+ /**
741
+ * The MSS Manifest contained invalid XML markup.
742
+ * <br> error.data[0] is the URI associated with the XML.
743
+ */
744
+ 'MSS_INVALID_XML': 4046,
745
+
746
+ /**
747
+ * MSS parser encountered a live playlist.
748
+ */
749
+ 'MSS_LIVE_CONTENT_NOT_SUPPORTED': 4047,
750
+
727
751
 
728
752
  // RETIRED: 'INCONSISTENT_BUFFER_STATE': 5000,
729
753
  // RETIRED: 'INVALID_SEGMENT_INDEX': 5001,
@@ -830,7 +854,8 @@ shaka.util.Error.Code = {
830
854
  'NO_LICENSE_SERVER_GIVEN': 6012,
831
855
 
832
856
  /**
833
- * A required offline session was removed. The content is not playable.
857
+ * A required offline session was removed. The content might not be playable
858
+ * depending of the playback context.
834
859
  */
835
860
  'OFFLINE_SESSION_REMOVED': 6013,
836
861
 
@@ -858,6 +883,17 @@ shaka.util.Error.Code = {
858
883
  */
859
884
  'SERVER_CERTIFICATE_REQUEST_FAILED': 6017,
860
885
 
886
+ /**
887
+ * The HDCP version does not meet the requirements.
888
+ */
889
+ 'MIN_HDCP_VERSION_NOT_MATCH': 6018,
890
+
891
+ /**
892
+ * Error when checking HDCP version.
893
+ * <br> error.data[0] is an error message string from the browser.
894
+ */
895
+ 'ERROR_CHECKING_HDCP_VERSION': 6019,
896
+
861
897
 
862
898
  /**
863
899
  * The call to Player.load() was interrupted by a call to Player.unload()
@@ -0,0 +1,220 @@
1
+ /**
2
+ * @license
3
+ * Copyright Brightcove, 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
+
18
+ goog.provide('shaka.util.ExpGolomb');
19
+
20
+ goog.require('shaka.util.DataViewReader');
21
+
22
+
23
+ /**
24
+ * @summary
25
+ * Parser for exponential Golomb codes, a variable-bitwidth number encoding
26
+ * scheme used by h264.
27
+ * Based on https://github.com/videojs/mux.js/blob/main/lib/utils/exp-golomb.js
28
+ *
29
+ * @export
30
+ */
31
+ shaka.util.ExpGolomb = class {
32
+ /**
33
+ * @param {!Uint8Array} data
34
+ */
35
+ constructor(data) {
36
+ /** @private {!Uint8Array} */
37
+ this.data_ = data;
38
+
39
+ /** @private {number} */
40
+ this.workingBytesAvailable_ = data.byteLength;
41
+
42
+ // the current word being examined
43
+ /** @private {number} */
44
+ this.workingWord_ = 0;
45
+
46
+ // the number of bits left to examine in the current word
47
+ /** @private {number} */
48
+ this.workingBitsAvailable_ = 0;
49
+ }
50
+
51
+ /**
52
+ * Load the next word
53
+ *
54
+ * @private
55
+ */
56
+ loadWord_() {
57
+ const position = this.data_.byteLength - this.workingBytesAvailable_;
58
+ const bytes = new Uint8Array(4);
59
+ const availableBytes = Math.min(4, this.workingBytesAvailable_);
60
+
61
+ if (availableBytes === 0) {
62
+ return;
63
+ }
64
+
65
+ bytes.set(this.data_.subarray(position, position + availableBytes));
66
+ const dataView = new shaka.util.DataViewReader(
67
+ bytes, shaka.util.DataViewReader.Endianness.BIG_ENDIAN);
68
+ this.workingWord_ = dataView.readUint32();
69
+
70
+ // track the amount of data that has been processed
71
+ this.workingBitsAvailable_ = availableBytes * 8;
72
+ this.workingBytesAvailable_ -= availableBytes;
73
+ }
74
+
75
+ /**
76
+ * Skip n bits
77
+ *
78
+ * @param {number} count
79
+ */
80
+ skipBits(count) {
81
+ if (this.workingBitsAvailable_ <= count) {
82
+ count -= this.workingBitsAvailable_;
83
+ const skipBytes = Math.floor(count / 8);
84
+ count -= (skipBytes * 8);
85
+ this.workingBitsAvailable_ -= skipBytes;
86
+ this.loadWord_();
87
+ }
88
+ this.workingWord_ <<= count;
89
+ this.workingBitsAvailable_ -= count;
90
+ }
91
+
92
+ /**
93
+ * Read n bits
94
+ *
95
+ * @param {number} size
96
+ * @return {number}
97
+ */
98
+ readBits(size) {
99
+ let bits = Math.min(this.workingBitsAvailable_, size);
100
+ const valu = this.workingWord_ >>> (32 - bits);
101
+ this.workingBitsAvailable_ -= bits;
102
+ if (this.workingBitsAvailable_ > 0) {
103
+ this.workingWord_ <<= bits;
104
+ } else if (this.workingBytesAvailable_ > 0) {
105
+ this.loadWord_();
106
+ }
107
+ bits = size - bits;
108
+ if (bits > 0) {
109
+ return (valu << bits) | this.readBits(bits);
110
+ }
111
+ return valu;
112
+ }
113
+
114
+ /**
115
+ * Return the number of skip leading zeros
116
+ *
117
+ * @return {number}
118
+ * @private
119
+ */
120
+ skipLeadingZeros_() {
121
+ let i;
122
+ for (i = 0; i < this.workingBitsAvailable_; ++i) {
123
+ if ((this.workingWord_ & (0x80000000 >>> i)) !== 0) {
124
+ // the first bit of working word is 1
125
+ this.workingWord_ <<= i;
126
+ this.workingBitsAvailable_ -= i;
127
+ return i;
128
+ }
129
+ }
130
+
131
+ // we exhausted workingWord and still have not found a 1
132
+ this.loadWord_();
133
+ return i + this.skipLeadingZeros_();
134
+ }
135
+
136
+ /**
137
+ * Skip exponential Golomb
138
+ */
139
+ skipExpGolomb() {
140
+ this.skipBits(1 + this.skipLeadingZeros_());
141
+ }
142
+
143
+ /**
144
+ * Return unsigned exponential Golomb
145
+ *
146
+ * @return {number}
147
+ */
148
+ readUnsignedExpGolomb() {
149
+ const clz = this.skipLeadingZeros_();
150
+ return this.readBits(clz + 1) - 1;
151
+ }
152
+
153
+ /**
154
+ * Return exponential Golomb
155
+ *
156
+ * @return {number}
157
+ */
158
+ readExpGolomb() {
159
+ const valu = this.readUnsignedExpGolomb();
160
+ if (0x01 & valu) {
161
+ // the number is odd if the low order bit is set
162
+ // add 1 to make it even, and divide by 2
163
+ return (1 + valu) >>> 1;
164
+ }
165
+ // divide by two then make it negative
166
+ return -1 * (valu >>> 1);
167
+ }
168
+
169
+ /**
170
+ * Read 1 bit as boolean
171
+ *
172
+ * @return {boolean}
173
+ */
174
+ readBoolean() {
175
+ return this.readBits(1) === 1;
176
+ }
177
+
178
+ /**
179
+ * Read 8 bits
180
+ *
181
+ * @return {number}
182
+ */
183
+ readUnsignedByte() {
184
+ return this.readBits(8);
185
+ }
186
+
187
+ /**
188
+ * The scaling list is optionally transmitted as part of a Sequence Parameter
189
+ * Set (SPS).
190
+ *
191
+ * @param {number} count the number of entries in this scaling list
192
+ * @see Recommendation ITU-T H.264, Section 7.3.2.1.1.1
193
+ */
194
+ skipScalingList(count) {
195
+ let lastScale = 8;
196
+ let nextScale = 8;
197
+
198
+ for (let j = 0; j < count; j++) {
199
+ if (nextScale !== 0) {
200
+ const deltaScale = this.readExpGolomb();
201
+ nextScale = (lastScale + deltaScale + 256) % 256;
202
+ }
203
+ lastScale = (nextScale === 0) ? lastScale : nextScale;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Return the slice type
209
+ *
210
+ * @return {number}
211
+ */
212
+ readSliceType() {
213
+ // skip Nalu type
214
+ this.readUnsignedByte();
215
+ // discard first_mb_in_slice
216
+ this.readUnsignedExpGolomb();
217
+ // return slice_type
218
+ return this.readUnsignedExpGolomb();
219
+ }
220
+ };