rx-player 4.0.0-dev.2023111400 → 4.0.0-dev.2023120600

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 (407) hide show
  1. package/CHANGELOG.md +11 -227
  2. package/FILES.md +1 -1
  3. package/VERSION +1 -1
  4. package/dist/_esm5.processed/compat/add_text_track.d.ts +1 -3
  5. package/dist/_esm5.processed/compat/add_text_track.js +4 -7
  6. package/dist/_esm5.processed/compat/browser_compatibility_types.d.ts +0 -7
  7. package/dist/_esm5.processed/compat/event_listeners.d.ts +2 -15
  8. package/dist/_esm5.processed/compat/event_listeners.js +2 -37
  9. package/dist/_esm5.processed/compat/index.d.ts +1 -3
  10. package/dist/_esm5.processed/compat/index.js +1 -3
  11. package/dist/_esm5.processed/config.d.ts +9 -21
  12. package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.d.ts +0 -58
  13. package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.js +14 -54
  14. package/dist/_esm5.processed/core/adaptive/utils/select_optimal_representation.d.ts +2 -8
  15. package/dist/_esm5.processed/core/adaptive/utils/select_optimal_representation.js +2 -11
  16. package/dist/_esm5.processed/core/api/debug/buffer_graph.js +2 -6
  17. package/dist/_esm5.processed/core/api/debug/modules/general_info.js +13 -32
  18. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_content.js +3 -3
  19. package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_size.js +1 -1
  20. package/dist/_esm5.processed/core/api/option_utils.d.ts +12 -35
  21. package/dist/_esm5.processed/core/api/option_utils.js +41 -230
  22. package/dist/_esm5.processed/core/api/public_api.d.ts +91 -266
  23. package/dist/_esm5.processed/core/api/public_api.js +439 -805
  24. package/dist/_esm5.processed/core/{segment_buffers/implementations/image → api/track_management}/index.d.ts +3 -2
  25. package/dist/_esm5.processed/core/{segment_buffers/implementations/image → api/track_management}/index.js +3 -2
  26. package/dist/_esm5.processed/core/api/{tracks_management/media_element_track_choice_manager.d.ts → track_management/media_element_tracks_store.d.ts} +15 -75
  27. package/dist/_esm5.processed/core/api/{tracks_management/media_element_track_choice_manager.js → track_management/media_element_tracks_store.js} +74 -193
  28. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.d.ts +84 -0
  29. package/dist/_esm5.processed/core/api/track_management/track_dispatcher.js +158 -0
  30. package/dist/_esm5.processed/core/api/track_management/tracks_store.d.ts +406 -0
  31. package/dist/_esm5.processed/core/api/track_management/tracks_store.js +932 -0
  32. package/dist/_esm5.processed/core/api/utils.d.ts +1 -0
  33. package/dist/_esm5.processed/core/api/utils.js +28 -11
  34. package/dist/_esm5.processed/core/decrypt/content_decryptor.js +3 -3
  35. package/dist/_esm5.processed/core/decrypt/find_key_system.js +83 -71
  36. package/dist/_esm5.processed/core/decrypt/get_media_keys.js +6 -5
  37. package/dist/_esm5.processed/core/decrypt/session_events_listener.js +10 -72
  38. package/dist/_esm5.processed/core/decrypt/utils/persistent_sessions_store.d.ts +4 -4
  39. package/dist/_esm5.processed/core/decrypt/utils/persistent_sessions_store.js +6 -4
  40. package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.d.ts +1 -3
  41. package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.js +7 -26
  42. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.d.ts +3 -9
  43. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.js +16 -9
  44. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher_creator.d.ts +1 -3
  45. package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher_creator.js +1 -1
  46. package/dist/_esm5.processed/core/fetchers/utils/schedule_request.d.ts +1 -6
  47. package/dist/_esm5.processed/core/fetchers/utils/schedule_request.js +4 -41
  48. package/dist/_esm5.processed/core/init/directfile_content_initializer.js +1 -1
  49. package/dist/_esm5.processed/core/init/media_source_content_initializer.d.ts +1 -8
  50. package/dist/_esm5.processed/core/init/media_source_content_initializer.js +5 -19
  51. package/dist/_esm5.processed/core/init/types.d.ts +5 -15
  52. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.d.ts +2 -36
  53. package/dist/_esm5.processed/core/init/utils/rebuffering_controller.js +2 -82
  54. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.d.ts +1 -2
  55. package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +2 -3
  56. package/dist/_esm5.processed/core/segment_buffers/implementations/types.d.ts +2 -2
  57. package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
  58. package/dist/_esm5.processed/core/segment_buffers/index.js +2 -1
  59. package/dist/_esm5.processed/core/segment_buffers/inventory/index.d.ts +1 -0
  60. package/dist/_esm5.processed/core/segment_buffers/inventory/index.js +1 -0
  61. package/dist/_esm5.processed/core/segment_buffers/inventory/utils.d.ts +33 -0
  62. package/dist/_esm5.processed/core/segment_buffers/inventory/utils.js +49 -0
  63. package/dist/_esm5.processed/core/segment_buffers/segment_buffers_store.d.ts +0 -1
  64. package/dist/_esm5.processed/core/segment_buffers/segment_buffers_store.js +2 -16
  65. package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.d.ts +0 -15
  66. package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.js +183 -93
  67. package/dist/_esm5.processed/core/stream/adaptation/get_representations_switch_strategy.d.ts +39 -0
  68. package/dist/_esm5.processed/core/stream/adaptation/get_representations_switch_strategy.js +133 -0
  69. package/dist/_esm5.processed/core/stream/adaptation/types.d.ts +27 -13
  70. package/dist/_esm5.processed/core/stream/index.d.ts +2 -3
  71. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.d.ts +2 -0
  72. package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.js +5 -7
  73. package/dist/_esm5.processed/core/stream/period/period_stream.js +13 -12
  74. package/dist/_esm5.processed/core/stream/period/types.d.ts +5 -14
  75. package/dist/_esm5.processed/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +2 -4
  76. package/dist/_esm5.processed/core/stream/period/utils/get_adaptation_switch_strategy.js +10 -46
  77. package/dist/_esm5.processed/core/stream/representation/representation_stream.js +29 -23
  78. package/dist/_esm5.processed/core/stream/representation/types.d.ts +11 -1
  79. package/dist/_esm5.processed/default_config.d.ts +35 -98
  80. package/dist/_esm5.processed/default_config.js +36 -113
  81. package/dist/_esm5.processed/errors/custom_loader_error.d.ts +1 -3
  82. package/dist/_esm5.processed/errors/custom_loader_error.js +1 -3
  83. package/dist/_esm5.processed/errors/media_error.js +2 -2
  84. package/dist/_esm5.processed/errors/network_error.d.ts +0 -1
  85. package/dist/_esm5.processed/errors/network_error.js +0 -1
  86. package/dist/_esm5.processed/errors/request_error.d.ts +2 -3
  87. package/dist/_esm5.processed/errors/request_error.js +2 -5
  88. package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -3
  89. package/dist/_esm5.processed/features/features_object.js +0 -2
  90. package/dist/_esm5.processed/features/list/directfile.js +2 -5
  91. package/dist/_esm5.processed/features/list/index.d.ts +0 -2
  92. package/dist/_esm5.processed/features/list/index.js +0 -2
  93. package/dist/_esm5.processed/features/types.d.ts +3 -27
  94. package/dist/_esm5.processed/manifest/adaptation.d.ts +9 -11
  95. package/dist/_esm5.processed/manifest/adaptation.js +41 -30
  96. package/dist/_esm5.processed/manifest/index.d.ts +3 -4
  97. package/dist/_esm5.processed/manifest/manifest.d.ts +5 -54
  98. package/dist/_esm5.processed/manifest/manifest.js +5 -110
  99. package/dist/_esm5.processed/manifest/period.d.ts +4 -5
  100. package/dist/_esm5.processed/manifest/representation.d.ts +10 -5
  101. package/dist/_esm5.processed/manifest/representation.js +15 -5
  102. package/dist/_esm5.processed/manifest/representation_index/index.d.ts +2 -2
  103. package/dist/_esm5.processed/manifest/representation_index/static.d.ts +2 -0
  104. package/dist/_esm5.processed/manifest/representation_index/static.js +6 -0
  105. package/dist/_esm5.processed/manifest/representation_index/types.d.ts +42 -21
  106. package/dist/_esm5.processed/manifest/types.d.ts +0 -2
  107. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.d.ts +17 -31
  108. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.js +26 -19
  109. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.d.ts +2 -0
  110. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.js +7 -1
  111. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.d.ts +2 -6
  112. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.js +11 -8
  113. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +2 -0
  114. package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +6 -0
  115. package/dist/_esm5.processed/parsers/manifest/dash/common/infer_adaptation_type.d.ts +2 -2
  116. package/dist/_esm5.processed/parsers/manifest/dash/common/infer_adaptation_type.js +1 -6
  117. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_adaptation_sets.js +3 -5
  118. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_mpd.d.ts +0 -2
  119. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_mpd.js +1 -1
  120. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_periods.js +2 -2
  121. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representation_index.d.ts +0 -2
  122. package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representation_index.js +2 -2
  123. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/AdaptationSet.js +10 -6
  124. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/Representation.js +4 -2
  125. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/utils.d.ts +10 -1
  126. package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/utils.js +18 -2
  127. package/dist/_esm5.processed/parsers/manifest/dash/node_parser_types.d.ts +4 -4
  128. package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/generators/AdaptationSet.js +3 -6
  129. package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/generators/Representation.js +1 -2
  130. package/dist/_esm5.processed/parsers/manifest/local/representation_index.d.ts +2 -0
  131. package/dist/_esm5.processed/parsers/manifest/local/representation_index.js +6 -0
  132. package/dist/_esm5.processed/parsers/manifest/metaplaylist/metaplaylist_parser.js +6 -6
  133. package/dist/_esm5.processed/parsers/manifest/metaplaylist/representation_index.d.ts +12 -3
  134. package/dist/_esm5.processed/parsers/manifest/metaplaylist/representation_index.js +11 -2
  135. package/dist/_esm5.processed/parsers/manifest/smooth/create_parser.d.ts +0 -1
  136. package/dist/_esm5.processed/parsers/manifest/smooth/create_parser.js +11 -17
  137. package/dist/_esm5.processed/parsers/manifest/smooth/representation_index.d.ts +21 -83
  138. package/dist/_esm5.processed/parsers/manifest/smooth/representation_index.js +53 -125
  139. package/dist/_esm5.processed/parsers/manifest/smooth/shared_smooth_segment_timeline.d.ts +119 -0
  140. package/dist/_esm5.processed/parsers/manifest/smooth/shared_smooth_segment_timeline.js +159 -0
  141. package/dist/_esm5.processed/parsers/manifest/smooth/utils/add_segment_infos.d.ts +3 -6
  142. package/dist/_esm5.processed/parsers/manifest/smooth/utils/add_segment_infos.js +4 -4
  143. package/dist/_esm5.processed/parsers/manifest/types.d.ts +3 -3
  144. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_extent.js +1 -8
  145. package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_origin.js +1 -9
  146. package/dist/_esm5.processed/public_types.d.ts +396 -308
  147. package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.d.ts +5 -4
  148. package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.js +5 -4
  149. package/dist/_esm5.processed/transports/dash/add_segment_integrity_checks_to_loader.js +4 -4
  150. package/dist/_esm5.processed/transports/dash/manifest_parser.js +2 -3
  151. package/dist/_esm5.processed/transports/dash/pipelines.js +1 -4
  152. package/dist/_esm5.processed/transports/dash/segment_loader.d.ts +2 -2
  153. package/dist/_esm5.processed/transports/dash/segment_loader.js +26 -20
  154. package/dist/_esm5.processed/transports/dash/segment_parser.js +19 -24
  155. package/dist/_esm5.processed/transports/dash/text_loader.js +5 -5
  156. package/dist/_esm5.processed/transports/dash/text_parser.js +28 -33
  157. package/dist/_esm5.processed/transports/local/pipelines.js +1 -10
  158. package/dist/_esm5.processed/transports/local/segment_loader.js +2 -2
  159. package/dist/_esm5.processed/transports/local/segment_parser.d.ts +1 -1
  160. package/dist/_esm5.processed/transports/local/segment_parser.js +10 -10
  161. package/dist/_esm5.processed/transports/local/text_parser.d.ts +2 -2
  162. package/dist/_esm5.processed/transports/local/text_parser.js +23 -23
  163. package/dist/_esm5.processed/transports/metaplaylist/pipelines.js +34 -52
  164. package/dist/_esm5.processed/{utils/list_to_map.d.ts → transports/smooth/is_mp4_embedded_track.d.ts} +5 -5
  165. package/dist/_esm5.processed/{features/list/image_buffer.d.ts → transports/smooth/is_mp4_embedded_track.js} +7 -6
  166. package/dist/_esm5.processed/transports/smooth/pipelines.js +33 -190
  167. package/dist/_esm5.processed/transports/smooth/segment_loader.d.ts +1 -1
  168. package/dist/_esm5.processed/transports/smooth/segment_loader.js +28 -22
  169. package/dist/_esm5.processed/transports/smooth/utils.d.ts +1 -26
  170. package/dist/_esm5.processed/transports/smooth/utils.js +1 -55
  171. package/dist/_esm5.processed/transports/types.d.ts +94 -89
  172. package/dist/_esm5.processed/transports/utils/call_custom_manifest_loader.js +3 -3
  173. package/dist/_esm5.processed/transports/utils/infer_segment_container.d.ts +3 -3
  174. package/dist/_esm5.processed/transports/utils/infer_segment_container.js +5 -7
  175. package/dist/_esm5.processed/transports/utils/parse_text_track.d.ts +8 -12
  176. package/dist/_esm5.processed/transports/utils/parse_text_track.js +19 -21
  177. package/dist/_esm5.processed/utils/array_includes.d.ts +2 -1
  178. package/dist/_esm5.processed/utils/array_includes.js +30 -28
  179. package/dist/_esm5.processed/utils/request/xhr.js +5 -5
  180. package/dist/commonjs/compat/is_codec_supported.js +22 -1
  181. package/dist/commonjs/config.d.ts +1 -0
  182. package/dist/commonjs/core/api/debug/buffer_graph.js +2 -6
  183. package/dist/commonjs/core/api/debug/modules/general_info.js +17 -10
  184. package/dist/commonjs/core/api/option_utils.d.ts +2 -0
  185. package/dist/commonjs/core/api/option_utils.js +2 -3
  186. package/dist/commonjs/core/api/public_api.d.ts +9 -0
  187. package/dist/commonjs/core/api/public_api.js +34 -9
  188. package/dist/commonjs/core/fetchers/manifest/manifest_fetcher.d.ts +6 -0
  189. package/dist/commonjs/core/fetchers/manifest/manifest_fetcher.js +11 -3
  190. package/dist/commonjs/core/fetchers/segment/segment_fetcher.d.ts +8 -1
  191. package/dist/commonjs/core/fetchers/segment/segment_fetcher.js +8 -4
  192. package/dist/commonjs/core/fetchers/segment/segment_fetcher_creator.d.ts +1 -0
  193. package/dist/commonjs/core/fetchers/utils/schedule_request.js +1 -1
  194. package/dist/commonjs/core/init/directfile_content_initializer.js +24 -7
  195. package/dist/commonjs/core/init/media_source_content_initializer.d.ts +6 -0
  196. package/dist/commonjs/core/init/media_source_content_initializer.js +4 -6
  197. package/dist/commonjs/core/init/utils/content_time_boundaries_observer.d.ts +13 -12
  198. package/dist/commonjs/core/init/utils/content_time_boundaries_observer.js +16 -17
  199. package/dist/commonjs/core/init/utils/get_initial_time.d.ts +17 -3
  200. package/dist/commonjs/core/init/utils/get_initial_time.js +9 -7
  201. package/dist/commonjs/core/stream/representation/utils/get_buffer_status.js +3 -3
  202. package/dist/commonjs/core/stream/representation/utils/get_needed_segments.js +1 -1
  203. package/dist/commonjs/default_config.d.ts +5 -0
  204. package/dist/commonjs/default_config.js +5 -0
  205. package/dist/commonjs/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -1
  206. package/dist/commonjs/experimental/tools/createMetaplaylist/get_duration_from_manifest.js +2 -0
  207. package/dist/commonjs/manifest/representation_index/static.d.ts +1 -1
  208. package/dist/commonjs/manifest/representation_index/static.js +2 -2
  209. package/dist/commonjs/manifest/representation_index/types.d.ts +4 -4
  210. package/dist/commonjs/parsers/manifest/dash/common/indexes/base.d.ts +6 -1
  211. package/dist/commonjs/parsers/manifest/dash/common/indexes/base.js +4 -3
  212. package/dist/commonjs/parsers/manifest/dash/common/indexes/get_segments_from_timeline.d.ts +5 -2
  213. package/dist/commonjs/parsers/manifest/dash/common/indexes/get_segments_from_timeline.js +15 -4
  214. package/dist/commonjs/parsers/manifest/dash/common/indexes/index.d.ts +5 -5
  215. package/dist/commonjs/parsers/manifest/dash/common/indexes/list.d.ts +1 -1
  216. package/dist/commonjs/parsers/manifest/dash/common/indexes/list.js +2 -2
  217. package/dist/commonjs/parsers/manifest/dash/common/indexes/template.d.ts +12 -5
  218. package/dist/commonjs/parsers/manifest/dash/common/indexes/template.js +42 -29
  219. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/index.d.ts +2 -1
  220. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +99 -6
  221. package/dist/commonjs/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +250 -51
  222. package/dist/commonjs/parsers/manifest/dash/common/manifest_bounds_calculator.d.ts +40 -17
  223. package/dist/commonjs/parsers/manifest/dash/common/manifest_bounds_calculator.js +38 -18
  224. package/dist/commonjs/parsers/manifest/dash/common/parse_adaptation_sets.js +13 -10
  225. package/dist/commonjs/parsers/manifest/dash/common/parse_mpd.js +27 -14
  226. package/dist/commonjs/parsers/manifest/dash/common/parse_periods.d.ts +1 -1
  227. package/dist/commonjs/parsers/manifest/dash/common/parse_periods.js +17 -18
  228. package/dist/commonjs/parsers/manifest/dash/common/parse_representation_index.d.ts +19 -6
  229. package/dist/commonjs/parsers/manifest/dash/common/parse_representation_index.js +21 -8
  230. package/dist/commonjs/parsers/manifest/dash/common/parse_representations.js +7 -3
  231. package/dist/commonjs/parsers/manifest/local/representation_index.d.ts +1 -1
  232. package/dist/commonjs/parsers/manifest/local/representation_index.js +3 -3
  233. package/dist/commonjs/parsers/manifest/metaplaylist/representation_index.d.ts +1 -1
  234. package/dist/commonjs/parsers/manifest/metaplaylist/representation_index.js +2 -2
  235. package/dist/commonjs/parsers/manifest/smooth/representation_index.d.ts +5 -5
  236. package/dist/commonjs/parsers/manifest/smooth/representation_index.js +25 -9
  237. package/dist/commonjs/parsers/manifest/utils/index_helpers.js +1 -1
  238. package/dist/commonjs/public_types.d.ts +78 -34
  239. package/dist/commonjs/transports/dash/init_segment_loader.js +10 -5
  240. package/dist/commonjs/transports/dash/manifest_parser.js +5 -2
  241. package/dist/commonjs/transports/dash/segment_loader.js +2 -1
  242. package/dist/commonjs/transports/dash/text_loader.js +2 -0
  243. package/dist/commonjs/transports/metaplaylist/manifest_loader.js +2 -1
  244. package/dist/commonjs/transports/metaplaylist/pipelines.js +4 -1
  245. package/dist/commonjs/transports/smooth/pipelines.js +4 -2
  246. package/dist/commonjs/transports/smooth/segment_loader.js +2 -1
  247. package/dist/commonjs/transports/types.d.ts +12 -0
  248. package/dist/commonjs/transports/utils/generate_manifest_loader.js +6 -3
  249. package/dist/commonjs/utils/request/fetch.d.ts +6 -0
  250. package/dist/commonjs/utils/request/fetch.js +29 -8
  251. package/dist/commonjs/utils/request/xhr.d.ts +11 -5
  252. package/dist/commonjs/utils/request/xhr.js +29 -8
  253. package/dist/es2017/compat/is_codec_supported.js +22 -1
  254. package/dist/es2017/config.d.ts +1 -0
  255. package/dist/es2017/core/api/debug/buffer_graph.js +2 -6
  256. package/dist/es2017/core/api/debug/modules/general_info.js +17 -10
  257. package/dist/es2017/core/api/option_utils.d.ts +2 -0
  258. package/dist/es2017/core/api/option_utils.js +2 -3
  259. package/dist/es2017/core/api/public_api.d.ts +9 -0
  260. package/dist/es2017/core/api/public_api.js +33 -8
  261. package/dist/es2017/core/fetchers/manifest/manifest_fetcher.d.ts +6 -0
  262. package/dist/es2017/core/fetchers/manifest/manifest_fetcher.js +11 -3
  263. package/dist/es2017/core/fetchers/segment/segment_fetcher.d.ts +8 -1
  264. package/dist/es2017/core/fetchers/segment/segment_fetcher.js +8 -4
  265. package/dist/es2017/core/fetchers/segment/segment_fetcher_creator.d.ts +1 -0
  266. package/dist/es2017/core/fetchers/utils/schedule_request.js +1 -1
  267. package/dist/es2017/core/init/directfile_content_initializer.js +24 -7
  268. package/dist/es2017/core/init/media_source_content_initializer.d.ts +6 -0
  269. package/dist/es2017/core/init/media_source_content_initializer.js +4 -6
  270. package/dist/es2017/core/init/utils/content_time_boundaries_observer.d.ts +13 -12
  271. package/dist/es2017/core/init/utils/content_time_boundaries_observer.js +16 -15
  272. package/dist/es2017/core/init/utils/get_initial_time.d.ts +17 -3
  273. package/dist/es2017/core/init/utils/get_initial_time.js +9 -7
  274. package/dist/es2017/core/stream/representation/utils/get_buffer_status.js +3 -3
  275. package/dist/es2017/core/stream/representation/utils/get_needed_segments.js +1 -1
  276. package/dist/es2017/default_config.d.ts +5 -0
  277. package/dist/es2017/default_config.js +5 -0
  278. package/dist/es2017/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -1
  279. package/dist/es2017/experimental/tools/createMetaplaylist/get_duration_from_manifest.js +2 -0
  280. package/dist/es2017/manifest/representation_index/static.d.ts +1 -1
  281. package/dist/es2017/manifest/representation_index/static.js +2 -2
  282. package/dist/es2017/manifest/representation_index/types.d.ts +4 -4
  283. package/dist/es2017/parsers/manifest/dash/common/indexes/base.d.ts +6 -1
  284. package/dist/es2017/parsers/manifest/dash/common/indexes/base.js +4 -3
  285. package/dist/es2017/parsers/manifest/dash/common/indexes/get_segments_from_timeline.d.ts +5 -2
  286. package/dist/es2017/parsers/manifest/dash/common/indexes/get_segments_from_timeline.js +15 -4
  287. package/dist/es2017/parsers/manifest/dash/common/indexes/index.d.ts +5 -5
  288. package/dist/es2017/parsers/manifest/dash/common/indexes/list.d.ts +1 -1
  289. package/dist/es2017/parsers/manifest/dash/common/indexes/list.js +2 -2
  290. package/dist/es2017/parsers/manifest/dash/common/indexes/template.d.ts +12 -5
  291. package/dist/es2017/parsers/manifest/dash/common/indexes/template.js +40 -27
  292. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/index.d.ts +2 -1
  293. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +99 -6
  294. package/dist/es2017/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +246 -51
  295. package/dist/es2017/parsers/manifest/dash/common/manifest_bounds_calculator.d.ts +40 -17
  296. package/dist/es2017/parsers/manifest/dash/common/manifest_bounds_calculator.js +38 -18
  297. package/dist/es2017/parsers/manifest/dash/common/parse_adaptation_sets.js +11 -8
  298. package/dist/es2017/parsers/manifest/dash/common/parse_mpd.js +27 -13
  299. package/dist/es2017/parsers/manifest/dash/common/parse_periods.d.ts +1 -1
  300. package/dist/es2017/parsers/manifest/dash/common/parse_periods.js +13 -16
  301. package/dist/es2017/parsers/manifest/dash/common/parse_representation_index.d.ts +19 -6
  302. package/dist/es2017/parsers/manifest/dash/common/parse_representation_index.js +10 -8
  303. package/dist/es2017/parsers/manifest/dash/common/parse_representations.js +7 -3
  304. package/dist/es2017/parsers/manifest/local/representation_index.d.ts +1 -1
  305. package/dist/es2017/parsers/manifest/local/representation_index.js +3 -3
  306. package/dist/es2017/parsers/manifest/metaplaylist/representation_index.d.ts +1 -1
  307. package/dist/es2017/parsers/manifest/metaplaylist/representation_index.js +2 -2
  308. package/dist/es2017/parsers/manifest/smooth/representation_index.d.ts +5 -5
  309. package/dist/es2017/parsers/manifest/smooth/representation_index.js +25 -9
  310. package/dist/es2017/parsers/manifest/utils/index_helpers.js +1 -1
  311. package/dist/es2017/public_types.d.ts +78 -34
  312. package/dist/es2017/transports/dash/init_segment_loader.js +5 -0
  313. package/dist/es2017/transports/dash/manifest_parser.js +3 -0
  314. package/dist/es2017/transports/dash/segment_loader.js +1 -0
  315. package/dist/es2017/transports/dash/text_loader.js +2 -0
  316. package/dist/es2017/transports/metaplaylist/manifest_loader.js +1 -0
  317. package/dist/es2017/transports/metaplaylist/pipelines.js +4 -1
  318. package/dist/es2017/transports/smooth/pipelines.js +2 -0
  319. package/dist/es2017/transports/smooth/segment_loader.js +1 -0
  320. package/dist/es2017/transports/types.d.ts +12 -0
  321. package/dist/es2017/transports/utils/generate_manifest_loader.js +3 -0
  322. package/dist/es2017/utils/request/fetch.d.ts +6 -0
  323. package/dist/es2017/utils/request/fetch.js +29 -8
  324. package/dist/es2017/utils/request/xhr.d.ts +11 -5
  325. package/dist/es2017/utils/request/xhr.js +30 -9
  326. package/dist/rx-player.js +723 -376
  327. package/dist/rx-player.min.js +1 -1
  328. package/package.json +3 -4
  329. package/scripts/update-version +2 -0
  330. package/sonar-project.properties +1 -1
  331. package/src/compat/is_codec_supported.ts +23 -1
  332. package/src/core/api/debug/buffer_graph.ts +2 -5
  333. package/src/core/api/debug/modules/general_info.ts +15 -10
  334. package/src/core/api/option_utils.ts +3 -3
  335. package/src/core/api/public_api.ts +35 -7
  336. package/src/core/fetchers/manifest/manifest_fetcher.ts +21 -3
  337. package/src/core/fetchers/segment/segment_fetcher.ts +19 -5
  338. package/src/core/fetchers/segment/segment_fetcher_creator.ts +1 -0
  339. package/src/core/fetchers/utils/schedule_request.ts +1 -1
  340. package/src/core/init/directfile_content_initializer.ts +23 -7
  341. package/src/core/init/media_source_content_initializer.ts +13 -7
  342. package/src/core/init/utils/content_time_boundaries_observer.ts +23 -22
  343. package/src/core/init/utils/get_initial_time.ts +25 -12
  344. package/src/core/stream/representation/utils/get_buffer_status.ts +3 -3
  345. package/src/core/stream/representation/utils/get_needed_segments.ts +2 -2
  346. package/src/default_config.ts +5 -0
  347. package/src/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.ts +3 -1
  348. package/src/experimental/tools/createMetaplaylist/get_duration_from_manifest.ts +2 -0
  349. package/src/manifest/representation_index/static.ts +2 -2
  350. package/src/manifest/representation_index/types.ts +4 -4
  351. package/src/parsers/manifest/dash/common/__tests__/manifest_bounds_calculator.test.ts +182 -36
  352. package/src/parsers/manifest/dash/common/indexes/base.ts +12 -4
  353. package/src/parsers/manifest/dash/common/indexes/get_segments_from_timeline.ts +19 -5
  354. package/src/parsers/manifest/dash/common/indexes/index.ts +16 -4
  355. package/src/parsers/manifest/dash/common/indexes/list.ts +2 -2
  356. package/src/parsers/manifest/dash/common/indexes/template.ts +52 -31
  357. package/src/parsers/manifest/dash/common/indexes/timeline/index.ts +4 -1
  358. package/src/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.ts +366 -60
  359. package/src/parsers/manifest/dash/common/manifest_bounds_calculator.ts +63 -25
  360. package/src/parsers/manifest/dash/common/parse_adaptation_sets.ts +10 -4
  361. package/src/parsers/manifest/dash/common/parse_mpd.ts +28 -15
  362. package/src/parsers/manifest/dash/common/parse_periods.ts +12 -17
  363. package/src/parsers/manifest/dash/common/parse_representation_index.ts +50 -26
  364. package/src/parsers/manifest/dash/common/parse_representations.ts +9 -3
  365. package/src/parsers/manifest/local/representation_index.ts +3 -3
  366. package/src/parsers/manifest/metaplaylist/representation_index.ts +2 -2
  367. package/src/parsers/manifest/smooth/representation_index.ts +23 -9
  368. package/src/parsers/manifest/utils/__tests__/get_first_time_from_adaptations.test.ts +1 -1
  369. package/src/parsers/manifest/utils/__tests__/get_last_time_from_adaptation.test.ts +1 -1
  370. package/src/parsers/manifest/utils/index_helpers.ts +1 -1
  371. package/src/public_types.ts +79 -34
  372. package/src/transports/dash/init_segment_loader.ts +5 -0
  373. package/src/transports/dash/manifest_parser.ts +6 -0
  374. package/src/transports/dash/segment_loader.ts +1 -0
  375. package/src/transports/dash/text_loader.ts +2 -0
  376. package/src/transports/metaplaylist/manifest_loader.ts +1 -0
  377. package/src/transports/metaplaylist/pipelines.ts +4 -1
  378. package/src/transports/smooth/pipelines.ts +2 -0
  379. package/src/transports/smooth/segment_loader.ts +1 -0
  380. package/src/transports/types.ts +12 -0
  381. package/src/transports/utils/generate_manifest_loader.ts +3 -0
  382. package/src/utils/request/fetch.ts +35 -8
  383. package/src/utils/request/xhr.ts +45 -14
  384. package/dist/_esm5.processed/compat/fullscreen.d.ts +0 -32
  385. package/dist/_esm5.processed/compat/fullscreen.js +0 -78
  386. package/dist/_esm5.processed/compat/is_offline.d.ts +0 -39
  387. package/dist/_esm5.processed/compat/is_offline.js +0 -43
  388. package/dist/_esm5.processed/core/api/tracks_management/track_choice_manager.d.ts +0 -258
  389. package/dist/_esm5.processed/core/api/tracks_management/track_choice_manager.js +0 -989
  390. package/dist/_esm5.processed/core/segment_buffers/implementations/image/image_segment_buffer.d.ts +0 -75
  391. package/dist/_esm5.processed/core/segment_buffers/implementations/image/image_segment_buffer.js +0 -133
  392. package/dist/_esm5.processed/features/list/bif_parser.d.ts +0 -23
  393. package/dist/_esm5.processed/features/list/bif_parser.js +0 -27
  394. package/dist/_esm5.processed/features/list/image_buffer.js +0 -25
  395. package/dist/_esm5.processed/transports/dash/image_pipelines.d.ts +0 -38
  396. package/dist/_esm5.processed/transports/dash/image_pipelines.js +0 -129
  397. package/dist/_esm5.processed/utils/list_to_map.js +0 -28
  398. package/dist/_esm5.processed/utils/simple_set.d.ts +0 -51
  399. package/dist/_esm5.processed/utils/simple_set.js +0 -57
  400. package/dist/_esm5.processed/utils/uniq.d.ts +0 -36
  401. package/dist/_esm5.processed/utils/uniq.js +0 -43
  402. package/dist/commonjs/parsers/manifest/utils/is_segment_still_available.d.ts +0 -29
  403. package/dist/commonjs/parsers/manifest/utils/is_segment_still_available.js +0 -54
  404. package/dist/es2017/parsers/manifest/utils/is_segment_still_available.d.ts +0 -29
  405. package/dist/es2017/parsers/manifest/utils/is_segment_still_available.js +0 -51
  406. package/src/parsers/manifest/utils/is_segment_still_available.ts +0 -58
  407. package/src/typings/object-assign.d.ts +0 -48
@@ -1,989 +0,0 @@
1
- /**
2
- * Copyright 2015 CANAL+ Group
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- /**
17
- * This file is used to abstract the notion of text, audio and video tracks
18
- * switching for an easier API management.
19
- */
20
- import log from "../../../log";
21
- import arrayFind from "../../../utils/array_find";
22
- import arrayIncludes from "../../../utils/array_includes";
23
- import isNullOrUndefined from "../../../utils/is_null_or_undefined";
24
- import normalizeLanguage from "../../../utils/languages";
25
- import objectAssign from "../../../utils/object_assign";
26
- import SortedList from "../../../utils/sorted_list";
27
- /**
28
- * Transform an array of IAudioTrackPreference into an array of
29
- * INormalizedPreferredAudioTrack to be exploited by the TrackChoiceManager.
30
- * @param {Array.<Object|null>} tracks
31
- * @returns {Array.<Object|null>}
32
- */
33
- function normalizeAudioTracks(tracks) {
34
- return tracks.map(function (t) { return t === null ?
35
- t :
36
- { normalized: t.language === undefined ? undefined :
37
- normalizeLanguage(t.language),
38
- audioDescription: t.audioDescription,
39
- codec: t.codec }; });
40
- }
41
- /**
42
- * Transform an array of ITextTrackPreference into an array of
43
- * INormalizedPreferredTextTrack to be exploited by the TrackChoiceManager.
44
- * @param {Array.<Object|null>} tracks
45
- * @returns {Array.<Object|null>}
46
- */
47
- function normalizeTextTracks(tracks) {
48
- return tracks.map(function (t) { return t === null ?
49
- t :
50
- { normalized: normalizeLanguage(t.language),
51
- forced: t.forced,
52
- closedCaption: t.closedCaption }; });
53
- }
54
- /**
55
- * Manage audio and text tracks for all active periods.
56
- * Choose the audio and text tracks for each period and record this choice.
57
- * @class TrackChoiceManager
58
- */
59
- var TrackChoiceManager = /** @class */ (function () {
60
- function TrackChoiceManager(args) {
61
- this._periods = new SortedList(function (a, b) { return a.period.start - b.period.start; });
62
- this._audioChoiceMemory = new WeakMap();
63
- this._textChoiceMemory = new WeakMap();
64
- this._videoChoiceMemory = new WeakMap();
65
- this._preferredAudioTracks = [];
66
- this._preferredTextTracks = [];
67
- this._preferredVideoTracks = [];
68
- this.trickModeTrackEnabled = args.preferTrickModeTracks;
69
- }
70
- /**
71
- * Set the list of preferred audio tracks, in preference order.
72
- * @param {Array.<Object>} preferredAudioTracks
73
- * @param {boolean} shouldApply - `true` if those preferences should be
74
- * applied on the currently loaded Period. `false` if it should only
75
- * be applied to new content.
76
- */
77
- TrackChoiceManager.prototype.setPreferredAudioTracks = function (preferredAudioTracks, shouldApply) {
78
- this._preferredAudioTracks = preferredAudioTracks;
79
- if (shouldApply) {
80
- this._applyAudioPreferences();
81
- }
82
- };
83
- /**
84
- * Set the list of preferred text tracks, in preference order.
85
- * @param {Array.<Object>} preferredTextTracks
86
- * @param {boolean} shouldApply - `true` if those preferences should be
87
- * applied on the currently loaded Periods. `false` if it should only
88
- * be applied to new content.
89
- */
90
- TrackChoiceManager.prototype.setPreferredTextTracks = function (preferredTextTracks, shouldApply) {
91
- this._preferredTextTracks = preferredTextTracks;
92
- if (shouldApply) {
93
- this._applyTextPreferences();
94
- }
95
- };
96
- /**
97
- * Set the list of preferred text tracks, in preference order.
98
- * @param {Array.<Object>} preferredVideoTracks
99
- * @param {boolean} shouldApply - `true` if those preferences should be
100
- * applied on the currently loaded Period. `false` if it should only
101
- * be applied to new content.
102
- */
103
- TrackChoiceManager.prototype.setPreferredVideoTracks = function (preferredVideoTracks, shouldApply) {
104
- this._preferredVideoTracks = preferredVideoTracks;
105
- if (shouldApply) {
106
- this._applyVideoPreferences();
107
- }
108
- };
109
- /**
110
- * Add shared reference to choose Adaptation for new "audio" or "text" Period.
111
- * @param {string} bufferType - The concerned buffer type
112
- * @param {Period} period - The concerned Period.
113
- * @param {Object} adaptationRef
114
- */
115
- TrackChoiceManager.prototype.addPeriod = function (bufferType, period, adaptationRef) {
116
- var _a;
117
- var periodItem = getPeriodItem(this._periods, period);
118
- var adaptations = period.getSupportedAdaptations(bufferType);
119
- if (periodItem !== undefined) {
120
- if (periodItem[bufferType] !== undefined) {
121
- log.warn("TrackChoiceManager: ".concat(bufferType, " already added for period"), period.start);
122
- return;
123
- }
124
- else {
125
- periodItem[bufferType] = { adaptations: adaptations, adaptationRef: adaptationRef };
126
- }
127
- }
128
- else {
129
- this._periods.add((_a = { period: period }, _a[bufferType] = { adaptations: adaptations, adaptationRef: adaptationRef }, _a));
130
- }
131
- };
132
- /**
133
- * Remove shared reference to choose an "audio", "video" or "text" Adaptation
134
- * for a Period.
135
- * @param {string} bufferType - The concerned buffer type
136
- * @param {Period} period - The concerned Period.
137
- */
138
- TrackChoiceManager.prototype.removePeriod = function (bufferType, period) {
139
- var periodIndex = findPeriodIndex(this._periods, period);
140
- if (periodIndex === undefined) {
141
- log.warn("TrackChoiceManager: ".concat(bufferType, " not found for period"), period.start);
142
- return;
143
- }
144
- var periodItem = this._periods.get(periodIndex);
145
- if (periodItem[bufferType] === undefined) {
146
- log.warn("TrackChoiceManager: ".concat(bufferType, " already removed for period"), period.start);
147
- return;
148
- }
149
- delete periodItem[bufferType];
150
- if (periodItem.audio === undefined &&
151
- periodItem.text === undefined &&
152
- periodItem.video === undefined) {
153
- this._periods.removeElement(periodItem);
154
- }
155
- };
156
- TrackChoiceManager.prototype.resetPeriods = function () {
157
- while (this._periods.length() > 0) {
158
- this._periods.pop();
159
- }
160
- };
161
- /**
162
- * Update the choice of all added Periods based on:
163
- * 1. What was the last chosen adaptation
164
- * 2. If not found, the preferences
165
- */
166
- TrackChoiceManager.prototype.update = function () {
167
- this._resetChosenAudioTracks();
168
- this._resetChosenTextTracks();
169
- this._resetChosenVideoTracks();
170
- };
171
- /**
172
- * Emit initial audio Adaptation through the given shared reference based on:
173
- * - the preferred audio tracks
174
- * - the last choice for this period, if one
175
- * @param {Period} period - The concerned Period.
176
- */
177
- TrackChoiceManager.prototype.setInitialAudioTrack = function (period) {
178
- var periodItem = getPeriodItem(this._periods, period);
179
- var audioInfos = periodItem !== undefined ? periodItem.audio :
180
- null;
181
- if (isNullOrUndefined(audioInfos) || periodItem === undefined) {
182
- throw new Error("TrackChoiceManager: Given Period not found.");
183
- }
184
- var audioAdaptations = period.getSupportedAdaptations("audio");
185
- var chosenAudioAdaptation = this._audioChoiceMemory.get(period);
186
- if (chosenAudioAdaptation === null) {
187
- // If the Period was previously without audio, keep it that way
188
- audioInfos.adaptationRef.setValue(null);
189
- }
190
- else if (chosenAudioAdaptation === undefined ||
191
- !arrayIncludes(audioAdaptations, chosenAudioAdaptation)) {
192
- // Find the optimal audio Adaptation
193
- var preferredAudioTracks = this._preferredAudioTracks;
194
- var normalizedPref = normalizeAudioTracks(preferredAudioTracks);
195
- var optimalAdaptation = findFirstOptimalAudioAdaptation(audioAdaptations, normalizedPref);
196
- this._audioChoiceMemory.set(period, optimalAdaptation);
197
- audioInfos.adaptationRef.setValue(optimalAdaptation);
198
- }
199
- else {
200
- audioInfos.adaptationRef.setValue(chosenAudioAdaptation); // set last one
201
- }
202
- };
203
- /**
204
- * Emit initial text Adaptation through the given shared reference based on:
205
- * - the preferred text tracks
206
- * - the last choice for this period, if one
207
- * @param {Period} period - The concerned Period.
208
- */
209
- TrackChoiceManager.prototype.setInitialTextTrack = function (period) {
210
- var periodItem = getPeriodItem(this._periods, period);
211
- var textInfos = periodItem !== undefined ? periodItem.text :
212
- null;
213
- if (isNullOrUndefined(textInfos) || periodItem === undefined) {
214
- throw new Error("TrackChoiceManager: Given Period not found.");
215
- }
216
- var textAdaptations = period.getSupportedAdaptations("text");
217
- var chosenTextAdaptation = this._textChoiceMemory.get(period);
218
- if (chosenTextAdaptation === null) {
219
- // If the Period was previously without text, keep it that way
220
- textInfos.adaptationRef.setValue(null);
221
- }
222
- else if (chosenTextAdaptation === undefined ||
223
- !arrayIncludes(textAdaptations, chosenTextAdaptation)) {
224
- // Find the optimal text Adaptation
225
- var preferredTextTracks = this._preferredTextTracks;
226
- var normalizedPref = normalizeTextTracks(preferredTextTracks);
227
- var optimalAdaptation = findFirstOptimalTextAdaptation(textAdaptations, normalizedPref, this._audioChoiceMemory.get(period));
228
- this._textChoiceMemory.set(period, optimalAdaptation);
229
- textInfos.adaptationRef.setValue(optimalAdaptation);
230
- }
231
- else {
232
- textInfos.adaptationRef.setValue(chosenTextAdaptation); // set last one
233
- }
234
- };
235
- /**
236
- * Emit initial video Adaptation through the given shared reference based on:
237
- * - the preferred video tracks
238
- * - the last choice for this period, if one
239
- * @param {Period} period - The concerned Period.
240
- */
241
- TrackChoiceManager.prototype.setInitialVideoTrack = function (period) {
242
- var periodItem = getPeriodItem(this._periods, period);
243
- var videoInfos = periodItem !== undefined ? periodItem.video :
244
- null;
245
- if (isNullOrUndefined(videoInfos) || periodItem === undefined) {
246
- throw new Error("TrackChoiceManager: Given Period not found.");
247
- }
248
- var videoAdaptations = period.getSupportedAdaptations("video");
249
- var prevVideoAdaptation = this._videoChoiceMemory.get(period);
250
- var newBaseAdaptation;
251
- if (prevVideoAdaptation === null) {
252
- newBaseAdaptation = null;
253
- }
254
- else if (prevVideoAdaptation !== undefined &&
255
- arrayIncludes(videoAdaptations, prevVideoAdaptation.baseAdaptation)) {
256
- // still exists, re-select it
257
- newBaseAdaptation = prevVideoAdaptation.baseAdaptation;
258
- }
259
- else {
260
- // If that Adaptation does not exist (e.g. no choice has been made or it
261
- // is not in the Manifest anymore), look at preferences
262
- var preferredVideoTracks = this._preferredVideoTracks;
263
- newBaseAdaptation = findFirstOptimalVideoAdaptation(videoAdaptations, preferredVideoTracks);
264
- }
265
- if (newBaseAdaptation === null) {
266
- this._videoChoiceMemory.set(period, null);
267
- videoInfos.adaptationRef.setValue(null);
268
- return;
269
- }
270
- var newVideoAdaptation = getRightVideoTrack(newBaseAdaptation, this.trickModeTrackEnabled);
271
- this._videoChoiceMemory.set(period, { baseAdaptation: newBaseAdaptation,
272
- adaptation: newVideoAdaptation });
273
- videoInfos.adaptationRef.setValue(newVideoAdaptation);
274
- };
275
- /**
276
- * Set audio track based on the ID of its adaptation for a given added Period.
277
- * @param {Period} period - The concerned Period.
278
- * @param {string} wantedId - adaptation id of the wanted track
279
- */
280
- TrackChoiceManager.prototype.setAudioTrackByID = function (period, wantedId) {
281
- var periodItem = getPeriodItem(this._periods, period);
282
- var audioInfos = periodItem !== undefined ? periodItem.audio :
283
- null;
284
- if (isNullOrUndefined(audioInfos)) {
285
- throw new Error("TrackChoiceManager: Given Period not found.");
286
- }
287
- var wantedAdaptation = arrayFind(audioInfos.adaptations, function (_a) {
288
- var id = _a.id;
289
- return id === wantedId;
290
- });
291
- if (wantedAdaptation === undefined) {
292
- throw new Error("Audio Track not found.");
293
- }
294
- var chosenAudioAdaptation = this._audioChoiceMemory.get(period);
295
- if (chosenAudioAdaptation === wantedAdaptation) {
296
- return;
297
- }
298
- this._audioChoiceMemory.set(period, wantedAdaptation);
299
- audioInfos.adaptationRef.setValue(wantedAdaptation);
300
- };
301
- /**
302
- * Set text track based on the ID of its adaptation for a given added Period.
303
- * @param {Period} period - The concerned Period.
304
- * @param {string} wantedId - adaptation id of the wanted track
305
- */
306
- TrackChoiceManager.prototype.setTextTrackByID = function (period, wantedId) {
307
- var periodItem = getPeriodItem(this._periods, period);
308
- var textInfos = periodItem !== undefined ? periodItem.text :
309
- null;
310
- if (isNullOrUndefined(textInfos)) {
311
- throw new Error("TrackChoiceManager: Given Period not found.");
312
- }
313
- var wantedAdaptation = arrayFind(textInfos.adaptations, function (_a) {
314
- var id = _a.id;
315
- return id === wantedId;
316
- });
317
- if (wantedAdaptation === undefined) {
318
- throw new Error("Text Track not found.");
319
- }
320
- var chosenTextAdaptation = this._textChoiceMemory.get(period);
321
- if (chosenTextAdaptation === wantedAdaptation) {
322
- return;
323
- }
324
- this._textChoiceMemory.set(period, wantedAdaptation);
325
- textInfos.adaptationRef.setValue(wantedAdaptation);
326
- };
327
- /**
328
- * Set video track based on the ID of its adaptation for a given added Period.
329
- * @param {Period} period - The concerned Period.
330
- * @param {string} wantedId - adaptation id of the wanted track
331
- *
332
- * @throws Error - Throws if the period given has not been added
333
- * @throws Error - Throws if the given id is not found in any video adaptation
334
- * of the given Period.
335
- */
336
- TrackChoiceManager.prototype.setVideoTrackByID = function (period, wantedId) {
337
- var periodItem = getPeriodItem(this._periods, period);
338
- var videoInfos = periodItem !== undefined ? periodItem.video :
339
- null;
340
- if (isNullOrUndefined(videoInfos)) {
341
- throw new Error("LanguageManager: Given Period not found.");
342
- }
343
- var wantedBaseAdaptation = arrayFind(videoInfos.adaptations, function (_a) {
344
- var id = _a.id;
345
- return id === wantedId;
346
- });
347
- if (wantedBaseAdaptation === undefined) {
348
- throw new Error("Video Track not found.");
349
- }
350
- var newVideoAdaptation = getRightVideoTrack(wantedBaseAdaptation, this.trickModeTrackEnabled);
351
- this._videoChoiceMemory.set(period, { baseAdaptation: wantedBaseAdaptation,
352
- adaptation: newVideoAdaptation });
353
- videoInfos.adaptationRef.setValue(newVideoAdaptation);
354
- };
355
- /**
356
- * Disable the current text track for a given period.
357
- *
358
- * @param {Period} period - The concerned Period.
359
- *
360
- * @throws Error - Throws if the period given has not been added
361
- */
362
- TrackChoiceManager.prototype.disableTextTrack = function (period) {
363
- var periodItem = getPeriodItem(this._periods, period);
364
- var textInfos = periodItem !== undefined ? periodItem.text :
365
- null;
366
- if (isNullOrUndefined(textInfos)) {
367
- throw new Error("TrackChoiceManager: Given Period not found.");
368
- }
369
- var chosenTextAdaptation = this._textChoiceMemory.get(period);
370
- if (chosenTextAdaptation === null) {
371
- return;
372
- }
373
- this._textChoiceMemory.set(period, null);
374
- textInfos.adaptationRef.setValue(null);
375
- };
376
- /**
377
- * Disable the current video track for a given period.
378
- * @param {Object} period
379
- * @throws Error - Throws if the period given has not been added
380
- */
381
- TrackChoiceManager.prototype.disableVideoTrack = function (period) {
382
- var periodItem = getPeriodItem(this._periods, period);
383
- var videoInfos = periodItem === null || periodItem === void 0 ? void 0 : periodItem.video;
384
- if (videoInfos === undefined) {
385
- throw new Error("TrackManager: Given Period not found.");
386
- }
387
- var chosenVideoAdaptation = this._videoChoiceMemory.get(period);
388
- if (chosenVideoAdaptation === null) {
389
- return;
390
- }
391
- this._videoChoiceMemory.set(period, null);
392
- videoInfos.adaptationRef.setValue(null);
393
- };
394
- TrackChoiceManager.prototype.disableVideoTrickModeTracks = function () {
395
- this.trickModeTrackEnabled = false;
396
- this._resetChosenVideoTracks();
397
- };
398
- TrackChoiceManager.prototype.enableVideoTrickModeTracks = function () {
399
- this.trickModeTrackEnabled = true;
400
- this._resetChosenVideoTracks();
401
- };
402
- /**
403
- * @returns {boolean}
404
- */
405
- TrackChoiceManager.prototype.isTrickModeEnabled = function () {
406
- return this.trickModeTrackEnabled;
407
- };
408
- /**
409
- * Returns an object describing the chosen audio track for the given audio
410
- * Period.
411
- *
412
- * Returns null is the the current audio track is disabled or not
413
- * set yet.
414
- *
415
- * @param {Period} period - The concerned Period.
416
- * @returns {Object|null} - The audio track chosen for this Period
417
- */
418
- TrackChoiceManager.prototype.getChosenAudioTrack = function (period) {
419
- var periodItem = getPeriodItem(this._periods, period);
420
- var audioInfos = periodItem !== undefined ? periodItem.audio :
421
- null;
422
- if (isNullOrUndefined(audioInfos)) {
423
- return null;
424
- }
425
- var chosenTrack = this._audioChoiceMemory.get(period);
426
- if (isNullOrUndefined(chosenTrack)) {
427
- return null;
428
- }
429
- return chosenTrack.toAudioTrack();
430
- };
431
- /**
432
- * Returns an object describing the chosen text track for the given text
433
- * Period.
434
- *
435
- * Returns null is the the current text track is disabled or not
436
- * set yet.
437
- *
438
- * @param {Period} period - The concerned Period.
439
- * @returns {Object|null} - The text track chosen for this Period
440
- */
441
- TrackChoiceManager.prototype.getChosenTextTrack = function (period) {
442
- var periodItem = getPeriodItem(this._periods, period);
443
- var textInfos = periodItem !== undefined ? periodItem.text :
444
- null;
445
- if (isNullOrUndefined(textInfos)) {
446
- return null;
447
- }
448
- var chosenTextAdaptation = this._textChoiceMemory.get(period);
449
- if (isNullOrUndefined(chosenTextAdaptation)) {
450
- return null;
451
- }
452
- return chosenTextAdaptation.toTextTrack();
453
- };
454
- /**
455
- * Returns an object describing the chosen video track for the given video
456
- * Period.
457
- *
458
- * Returns null is the the current video track is disabled or not
459
- * set yet.
460
- *
461
- * @param {Period} period - The concerned Period.
462
- * @returns {Object|null} - The video track chosen for this Period
463
- */
464
- TrackChoiceManager.prototype.getChosenVideoTrack = function (period) {
465
- var periodItem = getPeriodItem(this._periods, period);
466
- var videoInfos = periodItem !== undefined ? periodItem.video :
467
- null;
468
- if (isNullOrUndefined(videoInfos)) {
469
- return null;
470
- }
471
- var chosenVideoAdaptation = this._videoChoiceMemory.get(period);
472
- if (isNullOrUndefined(chosenVideoAdaptation)) {
473
- return null;
474
- }
475
- var currAdaptation = chosenVideoAdaptation.adaptation;
476
- return currAdaptation.toVideoTrack();
477
- };
478
- /**
479
- * Returns all available audio tracks for a given Period, as an array of
480
- * objects.
481
- *
482
- * @returns {Array.<Object>}
483
- */
484
- TrackChoiceManager.prototype.getAvailableAudioTracks = function (period) {
485
- var periodItem = getPeriodItem(this._periods, period);
486
- var audioInfos = periodItem !== undefined ? periodItem.audio :
487
- null;
488
- if (isNullOrUndefined(audioInfos)) {
489
- return [];
490
- }
491
- var chosenAudioAdaptation = this._audioChoiceMemory.get(period);
492
- var currentId = !isNullOrUndefined(chosenAudioAdaptation) ?
493
- chosenAudioAdaptation.id :
494
- null;
495
- return audioInfos.adaptations
496
- .map(function (adaptation) {
497
- var active = currentId === null ? false :
498
- currentId === adaptation.id;
499
- return objectAssign(adaptation.toAudioTrack(), { active: active });
500
- });
501
- };
502
- /**
503
- * Returns all available text tracks for a given Period, as an array of
504
- * objects.
505
- *
506
- * @param {Period} period
507
- * @returns {Array.<Object>}
508
- */
509
- TrackChoiceManager.prototype.getAvailableTextTracks = function (period) {
510
- var periodItem = getPeriodItem(this._periods, period);
511
- var textInfos = periodItem !== undefined ? periodItem.text :
512
- null;
513
- if (isNullOrUndefined(textInfos)) {
514
- return [];
515
- }
516
- var chosenTextAdaptation = this._textChoiceMemory.get(period);
517
- var currentId = !isNullOrUndefined(chosenTextAdaptation) ?
518
- chosenTextAdaptation.id :
519
- null;
520
- return textInfos.adaptations
521
- .map(function (adaptation) {
522
- var active = currentId === null ? false :
523
- currentId === adaptation.id;
524
- return objectAssign(adaptation.toTextTrack(), { active: active });
525
- });
526
- };
527
- /**
528
- * Returns all available video tracks for a given Period, as an array of
529
- * objects.
530
- *
531
- * @returns {Array.<Object>}
532
- */
533
- TrackChoiceManager.prototype.getAvailableVideoTracks = function (period) {
534
- var _a;
535
- var periodItem = getPeriodItem(this._periods, period);
536
- var videoInfos = periodItem !== undefined ? periodItem.video :
537
- null;
538
- if (isNullOrUndefined(videoInfos)) {
539
- return [];
540
- }
541
- var chosenVideoAdaptation = this._videoChoiceMemory.get(period);
542
- var currentId = chosenVideoAdaptation === undefined ?
543
- undefined :
544
- (_a = chosenVideoAdaptation === null || chosenVideoAdaptation === void 0 ? void 0 : chosenVideoAdaptation.adaptation.id) !== null && _a !== void 0 ? _a : undefined;
545
- return videoInfos.adaptations
546
- .map(function (adaptation) {
547
- var active = currentId === null ? false :
548
- currentId === adaptation.id;
549
- var track = adaptation.toVideoTrack();
550
- var trickModeTracks = track.trickModeTracks !== undefined ?
551
- track.trickModeTracks.map(function (trickModeAdaptation) {
552
- var isActive = currentId === null ? false :
553
- currentId === trickModeAdaptation.id;
554
- return objectAssign(trickModeAdaptation, { active: isActive });
555
- }) :
556
- [];
557
- var availableTrack = objectAssign(track, { active: active });
558
- if (trickModeTracks !== undefined) {
559
- availableTrack.trickModeTracks = trickModeTracks;
560
- }
561
- return availableTrack;
562
- });
563
- };
564
- /**
565
- * Reset all audio tracks choices to corresponds to the current preferences.
566
- */
567
- TrackChoiceManager.prototype._applyAudioPreferences = function () {
568
- // Remove all memorized choices and start over
569
- this._audioChoiceMemory = new WeakMap();
570
- this._resetChosenAudioTracks();
571
- };
572
- /**
573
- * Reset all text tracks choices to corresponds to the current preferences.
574
- */
575
- TrackChoiceManager.prototype._applyTextPreferences = function () {
576
- // Remove all memorized choices and start over
577
- this._textChoiceMemory = new WeakMap();
578
- this._resetChosenTextTracks();
579
- };
580
- /**
581
- * Reset all video tracks choices to corresponds to the current preferences.
582
- */
583
- TrackChoiceManager.prototype._applyVideoPreferences = function () {
584
- // Remove all memorized choices and start over
585
- this._videoChoiceMemory = new WeakMap();
586
- this._resetChosenVideoTracks();
587
- };
588
- /**
589
- * Choose again the best audio tracks for all current Periods.
590
- * This is based on two things:
591
- * 1. what was the track previously chosen for that Period (by checking
592
- * `this._audioChoiceMemory`).
593
- * 2. If no track were previously chosen or if it is not available anymore
594
- * we check the audio preferences.
595
- */
596
- TrackChoiceManager.prototype._resetChosenAudioTracks = function () {
597
- var _this = this;
598
- var preferredAudioTracks = this._preferredAudioTracks;
599
- var normalizedPref = normalizeAudioTracks(preferredAudioTracks);
600
- var recursiveUpdateAudioTrack = function (index) {
601
- if (index >= _this._periods.length()) {
602
- // we did all audio Periods, exit
603
- return;
604
- }
605
- var periodItem = _this._periods.get(index);
606
- if (isNullOrUndefined(periodItem.audio)) {
607
- // No audio choice for this period, check next one
608
- recursiveUpdateAudioTrack(index + 1);
609
- return;
610
- }
611
- var period = periodItem.period, audioItem = periodItem.audio;
612
- var audioAdaptations = period.getSupportedAdaptations("audio");
613
- var chosenAudioAdaptation = _this._audioChoiceMemory.get(period);
614
- if (chosenAudioAdaptation === null ||
615
- (chosenAudioAdaptation !== undefined &&
616
- arrayIncludes(audioAdaptations, chosenAudioAdaptation))) {
617
- // Already best audio for this Period, check next one
618
- recursiveUpdateAudioTrack(index + 1);
619
- return;
620
- }
621
- var optimalAdaptation = findFirstOptimalAudioAdaptation(audioAdaptations, normalizedPref);
622
- _this._audioChoiceMemory.set(period, optimalAdaptation);
623
- audioItem.adaptationRef.setValue(optimalAdaptation);
624
- // previous "next" call could have changed everything, start over
625
- recursiveUpdateAudioTrack(0);
626
- };
627
- recursiveUpdateAudioTrack(0);
628
- };
629
- /**
630
- * Choose again the best text tracks for all current Periods.
631
- * This is based on two things:
632
- * 1. what was the track previously chosen for that Period (by checking
633
- * `this._textChoiceMemory`).
634
- * 2. If no track were previously chosen or if it is not available anymore
635
- * we check the text preferences.
636
- */
637
- TrackChoiceManager.prototype._resetChosenTextTracks = function () {
638
- var _this = this;
639
- var preferredTextTracks = this._preferredTextTracks;
640
- var normalizedPref = normalizeTextTracks(preferredTextTracks);
641
- var recursiveUpdateTextTrack = function (index) {
642
- if (index >= _this._periods.length()) {
643
- // we did all text Periods, exit
644
- return;
645
- }
646
- var periodItem = _this._periods.get(index);
647
- if (isNullOrUndefined(periodItem.text)) {
648
- // No text choice for this period, check next one
649
- recursiveUpdateTextTrack(index + 1);
650
- return;
651
- }
652
- var period = periodItem.period, textItem = periodItem.text;
653
- var textAdaptations = period.getSupportedAdaptations("text");
654
- var chosenTextAdaptation = _this._textChoiceMemory.get(period);
655
- if (chosenTextAdaptation === null ||
656
- (chosenTextAdaptation !== undefined &&
657
- arrayIncludes(textAdaptations, chosenTextAdaptation))) {
658
- // Already best text for this Period, check next one
659
- recursiveUpdateTextTrack(index + 1);
660
- return;
661
- }
662
- var optimalAdaptation = findFirstOptimalTextAdaptation(textAdaptations, normalizedPref, _this._audioChoiceMemory.get(period));
663
- _this._textChoiceMemory.set(period, optimalAdaptation);
664
- textItem.adaptationRef.setValue(optimalAdaptation);
665
- // previous "next" call could have changed everything, start over
666
- recursiveUpdateTextTrack(0);
667
- };
668
- recursiveUpdateTextTrack(0);
669
- };
670
- /**
671
- * Choose again the best video tracks for all current Periods.
672
- * This is based on two things:
673
- * 1. what was the track previously chosen for that Period (by checking
674
- * `this._videoChoiceMemory`).
675
- * 2. If no track were previously chosen or if it is not available anymore
676
- * we check the video preferences.
677
- */
678
- TrackChoiceManager.prototype._resetChosenVideoTracks = function () {
679
- var _this = this;
680
- var preferredVideoTracks = this._preferredVideoTracks;
681
- var recursiveUpdateVideoTrack = function (index) {
682
- if (index >= _this._periods.length()) {
683
- // we did all video Periods, exit
684
- return;
685
- }
686
- var periodItem = _this._periods.get(index);
687
- if (isNullOrUndefined(periodItem.video)) {
688
- // No video choice for this period, check next one
689
- recursiveUpdateVideoTrack(index + 1);
690
- return;
691
- }
692
- var period = periodItem.period, videoItem = periodItem.video;
693
- var videoAdaptations = period.getSupportedAdaptations("video");
694
- var chosenVideoAdaptation = _this._videoChoiceMemory.get(period);
695
- if (chosenVideoAdaptation === null) {
696
- // No video track for that one, so nothing to change.
697
- recursiveUpdateVideoTrack(index + 1);
698
- return;
699
- }
700
- else if (chosenVideoAdaptation !== undefined &&
701
- arrayIncludes(videoAdaptations, chosenVideoAdaptation.baseAdaptation)) {
702
- // The right Base Adaptation is selected and is still available.
703
- // Check if the selected Adaptation is still right
704
- var wantedVideoAdaptation = getRightVideoTrack(chosenVideoAdaptation.baseAdaptation, _this.trickModeTrackEnabled);
705
- if (wantedVideoAdaptation.id === chosenVideoAdaptation.adaptation.id) {
706
- // We're good, continue.
707
- recursiveUpdateVideoTrack(index + 1);
708
- return;
709
- }
710
- else {
711
- // select the right track
712
- _this._videoChoiceMemory.set(period, {
713
- baseAdaptation: chosenVideoAdaptation.baseAdaptation,
714
- adaptation: wantedVideoAdaptation,
715
- });
716
- videoItem.adaptationRef.setValue(wantedVideoAdaptation);
717
- // previous "next" call could have changed everything, start over
718
- return recursiveUpdateVideoTrack(0);
719
- }
720
- }
721
- var optimalAdaptation = findFirstOptimalVideoAdaptation(videoAdaptations, preferredVideoTracks);
722
- if (optimalAdaptation === null) {
723
- _this._videoChoiceMemory.set(period, null);
724
- videoItem.adaptationRef.setValue(null);
725
- // previous "next" call could have changed everything, start over
726
- return recursiveUpdateVideoTrack(0);
727
- }
728
- var newVideoAdaptation = getRightVideoTrack(optimalAdaptation, _this.trickModeTrackEnabled);
729
- _this._videoChoiceMemory.set(period, { baseAdaptation: optimalAdaptation,
730
- adaptation: newVideoAdaptation });
731
- videoItem.adaptationRef.setValue(newVideoAdaptation);
732
- // previous "next" call could have changed everything, start over
733
- return recursiveUpdateVideoTrack(0);
734
- };
735
- recursiveUpdateVideoTrack(0);
736
- };
737
- return TrackChoiceManager;
738
- }());
739
- export default TrackChoiceManager;
740
- /**
741
- * Create a function allowing to compare audio Adaptations with a given
742
- * `preferredAudioTrack` preference to see if they match.
743
- *
744
- * This function is curried to be easily and optimally used in a loop context.
745
- *
746
- * @param {Object} preferredAudioTrack - The audio track preference you want to
747
- * compare audio Adaptations to.
748
- * @returns {Function} - Function taking in argument an audio Adaptation and
749
- * returning `true` if it matches the `preferredAudioTrack` preference (and
750
- * `false` otherwise.
751
- */
752
- function createAudioPreferenceMatcher(preferredAudioTrack) {
753
- /**
754
- * Compares an audio Adaptation to the given `preferredAudioTrack` preference.
755
- * Returns `true` if it matches, false otherwise.
756
- * @param {Object} audioAdaptation
757
- * @returns {boolean}
758
- */
759
- return function matchAudioPreference(audioAdaptation) {
760
- var _a;
761
- if (preferredAudioTrack.normalized !== undefined) {
762
- var language = (_a = audioAdaptation.normalizedLanguage) !== null && _a !== void 0 ? _a : "";
763
- if (language !== preferredAudioTrack.normalized) {
764
- return false;
765
- }
766
- }
767
- if (preferredAudioTrack.audioDescription !== undefined) {
768
- if (preferredAudioTrack.audioDescription) {
769
- if (audioAdaptation.isAudioDescription !== true) {
770
- return false;
771
- }
772
- }
773
- else if (audioAdaptation.isAudioDescription === true) {
774
- return false;
775
- }
776
- }
777
- if (preferredAudioTrack.codec === undefined) {
778
- return true;
779
- }
780
- var regxp = preferredAudioTrack.codec.test;
781
- var codecTestingFn = function (rep) {
782
- return rep.codec !== undefined && regxp.test(rep.codec);
783
- };
784
- if (preferredAudioTrack.codec.all) {
785
- return audioAdaptation.representations.every(codecTestingFn);
786
- }
787
- return audioAdaptation.representations.some(codecTestingFn);
788
- };
789
- }
790
- /**
791
- * Find an optimal audio adaptation given their list and the array of preferred
792
- * audio tracks sorted from the most preferred to the least preferred.
793
- *
794
- * `null` if the most optimal audio adaptation is no audio adaptation.
795
- * @param {Array.<Adaptation>} audioAdaptations
796
- * @param {Array.<Object|null>} preferredAudioTracks
797
- * @returns {Adaptation|null}
798
- */
799
- function findFirstOptimalAudioAdaptation(audioAdaptations, preferredAudioTracks) {
800
- if (audioAdaptations.length === 0) {
801
- return null;
802
- }
803
- for (var i = 0; i < preferredAudioTracks.length; i++) {
804
- var preferredAudioTrack = preferredAudioTracks[i];
805
- if (preferredAudioTrack === null) {
806
- return null;
807
- }
808
- var matchPreferredAudio = createAudioPreferenceMatcher(preferredAudioTrack);
809
- var foundAdaptation = arrayFind(audioAdaptations, matchPreferredAudio);
810
- if (foundAdaptation !== undefined) {
811
- return foundAdaptation;
812
- }
813
- }
814
- // no optimal adaptation, just return the first one
815
- return audioAdaptations[0];
816
- }
817
- /**
818
- * Create a function allowing to compare text Adaptations with a given
819
- * `preferredTextTrack` preference to see if they match.
820
- *
821
- * This function is curried to be easily and optimally used in a loop context.
822
- *
823
- * @param {Object} preferredTextTrack - The text track preference you want to
824
- * compare text Adaptations to.
825
- * @returns {Function} - Function taking in argument a text Adaptation and
826
- * returning `true` if it matches the `preferredTextTrack` preference (and
827
- * `false` otherwise.
828
- */
829
- function createTextPreferenceMatcher(preferredTextTrack) {
830
- /**
831
- * Compares a text Adaptation to the given `preferredTextTrack` preference.
832
- * Returns `true` if it matches, false otherwise.
833
- * @param {Object} textAdaptation
834
- * @returns {boolean}
835
- */
836
- return function matchTextPreference(textAdaptation) {
837
- var _a;
838
- return ((_a = textAdaptation.normalizedLanguage) !== null && _a !== void 0 ? _a : "") === preferredTextTrack.normalized &&
839
- (preferredTextTrack.closedCaption ? textAdaptation.isClosedCaption === true :
840
- textAdaptation.isClosedCaption !== true) &&
841
- (preferredTextTrack.forced === true ? textAdaptation.isForcedSubtitles === true :
842
- textAdaptation.isForcedSubtitles !== true);
843
- };
844
- }
845
- /**
846
- * Find an optimal text adaptation given their list and the array of preferred
847
- * text tracks sorted from the most preferred to the least preferred.
848
- *
849
- * `null` if the most optimal text adaptation is no text adaptation.
850
- * @param {Array.<Object>} textAdaptations
851
- * @param {Array.<Object|null>} preferredTextTracks
852
- * @param {Object|null|undefined} chosenAudioAdaptation
853
- * @returns {Adaptation|null}
854
- */
855
- function findFirstOptimalTextAdaptation(textAdaptations, preferredTextTracks, chosenAudioAdaptation) {
856
- var _a;
857
- if (textAdaptations.length === 0) {
858
- return null;
859
- }
860
- for (var i = 0; i < preferredTextTracks.length; i++) {
861
- var preferredTextTrack = preferredTextTracks[i];
862
- if (preferredTextTrack === null) {
863
- return null;
864
- }
865
- var matchPreferredText = createTextPreferenceMatcher(preferredTextTrack);
866
- var foundAdaptation = arrayFind(textAdaptations, matchPreferredText);
867
- if (foundAdaptation !== undefined) {
868
- return foundAdaptation;
869
- }
870
- }
871
- var forcedSubtitles = textAdaptations.filter(function (ad) { return ad.isForcedSubtitles === true; });
872
- if (forcedSubtitles.length > 0) {
873
- if (chosenAudioAdaptation !== null && chosenAudioAdaptation !== undefined) {
874
- var sameLanguage = arrayFind(forcedSubtitles, function (f) {
875
- return f.normalizedLanguage === chosenAudioAdaptation.normalizedLanguage;
876
- });
877
- if (sameLanguage !== undefined) {
878
- return sameLanguage;
879
- }
880
- }
881
- return (_a = arrayFind(forcedSubtitles, function (f) { return f.normalizedLanguage === undefined; })) !== null && _a !== void 0 ? _a : null;
882
- }
883
- // no optimal adaptation
884
- return null;
885
- }
886
- /**
887
- * Create a function allowing to compare video Adaptations with a given
888
- * `preferredVideoTrack` preference to see if they match.
889
- *
890
- * This function is curried to be easily and optimally used in a loop context.
891
- *
892
- * @param {Object} preferredVideoTrack - The video track preference you want to
893
- * compare video Adaptations to.
894
- * @returns {Function} - Function taking in argument a video Adaptation and
895
- * returning `true` if it matches the `preferredVideoTrack` preference (and
896
- * `false` otherwise.
897
- */
898
- function createVideoPreferenceMatcher(preferredVideoTrack) {
899
- /**
900
- * Compares a video Adaptation to the given `preferredVideoTrack` preference.
901
- * Returns `true` if it matches, false otherwise.
902
- * @param {Object} videoAdaptation
903
- * @returns {boolean}
904
- */
905
- return function matchVideoPreference(videoAdaptation) {
906
- if (preferredVideoTrack.signInterpreted !== undefined &&
907
- preferredVideoTrack.signInterpreted !== videoAdaptation.isSignInterpreted) {
908
- return false;
909
- }
910
- if (preferredVideoTrack.codec === undefined) {
911
- return true;
912
- }
913
- var regxp = preferredVideoTrack.codec.test;
914
- var codecTestingFn = function (rep) {
915
- return rep.codec !== undefined && regxp.test(rep.codec);
916
- };
917
- if (preferredVideoTrack.codec.all) {
918
- return videoAdaptation.representations.every(codecTestingFn);
919
- }
920
- return videoAdaptation.representations.some(codecTestingFn);
921
- };
922
- }
923
- /**
924
- * Find an optimal video adaptation given their list and the array of preferred
925
- * video tracks sorted from the most preferred to the least preferred.
926
- *
927
- * `null` if the most optimal video adaptation is no video adaptation.
928
- * @param {Array.<Adaptation>} videoAdaptations
929
- * @param {Array.<Object|null>} preferredVideoTracks
930
- * @returns {Adaptation|null}
931
- */
932
- function findFirstOptimalVideoAdaptation(videoAdaptations, preferredVideoTracks) {
933
- if (videoAdaptations.length === 0) {
934
- return null;
935
- }
936
- for (var i = 0; i < preferredVideoTracks.length; i++) {
937
- var preferredVideoTrack = preferredVideoTracks[i];
938
- if (preferredVideoTrack === null) {
939
- return null;
940
- }
941
- var matchPreferredVideo = createVideoPreferenceMatcher(preferredVideoTrack);
942
- var foundAdaptation = arrayFind(videoAdaptations, matchPreferredVideo);
943
- if (foundAdaptation !== undefined) {
944
- return foundAdaptation;
945
- }
946
- }
947
- // no optimal adaptation, just return the first one
948
- return videoAdaptations[0];
949
- }
950
- /**
951
- * Returns the index of the given `period` in the given `periods`
952
- * SortedList.
953
- * Returns `undefined` if that `period` is not found.
954
- * @param {Object} periods
955
- * @param {Object} period
956
- * @returns {number|undefined}
957
- */
958
- function findPeriodIndex(periods, period) {
959
- for (var i = 0; i < periods.length(); i++) {
960
- var periodI = periods.get(i);
961
- if (periodI.period.id === period.id) {
962
- return i;
963
- }
964
- }
965
- }
966
- /**
967
- * Returns element in the given `periods` SortedList that corresponds to the
968
- * `period` given.
969
- * Returns `undefined` if that `period` is not found.
970
- * @param {Object} periods
971
- * @param {Object} period
972
- * @returns {Object|undefined}
973
- */
974
- function getPeriodItem(periods, period) {
975
- for (var i = 0; i < periods.length(); i++) {
976
- var periodI = periods.get(i);
977
- if (periodI.period.id === period.id) {
978
- return periodI;
979
- }
980
- }
981
- }
982
- function getRightVideoTrack(adaptation, isTrickModeEnabled) {
983
- var _a;
984
- if (isTrickModeEnabled &&
985
- ((_a = adaptation.trickModeTracks) === null || _a === void 0 ? void 0 : _a[0]) !== undefined) {
986
- return adaptation.trickModeTracks[0];
987
- }
988
- return adaptation;
989
- }