rx-player 4.0.0-dev.2023120600 → 4.0.0-dev.2023121900
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.
- package/CHANGELOG.md +178 -2
- package/README.md +2 -33
- package/VERSION +1 -1
- package/dist/_esm5.processed/compat/add_text_track.d.ts +3 -1
- package/dist/_esm5.processed/compat/add_text_track.js +7 -4
- package/dist/_esm5.processed/compat/browser_compatibility_types.d.ts +7 -0
- package/dist/_esm5.processed/compat/event_listeners.d.ts +15 -2
- package/dist/_esm5.processed/compat/event_listeners.js +37 -2
- package/dist/_esm5.processed/compat/fullscreen.d.ts +32 -0
- package/dist/_esm5.processed/compat/fullscreen.js +78 -0
- package/dist/_esm5.processed/compat/index.d.ts +3 -1
- package/dist/_esm5.processed/compat/index.js +3 -1
- package/dist/_esm5.processed/compat/is_offline.d.ts +39 -0
- package/dist/_esm5.processed/compat/is_offline.js +43 -0
- package/dist/_esm5.processed/config.d.ts +21 -9
- package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.d.ts +58 -0
- package/dist/_esm5.processed/core/adaptive/adaptive_representation_selector.js +54 -14
- package/dist/_esm5.processed/core/adaptive/utils/select_optimal_representation.d.ts +8 -2
- package/dist/_esm5.processed/core/adaptive/utils/select_optimal_representation.js +11 -2
- package/dist/_esm5.processed/core/api/debug/modules/general_info.js +46 -17
- package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_content.js +3 -3
- package/dist/_esm5.processed/core/api/debug/modules/segment_buffer_size.js +1 -1
- package/dist/_esm5.processed/core/api/option_utils.d.ts +35 -14
- package/dist/_esm5.processed/core/api/option_utils.js +230 -47
- package/dist/_esm5.processed/core/api/public_api.d.ts +266 -92
- package/dist/_esm5.processed/core/api/public_api.js +802 -444
- package/dist/_esm5.processed/core/api/{track_management/media_element_tracks_store.d.ts → tracks_management/media_element_track_choice_manager.d.ts} +75 -15
- package/dist/_esm5.processed/core/api/{track_management/media_element_tracks_store.js → tracks_management/media_element_track_choice_manager.js} +193 -74
- package/dist/_esm5.processed/core/api/tracks_management/track_choice_manager.d.ts +258 -0
- package/dist/_esm5.processed/core/api/tracks_management/track_choice_manager.js +989 -0
- package/dist/_esm5.processed/core/api/utils.d.ts +0 -1
- package/dist/_esm5.processed/core/api/utils.js +11 -28
- package/dist/_esm5.processed/core/decrypt/content_decryptor.js +3 -3
- package/dist/_esm5.processed/core/decrypt/find_key_system.js +71 -83
- package/dist/_esm5.processed/core/decrypt/get_media_keys.js +5 -6
- package/dist/_esm5.processed/core/decrypt/session_events_listener.js +72 -10
- package/dist/_esm5.processed/core/decrypt/utils/persistent_sessions_store.d.ts +4 -4
- package/dist/_esm5.processed/core/decrypt/utils/persistent_sessions_store.js +4 -6
- package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.d.ts +3 -1
- package/dist/_esm5.processed/core/fetchers/manifest/manifest_fetcher.js +26 -7
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.d.ts +9 -3
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher.js +9 -16
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher_creator.d.ts +3 -1
- package/dist/_esm5.processed/core/fetchers/segment/segment_fetcher_creator.js +1 -1
- package/dist/_esm5.processed/core/fetchers/utils/schedule_request.d.ts +6 -1
- package/dist/_esm5.processed/core/fetchers/utils/schedule_request.js +41 -4
- package/dist/_esm5.processed/core/init/media_source_content_initializer.d.ts +8 -1
- package/dist/_esm5.processed/core/init/media_source_content_initializer.js +5 -2
- package/dist/_esm5.processed/core/init/types.d.ts +15 -5
- package/dist/_esm5.processed/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
- package/dist/_esm5.processed/core/segment_buffers/implementations/image/image_segment_buffer.d.ts +75 -0
- package/dist/_esm5.processed/core/segment_buffers/implementations/image/image_segment_buffer.js +133 -0
- package/dist/_esm5.processed/core/{api/track_management → segment_buffers/implementations/image}/index.d.ts +2 -3
- package/dist/_esm5.processed/core/{api/track_management → segment_buffers/implementations/image}/index.js +2 -3
- package/dist/_esm5.processed/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
- package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.d.ts +2 -1
- package/dist/_esm5.processed/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +4 -3
- package/dist/_esm5.processed/core/segment_buffers/implementations/types.d.ts +2 -2
- package/dist/_esm5.processed/core/segment_buffers/index.d.ts +2 -2
- package/dist/_esm5.processed/core/segment_buffers/index.js +1 -2
- package/dist/_esm5.processed/core/segment_buffers/inventory/index.d.ts +2 -3
- package/dist/_esm5.processed/core/segment_buffers/inventory/index.js +0 -1
- package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
- package/dist/_esm5.processed/core/segment_buffers/inventory/segment_inventory.js +19 -10
- package/dist/_esm5.processed/core/segment_buffers/segment_buffers_store.d.ts +1 -0
- package/dist/_esm5.processed/core/segment_buffers/segment_buffers_store.js +16 -2
- package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.d.ts +15 -0
- package/dist/_esm5.processed/core/stream/adaptation/adaptation_stream.js +93 -183
- package/dist/_esm5.processed/core/stream/adaptation/types.d.ts +13 -27
- package/dist/_esm5.processed/core/stream/index.d.ts +3 -2
- package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.d.ts +0 -2
- package/dist/_esm5.processed/core/stream/orchestrator/stream_orchestrator.js +7 -5
- package/dist/_esm5.processed/core/stream/period/period_stream.js +12 -13
- package/dist/_esm5.processed/core/stream/period/types.d.ts +14 -5
- package/dist/_esm5.processed/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +4 -2
- package/dist/_esm5.processed/core/stream/period/utils/get_adaptation_switch_strategy.js +46 -10
- package/dist/_esm5.processed/core/stream/representation/representation_stream.js +23 -29
- package/dist/_esm5.processed/core/stream/representation/types.d.ts +1 -11
- package/dist/_esm5.processed/core/stream/representation/utils/get_buffer_status.js +1 -1
- package/dist/_esm5.processed/core/stream/representation/utils/get_needed_segments.js +1 -1
- package/dist/_esm5.processed/default_config.d.ts +98 -35
- package/dist/_esm5.processed/default_config.js +113 -36
- package/dist/_esm5.processed/errors/custom_loader_error.d.ts +3 -1
- package/dist/_esm5.processed/errors/custom_loader_error.js +3 -1
- package/dist/_esm5.processed/errors/media_error.js +2 -2
- package/dist/_esm5.processed/errors/network_error.d.ts +1 -0
- package/dist/_esm5.processed/errors/network_error.js +1 -0
- package/dist/_esm5.processed/errors/request_error.d.ts +3 -2
- package/dist/_esm5.processed/errors/request_error.js +5 -2
- package/dist/_esm5.processed/experimental/tools/VideoThumbnailLoader/video_thumbnail_loader.js +3 -3
- package/dist/_esm5.processed/features/features_object.js +2 -0
- package/dist/_esm5.processed/{transports/smooth/is_mp4_embedded_track.js → features/list/bif_parser.d.ts} +6 -7
- package/dist/_esm5.processed/features/list/bif_parser.js +27 -0
- package/dist/_esm5.processed/features/list/directfile.js +5 -2
- package/dist/_esm5.processed/features/list/image_buffer.d.ts +23 -0
- package/dist/_esm5.processed/features/list/image_buffer.js +25 -0
- package/dist/_esm5.processed/features/list/index.d.ts +2 -0
- package/dist/_esm5.processed/features/list/index.js +2 -0
- package/dist/_esm5.processed/features/types.d.ts +27 -3
- package/dist/_esm5.processed/manifest/adaptation.d.ts +11 -9
- package/dist/_esm5.processed/manifest/adaptation.js +30 -41
- package/dist/_esm5.processed/manifest/index.d.ts +4 -3
- package/dist/_esm5.processed/manifest/manifest.d.ts +54 -5
- package/dist/_esm5.processed/manifest/manifest.js +110 -5
- package/dist/_esm5.processed/manifest/period.d.ts +5 -4
- package/dist/_esm5.processed/manifest/representation.d.ts +5 -10
- package/dist/_esm5.processed/manifest/representation.js +5 -15
- package/dist/_esm5.processed/manifest/representation_index/index.d.ts +2 -2
- package/dist/_esm5.processed/manifest/representation_index/static.d.ts +0 -2
- package/dist/_esm5.processed/manifest/representation_index/static.js +0 -6
- package/dist/_esm5.processed/manifest/representation_index/types.d.ts +21 -42
- package/dist/_esm5.processed/manifest/types.d.ts +2 -0
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.d.ts +31 -17
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/base.js +19 -26
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.d.ts +0 -2
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/list.js +1 -7
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.d.ts +6 -2
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/template.js +8 -11
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.d.ts +0 -2
- package/dist/_esm5.processed/parsers/manifest/dash/common/indexes/timeline/timeline_representation_index.js +0 -6
- package/dist/_esm5.processed/parsers/manifest/dash/common/infer_adaptation_type.d.ts +2 -2
- package/dist/_esm5.processed/parsers/manifest/dash/common/infer_adaptation_type.js +6 -1
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_adaptation_sets.js +5 -3
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_mpd.d.ts +2 -0
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_mpd.js +1 -1
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_periods.js +2 -2
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representation_index.d.ts +2 -0
- package/dist/_esm5.processed/parsers/manifest/dash/common/parse_representation_index.js +2 -2
- package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/AdaptationSet.js +6 -10
- package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/Representation.js +2 -4
- package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/utils.d.ts +1 -10
- package/dist/_esm5.processed/parsers/manifest/dash/js-parser/node_parsers/utils.js +2 -18
- package/dist/_esm5.processed/parsers/manifest/dash/node_parser_types.d.ts +4 -4
- package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/generators/AdaptationSet.js +6 -3
- package/dist/_esm5.processed/parsers/manifest/dash/wasm-parser/ts/generators/Representation.js +2 -1
- package/dist/_esm5.processed/parsers/manifest/local/representation_index.d.ts +0 -2
- package/dist/_esm5.processed/parsers/manifest/local/representation_index.js +0 -6
- package/dist/_esm5.processed/parsers/manifest/metaplaylist/metaplaylist_parser.js +6 -6
- package/dist/_esm5.processed/parsers/manifest/metaplaylist/representation_index.d.ts +3 -12
- package/dist/_esm5.processed/parsers/manifest/metaplaylist/representation_index.js +2 -11
- package/dist/_esm5.processed/parsers/manifest/smooth/create_parser.d.ts +1 -0
- package/dist/_esm5.processed/parsers/manifest/smooth/create_parser.js +17 -11
- package/dist/_esm5.processed/parsers/manifest/smooth/representation_index.d.ts +83 -21
- package/dist/_esm5.processed/parsers/manifest/smooth/representation_index.js +125 -53
- package/dist/_esm5.processed/parsers/manifest/smooth/utils/add_segment_infos.d.ts +6 -3
- package/dist/_esm5.processed/parsers/manifest/smooth/utils/add_segment_infos.js +4 -4
- package/dist/_esm5.processed/parsers/manifest/types.d.ts +3 -3
- package/dist/_esm5.processed/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
- package/dist/_esm5.processed/public_types.d.ts +310 -396
- package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.d.ts +4 -5
- package/dist/_esm5.processed/tools/TextTrackRenderer/text_track_renderer.js +4 -5
- package/dist/_esm5.processed/transports/dash/add_segment_integrity_checks_to_loader.js +4 -4
- package/dist/_esm5.processed/transports/dash/image_pipelines.d.ts +38 -0
- package/dist/_esm5.processed/transports/dash/image_pipelines.js +129 -0
- package/dist/_esm5.processed/transports/dash/manifest_parser.js +3 -2
- package/dist/_esm5.processed/transports/dash/pipelines.js +4 -1
- package/dist/_esm5.processed/transports/dash/segment_loader.d.ts +2 -2
- package/dist/_esm5.processed/transports/dash/segment_loader.js +20 -26
- package/dist/_esm5.processed/transports/dash/segment_parser.js +24 -19
- package/dist/_esm5.processed/transports/dash/text_loader.js +5 -5
- package/dist/_esm5.processed/transports/dash/text_parser.js +33 -28
- package/dist/_esm5.processed/transports/local/pipelines.js +10 -1
- package/dist/_esm5.processed/transports/local/segment_loader.js +2 -2
- package/dist/_esm5.processed/transports/local/segment_parser.d.ts +1 -1
- package/dist/_esm5.processed/transports/local/segment_parser.js +10 -10
- package/dist/_esm5.processed/transports/local/text_parser.d.ts +2 -2
- package/dist/_esm5.processed/transports/local/text_parser.js +23 -23
- package/dist/_esm5.processed/transports/metaplaylist/pipelines.js +52 -34
- package/dist/_esm5.processed/transports/smooth/pipelines.js +190 -33
- package/dist/_esm5.processed/transports/smooth/segment_loader.d.ts +1 -1
- package/dist/_esm5.processed/transports/smooth/segment_loader.js +22 -28
- package/dist/_esm5.processed/transports/smooth/utils.d.ts +26 -1
- package/dist/_esm5.processed/transports/smooth/utils.js +55 -1
- package/dist/_esm5.processed/transports/types.d.ts +89 -94
- package/dist/_esm5.processed/transports/utils/call_custom_manifest_loader.js +3 -3
- package/dist/_esm5.processed/transports/utils/infer_segment_container.d.ts +3 -3
- package/dist/_esm5.processed/transports/utils/infer_segment_container.js +7 -5
- package/dist/_esm5.processed/transports/utils/parse_text_track.d.ts +12 -8
- package/dist/_esm5.processed/transports/utils/parse_text_track.js +21 -19
- package/dist/_esm5.processed/utils/array_includes.d.ts +1 -2
- package/dist/_esm5.processed/utils/array_includes.js +28 -30
- package/dist/_esm5.processed/{transports/smooth/is_mp4_embedded_track.d.ts → utils/list_to_map.d.ts} +5 -5
- package/dist/_esm5.processed/utils/list_to_map.js +28 -0
- package/dist/_esm5.processed/utils/request/xhr.js +5 -5
- package/dist/_esm5.processed/utils/simple_set.d.ts +51 -0
- package/dist/_esm5.processed/utils/simple_set.js +57 -0
- package/dist/_esm5.processed/utils/uniq.d.ts +36 -0
- package/dist/_esm5.processed/utils/uniq.js +43 -0
- package/dist/commonjs/config.d.ts +1 -1
- package/dist/commonjs/core/adaptive/adaptive_representation_selector.d.ts +2 -19
- package/dist/commonjs/core/adaptive/adaptive_representation_selector.js +2 -2
- package/dist/commonjs/core/adaptive/network_analyzer.js +3 -3
- package/dist/commonjs/core/api/index.d.ts +1 -1
- package/dist/commonjs/core/api/playback_observer.d.ts +128 -8
- package/dist/commonjs/core/api/playback_observer.js +217 -64
- package/dist/commonjs/core/api/public_api.js +9 -9
- package/dist/commonjs/core/api/utils.js +1 -1
- package/dist/commonjs/core/decrypt/get_media_keys.js +2 -6
- package/dist/commonjs/core/init/directfile_content_initializer.js +5 -1
- package/dist/commonjs/core/init/media_source_content_initializer.js +28 -14
- package/dist/commonjs/core/init/utils/content_time_boundaries_observer.js +1 -2
- package/dist/commonjs/core/init/utils/create_stream_playback_observer.d.ts +1 -5
- package/dist/commonjs/core/init/utils/create_stream_playback_observer.js +16 -14
- package/dist/commonjs/core/init/utils/initial_seek_and_play.d.ts +9 -11
- package/dist/commonjs/core/init/utils/initial_seek_and_play.js +121 -91
- package/dist/commonjs/core/init/utils/rebuffering_controller.js +27 -70
- package/dist/commonjs/core/init/utils/stream_events_emitter/stream_events_emitter.js +4 -2
- package/dist/commonjs/core/segment_buffers/garbage_collector.js +1 -2
- package/dist/commonjs/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
- package/dist/commonjs/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
- package/dist/commonjs/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
- package/dist/commonjs/core/segment_buffers/index.d.ts +2 -2
- package/dist/commonjs/core/segment_buffers/inventory/index.d.ts +2 -2
- package/dist/commonjs/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
- package/dist/commonjs/core/segment_buffers/inventory/segment_inventory.js +19 -10
- package/dist/commonjs/core/stream/adaptation/get_representations_switch_strategy.d.ts +2 -2
- package/dist/commonjs/core/stream/adaptation/get_representations_switch_strategy.js +16 -9
- package/dist/commonjs/core/stream/orchestrator/stream_orchestrator.js +14 -18
- package/dist/commonjs/core/stream/period/period_stream.js +5 -8
- package/dist/commonjs/core/stream/period/types.d.ts +2 -3
- package/dist/commonjs/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +4 -5
- package/dist/commonjs/core/stream/period/utils/get_adaptation_switch_strategy.js +17 -13
- package/dist/commonjs/core/stream/representation/representation_stream.js +3 -4
- package/dist/commonjs/core/stream/representation/types.d.ts +2 -2
- package/dist/commonjs/core/stream/representation/utils/append_segment_to_buffer.js +11 -12
- package/dist/commonjs/core/stream/representation/utils/get_buffer_status.js +1 -1
- package/dist/commonjs/default_config.d.ts +7 -16
- package/dist/commonjs/default_config.js +16 -16
- package/dist/commonjs/manifest/adaptation.js +2 -1
- package/dist/commonjs/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
- package/dist/commonjs/public_types.d.ts +29 -2
- package/dist/es2017/config.d.ts +1 -1
- package/dist/es2017/core/adaptive/adaptive_representation_selector.d.ts +2 -19
- package/dist/es2017/core/adaptive/adaptive_representation_selector.js +2 -2
- package/dist/es2017/core/adaptive/network_analyzer.js +3 -3
- package/dist/es2017/core/api/index.d.ts +1 -1
- package/dist/es2017/core/api/playback_observer.d.ts +128 -8
- package/dist/es2017/core/api/playback_observer.js +217 -66
- package/dist/es2017/core/api/public_api.js +9 -9
- package/dist/es2017/core/api/utils.js +1 -1
- package/dist/es2017/core/decrypt/get_media_keys.js +2 -6
- package/dist/es2017/core/init/directfile_content_initializer.js +7 -1
- package/dist/es2017/core/init/media_source_content_initializer.js +30 -16
- package/dist/es2017/core/init/utils/content_time_boundaries_observer.js +1 -2
- package/dist/es2017/core/init/utils/create_stream_playback_observer.d.ts +1 -5
- package/dist/es2017/core/init/utils/create_stream_playback_observer.js +16 -14
- package/dist/es2017/core/init/utils/initial_seek_and_play.d.ts +9 -11
- package/dist/es2017/core/init/utils/initial_seek_and_play.js +120 -91
- package/dist/es2017/core/init/utils/rebuffering_controller.js +27 -70
- package/dist/es2017/core/init/utils/stream_events_emitter/stream_events_emitter.js +4 -2
- package/dist/es2017/core/segment_buffers/garbage_collector.js +1 -2
- package/dist/es2017/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.js +9 -2
- package/dist/es2017/core/segment_buffers/implementations/text/html/html_text_segment_buffer.js +1 -1
- package/dist/es2017/core/segment_buffers/implementations/text/native/native_text_segment_buffer.js +1 -1
- package/dist/es2017/core/segment_buffers/index.d.ts +2 -2
- package/dist/es2017/core/segment_buffers/inventory/index.d.ts +2 -2
- package/dist/es2017/core/segment_buffers/inventory/segment_inventory.d.ts +25 -8
- package/dist/es2017/core/segment_buffers/inventory/segment_inventory.js +19 -10
- package/dist/es2017/core/stream/adaptation/get_representations_switch_strategy.d.ts +2 -2
- package/dist/es2017/core/stream/adaptation/get_representations_switch_strategy.js +16 -9
- package/dist/es2017/core/stream/orchestrator/stream_orchestrator.js +16 -18
- package/dist/es2017/core/stream/period/period_stream.js +4 -7
- package/dist/es2017/core/stream/period/types.d.ts +2 -3
- package/dist/es2017/core/stream/period/utils/get_adaptation_switch_strategy.d.ts +4 -5
- package/dist/es2017/core/stream/period/utils/get_adaptation_switch_strategy.js +17 -13
- package/dist/es2017/core/stream/representation/representation_stream.js +3 -4
- package/dist/es2017/core/stream/representation/types.d.ts +2 -2
- package/dist/es2017/core/stream/representation/utils/append_segment_to_buffer.js +1 -2
- package/dist/es2017/core/stream/representation/utils/get_buffer_status.js +1 -1
- package/dist/es2017/default_config.d.ts +7 -16
- package/dist/es2017/default_config.js +16 -16
- package/dist/es2017/manifest/adaptation.js +2 -1
- package/dist/es2017/parsers/texttracks/ttml/html/apply_line_height.js +2 -1
- package/dist/es2017/public_types.d.ts +29 -2
- package/dist/mpd-parser.wasm +0 -0
- package/dist/rx-player.js +614 -438
- package/dist/rx-player.min.js +1 -1
- package/package.json +5 -1
- package/scripts/canal-release.patch +78 -0
- package/scripts/make-dev-releases +65 -0
- package/scripts/update-version +5 -0
- package/sonar-project.properties +1 -1
- package/src/core/adaptive/adaptive_representation_selector.ts +4 -21
- package/src/core/adaptive/network_analyzer.ts +3 -3
- package/src/core/api/index.ts +1 -0
- package/src/core/api/playback_observer.ts +327 -107
- package/src/core/api/public_api.ts +9 -9
- package/src/core/api/utils.ts +3 -1
- package/src/core/decrypt/get_media_keys.ts +2 -8
- package/src/core/init/directfile_content_initializer.ts +8 -8
- package/src/core/init/media_source_content_initializer.ts +27 -20
- package/src/core/init/utils/content_time_boundaries_observer.ts +1 -1
- package/src/core/init/utils/create_stream_playback_observer.ts +19 -20
- package/src/core/init/utils/initial_seek_and_play.ts +140 -108
- package/src/core/init/utils/rebuffering_controller.ts +32 -77
- package/src/core/init/utils/stream_events_emitter/stream_events_emitter.ts +5 -2
- package/src/core/segment_buffers/garbage_collector.ts +1 -1
- package/src/core/segment_buffers/implementations/audio_video/audio_video_segment_buffer.ts +10 -2
- package/src/core/segment_buffers/implementations/text/html/html_text_segment_buffer.ts +1 -1
- package/src/core/segment_buffers/implementations/text/native/native_text_segment_buffer.ts +1 -1
- package/src/core/segment_buffers/index.ts +2 -0
- package/src/core/segment_buffers/inventory/index.ts +2 -0
- package/src/core/segment_buffers/inventory/segment_inventory.ts +49 -17
- package/src/core/stream/adaptation/get_representations_switch_strategy.ts +21 -12
- package/src/core/stream/orchestrator/stream_orchestrator.ts +14 -19
- package/src/core/stream/period/period_stream.ts +7 -8
- package/src/core/stream/period/types.ts +2 -3
- package/src/core/stream/period/utils/get_adaptation_switch_strategy.ts +21 -15
- package/src/core/stream/representation/representation_stream.ts +3 -5
- package/src/core/stream/representation/types.ts +2 -2
- package/src/core/stream/representation/utils/append_segment_to_buffer.ts +1 -1
- package/src/core/stream/representation/utils/get_buffer_status.ts +2 -1
- package/src/default_config.ts +17 -17
- package/src/manifest/adaptation.ts +2 -1
- package/src/parsers/texttracks/ttml/html/apply_line_height.ts +3 -1
- package/src/public_types.ts +29 -2
- package/dist/_esm5.processed/core/api/track_management/track_dispatcher.d.ts +0 -84
- package/dist/_esm5.processed/core/api/track_management/track_dispatcher.js +0 -158
- package/dist/_esm5.processed/core/api/track_management/tracks_store.d.ts +0 -406
- package/dist/_esm5.processed/core/api/track_management/tracks_store.js +0 -932
- package/dist/_esm5.processed/core/segment_buffers/inventory/utils.d.ts +0 -33
- package/dist/_esm5.processed/core/segment_buffers/inventory/utils.js +0 -49
- package/dist/_esm5.processed/core/stream/adaptation/get_representations_switch_strategy.d.ts +0 -39
- package/dist/_esm5.processed/core/stream/adaptation/get_representations_switch_strategy.js +0 -133
- package/dist/_esm5.processed/parsers/manifest/smooth/shared_smooth_segment_timeline.d.ts +0 -119
- package/dist/_esm5.processed/parsers/manifest/smooth/shared_smooth_segment_timeline.js +0 -159
|
@@ -0,0 +1,989 @@
|
|
|
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
|
+
}
|