shaka-player 3.3.2 → 3.3.5

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 (339) hide show
  1. package/.csslintrc +11 -1
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  3. package/.github/pull_request_template.md +6 -34
  4. package/.github/workflows/build-and-test.yaml +129 -0
  5. package/.github/workflows/custom-actions/prep-for-appspot/action.yaml +56 -0
  6. package/.github/workflows/custom-actions/set-commit-status/action.yaml +41 -0
  7. package/.github/workflows/demo-version-index.yaml +29 -0
  8. package/.github/workflows/nightly-demo.yaml +42 -0
  9. package/.github/workflows/release-please.yaml +147 -0
  10. package/.github/workflows/safari-homedir-launcher.sh +18 -0
  11. package/.github/workflows/selenium-lab-tests.yaml +92 -0
  12. package/AUTHORS +2 -0
  13. package/CHANGELOG.md +1718 -1675
  14. package/CONTRIBUTING.md +2 -2
  15. package/CONTRIBUTORS +2 -0
  16. package/README.md +7 -7
  17. package/app-engine/README.md +9 -0
  18. package/app-engine/demo-version-index/README.md +14 -0
  19. package/app-engine/demo-version-index/app.yaml +2 -0
  20. package/app-engine/demo-version-index/main.py +162 -0
  21. package/app-engine/demo-version-index/requirements.txt +6 -0
  22. package/app-engine/demo-version-index/templates/index.html +114 -0
  23. package/app-engine/shaka-player-demo/README.md +18 -0
  24. package/app-engine/shaka-player-demo/app.yaml +61 -0
  25. package/app-engine/shaka-player-demo/main.py +95 -0
  26. package/app-engine/shaka-player-demo/posters/10yo.png +0 -0
  27. package/app-engine/shaka-player-demo/posters/10yo.xcf +0 -0
  28. package/app-engine/shaka-player-demo/posters/1yo.jpg +0 -0
  29. package/app-engine/shaka-player-demo/posters/2yo.png +0 -0
  30. package/app-engine/shaka-player-demo/posters/2yo.xcf +0 -0
  31. package/app-engine/shaka-player-demo/posters/3yo.png +0 -0
  32. package/app-engine/shaka-player-demo/posters/3yo.xcf +0 -0
  33. package/app-engine/shaka-player-demo/posters/4yo.png +0 -0
  34. package/app-engine/shaka-player-demo/posters/4yo.xcf +0 -0
  35. package/app-engine/shaka-player-demo/posters/5yo.png +0 -0
  36. package/app-engine/shaka-player-demo/posters/5yo.xcf +0 -0
  37. package/app-engine/shaka-player-demo/posters/6yo.png +0 -0
  38. package/app-engine/shaka-player-demo/posters/6yo.xcf +0 -0
  39. package/app-engine/shaka-player-demo/posters/7yo.png +0 -0
  40. package/app-engine/shaka-player-demo/posters/7yo.xcf +0 -0
  41. package/app-engine/shaka-player-demo/posters/8yo.png +0 -0
  42. package/app-engine/shaka-player-demo/posters/8yo.xcf +0 -0
  43. package/app-engine/shaka-player-demo/posters/9yo.png +0 -0
  44. package/app-engine/shaka-player-demo/posters/9yo.xcf +0 -0
  45. package/app-engine/shaka-player-demo/posters/audioOnly.gif +0 -0
  46. package/app-engine/shaka-player-demo/posters/audioRickRoll.gif +0 -0
  47. package/app-engine/shaka-player-demo/posters/colorbars.gif +0 -0
  48. package/app-engine/shaka-player-demo/posters/fireworks.jpg +0 -0
  49. package/app-engine/shaka-player-demo/posters/party-hat.png +0 -0
  50. package/app-engine/shaka-player-demo/posters/sources.txt +46 -0
  51. package/app-engine/shaka-player-demo/posters/standard.png +0 -0
  52. package/app-engine/shaka-player-demo/posters/trek.jpg +0 -0
  53. package/app-engine/shaka-player-demo/posters/valentines.png +0 -0
  54. package/app-engine/shaka-player-demo/posters/zombie.jpg +0 -0
  55. package/app-engine/shaka-player-demo/posters.py +110 -0
  56. package/app-engine/shaka-player-demo/requirements.txt +5 -0
  57. package/app-engine/shaka-player-demo/time.txt +1 -0
  58. package/build/README.md +3 -3
  59. package/build/checkversion.py +2 -2
  60. package/build/conformance.textproto +13 -0
  61. package/build/docker/Dockerfile +20 -0
  62. package/build/docker/docker-compose.yml +10 -0
  63. package/build/gendeps.py +18 -15
  64. package/build/shaka-lab.yaml +163 -0
  65. package/build/shakaBuildHelpers.py +4 -29
  66. package/build/test.py +94 -29
  67. package/build/types/core +0 -1
  68. package/build/types/polyfill +1 -0
  69. package/build/wrapper.template.js +2 -2
  70. package/demo/TengwarTelcontar.woff2 +0 -0
  71. package/demo/asset_card.js +1 -2
  72. package/demo/cast_receiver/index.html +1 -1
  73. package/demo/cast_receiver/receiver_app.css +14 -14
  74. package/demo/common/assets.js +2 -0
  75. package/demo/config.js +0 -1
  76. package/demo/custom.js +0 -1
  77. package/demo/customWarning.txt +2 -2
  78. package/demo/demo.less +29 -18
  79. package/demo/demo_uncompiled.js +1 -13
  80. package/demo/index.html +1 -1
  81. package/demo/main.js +3 -3
  82. package/dist/controls.css +3 -3
  83. package/dist/controls.css.map +1 -1
  84. package/dist/demo.compiled.debug.js +191 -194
  85. package/dist/demo.compiled.debug.map +4 -4
  86. package/dist/demo.compiled.js +191 -194
  87. package/dist/demo.compiled.map +4 -4
  88. package/dist/demo.css +1 -1
  89. package/dist/demo.css.map +1 -1
  90. package/dist/deps.js +232 -226
  91. package/dist/locales.js +30 -30
  92. package/dist/receiver.compiled.debug.js +43 -45
  93. package/dist/receiver.compiled.debug.map +4 -4
  94. package/dist/receiver.compiled.js +43 -45
  95. package/dist/receiver.compiled.map +4 -4
  96. package/dist/shaka-player.compiled.d.ts +247 -236
  97. package/dist/shaka-player.compiled.debug.d.ts +247 -236
  98. package/dist/shaka-player.compiled.debug.externs.js +15 -3
  99. package/dist/shaka-player.compiled.debug.js +284 -290
  100. package/dist/shaka-player.compiled.debug.map +4 -4
  101. package/dist/shaka-player.compiled.externs.js +15 -3
  102. package/dist/shaka-player.compiled.js +855 -859
  103. package/dist/shaka-player.compiled.map +4 -4
  104. package/dist/shaka-player.ui.d.ts +291 -280
  105. package/dist/shaka-player.ui.debug.d.ts +291 -280
  106. package/dist/shaka-player.ui.debug.externs.js +15 -3
  107. package/dist/shaka-player.ui.debug.js +296 -302
  108. package/dist/shaka-player.ui.debug.map +4 -4
  109. package/dist/shaka-player.ui.externs.js +15 -3
  110. package/dist/shaka-player.ui.js +1005 -1009
  111. package/dist/shaka-player.ui.map +4 -4
  112. package/docs/design/REDESIGN.md +33 -33
  113. package/docs/design/bg-fetch.md +2 -2
  114. package/docs/design/codec_preferences.md +1 -1
  115. package/docs/design/dash-audio-channels.md +3 -3
  116. package/docs/design/dash-manifests.md +1 -1
  117. package/docs/design/gap-jumping.md +3 -3
  118. package/docs/design/preload.md +2 -2
  119. package/docs/tutorials/faq.md +8 -8
  120. package/docs/tutorials/index.json +1 -0
  121. package/docs/tutorials/plugins.md +3 -3
  122. package/docs/tutorials/selenium-grid-config.md +122 -0
  123. package/docs/tutorials/welcome.md +10 -2
  124. package/externs/cmcd.js +1 -1
  125. package/karma.conf.js +141 -30
  126. package/lib/abr/simple_abr_manager.js +12 -6
  127. package/lib/cast/cast_proxy.js +3 -4
  128. package/lib/cea/cea608_data_channel.js +2 -2
  129. package/lib/cea/cea708_service.js +5 -4
  130. package/lib/cea/mp4_cea_parser.js +11 -5
  131. package/lib/cea/sei_processor.js +6 -3
  132. package/lib/dash/dash_parser.js +11 -14
  133. package/lib/dash/mpd_utils.js +4 -5
  134. package/lib/dash/segment_list.js +1 -2
  135. package/lib/dash/segment_template.js +3 -3
  136. package/lib/hls/hls_parser.js +34 -20
  137. package/lib/hls/manifest_text_parser.js +3 -3
  138. package/lib/media/adaptation_set.js +1 -2
  139. package/lib/media/content_workarounds.js +2 -2
  140. package/lib/media/drm_engine.js +3 -2
  141. package/lib/media/media_source_engine.js +10 -3
  142. package/lib/media/mp4_segment_index_parser.js +1 -4
  143. package/lib/media/playhead.js +2 -2
  144. package/lib/media/presentation_timeline.js +18 -8
  145. package/lib/media/streaming_engine.js +6 -6
  146. package/lib/media/time_ranges_utils.js +1 -3
  147. package/lib/media/video_wrapper.js +1 -1
  148. package/lib/net/networking_engine.js +1 -1
  149. package/lib/offline/indexeddb/storage_mechanism.js +4 -2
  150. package/lib/offline/storage.js +96 -95
  151. package/lib/player.js +190 -114
  152. package/lib/polyfill/all.js +2 -3
  153. package/lib/polyfill/encryption_scheme.js +1 -1
  154. package/lib/polyfill/media_capabilities.js +3 -3
  155. package/lib/polyfill/mediasource.js +1 -1
  156. package/lib/polyfill/symbol.js +46 -0
  157. package/lib/text/cue.js +1 -1
  158. package/lib/text/simple_text_displayer.js +2 -1
  159. package/lib/text/ttml_text_parser.js +8 -5
  160. package/lib/text/ui_text_displayer.js +1 -1
  161. package/lib/util/buffer_utils.js +1 -3
  162. package/lib/util/config_utils.js +25 -0
  163. package/lib/util/ebml_parser.js +3 -3
  164. package/lib/util/error.js +8 -1
  165. package/lib/util/iterables.js +0 -46
  166. package/lib/util/manifest_parser_utils.js +1 -1
  167. package/lib/util/mime_utils.js +48 -1
  168. package/lib/util/mp4_box_parsers.js +1 -4
  169. package/lib/util/mp4_parser.js +5 -7
  170. package/lib/util/periods.js +15 -15
  171. package/lib/util/platform.js +3 -3
  172. package/lib/util/player_configuration.js +9 -14
  173. package/lib/util/pssh.js +1 -4
  174. package/lib/util/stream_utils.js +8 -5
  175. package/lib/util/string_utils.js +3 -5
  176. package/lib/util/uint8array_utils.js +3 -5
  177. package/lib/util/xml_utils.js +15 -7
  178. package/package.json +61 -36
  179. package/roadmap.md +17 -17
  180. package/shaka-player.uncompiled.js +1 -0
  181. package/test/abr/simple_abr_manager_unit.js +3 -8
  182. package/test/ads/ad_manager_unit.js +0 -6
  183. package/test/cast/cast_proxy_unit.js +0 -8
  184. package/test/cast/cast_receiver_integration.js +1 -18
  185. package/test/cast/cast_receiver_unit.js +1 -9
  186. package/test/cast/cast_sender_unit.js +0 -6
  187. package/test/cast/cast_utils_unit.js +1 -13
  188. package/test/cea/cea608_memory_unit.js +0 -5
  189. package/test/cea/cea708_service_unit.js +0 -7
  190. package/test/cea/cea708_window_unit.js +0 -5
  191. package/test/cea/cea_decoder_unit.js +0 -6
  192. package/test/cea/dtvcc_packet_builder_unit.js +0 -3
  193. package/test/cea/dtvcc_packet_unit.js +0 -5
  194. package/test/cea/mp4_cea_parser_unit.js +0 -4
  195. package/test/dash/dash_parser_content_protection_unit.js +1 -10
  196. package/test/dash/dash_parser_live_unit.js +2 -15
  197. package/test/dash/dash_parser_manifest_unit.js +2 -40
  198. package/test/dash/dash_parser_segment_base_unit.js +1 -8
  199. package/test/dash/dash_parser_segment_list_unit.js +1 -7
  200. package/test/dash/dash_parser_segment_template_unit.js +0 -9
  201. package/test/dash/mpd_utils_unit.js +3 -11
  202. package/test/demo/demo_unit.js +0 -5
  203. package/test/deprecate/enforcer_unit.js +0 -4
  204. package/test/deprecate/version_unit.js +0 -2
  205. package/test/hls/hls_live_unit.js +28 -14
  206. package/test/hls/hls_parser_unit.js +2 -15
  207. package/test/hls/manifest_text_parser_unit.js +19 -10
  208. package/test/media/adaptation_set_criteria_unit.js +3 -7
  209. package/test/media/adaptation_set_unit.js +0 -2
  210. package/test/media/buffering_observer_unit.js +1 -4
  211. package/test/media/closed_caption_parser_unit.js +0 -3
  212. package/test/media/drm_engine_integration.js +2 -15
  213. package/test/media/drm_engine_unit.js +4 -24
  214. package/test/media/manifest_parser_unit.js +0 -4
  215. package/test/media/media_source_engine_integration.js +1 -7
  216. package/test/media/media_source_engine_unit.js +5 -18
  217. package/test/media/mp4_segment_index_parser_unit.js +0 -4
  218. package/test/media/play_rate_controller_unit.js +0 -4
  219. package/test/media/playhead_unit.js +8 -16
  220. package/test/media/presentation_timeline_unit.js +4 -7
  221. package/test/media/quality_observer_unit.js +0 -4
  222. package/test/media/region_observer_unit.js +1 -6
  223. package/test/media/region_timeline_unit.js +0 -3
  224. package/test/media/segment_index_unit.js +0 -6
  225. package/test/media/segment_reference_unit.js +0 -3
  226. package/test/media/stall_detector_unit.js +0 -5
  227. package/test/media/streaming_engine_integration.js +11 -36
  228. package/test/media/streaming_engine_unit.js +11 -35
  229. package/test/media/time_ranges_utils_unit.js +0 -2
  230. package/test/media/transmuxer_integration.js +0 -6
  231. package/test/media/webm_segment_index_parser_unit.js +0 -4
  232. package/test/net/data_uri_plugin_unit.js +0 -7
  233. package/test/net/http_plugin_unit.js +0 -9
  234. package/test/net/networking_engine_unit.js +0 -11
  235. package/test/offline/download_progress_estimator_unit.js +0 -2
  236. package/test/offline/indexeddb_storage_unit.js +1 -7
  237. package/test/offline/manifest_convert_unit.js +0 -8
  238. package/test/offline/offline_integration.js +1 -10
  239. package/test/offline/offline_manifest_parser_unit.js +0 -6
  240. package/test/offline/offline_scheme_unit.js +0 -8
  241. package/test/offline/offline_uri_unit.js +0 -2
  242. package/test/offline/storage_compatibility_unit.js +2 -15
  243. package/test/offline/storage_integration.js +1 -27
  244. package/test/player_external.js +9 -11
  245. package/test/player_integration.js +28 -38
  246. package/test/player_load_graph_integration.js +1 -6
  247. package/test/player_src_equals_external.js +3 -9
  248. package/test/player_src_equals_integration.js +81 -90
  249. package/test/player_unit.js +150 -38
  250. package/test/routing/walker_unit.js +0 -8
  251. package/test/test/assets/large_file.mpd +1 -1
  252. package/test/test/boot.js +84 -22
  253. package/test/test/externs/filters.js +4 -0
  254. package/test/test/externs/jasmine.js +2 -2
  255. package/test/test/externs/karma.js +4 -0
  256. package/test/test/namespace.js +10 -0
  257. package/test/test/util/canned_idb.js +0 -8
  258. package/test/test/util/cea_utils.js +0 -6
  259. package/test/test/util/dash_parser_util.js +0 -13
  260. package/test/test/util/fake_ad.js +0 -3
  261. package/test/test/util/fake_ad_manager.js +0 -9
  262. package/test/test/util/fake_demo_main.js +0 -5
  263. package/test/test/util/fake_drm_engine.js +0 -6
  264. package/test/test/util/fake_media_source_engine.js +0 -7
  265. package/test/test/util/fake_networking_engine.js +0 -5
  266. package/test/test/util/fake_text_displayer.js +0 -5
  267. package/test/test/util/indexeddb_utils.js +1 -10
  268. package/test/test/util/jasmine_fetch.js +0 -1
  269. package/test/test/util/loader.js +0 -18
  270. package/test/test/util/manifest_generator.js +9 -14
  271. package/test/test/util/manifest_parser_util.js +0 -6
  272. package/test/test/util/offline_utils.js +0 -5
  273. package/test/test/util/simple_fakes.js +40 -28
  274. package/test/test/util/stream_generator.js +0 -14
  275. package/test/test/util/streaming_engine_util.js +0 -15
  276. package/test/test/util/test_scheme.js +1 -19
  277. package/test/test/util/ttml_utils.js +0 -2
  278. package/test/test/util/ui_utils.js +0 -9
  279. package/test/test/util/util.js +5 -19
  280. package/test/test/util/waiter.js +84 -43
  281. package/test/text/cue_integration.js +0 -4
  282. package/test/text/lrc_text_parser_unit.js +0 -4
  283. package/test/text/mp4_ttml_parser_unit.js +0 -6
  284. package/test/text/mp4_vtt_parser_unit.js +1 -7
  285. package/test/text/sbv_text_parser_unit.js +0 -4
  286. package/test/text/simple_text_displayer_unit.js +1 -8
  287. package/test/text/srt_text_parser_unit.js +0 -4
  288. package/test/text/ssa_text_parser_unit.js +0 -5
  289. package/test/text/text_engine_unit.js +2 -7
  290. package/test/text/text_track_integration.js +0 -2
  291. package/test/text/ttml_text_parser_unit.js +2 -11
  292. package/test/text/ui_text_displayer_unit.js +44 -41
  293. package/test/text/vtt_text_parser_unit.js +0 -9
  294. package/test/text/web_vtt_generator_unit.js +0 -3
  295. package/test/ui/ad_ui_unit.js +0 -11
  296. package/test/ui/localization_unit.js +0 -3
  297. package/test/ui/text_displayer_layout_unit.js +1 -12
  298. package/test/ui/ui_customization_unit.js +0 -6
  299. package/test/ui/ui_integration.js +0 -16
  300. package/test/ui/ui_unit.js +1 -17
  301. package/test/util/abortable_operation_unit.js +4 -9
  302. package/test/util/array_utils_unit.js +0 -2
  303. package/test/util/buffer_utils_unit.js +0 -2
  304. package/test/util/cmcd_manager_unit.js +0 -3
  305. package/test/util/data_view_reader_unit.js +0 -4
  306. package/test/util/ebml_parser_unit.js +0 -4
  307. package/test/util/event_manager_unit.js +0 -3
  308. package/test/util/fake_event_target_unit.js +0 -5
  309. package/test/util/functional_unit.js +1 -1
  310. package/test/util/iterables_unit.js +0 -64
  311. package/test/util/language_utils_unit.js +0 -3
  312. package/test/util/manifest_parser_utils_unit.js +0 -2
  313. package/test/util/mime_utils_unit.js +54 -0
  314. package/test/util/mp4_box_parsers_unit.js +0 -5
  315. package/test/util/mp4_parser_unit.js +0 -4
  316. package/test/util/multi_map_unit.js +0 -3
  317. package/test/util/object_utils_unit.js +0 -2
  318. package/test/util/periods_unit.js +93 -7
  319. package/test/util/pssh_unit.js +0 -5
  320. package/test/util/state_history_unit.js +0 -2
  321. package/test/util/stream_utils_unit.js +3 -8
  322. package/test/util/string_utils_unit.js +0 -6
  323. package/test/util/text_parser_unit.js +0 -2
  324. package/test/util/xml_utils_unit.js +0 -4
  325. package/ui/less/ad_controls.less +6 -6
  326. package/ui/less/buttons.less +6 -6
  327. package/ui/less/containers.less +13 -15
  328. package/ui/less/overflow_menu.less +4 -4
  329. package/ui/less/range_elements.less +7 -2
  330. package/ui/less/tooltip.less +4 -4
  331. package/ui/locales/sjn-translations.yaml +257 -0
  332. package/ui/locales/sjn.json +42 -0
  333. package/ui/seek_bar.js +2 -1
  334. package/.github/workflows/build_and_test.yaml +0 -73
  335. package/.github/workflows/release.yaml +0 -53
  336. package/docs/tutorials/gsoc-ideas-list.md +0 -3
  337. package/externs/svgelement.js +0 -18
  338. package/externs/webcrypto.js +0 -18
  339. package/lib/util/mutex.js +0 -52
@@ -29,7 +29,6 @@ goog.require('shaka.util.Functional');
29
29
  goog.require('shaka.util.IDestroyable');
30
30
  goog.require('shaka.util.Iterables');
31
31
  goog.require('shaka.util.MimeUtils');
32
- goog.require('shaka.util.Mutex');
33
32
  goog.require('shaka.util.Platform');
34
33
  goog.require('shaka.util.PlayerConfiguration');
35
34
  goog.require('shaka.util.StreamUtils');
@@ -210,7 +209,7 @@ shaka.offline.Storage = class {
210
209
  }
211
210
 
212
211
  goog.asserts.assert(
213
- this.config_, 'Cannot reconfigure stroage after calling destroy.');
212
+ this.config_, 'Cannot reconfigure storage after calling destroy.');
214
213
  return shaka.util.PlayerConfiguration.mergeConfigObjects(
215
214
  /* destination= */ this.config_, /* updates= */ config );
216
215
  }
@@ -479,36 +478,34 @@ shaka.offline.Storage = class {
479
478
  async downloadSegments_(
480
479
  toDownload, manifestId, manifestDB, downloader, config, storage,
481
480
  manifest, drmEngine) {
481
+ let pendingManifestUpdates = {};
482
+ let pendingDataSize = 0;
483
+
482
484
  /**
483
485
  * @param {!Array.<!shaka.offline.DownloadInfo>} toDownload
484
486
  * @param {boolean} updateDRM
485
487
  */
486
488
  const download = async (toDownload, updateDRM) => {
487
- const throwIfAbortedFn = () => {
488
- this.ensureNotDestroyed_();
489
- };
490
489
  for (const download of toDownload) {
491
- /** @param {?BufferSource} data */
492
- let data;
493
490
  const request = download.makeSegmentRequest(config);
494
491
  const estimateId = download.estimateId;
495
492
  const isInitSegment = download.isInitSegment;
496
- const onDownloaded = (d) => {
497
- data = d;
498
- return Promise.resolve();
499
- };
500
- downloader.queue(download.groupId,
501
- request, estimateId, isInitSegment, onDownloaded);
502
- downloader.queueWork(download.groupId, async () => {
503
- goog.asserts.assert(data, 'We should have loaded data by now');
504
- goog.asserts.assert(data instanceof ArrayBuffer,
505
- 'The data should be an ArrayBuffer');
506
493
 
494
+ const onDownloaded = async (data) => {
495
+ // Store the data.
496
+ const dataKeys = await storage.addSegments([{data}]);
497
+ this.ensureNotDestroyed_();
498
+
499
+ // Store the necessary update to the manifest, to be processed later.
507
500
  const ref = /** @type {!shaka.media.SegmentReference} */ (
508
501
  download.ref);
509
- manifestDB = (await shaka.offline.Storage.assignStreamToManifest(
510
- manifestId, ref, {data}, throwIfAbortedFn)) || manifestDB;
511
- });
502
+ const id = shaka.offline.DownloadInfo.idForSegmentRef(ref);
503
+ pendingManifestUpdates[id] = dataKeys[0];
504
+ pendingDataSize += data.byteLength;
505
+ };
506
+
507
+ downloader.queue(download.groupId,
508
+ request, estimateId, isInitSegment, onDownloaded);
512
509
  }
513
510
  await downloader.waitToFinish();
514
511
 
@@ -516,8 +513,8 @@ shaka.offline.Storage = class {
516
513
  // Re-store the manifest, to attach session IDs.
517
514
  // These were (maybe) discovered inside the downloader; we can only add
518
515
  // them now, at the end, since the manifestDB is in flux during the
519
- // process of downloading and storing, and assignStreamToManifest does
520
- // not know about the DRM engine.
516
+ // process of downloading and storing, and assignSegmentsToManifest
517
+ // does not know about the DRM engine.
521
518
  this.ensureNotDestroyed_();
522
519
  this.setManifestDrmFields_(manifest, manifestDB, drmEngine, config);
523
520
  await storage.updateManifest(manifestId, manifestDB);
@@ -526,24 +523,54 @@ shaka.offline.Storage = class {
526
523
 
527
524
  const usingBgFetch = false; // TODO: Get.
528
525
 
529
- if (this.getManifestIsEncrypted_(manifest) && usingBgFetch &&
530
- !this.getManifestIncludesInitData_(manifest)) {
531
- // Background fetch can't make DRM sessions, so if we have to get the
532
- // init data from the init segments, download those first before anything
533
- // else.
534
- await download(toDownload.filter((info) => info.isInitSegment), true);
535
- this.ensureNotDestroyed_();
536
- toDownload = toDownload.filter((info) => !info.isInitSegment);
537
- }
526
+ try {
527
+ if (this.getManifestIsEncrypted_(manifest) && usingBgFetch &&
528
+ !this.getManifestIncludesInitData_(manifest)) {
529
+ // Background fetch can't make DRM sessions, so if we have to get the
530
+ // init data from the init segments, download those first before
531
+ // anything else.
532
+ await download(toDownload.filter((info) => info.isInitSegment), true);
533
+ this.ensureNotDestroyed_();
534
+ toDownload = toDownload.filter((info) => !info.isInitSegment);
538
535
 
539
- if (!usingBgFetch) {
540
- await download(toDownload, false);
541
- this.ensureNotDestroyed_();
536
+ // Copy these and reset them now, before calling await.
537
+ const manifestUpdates = pendingManifestUpdates;
538
+ const dataSize = pendingDataSize;
539
+ pendingManifestUpdates = {};
540
+ pendingDataSize = 0;
542
541
 
543
- goog.asserts.assert(
544
- !manifestDB.isIncomplete, 'The manifest should be complete by now');
545
- } else {
546
- // TODO: Send the request to the service worker. Don't await the result.
542
+ await shaka.offline.Storage.assignSegmentsToManifest(
543
+ storage, manifestId, manifestDB, manifestUpdates, dataSize,
544
+ () => this.ensureNotDestroyed_());
545
+ this.ensureNotDestroyed_();
546
+ }
547
+
548
+ if (!usingBgFetch) {
549
+ await download(toDownload, false);
550
+ this.ensureNotDestroyed_();
551
+
552
+ // Copy these and reset them now, before calling await.
553
+ const manifestUpdates = pendingManifestUpdates;
554
+ const dataSize = pendingDataSize;
555
+ pendingManifestUpdates = {};
556
+ pendingDataSize = 0;
557
+
558
+ await shaka.offline.Storage.assignSegmentsToManifest(
559
+ storage, manifestId, manifestDB, manifestUpdates, dataSize,
560
+ () => this.ensureNotDestroyed_());
561
+ this.ensureNotDestroyed_();
562
+
563
+ goog.asserts.assert(
564
+ !manifestDB.isIncomplete, 'The manifest should be complete by now');
565
+ } else {
566
+ // TODO: Send the request to the service worker. Don't await the result.
567
+ }
568
+ } catch (error) {
569
+ const dataKeys = Object.values(pendingManifestUpdates);
570
+ // Remove these pending segments that are not yet linked to the manifest.
571
+ await storage.removeSegments(dataKeys, (key) => {});
572
+
573
+ throw error;
547
574
  }
548
575
  }
549
576
 
@@ -567,70 +594,50 @@ shaka.offline.Storage = class {
567
594
  }
568
595
 
569
596
  /**
570
- * Load the given manifest, modifies it by assigning the given data to the
571
- * segments corresponding to "ref", then re-stores the manifest.
572
- * The parts of this function that modify the manifest are protected by a
573
- * mutex, to prevent race conditions; specifically, it prevents two parallel
574
- * instances of this method from both loading the manifest into memory at the
575
- * same time, which would result in the slower/later call overwriting the
576
- * changes of the other.
597
+ * Updates the given manifest, assigns database keys to segments, then stores
598
+ * the updated manifest.
577
599
  *
600
+ * It is up to the caller to ensure that this method is not called
601
+ * concurrently on the same manifest.
602
+ *
603
+ * @param {shaka.extern.StorageCell} storage
578
604
  * @param {number} manifestId
579
- * @param {!shaka.media.SegmentReference} ref
580
- * @param {shaka.extern.SegmentDataDB} data
605
+ * @param {!shaka.extern.ManifestDB} manifestDB
606
+ * @param {!Object.<string, number>} manifestUpdates
607
+ * @param {number} dataSizeUpdate
581
608
  * @param {function()} throwIfAbortedFn A function that should throw if the
582
609
  * download has been aborted.
583
- * @return {!Promise.<?shaka.extern.ManifestDB>}
610
+ * @return {!Promise}
584
611
  */
585
- static async assignStreamToManifest(manifestId, ref, data, throwIfAbortedFn) {
586
- /** @type {shaka.offline.StorageMuxer} */
587
- const muxer = new shaka.offline.StorageMuxer();
588
-
589
- const idForRef = shaka.offline.DownloadInfo.idForSegmentRef(ref);
612
+ static async assignSegmentsToManifest(
613
+ storage, manifestId, manifestDB, manifestUpdates, dataSizeUpdate,
614
+ throwIfAbortedFn) {
590
615
  let manifestUpdated = false;
591
- let dataKey;
592
- let activeHandle;
593
- /** @type {!shaka.extern.ManifestDB} */
594
- let manifestDB;
595
-
596
- let mutexId = 0;
597
616
 
598
617
  try {
599
- await muxer.init();
600
- activeHandle = await muxer.getActive();
601
-
602
- // Store the data.
603
- const dataKeys = await activeHandle.cell.addSegments([data]);
604
- dataKey = dataKeys[0];
605
- throwIfAbortedFn();
606
-
607
- // Acquire the mutex before accessing the manifest, since there could be
608
- // multiple instances of this method running at once.
609
- mutexId = await shaka.offline.Storage.mutex_.acquire();
610
- throwIfAbortedFn();
611
-
612
- // Load the manifest.
613
- const manifests = await activeHandle.cell.getManifests([manifestId]);
614
- throwIfAbortedFn();
615
- manifestDB = manifests[0];
616
-
617
618
  // Assign the stored data to the manifest.
618
619
  let complete = true;
619
620
  for (const stream of manifestDB.streams) {
620
621
  for (const segment of stream.segments) {
621
- if (segment.pendingSegmentRefId == idForRef) {
622
+ let dataKey = segment.pendingSegmentRefId ?
623
+ manifestUpdates[segment.pendingSegmentRefId] : null;
624
+ if (dataKey != null) {
622
625
  segment.dataKey = dataKey;
623
626
  // Now that the segment has been associated with the appropriate
624
627
  // dataKey, the pendingSegmentRefId is no longer necessary.
625
628
  segment.pendingSegmentRefId = undefined;
626
629
  }
627
- if (segment.pendingInitSegmentRefId == idForRef) {
630
+
631
+ dataKey = segment.pendingInitSegmentRefId ?
632
+ manifestUpdates[segment.pendingInitSegmentRefId] : null;
633
+ if (dataKey != null) {
628
634
  segment.initSegmentKey = dataKey;
629
635
  // Now that the init segment has been associated with the
630
636
  // appropriate initSegmentKey, the pendingInitSegmentRefId is no
631
637
  // longer necessary.
632
638
  segment.pendingInitSegmentRefId = undefined;
633
639
  }
640
+
634
641
  if (segment.pendingSegmentRefId) {
635
642
  complete = false;
636
643
  }
@@ -641,33 +648,30 @@ shaka.offline.Storage = class {
641
648
  }
642
649
 
643
650
  // Update the size of the manifest.
644
- manifestDB.size += data.data.byteLength;
651
+ manifestDB.size += dataSizeUpdate;
645
652
 
646
653
  // Mark the manifest as complete, if all segments are downloaded.
647
654
  if (complete) {
648
655
  manifestDB.isIncomplete = false;
649
656
  }
650
657
 
651
- // Re-store the manifest.
652
- await activeHandle.cell.updateManifest(manifestId, manifestDB);
658
+ // Update the manifest.
659
+ await storage.updateManifest(manifestId, manifestDB);
653
660
  manifestUpdated = true;
654
661
  throwIfAbortedFn();
655
662
  } catch (e) {
656
663
  await shaka.offline.Storage.cleanStoredManifest(manifestId);
657
664
 
658
- if (activeHandle && !manifestUpdated && dataKey) {
665
+ if (!manifestUpdated) {
666
+ const dataKeys = Object.values(manifestUpdates);
659
667
  // The cleanStoredManifest method will not "see" any segments that have
660
668
  // been downloaded but not assigned to the manifest yet. So un-store
661
669
  // them separately.
662
- await activeHandle.cell.removeSegments([dataKey], (key) => {});
670
+ await storage.removeSegments(dataKeys, (key) => {});
663
671
  }
664
672
 
665
673
  throw e;
666
- } finally {
667
- await muxer.destroy();
668
- shaka.offline.Storage.mutex_.release(mutexId);
669
674
  }
670
- return manifestDB;
671
675
  }
672
676
 
673
677
  /**
@@ -804,10 +808,10 @@ shaka.offline.Storage = class {
804
808
  makeManifestDB_(drmEngine, manifest, uri, metadata, config, downloader) {
805
809
  const pendingContent = shaka.offline.StoredContentUtils.fromManifest(
806
810
  uri, manifest, /* size= */ 0, metadata);
807
- // In https://github.com/google/shaka-player/issues/2652, we found that this
808
- // callback would be removed by the compiler if we reference the config in
809
- // the onProgress closure below. Reading it into a local variable first
810
- // seems to work around this apparent compiler bug.
811
+ // In https://github.com/shaka-project/shaka-player/issues/2652, we found
812
+ // that this callback would be removed by the compiler if we reference the
813
+ // config in the onProgress closure below. Reading it into a local
814
+ // variable first seems to work around this apparent compiler bug.
811
815
  const progressCallback = config.offline.progressCallback;
812
816
 
813
817
  const onProgress = (progress, size) => {
@@ -1662,9 +1666,6 @@ shaka.offline.Storage = class {
1662
1666
  }
1663
1667
  };
1664
1668
 
1665
- /** @private {!shaka.util.Mutex} */
1666
- shaka.offline.Storage.mutex_ = new shaka.util.Mutex();
1667
-
1668
1669
  shaka.offline.Storage.defaultSystemIds_ = new Map()
1669
1670
  .set('org.w3.clearkey', '1077efecc0b24d02ace33c1e52e2fb4b')
1670
1671
  .set('com.widevine.alpha', 'edef8ba979d64acea3c827dcd51d21ed')