@amazon/vinyl 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -8
- package/dist/index.cjs +276 -200
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +280 -203
- package/dist/index.js.map +4 -4
- package/dist/test/benchmark.es5.js +169 -232
- package/dist/test/benchmark.js +1475 -1933
- package/dist/test/benchmark.js.map +4 -4
- package/dist/test/integ.es5.js +771 -394
- package/dist/test/integ.js +6063 -5273
- package/dist/test/integ.js.map +4 -4
- package/dist/test/jasmineHtml.es5.js +8 -8
- package/dist/test/jasmineHtml.js +8 -4
- package/dist/test/jasmineHtml.js.map +3 -3
- package/dist/types/current/client/Capabilities.d.ts.map +1 -1
- package/dist/types/current/client/CapabilitiesImpl.d.ts.map +1 -1
- package/dist/types/current/drm/DrmController.d.ts +2 -2
- package/dist/types/current/drm/DrmController.d.ts.map +1 -1
- package/dist/types/current/drm/DrmControllerImpl.d.ts +3 -3
- package/dist/types/current/drm/DrmControllerImpl.d.ts.map +1 -1
- package/dist/types/current/drm/DrmControllerImpl.js +7 -7
- package/dist/types/current/drm/DrmKeySystemResolver.d.ts +1 -1
- package/dist/types/current/drm/DrmKeySystemResolver.d.ts.map +1 -1
- package/dist/types/current/drm/DrmKeySystemResolver.js +1 -1
- package/dist/types/current/drm/DrmOptions.d.ts +1 -1
- package/dist/types/current/drm/DrmOptions.d.ts.map +1 -1
- package/dist/types/current/drm/DrmOptions.js +1 -1
- package/dist/types/current/drm/commonEme/CommonEme.d.ts +2 -2
- package/dist/types/current/drm/commonEme/CommonEme.d.ts.map +1 -1
- package/dist/types/current/drm/commonEme/CommonEmeFactory.d.ts +1 -1
- package/dist/types/current/drm/commonEme/CommonEmeFactory.d.ts.map +1 -1
- package/dist/types/current/drm/commonEme/MsCommonEme.d.ts +1 -1
- package/dist/types/current/drm/commonEme/MsCommonEme.d.ts.map +1 -1
- package/dist/types/current/drm/commonEme/MsCommonEme.js +1 -1
- package/dist/types/current/drm/commonEme/StandardCommonEme.d.ts +1 -1
- package/dist/types/current/drm/commonEme/StandardCommonEme.d.ts.map +1 -1
- package/dist/types/current/drm/commonEme/WebKitCommonEme.d.ts +2 -2
- package/dist/types/current/drm/commonEme/WebKitCommonEme.d.ts.map +1 -1
- package/dist/types/current/drm/commonEme/WebKitCommonEme.js +1 -1
- package/dist/types/current/drm/commonEme/createDrmErrorHandler.js +1 -1
- package/dist/types/current/drm/licenseProvider/LicenseProvider.d.ts +1 -1
- package/dist/types/current/drm/licenseProvider/LicenseProvider.d.ts.map +1 -1
- package/dist/types/current/global/environment.d.ts +6 -2
- package/dist/types/current/global/environment.d.ts.map +1 -1
- package/dist/types/current/global/environment.js +4 -3
- package/dist/types/current/global/initializeVinylGlobal.js +1 -1
- package/dist/types/current/patch/media/MediaElementPatchOptions.js +1 -1
- package/dist/types/current/patch/media/patchMediaElement.js +1 -1
- package/dist/types/current/patch/media/patches/createPreventStallsPatch.d.ts +1 -1
- package/dist/types/current/patch/media/patches/createPreventStallsPatch.d.ts.map +1 -1
- package/dist/types/current/patch/media/patches/createUnreliablePlaybackEventsPatch.d.ts +1 -1
- package/dist/types/current/patch/media/patches/createUnreliablePlaybackEventsPatch.d.ts.map +1 -1
- package/dist/types/current/playback/PlaybackControllerImpl.d.ts +1 -1
- package/dist/types/current/playback/PlaybackControllerImpl.d.ts.map +1 -1
- package/dist/types/current/playback/PlaybackControllerImpl.js +4 -4
- package/dist/types/current/playback/ReadonlyPlaybackController.d.ts.map +1 -1
- package/dist/types/current/playback/error/ReportableMediaError.js +1 -1
- package/dist/types/current/playback/logging/playbackStateLoggingHandler.d.ts +1 -1
- package/dist/types/current/playback/logging/playbackStateLoggingHandler.d.ts.map +1 -1
- package/dist/types/current/playback/logging/playbackStateLoggingHandler.js +1 -1
- package/dist/types/current/playback/nextHasMetadata.d.ts +1 -1
- package/dist/types/current/playback/nextHasMetadata.d.ts.map +1 -1
- package/dist/types/current/streaming/ContentStream.d.ts +4 -4
- package/dist/types/current/streaming/ContentStream.d.ts.map +1 -1
- package/dist/types/current/streaming/ContentStreamingOptions.d.ts +2 -2
- package/dist/types/current/streaming/ContentStreamingOptions.d.ts.map +1 -1
- package/dist/types/current/streaming/MediaQualityMetadata.d.ts +2 -2
- package/dist/types/current/streaming/MediaQualityMetadata.d.ts.map +1 -1
- package/dist/types/current/streaming/MediaQualityMetadata.js +1 -1
- package/dist/types/current/streaming/MediaTimeline.d.ts +6 -5
- package/dist/types/current/streaming/MediaTimeline.d.ts.map +1 -1
- package/dist/types/current/streaming/SegmentController.d.ts +2 -7
- package/dist/types/current/streaming/SegmentController.d.ts.map +1 -1
- package/dist/types/current/streaming/SegmentControllerImpl.d.ts +5 -6
- package/dist/types/current/streaming/SegmentControllerImpl.d.ts.map +1 -1
- package/dist/types/current/streaming/SegmentControllerImpl.js +5 -15
- package/dist/types/current/streaming/SegmentReference.d.ts +1 -1
- package/dist/types/current/streaming/SegmentReference.d.ts.map +1 -1
- package/dist/types/current/streaming/StreamingEventMap.d.ts +1 -1
- package/dist/types/current/streaming/StreamingEventMap.d.ts.map +1 -1
- package/dist/types/current/streaming/abr/QualitySelector.d.ts +1 -1
- package/dist/types/current/streaming/abr/QualitySelector.d.ts.map +1 -1
- package/dist/types/current/streaming/abr/QualitySelectorImpl.d.ts +18 -3
- package/dist/types/current/streaming/abr/QualitySelectorImpl.d.ts.map +1 -1
- package/dist/types/current/streaming/abr/QualitySelectorImpl.js +8 -2
- package/dist/types/current/streaming/buffering/BufferingController.d.ts +3 -13
- package/dist/types/current/streaming/buffering/BufferingController.d.ts.map +1 -1
- package/dist/types/current/streaming/buffering/BufferingController.js +1 -24
- package/dist/types/current/streaming/buffering/MediaSourceController.d.ts +41 -15
- package/dist/types/current/streaming/buffering/MediaSourceController.d.ts.map +1 -1
- package/dist/types/current/streaming/buffering/MediaSourceController.js +74 -17
- package/dist/types/current/streaming/buffering/SourceBufferController.d.ts +1 -1
- package/dist/types/current/streaming/buffering/SourceBufferController.d.ts.map +1 -1
- package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.d.ts +1 -1
- package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.d.ts.map +1 -1
- package/dist/types/current/streaming/createDefaultMediaTimelineTransformer.js +2 -2
- package/dist/types/current/streaming/mediaTimelineFilter.d.ts +3 -3
- package/dist/types/current/streaming/mediaTimelineFilter.d.ts.map +1 -1
- package/dist/types/current/streaming/mediaTimelineFilter.js +1 -1
- package/dist/types/current/streaming/mediaTimelineLanguageFilter.d.ts +1 -1
- package/dist/types/current/streaming/mediaTimelineLanguageFilter.d.ts.map +1 -1
- package/dist/types/current/streaming/util/segment.d.ts +1 -1
- package/dist/types/current/streaming/util/segment.d.ts.map +1 -1
- package/dist/types/current/track/AutoResetController.d.ts +37 -12
- package/dist/types/current/track/AutoResetController.d.ts.map +1 -1
- package/dist/types/current/track/AutoResetController.js +38 -28
- package/dist/types/current/track/Track.d.ts.map +1 -1
- package/dist/types/current/track/TrackBase.d.ts.map +1 -1
- package/dist/types/current/track/TrackController.d.ts +2 -2
- package/dist/types/current/track/TrackController.d.ts.map +1 -1
- package/dist/types/current/track/TrackFactory.d.ts +1 -1
- package/dist/types/current/track/TrackFactory.d.ts.map +1 -1
- package/dist/types/current/track/createSegmentDataProvider.d.ts.map +1 -1
- package/dist/types/current/track/createVinylTrackFactories.d.ts +5 -5
- package/dist/types/current/track/createVinylTrackFactories.d.ts.map +1 -1
- package/dist/types/current/track/createVinylTrackFactories.js +4 -4
- package/dist/types/current/track/dash/DashManifestController.d.ts +1 -1
- package/dist/types/current/track/dash/DashManifestController.d.ts.map +1 -1
- package/dist/types/current/track/dash/DashMediaQualityMetadataResolver.d.ts.map +1 -1
- package/dist/types/current/track/dash/DashMediaQualityMetadataResolver.js +1 -1
- package/dist/types/current/track/dash/DashTrack.d.ts +4 -4
- package/dist/types/current/track/dash/DashTrack.d.ts.map +1 -1
- package/dist/types/current/track/dash/DashTrack.js +2 -2
- package/dist/types/current/track/dash/buildDashMediaTimeline.d.ts +2 -2
- package/dist/types/current/track/dash/buildDashMediaTimeline.d.ts.map +1 -1
- package/dist/types/current/track/dash/buildDashMediaTimeline.js +2 -2
- package/dist/types/current/track/dash/createDashContentStreamFactories.d.ts.map +1 -1
- package/dist/types/current/track/dash/createDashContentTypesValue.d.ts +2 -2
- package/dist/types/current/track/dash/createDashContentTypesValue.d.ts.map +1 -1
- package/dist/types/current/track/dash/createDashContentTypesValue.js +1 -1
- package/dist/types/current/track/dash/createDashFactories.d.ts +12 -12
- package/dist/types/current/track/dash/createDashFactories.d.ts.map +1 -1
- package/dist/types/current/track/dash/createDashFactories.js +8 -8
- package/dist/types/current/track/dash/createDashManifestProvider.d.ts +1 -1
- package/dist/types/current/track/dash/createDashManifestProvider.d.ts.map +1 -1
- package/dist/types/current/track/dash/createDashManifestProvider.js +1 -1
- package/dist/types/current/track/dash/createDefaultDashManifestTransformer.d.ts +1 -1
- package/dist/types/current/track/dash/createDefaultDashManifestTransformer.d.ts.map +1 -1
- package/dist/types/current/track/dash/createDefaultDashManifestTransformer.js +1 -1
- package/dist/types/current/track/dash/createSegmentControllerFactory.d.ts.map +1 -1
- package/dist/types/current/track/dash/manifestTransformUtils.d.ts +1 -1
- package/dist/types/current/track/dash/manifestTransformUtils.d.ts.map +1 -1
- package/dist/types/current/track/dash/timeline/DashRepresentationSegmentProvider.d.ts +3 -3
- package/dist/types/current/track/dash/timeline/DashRepresentationSegmentProvider.d.ts.map +1 -1
- package/dist/types/current/track/dash/timeline/DashRepresentationSegmentProvider.js +3 -3
- package/dist/types/current/track/dash/urlDashManifestProvider.d.ts +1 -1
- package/dist/types/current/track/dash/urlDashManifestProvider.d.ts.map +1 -1
- package/dist/types/current/track/dash/util/mimeType.d.ts.map +1 -1
- package/dist/types/current/track/dash/util/mimeType.js +1 -1
- package/dist/types/current/track/dash/util/mpd.d.ts +3 -2
- package/dist/types/current/track/dash/util/mpd.d.ts.map +1 -1
- package/dist/types/current/track/dash/util/mpd.js +13 -3
- package/dist/types/current/track/dash/util/uriResolution.js +1 -1
- package/dist/types/current/track/filters/keySystemFilter.d.ts.map +1 -1
- package/dist/types/current/track/filters/resourceTypeFilter.d.ts.map +1 -1
- package/dist/types/current/track/filters/sampleRateFilter.d.ts.map +1 -1
- package/dist/types/current/track/hls/HlsTrack.d.ts.map +1 -1
- package/dist/types/current/track/hls/buildHlsMediaTimeline.d.ts +3 -3
- package/dist/types/current/track/hls/buildHlsMediaTimeline.d.ts.map +1 -1
- package/dist/types/current/track/hls/buildHlsMediaTimeline.js +16 -14
- package/dist/types/current/track/hls/createDefaultHlsManifestTransformer.d.ts +1 -1
- package/dist/types/current/track/hls/createDefaultHlsManifestTransformer.d.ts.map +1 -1
- package/dist/types/current/track/hls/createHlsContentStreamFactories.d.ts.map +1 -1
- package/dist/types/current/track/hls/util/hlsSegmentTime.d.ts +1 -1
- package/dist/types/current/track/hls/util/hlsSegmentTime.d.ts.map +1 -1
- package/dist/types/current/track/hls/util/hlsSegmentTime.js +1 -1
- package/dist/types/current/track/mse/MseTrack.d.ts +2 -2
- package/dist/types/current/track/mse/MseTrack.d.ts.map +1 -1
- package/dist/types/current/track/mse/MseTrack.js +2 -1
- package/dist/types/current/track/mse/codec.d.ts.map +1 -1
- package/dist/types/current/track/source/FixedPlaybackQuality.d.ts +1 -1
- package/dist/types/current/track/source/FixedPlaybackQuality.d.ts.map +1 -1
- package/dist/types/current/track/source/SourceObjectTrack.d.ts +4 -4
- package/dist/types/current/track/source/SourceObjectTrack.d.ts.map +1 -1
- package/dist/types/current/track/source/SourceObjectTrack.js +2 -2
- package/dist/types/current/track/source/SourceTrack.d.ts +4 -4
- package/dist/types/current/track/source/SourceTrack.d.ts.map +1 -1
- package/dist/types/current/track/source/SourceTrack.js +2 -2
- package/dist/types/current/track/source/SourceTrackBase.d.ts +2 -2
- package/dist/types/current/track/source/SourceTrackBase.d.ts.map +1 -1
- package/dist/types/current/track/source/SourceTrackBase.js +2 -2
- package/dist/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/types/current/vinyl/ReadonlyPlaybackStreamingState.d.ts.map +1 -1
- package/dist/types/current/vinyl/VinylDeps.d.ts +1 -1
- package/dist/types/current/vinyl/VinylDeps.d.ts.map +1 -1
- package/dist/types/current/vinyl/VinylOptions.d.ts.map +1 -1
- package/dist/types/current/vinyl/VinylPatchOptions.d.ts.map +1 -1
- package/dist/types/current/vinyl/VinylPlayer.d.ts +26 -2
- package/dist/types/current/vinyl/VinylPlayer.d.ts.map +1 -1
- package/dist/types/current/vinyl/VinylPlayer.js +18 -3
- package/dist/types/current/vinyl/createVinylFactories.d.ts +9 -11
- package/dist/types/current/vinyl/createVinylFactories.d.ts.map +1 -1
- package/dist/types/current/vinyl/createVinylFactories.js +2 -2
- package/dist/types/ts3.7/drm/DrmController.d.ts +2 -2
- package/dist/types/ts3.7/drm/DrmControllerImpl.d.ts +3 -3
- package/dist/types/ts3.7/drm/DrmKeySystemResolver.d.ts +1 -1
- package/dist/types/ts3.7/drm/DrmOptions.d.ts +1 -1
- package/dist/types/ts3.7/drm/commonEme/CommonEme.d.ts +2 -2
- package/dist/types/ts3.7/drm/commonEme/CommonEmeFactory.d.ts +1 -1
- package/dist/types/ts3.7/drm/commonEme/MsCommonEme.d.ts +1 -1
- package/dist/types/ts3.7/drm/commonEme/StandardCommonEme.d.ts +1 -1
- package/dist/types/ts3.7/drm/commonEme/WebKitCommonEme.d.ts +2 -2
- package/dist/types/ts3.7/drm/licenseProvider/LicenseProvider.d.ts +1 -1
- package/dist/types/ts3.7/global/environment.d.ts +6 -2
- package/dist/types/ts3.7/patch/media/patches/createPreventStallsPatch.d.ts +1 -1
- package/dist/types/ts3.7/patch/media/patches/createUnreliablePlaybackEventsPatch.d.ts +1 -1
- package/dist/types/ts3.7/playback/PlaybackControllerImpl.d.ts +1 -1
- package/dist/types/ts3.7/playback/logging/playbackStateLoggingHandler.d.ts +1 -1
- package/dist/types/ts3.7/playback/nextHasMetadata.d.ts +1 -1
- package/dist/types/ts3.7/streaming/ContentStream.d.ts +4 -4
- package/dist/types/ts3.7/streaming/ContentStreamingOptions.d.ts +2 -2
- package/dist/types/ts3.7/streaming/MediaQualityMetadata.d.ts +2 -2
- package/dist/types/ts3.7/streaming/MediaTimeline.d.ts +6 -5
- package/dist/types/ts3.7/streaming/SegmentController.d.ts +2 -7
- package/dist/types/ts3.7/streaming/SegmentControllerImpl.d.ts +5 -6
- package/dist/types/ts3.7/streaming/SegmentReference.d.ts +1 -1
- package/dist/types/ts3.7/streaming/StreamingEventMap.d.ts +1 -1
- package/dist/types/ts3.7/streaming/abr/QualitySelector.d.ts +1 -1
- package/dist/types/ts3.7/streaming/abr/QualitySelectorImpl.d.ts +18 -3
- package/dist/types/ts3.7/streaming/buffering/BufferingController.d.ts +3 -13
- package/dist/types/ts3.7/streaming/buffering/MediaSourceController.d.ts +41 -15
- package/dist/types/ts3.7/streaming/buffering/SourceBufferController.d.ts +1 -1
- package/dist/types/ts3.7/streaming/createDefaultMediaTimelineTransformer.d.ts +1 -1
- package/dist/types/ts3.7/streaming/mediaTimelineFilter.d.ts +3 -3
- package/dist/types/ts3.7/streaming/mediaTimelineLanguageFilter.d.ts +1 -1
- package/dist/types/ts3.7/streaming/util/segment.d.ts +1 -1
- package/dist/types/ts3.7/track/AutoResetController.d.ts +37 -12
- package/dist/types/ts3.7/track/TrackController.d.ts +2 -2
- package/dist/types/ts3.7/track/TrackFactory.d.ts +1 -1
- package/dist/types/ts3.7/track/createVinylTrackFactories.d.ts +5 -5
- package/dist/types/ts3.7/track/dash/DashManifestController.d.ts +1 -1
- package/dist/types/ts3.7/track/dash/DashTrack.d.ts +4 -4
- package/dist/types/ts3.7/track/dash/buildDashMediaTimeline.d.ts +2 -2
- package/dist/types/ts3.7/track/dash/createDashContentTypesValue.d.ts +2 -2
- package/dist/types/ts3.7/track/dash/createDashFactories.d.ts +12 -12
- package/dist/types/ts3.7/track/dash/createDashManifestProvider.d.ts +1 -1
- package/dist/types/ts3.7/track/dash/createDefaultDashManifestTransformer.d.ts +1 -1
- package/dist/types/ts3.7/track/dash/manifestTransformUtils.d.ts +1 -1
- package/dist/types/ts3.7/track/dash/timeline/DashRepresentationSegmentProvider.d.ts +3 -3
- package/dist/types/ts3.7/track/dash/urlDashManifestProvider.d.ts +1 -1
- package/dist/types/ts3.7/track/dash/util/mpd.d.ts +3 -2
- package/dist/types/ts3.7/track/hls/buildHlsMediaTimeline.d.ts +3 -3
- package/dist/types/ts3.7/track/hls/createDefaultHlsManifestTransformer.d.ts +1 -1
- package/dist/types/ts3.7/track/hls/util/hlsSegmentTime.d.ts +1 -1
- package/dist/types/ts3.7/track/mse/MseTrack.d.ts +2 -2
- package/dist/types/ts3.7/track/source/FixedPlaybackQuality.d.ts +1 -1
- package/dist/types/ts3.7/track/source/SourceObjectTrack.d.ts +4 -4
- package/dist/types/ts3.7/track/source/SourceTrack.d.ts +4 -4
- package/dist/types/ts3.7/track/source/SourceTrackBase.d.ts +2 -2
- package/dist/types/ts3.7/vinyl/VinylDeps.d.ts +1 -1
- package/dist/types/ts3.7/vinyl/VinylPlayer.d.ts +18 -2
- package/dist/types/ts3.7/vinyl/createVinylFactories.d.ts +9 -11
- package/dist/types/ts4.1/drm/DrmController.d.ts +2 -2
- package/dist/types/ts4.1/drm/DrmControllerImpl.d.ts +3 -3
- package/dist/types/ts4.1/drm/DrmKeySystemResolver.d.ts +1 -1
- package/dist/types/ts4.1/drm/DrmOptions.d.ts +1 -1
- package/dist/types/ts4.1/drm/commonEme/CommonEme.d.ts +2 -2
- package/dist/types/ts4.1/drm/commonEme/CommonEmeFactory.d.ts +1 -1
- package/dist/types/ts4.1/drm/commonEme/MsCommonEme.d.ts +1 -1
- package/dist/types/ts4.1/drm/commonEme/StandardCommonEme.d.ts +1 -1
- package/dist/types/ts4.1/drm/commonEme/WebKitCommonEme.d.ts +2 -2
- package/dist/types/ts4.1/drm/licenseProvider/LicenseProvider.d.ts +1 -1
- package/dist/types/ts4.1/global/environment.d.ts +6 -2
- package/dist/types/ts4.1/patch/media/patches/createPreventStallsPatch.d.ts +1 -1
- package/dist/types/ts4.1/patch/media/patches/createUnreliablePlaybackEventsPatch.d.ts +1 -1
- package/dist/types/ts4.1/playback/PlaybackControllerImpl.d.ts +1 -1
- package/dist/types/ts4.1/playback/logging/playbackStateLoggingHandler.d.ts +1 -1
- package/dist/types/ts4.1/playback/nextHasMetadata.d.ts +1 -1
- package/dist/types/ts4.1/streaming/ContentStream.d.ts +4 -4
- package/dist/types/ts4.1/streaming/ContentStreamingOptions.d.ts +2 -2
- package/dist/types/ts4.1/streaming/MediaQualityMetadata.d.ts +2 -2
- package/dist/types/ts4.1/streaming/MediaTimeline.d.ts +6 -5
- package/dist/types/ts4.1/streaming/SegmentController.d.ts +2 -7
- package/dist/types/ts4.1/streaming/SegmentControllerImpl.d.ts +5 -6
- package/dist/types/ts4.1/streaming/SegmentReference.d.ts +1 -1
- package/dist/types/ts4.1/streaming/StreamingEventMap.d.ts +1 -1
- package/dist/types/ts4.1/streaming/abr/QualitySelector.d.ts +1 -1
- package/dist/types/ts4.1/streaming/abr/QualitySelectorImpl.d.ts +18 -3
- package/dist/types/ts4.1/streaming/buffering/BufferingController.d.ts +3 -13
- package/dist/types/ts4.1/streaming/buffering/MediaSourceController.d.ts +41 -15
- package/dist/types/ts4.1/streaming/buffering/SourceBufferController.d.ts +1 -1
- package/dist/types/ts4.1/streaming/createDefaultMediaTimelineTransformer.d.ts +1 -1
- package/dist/types/ts4.1/streaming/mediaTimelineFilter.d.ts +3 -3
- package/dist/types/ts4.1/streaming/mediaTimelineLanguageFilter.d.ts +1 -1
- package/dist/types/ts4.1/streaming/util/segment.d.ts +1 -1
- package/dist/types/ts4.1/track/AutoResetController.d.ts +37 -12
- package/dist/types/ts4.1/track/TrackController.d.ts +2 -2
- package/dist/types/ts4.1/track/TrackFactory.d.ts +1 -1
- package/dist/types/ts4.1/track/createVinylTrackFactories.d.ts +5 -5
- package/dist/types/ts4.1/track/dash/DashManifestController.d.ts +1 -1
- package/dist/types/ts4.1/track/dash/DashTrack.d.ts +4 -4
- package/dist/types/ts4.1/track/dash/buildDashMediaTimeline.d.ts +2 -2
- package/dist/types/ts4.1/track/dash/createDashContentTypesValue.d.ts +2 -2
- package/dist/types/ts4.1/track/dash/createDashFactories.d.ts +12 -12
- package/dist/types/ts4.1/track/dash/createDashManifestProvider.d.ts +1 -1
- package/dist/types/ts4.1/track/dash/createDefaultDashManifestTransformer.d.ts +1 -1
- package/dist/types/ts4.1/track/dash/manifestTransformUtils.d.ts +1 -1
- package/dist/types/ts4.1/track/dash/timeline/DashRepresentationSegmentProvider.d.ts +3 -3
- package/dist/types/ts4.1/track/dash/urlDashManifestProvider.d.ts +1 -1
- package/dist/types/ts4.1/track/dash/util/mpd.d.ts +3 -2
- package/dist/types/ts4.1/track/hls/buildHlsMediaTimeline.d.ts +3 -3
- package/dist/types/ts4.1/track/hls/createDefaultHlsManifestTransformer.d.ts +1 -1
- package/dist/types/ts4.1/track/hls/util/hlsSegmentTime.d.ts +1 -1
- package/dist/types/ts4.1/track/mse/MseTrack.d.ts +3 -3
- package/dist/types/ts4.1/track/source/FixedPlaybackQuality.d.ts +1 -1
- package/dist/types/ts4.1/track/source/SourceObjectTrack.d.ts +5 -5
- package/dist/types/ts4.1/track/source/SourceTrack.d.ts +5 -5
- package/dist/types/ts4.1/track/source/SourceTrackBase.d.ts +3 -3
- package/dist/types/ts4.1/vinyl/VinylDeps.d.ts +1 -1
- package/dist/types/ts4.1/vinyl/VinylPlayer.d.ts +18 -2
- package/dist/types/ts4.1/vinyl/createVinylFactories.d.ts +9 -11
- package/dist/types/ts4.7/drm/DrmController.d.ts +2 -2
- package/dist/types/ts4.7/drm/DrmControllerImpl.d.ts +3 -3
- package/dist/types/ts4.7/drm/DrmKeySystemResolver.d.ts +1 -1
- package/dist/types/ts4.7/drm/DrmOptions.d.ts +1 -1
- package/dist/types/ts4.7/drm/commonEme/CommonEme.d.ts +2 -2
- package/dist/types/ts4.7/drm/commonEme/CommonEmeFactory.d.ts +1 -1
- package/dist/types/ts4.7/drm/commonEme/MsCommonEme.d.ts +1 -1
- package/dist/types/ts4.7/drm/commonEme/StandardCommonEme.d.ts +1 -1
- package/dist/types/ts4.7/drm/commonEme/WebKitCommonEme.d.ts +2 -2
- package/dist/types/ts4.7/drm/licenseProvider/LicenseProvider.d.ts +1 -1
- package/dist/types/ts4.7/global/environment.d.ts +6 -2
- package/dist/types/ts4.7/patch/media/patches/createPreventStallsPatch.d.ts +1 -1
- package/dist/types/ts4.7/patch/media/patches/createUnreliablePlaybackEventsPatch.d.ts +1 -1
- package/dist/types/ts4.7/playback/PlaybackControllerImpl.d.ts +1 -1
- package/dist/types/ts4.7/playback/logging/playbackStateLoggingHandler.d.ts +1 -1
- package/dist/types/ts4.7/playback/nextHasMetadata.d.ts +1 -1
- package/dist/types/ts4.7/streaming/ContentStream.d.ts +4 -4
- package/dist/types/ts4.7/streaming/ContentStreamingOptions.d.ts +2 -2
- package/dist/types/ts4.7/streaming/MediaQualityMetadata.d.ts +2 -2
- package/dist/types/ts4.7/streaming/MediaTimeline.d.ts +6 -5
- package/dist/types/ts4.7/streaming/SegmentController.d.ts +2 -7
- package/dist/types/ts4.7/streaming/SegmentControllerImpl.d.ts +5 -6
- package/dist/types/ts4.7/streaming/SegmentReference.d.ts +1 -1
- package/dist/types/ts4.7/streaming/StreamingEventMap.d.ts +1 -1
- package/dist/types/ts4.7/streaming/abr/QualitySelector.d.ts +1 -1
- package/dist/types/ts4.7/streaming/abr/QualitySelectorImpl.d.ts +18 -3
- package/dist/types/ts4.7/streaming/buffering/BufferingController.d.ts +3 -13
- package/dist/types/ts4.7/streaming/buffering/MediaSourceController.d.ts +41 -15
- package/dist/types/ts4.7/streaming/buffering/SourceBufferController.d.ts +1 -1
- package/dist/types/ts4.7/streaming/createDefaultMediaTimelineTransformer.d.ts +1 -1
- package/dist/types/ts4.7/streaming/mediaTimelineFilter.d.ts +3 -3
- package/dist/types/ts4.7/streaming/mediaTimelineLanguageFilter.d.ts +1 -1
- package/dist/types/ts4.7/streaming/util/segment.d.ts +1 -1
- package/dist/types/ts4.7/track/AutoResetController.d.ts +37 -12
- package/dist/types/ts4.7/track/TrackController.d.ts +2 -2
- package/dist/types/ts4.7/track/TrackFactory.d.ts +1 -1
- package/dist/types/ts4.7/track/createVinylTrackFactories.d.ts +5 -5
- package/dist/types/ts4.7/track/dash/DashManifestController.d.ts +1 -1
- package/dist/types/ts4.7/track/dash/DashTrack.d.ts +4 -4
- package/dist/types/ts4.7/track/dash/buildDashMediaTimeline.d.ts +2 -2
- package/dist/types/ts4.7/track/dash/createDashContentTypesValue.d.ts +2 -2
- package/dist/types/ts4.7/track/dash/createDashFactories.d.ts +12 -12
- package/dist/types/ts4.7/track/dash/createDashManifestProvider.d.ts +1 -1
- package/dist/types/ts4.7/track/dash/createDefaultDashManifestTransformer.d.ts +1 -1
- package/dist/types/ts4.7/track/dash/manifestTransformUtils.d.ts +1 -1
- package/dist/types/ts4.7/track/dash/timeline/DashRepresentationSegmentProvider.d.ts +3 -3
- package/dist/types/ts4.7/track/dash/urlDashManifestProvider.d.ts +1 -1
- package/dist/types/ts4.7/track/dash/util/mpd.d.ts +3 -2
- package/dist/types/ts4.7/track/hls/buildHlsMediaTimeline.d.ts +3 -3
- package/dist/types/ts4.7/track/hls/createDefaultHlsManifestTransformer.d.ts +1 -1
- package/dist/types/ts4.7/track/hls/util/hlsSegmentTime.d.ts +1 -1
- package/dist/types/ts4.7/track/mse/MseTrack.d.ts +2 -2
- package/dist/types/ts4.7/track/source/FixedPlaybackQuality.d.ts +1 -1
- package/dist/types/ts4.7/track/source/SourceObjectTrack.d.ts +4 -4
- package/dist/types/ts4.7/track/source/SourceTrack.d.ts +4 -4
- package/dist/types/ts4.7/track/source/SourceTrackBase.d.ts +2 -2
- package/dist/types/ts4.7/vinyl/VinylDeps.d.ts +1 -1
- package/dist/types/ts4.7/vinyl/VinylPlayer.d.ts +26 -2
- package/dist/types/ts4.7/vinyl/createVinylFactories.d.ts +9 -11
- package/dist/unit/types/current/streaming/MediaTimeline.test.js +6 -1
- package/dist/unit/types/current/streaming/MseTrack.test.js +4 -0
- package/dist/unit/types/current/streaming/SegmentControllerImpl.test.js +3 -33
- package/dist/unit/types/current/streaming/abr/QualitySelectorImpl.test.js +73 -0
- package/dist/unit/types/current/streaming/buffering/BufferingController.test.js +1 -41
- package/dist/unit/types/current/streaming/buffering/MediaSourceController.test.js +97 -17
- package/dist/unit/types/current/streaming/createDefaultMediaTimelineTransformer.test.js +6 -0
- package/dist/unit/types/current/streaming/mediaTimelineFilter.test.js +2 -0
- package/dist/unit/types/current/streaming/mediaTimelineLanguageFilter.test.js +7 -0
- package/dist/unit/types/current/track/AutoResetController.test.js +134 -22
- package/dist/unit/types/current/track/dash/createDashContentStreamFactories.test.js +5 -1
- package/dist/unit/types/current/track/dash/createSegmentControllerFactory.test.js +5 -1
- package/dist/unit/types/current/track/dash/util/mpd.test.js +29 -0
- package/dist/unit/types/current/track/hls/buildHlsMediaTimeline.test.js +16 -8
- package/dist/unit/types/current/track/hls/createHlsContentStreamFactories.test.js +5 -1
- package/dist/unit/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/unit/types/current/vinyl/VinylPlayer.test.js +35 -0
- package/dist/vinylTestUtil/index.js +20 -14
- package/dist/vinylTestUtil/index.js.map +2 -2
- package/dist/vinylTestUtil/types/current/media/FrequencyAnalyzer.js +1 -1
- package/dist/vinylTestUtil/types/current/mediaSource/ControlledMediaSource.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/dash/mockDashManifest.d.ts +12 -12
- package/dist/vinylTestUtil/types/current/mock/dom/ms/MockMSMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/current/mock/dom/webkit/MockWebKitMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.d.ts +6 -6
- package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/player/MockVinylPlayerDependencies.js +7 -7
- package/dist/vinylTestUtil/types/current/mock/streaming/MockSegmentController.d.ts +0 -1
- package/dist/vinylTestUtil/types/current/mock/streaming/MockSegmentController.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/streaming/MockSegmentController.js +0 -1
- package/dist/vinylTestUtil/types/current/mock/streaming/buffering/MockMediaSourceController.d.ts +0 -1
- package/dist/vinylTestUtil/types/current/mock/streaming/buffering/MockMediaSourceController.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/streaming/buffering/MockMediaSourceController.js +0 -1
- package/dist/vinylTestUtil/types/current/mock/track/MockAutoResetController.d.ts +1 -0
- package/dist/vinylTestUtil/types/current/mock/track/MockAutoResetController.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/track/MockAutoResetController.js +1 -0
- package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.d.ts +5 -5
- package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/track/dash/createMockDashDependencies.js +11 -7
- package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.d.ts +5 -5
- package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/mock/track/hls/createMockHlsDependencies.js +11 -7
- package/dist/vinylTestUtil/types/current/player/createVinylSuite.js +1 -1
- package/dist/vinylTestUtil/types/current/tsconfig.tsbuildinfo +1 -1
- package/dist/vinylTestUtil/types/current/util/playback/expectTrackCanSeek.js +1 -1
- package/dist/vinylTestUtil/types/current/util/playback/expectTrackPlays.js +2 -2
- package/dist/vinylTestUtil/types/current/util/playback/expectTrackPlaysUntil.d.ts.map +1 -1
- package/dist/vinylTestUtil/types/current/util/playback/expectTrackPlaysUntil.js +1 -2
- package/dist/vinylTestUtil/types/ts3.7/mock/dash/mockDashManifest.d.ts +12 -12
- package/dist/vinylTestUtil/types/ts3.7/mock/dom/ms/MockMSMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/ts3.7/mock/dom/webkit/MockWebKitMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/ts3.7/mock/player/MockVinylPlayerDependencies.d.ts +6 -6
- package/dist/vinylTestUtil/types/ts3.7/mock/streaming/MockSegmentController.d.ts +0 -1
- package/dist/vinylTestUtil/types/ts3.7/mock/streaming/buffering/MockMediaSourceController.d.ts +0 -1
- package/dist/vinylTestUtil/types/ts3.7/mock/track/MockAutoResetController.d.ts +1 -0
- package/dist/vinylTestUtil/types/ts3.7/mock/track/dash/createMockDashDependencies.d.ts +5 -5
- package/dist/vinylTestUtil/types/ts3.7/mock/track/hls/createMockHlsDependencies.d.ts +5 -5
- package/dist/vinylTestUtil/types/ts4.1/mock/dash/mockDashManifest.d.ts +12 -12
- package/dist/vinylTestUtil/types/ts4.1/mock/dom/ms/MockMSMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/ts4.1/mock/dom/webkit/MockWebKitMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/ts4.1/mock/player/MockVinylPlayerDependencies.d.ts +6 -6
- package/dist/vinylTestUtil/types/ts4.1/mock/streaming/MockSegmentController.d.ts +0 -1
- package/dist/vinylTestUtil/types/ts4.1/mock/streaming/buffering/MockMediaSourceController.d.ts +0 -1
- package/dist/vinylTestUtil/types/ts4.1/mock/track/MockAutoResetController.d.ts +1 -0
- package/dist/vinylTestUtil/types/ts4.1/mock/track/dash/createMockDashDependencies.d.ts +5 -5
- package/dist/vinylTestUtil/types/ts4.1/mock/track/hls/createMockHlsDependencies.d.ts +5 -5
- package/dist/vinylTestUtil/types/ts4.7/mock/dash/mockDashManifest.d.ts +12 -12
- package/dist/vinylTestUtil/types/ts4.7/mock/dom/ms/MockMSMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/ts4.7/mock/dom/webkit/MockWebKitMediaKeySession.d.ts +2 -2
- package/dist/vinylTestUtil/types/ts4.7/mock/player/MockVinylPlayerDependencies.d.ts +6 -6
- package/dist/vinylTestUtil/types/ts4.7/mock/streaming/MockSegmentController.d.ts +0 -1
- package/dist/vinylTestUtil/types/ts4.7/mock/streaming/buffering/MockMediaSourceController.d.ts +0 -1
- package/dist/vinylTestUtil/types/ts4.7/mock/track/MockAutoResetController.d.ts +1 -0
- package/dist/vinylTestUtil/types/ts4.7/mock/track/dash/createMockDashDependencies.d.ts +5 -5
- package/dist/vinylTestUtil/types/ts4.7/mock/track/hls/createMockHlsDependencies.d.ts +5 -5
- package/docs/USAGE.md +33 -0
- package/package.json +13 -15
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../src/vinyl/playerConfigFactory.ts", "../src/client/Capabilities.ts", "../src/util/media/mediaSource.ts", "../src/util/media/getAudioContext.ts", "../src/client/CapabilitiesImpl.ts", "../src/vinyl/createVinylFactories.ts", "../src/patch/media/patchMediaElement.ts", "../src/patch/media/patches/createUnreliablePlaybackEventsPatch.ts", "../src/patch/media/patches/createPreventStallsPatch.ts", "../src/playback/PlaybackControllerImpl.ts", "../src/playback/PlaybackController.ts", "../src/playback/ReadonlyPlaybackController.ts", "../src/playback/error/InvalidSeekError.ts", "../src/playback/logging/playbackStateLoggingHandler.ts", "../src/event/ChangeEvent.ts", "../src/playback/nextHasMetadata.ts", "../src/playback/error/ReportableMediaError.ts", "../src/playback/logging/mediaErrorToJson.ts", "../src/playback/PlaybackSourceImpl.ts", "../src/track/TrackFactory.ts", "../src/track/source/SourceObjectTrack.ts", "../src/track/TrackBase.ts", "../src/drm/DrmOptions.ts", "../src/drm/DrmKeySystem.ts", "../src/drm/licenseProvider/LicenseProvider.ts", "../src/track/source/FixedPlaybackQuality.ts", "../src/track/source/SourceTrackBase.ts", "../src/streaming/MediaQualityMetadata.ts", "../src/streaming/DescriptorRecord.ts", "../src/track/source/SourceTrack.ts", "../src/track/dash/DashTrack.ts", "../src/track/mse/MseTrack.ts", "../src/streaming/MediaTimeline.ts", "../src/track/hls/HlsTrack.ts", "../src/track/createVinylTrackFactories.ts", "../src/track/TrackController.ts", "../src/patch/media/MediaElementPatchOptions.ts", "../src/vinyl/VinylPatchOptions.ts", "../src/track/dash/util/mpd.ts", "../src/track/dash/util/uriResolution.ts", "../src/track/dash/createDefaultDashManifestTransformer.ts", "../src/track/dash/manifestTransformUtils.ts", "../src/track/dash/DashMediaQualityMetadataResolver.ts", "../src/track/mse/codec.ts", "../src/track/dash/util/mimeType.ts", "../src/drm/CencEncryptionScheme.ts", "../src/streaming/buffering/MediaSourceController.ts", "../src/
|
|
4
|
-
"sourcesContent": ["/** Auto-generated from build scripts */\nexport * from './vinyl/playerConfigFactory'\nexport * from './vinyl/createVinylFactories'\nexport * from './vinyl/VinylPlayer'\nexport * from './vinyl/VinylPatchOptions'\nexport * from './vinyl/VinylOptions'\nexport * from './vinyl/VinylDeps'\nexport * from './vinyl/ReadonlyPlaybackStreamingState'\nexport * from './util/media/sourceBuffer'\nexport * from './util/media/mediaSource'\nexport * from './util/media/getAudioContext'\nexport * from './track/createVinylTrackFactories'\nexport * from './track/createSegmentDataProvider'\nexport * from './track/TrackFactory'\nexport * from './track/TrackController'\nexport * from './track/TrackBase'\nexport * from './track/Track'\nexport * from './track/AutoResetController'\nexport * from './track/source/SourceTrackBase'\nexport * from './track/source/SourceTrack'\nexport * from './track/source/SourceObjectTrack'\nexport * from './track/source/FixedPlaybackQuality'\nexport * from './track/mse/codec'\nexport * from './track/mse/MseTrack'\nexport * from './track/hls/createUrlHlsManifestProvider'\nexport * from './track/hls/createHlsFactories'\nexport * from './track/hls/createHlsContentTypesValue'\nexport * from './track/hls/createHlsContentStreamFactories'\nexport * from './track/hls/createDefaultHlsManifestTransformer'\nexport * from './track/hls/buildHlsMediaTimeline'\nexport * from './track/hls/HlsTrack'\nexport * from './track/hls/HlsMediaQualityMetadataResolver'\nexport * from './track/hls/HlsManifestProvider'\nexport * from './track/hls/HlsManifestController'\nexport * from './track/hls/util/hlsSegmentTime'\nexport * from './track/hls/util/hlsByteRangeToMediaRange'\nexport * from './track/filters/sampleRateFilter'\nexport * from './track/filters/resourceTypeFilter'\nexport * from './track/filters/languageFilter'\nexport * from './track/filters/keySystemFilter'\nexport * from './track/dash/urlDashManifestProvider'\nexport * from './track/dash/manifestTransformUtils'\nexport * from './track/dash/createSegmentControllerFactory'\nexport * from './track/dash/createDefaultDashManifestTransformer'\nexport * from './track/dash/createDashManifestProvider'\nexport * from './track/dash/createDashFactories'\nexport * from './track/dash/createDashContentTypesValue'\nexport * from './track/dash/createDashContentStreamFactories'\nexport * from './track/dash/buildDashMediaTimeline'\nexport * from './track/dash/DashTrack'\nexport * from './track/dash/DashMediaQualityMetadataResolver'\nexport * from './track/dash/DashManifestProvider'\nexport * from './track/dash/DashManifestController'\nexport * from './track/dash/util/uriResolution'\nexport * from './track/dash/util/mpd'\nexport * from './track/dash/util/mimeType'\nexport * from './track/dash/timeline/DashRepresentationSegmentProvider'\nexport * from './streaming/mediaTimelineLanguageFilter'\nexport * from './streaming/mediaTimelineFilter'\nexport * from './streaming/createDefaultMediaTimelineTransformer'\nexport * from './streaming/StreamingEventMap'\nexport * from './streaming/SegmentReference'\nexport * from './streaming/SegmentPrefetch'\nexport * from './streaming/SegmentDataSlot'\nexport * from './streaming/SegmentControllerImpl'\nexport * from './streaming/SegmentController'\nexport * from './streaming/MediaTimeline'\nexport * from './streaming/MediaQualityMetadata'\nexport * from './streaming/ManifestController'\nexport * from './streaming/DrmInitDataType'\nexport * from './streaming/DescriptorRecord'\nexport * from './streaming/ContentTypesValue'\nexport * from './streaming/ContentStreamingOptions'\nexport * from './streaming/ContentStream'\nexport * from './streaming/util/segment'\nexport * from './streaming/buffering/SourceBufferController'\nexport * from './streaming/buffering/MediaSourceController'\nexport * from './streaming/buffering/BufferingController'\nexport * from './streaming/buffering/error/SourceBufferError'\nexport * from './streaming/abr/QualitySelectorImpl'\nexport * from './streaming/abr/QualitySelector'\nexport * from './playback/nextHasMetadata'\nexport * from './playback/ReadonlyPlaybackController'\nexport * from './playback/PlaybackSourceImpl'\nexport * from './playback/PlaybackSource'\nexport * from './playback/PlaybackControllerImpl'\nexport * from './playback/PlaybackController'\nexport * from './playback/loudness/LoudnessNormalizationControllerImplOptions'\nexport * from './playback/loudness/LoudnessNormalizationControllerImpl'\nexport * from './playback/loudness/LoudnessNormalizationController'\nexport * from './playback/logging/playbackStateLoggingHandler'\nexport * from './playback/logging/mediaErrorToJson'\nexport * from './playback/error/ReportableMediaError'\nexport * from './playback/error/InvalidSeekError'\nexport * from './patch/media/patchMediaElement'\nexport * from './patch/media/MediaElementPatchOptions'\nexport * from './patch/media/HtmlMediaElementPatch'\nexport * from './patch/media/patches/createUnreliablePlaybackEventsPatch'\nexport * from './patch/media/patches/createPreventStallsPatch'\nexport * from './global/initializeVinylGlobal'\nexport * from './global/globalRef'\nexport * from './global/environment'\nexport * from './global/configureVinylGlobal'\nexport * from './global/PlayerRegistry'\nexport * from './event/ChangeEvent'\nexport * from './event/BasicErrorEvent'\nexport * from './drm/DrmOptions'\nexport * from './drm/DrmKeySystemResolver'\nexport * from './drm/DrmKeySystem'\nexport * from './drm/DrmControllerImpl'\nexport * from './drm/DrmController'\nexport * from './drm/CencEncryptionScheme'\nexport * from './drm/util/unpackPlayReadyChallenge'\nexport * from './drm/util/extractContentId'\nexport * from './drm/util/createFairPlaySessionInitData'\nexport * from './drm/licenseProvider/defaultLicenseProvider'\nexport * from './drm/licenseProvider/LicenseProvider'\nexport * from './drm/error/DrmError'\nexport * from './drm/dom/WebKitMediaKeys'\nexport * from './drm/dom/MSMediaKeys'\nexport * from './drm/dom/HTMLMediaElement'\nexport * from './drm/commonEme/createDrmErrorHandler'\nexport * from './drm/commonEme/WebKitCommonEme'\nexport * from './drm/commonEme/StandardCommonEme'\nexport * from './drm/commonEme/MsCommonEme'\nexport * from './drm/commonEme/EncryptedInitData'\nexport * from './drm/commonEme/CommonEmeFactory'\nexport * from './drm/commonEme/CommonEme'\nexport * from './client/Client'\nexport * from './client/CapabilitiesImpl'\nexport * from './client/Capabilities'\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { data, type MutableValue } from '@amazon/vinyl-observable'\nimport type { AddDisposable, AnyRecord } from '@amazon/vinyl-util'\nimport type { Validator } from '@amazon/vinyl-validation'\n\nexport function playerConfigFactory<T>(\n defaults: T,\n validator: Validator<T>\n): (_deps: AnyRecord, add: AddDisposable) => MutableValue<T> {\n return (_deps, add) => {\n const config = data<T>(defaults)\n add(\n config.onData((data) => {\n // Throws if data does not pass validation\n validator.assert(data)\n })\n )\n return config\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport type { DrmKeySystemSupport } from '@/drm/DrmController'\n\nexport enum CanPlayTypeResult {\n /**\n * The media cannot be played on the current device.\n */\n NO = 'no',\n\n /**\n * There is not enough information to determine whether the media can play.\n */\n MAYBE = 'maybe',\n\n /**\n * The media is probably playable on this device.\n */\n PROBABLY = 'probably',\n}\n\n/**\n * Detected capabilities of the device.\n */\nexport interface Capabilities {\n /**\n * Returns true if Media Source Extensions are supported.\n *\n * Note that this does not test DRM or any DRM key systems.\n */\n readonly mse: boolean\n\n /**\n * Returns true if Encrypted Media Extensions are supported.\n */\n readonly eme: boolean\n\n /**\n * Returns true if native Dynamic Adaptive Streaming is supported.\n *\n * (Legacy Edge 12-18 and XBox One)\n * Note that this is not the same as supporting a dash track.\n */\n readonly dash: boolean\n\n /**\n * Returns true if native HTTP Live Streaming is supported.\n *\n * iOS 7.0+, Safari 8.0+\n * Note that this does not do FairPlay detection.\n */\n readonly hls: boolean\n\n /**\n * Returns the sample rate, in samples per second, that this platform supports.\n * Returns null if the sample rate cannot be determined.\n */\n readonly sampleRate: number | null\n\n /**\n * Returns a string that specifies whether the client can play a given media resource type for progressive\n * content.\n *\n * @param type A string specifying the MIME type of the media and (optionally) a codecs\n * parameter containing a comma-separated list of the supported codecs.\n */\n canPlayType(type: string): CanPlayTypeResult\n\n /**\n * Returns a boolean that specifies whether the client can play a given media resource type for streaming\n * content with media source extensions.\n *\n * @param type A string specifying the MIME type of the media and (optionally) a codecs\n * parameter containing a comma-separated list of the supported codecs.\n */\n canPlayTypeMse(type: string): boolean\n\n /**\n * Returns a promise describing support for the given key system.\n *\n * @param keySystem\n */\n supportsKeySystem(keySystem: DrmKeySystem): Promise<DrmKeySystemSupport>\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { MediaUnsupportedError } from '@amazon/vinyl-util'\nimport type { Unsubscribe } from '@amazon/vinyl-util'\nimport type { SignalOptions } from '@amazon/vinyl-util'\nimport { withTimeout } from '@amazon/vinyl-util'\n\ndeclare global {\n var ManagedMediaSource: typeof MediaSource | undefined\n}\n\n/**\n * Returns true if the UA supports media source extensions.\n */\nexport function supportsMse(): boolean {\n return (\n typeof ManagedMediaSource === 'function' ||\n typeof MediaSource === 'function'\n )\n}\n\n/**\n * Returns ManagedMediaSource or MediaSource.\n */\nfunction getMediaSourceCtor(): typeof MediaSource {\n if (typeof ManagedMediaSource === 'function') return ManagedMediaSource\n else return MediaSource\n}\n\n/**\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaSource/isTypeSupported_static)\n */\nexport function isTypeSupported(type: string): boolean {\n assertMseSupported()\n return getMediaSourceCtor().isTypeSupported(type)\n}\n\n/**\n * Constructs a new ManagedMediaSource or MediaSource.\n */\nexport function createMediaSource(): MediaSource {\n assertMseSupported()\n return new (getMediaSourceCtor())()\n}\n\n/**\n * Throws a MediaUnsupportedError if MSE is not supported.\n */\nexport function assertMseSupported(): void {\n if (!supportsMse())\n throw new MediaUnsupportedError(\n 'Media Source Extensions not supported',\n 'mse-unsupported'\n )\n}\n\n/**\n * Invokes a callback when the media source is open.\n * The callback will be invoked immediately if already open.\n */\nexport function onMediaSourceOpen(\n mediaSource: MediaSource,\n callback: () => void,\n options?: SignalOptions\n): Unsubscribe {\n const open = mediaSource.readyState === 'open'\n if (open) callback()\n const handler = () => callback()\n if (!options?.once || !open) {\n // compatibility note: MediaSource.addEventListener is more widely supported than onsourceopen\n // https://caniuse.com/mdn-api_mediasource_sourceopen_event\n mediaSource.addEventListener('sourceopen', handler, options)\n return () => mediaSource.removeEventListener('sourceopen', handler)\n } else {\n return () => {}\n }\n}\n\n/**\n * Invokes a callback when the media source is next ended.\n * The callback will be invoked immediately if already ended.\n */\nexport function onMediaSourceEnded(\n mediaSource: MediaSource,\n callback: () => void,\n options?: SignalOptions\n): Unsubscribe {\n const ended = mediaSource.readyState === 'ended'\n if (ended) callback()\n const handler = () => callback()\n if (!options?.once || !ended) {\n mediaSource.addEventListener('sourceended', handler, options)\n return () => mediaSource.removeEventListener('sourceended', handler)\n } else {\n return () => {}\n }\n}\n\n/**\n * Returns a Promise that resolves when the media source is next in an 'ended' state.\n *\n * @param mediaSource\n * @param timeout The number of seconds before rejecting with a TimeoutError.\n * @param timeoutMessage\n */\nexport function nextMediaSourceEnded(\n mediaSource: MediaSource,\n timeout: number = 5,\n timeoutMessage?: string\n): Promise<void> {\n return withTimeout(\n new Promise((resolve) => {\n onMediaSourceEnded(mediaSource, resolve, { once: true })\n }),\n timeout,\n timeoutMessage\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { globalRef, lazy } from '@amazon/vinyl-util'\n\ntype MaybeAudioContext = typeof AudioContext | undefined\n\ndeclare global {\n var webkitAudioContext: MaybeAudioContext\n}\n\n/**\n * Creates a new AudioContext.\n * Returns null if not supported on this platform.\n */\nexport function createAudioContext(): AudioContext | null {\n const ctor =\n (global.AudioContext as MaybeAudioContext) ?? global.webkitAudioContext\n return ctor ? new ctor() : null\n}\n\n/**\n * Some devices have a hard limit to how many audio context objects can be created.\n * Uses a lazy instance to ensure only one context is created, even within integ tests.\n */\nconst audioContextSingleton = /* @__PURE__ */ lazy(createAudioContext)\n\n/**\n * The audio context global reference.\n */\nexport const audioContextRef = /* @__PURE__ */ globalRef<AudioContext | null>(\n () => audioContextSingleton.value\n)\n\n/**\n * Returns an AudioContext singleton, or returns null if not supported on this platform.\n *\n * If the first time this is called is outside a user gesture, the AudioContext will be unable to start in a\n * running state.\n */\nexport function getAudioContext(): AudioContext | null {\n return audioContextRef.value\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type DrmKeySystem } from '@/drm/DrmKeySystem'\nimport type { Capabilities } from './Capabilities'\nimport { CanPlayTypeResult } from './Capabilities'\nimport { isTypeSupported, supportsMse } from '@/util/media/mediaSource'\nimport { getAudioContext } from '@/util/media/getAudioContext'\nimport type { DrmController, DrmKeySystemSupport } from '@/drm/DrmController'\n\n/**\n * Dependencies for CapabilitiesImpl.\n */\nexport interface CapabilitiesImplDeps {\n readonly media: HTMLMediaElement\n readonly drmController: DrmController\n}\n\n/**\n * Client support detection.\n */\nexport class CapabilitiesImpl implements Capabilities {\n constructor(private readonly deps: CapabilitiesImplDeps) {}\n\n get mse(): boolean {\n return supportsMse()\n }\n\n get dash(): boolean {\n return this.canPlayType('application/dash+xml') !== CanPlayTypeResult.NO\n }\n\n get hls(): boolean {\n return (\n this.canPlayType('application/vnd.apple.mpegurl') !==\n CanPlayTypeResult.NO\n )\n }\n\n get eme(): boolean {\n return this.deps.drmController.isEmeSupported()\n }\n\n get sampleRate(): number | null {\n return getAudioContext()?.sampleRate ?? null\n }\n\n canPlayType(type: string): CanPlayTypeResult {\n const media: HTMLMediaElement = this.deps.media\n if (typeof media.canPlayType === 'undefined')\n return CanPlayTypeResult.NO\n const str = media.canPlayType(type)\n switch (str) {\n case '':\n return CanPlayTypeResult.NO\n case 'maybe':\n return CanPlayTypeResult.MAYBE\n case 'probably':\n return CanPlayTypeResult.PROBABLY\n }\n }\n\n canPlayTypeMse(type: string): boolean {\n return isTypeSupported(type)\n }\n\n async supportsKeySystem(\n keySystem: DrmKeySystem\n ): Promise<DrmKeySystemSupport> {\n // Take the most commonly supported codec and media format, check the DrmController if\n // it is supported with the given key system.\n return this.deps.drmController.isSupported({\n initDataType: 'cenc',\n encryptionScheme: 'cenc',\n contentType: 'audio',\n mimeType: 'audio/mp4; codecs=\"mp4a.40.2\"',\n contentProtections: [{ keySystem }],\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { CapabilitiesImplDeps } from '@/client/CapabilitiesImpl'\nimport { CapabilitiesImpl } from '@/client/CapabilitiesImpl'\nimport type { Merge, PartialDeep, PatchedRef } from '@amazon/vinyl-util'\nimport { mergeDeep, noop } from '@amazon/vinyl-util'\nimport { patchMediaElement } from '@/patch/media/patchMediaElement'\nimport type {\n PlaybackControllerImplDeps,\n PlaybackControllerImplOptions,\n} from '@/playback/PlaybackControllerImpl'\nimport { PlaybackControllerImpl } from '@/playback/PlaybackControllerImpl'\nimport type { PlaybackSourceImplDeps } from '@/playback/PlaybackSourceImpl'\nimport { PlaybackSourceImpl } from '@/playback/PlaybackSourceImpl'\nimport {\n createVinylTrackFactories,\n type VinylTrackFactoryDeps,\n} from '@/track/createVinylTrackFactories'\nimport type {\n TrackControllerImplDeps,\n TrackControllerImplOptions,\n} from '@/track/TrackController'\nimport { TrackControllerImpl } from '@/track/TrackController'\nimport { createTrackFactory } from '@/track/TrackFactory'\nimport type { VinylDeps } from './VinylDeps'\nimport type { VinylPatchOptions } from './VinylPatchOptions'\nimport { defaultPatchOptions } from './VinylPatchOptions'\nimport { type QualitySelectorImplOptions } from '@/streaming/abr/QualitySelectorImpl'\nimport { createDashFactories } from '@/track/dash/createDashFactories'\nimport { createHlsFactories } from '@/track/hls/createHlsFactories'\nimport { type DrmOptions } from '@/drm/DrmOptions'\nimport { commonEmeFactory } from '@/drm/commonEme/CommonEmeFactory'\nimport {\n DrmControllerImpl,\n type DrmControllerImplDeps,\n} from '@/drm/DrmControllerImpl'\nimport { defaultDrmKeySystemResolver } from '@/drm/DrmKeySystemResolver'\nimport { LoudnessNormalizationControllerImpl } from '@/playback/loudness/LoudnessNormalizationControllerImpl'\nimport {\n AutoResetControllerImpl,\n type AutoResetControllerImplDeps,\n type AutoResetControllerImplOptions,\n} from '@/track/AutoResetController'\nimport type { Dependencies, Factories } from '@amazon/vinyl-di'\nimport { validateFactories } from '@amazon/vinyl-di'\nimport type { ContentStreamingOptions } from '@/streaming/ContentStreamingOptions'\nimport {\n defaultVinylOptions,\n type VinylOptions,\n vinylOptionsValidator,\n} from '@/vinyl/VinylOptions'\nimport { playerConfigFactory } from '@/vinyl/playerConfigFactory'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\n\n/**\n * Configuration used by the default dependency factories for Vinyl.\n *\n * These options are used during player construction, changes after construction will have no\n * effect.\n */\nexport interface VinylDependencyOptions {\n /**\n * The media element.\n */\n readonly media: HTMLMediaElement\n\n /**\n * Flags for patches that should be applied browser-specifically.\n * These will be defaulted based on the user-agent.\n */\n readonly patches?: PartialDeep<VinylPatchOptions>\n\n /**\n * Configuration for the track controller.\n */\n readonly trackController?: Partial<TrackControllerImplOptions>\n\n /**\n * Configuration for the playback controller.\n */\n readonly playbackController?: Partial<PlaybackControllerImplOptions>\n\n /**\n * Configuration for segmented streaming tracks (hls / dash).\n */\n readonly streaming?: PartialDeep<ContentStreamingOptions>\n\n /**\n * Configuration for all drm-related components.\n */\n readonly drm?: Partial<DrmOptions>\n\n /**\n * Configuration for adaptive bitrate switching.\n */\n readonly abr?: PartialDeep<QualitySelectorImplOptions>\n\n /**\n * Configuration for auto-reset behavior.\n */\n readonly autoReset?: Partial<AutoResetControllerImplOptions>\n}\n\n/**\n * Creates the dependency factories for a standard player.\n *\n * @param options\n */\nexport function createVinylFactories(options: VinylDependencyOptions) {\n const patches = mergeDeep([\n defaultPatchOptions.value,\n options.patches ?? {},\n ])\n return validateFactories({\n options: playerConfigFactory<VinylOptions>(\n defaultVinylOptions,\n vinylOptionsValidator\n ),\n patchedMedia: (): PatchedRef<HTMLMediaElement> => {\n // Patches the media element if necessary.\n return patchMediaElement(options.media, patches.media)\n },\n media: (deps: {\n readonly patchedMedia: {\n readonly patched: HTMLMediaElement\n }\n }): HTMLMediaElement => deps.patchedMedia.patched,\n playbackController: (deps: PlaybackControllerImplDeps) =>\n new PlaybackControllerImpl(deps, options.playbackController),\n playbackSource: (deps: PlaybackSourceImplDeps) =>\n new PlaybackSourceImpl(deps),\n loudnessNormalizationController: (deps: {\n options: ObservableValue<\n Pick<VinylOptions, 'loudnessNormalization'>\n >\n }) =>\n new LoudnessNormalizationControllerImpl({\n options: deps.options.pick('loudnessNormalization'),\n }),\n capabilities: (deps: CapabilitiesImplDeps) =>\n new CapabilitiesImpl(deps),\n requestInterceptor: () => noop,\n trackFactory: (deps: VinylTrackFactoryDeps) =>\n createTrackFactory(createVinylTrackFactories(deps)),\n trackController: (deps: TrackControllerImplDeps<any>) =>\n new TrackControllerImpl<any>(deps, options.trackController),\n drmKeySystemResolver: () => defaultDrmKeySystemResolver,\n drmController: (deps: DrmControllerImplDeps) =>\n new DrmControllerImpl(deps, options.drm),\n commonEme: commonEmeFactory,\n autoResetController: (deps: AutoResetControllerImplDeps) =>\n new AutoResetControllerImpl(deps, options.autoReset),\n createDashFactories: createDashFactories(options),\n createHlsFactories: createHlsFactories(options),\n } as const) satisfies Factories<VinylDeps>\n}\n\n/**\n * The dependency map type of the default player dependency factories.\n */\nexport type DefaultVinylFactories = ReturnType<typeof createVinylFactories>\n\n/**\n * Provides the dependency type for a dependency with merged overrides.\n */\nexport type InferVinylOverrideDependencyType<\n Overrides,\n K extends keyof DefaultVinylFactories,\n> = Dependencies<\n Overrides extends Factories\n ? Merge<DefaultVinylFactories, Overrides>\n : DefaultVinylFactories\n>[K]\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type PatchedRef, patchTargetFromFlags } from '@amazon/vinyl-util'\nimport type { MediaElementPatchOptions } from './MediaElementPatchOptions'\nimport { createUnreliablePlaybackEventsPatch } from './patches/createUnreliablePlaybackEventsPatch'\nimport { createPreventStallsPatch } from '@/patch/media/patches/createPreventStallsPatch'\n\n/**\n * Applies patches corresponding to the patch flags on the given media element.\n *\n * Adds logging for fabricated or squelched events.\n */\nexport function patchMediaElement<\n T extends HTMLMediaElement = HTMLMediaElement,\n>(media: T, options: MediaElementPatchOptions): PatchedRef<T> {\n return patchTargetFromFlags(\n media,\n options,\n ['unreliablePlaybackEvents', createUnreliablePlaybackEventsPatch],\n ['preventStalls', createPreventStallsPatch]\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Browser, hasBrowser, type Timestamp } from '@amazon/vinyl-util'\nimport {\n closeTo,\n createDisposer,\n DomEventHost,\n onAny,\n SignalImpl,\n} from '@amazon/vinyl-util'\nimport type { HtmlMediaElementPatch } from '@/patch/media/HtmlMediaElementPatch'\n\n/**\n * The interval (in seconds) to poll for time progress in a media element.\n *\n * @private\n */\nexport const UNRELIABLE_EVENTS_POLL_INTERVAL = 0.2\n\n/**\n * Minimum amount of time playback must be stalled before fabricating a waiting event.\n */\nexport const MIN_STALLED_BEFORE_FAB = 0.8\n\n/**\n * Minimum amount of time playback must be progressing before fabricating a playing event.\n */\nexport const MIN_PLAYING_BEFORE_FAB = 0.4\n\n/**\n * If currentTime does not change larger than this value, it will be considered to be stalled.\n */\nconst MIN_PLAYING_DELTA = 0.05\n\n/**\n * If currentTime changes beyond this tolerance the apparent state will be considered to be seeking.\n */\nconst MIN_SEEKING_DELTA = 0.5\n\nenum PlayHeadState {\n /**\n * The last time update was an increment from the previous.\n */\n PLAYING,\n\n /**\n * The last time update was close to the previous.\n */\n STOPPED,\n\n /**\n * The last time update was a non-incremental change.\n */\n SEEKING,\n}\n\n/**\n * Playback events such as playing, canPlay, and waiting are unreliable on this platform.\n * Watch playback state and fabricate events when necessary.\n */\nexport function createUnreliablePlaybackEventsPatch(\n media: HTMLMediaElement\n): HtmlMediaElementPatch {\n const { add, dispose } = createDisposer()\n const domEvents = add(new DomEventHost<HTMLMediaElementEventMap>(media))\n const eventFabricated = add(new SignalImpl<Event>())\n\n // The timestamp of the last change.\n let stateChangedAt: Timestamp = Date.now()\n\n // The current observed state based on the play head progress.\n let currentApparentState: PlayHeadState = PlayHeadState.STOPPED\n\n /**\n * @param state The new apparent state.\n * @param changedAt The timestamp the apparent state was changed.\n */\n function setApparentState(\n state: PlayHeadState,\n changedAt: Timestamp = Date.now()\n ) {\n if (currentApparentState !== state) {\n currentApparentState = state\n stateChangedAt = changedAt\n }\n }\n\n /**\n * Returns the number of seconds since the last state change.\n */\n function elapsedStateTime(): number {\n return (Date.now() - stateChangedAt) / 1000\n }\n\n let lastTimestamp: Timestamp = Date.now()\n let lastTime = media.currentTime\n\n let waiting = false\n let seeking = false\n\n onAny(\n domEvents,\n ['emptied', 'ended', 'pause', 'playing', 'seeking'],\n () => {\n waiting = false\n }\n )\n\n let playing = false\n onAny(\n domEvents,\n ['emptied', 'ended', 'pause', 'seeking', 'waiting'],\n () => {\n playing = false\n }\n )\n\n domEvents.on('seeking', () => {\n seeking = true\n })\n domEvents.on('seeked', () => {\n seeking = false\n setApparentState(PlayHeadState.SEEKING)\n })\n domEvents.on('play', () => {\n // Resets the timer so that the !paused state does not immediately trigger a 'waiting' event.\n stateChangedAt = Date.now()\n })\n\n // All events that can affect the ready state.\n // canplay and canplaythrough are handled in the overridden events map.\n const readyStateEvents = [\n 'emptied',\n 'loadeddata',\n 'loadedmetadata',\n 'waiting',\n ] as const\n let lastReadyStateEvent = 'emptied'\n add(\n onAny(domEvents, readyStateEvents, (_, type) => {\n lastReadyStateEvent = type\n })\n )\n\n const checkApparentState = () => {\n const progressed = (media.currentTime - lastTime) / media.playbackRate\n const now = Date.now()\n if (Math.abs(progressed) > MIN_SEEKING_DELTA) {\n setApparentState(PlayHeadState.SEEKING, lastTimestamp)\n } else if (progressed >= MIN_PLAYING_DELTA) {\n setApparentState(PlayHeadState.PLAYING, lastTimestamp)\n } else if (closeTo(progressed, 0, MIN_PLAYING_DELTA)) {\n setApparentState(PlayHeadState.STOPPED, lastTimestamp)\n }\n lastTime = media.currentTime\n lastTimestamp = now\n\n if (\n !playing &&\n !seeking &&\n !media.paused &&\n !media.ended &&\n media.readyState >= media.HAVE_FUTURE_DATA &&\n currentApparentState === PlayHeadState.PLAYING &&\n elapsedStateTime() >= MIN_PLAYING_BEFORE_FAB\n ) {\n // The play head is progressing but a playing event was never observed.\n waiting = false\n playing = true\n\n if (\n lastReadyStateEvent !== 'canplay' &&\n lastReadyStateEvent !== 'canplaythrough'\n ) {\n lastReadyStateEvent = 'canplay'\n eventFabricated.dispatch(new CustomEvent('canplay'))\n }\n if (media.readyState >= media.HAVE_ENOUGH_DATA) {\n if (lastReadyStateEvent !== 'canplaythrough') {\n lastReadyStateEvent = 'canplaythrough'\n eventFabricated.dispatch(new CustomEvent('canplaythrough'))\n }\n }\n eventFabricated.dispatch(new CustomEvent('playing'))\n }\n if (\n !waiting &&\n !media.paused &&\n !media.ended &&\n currentApparentState === PlayHeadState.STOPPED &&\n elapsedStateTime() >= MIN_STALLED_BEFORE_FAB\n ) {\n waiting = true\n playing = false\n // currentTime is not changing; playback has stopped but no 'waiting' event\n // was observed.\n eventFabricated.dispatch(new CustomEvent('waiting'))\n }\n }\n\n const playbackWatchIntervalId = setInterval(\n checkApparentState,\n UNRELIABLE_EVENTS_POLL_INTERVAL * 1000\n )\n add(() => {\n clearInterval(playbackWatchIntervalId)\n })\n return {\n eventFabricated,\n properties: {\n /**\n * Platforms that have unreliable waiting events, also have unreliable ready state\n * when the end of buffered data has been reached. If the media is in a waiting state,\n * the highest ready state that is possible is HAVE_METADATA.\n */\n readyState: {\n get() {\n return waiting\n ? Math.min(media.readyState, media.HAVE_METADATA)\n : media.readyState\n },\n },\n },\n events: {\n canplay(event) {\n // Do not emit the canplay event if one was fabricated.\n const eventOrNull =\n lastReadyStateEvent === 'canplay' ? null : event\n lastReadyStateEvent = 'canplay'\n return eventOrNull\n },\n\n canplaythrough(event) {\n // Do not emit the canplaythrough event if one was fabricated.\n const eventOrNull =\n lastReadyStateEvent === 'canplaythrough' ? null : event\n lastReadyStateEvent = 'canplaythrough'\n return eventOrNull\n },\n\n playing(event) {\n if (playing) {\n // Do not emit the playing event if one was fabricated.\n return null\n }\n setApparentState(PlayHeadState.PLAYING)\n playing = true\n return event\n },\n\n waiting(event) {\n if (waiting) {\n // Do not emit the waiting event if one was fabricated.\n return null\n }\n waiting = true\n setApparentState(PlayHeadState.STOPPED)\n return event\n },\n },\n\n dispose,\n }\n}\n\n/**\n * Chrome <= 53 has unreliable waiting events.\n * Safari, and Edge Legacy miss playing events after seeking.\n */\nexport function requiresUnreliablePlaybackEventsPatch(): boolean {\n return (\n hasBrowser(Browser.SAFARI) ||\n hasBrowser(Browser.EDGE_LEGACY) ||\n hasBrowser(Browser.CHROMIUM, null, '53')\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n Browser,\n closeTo,\n createDisposer,\n createLogPrefix,\n DomEventHost,\n hasBrowser,\n logInfo,\n type LogTarget,\n logWarn,\n noop,\n} from '@amazon/vinyl-util'\nimport type { HtmlMediaElementPatch } from '@/patch/media/HtmlMediaElementPatch'\n\n/**\n * The number of timeupdate events stuck at the same position before attempting to jiggle the playhead.\n * @private\n */\nexport const MAX_UNCHANGED_COUNT = 10\n\n/**\n * On affected UAs, playback can become stuck. timeupdate events are observed but playback position is never changing.\n * This patch applies a workaround which will pause and play again after max number of timeupdate events with no\n * actual time progression.\n */\nexport function createPreventStallsPatch(\n media: HTMLMediaElement\n): HtmlMediaElementPatch {\n const { add, dispose } = createDisposer()\n const domEvents = add(new DomEventHost<HTMLMediaElementEventMap>(media))\n const pathTarget: LogTarget = {\n logPrefix: createLogPrefix('createPreventStallsPatch'),\n }\n let unchangedCount = 0\n let attemptedFix = false\n let previousTime = media.currentTime\n domEvents.on('timeupdate', () => {\n if (media.paused) return\n if (closeTo(media.currentTime, previousTime, 0.01)) {\n if (++unchangedCount >= MAX_UNCHANGED_COUNT && !attemptedFix) {\n logWarn(\n pathTarget,\n `Detected stall at time ${media.currentTime}, attempting fix`\n )\n attemptedFix = true\n unchangedCount = 0\n media.pause()\n media.play().catch(noop)\n }\n } else {\n if (attemptedFix) {\n logInfo(pathTarget, 'stall ended')\n attemptedFix = false\n } // Unstuck\n unchangedCount = 0\n previousTime = media.currentTime\n }\n })\n\n return {\n dispose,\n }\n}\n\n/**\n * Returns true if stall detection should be enabled for the current user agent.\n */\nexport function requiresPreventStallsPatch(): boolean {\n return hasBrowser(Browser.EDGE_LEGACY)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n Abort,\n AbortError,\n Browser,\n clamp,\n closeTo,\n createDisposer,\n createTimeRangesReader,\n DomEventHost,\n ErrorLevel,\n ErrorOrigin,\n EventHostImpl,\n getUserAgentInfo,\n hasBrowser,\n logDebug,\n logInfo,\n logWarn,\n nextEventAsPromise,\n onAny,\n ownKeys,\n type ReadonlyEventHost,\n type ReadonlyRanges,\n TimeoutSlot,\n toLowerCase,\n withAbort,\n withTimeout,\n} from '@amazon/vinyl-util'\nimport { LIVE_DURATION, type PlaybackController } from './PlaybackController'\nimport {\n type PlaybackControllerEventMap,\n PlaybackReadyState,\n playedReasons,\n waitedReasons,\n} from './ReadonlyPlaybackController'\nimport { InvalidSeekError } from '@/playback/error/InvalidSeekError'\nimport { playbackStateLoggingHandler } from '@/playback/logging/playbackStateLoggingHandler'\nimport { createChangeEventTrigger } from '@/event/ChangeEvent'\nimport { nextHasMetadata } from '@/playback/nextHasMetadata'\nimport type { LoudnessNormalizationController } from '@/playback/loudness/LoudnessNormalizationController'\nimport { ReportableMediaError } from '@/playback/error/ReportableMediaError'\n\nexport interface PlaybackControllerImplOptions {\n /**\n * An affordance when comparing the last currentTime and the new currentTime after a seek.\n * Most browsers have around 30-40 time updates per second, but some constrained devices only\n * have a few. This value needs to be large enough where the last timeupdate in a looping track\n * is at currentTime >= duration - LOOP_TIME_AFFORDANCE.\n * Default: 2\n */\n readonly loopTimeAffordance: number\n\n /**\n * The minimum number of seconds before the end of the next seekable range allowed for a seek\n * operation. Some browsers will never complete a seek operation if the seek is too close to\n * this end range.\n * Default: getMinSeekableBufferDefault() which is between 0.5 and 5, browser dependent.\n */\n readonly minSeekableBuffer: number\n\n /**\n * The number of seconds before the promise returned by play() is rejected regardless whether\n * the media element response has settled.\n * Default: 30\n */\n readonly playTimeout: number\n\n /**\n * The number of seconds before the promise returned by seek() is rejected.\n * Default: 30\n */\n readonly seekTimeout: number\n}\n\nexport const defaultPlaybackControllerImplOptions = {\n loopTimeAffordance: 2,\n minSeekableBuffer: -1, // Default comes from getMinSeekableBufferDefault()\n playTimeout: 30,\n seekTimeout: 30,\n} as const satisfies PlaybackControllerImplOptions\n\n/**\n * Safari and Edge Legacy cannot reliably seek close to the end of a seekable range.\n * Firefox can but if the playhead reaches the end of track before the media stream is closed, an 'ended' event\n * will never fire.\n */\nexport function getMinSeekableBufferDefault() {\n return !hasBrowser(Browser.CHROMIUM) ? 5 : 2\n}\n\nexport interface PlaybackControllerImplDeps {\n readonly media: HTMLMediaElement\n readonly loudnessNormalizationController: LoudnessNormalizationController\n}\n\nexport class PlaybackControllerImpl\n extends EventHostImpl<PlaybackControllerEventMap>\n implements PlaybackController\n{\n private readonly loudnessNormalizationController: LoudnessNormalizationController\n get [Symbol.toStringTag](): string {\n return 'PlaybackControllerImpl'\n }\n\n private _error: Error | null = null\n private readonly media: HTMLMediaElement\n private readonly domEvents: DomEventHost<HTMLMediaElementEventMap>\n private readonly disposer = /* @__PURE__ */ createDisposer()\n private _playing = false\n private _seeking = false\n private _waiting = false\n\n // default user volume (0.0 to 1.0 scale)\n private userVolume: number = 1.0\n private _pendingPlay: Promise<void> | null = null\n private playAbort: Abort | null = null\n private disposeAbort = /* @__PURE__ */ new Abort()\n\n readonly options: PlaybackControllerImplOptions\n\n constructor(\n deps: PlaybackControllerImplDeps,\n options?: Partial<PlaybackControllerImplOptions>\n ) {\n super()\n this.options = {\n ...defaultPlaybackControllerImplOptions,\n minSeekableBuffer: getMinSeekableBufferDefault(),\n ...options,\n }\n this.loudnessNormalizationController =\n deps.loudnessNormalizationController\n logInfo(this, 'constructed', this.options)\n this.media = deps.media\n\n const { add } = this.disposer\n add(() => {\n this.disposeAbort.abort()\n this.disposeAbort.dispose()\n })\n\n this.domEvents = add(\n new DomEventHost<HTMLMediaElementEventMap>(deps.media)\n )\n\n // Log media events.\n add(playbackStateLoggingHandler(this))\n\n // Reports media errors\n this.domEvents.on('error', (_) => {\n const error = new ReportableMediaError(this.media.error)\n if (error.level === ErrorLevel.SILENT) {\n // Not a fatal error, log and ignore\n logInfo(this, error.message)\n return\n }\n this._error = error\n this.dispatch('error', {\n target: this,\n error,\n })\n })\n\n this.initializeEvents()\n\n // Listen for loudness normalization changes\n add(\n this.loudnessNormalizationController.on('change', () => {\n this.refreshVolume()\n })\n )\n }\n\n /**\n * Updates volume with loudness gain, on the mediaElement.\n * @private\n */\n private refreshVolume(): void {\n const effectiveVolume =\n this.userVolume * this.loudnessNormalizationController.gain\n this.media.volume = Math.min(1.0, effectiveVolume) // valid range (0-1)\n logDebug(this, 'refreshVolume', {\n userVolume: this.userVolume,\n lnGain: this.loudnessNormalizationController.gain,\n effectiveVolume: this.media.volume,\n })\n }\n\n /**\n * Listens to select events on the media element, redispatching as playback state events.\n * @private\n */\n private initializeEvents() {\n this.initializePlainEvents()\n this.initializeChangeEvents()\n this.initializeOperationEvents()\n this.initializeMutedEvent()\n this.initializeLoopedEvent()\n this.initializeReadyStateChangeEvent()\n }\n\n /**\n * Re-dispatches the plain DOM events without extra information.\n *\n * @private\n */\n private initializePlainEvents() {\n // Re-dispatch html media element events exposed on the playback controller as empty events.\n for (const key of [\n 'abort',\n 'canPlay',\n 'canPlayThrough',\n 'emptied',\n 'ended',\n 'loadStart',\n 'loadedData',\n 'loadedMetadata',\n 'pause',\n 'play',\n 'playing',\n 'seeking',\n 'waiting',\n 'waitingForKey',\n ] as const) {\n this.domEvents.on(toLowerCase(key), () => this.dispatch(key, {}))\n }\n\n // Keep specific event information for progress events.\n\n this.domEvents.on('progress', (e) => {\n this.dispatch('progress', { loaded: e.loaded, total: e.total })\n })\n }\n\n /**\n * Delegates the DOM events with additional information about what the previous and current\n * values are.\n * @private\n */\n private initializeChangeEvents() {\n const changeEventGetters = {\n durationChange: () => this.duration,\n timeUpdate: () => this.currentTime,\n volumeChange: () => this.volume,\n rateChange: () => this.playbackRate,\n } as const\n for (const key of ownKeys(changeEventGetters)) {\n this.domEvents.on(\n toLowerCase(key),\n createChangeEventTrigger(changeEventGetters[key], (event) => {\n this.dispatch(key, event)\n })\n )\n }\n }\n\n /**\n * Operation events provide an easy way to listen for the terminus of a state.\n * For example after a 'waiting' event, there are several different events that indicate that\n * the waiting has finished, and this API provides those events conflated into a single\n * 'waited' event.\n * @private\n */\n private initializeOperationEvents() {\n // seeking state + seeked event\n // media element has a seeked event, add operation details and set state.\n this.operationEvent(\n this.domEvents,\n 'seeking',\n // A seeked event may not be emitted in certain cases such as changing tracks before the seek can finish.\n ['seeked', 'emptied'],\n () => (this._seeking = true),\n (info) => {\n this._seeking = false\n this.dispatch('seeked', info)\n }\n )\n\n // waiting state + waited event\n this.operationEvent(\n this,\n 'waiting',\n waitedReasons,\n () => (this._waiting = true),\n (info) => {\n this._waiting = false\n this.dispatch('waited', info)\n }\n )\n\n // playing state + played event\n let startedTime = 0\n this.operationEvent(\n this,\n 'playing',\n playedReasons,\n () => {\n this._playing = true\n startedTime = this.currentTime\n },\n (info) => {\n this._playing = false\n this.dispatch('played', {\n ...info,\n playbackTime: this.currentTime - startedTime,\n })\n }\n )\n }\n\n /**\n * When going into a state from a beginEvent, dispatches endEvent when any of the endEvents\n * is dispatched.\n *\n * This allows consumers of the playback state to listen for the exit of a state without\n * needing to know every event that ends that state.\n *\n * @param host The event host emitting the primary events.\n * @param beginEvent The event that enters a state.\n * @param endEvents A list of events that exits the entered state.\n * @param onBegin Invoked when the operation has begun.\n * @param onEnd Invoked when the operation has completed.\n */\n private operationEvent<EventMap, const EndEvent extends keyof EventMap>(\n host: ReadonlyEventHost<EventMap>,\n beginEvent: keyof EventMap,\n endEvents: readonly EndEvent[],\n onBegin: () => void,\n onEnd: (info: {\n started: number\n ended: number\n duration: number\n reason: EndEvent\n }) => void\n ) {\n let startedAt = 0\n let started = false\n host.on(beginEvent, () => {\n onBegin()\n started = true\n startedAt = Date.now()\n })\n onAny(host, endEvents, (_, event) => {\n if (started) {\n started = false\n const now = Date.now()\n onEnd({\n started: startedAt,\n ended: now,\n duration: (now - startedAt) / 1000,\n reason: event,\n })\n }\n })\n }\n\n /**\n * Dispatches a 'mutedChange' event when 'muted' state has changed.\n *\n * The DOM element only provides a 'volumeChange' event, which is filtered to watch when\n * muted has changed.\n *\n * @private\n */\n private initializeMutedEvent() {\n const { add } = this.disposer\n let previousMuted = this.muted\n\n // Dispatches a mutedChange event if the muted property changed since the last check.\n const maybeDispatchMutedChange = () => {\n if (this.muted === previousMuted) return\n previousMuted = this.muted\n this.dispatch('mutedChange', {\n previous: !this.muted,\n current: this.muted,\n })\n }\n const mutedTimeoutSlot = add(new TimeoutSlot())\n this.on('volumeChange', () => {\n maybeDispatchMutedChange()\n // The volumechange event may be emitted before the muted property change.\n // This has been observed on legacy edge and as a rare occurrence for Chrome.\n mutedTimeoutSlot.set(maybeDispatchMutedChange, 0.2)\n })\n }\n\n /**\n * Dispatches a looped event if loop is true and playback wraps back to the start.\n * Safari emits timeupdate events at duration and then 0 before the seeking event\n * Other browsers emit the seeking before the timeupdate near zero.\n * Firefox timeupdate after the loop is near zero, not exactly.\n *\n * @private\n */\n private initializeLoopedEvent() {\n let lastTime = 0\n this.on('timeUpdate', () => {\n if (\n this.loop &&\n !this.paused &&\n this.currentTime <= this.options.loopTimeAffordance &&\n lastTime >= this.duration - this.options.loopTimeAffordance\n ) {\n if (getUserAgentInfo().browserLike?.name === Browser.FIREFOX) {\n // Firefox does not emit a 'playing' event after a loop, fabricate one.\n logDebug(this, 'fabricating Firefox playing event on loop')\n this.dispatch('playing', {})\n }\n this.dispatch('looped', {})\n }\n lastTime = this.currentTime\n })\n }\n\n get buffered(): ReadonlyRanges {\n return createTimeRangesReader(this.media.buffered)\n }\n\n get currentTime(): number {\n return this.media.currentTime\n }\n\n get currentTimePercent(): number {\n return this.duration > 0 ? this.currentTime / this.duration : 0\n }\n\n get defaultPlaybackRate(): number {\n return this.media.defaultPlaybackRate\n }\n\n set defaultPlaybackRate(value: number) {\n logDebug(this, `defaultPlaybackRate set to ${value}`)\n this.media.defaultPlaybackRate = value\n }\n\n get duration(): number {\n if (this.media.duration >= LIVE_DURATION)\n return Number.POSITIVE_INFINITY\n return this.media.duration\n }\n\n get ended(): boolean {\n return this.media.ended\n }\n\n get error(): Error | null {\n return this._error\n }\n\n get loop(): boolean {\n return this.media.loop\n }\n\n set loop(value: boolean) {\n logDebug(this, `loop set to ${value}`)\n this.media.loop = value\n }\n\n get muted(): boolean {\n return this.media.muted\n }\n\n set muted(value: boolean) {\n logDebug(this, `muted set to ${value}`)\n this.media.muted = value\n }\n\n get networkState(): number {\n return this.media.networkState\n }\n\n get paused(): boolean {\n return this.media.paused\n }\n\n get playbackRate(): number {\n return this.media.playbackRate\n }\n\n set playbackRate(value: number) {\n logDebug(this, `playbackRate set to ${value}`)\n this.media.playbackRate = value\n }\n\n get playing(): boolean {\n return this._playing\n }\n\n get preservesPitch(): boolean {\n return this.media.preservesPitch\n }\n\n set preservesPitch(value: boolean) {\n logDebug(this, `preservesPitch set to ${value}`)\n this.media.preservesPitch = value\n }\n\n get readyState(): PlaybackReadyState {\n return this.media.readyState\n }\n\n get seekable(): ReadonlyRanges {\n return createTimeRangesReader(this.media.seekable)\n }\n\n get seeking(): boolean {\n return this._seeking\n }\n\n get volume(): number {\n return this.userVolume\n }\n\n set volume(value: number) {\n logDebug(this, `volume set to ${value}`)\n this.userVolume = value\n this.refreshVolume()\n }\n\n get waiting(): boolean {\n return this._waiting\n }\n\n pause(): void {\n logDebug(this, 'pause')\n this.playAbort?.abort(\n new AbortError(\n 'The play() request was interrupted by a call to pause().'\n )\n )\n this.pendingPlay = null\n this.media.pause()\n }\n\n private get pendingPlay(): Promise<void> | null {\n return this._pendingPlay\n }\n\n private set pendingPlay(value: Promise<void> | null) {\n this._pendingPlay = value\n this.dispatch('playIsPendingChange', {\n previous: value == null,\n current: value != null,\n })\n }\n\n play(): Promise<void> {\n logDebug(this, 'play')\n if (!this.pendingPlay) {\n const playAbort = new Abort()\n this.playAbort = playAbort\n this.pendingPlay = withAbort(\n (async () => {\n await nextHasMetadata(this)\n playAbort.throwIfAborted()\n await withTimeout(\n this.media.play(),\n this.options.playTimeout,\n 'play() timed out after {time}s',\n ErrorOrigin.INTERNAL,\n ErrorLevel.SILENT\n )\n })(),\n playAbort\n )\n .catch((reason) => {\n this.dispatch('playRejected', { reason })\n throw reason\n })\n .finally(() => {\n this.pendingPlay = null\n this.playAbort = null\n })\n }\n return this.pendingPlay\n }\n\n get canPlay(): boolean {\n return this.readyState >= PlaybackReadyState.HAVE_FUTURE_DATA\n }\n\n get canPlayThrough(): boolean {\n return this.readyState >= PlaybackReadyState.HAVE_ENOUGH_DATA\n }\n\n get hasMetadata(): boolean {\n return this.readyState >= PlaybackReadyState.HAVE_METADATA\n }\n\n get playIsPending(): boolean {\n return this.pendingPlay != null\n }\n\n async seekTo(time: number, tolerance = 0.5): Promise<void> {\n logDebug(this, `seekTo: ${time}`)\n const nextEvent = <K extends keyof PlaybackControllerEventMap>(\n type: K\n ): Promise<PlaybackControllerEventMap[K]> => {\n return withAbort(\n withTimeout(\n nextEventAsPromise(this, type),\n this.options.seekTimeout,\n `seek timed out on ${type} event after {time}s`,\n ErrorOrigin.INTERNAL,\n ErrorLevel.WARN\n ),\n this.disposeAbort\n )\n }\n\n // Cannot seek until there are seekable ranges.\n if (!this.hasMetadata) {\n await nextEvent('loadedMetadata')\n }\n\n const seekable = this.seekable\n const range = seekable.getRangeAt(\n clamp(time, 0, this.duration),\n tolerance\n )\n if (range == null) {\n logWarn(\n this,\n `seekTo: seek outside of seekable ranges, seek ignored`\n )\n throw new InvalidSeekError(time, seekable, tolerance)\n }\n const clampedTime = Math.max(\n Math.min(time, range[1] - this.options.minSeekableBuffer),\n range[0]\n )\n\n // No-op check\n\n logDebug(\n this,\n `seekTo operation, requested: ${time}, actual: ${clampedTime}`\n )\n\n if (closeTo(clampedTime, this.currentTime, tolerance)) {\n // Within tolerance of the currentTime, no seek needed.\n logDebug(\n this,\n `seekTo: requested: ${time}, actual: ${clampedTime} no-op`\n )\n } else {\n const seeking = nextEvent('seeking')\n this.media.currentTime = clampedTime\n await seeking\n const seekedEvent = await nextEvent('seeked')\n if (seekedEvent.reason === 'emptied') {\n // Seek finished due to track unloading. Abort any pending seek.\n throw new AbortError()\n }\n }\n }\n\n /**\n * Dispatches a readyStateChange event when {@link readyState} changes.\n * @private\n */\n private initializeReadyStateChangeEvent() {\n let previous = this.readyState\n onAny(\n this,\n [\n 'canPlay',\n 'canPlayThrough',\n 'emptied',\n 'loadedData',\n 'loadedMetadata',\n 'waiting',\n ],\n () => {\n const current = this.readyState\n if (previous !== current) {\n this.dispatch('readyStateChange', {\n previous,\n current,\n })\n previous = this.readyState\n }\n }\n )\n }\n\n reset() {\n if (this._error == null) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.dispatch('reset', {})\n }\n\n /**\n * True if this controller has been disposed.\n */\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.disposer.dispose()\n }\n}\n\n/**\n * Returns true if the play rejection reason is a not allowed error. This indicates that play\n * should be retried within a user interaction stack.\n * @param reason\n */\nexport function isNotAllowedError(\n reason: any\n): reason is { name: 'NotAllowedError' } {\n return reason?.name === 'NotAllowedError'\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyPlaybackController } from './ReadonlyPlaybackController'\n\nexport interface PlaybackController extends ReadonlyPlaybackController {\n defaultPlaybackRate: number\n loop: boolean\n muted: boolean\n playbackRate: number\n preservesPitch: boolean\n volume: number\n\n /**\n * Pauses playback of the media, if the media is already in a paused state\n * this method will have no effect.\n * If a play is pending, the play will be aborted and the promise returned by play() will be\n * rejected.\n *\n * @see pendingPlay\n * @see play\n */\n pause(): void\n\n /**\n * Attempts to begin playback of the media. It returns a Promise which is resolved when\n * playback has been successfully started.\n *\n * Failure to begin playback for any reason, such as permission issues or interruption via\n * pause, results in the promise being rejected.\n *\n * The first time play() is invoked, except muted video, should be in response to a user\n * interaction such as a button click.\n *\n * @see isNotAllowedError\n */\n play(): Promise<void>\n\n /**\n * Safely seeks to the given time.\n * The seek will begin only after {@link readyState} is at least\n * {@link PlaybackReadyState.HAVE_METADATA}.\n * If a previous seek was still pending, the previous seek will be ignored.\n * Returns a Promise that resolves when the seek has completed. If the seek is interrupted\n * by another seek, the promise will be rejected with an `AbortError`.\n * If the seek is not to a seekable range, the promise will reject with an {@link InvalidSeekError}.\n *\n * @param time The value, in seconds, to set the playback time.\n * @param tolerance The amount of tolerance to have when the time is outside the seekable\n * ranges to snap, in seconds. If time is outside all seekable ranges beyond this tolerance,\n * the seek will be ignored. Default: 0.5\n */\n seekTo(time: number, tolerance?: number): Promise<void>\n\n /**\n * Resets the error state.\n */\n reset(): void\n}\n\n/**\n * The maximum duration media can be before it is considered 'live'.\n */\nexport const LIVE_DURATION = 4294967296 // 2 ** 32\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AnyRecord,\n ReadonlyEventHost,\n ReadonlyRanges,\n Timestamp,\n} from '@amazon/vinyl-util'\nimport type { ChangeEvent } from '@/event/ChangeEvent'\nimport type { BasicErrorEvent } from '@/event/BasicErrorEvent'\n\nexport interface ProgressEvent {\n readonly loaded: number\n readonly total: number\n}\n\nexport interface OperationCompletedEvent<K> {\n /**\n * The timestamp the operation began.\n */\n readonly started: Timestamp\n\n /**\n * The timestamp the operation completed.\n */\n readonly ended: Timestamp\n\n /**\n * The total number of seconds the operation took.\n */\n readonly duration: number\n\n /**\n * The reason the operation completed.\n */\n readonly reason: K\n}\n\nexport interface PlayedEvent extends OperationCompletedEvent<PlayedReason> {\n /**\n * The total number of seconds elapsed for the track (using `currentTime`).\n */\n readonly playbackTime: number\n}\n\n/**\n * The reason playback has stopped.\n * These are source event types from the media element that all indicate playback has stopped.\n * @see PlaybackControllerEventMap\n */\nexport enum PlayedReason {\n EMPTIED = 'emptied',\n /**\n * Note - 'ended' reason is generally unused, however it is not part of the w3c spec to guarantee a 'pause' event\n * before 'ended'.\n */\n ENDED = 'ended',\n PAUSE = 'pause',\n SEEKING = 'seeking',\n WAITING = 'waiting',\n}\n\n/**\n * A list of all events that cause the 2nd-order 'played' event.\n */\nexport const playedReasons = [\n PlayedReason.EMPTIED,\n PlayedReason.ENDED,\n PlayedReason.PAUSE,\n PlayedReason.SEEKING,\n PlayedReason.WAITING,\n] as const satisfies readonly PlayedReason[]\n\nexport interface PlayRejectedEvent {\n /**\n * The reason for the play() rejection.\n *\n * @see #isNotAllowedError\n */\n reason: any\n}\n\nexport interface PlaybackControllerEventMap {\n /**\n * Fired when the resource was not fully loaded, but not as the result of an error.\n */\n readonly abort: AnyRecord\n\n /**\n * Fired when the user agent can play the media, but estimates that not enough data has been\n * loaded to play the media up to its end without having to stop for further buffering of\n * content.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_FUTURE_DATA}\n */\n readonly canPlay: AnyRecord\n\n /**\n * Fired when the user agent can play the media, and estimates that enough data has been\n * loaded to play the media up to its end without having to stop for further buffering of content.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_ENOUGH_DATA}\n */\n readonly canPlayThrough: AnyRecord\n\n /**\n * Fired when the duration attribute has been updated.\n */\n readonly durationChange: ChangeEvent<number>\n\n /**\n * Fired when the media has become empty; for example, this event is sent if the media has\n * already been loaded (or partially loaded), and the load() method is called to reload it.\n *\n * readyState will be {@link PlaybackReadyState.HAVE_NOTHING}\n */\n readonly emptied: AnyRecord\n\n /**\n * Fired when playback or streaming has stopped because the end of the media was reached or\n * because no further data is available.\n */\n readonly ended: AnyRecord\n\n /**\n * Dispatched when the media element dispatches an error.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Fired when {@link ReadonlyPlaybackController.playIsPending} has changed.\n */\n readonly playIsPendingChange: ChangeEvent<boolean>\n\n /**\n * Fired when the frame at the current playback position of the media has finished loading;\n * often the first frame.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_CURRENT_DATA}\n */\n readonly loadedData: AnyRecord\n\n /**\n * Fired when the metadata has been loaded.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_METADATA}\n */\n readonly loadedMetadata: AnyRecord\n\n /**\n * Fired when the browser has started to load a resource.\n */\n readonly loadStart: AnyRecord\n\n /**\n * Fired when {@link ReadonlyPlaybackController.loop} is true and playback has looped to track beginning.\n */\n readonly looped: AnyRecord\n\n /**\n * Fired when the mute status has changed.\n */\n readonly mutedChange: ChangeEvent<boolean>\n\n /**\n * Fired when a request to pause an activity is handled and the activity has entered its paused\n * state, most commonly after the media has been paused through a call to the element's\n * pause() method.\n */\n readonly pause: AnyRecord\n\n /**\n * Fired when the paused property is changed from true to false, as a result of the play\n * method, or the autoplay attribute.\n */\n readonly play: AnyRecord\n\n /**\n * Fired if play() has been attempted, but rejected.\n */\n readonly playRejected: PlayRejectedEvent\n\n /**\n * Fired when playback has stopped, for any reason.\n *\n * When media begins playing, a `playing` event is emitted. If playback stops due to 'pause',\n * 'seeking', 'emptied', 'waiting', or 'ended', then `played` will be fired.\n */\n readonly played: PlayedEvent\n\n /**\n * Fired after playback is first started, and whenever it is restarted. For example, it is\n * fired when playback resumes after having been paused or delayed due to lack of data.\n */\n readonly playing: AnyRecord\n\n /**\n * Fired periodically as the browser loads a resource.\n */\n readonly progress: ProgressEvent\n\n /**\n * Fired when the playback rate has changed.\n */\n readonly rateChange: ChangeEvent<number>\n\n /**\n * Fired when {@link ReadonlyPlaybackController.readyState} has changed.\n *\n * This is fired when any of the following events have fired:\n * {@link loadedData},\n * {@link loadedMetadata}\n * {@link canPlay}\n * {@link canPlayThrough}\n * {@link emptied}\n * {@link waiting}\n */\n readonly readyStateChange: ChangeEvent<PlaybackReadyState>\n\n /**\n * Fired when a seek operation completed, the current playback position has changed, and the\n * Boolean seeking attribute is changed to false.\n */\n readonly seeked: OperationCompletedEvent<'seeked' | 'playing' | 'emptied'>\n\n /**\n * Fired when a seek operation starts, meaning the Boolean seeking attribute has changed to\n * true and the media is seeking a new position.\n */\n readonly seeking: AnyRecord\n\n /**\n * Fired when the time indicated by the currentTime attribute has been updated.\n */\n readonly timeUpdate: ChangeEvent<number>\n\n /**\n * Fired when the volume has changed.\n */\n readonly volumeChange: ChangeEvent<number>\n\n /**\n * Fired when playback has stopped because of a temporary lack of data.\n *\n * Note: this includes during initial loading or after a seek and data is needed to buffer.\n * Will not be emitted when paused.\n */\n readonly waiting: AnyRecord\n\n /**\n * Fired when waiting has completed.\n * This will be emitted after a waiting event when playback has resumed, paused, or unloaded.\n */\n readonly waited: OperationCompletedEvent<WaitedReason>\n\n /**\n * Playback is blocked waiting for a key.\n */\n readonly waitingForKey: AnyRecord\n\n /**\n * Emitted when the error state has been reset.\n */\n readonly reset: AnyRecord\n}\n\n/**\n * Reasons why a 'waiting' operation has ended.\n */\nexport enum WaitedReason {\n PLAYING = 'playing',\n PAUSE = 'pause',\n EMPTIED = 'emptied',\n SEEKING = 'seeking',\n}\n\n/**\n * A list of all events that cause the 2nd-order 'waited' event.\n */\nexport const waitedReasons = [\n WaitedReason.PLAYING,\n WaitedReason.PAUSE,\n WaitedReason.EMPTIED,\n WaitedReason.SEEKING,\n] as const satisfies readonly WaitedReason[]\n\nexport const ALL_PLAYBACK_STATE_EVENTS = [\n 'abort',\n 'canPlay',\n 'canPlayThrough',\n 'durationChange',\n 'emptied',\n 'ended',\n 'error',\n 'playIsPendingChange',\n 'loadedData',\n 'loadedMetadata',\n 'loadStart',\n 'looped',\n 'mutedChange',\n 'pause',\n 'play',\n 'playRejected',\n 'played',\n 'playing',\n 'progress',\n 'rateChange',\n 'readyStateChange',\n 'reset',\n 'seeked',\n 'seeking',\n 'timeUpdate',\n 'volumeChange',\n 'waited',\n 'waiting',\n 'waitingForKey',\n] as const satisfies readonly (keyof PlaybackControllerEventMap)[]\n\nexport enum PlaybackReadyState {\n /**\n * No information is available about the media resource.\n *\n * readyState will be this after `emptied`\n */\n HAVE_NOTHING = 0,\n\n /**\n * Enough of the media resource has been retrieved that the metadata attributes are initialized\n * Seeking will no longer raise an exception.\n *\n * readyState will be at least this after `loadedMetadata`\n */\n HAVE_METADATA = 1,\n\n /**\n * Data is available for the current playback position, but not enough to actually play more\n * than one frame.\n *\n * readyState will be at least this after `loadedData`\n */\n HAVE_CURRENT_DATA = 2,\n\n /**\n * Data for the current playback position as well as for at least a little bit of time into the\n * future is available (in other words, at least two frames of video, for example).\n *\n * readyState will be at least this after `canPlay`\n */\n HAVE_FUTURE_DATA = 3,\n\n /**\n * Enough data is available\u2014and the download rate is high enough\u2014that the media can be played\n * through to the end without interruption.\n *\n * readyState will be at least this after `canPlayThrough`\n */\n HAVE_ENOUGH_DATA = 4,\n}\n\n/**\n * An enumeration of possible networkState values on a media element.\n */\nexport enum PlaybackNetworkState {\n /**\n * There is no data yet. Also, readyState is HAVE_NOTHING.\n */\n NETWORK_EMPTY = 0,\n\n /**\n * HTMLMediaElement is active and has selected a resource, but is not using the network.\n */\n NETWORK_IDLE = 1,\n\n /**\n * The browser is downloading HTMLMediaElement data.\n */\n NETWORK_LOADING = 2,\n\n /**\n * No HTMLMediaElement src found.\n */\n NETWORK_NO_SOURCE = 3,\n}\n\nexport interface ReadonlyPlaybackController extends ReadonlyEventHost<PlaybackControllerEventMap> {\n /**\n * Returns a new static normalized ReadonlyRanges object that represents the ranges of the\n * media resource, if any, that the user agent has buffered at the moment the buffered\n * property is accessed.\n *\n * Note: `ReadonlyRanges` is a view to the DOM `TimeRanges` object.\n */\n readonly buffered: ReadonlyRanges\n\n /**\n * True if the {@link readyState} is {@link PlaybackReadyState.HAVE_FUTURE_DATA}\n * This will be true after a {@link PlaybackControllerEventMap.canPlay} event.\n *\n * Note that security permissions may not allow a track to load past metadata before there has\n * been a user interaction. This should not be relied upon before invoking\n * {@link PlaybackController.play}.\n */\n readonly canPlay: boolean\n\n /**\n * True if the {@link readyState} is {@link PlaybackReadyState.HAVE_ENOUGH_DATA}\n * This will be true after a {@link PlaybackControllerEventMap.canPlayThrough} event.\n *\n * Note that security permissions may not allow a track to load past metadata before there has\n * been a user interaction. This should not be relied upon before invoking\n * {@link PlaybackController.play}.\n */\n readonly canPlayThrough: boolean\n\n /**\n * The current playback time in seconds.\n * When changed, a 'timeUpdate' event is emitted.\n */\n readonly currentTime: number\n\n /**\n * Returns current time as a percent of the total duration.\n *\n * @return A number between 0-1\n */\n readonly currentTimePercent: number\n\n /**\n * The default playback rate when the user is not using fast forward or reverse for a\n * video or audio resource.\n */\n readonly defaultPlaybackRate: number\n\n /**\n * The length of the element's media in seconds.\n * Observe changes with `durationChange` events.\n */\n readonly duration: number\n\n /**\n * Indicates whether the media element has ended playback.\n */\n readonly ended: boolean\n\n /**\n * The Error object for the most recent error, or null if there has not been an error.\n * When an error event is received by the element, you can determine details about what\n * happened by examining this object.\n */\n readonly error: Error | null\n\n /**\n * True if the {@link readyState} is at least {@link PlaybackReadyState.HAVE_METADATA}\n *\n * This will be true after a {@link PlaybackControllerEventMap.loadedMetadata} event and\n * false after an {@link PlaybackControllerEventMap.emptied} event.\n */\n readonly hasMetadata: boolean\n\n /**\n * Controls whether the media element should start over when it reaches the end.\n */\n readonly loop: boolean\n\n /**\n * Indicates whether the media element muted.\n * Observe changes with `mutedChange` events.\n */\n readonly muted: boolean\n\n /**\n * Indicates the current state of the fetching of media over the network.\n */\n readonly networkState: PlaybackNetworkState\n\n /**\n * Indicates whether the media element is paused.\n * Observe changes with `play` and `pause` events.\n */\n readonly paused: boolean\n\n /**\n * Sets the rate at which the media is being played back. This is used to implement user\n * controls for fast-forward, slow motion, and so forth. The normal playback rate is\n * multiplied by this value to obtain the current rate, so a value of 1.0 indicates normal\n * speed.\n */\n readonly playbackRate: number\n\n /**\n * True if playback has started, is not paused, stalled, or seeking.\n * Observe changes with 'playing' and 'played' events.\n */\n readonly playing: boolean\n\n /**\n * True if `play` has been called and the returned promise is currently in a pending state.\n * Observe changes with {@link PlaybackControllerEventMap.playIsPendingChange} events.\n */\n readonly playIsPending: boolean\n\n /**\n * Determines whether the browser should adjust the pitch of the audio to compensate\n * for changes to the playback rate.\n * Default: true\n */\n readonly preservesPitch: boolean\n\n /**\n * Indicates the readiness state of the media.\n * Observe changes with {@link PlaybackControllerEventMap.readyStateChange} events.\n */\n readonly readyState: PlaybackReadyState\n\n /**\n * Returns a new static normalized `ReadonlyRanges` object that represents the ranges of the\n * media resource, if any, that the user agent is able to seek to at the time seekable\n * property is accessed.\n *\n * Note: `ReadonlyRanges` is a view to the DOM `TimeRanges` object.\n */\n readonly seekable: ReadonlyRanges\n\n /**\n * True if the element is currently seeking.\n * Observe changes with `seeking` and `seeked` events.\n */\n readonly seeking: boolean\n\n /**\n * The volume level for audio portions of the media element.\n * Observe changes with `volumeChange` events.\n */\n readonly volume: number\n\n /**\n * True if playback is stopped due to waiting for data.\n * Observe changes with `waiting` and `waited` events.\n */\n readonly waiting: boolean\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ErrorLevel, type Json, ReportableError } from '@amazon/vinyl-util'\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport type { ReadonlyRanges } from '@amazon/vinyl-util'\n\n/**\n * An error indicating a seek was out of range.\n * This will have an error level of `ErrorLevel.WARN`.\n * This indicates a bad seek request, but is recoverable.\n */\nexport class InvalidSeekError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'InvalidSeekError'\n }\n\n constructor(\n readonly time: number,\n readonly seekable: ReadonlyRanges,\n readonly tolerance: number\n ) {\n super(\n `Could not seek to time: ${time}, outside of seekable ranges ${seekable} with tolerance ${tolerance}`,\n ErrorOrigin.API,\n ErrorLevel.WARN\n )\n Object.setPrototypeOf(this, InvalidSeekError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n time: this.time,\n seekable: Array.from(this.seekable),\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Disposable } from '@amazon/vinyl-util'\nimport { createDisposer } from '@amazon/vinyl-util'\nimport { logDebug } from '@amazon/vinyl-util'\nimport type { ReadonlyPlaybackController } from '@/playback/ReadonlyPlaybackController'\nimport { ALL_PLAYBACK_STATE_EVENTS } from '@/playback/ReadonlyPlaybackController'\nimport { throttle } from '@amazon/vinyl-util'\nimport { substitute } from '@amazon/vinyl-util'\nimport { createLogPrefix, type LogTarget } from '@amazon/vinyl-util'\n\n/**\n * The number of seconds to throttle timeupdate logs.\n * Logs will not be emitted for timeupdate events less than this interval.\n */\nexport const TIMEUPDATE_THROTTLE = 5\n\n/**\n * @private\n */\nconst locale = {\n /**\n * The timeupdate log message when grouping several updates together.\n *\n * Param start - start time\n * Param end - end time\n * Param count - number of events\n */\n timeupdateLogBatch: 'timeUpdate {start}-{end} x{count}',\n} as const\n\n/**\n * Logs all playback state events.\n *\n * @param playbackState The event host with playback events to observe.\n * @return Returns a disposable handle to remove all added handlers.\n */\nexport function playbackStateLoggingHandler(\n playbackState: ReadonlyPlaybackController\n): Disposable {\n const target: LogTarget = {\n logPrefix: createLogPrefix('Playback'),\n }\n const disposer = createDisposer()\n const { add } = disposer\n\n // Log time update events so that sequential time updates are debounced.\n let timeUpdateCount = 0\n let startTime: number | null = null\n\n /**\n * Logs the cumulated timeupdate event counts, resetting the window.\n */\n const logTimeupdateBatch = () => {\n if (startTime == null) return\n const currentTime = playbackState.currentTime\n logDebug(\n target,\n substitute(locale.timeupdateLogBatch, {\n start: startTime.toFixed(1),\n end: currentTime.toFixed(1),\n count: timeUpdateCount,\n })\n )\n timeUpdateCount = 0\n startTime = null\n }\n\n /**\n * Throttles timeupdate logs to the given interval.\n */\n const logTimeupdateBatchThrottled = add(\n throttle(logTimeupdateBatch, TIMEUPDATE_THROTTLE, { trailing: true })\n )\n\n add(\n playbackState.on('timeUpdate', () => {\n timeUpdateCount++\n if (startTime == null) startTime = playbackState.currentTime\n logTimeupdateBatchThrottled()\n })\n )\n\n for (const type of ALL_PLAYBACK_STATE_EVENTS) {\n if (type === 'timeUpdate') continue\n add(\n playbackState.on(type, (event) => {\n logTimeupdateBatch()\n logDebug(target, type, event)\n })\n )\n }\n\n return disposer\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface ChangeEvent<T> {\n readonly previous: T | null\n readonly current: T\n}\n\n/**\n * Creates a function, which when invoked, will call `inner` with a new ChangeEvent.\n *\n * @param getter\n * @param inner\n */\nexport function createChangeEventTrigger<T>(\n getter: () => T,\n inner: (event: ChangeEvent<T>) => void\n): () => void {\n let current = getter()\n return () => {\n const event: ChangeEvent<T> = {\n previous: current,\n current: getter(),\n }\n current = event.current\n inner(event)\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n PlaybackControllerEventMap,\n ReadonlyPlaybackController,\n} from '@/playback/ReadonlyPlaybackController'\nimport {\n type AnyRecord,\n nextEventAsPromise,\n type NextEventAsPromiseOptions,\n} from '@amazon/vinyl-util'\n\nexport function nextHasMetadata(\n controller: ReadonlyPlaybackController,\n options?: NextEventAsPromiseOptions<\n PlaybackControllerEventMap,\n 'loadedMetadata'\n >\n): Promise<AnyRecord> {\n if (controller.hasMetadata) return Promise.resolve({})\n return nextEventAsPromise(controller, 'loadedMetadata', options)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n ErrorLevel,\n ErrorOrigin,\n type Json,\n type Maybe,\n ReportableError,\n} from '@amazon/vinyl-util'\nimport { mediaErrorToJson } from '@/playback/logging/mediaErrorToJson'\n\n/**\n * An error from the media element\n */\nexport class ReportableMediaError extends ReportableError {\n // Copied from MediaError to ensure compatibility in Node\n static readonly MEDIA_ERR_ABORTED = 1\n static readonly MEDIA_ERR_NETWORK = 2\n static readonly MEDIA_ERR_DECODE = 3\n static readonly MEDIA_ERR_SRC_NOT_SUPPORTED = 4\n\n get [Symbol.toStringTag](): string {\n return 'ReportableMediaError'\n }\n\n readonly reason: string\n readonly code: number\n\n constructor(error: Maybe<MediaError>) {\n const { name, code, message } = mediaErrorToJson(error)\n const level =\n error == null || code === ReportableMediaError.MEDIA_ERR_ABORTED\n ? ErrorLevel.SILENT\n : ErrorLevel.FATAL\n super(message, ErrorOrigin.MEDIA, level)\n this.reason = name\n this.code = code\n Object.setPrototypeOf(this, ReportableMediaError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n reason: this.reason,\n code: this.code,\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe } from '@amazon/vinyl-util'\n\nexport function mediaErrorToJson(error: Maybe<MediaError>): {\n readonly name: string\n readonly message: string\n readonly code: number\n} {\n let message: string = 'An unknown media error has occurred.'\n let name: string = 'UNKNOWN_MEDIA_ERROR'\n let code = -1\n if (error) {\n code = error.code\n switch (error.code) {\n case error.MEDIA_ERR_ABORTED: {\n message = `The requesting of the associated resource was aborted by the user's request.`\n name = 'MEDIA_ERR_ABORTED'\n break\n }\n case error.MEDIA_ERR_NETWORK: {\n message = 'A network error occurred.'\n name = 'MEDIA_ERR_NETWORK'\n break\n }\n case error.MEDIA_ERR_DECODE: {\n name = 'MEDIA_ERR_DECODE'\n message =\n 'An error occurred while trying to decode the media resource.'\n break\n }\n case error.MEDIA_ERR_SRC_NOT_SUPPORTED: {\n name = 'MEDIA_ERR_SRC_NOT_SUPPORTED'\n message = 'The associated resource was not supported.'\n break\n }\n }\n }\n return {\n name,\n message,\n code,\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { CrossOrigin, PlaybackSource } from './PlaybackSource'\n\nexport interface PlaybackSourceImplDeps {\n readonly media: HTMLMediaElement\n}\n\nexport class PlaybackSourceImpl implements PlaybackSource {\n protected readonly media: HTMLMediaElement\n\n constructor(deps: PlaybackSourceImplDeps) {\n this.media = deps.media\n }\n\n get crossOrigin(): CrossOrigin {\n return this.media.crossOrigin as CrossOrigin\n }\n\n set crossOrigin(value: CrossOrigin) {\n this.media.crossOrigin = value\n }\n\n get currentSrc(): string {\n return this.media.currentSrc\n }\n\n load(): void {\n this.media.load()\n }\n\n get src(): string {\n return this.media.src\n }\n\n set src(value: string | null) {\n if (!value) this.media.removeAttribute('src')\n else this.media.src = value\n }\n\n get srcObject(): MediaStream | null {\n return this.media.srcObject as MediaStream | null\n }\n\n set srcObject(value: MediaStream | null) {\n this.media.srcObject = value\n }\n\n get disableRemotePlayback(): boolean {\n return this.media.disableRemotePlayback\n }\n\n set disableRemotePlayback(value: boolean) {\n this.media.disableRemotePlayback = value\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AnyRecord, Maybe, ReadonlyRecord } from '@amazon/vinyl-util'\nimport { ErrorOrigin, ownKeys } from '@amazon/vinyl-util'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n isOneOf,\n object,\n string,\n type ValueSchema,\n} from '@amazon/vinyl-validation'\n\nimport type { Track, TrackTypeId, TrackUri } from '@/track/Track'\n\nexport interface TrackLoadOptions {\n /**\n * The track type, used to map to a track factory.\n */\n readonly type: TrackTypeId\n\n /**\n * The track identifier.\n */\n readonly uri: TrackUri\n\n /**\n * The track configuration.\n */\n readonly config?: Maybe<AnyRecord>\n}\n\nexport const trackLoadOptionsValidator: ObjectSchema<TrackLoadOptions> = /* @__PURE__ */ object(\n {\n type: /* @__PURE__ */ string(),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n config: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).maybe().optional(),\n }\n)\n\n/**\n * Produces a new Track for the given configuration options.\n */\nexport interface TrackFactory<TrackLoadOptionsType extends TrackLoadOptions> {\n /**\n * Throws a validation error if the track options are invalid.\n */\n validate(options: TrackLoadOptionsType): void\n\n /**\n * Constructs a new track from the provided load options.\n */\n createTrack(options: TrackLoadOptionsType): Track\n}\n\nexport type InferLoadOptionsFromFactory<T extends TrackFactory<any>> =\n T extends TrackFactory<infer LoadOptions> ? LoadOptions : never\n\nexport type CombinedTrackFactoryOptions<\n T extends ReadonlyRecord<TrackTypeId, TrackFactory<TrackLoadOptions>>,\n> = InferLoadOptionsFromFactory<T[keyof T]>\n\nexport type TrackFactoryRecord = ReadonlyRecord<\n TrackTypeId,\n TrackFactory<TrackLoadOptions>\n>\n\n/**\n * Validates that the keys of the track factory record match the track type\n * for the track factory.\n */\nexport type ValidTrackFactoryRecord<T extends TrackFactoryRecord> = {\n readonly [K in keyof T]: K extends InferLoadOptionsFromFactory<T[K]>['type']\n ? T[K]\n : never\n}\n\n/**\n * Given a map of TrackTypeId => TrackFactory, returns a track factory\n * that supports any of the provided track types.\n * The factory will be mapped by the track load options `type` property.\n *\n * @param factories\n */\nexport function createTrackFactory<T extends TrackFactoryRecord>(\n factories: ValidTrackFactoryRecord<T>\n): TrackFactory<CombinedTrackFactoryOptions<T>> {\n // Validates that the track type attempting to be created exists in the factory map.\n const typeValidator: ValueSchema<keyof T> = isOneOf(...ownKeys(factories))\n return {\n validate(options): void {\n typeValidator.assert(options.type, ErrorOrigin.API)\n factories[options.type].validate(options)\n },\n\n createTrack(options): Track {\n return factories[options.type].createTrack(options)\n },\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { PlaybackSource } from '@/playback/PlaybackSource'\nimport type { Track, TrackTypeId, TrackUri } from '@/track/Track'\nimport { type TrackBaseDeps } from '@/track/TrackBase'\nimport {\n type TrackFactory,\n type TrackLoadOptions,\n trackLoadOptionsValidator,\n} from '@/track/TrackFactory'\nimport { ErrorOrigin, type Maybe } from '@amazon/vinyl-util'\nimport { func, isOneOf, type ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n SourceTrackBase,\n type SourceTrackBaseOptions,\n sourceTrackBaseOptionsValidator,\n} from '@/track/source/SourceTrackBase'\n\n/**\n * Dependencies for a SourceObjectTrack.\n */\nexport interface SourceObjectTrackDeps extends TrackBaseDeps {\n readonly playbackSource: PlaybackSource\n}\n\nexport interface SourceObjectTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'srcObject'\n\n /**\n * A function to produce a MediaStream, or Promise<MediaStream>.\n */\n readonly srcObjectProvider: (\n uri: TrackUri\n ) => Promise<MediaStream> | MediaStream\n\n /**\n * Configuration options for the SourceObjectTrack.\n * Will be provided on preload and activate.\n */\n readonly config?: Maybe<SourceTrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<SourceObjectTrackLoadOptions> =\n /* @__PURE__ */ trackLoadOptionsValidator.extend({\n srcObjectProvider: /* @__PURE__ */ func(),\n type: /* @__PURE__ */ isOneOf('srcObject'),\n config: /* @__PURE__ */ /* @__PURE__ */ sourceTrackBaseOptionsValidator.maybe().optional(),\n })\n\nexport function createSourceObjectTrackFactory(\n deps: SourceObjectTrackDeps\n): TrackFactory<SourceObjectTrackLoadOptions> {\n return {\n validate(options: SourceObjectTrackLoadOptions): void {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(options: SourceObjectTrackLoadOptions): Track {\n return new SourceObjectTrack(\n options.uri,\n options.type,\n Promise.resolve(options.srcObjectProvider(options.uri)),\n deps\n )\n },\n }\n}\n\n// TODO: Accept a provider function instead of a Promise for srcObject to support reset.\nexport class SourceObjectTrack extends SourceTrackBase<MediaStream> {\n get [Symbol.toStringTag](): string {\n return 'SourceObjectTrack'\n }\n\n constructor(\n uri: TrackUri,\n type: TrackTypeId,\n srcObject: Promise<MediaStream>,\n protected readonly deps: SourceObjectTrackDeps\n ) {\n super(uri, type, srcObject, deps)\n }\n\n protected setSrc(src: MediaStream) {\n this.deps.playbackSource.srcObject = src\n }\n\n protected clearSrc(): void {\n this.deps.playbackSource.srcObject = null\n this.deps.playbackSource.load()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport { any, number, object } from '@amazon/vinyl-validation'\nimport {\n createAbortSlot,\n createDisposer,\n emptyRanges,\n EventHostImpl,\n isSilentError,\n logDebug,\n type Maybe,\n noop,\n type ReadonlyRanges,\n type ReadonlySet,\n} from '@amazon/vinyl-util'\nimport type { PlaybackController } from '@/playback/PlaybackController'\nimport type {\n Track,\n TrackEventMap,\n TrackPreloadOptions,\n TrackTypeId,\n TrackUri,\n} from './Track'\nimport { type DrmController } from '@/drm/DrmController'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport { type DrmOptions, drmOptionsValidator } from '@/drm/DrmOptions'\n\n/**\n * Dependencies for TrackBase.\n */\nexport interface TrackBaseDeps {\n /**\n * When the track is activated, playback will seek to the track's start time.\n */\n readonly playbackController: PlaybackController\n\n /**\n * DrmController manages track encryption.\n */\n readonly drmController: DrmController\n}\n\n/**\n * General configuration for tracks set in track load options.\n */\nexport interface TrackBaseOptions {\n /**\n * The time to seek to when the track has been activated.\n * For MSE tracks this will affect pre-fetching.\n */\n readonly startTime?: Maybe<number>\n\n /**\n * Extra application data to associate with the track.\n */\n readonly extra?: any\n\n /**\n * DRM Configuration overrides for this track.\n */\n readonly drm?: Partial<DrmOptions>\n}\n\nexport const trackBaseOptionsValidator: ObjectSchema<TrackBaseOptions> = /* @__PURE__ */ object(\n {\n extra: /* @__PURE__ */ /* @__PURE__ */ any().optional(),\n startTime: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ number().maybe().optional(),\n drm: /* @__PURE__ */ /* @__PURE__ */ drmOptionsValidator.partial().optional(),\n }\n)\n\n/**\n * A base class for all tracks.\n */\nexport abstract class TrackBase<\n EventMap extends TrackEventMap = TrackEventMap,\n LoadOptionsType extends TrackBaseOptions = TrackBaseOptions,\n>\n extends EventHostImpl<EventMap>\n implements Track<LoadOptionsType>\n{\n get [Symbol.toStringTag](): string {\n return 'TrackBase'\n }\n\n /**\n * The current load options, if this is an active track.\n */\n protected loadOptions: LoadOptionsType | null = null\n\n protected readonly errorHandler = (error: any): void => {\n if (this._error) return // Already in an error state\n if (!isSilentError(error)) {\n this._error = error\n this.dispatch('error', {\n target: this,\n error,\n })\n }\n }\n protected readonly disposer = /* @__PURE__ */ createDisposer()\n protected drmSessionAbort = /* @__PURE__ */ createAbortSlot()\n\n get fetchedRanges(): ReadonlyRanges {\n return emptyRanges\n }\n\n abstract get contentTypes(): ReadonlySet<ContentType>\n\n abstract get qualities(): readonly MediaQualityMetadata[] | null\n abstract get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null\n\n abstract getStreamingQuality(\n contentType: ContentType\n ): MediaQualityMetadata | null\n abstract getBufferingQuality(\n contentType: ContentType\n ): MediaQualityMetadata | null\n abstract getPlaybackQuality(\n contentType: ContentType\n ): MediaQualityMetadata | null\n\n /**\n * Sets on handleError, cleared on 'reset'.\n */\n protected _error: Error | null = null\n\n private _active = false\n\n protected constructor(\n /**\n * The identifier of this track, used as the key in the track cache.\n */\n readonly uri: TrackUri,\n\n /**\n * The track type.\n */\n readonly type: TrackTypeId,\n\n protected readonly deps: TrackBaseDeps\n ) {\n super()\n }\n\n get error(): Error | null {\n return this._error\n }\n\n preload(\n _trackOptions: TrackPreloadOptions,\n _loadOptions: LoadOptionsType\n ): void {}\n\n get extra(): any {\n return this.loadOptions?.extra ?? null\n }\n\n get active(): boolean {\n return this._active\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n activate(loadOptions: LoadOptionsType): void {\n if (this._active) return\n this.loadOptions = loadOptions\n this.reset() // Reset error state on activate\n this._active = true\n logDebug(this, 'activate', this.uri)\n this.deps.playbackController\n .seekTo(loadOptions.startTime ?? 0)\n .catch(noop)\n this.deps.drmController.configure(loadOptions.drm)\n this.onActivated(loadOptions)\n }\n\n /**\n * The track has been activated.\n * Operations on shared resources such as the playback controller may only be done while the\n * track is currently active. For example if there is a loading operation before the\n * playback source is set, isActive must be checked before the property is changed.\n */\n abstract onActivated(loadOptions: LoadOptionsType): void\n\n deactivate(): void {\n if (!this._active) return\n this._active = false\n this.loadOptions = null\n logDebug(this, 'deactivate', this.uri)\n this.deps.playbackController.pause()\n this.onDeactivated()\n this.closeDrmSessions()\n }\n\n abstract onDeactivated(): void\n\n toString(): string {\n return `[${this[Symbol.toStringTag]}#${this.uri}]`\n }\n\n protected closeDrmSessions() {\n this.drmSessionAbort.abort()\n }\n\n abstract clearPrefetch(): void\n\n /**\n * Resets the track to recover from error states.\n * Base implementation does nothing.\n *\n * Overrides should dispatch 'reset' after resetting error state.\n */\n reset(): void {\n if (this._error == null) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.dispatch('reset', {})\n }\n\n dispose() {\n if (this.active) this.deactivate()\n else this.closeDrmSessions() // closes sessions created from prefetch.\n this.disposer.dispose()\n super.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyRecord, ValueProvider } from '@amazon/vinyl-util'\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\nimport type { MediaFormatMetadata } from '@/streaming/MediaQualityMetadata'\nimport {\n enumOf,\n func,\n isOneOf,\n number,\n object,\n type ObjectSchema,\n record,\n recordValues,\n string,\n type ValueSchema,\n} from '@amazon/vinyl-validation'\nimport { DrmKeySystem, drmKeySystemValidator } from './DrmKeySystem'\nimport {\n type LicenseProvider,\n type LicenseServerOptions,\n licenseServerOptionsValidator,\n} from '@/drm/licenseProvider/LicenseProvider'\n\n/**\n * DrmRobustness is the requested security level for audio or video decryption.\n */\nexport enum DrmRobustness {\n SW_SECURE_CRYPTO = 'SW_SECURE_CRYPTO',\n SW_SECURE_DECODE = 'SW_SECURE_DECODE',\n HW_SECURE_CRYPTO = 'HW_SECURE_CRYPTO',\n HW_SECURE_DECODE = 'HW_SECURE_DECODE',\n HW_SECURE_ALL = 'HW_SECURE_ALL',\n}\n\n/**\n * DrmConfig configures DrmController and LicenseProvider.\n */\nexport interface DrmOptions {\n readonly keySystems: {\n readonly [p in DrmKeySystem]?: DrmKeySystemOptions\n } & {\n readonly [DrmKeySystem.CLEAR_KEY]?: DrmClearKeySystemOptions\n } & {\n /**\n * A wildcard to match any key system when there wasn't a match.\n */\n readonly ['*']?: DrmKeySystemOptions\n }\n\n /**\n *\n * If not set, the license provider from the player dependencies will\n * be used.\n */\n readonly licenseProvider?: LicenseProvider\n}\n\n/**\n * Clear key system options that extend base DRM key system options with clear\n * key mappings. Used for unencrypted content or testing scenarios where keys\n * are provided in plain text.\n */\nexport type DrmClearKeySystemOptions = DrmKeySystemOptions & {\n readonly keys: ReadonlyRecord<string, string>\n}\n\nexport interface DrmKeySystemOptions {\n /**\n * License server configuration used to make license requests.\n */\n readonly licenseServer?: ValueProvider<LicenseServerOptions>\n\n /**\n * Audio-specific DRM configuration.\n */\n readonly audio?: DrmMediaKeySystemOptions\n\n /**\n * Video-specific DRM configuration.\n */\n readonly video?: DrmMediaKeySystemOptions\n\n /**\n * Key systems with a higher priority take precedence.\n * If two key systems have equal priority, the order will be as it appears\n * in DrmInfo (provided by the manifest).\n */\n readonly priority?: number\n\n /**\n * Transform applied to init data before session creation.\n * Always invoked for every key system. The default implementation\n * handles {@link DrmKeySystem.FAIR_PLAY_1_0} by packing the init data,\n * content ID, and server certificate into the format expected by\n * WebKit-prefixed EME. For all other key systems, returns init data\n * unchanged.\n */\n readonly initDataTransformer?: InitDataTransformer\n}\n\n/**\n * Transforms raw init data before it is passed to the CDM for session creation.\n *\n * @param initData - The raw initialization data.\n * @param initDataType - The initialization data type (e.g. 'cenc', 'skd').\n * @param drmInfo - The media format metadata for the current content.\n * @returns The transformed init data to pass to the CDM.\n */\nexport type InitDataTransformer = (\n initData: Uint8Array<ArrayBuffer>,\n initDataType: DrmInitDataType,\n drmInfo: MediaFormatMetadata\n) => Uint8Array<ArrayBuffer>\n\nexport interface DrmMediaKeySystemOptions {\n readonly robustness?: DrmRobustness\n}\n\nexport const drmRobustnessValidator: ValueSchema<DrmRobustness> =\n /* @__PURE__ */ enumOf(DrmRobustness)\n\nexport const drmMediaKeySystemOptionsValidator: ObjectSchema<DrmMediaKeySystemOptions> =\n /* @__PURE__ */ object({\n robustness: /* @__PURE__ */ drmRobustnessValidator.optional(),\n })\n\nexport const drmKeySystemOptionsValidator: ObjectSchema<DrmKeySystemOptions> =\n /* @__PURE__ */ object({\n licenseServer: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().or(licenseServerOptionsValidator).optional(),\n audio: /* @__PURE__ */ drmMediaKeySystemOptionsValidator.optional(),\n video: /* @__PURE__ */ drmMediaKeySystemOptionsValidator.optional(),\n priority: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n initDataTransformer: /* @__PURE__ */ /* @__PURE__ */ func().optional(),\n })\n\nexport const drmClearKeySystemOptionsValidator: ObjectSchema<DrmClearKeySystemOptions> =\n /* @__PURE__ */ drmKeySystemOptionsValidator.extend({\n keys: /* @__PURE__ */ recordValues(/* @__PURE__ */ string()),\n })\n\nexport const drmOptionsValidator: ObjectSchema<DrmOptions> = /* @__PURE__ */ object({\n keySystems: /* @__PURE__ */ /* @__PURE__ */ record(\n /* @__PURE__ */ drmKeySystemValidator.or(/* @__PURE__ */ isOneOf('*')),\n /* @__PURE__ */ drmKeySystemOptionsValidator.optional()\n ).and(\n /* @__PURE__ */ object<{\n readonly [DrmKeySystem.CLEAR_KEY]?: DrmClearKeySystemOptions\n }>({\n [DrmKeySystem.CLEAR_KEY]:\n /* @__PURE__ */ drmClearKeySystemOptionsValidator.optional(),\n })\n ),\n\n licenseProvider: /* @__PURE__ */ /* @__PURE__ */ func().optional(),\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ValueSchema } from '@amazon/vinyl-validation'\nimport { string } from '@amazon/vinyl-validation'\n\nexport enum DrmKeySystem {\n /**\n * Plain text encryption.\n */\n CLEAR_KEY = 'org.w3.clearkey',\n\n /**\n * Google's Widevine.\n */\n WIDEVINE = 'com.widevine.alpha',\n\n /**\n * Microsoft's PlayReady.\n *\n * - Deprecated.\n * - Will be removed in a future release.\n * - Non-compliant with any version of the EME specification.\n */\n PLAY_READY = 'com.microsoft.playready',\n\n /**\n * Microsoft's PlayReady for Chromecast.\n *\n * - Deprecated.\n * - Will be removed in a future release.\n * - Non-compliant with any version of the EME specification.\n */\n PLAY_READY_CHROMECAST = 'com.chromecast.playready',\n\n /**\n * Microsoft's PlayReady.\n *\n * - Security Level 2000.\n * - Best effort compliance with latest EME specification.\n */\n PLAY_READY_RECOMMENDATION = 'com.microsoft.playready.recommendation',\n\n /**\n * Microsoft's PlayReady.\n *\n * - Supported on devices with required hardware.\n * - Security Level 3000.\n * - Best effort compliance with latest EME specification.\n */\n PLAY_READY_3000 = 'com.microsoft.playready.recommendation.3000',\n\n /**\n * Apple's Fairplay for modern EME.\n */\n FAIR_PLAY = 'com.apple.fps',\n\n /**\n * Apple's Fairplay for legacy Apple Media Keys.\n */\n FAIR_PLAY_1_0 = 'com.apple.fps.1_0',\n}\n\n/**\n * Validates that the key system value is a string.\n * While DrmKeySystem is an enum to be useful for providing known key systems,\n * avoid strict validation to allow for unknown key systems.\n */\nexport const drmKeySystemValidator =\n /* @__PURE__ */ /* @__PURE__ */ string().notEmpty() as ValueSchema<DrmKeySystem>\n\nexport const PLAY_READY_KEY_SYSTEMS: readonly DrmKeySystem[] = [\n DrmKeySystem.PLAY_READY,\n DrmKeySystem.PLAY_READY_CHROMECAST,\n DrmKeySystem.PLAY_READY_RECOMMENDATION,\n DrmKeySystem.PLAY_READY_3000,\n] as const\n\nexport function isPlayReady(keySystem: DrmKeySystem): boolean {\n return PLAY_READY_KEY_SYSTEMS.includes(keySystem)\n}\n\nexport const FAIR_PLAY_KEY_SYSTEMS: readonly DrmKeySystem[] = [\n DrmKeySystem.FAIR_PLAY,\n DrmKeySystem.FAIR_PLAY_1_0,\n] as const\n\nexport function isFairPlay(keySystem: DrmKeySystem): boolean {\n return FAIR_PLAY_KEY_SYSTEMS.includes(keySystem)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type Maybe, type ReadonlyAbort } from '@amazon/vinyl-util'\nimport type { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport {\n any,\n instanceOf,\n object,\n type ObjectSchema,\n string,\n} from '@amazon/vinyl-validation'\n\n/**\n * LicenseProvider handles requesting DRM licenses for specific key systems.\n */\nexport type LicenseProvider = (\n keySystem: DrmKeySystem,\n serverOptions: LicenseServerOptions,\n challenge: ArrayBuffer,\n abort?: ReadonlyAbort\n) => Promise<ArrayBuffer>\n\n/**\n * Basic license server configuration.\n * The license provider is given the matching configuration for the selected\n * key system.\n */\nexport interface LicenseServerOptions {\n /**\n * The license server URL.\n * This is required when using the default license provider.\n */\n readonly url?: Maybe<string | URL>\n\n /**\n * License request init options.\n */\n readonly init?: Maybe<RequestInit>\n\n /**\n * If set, provides the server certificate.\n * An ArrayBufferLike object containing the server certificate.\n * The contents are Key System-specific.\n * If a `string` is provided, the value will be considered to be Base 64.\n */\n readonly serverCertificate?: Maybe<ServerCertificate>\n}\n\n/**\n * An ArrayBufferLike object containing the server certificate.\n * The contents are Key System-specific.\n * If a `string` is provided, the value will be considered to be Base 64.\n */\nexport type ServerCertificate = ArrayBuffer | string\n\nexport const licenseServerOptionsValidator: ObjectSchema<LicenseServerOptions> =\n /* @__PURE__ */ object({\n url: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().or(/* @__PURE__ */ instanceOf(URL)).maybe().optional(),\n init: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).cast<RequestInit>().maybe().optional(),\n serverCertificate: /* @__PURE__ */ /* @__PURE__ */ any().optional(),\n })\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { TrackEventMap } from '@/track/Track'\nimport type { Unsubscribe } from '@amazon/vinyl-util'\nimport { EventHostImpl, type ReadonlySet } from '@amazon/vinyl-util'\nimport { PlaybackReadyState } from '@/playback/ReadonlyPlaybackController'\nimport type { PlaybackController } from '@/playback/PlaybackController'\nimport type { ChangeEvent } from '@/event/ChangeEvent'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\n\n/**\n * FixedPlaybackQuality has a singular quality for selection.\n *\n * streamingQuality will always be the fixed quality.\n *\n * bufferingQuality will be the fixed quality when active, otherwise null.\n *\n * playbackQuality will be the fixed quality when active and data is buffered, otherwise null.\n */\nexport class FixedPlaybackQuality extends EventHostImpl<\n Pick<\n TrackEventMap,\n | 'streamingQualityChange'\n | 'bufferingQualityChange'\n | 'playbackQualityChange'\n >\n> {\n private _fixedQuality!: MediaQualityMetadata\n private _contentTypes = /* @__PURE__ */ new Set<ContentType>()\n\n private _isActive = false\n get active(): boolean {\n return this._isActive\n }\n\n constructor(\n fixedQuality: MediaQualityMetadata,\n private readonly deps: {\n readonly playbackController: PlaybackController\n }\n ) {\n super()\n this.fixedQuality = fixedQuality\n }\n\n get contentTypes(): ReadonlySet<ContentType> {\n return this._contentTypes\n }\n\n get fixedQuality(): MediaQualityMetadata {\n return this._fixedQuality\n }\n\n set fixedQuality(value: MediaQualityMetadata) {\n const previous = this._fixedQuality\n this._fixedQuality = value\n this._contentTypes = new Set()\n if (value.contentType) this._contentTypes.add(value.contentType)\n this.dispatch('streamingQualityChange', {\n previous,\n current: this._fixedQuality,\n })\n if (this.active) {\n this.bufferingQuality = value\n if (\n this.deps.playbackController.readyState >=\n PlaybackReadyState.HAVE_CURRENT_DATA\n ) {\n this.playbackQuality = value\n }\n }\n }\n\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n if (contentType !== this._fixedQuality.contentType) return null\n return this._fixedQuality\n }\n\n private _bufferingQuality: MediaQualityMetadata | null = null\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n if (contentType !== this._bufferingQuality?.contentType) return null\n return this._bufferingQuality\n }\n\n private set bufferingQuality(value: MediaQualityMetadata | null) {\n const previous = this._bufferingQuality\n if (previous === value) return\n this._bufferingQuality = value\n this.dispatch('bufferingQualityChange', {\n previous,\n current: this._bufferingQuality,\n })\n }\n\n private _playbackQuality: MediaQualityMetadata | null = null\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n if (contentType !== this._playbackQuality?.contentType) return null\n return this._playbackQuality\n }\n\n private set playbackQuality(value: MediaQualityMetadata | null) {\n const previous = this._playbackQuality\n if (previous === value) return\n this._playbackQuality = value\n this.dispatch('playbackQualityChange', {\n previous,\n current: this._playbackQuality,\n })\n }\n\n private readyStateChangeSub: Unsubscribe | null = null\n activate() {\n if (this._isActive) return\n this._isActive = true\n this.bufferingQuality = this._fixedQuality\n const pC = this.deps.playbackController\n this.readyStateChangeSub = pC.on(\n 'readyStateChange',\n this.onReadyStateChange\n )\n if (pC.readyState >= PlaybackReadyState.HAVE_CURRENT_DATA) {\n this.playbackQuality = this._fixedQuality\n }\n }\n\n deactivate() {\n if (!this._isActive) return\n this._isActive = false\n this.readyStateChangeSub!()\n this.readyStateChangeSub = null\n this.bufferingQuality = null\n this.playbackQuality = null\n }\n\n private onReadyStateChange = (event: ChangeEvent<PlaybackReadyState>) => {\n const hasData = event.current >= PlaybackReadyState.HAVE_CURRENT_DATA\n this.playbackQuality = hasData ? this._fixedQuality : null\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n TrackBase,\n type TrackBaseDeps,\n type TrackBaseOptions,\n trackBaseOptionsValidator,\n} from '@/track/TrackBase'\nimport type {\n TrackEventMap,\n TrackPreloadOptions,\n TrackTypeId,\n TrackUri,\n} from '@/track/Track'\nimport { FixedPlaybackQuality } from '@/track/source/FixedPlaybackQuality'\nimport {\n logDebug,\n type Maybe,\n type ReadonlySet,\n redispatchEvents,\n} from '@amazon/vinyl-util'\nimport {\n type ContentType,\n createEmptyMediaQualityMetadata,\n type MediaQualityMetadata,\n mediaQualityMetadataValidator,\n} from '@/streaming/MediaQualityMetadata'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\n\nexport interface SourceTrackBaseOptions extends TrackBaseOptions {\n /**\n * Quality metadata.\n * May be used to configure DRM (for native HLS), codec, or other track metadata.\n */\n readonly qualityMetadata?: Maybe<Partial<MediaQualityMetadata>>\n}\n\nexport const sourceTrackBaseOptionsValidator: ObjectSchema<SourceTrackBaseOptions> =\n /* @__PURE__ */ trackBaseOptionsValidator.extend({\n qualityMetadata: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ mediaQualityMetadataValidator\n .partial()\n .maybe()\n .optional(),\n })\n\nconst emptyMediaQualityMetadata: MediaQualityMetadata =\n /* @__PURE__ */ createEmptyMediaQualityMetadata()\n\nexport abstract class SourceTrackBase<\n SrcType,\n EventMap extends TrackEventMap = TrackEventMap,\n LoadOptionsType extends SourceTrackBaseOptions = SourceTrackBaseOptions,\n> extends TrackBase<EventMap, LoadOptionsType> {\n private readonly fixedPlaybackQuality: FixedPlaybackQuality\n private _resolvedSrc: SrcType | null = null\n\n protected constructor(\n uri: TrackUri,\n type: TrackTypeId,\n public readonly src: Promise<SrcType>,\n protected readonly deps: TrackBaseDeps\n ) {\n super(uri, type, deps)\n const add = this.disposer.add\n this.src\n .then((src) => {\n this._resolvedSrc = src\n if (this.active) this.setSrc(src)\n })\n .catch(this.errorHandler)\n this.fixedPlaybackQuality = add(\n new FixedPlaybackQuality(emptyMediaQualityMetadata, deps)\n )\n this.fixedPlaybackQuality.on('bufferingQualityChange', (event) => {\n this.deps.drmController.setBufferingDrmInfo(\n event.current,\n this.drmSessionAbort.value\n )\n })\n redispatchEvents(this, this.fixedPlaybackQuality, [\n 'streamingQualityChange',\n 'bufferingQualityChange',\n 'playbackQualityChange',\n ])\n }\n\n preload(trackOptions: TrackPreloadOptions, loadOptions: LoadOptionsType) {\n super.preload(trackOptions, loadOptions)\n this.fixedPlaybackQuality.fixedQuality = {\n ...emptyMediaQualityMetadata,\n ...loadOptions.qualityMetadata,\n }\n }\n\n get contentTypes(): ReadonlySet<ContentType> {\n return this.fixedPlaybackQuality.contentTypes\n }\n\n get qualities(): readonly MediaQualityMetadata[] | null {\n return null\n }\n\n get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null {\n return null\n }\n\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.fixedPlaybackQuality.getStreamingQuality(contentType)\n }\n\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.fixedPlaybackQuality.getBufferingQuality(contentType)\n }\n\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.fixedPlaybackQuality.getPlaybackQuality(contentType)\n }\n\n onActivated(): void {\n this.fixedPlaybackQuality.activate()\n this.deps.drmController.initializeForPlayback(\n this.fixedPlaybackQuality.fixedQuality,\n this.drmSessionAbort.value\n )\n if (this._resolvedSrc != null) this.setSrc(this._resolvedSrc)\n }\n\n protected abstract setSrc(src: SrcType): void\n protected abstract clearSrc(): void\n\n onDeactivated(): void {\n if (this._resolvedSrc != null) this.clearSrc()\n this.fixedPlaybackQuality.deactivate()\n }\n\n clearPrefetch() {\n // Source tracks do not prefetch\n logDebug(this, 'clearPrefetch no-op')\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createShortUid,\n type Maybe,\n type MutableDeep,\n} from '@amazon/vinyl-util'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n array,\n enumOf,\n isOneOf,\n number,\n object,\n string,\n tuple,\n} from '@amazon/vinyl-validation'\nimport {\n type DescriptorRecord,\n descriptorRecordValidator,\n descriptorValidator,\n} from '@/streaming/DescriptorRecord'\n\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\nimport type { CencEncryptionScheme } from '@/drm/CencEncryptionScheme'\nimport { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport type { FrameRate } from '@amazon/vinyl-mpd-parser'\n\nexport type ContentType = 'audio' | 'video' | 'text'\n\nexport const ALL_CONTENT_TYPES = [\n 'video',\n 'audio',\n 'text',\n] as const satisfies ContentType[]\n\n/**\n * Contains media formatting and encryption metadata.\n */\nexport interface MediaFormatMetadata {\n /**\n * The content type of the representation, e.g. 'audio', 'video', 'text'\n * Must be non-null for segmented media.\n */\n readonly contentType: ContentType | null\n\n /**\n * The full MIME type of the media.\n *\n * Must be non-null for segmented media.\n */\n readonly mimeType: string | null\n\n /**\n * The initialization data format.\n */\n readonly initDataType: DrmInitDataType | null\n\n /**\n * The method of encryption, or null.\n */\n readonly encryptionScheme: CencEncryptionScheme | null\n\n /**\n * Protection schemes used in this media.\n */\n readonly contentProtections: readonly DrmProtection[]\n}\n\n/**\n * Protection information for a key system.\n * Media may have more than one protection system.\n */\nexport interface DrmProtection {\n /**\n * The key system used in the encryption.\n */\n readonly keySystem: DrmKeySystem\n\n /**\n * The initialization key, in base 64.\n */\n readonly pssh?: Maybe<string>\n\n /**\n * PlayReady object.\n */\n readonly pro?: Maybe<string>\n}\n\nexport const drmProtectionValidator: ObjectSchema<DrmProtection> =\n /* @__PURE__ */ descriptorValidator.extend({\n keySystem: /* @__PURE__ */ enumOf(DrmKeySystem),\n pro: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n pssh: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n })\n\nexport const mediaFormatMetadataValidator: ObjectSchema<MediaFormatMetadata> =\n /* @__PURE__ */ object({\n contentProtections: /* @__PURE__ */ /* @__PURE__ */ array(drmProtectionValidator).readonly(),\n contentType: /* @__PURE__ */ /* @__PURE__ */ isOneOf('audio', 'video', 'text').orNull(),\n initDataType: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n encryptionScheme: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n mimeType: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n })\n\n/**\n * Metadata representing attributes of a media representation.\n */\nexport interface MediaQualityMetadata extends MediaFormatMetadata {\n /**\n * Provides a decoding identifier. If this value changes from the previously buffered\n * segment, the initialization segment must be buffered before appending the media segment.\n * Unique to the track.\n */\n readonly decoderId: string\n\n /**\n * The quality id identifies the quality representation.\n * Unique to the track.\n */\n readonly qualityId: string\n\n /**\n * Optional string specifying the codec(s) used for this representation. The format follows the RFC 6381 codec\n * string format.\n */\n readonly codecs: string | null\n\n /**\n * The average bandwidth in bits per second required for playing this representation.\n * For HLS, and non-segmented media this will be null.\n */\n readonly bandwidth: number | null\n\n /**\n * The peak bandwidth in bits per second required for playing this representation\n * with its cumulative A/V content streams.\n *\n * Guaranteed to be set for segmented media.\n */\n readonly bandwidthTotal: number | null\n\n /**\n * Audio sampling rate(s) in samples per second.\n * An array of either one or two decimal integer values. If there are two elements this represents a minimum and\n * maximum sampling rate of the audio media.\n */\n readonly audioSamplingRate: readonly number[] | null\n\n /**\n * Frame rate for video representations, specified either as a ratio of integers, e.g. [30000, 1001]\n */\n readonly frameRate: FrameRate | null\n\n /**\n * For video representations, the width of the video in pixels.\n */\n readonly width: number | null\n\n /**\n * For video representations, the height of the video in pixels.\n */\n readonly height: number | null\n\n /**\n * Information that may enhance playback or presentation.\n */\n readonly supplementalProperties: DescriptorRecord\n\n /**\n * Specifies the language of the content, using a code as defined by RFC 5646.\n */\n readonly lang: string | null\n\n /**\n * Identifies the group this quality belongs to (e.g. the adaptation set).\n */\n readonly groupId: string\n\n /**\n * The group IDs that this quality is permitted to switch to during playback.\n * Derived from the DASH `urn:mpeg:dash:adaptation-set-switching:2016` supplemental property.\n * Includes the quality's own groupId.\n * Null means no switching constraint (all groups are permitted).\n * An array restricts switching to only the listed group IDs.\n * Default behavior:\n * - DASH: restricted to own group unless adaptation-set-switching property is present.\n * - HLS: restricted to variants with the same base codec and language.\n */\n readonly switchingGroupIds: readonly string[] | null\n}\n\n/**\n * Creates a new, empty media format metadata object.\n */\nexport function createEmptyMediaFormatMetadata(): MutableDeep<MediaFormatMetadata> {\n return {\n contentType: null,\n mimeType: null,\n initDataType: null,\n encryptionScheme: null,\n contentProtections: [],\n }\n}\n\n/**\n * Creates a new empty media quality metadata object.\n */\nexport function createEmptyMediaQualityMetadata(): MutableDeep<MediaQualityMetadata> {\n return {\n ...createEmptyMediaFormatMetadata(),\n decoderId: createShortUid(),\n qualityId: createShortUid(),\n codecs: null,\n bandwidth: null,\n bandwidthTotal: null,\n supplementalProperties: {},\n audioSamplingRate: null,\n frameRate: null,\n height: null,\n width: null,\n lang: null,\n groupId: createShortUid(),\n switchingGroupIds: null,\n }\n}\n\nexport const mediaQualityMetadataValidator: ObjectSchema<MediaQualityMetadata> =\n /* @__PURE__ */ mediaFormatMetadataValidator.extend({\n audioSamplingRate: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ array(/* @__PURE__ */ number()).readonly().orNull(),\n bandwidth: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n bandwidthTotal: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n codecs: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n decoderId: /* @__PURE__ */ string(),\n frameRate: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ tuple(/* @__PURE__ */ number(), /* @__PURE__ */ number()).readonly().orNull(),\n height: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n qualityId: /* @__PURE__ */ string(),\n supplementalProperties: descriptorRecordValidator,\n width: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n lang: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n groupId: /* @__PURE__ */ string(),\n switchingGroupIds: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ array(/* @__PURE__ */ string()).readonly().orNull(),\n })\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n array,\n object,\n type ObjectSchema,\n record,\n type RecordSchema,\n string,\n} from '@amazon/vinyl-validation'\nimport { first, type Maybe, type ReadonlyRecord } from '@amazon/vinyl-util'\nimport { type Uri } from '@amazon/vinyl-xml'\n\n/**\n * A map of scheme URIs to a descriptor list.\n */\nexport type DescriptorRecord = ReadonlyRecord<\n Uri,\n readonly Descriptor[] | undefined\n>\n\n/**\n * A generic descriptor providing extended information.\n */\nexport interface Descriptor {\n /**\n * An optional unique identifier for the descriptor.\n */\n readonly id?: Maybe<string>\n\n /**\n * An optional value associated with the descriptor, whose interpretation depends on the scheme.\n */\n readonly value?: Maybe<string>\n}\n\n/**\n * Gets The first matching descriptor value from a record with a matching URI and optional id.\n *\n * @param record The descriptor record.\n * @param uri The URI key.\n * @param id An optional id. If provided the descriptor must have a matching id.\n */\nexport function getDescriptorValue(\n record: DescriptorRecord,\n uri: Uri,\n id?: Maybe<string>\n): string | null {\n let arr = record[uri]\n if (!arr) return null\n if (id !== undefined) arr = arr.filter((descriptor) => descriptor.id === id)\n return first(arr)?.value ?? null\n}\n\nexport const descriptorValidator: ObjectSchema<Descriptor> = /* @__PURE__ */ object({\n id: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n value: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n})\n\nexport const descriptorRecordValidator: RecordSchema<DescriptorRecord> = /* @__PURE__ */ record<\n Uri,\n readonly Descriptor[] | undefined\n>(/* @__PURE__ */ string(), /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ array(descriptorValidator).readonly().orUndefined())\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Track, TrackTypeId, TrackUri } from '@/track/Track'\nimport { type TrackBaseDeps } from '@/track/TrackBase'\nimport {\n type TrackFactory,\n type TrackLoadOptions,\n trackLoadOptionsValidator,\n} from '@/track/TrackFactory'\nimport { ErrorOrigin, type Maybe } from '@amazon/vinyl-util'\nimport {\n func,\n isOneOf,\n type ObjectSchema,\n string,\n} from '@amazon/vinyl-validation'\nimport {\n SourceTrackBase,\n type SourceTrackBaseOptions,\n sourceTrackBaseOptionsValidator,\n} from '@/track/source/SourceTrackBase'\nimport type { PlaybackSource } from '@/playback/PlaybackSource'\n\n/**\n * Dependencies for a SourceTrack.\n */\nexport interface SourceTrackDeps extends TrackBaseDeps {\n readonly playbackSource: PlaybackSource\n}\n\nexport interface SourceTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'src'\n\n /**\n * If set, will be called to provide the track src.\n * Otherwise, the uri will be used.\n */\n readonly srcProvider?: Maybe<(uri: TrackUri) => Promise<string> | string>\n\n /**\n * Configuration options for the SourceTrack.\n * Will be provided on preload and activate.\n */\n readonly config?: Maybe<SourceTrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<SourceTrackLoadOptions> =\n /* @__PURE__ */ trackLoadOptionsValidator.extend({\n config: /* @__PURE__ */ /* @__PURE__ */ sourceTrackBaseOptionsValidator.maybe().optional(),\n srcProvider: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().maybe().optional(),\n type: /* @__PURE__ */ isOneOf('src'),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n })\n\nexport function createSourceTrackFactory(\n deps: SourceTrackDeps\n): TrackFactory<SourceTrackLoadOptions> {\n return {\n validate(options: SourceTrackLoadOptions) {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(options: SourceTrackLoadOptions): Track {\n return new SourceTrack(\n options.uri,\n options.type,\n options.srcProvider\n ? Promise.resolve(options.srcProvider(options.uri))\n : Promise.resolve(options.uri),\n deps\n )\n },\n }\n}\n\n// TODO: Accept a provider function instead of a Promise for src to support reset.\nexport class SourceTrack extends SourceTrackBase<string> {\n get [Symbol.toStringTag](): string {\n return 'SourceTrack'\n }\n\n constructor(\n uri: TrackUri,\n type: TrackTypeId,\n src: Promise<string>,\n protected readonly deps: SourceTrackDeps\n ) {\n super(uri, type, src, deps)\n }\n\n protected setSrc(src: string) {\n this.deps.playbackSource.src = src\n }\n\n protected clearSrc() {\n this.deps.playbackSource.src = null\n this.deps.playbackSource.load()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type TrackBaseOptions,\n trackBaseOptionsValidator,\n} from '@/track/TrackBase'\nimport {\n type DashManifestProvider,\n type DashManifestData,\n} from './DashManifestProvider'\nimport type { DashManifestController } from './DashManifestController'\nimport type { TrackFactory, TrackLoadOptions } from '@/track/TrackFactory'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport {\n ErrorOrigin,\n type Maybe,\n type RequestInitOptions,\n} from '@amazon/vinyl-util'\nimport {\n func,\n isOneOf,\n object,\n type ObjectSchema,\n string,\n} from '@amazon/vinyl-validation'\nimport type { Track } from '@/track/Track'\nimport { type Factories } from '@amazon/vinyl-di'\nimport type { DashMediaQualityMetadataResolver } from '@/track/dash/DashMediaQualityMetadataResolver'\nimport { MseTrack, type MseTrackDeps } from '@/track/mse/MseTrack'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\n\nexport interface DashTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'dash'\n\n /**\n * If set, will be used to resolve the dash manifest.\n * Otherwise, the uri will be assumed to represent a URL to an MPD.\n * The manifest provider is not expected to cache results.\n */\n readonly manifestProvider?: Maybe<DashManifestProvider>\n\n /**\n * If a manifest provider is not set, the uri will be used to fetch a manifest.\n * This can be set to provide Request initialization options such as headers or request method.\n */\n readonly requestInit?: Maybe<RequestInitOptions>\n\n /**\n * Request initialization options for segment requests, such as headers.\n * Range headers set by the player for byte-range requests will not be overridden.\n */\n readonly segmentRequestInit?: Maybe<RequestInitOptions>\n\n /**\n * Configuration options for the DashTrack.\n * Will be set before the track is activated.\n */\n readonly config?: Maybe<TrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<DashTrackLoadOptions> = /* @__PURE__ */ object({\n config: /* @__PURE__ */ /* @__PURE__ */ trackBaseOptionsValidator.maybe().optional(),\n manifestProvider: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().maybe().optional(),\n requestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).cast<RequestInitOptions>().maybe().optional(),\n segmentRequestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({})\n .cast<RequestInitOptions>()\n .maybe()\n .optional(),\n type: /* @__PURE__ */ isOneOf('dash'),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n})\n\nexport type DashTrackFactoryDeps = {\n readonly createDashFactories: (\n loadOptions: DashTrackLoadOptions\n ) => Factories<DashTrackDeps>\n}\n\nexport function createDashTrackFactory(\n deps: DashTrackFactoryDeps\n): TrackFactory<DashTrackLoadOptions> {\n return {\n validate(options: DashTrackLoadOptions) {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(loadOptions: DashTrackLoadOptions): Track {\n return new MseTrack(\n loadOptions.uri,\n loadOptions.type,\n deps.createDashFactories(loadOptions)\n )\n },\n }\n}\n\nexport interface DashTrackDeps extends MseTrackDeps {\n readonly manifestController: DashManifestController\n readonly mediaQualityMetadataResolver: DashMediaQualityMetadataResolver\n readonly manifestTransformed: ObservableValue<Promise<DashManifestData>>\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n TrackBase,\n type TrackBaseDeps,\n type TrackBaseOptions,\n} from '@/track/TrackBase'\nimport {\n Abort,\n equalDeep,\n type Fun,\n IntersectionRanges,\n logDebug,\n type ReadonlyRanges,\n type ReadonlySet,\n redispatchEvents,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport type { TrackPreloadOptions, TrackTypeId, TrackUri } from '@/track/Track'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport { createContainer, type Factories } from '@amazon/vinyl-di'\nimport type {\n ContentStream,\n ContentStreamActivateOptions,\n ContentStreamPreloadOptions,\n} from '@/streaming/ContentStream'\nimport type { MediaSourceController } from '@/streaming/buffering/MediaSourceController'\nimport type { PlaybackSource } from '@/playback/PlaybackSource'\nimport type { ContentTypesValue } from '@/streaming/ContentTypesValue'\nimport type { ManifestController } from '@/streaming/ManifestController'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\nimport {\n getMediaPeriodAtTime,\n type MediaPeriod,\n} from '@/streaming/MediaTimeline'\n\nexport type MseTrackDeps = TrackBaseDeps & {\n readonly contentTypesValue: ContentTypesValue\n readonly contentStreamFactory: (contentType: ContentType) => ContentStream\n readonly manifestController: ManifestController<unknown>\n readonly mediaSourceController: MediaSourceController\n readonly playbackSource: PlaybackSource\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n}\n\ntype FunctionKeys<T> = {\n [P in keyof T]: T[P] extends Fun ? P : never\n}[keyof T]\n\n/**\n * An MseTrack uses media source extensions for streaming.\n */\nexport class MseTrack extends TrackBase {\n get [Symbol.toStringTag](): string {\n return 'MseTrack'\n }\n\n declare protected readonly deps: MseTrackDeps\n\n private readonly streams: ContentStream[] = []\n private readonly disposeAbort = /* @__PURE__ */ new Abort()\n private lastPreloadOptions: ContentStreamPreloadOptions | null = null\n private activateOptions: ContentStreamActivateOptions | null = null\n private readonly allFetchedRanges: ReadonlyRanges[] = []\n private readonly _fetchedRanges = /* @__PURE__ */ new IntersectionRanges(\n this.allFetchedRanges,\n { useCache: true }\n )\n private _contentTypes: ReadonlySet<ContentType> = /* @__PURE__ */ new Set()\n\n private _qualities: readonly MediaQualityMetadata[] | null = null\n private _qualitiesUnfiltered: readonly MediaQualityMetadata[] | null = null\n private timeUpdateSub: Unsubscribe | null = null\n private _cachedPeriod: MediaPeriod | null = null\n\n constructor(\n uri: TrackUri,\n type: TrackTypeId,\n dependencyFactories: Factories<MseTrackDeps>\n ) {\n const depsContainer = createContainer(dependencyFactories)\n const deps = depsContainer.dependencies\n super(uri, type, deps)\n logDebug(this, 'constructed')\n const { add } = this.disposer\n add(depsContainer)\n this.deps = deps\n\n add(\n deps.contentTypesValue.onData((contentTypesPromise) => {\n contentTypesPromise\n .then((contentTypes) => {\n if (this.disposer.disposed) return\n if (equalDeep(this.contentTypes, contentTypes)) return // no-op\n this.clearStreams()\n for (const contentType of contentTypes) {\n this.createStream(contentType)\n }\n // Sets the content types and dispatches a change event:\n this.contentTypes = contentTypes\n })\n .catch(this.errorHandler)\n })\n )\n\n // DRM\n this.on('streamingQualityChange', (event) => {\n if (this.activateOptions) {\n this.deps.drmController.initializeForPlayback(\n event.current,\n this.disposeAbort\n )\n }\n })\n\n this.on('bufferingQualityChange', (event) => {\n this.deps.drmController.setBufferingDrmInfo(\n event.current,\n this.disposeAbort\n )\n })\n\n // Listen for timeline changes to update qualities.\n add(\n deps.mediaTimelineTransformed.onData(() => {\n this._cachedPeriod = null\n this.updateQualities()\n })\n )\n add(\n deps.mediaTimeline.onData(() => {\n this._cachedPeriod = null\n this.updateQualitiesUnfiltered()\n })\n )\n }\n\n /**\n * Updates the cached qualities list from the transformed timeline for the current period.\n */\n private updateQualities(): void {\n const time = this.deps.playbackController.currentTime\n this.deps.mediaTimelineTransformed.value\n .then((timeline) => {\n if (this.disposer.disposed) return\n const period = getMediaPeriodAtTime(timeline, time)\n this._cachedPeriod = period\n const newQualities = period\n ? period.qualities.map((q) => q.metadata)\n : null\n if (!equalDeep(newQualities, this._qualities)) {\n const previous = this._qualities\n this._qualities = newQualities\n if (newQualities) {\n this.dispatch('qualitiesChange', {\n previous: previous ?? [],\n current: newQualities,\n })\n }\n }\n })\n .catch(this.errorHandler)\n }\n\n /**\n * Updates the cached unfiltered qualities list from the raw timeline for the current period.\n */\n private updateQualitiesUnfiltered(): void {\n const time = this.deps.playbackController.currentTime\n this.deps.mediaTimeline.value\n .then((timeline) => {\n if (this.disposer.disposed) return\n const period = getMediaPeriodAtTime(timeline, time)\n const newQualities = period\n ? period.qualities.map((q) => q.metadata)\n : null\n if (!equalDeep(newQualities, this._qualitiesUnfiltered)) {\n const previous = this._qualitiesUnfiltered\n this._qualitiesUnfiltered = newQualities\n if (newQualities) {\n this.dispatch('qualitiesUnfilteredChange', {\n previous: previous ?? [],\n current: newQualities,\n })\n }\n }\n })\n .catch(this.errorHandler)\n }\n\n /**\n * Creates and adds a content stream for the given content type.\n *\n * @param contentType\n */\n protected createStream(contentType: ContentType): void {\n const stream = this.deps.contentStreamFactory(contentType)\n redispatchEvents(this, stream, [\n 'fetchedRangesChange',\n 'streamingQualityChange',\n 'bufferingQualityChange',\n 'playbackQualityChange',\n ])\n stream.on('bufferingEnded', () => {\n if (this.bufferingEnded) {\n this.deps.mediaSourceController.endOfStream()\n this.dispatch('bufferingEnded', {})\n }\n })\n stream.on('fetchedRangesChange', () => {\n this._fetchedRanges.invalidate()\n })\n stream.on('error', (event) => {\n if (!this._error) {\n // Set error state and bubble event\n this._error = event.error\n this.dispatch('error', event)\n }\n })\n\n // The fetched ranges of the track is the intersection of all content stream fetched ranges.\n this.allFetchedRanges.push(stream.fetchedRanges)\n this._fetchedRanges.invalidate()\n\n this.streams.push(stream)\n if (this.lastPreloadOptions) {\n stream.preload(this.lastPreloadOptions)\n }\n if (this.activateOptions) {\n stream.activate(this.activateOptions)\n }\n }\n\n preload(trackOptions: TrackPreloadOptions, loadOptions: TrackBaseOptions) {\n const options = {\n startTime: loadOptions.startTime,\n prefetchPriority: trackOptions.prefetchPriority,\n }\n this.lastPreloadOptions = options\n this.callOnStreams('preload', options)\n }\n\n get contentTypes(): ReadonlySet<ContentType> {\n return this._contentTypes\n }\n\n set contentTypes(value: ReadonlySet<ContentType>) {\n const previous = this._contentTypes\n this._contentTypes = value\n this.dispatch('contentTypesChange', {\n previous,\n current: value,\n })\n }\n\n get qualities(): readonly MediaQualityMetadata[] | null {\n return this._qualities\n }\n\n get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null {\n return this._qualitiesUnfiltered\n }\n\n get fetchedRanges(): ReadonlyRanges {\n return this._fetchedRanges\n }\n\n /**\n * Clears all fetched fragments and source buffers. Streaming will resume.\n * This should be called if a change has been made where the user would expect an immediate change,\n * for example, changing streaming quality from SD to HD.\n */\n clearPrefetch() {\n logDebug(this, 'clearPrefetch')\n this.callOnStreams('clearPrefetch')\n }\n\n /**\n * Resets the track to recover from error states.\n * Resets both the segment controller and buffering controller to clear failed segments and error conditions.\n */\n reset(): void {\n if (!this.error) {\n logDebug(this, 'reset no-op')\n return\n }\n this.deps.manifestController.reset()\n this.callOnStreams('reset')\n super.reset()\n }\n\n onActivated(loadOptions: TrackBaseOptions): void {\n this.activateOptions = loadOptions\n // AirPlay not supported using managed media sources\n this.deps.playbackSource.disableRemotePlayback = true\n\n this.streams.forEach((stream) => {\n this.deps.drmController.initializeForPlayback(\n stream.streamingQuality,\n this.disposeAbort\n )\n })\n this.deps.playbackSource.src =\n this.deps.mediaSourceController.createUrl()\n this.callOnStreams('activate', loadOptions)\n\n // Listen for timeUpdate to detect period changes.\n this.timeUpdateSub = this.deps.playbackController.on(\n 'timeUpdate',\n () => {\n const time = this.deps.playbackController.currentTime\n const cached = this._cachedPeriod\n if (\n cached &&\n time >= cached.startTime &&\n time < cached.endTime\n ) {\n return\n }\n this.updateQualities()\n this.updateQualitiesUnfiltered()\n }\n )\n }\n\n onDeactivated(): void {\n this.activateOptions = null\n this.timeUpdateSub?.()\n this.timeUpdateSub = null\n this.callOnStreams('deactivate')\n\n this.deps.playbackSource.src = null\n this.deps.playbackSource.load()\n }\n\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.getStream(contentType)?.streamingQuality ?? null\n }\n\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.getStream(contentType)?.bufferingQuality ?? null\n }\n\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.getStream(contentType)?.playbackQuality ?? null\n }\n\n /**\n * Calls the specified method on all streams with the provided arguments.\n */\n private callOnStreams<K extends FunctionKeys<ContentStream>>(\n functionName: K,\n ...args: Parameters<ContentStream[K]>\n ) {\n this.streams.forEach((stream) => {\n ;(stream[functionName] as Fun)(...args)\n })\n }\n\n private getStream(contentType: ContentType): ContentStream | undefined {\n return this.streams.find((s) => s.contentType === contentType)\n }\n\n private clearStreams() {\n this.callOnStreams('dispose')\n this.streams.length = 0\n this.allFetchedRanges.length = 0\n this._fetchedRanges.invalidate()\n }\n\n get bufferingEnded(): boolean {\n return this.streams.every((stream) => stream.bufferingEnded)\n }\n\n dispose(): void {\n logDebug(this, 'dispose')\n this.timeUpdateSub?.()\n this.timeUpdateSub = null\n this.clearStreams()\n super.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SegmentReference } from '@/streaming/SegmentReference'\nimport type { SegmentDataProvider } from '@/streaming/SegmentDataSlot'\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\nimport { sortedInsertionIndex } from '@amazon/vinyl-util'\n\n/**\n * Represents a single quality within a period, providing access to its metadata\n * and segment data.\n */\nexport interface MediaQualityData {\n readonly metadata: MediaQualityMetadata\n\n /**\n * Gets the segment reference at the given time, or null if the time is outside the range.\n * @param time The time, in seconds, relative to the presentation timeline.\n * @param affordance Forward-snap tolerance in seconds: if `time` falls just before a\n * segment's start (within `affordance`), that segment is returned. Defaults to `0`.\n */\n getSegment(\n time: number,\n affordance?: number\n ): Promise<SegmentReference<SegmentDataProvider> | null>\n}\n\n/**\n * Represents a period within the media timeline.\n */\nexport interface MediaPeriod {\n readonly startTime: number\n readonly endTime: number\n readonly qualities: readonly MediaQualityData[]\n}\n\n/**\n * Represents the full media timeline, composed of one or more periods.\n */\nexport interface MediaTimeline {\n readonly periods: readonly MediaPeriod[]\n\n /**\n * The minimum duration of the buffer that a client should maintain for uninterrupted playback.\n */\n readonly minBufferTime: number\n\n /**\n * The total duration of the media, in seconds.\n * Returns null if duration cannot be determined.\n */\n getDuration?(): Promise<number | null>\n}\n\n/**\n * Gets the period spanning the given presentation time.\n */\nexport function getMediaPeriodAtTime(\n timeline: MediaTimeline,\n time: number\n): MediaPeriod | null {\n const index =\n sortedInsertionIndex(timeline.periods, time, (time, period) => {\n return time - period.startTime\n }) - 1\n if (index < 0) return null\n const period = timeline.periods[index]\n return time >= period.endTime ? null : period\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe, RequestInitOptions } from '@amazon/vinyl-util'\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport type { TrackLoadOptions, TrackFactory } from '../TrackFactory'\nimport type { TrackBaseOptions } from '../TrackBase'\nimport type { Track } from '../Track'\nimport type { HlsManifestProvider } from './HlsManifestProvider'\nimport type { HlsManifestController } from './HlsManifestController'\nimport type { HlsManifestData } from './HlsManifestProvider'\nimport type { HlsMediaQualityMetadataResolver } from './HlsMediaQualityMetadataResolver'\nimport type { MseTrackDeps } from '../mse/MseTrack'\nimport { MseTrack } from '../mse/MseTrack'\nimport {\n func,\n isOneOf,\n object,\n string,\n type ObjectSchema,\n} from '@amazon/vinyl-validation'\nimport { trackBaseOptionsValidator } from '../TrackBase'\nimport type { Factories } from '@amazon/vinyl-di'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\n\nexport interface HlsTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'hls'\n readonly manifestProvider?: Maybe<HlsManifestProvider>\n readonly requestInit?: Maybe<RequestInitOptions>\n readonly segmentRequestInit?: Maybe<RequestInitOptions>\n readonly config?: Maybe<TrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<HlsTrackLoadOptions> = /* @__PURE__ */ object({\n config: /* @__PURE__ */ /* @__PURE__ */ trackBaseOptionsValidator.maybe().optional(),\n manifestProvider: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().maybe().optional(),\n requestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).cast<RequestInitOptions>().maybe().optional(),\n segmentRequestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({})\n .cast<RequestInitOptions>()\n .maybe()\n .optional(),\n type: /* @__PURE__ */ isOneOf('hls'),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n})\n\nexport interface HlsTrackDeps extends MseTrackDeps {\n readonly manifestController: HlsManifestController\n readonly manifestTransformed: ObservableValue<Promise<HlsManifestData>>\n readonly mediaQualityMetadataResolver: HlsMediaQualityMetadataResolver\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n}\n\nexport type HlsTrackFactoryDeps = {\n readonly createHlsFactories: (\n loadOptions: HlsTrackLoadOptions\n ) => Factories<HlsTrackDeps>\n}\n\nexport function createHlsTrackFactory(\n deps: HlsTrackFactoryDeps\n): TrackFactory<HlsTrackLoadOptions> {\n return {\n validate(options: HlsTrackLoadOptions) {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(loadOptions: HlsTrackLoadOptions): Track {\n return new MseTrack(\n loadOptions.uri,\n loadOptions.type,\n deps.createHlsFactories(loadOptions)\n )\n },\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createSourceObjectTrackFactory,\n type SourceObjectTrackDeps,\n type SourceObjectTrackLoadOptions,\n} from '@/track/source/SourceObjectTrack'\nimport {\n createSourceTrackFactory,\n type SourceTrackDeps,\n type SourceTrackLoadOptions,\n} from '@/track/source/SourceTrack'\nimport type { TrackTypeId } from '@/track/Track'\nimport type { TrackFactory } from '@/track/TrackFactory'\nimport type { ReadonlyRecord } from '@amazon/vinyl-util'\nimport {\n createDashTrackFactory,\n type DashTrackFactoryDeps,\n type DashTrackLoadOptions,\n} from '@/track/dash/DashTrack'\nimport {\n createHlsTrackFactory,\n type HlsTrackFactoryDeps,\n type HlsTrackLoadOptions,\n} from '@/track/hls/HlsTrack'\n\nexport interface VinylTrackFactoryDeps\n extends\n SourceTrackDeps,\n SourceObjectTrackDeps,\n DashTrackFactoryDeps,\n HlsTrackFactoryDeps {}\n\nexport type VinylTrackLoadOptions =\n | SourceObjectTrackLoadOptions\n | SourceTrackLoadOptions\n | DashTrackLoadOptions\n | HlsTrackLoadOptions\n\n/**\n * Provides a map of track type id to their respective loaders.\n * @param deps\n */\nexport function createVinylTrackFactories(deps: VinylTrackFactoryDeps) {\n return {\n src: createSourceTrackFactory(deps),\n srcObject: createSourceObjectTrackFactory(deps),\n dash: createDashTrackFactory(deps),\n hls: createHlsTrackFactory(deps),\n } as const satisfies ReadonlyRecord<\n TrackTypeId,\n TrackFactory<VinylTrackLoadOptions>\n >\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n countElements,\n createDisposer,\n type Disposable,\n EventHostImpl,\n first,\n getOrSet,\n logDebug,\n logInfo,\n LruCache,\n type Maybe,\n noop,\n type ReadonlyEventHost,\n type TimeoutId,\n} from '@amazon/vinyl-util'\nimport type { PlaybackController } from '@/playback/PlaybackController'\nimport type { ReadonlyTrack, Track, TrackUri } from '@/track/Track'\nimport type { TrackFactory, TrackLoadOptions } from '@/track/TrackFactory'\nimport type { ChangeEvent } from '@/event/ChangeEvent'\n\nexport interface TrackControllerEventMap<\n TrackLoadOptionsType extends TrackLoadOptions,\n> {\n /**\n * Emitted when the current track is changing.\n * This is emitted before the previous track has been deactivated and\n * new track has been activated.\n */\n readonly currentTrackChanging: ChangeEvent<ReadonlyTrack | null>\n\n /**\n * Emitted when the current track has changed.\n * If there is a queue change, the currentTrackChange event is always emitted first.\n * This is emitted after the previous track has been deactivated and\n * new track has been activated.\n */\n readonly currentTrackChange: ChangeEvent<ReadonlyTrack | null>\n\n /**\n * Dispatched when the queue has changed.\n */\n readonly queueChange: ChangeEvent<readonly TrackLoadOptionsType[]>\n\n /**\n * Emitted when the last track of the playback queue has ended.\n * When the last track in a queue has ended, the track will not change and therefore a `currentTrackChange`\n * event will not be emitted.\n */\n readonly queueEnded: AnyRecord\n}\n\nexport const ALL_TRACK_CONTROLLER_EVENTS = [\n 'currentTrackChanging',\n 'currentTrackChange',\n 'queueChange',\n 'queueEnded',\n] as const satisfies readonly (keyof TrackControllerEventMap<any>)[]\n\n/**\n * A readonly interface to the track controller.\n */\nexport interface ReadonlyTrackController<\n TrackLoadOptionsType extends TrackLoadOptions,\n> extends ReadonlyEventHost<TrackControllerEventMap<TrackLoadOptionsType>> {\n /**\n * Returns the current track.\n */\n readonly currentTrack: ReadonlyTrack | null\n\n /**\n * Returns the current queue of TrackLoadOptions.\n * Observe 'queueChange' for changes to this queue.\n */\n readonly queue: readonly TrackLoadOptionsType[]\n\n /**\n * Returns true if there is at least one track in the queue.\n */\n hasNext(): boolean\n\n /**\n * Returns true if the track with the given URI is cached.\n */\n isTrackCached(uri: TrackUri): boolean\n\n /**\n * Returns the cached track for the given URI, or null if the track is not cached.\n */\n getCachedTrack(uri: TrackUri): ReadonlyTrack | null\n\n /**\n * Returns an iterator of currently cached tracks.\n */\n getCachedTracks(): IterableIterator<ReadonlyTrack>\n}\n\n/**\n * Responsible for queuing track load configurations.\n * This is the authority for which is the current track.\n */\nexport interface TrackController<\n TrackLoadOptionsType extends TrackLoadOptions,\n> extends ReadonlyTrackController<TrackLoadOptionsType> {\n /**\n * Preloads the given list of tracks.\n * The tracks provided will not be enqueued.\n * The track controller's cache size will automatically increase to accommodate the request.\n *\n * Prefetch priority note:\n * Tracks have a prefetch priority, later calls to preload will have a higher precedence than previous calls.\n * Previous tracks given to `preload` will drop off when they are evicted from the cache. This is dependent on\n * cache size.\n *\n * @param loadOptionsList\n */\n preload(...loadOptionsList: readonly TrackLoadOptionsType[]): void\n\n /**\n * Sets the current queue to the provided track list.\n * When the track ends, the next will be played.\n *\n * `load` does not begin playback. Call `play()` after a load to start playback.\n * Browser autoplay policies may require the first call to `play()` to be in response to a user interaction\n * such as a click, touch, keypress, or voice event.\n *\n * Note that if the current track is the first track provided in the list, that track will be restarted.\n * To set the queue without unloading the current track, use {@link clearQueue} followed by {@link enqueue}.\n *\n * @param loadOptionsList A list of load configuration objects to set as a playback queue.\n */\n load(...loadOptionsList: readonly TrackLoadOptionsType[]): void\n\n /**\n * Unloads the active track and clears the queue.\n * This is the same as calling {@link load} with zero parameters.\n */\n unload(): void\n\n /**\n * Appends the given tracks to the current queue.\n *\n * @param loadOptionsList The track load configurations to append.\n */\n enqueue(...loadOptionsList: readonly TrackLoadOptionsType[]): void\n\n /**\n * Activates the next track in the queue.\n * If the media is not paused the next track will begin playing automatically.\n *\n * @see ReadonlyTrackController.hasNext\n */\n next(): void\n\n /**\n * Clears all fetched fragments and source buffers.\n * Playback will be interrupted, and streaming will resume again when data has been fetched and buffered.\n * This should be called if a change has been made where the user would expect an immediate change,\n * for example, changing streaming quality from SD to HD.\n *\n * Does not unload manifests.\n */\n clearPrefetch(): void\n\n /**\n * Clears the track cache and unloads the current track.\n */\n clearTrackCache(): void\n\n /**\n * Clears the current queue.\n * Does not stop the current track or affect the prefetched cache.\n */\n clearQueue(): void\n\n /**\n * Resets the current track's error state.\n */\n reset(): void\n}\n\nexport interface TrackControllerImplDeps<\n TrackLoadOptionsType extends TrackLoadOptions,\n> {\n readonly trackFactory: TrackFactory<TrackLoadOptionsType>\n\n readonly playbackController: PlaybackController\n}\n\nexport interface TrackControllerImplOptions {\n /**\n * When tracks are queued, the number of tracks to prefetch ahead of the current track.\n * Default: 2\n */\n readonly trackPrefetchCount: number\n\n /**\n * The number of seconds before load calls will time out if the first track's metadata is not loaded within\n * this time.\n * Default: 60\n */\n readonly loadTimeout: number\n\n /**\n * The number of tracks that may be preloaded at one time (not counting queue prefetch).\n * This extends the track cache capacity and allows a certain number of tracks no longer in the queue to remain\n * cached.\n *\n * Default: 2\n */\n readonly preloadCapacity: number\n}\n\nconst defaultTrackControllerImplOptions = {\n trackPrefetchCount: 2,\n loadTimeout: 60,\n preloadCapacity: 2,\n} as const satisfies TrackControllerImplOptions\n\n/**\n * Track priority will be assigned based on calls to `preload`.\n * Segment background prefetching is shared if there are multiple players instances (in the rare case there would be\n * multiple players). Having a global incrementing trackPriority prevents one player from starving another.\n */\nexport const trackPriority = {\n value: 0,\n}\n\nexport class TrackControllerImpl<TrackLoadOptionsType extends TrackLoadOptions>\n extends EventHostImpl<TrackControllerEventMap<TrackLoadOptionsType>>\n implements TrackController<TrackLoadOptionsType>, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'TrackControllerImpl'\n }\n\n // When tracks are preloaded, the cache capacity may expand automatically to accommodate.\n private _autoPreloadCapacity = 0\n private readonly trackCache = /* @__PURE__ */ new LruCache<string, Track>(0)\n private _queue: readonly TrackLoadOptionsType[] = []\n private _current: TrackLoadOptionsType | null = null\n private readonly disposer = /* @__PURE__ */ createDisposer()\n private _options: TrackControllerImplOptions =\n defaultTrackControllerImplOptions\n\n private trackEndedTimeoutId: TimeoutId | null = null\n\n constructor(\n private readonly deps: TrackControllerImplDeps<TrackLoadOptionsType>,\n initialOptions?: Partial<TrackControllerImplOptions>\n ) {\n super()\n const { add } = this.disposer\n\n this.trackCache.onEvicting = (track) => {\n // Do not evict tracks within the prefetch range.\n return (\n this.prefetched.find((value) => value.uri === track.uri) == null\n )\n }\n\n this.trackCache.onEvict = (track) => {\n logDebug(this, `Disposing track: ${track.uri}`)\n track.dispose()\n return true\n }\n\n add(\n deps.playbackController.on('ended', () => {\n this.trackEndedTimeoutId = setTimeout(() => {\n // Adds a frame delay to allow applications an opportunity to respond to 'ended' events before the\n // track is changed.\n this.trackEndedTimeoutId = null\n if (this.hasNext()) {\n this.next()\n } else {\n logInfo(this, 'queueEnded')\n this.dispatch('queueEnded', {})\n }\n })\n })\n )\n this.configure(initialOptions)\n }\n\n private clearTrackEndedTimeout() {\n if (this.trackEndedTimeoutId) {\n clearTimeout(this.trackEndedTimeoutId)\n this.trackEndedTimeoutId = null\n }\n }\n\n /**\n * Returns the currently set configuration.\n */\n get options(): TrackControllerImplOptions {\n return this._options\n }\n\n /**\n * Configures this track queue from the provided partial options.\n *\n * @param options\n */\n configure(options: Maybe<Partial<TrackControllerImplOptions>>) {\n logDebug(this, 'configure', options)\n this._options = {\n ...this._options,\n ...options,\n }\n this.checkCacheCapacity()\n }\n\n /**\n * Checks if the cache capacity needs to be changed.\n */\n private checkCacheCapacity() {\n const capacity =\n this.preloadCapacity + this._options.trackPrefetchCount + 1\n if (capacity !== this.trackCache.capacity) {\n logDebug(this, 'track cache capacity changed:', capacity)\n this.trackCache.capacity = capacity\n }\n }\n\n get queue(): readonly TrackLoadOptionsType[] {\n return this._queue\n }\n\n /**\n * Returns the subset of the queue that should be prefetched.\n * @private\n */\n private get prefetched(): readonly TrackLoadOptionsType[] {\n const tracks: TrackLoadOptionsType[] = []\n if (this._current) tracks.push(this._current)\n tracks.push(...this._queue.slice(0, this.options.trackPrefetchCount))\n return tracks\n }\n\n isTrackCached(uri: TrackUri): boolean {\n return this.trackCache.has(uri)\n }\n\n getCachedTrack(uri: TrackUri): ReadonlyTrack | null {\n return this.trackCache.get(uri) ?? null\n }\n\n getCachedTracks(): IterableIterator<ReadonlyTrack> {\n return this.trackCache.values()\n }\n\n /**\n * Returns the current preload capacity.\n * This automatically increases when preload is called with more tracks than the current capacity.\n */\n get preloadCapacity(): number {\n return Math.max(\n this._autoPreloadCapacity,\n this._options.preloadCapacity\n )\n }\n\n private validateLoadOptions = (loadOptions: TrackLoadOptionsType) =>\n this.deps.trackFactory.validate(loadOptions)\n\n preload(...loadOptionsList: readonly TrackLoadOptionsType[]): void {\n logDebug(this, `preload ${loadOptionsList.length} items`)\n loadOptionsList.forEach(this.validateLoadOptions)\n this._preload(loadOptionsList)\n }\n\n private _preload(loadOptionsList: readonly TrackLoadOptionsType[]): void {\n const prefetched = this.prefetched\n // Calculate the required preload capacity as the number of tracks requested that are not within the\n // prefetch window. If this value is greater than the current preloadCapacity, increase the cache size.\n const requiredPreloadCapacity = countElements(\n loadOptionsList,\n (loadOptions) => {\n return (\n prefetched.find((element) => {\n return element.uri === loadOptions.uri\n }) == null\n )\n }\n )\n if (this._autoPreloadCapacity < requiredPreloadCapacity) {\n this._autoPreloadCapacity = requiredPreloadCapacity\n this.checkCacheCapacity()\n }\n // Tracks requested to preload will have a priority where the first track in the list (next track) has\n // the highest precedence. (Higher priority values take precedence)\n trackPriority.value += loadOptionsList.length\n let priority = trackPriority.value\n for (const loadOptions of loadOptionsList) {\n const track = this.getOrCreateTrack(loadOptions.uri, loadOptions)\n track.preload(\n {\n prefetchPriority: priority--,\n },\n loadOptions.config ?? {}\n )\n }\n }\n\n load(...loadOptionsList: readonly TrackLoadOptionsType[]): void {\n logDebug(this, `load ${loadOptionsList.length} items`)\n loadOptionsList.forEach(this.validateLoadOptions)\n this.clearTrackEndedTimeout()\n this._current = loadOptionsList[0] ?? null\n const previousQueue = this._queue\n this._queue = loadOptionsList.slice(1)\n this._preload(this.prefetched)\n this.activateCurrent()\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n unload() {\n this.load()\n }\n\n enqueue(...loadOptionsList: readonly TrackLoadOptionsType[]): void {\n logDebug(this, `enqueue ${loadOptionsList.length} items`)\n loadOptionsList.forEach(this.validateLoadOptions)\n const previousQueue = this._queue\n this._queue = this._queue.concat(loadOptionsList)\n this._preload(this.prefetched)\n if (this.currentTrack == null && this.hasNext()) this.next()\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n hasNext(): boolean {\n return this._queue.length > 0\n }\n\n next(): void {\n this.clearTrackEndedTimeout()\n const playbackController = this.deps.playbackController\n const shouldPlay =\n playbackController.ended || !playbackController.paused\n const next = first(this._queue)\n const previousQueue = this._queue\n this._queue = this._queue.slice(1)\n this._current = next ?? null\n logDebug(this, 'next, nextTrack:', this._current)\n if (\n this.options.trackPrefetchCount > 0 &&\n this._queue.length >= this.options.trackPrefetchCount\n ) {\n this._preload([this._queue[this.options.trackPrefetchCount - 1]])\n }\n this.activateCurrent()\n if (shouldPlay) void playbackController.play().catch(noop)\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n clearTrackCache() {\n logDebug(this, 'clearTrackCache')\n this.clearTrackEndedTimeout()\n const previousQueue = this._queue\n this._queue = []\n this.trackCache.forEach((track) => {\n track.dispose()\n })\n this.trackCache.clear()\n this._autoPreloadCapacity = 0\n this.checkCacheCapacity()\n this.clearCurrentTrack()\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n clearPrefetch(): void {\n for (const cachedTrack of this.trackCache.values()) {\n cachedTrack.clearPrefetch()\n }\n }\n\n clearQueue(): void {\n this.clearTrackEndedTimeout()\n const previous = this._queue\n this._queue = []\n this.dispatch('queueChange', {\n previous,\n current: this._queue,\n })\n }\n\n /**\n * If the given track id is the current track or in the cache, returns that track.\n * Otherwise, constructs a new track, adds it to the cache, and returns it.\n *\n * @param uri The unique resource identifier.\n * @param loadOptions\n * @private\n */\n private getOrCreateTrack(\n uri: TrackUri,\n loadOptions: TrackLoadOptionsType\n ): Track {\n return getOrSet(this.trackCache, uri, () => {\n const newTrack = this.deps.trackFactory.createTrack(loadOptions)\n this.trackCache.set(uri, newTrack)\n return newTrack\n })\n }\n\n /**\n * Get the current track from cache or create a new track, then activates that track.\n */\n private activateCurrent(): void {\n const loadOptions = this._current\n if (!loadOptions) {\n this.clearCurrentTrack()\n return\n }\n this.setCurrentTrack(\n this.getOrCreateTrack(loadOptions.uri, loadOptions),\n loadOptions\n )\n }\n\n private _currentTrack: Track | null = null\n get currentTrack(): ReadonlyTrack | null {\n return this._currentTrack\n }\n\n /**\n * Sets the current track. If the given track is already current, it will be de-activated and re-activated and\n * the currentTrackChange event will still be emitted.\n * The same track may be in the queue multiple times.\n */\n private setCurrentTrack(\n value: Track | null,\n loadOptions: TrackLoadOptionsType | null\n ) {\n const previousTrack = this._currentTrack\n this.dispatch('currentTrackChanging', {\n previous: previousTrack,\n current: value,\n })\n this._currentTrack = value\n if (previousTrack?.active === true) previousTrack.deactivate()\n const loadOptionsConfig = loadOptions?.config ?? {}\n if (value?.active === false) value.activate(loadOptionsConfig)\n logDebug(\n this,\n `currentTrackChange, previous: ${previousTrack} current: ${value}`\n )\n this.dispatch('currentTrackChange', {\n previous: previousTrack,\n current: value,\n })\n }\n\n private clearCurrentTrack() {\n this.setCurrentTrack(null, null)\n }\n\n reset() {\n this._currentTrack?.reset()\n }\n\n dispose() {\n logDebug(this, 'dispose')\n super.dispose()\n this.clearTrackCache()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { lazy } from '@amazon/vinyl-util'\nimport { requiresUnreliablePlaybackEventsPatch } from './patches/createUnreliablePlaybackEventsPatch'\nimport { requiresPreventStallsPatch } from '@/patch/media/patches/createPreventStallsPatch'\n\nexport interface MediaElementPatchOptions {\n /**\n * Playback events 'playing' and 'waiting' are unreliable after seeking.\n *\n * Risks for false positive: LOW. Timing of emitted playing events may be subtly\n * different, but they will not be duplicated.\n * Risks for false negative: MEDIUM. Certain playback events on affected platforms will be missed.\n */\n readonly unreliablePlaybackEvents?: boolean\n\n /**\n * The affected user agent gets into a state where playback can become stalled and needs help getting unstuck.\n */\n readonly preventStalls?: boolean\n}\n\n/**\n * Aggregates flags for toggling patches.\n */\nexport const defaultMediaElementPatchOptions = /* @__PURE__ */ lazy<\n Required<MediaElementPatchOptions>\n>(() => {\n return {\n unreliablePlaybackEvents: requiresUnreliablePlaybackEventsPatch(),\n preventStalls: requiresPreventStallsPatch(),\n } as const satisfies Required<MediaElementPatchOptions>\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaElementPatchOptions } from '@/patch/media/MediaElementPatchOptions'\nimport { defaultMediaElementPatchOptions } from '@/patch/media/MediaElementPatchOptions'\nimport { lazy } from '@amazon/vinyl-util'\n\n/**\n * Flags for applying patches.\n * Default flags will be applied based on user agent, but may be overridden during player creation.\n */\nexport interface VinylPatchOptions {\n readonly media: MediaElementPatchOptions\n}\n\nexport const defaultPatchOptions = /* @__PURE__ */ lazy<VinylPatchOptions>(() => {\n return {\n media: defaultMediaElementPatchOptions.value,\n } as const satisfies VinylPatchOptions\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { last, merge, sortedInsertionIndex } from '@amazon/vinyl-util'\n\nimport {\n type AdaptationSetType,\n type DashManifest,\n type MPDtype,\n type PeriodType,\n type RepresentationType,\n type SegmentBaseType,\n type SegmentListType,\n type SegmentTemplateType,\n} from '@amazon/vinyl-mpd-parser'\n\n// TODO: For dynamic MPDs, availability time offsets should be summed.\n\n/**\n * Calculates the inherited SegmentList for the given representation. Or returns undefined if no SegmentList is\n * present in the hierarchy.\n */\nexport function getSegmentList(\n representation: RepresentationType\n): SegmentListType | undefined {\n return mergeIfAnyDefined(\n representation.parent.parent.SegmentList,\n representation.parent.SegmentList,\n representation.SegmentList\n )\n}\n\n/**\n * Calculates the inherited SegmentTemplate for the given representation. Or returns undefined if no SegmentTemplate is\n * present in the hierarchy.\n */\nexport function getSegmentTemplate(\n representation: RepresentationType\n): SegmentTemplateType | undefined {\n return mergeIfAnyDefined(\n representation.parent.parent.SegmentTemplate,\n representation.parent.SegmentTemplate,\n representation.SegmentTemplate\n )\n}\n\n/**\n * Calculates the inherited SegmentBase for the given representation. Or returns undefined if no SegmentBase is\n * present in the hierarchy.\n */\nexport function getSegmentBase(\n representation: RepresentationType\n): SegmentBaseType | undefined {\n return mergeIfAnyDefined(\n representation.parent.parent.SegmentBase,\n representation.parent.SegmentBase,\n representation.SegmentBase\n )\n}\n\n/**\n * Returns the representation's ancestry: [MPD, Period, AdaptationSet, Representation]\n */\nexport function getRepresentationAncestry(\n representation: RepresentationType\n): readonly [MPDtype, PeriodType, AdaptationSetType, RepresentationType] {\n const adaptationSet = representation.parent\n const period = adaptationSet.parent\n const mpd = period.parent\n return [mpd, period, adaptationSet, representation]\n}\n\n/**\n * Merges the properties of all sources into a new object.\n * Used to calculate inherited properties.\n * If all sources are undefined, returns undefined.\n */\nfunction mergeIfAnyDefined<T>(...sources: T[]): T | undefined {\n if (!sources.some((source) => source)) return undefined\n return merge(...sources)\n}\n\nexport type PeriodRange = readonly [number, number | null]\n\n/**\n * Calculates the period start and end time.\n */\nexport function calculatePeriodTimeRange(period: PeriodType): PeriodRange {\n return [calculatePeriodStart(period), calculatePeriodEnd(period)]\n}\n\n/**\n * Calculates the start time of the given period.\n *\n * In a static presentation, the first period SHALL start at the zero point of the MPD timeline (with a\n * Period@start value of 0 seconds).\n */\nexport function calculatePeriodStart(period: PeriodType): number {\n return period.start ?? 0\n}\n\n/**\n * In a static presentation, the last period SHALL have a Period@duration.\n *\n * In a dynamic presentation, the first period SHALL start at or after the zero point of the MPD timeline (with a\n * Period@start value of 0 seconds or greater).\n *\n * In a dynamic presentation, the last period MAY have a Period@duration, in which case it has a fixed duration. If\n * without Period@duration, the last period in a dynamic presentation has an unlimited duration (that may later be\n * shortened by an MPD update).\n */\nexport function calculatePeriodEnd(period: PeriodType): number | null {\n if (period.start != null && period.duration != null)\n return period.start + period.duration\n\n const mpd = period.parent\n const periodIndex = mpd.Period.indexOf(period)\n if (periodIndex < mpd.Period.length - 1)\n return calculatePeriodStart(mpd.Period[periodIndex + 1])\n else return mpd.mediaPresentationDuration ?? null\n}\n\n/**\n * Converts a sample time to an MPD-relative time.\n *\n * The samples within a representation exist on a linear sample timeline defined by the encoder. This function maps\n * those sample times onto the MPD timeline.\n *\n * https://dashif-documents.azurewebsites.net/Guidelines-TimingModel/master/Guidelines-TimingModel.html\n *\n * @param sampleTime The sample start time, in timescale units, relative to the media.\n * @param periodStart The presentation start time of the period, relative to the MPD timeline.\n * @param presentationTimeOffset Specifies a presentation time offset in the media timeline relative to the start\n * of the Period, in timescale units, used to adjust the timing of media presentation.\n * @param timescale The timescale, in units per second.\n */\nexport function sampleToMpdTime(\n sampleTime: number,\n periodStart: number,\n presentationTimeOffset: number,\n timescale: number\n): number {\n return periodStart + (sampleTime - presentationTimeOffset) / timescale\n}\n\n/**\n * Gets the period spanning the given presentation time.\n */\nexport function getPeriodAtTime(\n manifest: DashManifest,\n time: number\n): PeriodType | null {\n const index =\n sortedInsertionIndex(manifest.MPD.Period, time, (time, period) => {\n return time - calculatePeriodStart(period)\n }) - 1\n if (index < 0) return null\n const period = manifest.MPD.Period[index]\n const periodEnd = calculatePeriodEnd(period)\n return periodEnd != null && time >= periodEnd ? null : period\n}\n\n/**\n * Flattens representations across all adaptation sets for the given Period.\n */\nexport function flattenRepresentations(\n period: PeriodType\n): RepresentationType[] {\n const out: RepresentationType[] = []\n period.AdaptationSet?.forEach((adaptationSet) => {\n adaptationSet.Representation?.forEach((representation) => {\n out.push(representation)\n })\n })\n return out\n}\n\n/**\n * Calculates the manifest duration, either from the mediaPresentationDuration or the last period end time.\n * @param manifest\n */\nexport function calculateDuration(manifest: DashManifest): number | null {\n const mpdDuration = manifest.MPD.mediaPresentationDuration\n if (mpdDuration != null) return mpdDuration\n // If mediaPresentationDuration is not present, take the end time of the last period.\n return calculatePeriodEnd(last(manifest.MPD.Period)!)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { BaseURLType, RepresentationType } from '@amazon/vinyl-mpd-parser'\nimport { getRepresentationAncestry } from '@/track/dash/util/mpd'\nimport type { Uri } from '@amazon/vinyl-xml'\nimport type { Maybe } from '@amazon/vinyl-util'\nimport {\n ErrorOrigin,\n IllegalArgumentError,\n resolveUrl,\n substituteIdentifiers,\n ValidationError,\n} from '@amazon/vinyl-util'\n\n/**\n * Selects a base URL alternate.\n */\nexport interface BaseUrlSelector {\n /**\n * Given a list of Dash base URLs, chooses which one will be used.\n *\n * @param baseUrls A list of Dash base URL objects for a single scope.\n * Guaranteed to not be empty.\n */\n selectBaseUrl(baseUrls: readonly BaseURLType[]): BaseURLType\n}\n\nexport const pickFirstBaseUrlSelector: BaseUrlSelector = {\n selectBaseUrl(baseUrls: readonly BaseURLType[]): BaseURLType {\n return baseUrls[0]\n },\n}\n\nexport interface DashUriResolveDeps {\n /**\n * Selects the BaseURL from provided alternates.\n */\n readonly baseUrlSelector: BaseUrlSelector\n}\n\nexport interface ResolvedDashUri {\n /**\n * The absolute URL.\n */\n readonly url: string\n\n /**\n * The service location.\n * @see BaseURL.serviceLocation\n */\n readonly serviceLocation: string | null\n}\n\nexport interface DashUriResolveOptions {\n /**\n * The URI to resolve.\n */\n readonly uri?: Maybe<Uri>\n\n /**\n * The representation to use as the scope for BaseURL resolution.\n */\n readonly representation: RepresentationType\n\n /**\n * The resource location of the manifest.\n */\n readonly baseUrl: string\n}\n\n/**\n * Resolves the base URL. Walks down the ancestry, concatenating BaseURL paths according to\n * MPEG-DASH ISO/IEC 23009-1 standard, section 5.6.4.\n *\n * The BaseURL elements are used to define the base URL against which relative URLs specified in the manifest are\n * resolved. This can occur at multiple levels within the manifest (e.g., at the Period, Adaptation Set, or\n * Representation level).\n * Relative URLs are resolved according to standard URL resolution rules, as defined by RFC 3986. This involves\n * resolving the relative URL against the effective base URL, which could be the URL of the manifest itself or\n * a <BaseURL> specified at a higher level in the manifest hierarchy.\n *\n * Manifest URL as Base: If no <BaseURL> is specified, the URL from which the DASH manifest (MPD file) was\n * retrieved acts as the base URL for resolving any relative URLs.\n *\n * https://standards.iso.org/ittf/PubliclyAvailableStandards/index.html\n *\n * Note: URL resolution is not a simple concatenation, the `URL` class is used to resolve relative URLs per RFC\n * 3986:2005.\n *\n * @return Returns a resolved BaseURL object with calculated values according to inheritance rules.\n */\nexport function resolveDashUri(\n deps: DashUriResolveDeps,\n options: DashUriResolveOptions\n): ResolvedDashUri {\n const { representation, baseUrl, uri } = options\n const baseUrlSelector = deps.baseUrlSelector\n\n const scopeChain = getRepresentationAncestry(representation)\n\n let resolved = baseUrl\n let serviceLocation: string | null = null\n scopeChain.forEach((scope) => {\n if (scope.BaseURL && scope.BaseURL.length) {\n const selectedBaseUrl = baseUrlSelector.selectBaseUrl(scope.BaseURL)\n resolved = resolveUrl(selectedBaseUrl._content, resolved)\n if (selectedBaseUrl.serviceLocation)\n serviceLocation = selectedBaseUrl.serviceLocation\n }\n })\n if (uri != null) {\n resolved = resolveUrl(uri, resolved)\n } else if (resolved === baseUrl) {\n throw new ValidationError(\n 'media missing URI or BaseURL',\n ErrorOrigin.MEDIA\n )\n }\n return { url: resolved, serviceLocation }\n}\n\nexport interface SegmentTemplateUriOptions {\n /**\n * The sequence number of the segment. Will replace `$Number$` in url templates.\n */\n readonly segmentNumber?: Maybe<number>\n\n /**\n * The sample time of the segment. Will replace `$Time$` in url templates.\n */\n readonly sampleTime?: Maybe<number>\n\n /**\n * The representation, will use the id and bandwidth for replacement tokens.\n */\n readonly representation: RepresentationType\n}\n\n/**\n * Supported segment template tokens\n *\n * Does not currently support SubNumber.\n */\ninterface SegmentTemplateTokens {\n /**\n * This placeholder is replaced by the ID of the representation.\n */\n readonly RepresentationID: string\n\n /**\n * This placeholder is replaced by the sequence number of the segment.\n */\n readonly Number: number\n\n /**\n * This placeholder is replaced by the calculated sample time of the segment.\n */\n readonly Time: number\n\n /**\n * Replaced by the bandwidth attribute of the representation.\n */\n readonly Bandwidth: number\n}\n\n/**\n * Creates a segment url using segment template tokens, as defined in 5.3.9.4.4.\n */\nexport function segmentTemplateUrl(\n uri: Uri,\n options: SegmentTemplateUriOptions\n): Uri {\n try {\n return substituteIdentifiers(uri, {\n Bandwidth: options.representation.bandwidth,\n Number: options.segmentNumber ?? 0,\n RepresentationID: options.representation.id,\n Time: options.sampleTime ?? 0,\n } as const satisfies SegmentTemplateTokens)\n } catch (error) {\n if (error instanceof IllegalArgumentError) {\n // An IllegalArgumentError here indicates that a template URL provided was unsupported.\n throw new ValidationError(error.message, ErrorOrigin.MEDIA)\n } else {\n throw error\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { DashManifestData } from '@/track/dash/DashManifestProvider'\nimport type {\n AdaptationSetType,\n DashManifest,\n RepresentationType,\n} from '@amazon/vinyl-mpd-parser'\nimport { type Comparator, compareBy } from '@amazon/vinyl-util'\nimport {\n sortDashAdaptationSets,\n sortDashRepresentations,\n} from '@/track/dash/manifestTransformUtils'\n\nexport interface DashManifestTransformerDeps {\n readonly manifestController: ObservableValue<Promise<DashManifestData>>\n}\n\n/**\n * The default dash manifest transformer sorts adaptation sets and representations.\n * Quality filtering is handled by the media timeline transformer.\n */\nexport function createDefaultDashManifestTransformer(\n deps: DashManifestTransformerDeps\n): ObservableValue<Promise<DashManifestData>> {\n return deps.manifestController.map(async (manifestAndPath) => {\n const { manifest, baseUrl } = await manifestAndPath\n let m: DashManifest = sortDashAdaptationSets(\n createDefaultAdaptationSetComparator(),\n manifest\n )\n m = sortDashRepresentations(createDefaultRepresentationComparator(), m)\n return { baseUrl, manifest: m }\n })\n}\n\n/**\n * The default adaptation set comparator orders by descending selectionPriority.\n */\nexport function createDefaultAdaptationSetComparator(): Comparator<AdaptationSetType> {\n return compareBy((adaptationSet) => -adaptationSet.selectionPriority)\n}\n\n/**\n * The default representation comparator orders by ascending quality ranking and descending bandwidth.\n */\nexport function createDefaultRepresentationComparator(): Comparator<RepresentationType> {\n return compareBy(\n (representation) => representation.qualityRanking,\n (representation) => -representation.bandwidth\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AdaptationSetType,\n DashManifest,\n RepresentationType,\n} from '@amazon/vinyl-mpd-parser'\nimport type { DashManifestData } from '@/track/dash/DashManifestProvider'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport {\n clone,\n type Comparator,\n type FilterPredicate,\n type MaybePromise,\n} from '@amazon/vinyl-util'\n\n/**\n * Returns true if the given Dash manifest has unfiltered representations in every Period.\n */\nexport function manifestIsPlayable(manifest: DashManifest): boolean {\n return manifest.MPD.Period.every((period) =>\n period.AdaptationSet?.some(\n (adaptationSet) => adaptationSet.Representation?.length\n )\n )\n}\n\n/**\n * Filters dash representations using a synchronous predicate.\n */\nexport function filterDashRepresentations(\n filter: FilterPredicate<RepresentationType>,\n throwError: () => never,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n if (period.AdaptationSet) {\n for (const adaptationSet of period.AdaptationSet) {\n if (adaptationSet.Representation) {\n adaptationSet.Representation =\n adaptationSet.Representation.filter(filter)\n }\n }\n }\n }\n\n if (!manifestIsPlayable(result)) {\n throwError()\n }\n\n return result\n}\n\n/**\n * Filters dash adaptation sets using a synchronous predicate.\n */\nexport function filterDashAdaptationSets(\n filter: FilterPredicate<AdaptationSetType>,\n throwError: () => never,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n if (period.AdaptationSet) {\n period.AdaptationSet = period.AdaptationSet.filter(filter)\n }\n }\n\n if (!manifestIsPlayable(result)) {\n throwError()\n }\n\n return result\n}\n\n/**\n * Sorts dash adaptation sets using a comparator.\n */\nexport function sortDashAdaptationSets(\n comparator: Comparator<AdaptationSetType>,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n period.AdaptationSet?.sort(comparator)\n }\n\n return result\n}\n\n/**\n * Sorts dash representations using a comparator.\n */\nexport function sortDashRepresentations(\n comparator: Comparator<RepresentationType>,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n if (period.AdaptationSet) {\n for (const adaptationSet of period.AdaptationSet) {\n if (adaptationSet.Representation) {\n adaptationSet.Representation.sort(comparator)\n }\n }\n }\n }\n\n return result\n}\n\n/**\n * Maps a manifest transformation function over a DashManifestData observable.\n * Handles the boilerplate of extracting manifest/baseUrl and reconstructing the result.\n */\nexport function mapManifestTransform(\n manifestController: ObservableValue<Promise<DashManifestData>>,\n transformManifest: (manifest: DashManifest) => MaybePromise<DashManifest>\n): ObservableValue<Promise<DashManifestData>> {\n return manifestController.map(async (manifestAndPath) => {\n const { manifest, baseUrl } = await manifestAndPath\n return {\n baseUrl,\n manifest: await transformManifest(manifest),\n }\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n ErrorOrigin,\n type ExtractValues,\n getOrSet,\n getOrSetProp,\n memoize,\n type MutableDeep,\n sortedInsertionIndex,\n ValidationError,\n} from '@amazon/vinyl-util'\nimport {\n type AdaptationSetType,\n type ContentProtection,\n ContentProtectionScheme,\n type DescriptorType,\n type PeriodType,\n type RepresentationBaseType,\n type RepresentationType,\n} from '@amazon/vinyl-mpd-parser'\nimport type {\n ContentType,\n DrmProtection,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport { type DrmKeySystemResolver } from '@/drm/DrmKeySystemResolver'\nimport { getRepresentationMimeInfo } from '@/track/dash/util/mimeType'\nimport type { DescriptorRecord } from '@/streaming/DescriptorRecord'\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\nimport {\n type CencEncryptionScheme,\n parseCencEncryptionScheme,\n} from '@/drm/CencEncryptionScheme'\n\n/**\n * DASH supplemental property scheme URI for adaptation set switching.\n * @see https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf Section 3.8\n */\nexport const ADAPTATION_SET_SWITCHING_SCHEME =\n 'urn:mpeg:dash:adaptation-set-switching:2016'\n\n/**\n * Creates abstract MediaQualityMetadata from a Dash Representation.\n */\nexport type DashMediaQualityMetadataResolver = (\n representation: RepresentationType\n) => MediaQualityMetadata\n\n/**\n * Returns a dash metadata resolver that calculates media encoding metadata from the representation.\n * The most recently used representations will return cached results.\n */\nexport function createDefaultDashMediaQualityMetadataResolver(\n deps: DashMediaQualityMetadataResolverDeps\n): DashMediaQualityMetadataResolver {\n return memoize(\n (representation) =>\n createMediaQualityMetadataFromDashRepresentation(\n representation,\n deps\n ),\n (representation) => representation,\n 30\n )\n}\n\nexport interface DashMediaQualityMetadataResolverDeps {\n readonly drmKeySystemResolver: DrmKeySystemResolver\n}\n\nexport function createMediaQualityMetadataFromDashRepresentation(\n representation: RepresentationType,\n deps: DashMediaQualityMetadataResolverDeps\n): MediaQualityMetadata {\n const { contentType, mimeType } = getRepresentationMimeInfo(representation)\n if (!contentType || !mimeType)\n throw new ValidationError(\n 'mimeType cannot be inferred',\n ErrorOrigin.MEDIA\n )\n const adaptationSet = representation.parent\n const period = adaptationSet.parent\n const mpd = period.parent\n\n const periodId = period.id ?? `$${mpd.Period.indexOf(period)}`\n const adaptationSetId =\n adaptationSet.id ?? `$${period.AdaptationSet!.indexOf(adaptationSet)}`\n const qualityId = `${periodId}_${adaptationSetId}_${representation.id}`\n // Representations within the same adaptation set where bitstreamSwitching is true can be changed without\n // reinitializing the decoder.\n let decoderId = `${periodId}_${adaptationSetId}`\n const bitstreamSwitching =\n adaptationSet.bitstreamSwitching ?? period.bitstreamSwitching\n if (!bitstreamSwitching) decoderId += `_${representation.id}`\n\n // Resolve the adaptation set switching group. Adaptation sets that declare\n // urn:mpeg:dash:adaptation-set-switching:2016 with each other's IDs form a switching group,\n // meaning their representations are permitted to switch between each other.\n const groupId = `${periodId}_${adaptationSetId}`\n const switchingGroupIds = resolveAdaptationSetSwitchingGroupIds(\n adaptationSet,\n periodId,\n adaptationSetId\n )\n\n // Pick a representation base property which may be inherited from the adaptation set.\n function pick<K extends keyof RepresentationBaseType>(\n key: K\n ): NonNullable<RepresentationBaseType[K]> | null {\n return representation[key] ?? adaptationSet[key] ?? null\n }\n\n // Combines the descriptors for the given key into a map of scheme URI to Descriptor lists.\n type DescriptorProps = keyof ExtractValues<\n Required<RepresentationBaseType>,\n readonly DescriptorType[]\n >\n function mergeDescriptors(key: DescriptorProps): DescriptorRecord {\n const arr1 = adaptationSet[key] ?? []\n const arr2 = representation[key] ?? []\n return mapDescriptors([...arr1, ...arr2])\n }\n\n const contentProtections = [\n ...(adaptationSet.ContentProtection ?? []),\n ...(representation.ContentProtection ?? []),\n ]\n\n // Get the encryption scheme from the parsed CENC ContentProtection value.\n let initDataType: DrmInitDataType | null = null\n let encryptionScheme: CencEncryptionScheme | null = null\n for (let i = contentProtections.length - 1; i >= 0; i--) {\n const cP = contentProtections[i]\n if (cP.schemeIdUri === ContentProtectionScheme.CENC) {\n initDataType = 'cenc'\n encryptionScheme =\n parseCencEncryptionScheme(cP.value)?.scheme ?? null\n break\n }\n }\n\n return {\n qualityId,\n decoderId,\n groupId,\n switchingGroupIds,\n mimeType,\n contentType,\n codecs: pick('codecs'),\n bandwidth: representation.bandwidth,\n bandwidthTotal: estimatePeakBandwidth(representation, contentType),\n audioSamplingRate: pick('audioSamplingRate'),\n frameRate: pick('frameRate'),\n width: pick('width'),\n height: pick('height'),\n lang: adaptationSet.lang ?? null,\n contentProtections: contentProtections.flatMap((cP) =>\n contentProtectionToMetadata(cP, deps)\n ),\n encryptionScheme,\n initDataType,\n supplementalProperties: mergeDescriptors('SupplementalProperty'),\n }\n}\n\n/**\n * Estimates the total bandwidth a representation would use when paired with\n * proportionally matched qualities from sibling content types.\n *\n * For each sibling content type, the representation's relative position within its own\n * content type's sorted bandwidth list is mapped to the corresponding position in the\n * sibling's list. This produces realistic pairings \u2014 e.g. with video [v1,v2,v3,v4] and\n * audio [a1,a2], v1 pairs with a1, v2 with a1, v3 with a2, v4 with a2.\n */\nexport function estimatePeakBandwidth(\n representation: RepresentationType,\n contentType: ContentType\n): number {\n const sortedByType = getPeriodSortedBandwidths(representation.parent.parent)\n const own = sortedByType.get(contentType)\n if (!own || own.length === 0) return representation.bandwidth\n // Find the closest match in the descending-sorted array. indexOf would return -1\n // when the representation's bandwidth was collapsed by the 10% dedup threshold.\n const ownIndex = Math.max(\n 0,\n sortedInsertionIndex(own, representation.bandwidth, (a, b) => b - a) - 1\n )\n const position = own.length <= 1 ? 0 : ownIndex / (own.length - 1)\n let total = representation.bandwidth\n for (const [ct, bandwidths] of sortedByType) {\n if (ct === contentType) continue\n const peerIndex = Math.min(\n Math.round(position * (bandwidths.length - 1)),\n bandwidths.length - 1\n )\n total += bandwidths[peerIndex]\n }\n return total\n}\n\n/**\n * Returns sorted (descending) bandwidth arrays per content type for a period.\n * Bandwidths within 10% of an existing entry are collapsed to reduce noise\n * from near-duplicate quality tiers.\n * Cached by period reference.\n */\nexport const getPeriodSortedBandwidths = /* @__PURE__ */ memoize(\n (period: PeriodType): ReadonlyMap<ContentType, readonly number[]> => {\n const byType = new Map<ContentType, number[]>()\n for (const as of period.AdaptationSet ?? []) {\n for (const rep of as.Representation ?? []) {\n const contentType = getRepresentationMimeInfo(rep).contentType\n if (!contentType) continue\n const arr = getOrSet(byType, contentType, () => [])\n if (\n !arr.some(\n (existing) =>\n Math.abs(existing - rep.bandwidth) / existing < 0.1\n )\n ) {\n const index = sortedInsertionIndex(\n arr,\n rep.bandwidth,\n (a, b) => b - a\n )\n arr.splice(index, 0, rep.bandwidth)\n }\n }\n }\n return byType\n },\n (period) => period,\n 5\n)\n\n/**\n * Converts a Dash ContentProtection element to a list of DrmProtection metadata.\n */\nexport function contentProtectionToMetadata(\n contentProtection: ContentProtection,\n deps: DashMediaQualityMetadataResolverDeps\n): readonly DrmProtection[] {\n const keySystems = deps.drmKeySystemResolver(contentProtection.schemeIdUri)\n return keySystems.map((keySystem) => {\n return {\n keySystem,\n pssh: contentProtection.pssh?._content ?? null,\n pro: contentProtection.pro?._content ?? null,\n }\n })\n}\n\n/**\n * Creates a DescriptorRecord from the Dash list of DescriptorType objects.\n * @param descriptors\n */\nfunction mapDescriptors(\n descriptors: readonly DescriptorType[]\n): DescriptorRecord {\n const out: MutableDeep<DescriptorRecord> = {}\n for (const descriptor of descriptors) {\n const arr = getOrSetProp(out, descriptor.schemeIdUri, () => [])!\n arr.push({\n id: descriptor.id ?? null,\n value: descriptor.value ?? null,\n })\n }\n return out\n}\n\n/**\n * Resolves the group IDs that the given adaptation set is permitted to switch to.\n *\n * Per DASH spec, adaptation sets declare `urn:mpeg:dash:adaptation-set-switching:2016` with a\n * comma-separated list of other adaptation set IDs they can switch to.\n *\n * Always includes the adaptation set's own groupId. If no switching property is present,\n * returns only the adaptation set's own groupId.\n */\nfunction resolveAdaptationSetSwitchingGroupIds(\n adaptationSet: AdaptationSetType,\n periodId: string,\n adaptationSetId: string | number\n): readonly string[] | null {\n const selfGroupId = `${periodId}_${adaptationSetId}`\n const switchingProp = adaptationSet.SupplementalProperty?.find(\n (p) => p.schemeIdUri === ADAPTATION_SET_SWITCHING_SCHEME\n )\n if (!switchingProp) return [selfGroupId]\n\n const value = switchingProp.value?.trim()\n if (!value) return [selfGroupId]\n\n const targetIds = value.split(',').map((s) => s.trim())\n return [selfGroupId, ...targetIds.map((id) => `${periodId}_${id}`)]\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\n\n/**\n * RFC 6381 codec prefixes for video content.\n */\nconst VIDEO_CODEC_PREFIXES = [\n 'avc1',\n 'avc3',\n 'hvc1',\n 'hev1',\n 'vp09',\n 'av01',\n 'dvh1',\n 'dvhe',\n] as const\n\n/**\n * RFC 6381 codec prefixes for audio content.\n */\nconst AUDIO_CODEC_PREFIXES = ['mp4a', 'ac-3', 'ec-3', 'opus', 'flac'] as const\n\n/**\n * RFC 6381 codec prefixes for text/subtitle content.\n */\nconst TEXT_CODEC_PREFIXES = ['stpp', 'wvtt'] as const\n\n/**\n * Returns the ContentType for a single RFC 6381 codec string, or null if\n * unrecognized.\n */\nexport function codecToContentType(codec: string): ContentType | null {\n const lower = codec.trim().toLowerCase()\n for (const p of VIDEO_CODEC_PREFIXES) {\n if (lower.startsWith(p)) return 'video'\n }\n for (const p of AUDIO_CODEC_PREFIXES) {\n if (lower.startsWith(p)) return 'audio'\n }\n for (const p of TEXT_CODEC_PREFIXES) {\n if (lower.startsWith(p)) return 'text'\n }\n return null\n}\n\n/**\n * Splits a comma-separated CODECS attribute value and returns the set of\n * ContentType values present.\n */\nexport function codecsToContentTypes(codecs: string): Set<ContentType> {\n const types = new Set<ContentType>()\n for (const codec of codecs.split(',')) {\n const type = codecToContentType(codec)\n if (type) types.add(type)\n }\n return types\n}\n\n/**\n * Returns the full MIME type string for a content type, optionally with codecs.\n */\nexport function contentTypeToMimeType(\n contentType: ContentType,\n codecs: string | null\n): string {\n const base = contentType === 'video' ? 'video/mp4' : 'audio/mp4'\n return codecs ? `${base}; codecs=\"${codecs}\"` : base\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { RepresentationType } from '@amazon/vinyl-mpd-parser'\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\nimport { codecToContentType } from '@/track/mse/codec'\n\nexport interface RepresentationMimeInfo {\n readonly mimeType: string | null\n readonly contentType: ContentType | null\n}\n\n/**\n * Returns the full mime type with codecs and the inferred content type from the\n * provided representation.\n */\nexport function getRepresentationMimeInfo(\n representation: RepresentationType\n): RepresentationMimeInfo {\n const adaptationSet = representation.parent\n let mimeType = representation.mimeType ?? adaptationSet.mimeType\n const codecs = representation.codecs ?? adaptationSet.codecs\n if (!mimeType) {\n const contentType =\n (adaptationSet.contentType as ContentType | undefined) ??\n (codecs ? codecToContentType(codecs.split(',')[0]) : null)\n switch (contentType) {\n case 'audio':\n mimeType = 'audio/mp4'\n break\n case 'video':\n mimeType = 'video/mp4'\n break\n default:\n return { mimeType: null, contentType: null }\n }\n const fullMimeType = codecs\n ? `${mimeType}; codecs=\"${codecs}\"`\n : mimeType\n return { mimeType: fullMimeType, contentType }\n }\n const fullMimeType = codecs ? `${mimeType}; codecs=\"${codecs}\"` : mimeType\n let contentType: ContentType | null =\n (adaptationSet.contentType as ContentType | undefined) ?? null\n if (!contentType) {\n if (mimeType.startsWith('audio/')) contentType = 'audio'\n else if (mimeType.startsWith('video/')) contentType = 'video'\n else if (\n mimeType.startsWith('text/') ||\n mimeType === 'application/json' ||\n mimeType === 'application/xml'\n )\n contentType = 'text'\n }\n return { mimeType: fullMimeType, contentType }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type Maybe,\n parseIntSafe,\n type ReadonlyRecord,\n} from '@amazon/vinyl-util'\n\n/**\n * https://www.w3.org/TR/encrypted-media-2/#dom-mediakeysystemmediacapability-encryptionscheme\n */\nexport type CencEncryptionScheme =\n /**\n * AES-CTR mode full sample and video NAL subsample encryption.\n */\n | 'cenc'\n\n /**\n * AES-CBC mode partial video NAL pattern encryption. For video, the spec allows various encryption patterns.\n */\n | 'cbcs'\n\n /**\n * The same as \"cbcs\" mode, but with a specific encrypt:skip pattern of 1:9 for video.\n */\n | 'cbcs-1-9'\n | string\n\nexport interface CencEncryptionSchemeAndVersion {\n readonly scheme: CencEncryptionScheme\n readonly version: number | null\n}\n\nconst encryptionSchemeRegex = /([a-z]{4})(?::([\\da-f]{1,8}))?/\n\nconst protectionSchemeCodes: ReadonlyRecord<\n string,\n CencEncryptionScheme | undefined\n> = {\n ['cbcs']: 'cbcs',\n ['cenc']: 'cenc',\n}\n\n/**\n * 5.8.5.2.2 The MP4 Protection Scheme\n *\n * For Representations based on ISO/IEC 14496-12, the following URI is defined to indicate protection\n * schemes identified by the Scheme Type within the Scheme Type Box of the Protection Scheme\n * Information Box of the file:\n * urn:mpeg:dash:mp4protection:2011\n * In this scheme, the `value` attribute shall present and shall be the 4CC contained in the Scheme Type\n * Box, suitably percent-encoded according to IETF RFC 8141, and may include the version number. The\n * 4CC and the version number, if present, shall be separated by a \":\". The version number shall be encoded\n * as up to 8 hexadecimal digits, where the leading '0's may be omitted.\n *\n * @param value\n */\nexport function parseCencEncryptionScheme(\n value: Maybe<string>\n): CencEncryptionSchemeAndVersion | null {\n if (!value) return null\n const match = encryptionSchemeRegex.exec(value)\n if (!match) return null\n const version = parseIntSafe(match[2], 16)\n const scheme = protectionSchemeCodes[match[1]]\n if (!scheme) return null\n return {\n scheme,\n version,\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n createDisposer,\n type Disposable,\n DomEventHost,\n ErrorLevel,\n ErrorOrigin,\n EventHostImpl,\n type Json,\n logDebug,\n type LogTarget,\n type ReadonlyEventHost,\n type ReadonlySet,\n ReportableError,\n toJson,\n toLowerCase,\n} from '@amazon/vinyl-util'\nimport type { ContentTypesValue } from '@/streaming/ContentTypesValue'\nimport type { BasicErrorEvent } from '@/event/BasicErrorEvent'\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\n\nexport interface SourceBufferRef extends Disposable {\n /**\n * The source buffer.\n */\n readonly value: SourceBuffer\n}\n\nexport interface MediaSourceControllerEventMap {\n /**\n * The media source has entered a 'closed' state.\n */\n readonly sourceClose: AnyRecord\n\n /**\n * The media source has entered an 'ended' state.\n */\n readonly sourceEnded: AnyRecord\n\n /**\n * The media source has entered an 'open' state.\n */\n readonly sourceOpen: AnyRecord\n\n /**\n * All source buffers have been created and data may be appended.\n */\n readonly readyToAppend: AnyRecord\n\n /**\n * An error has occurred.\n */\n readonly error: BasicErrorEvent\n}\n\nexport interface ReadonlyMediaSourceController extends ReadonlyEventHost<MediaSourceControllerEventMap> {\n /**\n * Returns the parent media source ready state.\n */\n readonly readyState: ReadyState\n\n /**\n * Gets the media source's duration.\n */\n readonly duration: number\n\n /**\n * True if all source buffers have been created and data may be appended.\n */\n readonly readyToAppend: boolean\n}\n\nexport interface MediaSourceController extends ReadonlyMediaSourceController {\n /**\n * Sets/gets the media source's duration.\n */\n duration: number\n\n /**\n * Constructs a new SourceBuffer with the given content type and mime type.\n */\n createSourceBuffer(\n contentType: ContentType,\n mimeType: string\n ): SourceBufferRef\n\n /**\n * Signals the end of the stream.\n * @param error A string representing an error to throw when the end of the stream is reached.\n */\n endOfStream(error?: EndOfStreamError): void\n\n /**\n * Creates an Object URL to use as the source for this stream.\n */\n createUrl(): string\n}\n\nexport interface MediaSourceControllerImplDeps {\n /**\n * Creates a new media source.\n */\n readonly mediaSourceFactory: () => MediaSource\n\n /**\n * Provides the streams that must be created before appending.\n */\n readonly contentTypesValue: ContentTypesValue\n}\n\nexport class MediaSourceControllerImpl\n extends EventHostImpl<MediaSourceControllerEventMap>\n implements MediaSourceController, LogTarget\n{\n get [Symbol.toStringTag](): string {\n return 'MediaSourceControllerImpl'\n }\n\n private sourceBufferCount = 0\n\n private readonly mediaSource: MediaSource\n private readonly disposer = /* @__PURE__ */ createDisposer()\n private contentTypes: ReadonlySet<ContentType> | null = null\n\n constructor(deps: MediaSourceControllerImplDeps) {\n super()\n this.mediaSource = deps.mediaSourceFactory()\n this.initializeEvents()\n this.disposer.add(\n deps.contentTypesValue.onData((value) => {\n this.contentTypes = null\n value\n .then((contentTypes) => {\n this.contentTypes = contentTypes\n this.checkReady()\n })\n .catch((error) => {\n this.dispatch('error', {\n target: this,\n error: error,\n })\n })\n })\n )\n }\n\n private initializeEvents(): void {\n const domEvents = new DomEventHost<MediaSourceEventMap>(\n this.mediaSource\n )\n // Re-dispatch html media element events exposed on the playback controller as empty events.\n for (const key of [\n 'sourceClose',\n 'sourceOpen',\n 'sourceEnded',\n ] as const) {\n domEvents.on(toLowerCase(key), () => this.dispatch(key, {}))\n }\n }\n\n get duration(): number {\n return this.mediaSource.duration\n }\n\n set duration(value: number) {\n this.mediaSource.duration = value\n }\n\n get readyState(): ReadyState {\n return this.mediaSource.readyState\n }\n\n createSourceBuffer(\n contentType: ContentType,\n mimeType: string\n ): SourceBufferRef {\n const mediaSource = this.mediaSource\n logDebug(\n this,\n 'create source buffer',\n contentType,\n mimeType,\n mediaSource.readyState,\n 'sourceBufferCount:',\n this.sourceBufferCount\n )\n let sourceBuffer: SourceBuffer\n try {\n sourceBuffer = mediaSource.addSourceBuffer(mimeType)\n } catch (error: any) {\n throw new MediaSourceError('error creating source buffer', error)\n }\n sourceBuffer.mode = 'sequence'\n ++this.sourceBufferCount\n this.checkReady()\n\n const dispose = () => {\n logDebug(\n this,\n 'removing source buffer from media source',\n mediaSource.readyState\n )\n if (mediaSource.readyState !== 'closed') {\n mediaSource.removeSourceBuffer(sourceBuffer)\n }\n --this.sourceBufferCount\n }\n\n return {\n value: sourceBuffer,\n dispose,\n }\n }\n\n /**\n * Emits a 'readyToAppend' event if all source buffers have been created.\n */\n private readonly checkReady = () => {\n if (this.readyToAppend) this.dispatch('readyToAppend', {})\n }\n\n endOfStream(error?: EndOfStreamError) {\n logDebug(this, 'endOfStream, error:', error)\n this.mediaSource.endOfStream(error)\n }\n\n createUrl(): string {\n return URL.createObjectURL(this.mediaSource)\n }\n\n get readyToAppend(): boolean {\n return this.contentTypes?.size === this.sourceBufferCount\n }\n\n dispose() {\n super.dispose()\n this.disposer.dispose()\n }\n}\n\nexport class MediaSourceError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'MediaSourceError'\n }\n\n constructor(\n message: string,\n private readonly reason: Error\n ) {\n super(message, ErrorOrigin.INTERNAL, ErrorLevel.FATAL)\n Object.setPrototypeOf(this, MediaSourceError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n reason: toJson(this.reason),\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { data } from '@amazon/vinyl-observable'\nimport { createAbortSlot, createDisposer, logDebug } from '@amazon/vinyl-util'\nimport type {\n DashManifestData,\n DashManifestProvider,\n} from '@/track/dash/DashManifestProvider'\nimport type { ManifestController } from '@/streaming/ManifestController'\n\nexport type DashManifestController = ManifestController<\n Promise<DashManifestData>\n>\n\nexport interface DashManifestControllerImplDeps {\n /**\n * Resolves the untransformed manifest.\n */\n readonly manifestProvider: DashManifestProvider\n}\n\nexport class DashManifestControllerImpl implements DashManifestController {\n get [Symbol.toStringTag](): string {\n return 'DashManifestControllerImpl'\n }\n\n get logPrefix(): string {\n return 'DashManifestControllerImpl'\n }\n\n private readonly _data = /* @__PURE__ */ data<Promise<DashManifestData>>(\n /* @__PURE__ */ Promise.reject(/* @__PURE__ */ new Error('manifest not loaded'))\n )\n private _error: Error | null = null\n private readonly abortSlot = /* @__PURE__ */ createAbortSlot()\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n constructor(readonly deps: DashManifestControllerImplDeps) {\n // Suppress unhandled rejection on the initial placeholder.\n this._data.value.catch(() => {})\n this.refresh()\n }\n\n /**\n * The most recent error from the manifest provider, or null.\n * This may be a silent error, such as an AbortError.\n */\n get error(): Error | null {\n return this._error\n }\n\n /**\n * Reloads the manifest. Aborts any in-flight request and clears any\n * previous error before starting a new fetch.\n */\n refresh() {\n logDebug(this, 'refresh')\n this.abort()\n this._error = null\n const promise = this.deps.manifestProvider(this.abortSlot.value)\n promise.catch((error: Error) => {\n this._error = error\n })\n this._data.value = promise\n }\n\n /**\n * If the manifest is in an error state, triggers a refresh.\n */\n reset() {\n logDebug(this, 'reset')\n if (this._error) {\n this.refresh()\n }\n }\n\n get value() {\n return this._data.value\n }\n\n get changeId() {\n return this._data.changeId\n }\n\n getValue() {\n return this._data.getValue()\n }\n\n onData(\n callback: (\n value: Promise<DashManifestData>,\n previous: Promise<DashManifestData> | undefined\n ) => void\n ) {\n return this._data.onData(callback)\n }\n\n map<U>(transform: (value: Promise<DashManifestData>) => U) {\n return this._data.map(transform)\n }\n\n pick<K extends keyof NonNullable<Promise<DashManifestData>>>(prop: K) {\n return this._data.pick(prop)\n }\n\n private abort() {\n this.abortSlot.abort()\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.abort()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createLogPrefix,\n createTaskQueue,\n createTimeRangesReader,\n type Disposable,\n emptyRanges,\n ErrorOrigin,\n IllegalStateError,\n logDebug,\n type LogTarget,\n nextEventAsPromise,\n type ReadonlyRanges,\n type Task,\n} from '@amazon/vinyl-util'\nimport { nextSourceBufferIdle } from '@/util/media/sourceBuffer'\nimport { SourceBufferError } from './error/SourceBufferError'\nimport type {\n MediaSourceController,\n SourceBufferRef,\n} from './MediaSourceController'\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\n\n// Prevents unintentionally dropped keyframes\nexport const APPEND_WINDOW_START_OFFSET = 0.05\nexport const APPEND_WINDOW_END_OFFSET = 0.01\n\n// The number of seconds before aborting the wait for media source controller's readyToAppend event.\nexport const READY_TO_APPEND_TIMEOUT = 30\n\nexport type SourceBufferControllerFactory = () => SourceBufferController\n\nexport interface SourceBufferController extends Disposable {\n readonly buffered: ReadonlyRanges\n\n /**\n * Returns true if an operation is currently running.\n */\n isBusy(): boolean\n\n /**\n * Enqueues an operation.\n * Guaranteed to be invoked when the source buffer is not updating.\n */\n enqueue<T = void>(task: Task<T>): Promise<T>\n\n /**\n * Enqueues appending an initialization segment, reinitializing the decoder.\n */\n appendInit(data: ArrayBuffer, mimeType: string): Promise<void>\n\n /**\n * Enqueues appending a media segment.\n * An `appendInit` call must precede appending media segments.\n * A promise is returned that will resolve when the task is complete.\n */\n append(data: ArrayBuffer): Promise<void>\n\n /**\n * Sets the timestampOffset on the backing source buffer.\n */\n setTimestampOffset(timestampOffset: number): Promise<void>\n\n /**\n * Sets the append window on the backing source buffer.\n * Keyframes outside this range will be discarded.\n */\n setAppendWindow(\n appendWindowStart?: number,\n appendWindowEnd?: number\n ): Promise<void>\n\n /**\n * Removes media segments within a specific time range from the SourceBuffer.\n */\n remove(startTime: number, endTime: number): Promise<void>\n\n /**\n * Aborts any pending buffers and clears all buffered ranges.\n */\n clear(): Promise<void>\n}\n\nexport interface SourceBufferControllerImplDeps {\n /**\n * Produces the source buffer for appending.\n */\n readonly mediaSourceController: MediaSourceController\n}\n\n/**\n * The SourceBufferController manages a single source buffer. It provides queued commands for appending and clearing\n * data.\n */\nexport class SourceBufferControllerImpl\n implements LogTarget, SourceBufferController, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'SourceBufferController'\n }\n\n private sourceBufferRef: SourceBufferRef | null = null\n\n private mimeType: string | null = null\n private queue = /* @__PURE__ */ createTaskQueue()\n\n readonly logPrefix = /* @__PURE__ */ createLogPrefix(this)\n private readonly mediaSourceController: MediaSourceController\n\n constructor(\n deps: SourceBufferControllerImplDeps,\n readonly contentType: ContentType\n ) {\n logDebug(this, 'constructed, contentType:', contentType)\n this.mediaSourceController = deps.mediaSourceController\n }\n\n private get sourceBuffer(): SourceBuffer | null {\n return this.sourceBufferRef && this.sourceBufferRef.value\n }\n\n private _buffered: ReadonlyRanges | null = null\n get buffered(): ReadonlyRanges {\n if (this._buffered == null) {\n if (!this.sourceBuffer) this._buffered = emptyRanges\n else\n this._buffered = createTimeRangesReader(\n this.sourceBuffer.buffered\n )\n }\n return this._buffered\n }\n\n /**\n * Clears the cached buffered ranges. They will be recreated next access.\n */\n private clearBufferedCache = () => {\n this._buffered = null\n }\n\n isBusy(): boolean {\n return this.queue.running > 0\n }\n\n enqueue<T = void>(task: Task<T>): Promise<T> {\n return this.queue.enqueue(task)\n }\n\n async appendInit(data: ArrayBuffer, mimeType: string): Promise<void> {\n return this.queue.enqueue(async (abort) => {\n if (this.mimeType !== mimeType) {\n if (this.sourceBuffer && 'changeType' in this.sourceBuffer) {\n // There is an existing source buffer and its mime type can be changed.\n logDebug(this, 'changeType', mimeType)\n this.sourceBuffer.changeType(mimeType)\n } else {\n // There is either no existing source buffer or a new buffer must be created\n // with the new mime type.\n this.sourceBufferRef?.dispose()\n const newSourceBufferRef =\n this.mediaSourceController.createSourceBuffer(\n this.contentType,\n mimeType\n )\n // Do not append to the source buffer until all streams have been created:\n if (!this.mediaSourceController.readyToAppend)\n await nextEventAsPromise(\n this.mediaSourceController,\n 'readyToAppend',\n { timeout: READY_TO_APPEND_TIMEOUT, abort }\n ).catch((error) => {\n // The readyToAppend was aborted or timed out, dispose the source buffer\n newSourceBufferRef.dispose()\n throw error\n })\n this.sourceBufferRef = newSourceBufferRef\n }\n this.mimeType = mimeType\n }\n const sourceBuffer = this.sourceBuffer!\n logDebug(this, `appending init ${data.byteLength} bytes`)\n sourceBuffer.appendBuffer(data)\n await this.nextIdle()\n logDebug(this, 'appended init')\n })\n }\n\n async append(data: ArrayBuffer): Promise<void> {\n return this.queue.enqueue(async () => {\n logDebug(this, `appending ${data.byteLength} bytes`)\n const sourceBuffer = this.sourceBuffer\n if (!sourceBuffer)\n throw new SourceBufferError(\n 'media segment provided before init segment',\n ErrorOrigin.INTERNAL\n )\n sourceBuffer.appendBuffer(data)\n await this.nextIdle()\n logDebug(this, 'appended', this.buffered)\n })\n }\n\n setTimestampOffset(timestampOffset: number): Promise<void> {\n return this.queue.enqueue(() => {\n const sourceBuffer = this.sourceBuffer\n if (!sourceBuffer)\n throw new IllegalStateError(\n 'source buffer must be initialized before setting timestamp offset'\n )\n logDebug(this, 'timestampOffset:', timestampOffset.toFixed(4))\n sourceBuffer.timestampOffset = timestampOffset\n })\n }\n\n setAppendWindow(\n appendWindowStart: number = 0,\n appendWindowEnd: number = Number.POSITIVE_INFINITY\n ): Promise<void> {\n return this.queue.enqueue(() => {\n const sourceBuffer = this.sourceBuffer\n if (!sourceBuffer)\n throw new IllegalStateError(\n 'source buffer must be initialized before setting append window'\n )\n const finalAppendWindowStart = Math.max(\n 0,\n appendWindowStart - APPEND_WINDOW_START_OFFSET\n )\n const finalAppendWindowEnd =\n appendWindowEnd + APPEND_WINDOW_END_OFFSET\n logDebug(\n this,\n 'appendWindow:',\n finalAppendWindowStart.toFixed(4),\n finalAppendWindowEnd.toFixed(4)\n )\n\n // start may not be greater than end, even temporarily.\n // Avoids the error: \"Failed to set the 'appendWindow___' property\"\n sourceBuffer.appendWindowStart = 0\n sourceBuffer.appendWindowEnd = finalAppendWindowEnd\n sourceBuffer.appendWindowStart = finalAppendWindowStart\n })\n }\n\n remove(startTime: number, endTime: number): Promise<void> {\n return this.queue.enqueue(async () => {\n if (endTime > startTime) {\n logDebug(this, `removing range: ${startTime}-${endTime}`)\n this.sourceBuffer?.remove(startTime, endTime)\n await this.nextIdle()\n logDebug(this, 'removed, new buffered:', this.buffered)\n }\n })\n }\n\n /**\n * Returns a promise that resolves when the source buffer is no longer updating.\n * @private\n */\n private nextIdle = (): Promise<void> =>\n nextSourceBufferIdle(this.sourceBuffer).finally(this.clearBufferedCache)\n\n async clear(): Promise<void> {\n await this.remove(0, Number.POSITIVE_INFINITY)\n }\n\n /**\n * Aborts any pending operations and disposes the backed SourceBuffer.\n */\n dispose() {\n logDebug(this, 'dispose')\n this.queue.abort()\n this.sourceBufferRef?.dispose()\n this.sourceBufferRef = null\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { promise } from '@amazon/vinyl-util'\nimport type { Maybe } from '@amazon/vinyl-util'\nimport { SourceBufferError } from '@/streaming/buffering/error/SourceBufferError'\nimport { AbortError } from '@amazon/vinyl-util'\n\n/**\n * Returns a promise that resolves when the given source buffer is next idle.\n * If the source buffer errs, the promise will be rejected with a {@link SourceBufferError}.\n *\n * @param sourceBuffer\n */\nexport function nextSourceBufferIdle(\n sourceBuffer: Maybe<SourceBuffer>\n): Promise<void> {\n if (!sourceBuffer) return Promise.resolve()\n if (!sourceBuffer.updating) return Promise.resolve()\n return promise((resolve, reject) => {\n const removeListeners = () => {\n sourceBuffer.removeEventListener('error', onErred)\n sourceBuffer.removeEventListener('abort', onAborted)\n sourceBuffer.removeEventListener('update', onEnded)\n }\n const onEnded = () => {\n removeListeners()\n resolve()\n }\n const onErred = (_event: any) => {\n removeListeners()\n reject(new SourceBufferError())\n }\n const onAborted = () => {\n removeListeners()\n reject(new AbortError())\n }\n sourceBuffer.addEventListener('error', onErred)\n sourceBuffer.addEventListener('abort', onAborted)\n sourceBuffer.addEventListener('update', onEnded)\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport { ReportableError } from '@amazon/vinyl-util'\n\n/**\n * An error emitted from the SourceBuffer.\n */\nexport class SourceBufferError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'SourceBufferError'\n }\n\n constructor(\n message = `A SourceBuffer error has occurred.`,\n origin = ErrorOrigin.MEDIA\n ) {\n super(message, origin)\n Object.setPrototypeOf(this, SourceBufferError.prototype)\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n type Clearable,\n createAbortSlot,\n createDisposer,\n createTaskQueue,\n type Disposable,\n type Disposer,\n EventHostImpl,\n getLogLevel,\n isSilentError,\n LinkedList,\n logDebug,\n LogLevel,\n logVerbose,\n logWarn,\n type ReadonlyEventHost,\n throttle,\n} from '@amazon/vinyl-util'\nimport type { ReadonlyPlaybackController } from '@/playback/ReadonlyPlaybackController'\nimport type { SourceBufferController } from './SourceBufferController'\nimport type { ReadonlySegmentController } from '@/streaming/SegmentController'\nimport type { SegmentReference } from '@/streaming/SegmentReference'\nimport { LIVE_DURATION } from '@/playback/PlaybackController'\nimport type { BasicErrorEvent } from '@/event/BasicErrorEvent'\nimport type { ChangeEvent } from '@/event/ChangeEvent'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport { type MediaSourceController } from '@/streaming/buffering/MediaSourceController'\nimport { SEGMENT_START_AFFORDANCE } from '@/streaming/SegmentController'\n\n/**\n * Chrome 52 has decoding errors when duration is set to the mediaPresentationDuration.\n * Adds a slight padding as a workaround.\n * @private\n */\nexport const DURATION_PADDING = 0.1\n\n/**\n * The interval to throttle polling the buffer.\n * Reset after a seek.\n * @private\n */\nexport const POLL_BUFFER_THROTTLE = 0.1\n\n/**\n * If segments are too large to append, reduces the max append size.\n */\nexport const QUOTA_REACHED_SCALE = 0.8\n\n/**\n * If quota exceeded errors are hit, the max append size will not be reduced below this value and the buffering\n * controller will be set to an erred state.\n */\nexport const MIN_APPEND_SIZE = 524288 // 512 * 1024\n\n/**\n * If the content type does not match a config setting.\n */\nexport const DEFAULT_MAX_APPEND_SIZE = 10485760 // 10 * 1024 * 1024\n\nexport interface BufferingControllerEventMap {\n /**\n * Dispatched when an error of severity warning or fatal occurred while buffering.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Dispatched when the currently playing media encoding has changed.\n */\n readonly playbackQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * Dispatched when the currently buffering quality changes.\n * This is dispatched before the segment is appended.\n */\n readonly bufferingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * The last segment has finished appending.\n */\n readonly bufferingEnded: AnyRecord\n}\n\nexport interface BufferingController\n extends\n ReadonlyEventHost<BufferingControllerEventMap>,\n Clearable,\n Disposable {\n /**\n * The last error emitted.\n * Buffering will halt if this controller is in an error state.\n * Deactivating this controller will reset the error state.\n */\n readonly error: Error | null\n\n /**\n * The currently buffering media quality.\n * This is set immediately before a segment of a new quality is appended.\n *\n * Listen to {@link BufferingControllerEventMap.bufferingQualityChange} events for changes.\n */\n readonly bufferingQuality: MediaQualityMetadata | null\n\n /**\n * The currently playing media quality.\n *\n * Listen to {@link BufferingControllerEventMap.playbackQualityChange} events for changes.\n */\n readonly playbackQuality: MediaQualityMetadata | null\n\n /**\n * True if this buffering controller is active.\n */\n readonly active: boolean\n\n /**\n * True if the stream has buffered the last segment.\n */\n readonly bufferingEnded: boolean\n\n /**\n * Begins buffering.\n */\n activate(): void\n\n /**\n * Stops buffering.\n */\n deactivate(): void\n\n /**\n * If this controller is in an error state, resets and tries again.\n */\n reset(): void\n}\n\n/**\n * The measured source buffer quotas.\n */\nconst sourceBufferQuotas = /* @__PURE__ */ new Map<string, number>()\n\n/**\n * Clears the current estimated source buffer quota.\n * @private\n */\nexport function clearSourceBufferQuota() {\n sourceBufferQuotas.clear()\n}\n\n/**\n * Returns the measured source buffer quota for the given content type.\n * Will return null if the quota was never reached.\n *\n * @param contentType\n */\nexport function getSourceBufferQuota(contentType: ContentType): number | null {\n return sourceBufferQuotas.get(contentType) ?? null\n}\n\nexport interface BufferingControllerImplDeps {\n readonly mediaSourceController: MediaSourceController\n readonly segmentController: ReadonlySegmentController\n readonly playbackController: ReadonlyPlaybackController\n readonly sourceBufferControllerFactory: () => SourceBufferController\n}\nexport interface BufferingControllerImplOptions {\n /**\n * When the buffer falls below this time threshold, the next segment will be requested from the\n * segment controller and appended.\n * Default: 4s\n */\n readonly minBuffer: number\n\n /**\n * The maximum number of bytes to append at a time per content type.\n * Default: { audio: 1MiB, video: 15MiB }\n */\n readonly maxAppendSize: Partial<Record<ContentType, number>>\n}\n\nconst defaultBufferingControllerOptions = {\n minBuffer: 4.0,\n maxAppendSize: {\n audio: 10485760, // 10 * 1024 * 1024\n video: 157286400, // 150 * 1024 * 1024\n },\n} as const satisfies BufferingControllerImplOptions\n\n/**\n * The buffering controller is responsible for requesting and appending segments to the source\n * buffer controller.\n */\nexport class BufferingControllerImpl\n extends EventHostImpl<BufferingControllerEventMap>\n implements BufferingController, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'BufferingControllerImpl'\n }\n\n readonly options: BufferingControllerImplOptions\n private readonly mediaSourceController: MediaSourceController\n private readonly playbackController: ReadonlyPlaybackController\n private readonly segmentController: ReadonlySegmentController\n\n private sourceBufferController: SourceBufferController | null = null\n private decoderId: string | null = null\n\n /**\n * The currently buffered segments.\n */\n private buffered = /* @__PURE__ */ new LinkedList<SegmentReference<ArrayBuffer>>()\n private appendOffset = 0\n\n /**\n * The currently buffering quality.\n */\n private _bufferingQuality: MediaQualityMetadata | null = null\n\n /**\n * If true and in a bufferingEnded state, the segment provider will be queried again.\n * This will be set to true after the segment controller reports a change event, indicating that there may be new\n * segments to append.\n */\n private reopen = false\n private _error: Error | null = null\n private _bufferingEnded = false\n\n private readonly queue = /* @__PURE__ */ createTaskQueue()\n\n private disposer = /* @__PURE__ */ createDisposer()\n private _active = false\n private activateDisposer: Disposer | null = null\n\n private readonly segmentAbort = /* @__PURE__ */ createAbortSlot()\n\n constructor(\n readonly deps: BufferingControllerImplDeps,\n readonly contentType: ContentType,\n options?: Partial<BufferingControllerImplOptions>\n ) {\n super()\n this.options = {\n ...defaultBufferingControllerOptions,\n ...options,\n }\n logDebug(this, 'constructed', this.options)\n this.mediaSourceController = deps.mediaSourceController\n this.playbackController = deps.playbackController\n this.segmentController = deps.segmentController\n }\n\n get active(): boolean {\n return this._active\n }\n\n /**\n * Activates the buffering controller, watching the playhead and segment controller.\n */\n activate() {\n if (this._active) return\n this._active = true\n logDebug(this, 'activate')\n this.activateDisposer = createDisposer()\n const { add } = this.activateDisposer\n this.sourceBufferController = add(\n this.deps.sourceBufferControllerFactory()\n )\n add(this.playbackController.on('timeUpdate', this.pollBuffer))\n add(\n this.playbackController.on('seeking', () => {\n this.clear()\n })\n )\n\n const onMediaSourceOpen = () => {\n logDebug(this, 'media source opened')\n this.refreshDuration()\n this.pollBufferImmediate()\n }\n if (this.mediaSourceOpen) {\n onMediaSourceOpen()\n } else {\n add(this.mediaSourceController.on('sourceOpen', onMediaSourceOpen))\n }\n add(\n this.segmentController.on('change', () => {\n this.reopen = true\n this.refreshDuration()\n this.pollBufferImmediate()\n })\n )\n }\n\n deactivate() {\n if (!this._active) return\n logDebug(this, 'deactivate')\n this.abortCurrentSegment()\n this.resetBufferedState()\n this.activateDisposer!.dispose()\n this.activateDisposer = null\n this.sourceBufferController = null\n this._active = false\n }\n\n reset(): void {\n if (!this._error) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.pollBufferImmediate()\n }\n\n /**\n * Returns true if there are active operations.\n */\n get busy(): boolean {\n return this.queue.running > 0\n }\n\n /**\n * Enqueues a duration update.\n */\n private refreshDuration() {\n this.sourceBufferController!.enqueue(async () => {\n if (!this.mediaSourceOpen) return // Cannot set duration when media source is not open.\n const duration = await this.segmentController.getDuration()\n // For live streams, set the duration to LIVE_DURATION; not all browsers support +Infinity duration.\n const newDuration =\n duration == null ? LIVE_DURATION : duration + DURATION_PADDING\n logDebug(this, `setting duration: ${newDuration}`)\n this.mediaSourceController.duration = newDuration\n }).catch(this.handleError)\n }\n\n /**\n * Resets the throttle and polls the buffer on the next frame.\n */\n private pollBufferImmediate = () => {\n this.pollBuffer.reset()\n setTimeout(() => {\n if (this.active) this.pollBuffer()\n })\n }\n\n /**\n * If buffered time reaches below minBuffer, request the segment for the next unbuffered\n * time and append.\n * @private\n */\n private readonly pollBuffer = /* @__PURE__ */ this.disposer.add(\n /* @__PURE__ */ throttle(\n () => {\n const time = this.playbackController.currentTime\n if (getLogLevel() === LogLevel.VERBOSE) {\n logVerbose(\n this,\n `pollBuffer time: ${time}, bufferedTime: ${this.getBufferedTime()}, busy: ${this.busy}, error: ${this.error != null}, readyState: ${this.mediaSourceController.readyState}`\n )\n }\n this.refreshHead()\n if (!this.shouldAppend()) return\n this.reopen = false\n this.queue\n .enqueue(() => this.appendNext())\n .catch(this.handleError)\n // An append has finished. Poll again on the next frame.\n // The append either completed successfully, erred fatally (setting an error state),\n // or erred silently (an abort).\n .finally(this.pollBufferImmediate)\n },\n POLL_BUFFER_THROTTLE,\n {\n leading: true,\n trailing: true,\n }\n )\n )\n\n private shouldAppend(): boolean {\n return (\n this.active &&\n !this.busy &&\n !this.error &&\n !this.mediaSourceClosed &&\n (!this.bufferingEnded || this.reopen) &&\n // Return true if the current buffer is less than the minimum buffer and the playhead has not reached duration.\n this.getBufferedTime() <= this.options.minBuffer\n )\n }\n\n /**\n * The buffered segment at the playhead.\n */\n private get head(): SegmentReference<ArrayBuffer> | undefined {\n return this.buffered.head?.value\n }\n\n /**\n * The most recently buffered segment.\n */\n private get tail(): SegmentReference<ArrayBuffer> | undefined {\n return this.buffered.tail?.value\n }\n\n protected async appendNext(): Promise<void> {\n logVerbose(this, 'appendNext')\n const sourceBufferController = this.sourceBufferController!\n const time = this.playbackController.currentTime\n\n const tail = this.tail\n let streamingSegment: SegmentReference<ArrayBuffer> | null\n // If appendOffset is less than the last buffered segment size, this indicates a partial append, continue\n // buffering the last segment.\n if (tail && this.appendOffset < tail.data.byteLength) {\n streamingSegment = tail\n } else {\n streamingSegment = await this.segmentController.getSegment(\n // If buffering is a continuation from the previous segment, use its end time.\n // Otherwise, start streaming from slightly behind the playhead.\n tail?.endTime ?? time - SEGMENT_START_AFFORDANCE,\n this.segmentAbort.value\n )\n logVerbose(this, 'streamingSegment', streamingSegment)\n if (streamingSegment) this.appendOffset = 0\n }\n if (!streamingSegment) {\n await sourceBufferController.enqueue(() => {\n if (this.mediaSourceOpen) this.endBuffering()\n })\n return\n }\n this.bufferingQuality = streamingSegment.quality\n if (this.decoderId !== streamingSegment.quality.decoderId) {\n // Append the initialization segment before the media segment if the decoder\n // needs (re)-initialization.\n this.decoderId = null\n await sourceBufferController.appendInit(\n streamingSegment.initData,\n streamingSegment.quality.mimeType!\n )\n this.decoderId = streamingSegment.quality.decoderId\n }\n // Set the timestamp offset only if appending from an unbuffered position.\n if (!tail) {\n await sourceBufferController.setTimestampOffset(\n streamingSegment.timestampOffset\n )\n }\n\n const maxAppendSize = this.getMaxAppendSize(\n streamingSegment.quality.contentType!\n )\n\n const currentBitrate =\n streamingSegment.data.byteLength /\n (streamingSegment.endTime - streamingSegment.startTime)\n const appendSize =\n maxAppendSize - currentBitrate * this.getBufferedTime()\n if (appendSize <= 0) {\n // current buffered data is filling entire quota\n return\n }\n\n const byteLength = streamingSegment.data.byteLength\n if (byteLength > appendSize) {\n const newOffset = this.appendOffset + appendSize\n const chunk = streamingSegment.data.slice(\n this.appendOffset,\n newOffset\n )\n await sourceBufferController.append(chunk)\n if (this.appendOffset === 0) {\n this.buffered.push(streamingSegment)\n }\n this.appendOffset = newOffset\n logVerbose(\n this,\n `appended chunk, this.appendOffset: ${this.appendOffset}`\n )\n } else {\n await sourceBufferController.append(streamingSegment.data)\n this.appendOffset = streamingSegment.data.byteLength\n this.buffered.push(streamingSegment)\n }\n if (!tail) this.refreshHead() // Update quality immediately if buffer was empty\n }\n\n private abortCurrentSegment() {\n this.segmentAbort.abort()\n }\n\n /**\n * Checks if the playhead has progressed past the current head segment and shifts the linked list.\n * Updates the playback quality if changed.\n */\n private refreshHead() {\n const head = this.head\n const tail = this.tail\n const time = this.playbackController.currentTime\n if (head && time >= head.endTime && head !== tail) {\n // The playhead has passed the end of the head segment.\n this.buffered.shift()\n }\n this.playbackQuality = this.head?.quality ?? null\n }\n\n private getMaxAppendSize(contentType: ContentType): number {\n const maxAppendSize =\n this.options.maxAppendSize[contentType] ?? DEFAULT_MAX_APPEND_SIZE\n const sourceBufferQuota = sourceBufferQuotas.get(contentType)\n return sourceBufferQuota == null\n ? maxAppendSize\n : Math.min(sourceBufferQuota, maxAppendSize)\n }\n\n private _playbackQuality: MediaQualityMetadata | null = null\n\n get playbackQuality(): MediaQualityMetadata | null {\n return this._playbackQuality\n }\n\n /**\n * Returns the quality currently buffering.\n */\n get bufferingQuality(): MediaQualityMetadata | null {\n return this._bufferingQuality\n }\n\n private set bufferingQuality(value: MediaQualityMetadata | null) {\n const previous = this._bufferingQuality\n if (value?.qualityId === previous?.qualityId) return\n this._bufferingQuality = value\n logDebug(this, 'bufferingQualityChange', value)\n this.dispatch('bufferingQualityChange', {\n previous,\n current: value,\n })\n }\n\n /**\n * Sets the current playback quality and emits a playbackQualityChange event.\n * No-ops if quality id has not changed.\n */\n private set playbackQuality(value: MediaQualityMetadata | null) {\n const previous = this._playbackQuality\n if (value?.qualityId === previous?.qualityId) return\n this._playbackQuality = value\n logDebug(this, 'playbackQualityChange', value)\n this.dispatch('playbackQualityChange', {\n previous,\n current: value,\n })\n }\n\n /**\n * The last error emitted.\n * Buffering will halt if this controller is in an error state.\n * Deactivating this controller will reset the error state.\n */\n get error(): Error | null {\n return this._error\n }\n\n /**\n * Returns true if the media source's ready state is 'open'\n */\n private get mediaSourceOpen(): boolean {\n return this.mediaSourceController.readyState === 'open'\n }\n\n /**\n * Returns true if the media source's ready state is 'closed'\n */\n private get mediaSourceClosed(): boolean {\n return this.mediaSourceController.readyState === 'closed'\n }\n\n /**\n * Returns true if the last segment has been appended.\n */\n get bufferingEnded(): boolean {\n return this._bufferingEnded\n }\n\n private readonly handleError = (error: Error) => {\n if ('name' in error && error.name === 'QuotaExceededError') {\n const contentType = this.bufferingQuality?.contentType\n if (contentType) {\n const newAppendSize =\n this.getMaxAppendSize(contentType) * QUOTA_REACHED_SCALE\n if (newAppendSize >= MIN_APPEND_SIZE) {\n sourceBufferQuotas.set(contentType, newAppendSize)\n logWarn(\n this,\n 'QuotaExceededError, new source buffer limit:',\n (newAppendSize / 1024 / 1024).toFixed(1) + ' MiB'\n )\n const sourceBufferController = this.sourceBufferController\n if (sourceBufferController) {\n this.clear()\n }\n return // If the quota size was successfully reduced, do not err and try again.\n }\n }\n }\n if (!isSilentError(error)) {\n // Set this controller to an error state. If in an error state, buffering will\n // not continue.\n this._error = error\n this.dispatch('error', {\n target: this,\n error,\n })\n }\n }\n\n /**\n * Returns the amount of time buffered at the current media position.\n * @private\n */\n getBufferedTime(): number {\n if (!this.active) return 0\n const time = this.playbackController.currentTime\n const range = this.sourceBufferController!.buffered.getRangeAt(time)\n if (!range) return 0\n return range[1] - time\n }\n\n /**\n * Cancels any currently buffering fragments and clears the source buffer.\n */\n clear(): void {\n if (!this.active) return\n logDebug(this, 'clear')\n this.abortCurrentSegment()\n // Enqueue clearing the buffer and buffered list.\n this.queue\n .enqueue(this.finishAndClearBuffers)\n .catch(this.handleError)\n .finally(() => {\n this.resetBufferedState()\n this.pollBufferImmediate()\n })\n }\n\n private endBuffering(): void {\n logDebug(this, 'bufferingEnded')\n this._bufferingEnded = true\n this.bufferingQuality = null\n this.dispatch('bufferingEnded', {})\n }\n\n private resetBufferedState() {\n this.decoderId = null\n this.appendOffset = 0\n this.buffered.clear()\n this._bufferingEnded = false\n this.bufferingQuality = null\n this.playbackQuality = null\n }\n\n /**\n * Finish any partial appends and clear the source buffer.\n */\n private finishAndClearBuffers = async () => {\n if (!this.active) return\n logVerbose(this, 'finishAndClearBuffers')\n await this.sourceBufferController!.clear()\n logVerbose(this, 'finishAndClearBuffers complete')\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.deactivate()\n super.dispose()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AnyRecord,\n Disposable,\n ReadonlyAbort,\n ReadonlyEventHost,\n ReadonlyRanges,\n} from '@amazon/vinyl-util'\nimport type { SegmentReference } from '@/streaming/SegmentReference'\nimport type { ChangeEvent } from '@/event/ChangeEvent'\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\n\n/**\n * Forward-snap tolerance, in seconds, applied when looking up a segment by time.\n *\n * If the requested time falls within this window before a segment's `startTime`,\n * that segment is returned rather than treating the gap as uncovered. This absorbs\n * small alignment differences between qualities, where one quality's segment may\n * begin a few milliseconds later than another's at the same logical boundary.\n *\n * Pass to `getSegmentAtTime` (and `MediaQualityData.getSegment`) as the `affordance`\n * argument. Callers resuming streaming after a seek should also bias the requested\n * time *behind* the playhead by at least this amount, so any subsequent appends\n * cover the playhead without leaving a gap. The `SegmentController` clamps negative\n * request times to `0`, so callers don't need to guard against the bias going below\n * the start of the timeline.\n */\nexport const SEGMENT_START_AFFORDANCE = 0.2\n\nexport interface SegmentControllerEventMap {\n /**\n * fetchedRanges have been updated.\n */\n readonly fetchedRangesChange: AnyRecord\n\n /**\n * Emitted when the timeline has changed.\n */\n readonly change: AnyRecord\n\n /**\n * Dispatched when the current streaming quality changes.\n * This is dispatched when a new quality is requested.\n */\n readonly streamingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n}\n\n/**\n * The SegmentController provides segments to buffer for the given time.\n * It is expected to prefetch segments based on the expectation of when the segments will be\n * needed next.\n */\nexport interface ReadonlySegmentController extends ReadonlyEventHost<SegmentControllerEventMap> {\n readonly error: Error | null\n\n /**\n * The time ranges currently fetched.\n */\n readonly fetchedRanges: ReadonlyRanges\n\n /**\n * The most recently requested quality metadata.\n */\n readonly streamingQuality: MediaQualityMetadata | null\n\n /**\n * The duration of the media, in seconds.\n * Returns null if duration cannot be determined.\n */\n getDuration(): Promise<number | null>\n\n /**\n * Returns a Promise for a segment covering the given time, with quality chosen by\n * the configured `QualitySelector`. Resolves to `null` if no media exists at that\n * time. Negative `time` values are clamped to `0`.\n *\n * The lookup forward-snaps by `SEGMENT_START_AFFORDANCE`: if `time` falls within\n * that window before a segment's `startTime`, that segment is returned. This\n * absorbs sub-second segment-boundary differences across qualities so an ABR\n * switch doesn't replay or skip media at the boundary.\n *\n * Calling this also blocks the prefetch queue until the returned promise settles,\n * so the active request is prioritized over background prefetching.\n *\n * @param time The time, in seconds, the requested segment should span.\n * @param abort Aborts the returned promise (rejecting with `AbortError`) and\n * releases the prefetch-queue lock. The underlying network request may continue\n * so its result can still populate the cache.\n */\n getSegment(\n time: number,\n abort?: ReadonlyAbort\n ): Promise<SegmentReference<ArrayBuffer> | null>\n}\n\n/**\n * Configuration the track is expected to provide to the SegmentController.\n */\nexport interface PrefetchOptions {\n /**\n * The prefetching priority of the track. Higher numbers take precedence.\n */\n readonly trackPrefetchPriority: number\n\n /**\n * When the track is inactive, the starting time to prefetch from.\n */\n readonly startTime: number\n}\n\n/**\n * Provides segments for a given time.\n * Handles segment prefetching and caching.\n */\nexport interface SegmentController\n extends ReadonlySegmentController, Disposable {\n /**\n * Configures this segment provider.\n */\n configure(options: Partial<PrefetchOptions>): void\n\n /**\n * Clears the cached segments.\n * Currently pending segment promises will be rejected with an abort reason.\n */\n clear(): void\n\n /**\n * Indicates that this segment provider is providing segments for an active track and should be prioritized\n * accordingly.\n */\n activate(): void\n\n /**\n * Indicates that this segment provider is providing segments for an inactive track.\n */\n deactivate(): void\n\n /**\n * Resets failed segments to a pending state.\n */\n reset(): void\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Mutable, Unsubscribe } from '@amazon/vinyl-util'\nimport {\n Abort,\n clone,\n closeTo,\n createDisposer,\n EventHostImpl,\n getNetworkState,\n getOrSet,\n isSilentError,\n logDebug,\n logError,\n noop,\n type Range,\n rangeIntersects,\n RangesImpl,\n type ReadonlyAbort,\n type ReadonlyRanges,\n throttle,\n withAbort,\n} from '@amazon/vinyl-util'\nimport type { ReadonlyPlaybackController } from '@/playback/ReadonlyPlaybackController'\nimport {\n type PrefetchOptions,\n SEGMENT_START_AFFORDANCE,\n type SegmentController,\n type SegmentControllerEventMap,\n} from '@/streaming/SegmentController'\nimport {\n type SegmentDataProvider,\n SegmentDataSlot,\n SegmentStatus,\n} from '@/streaming/SegmentDataSlot'\nimport {\n defaultTrackPriority,\n enqueueSegmentPrefetch,\n immediatePrefetchPriority,\n type SegmentPrefetchPriority,\n} from '@/streaming/SegmentPrefetch'\nimport {\n getSegmentAtTime,\n getSegmentInsertionIndexAtTime,\n} from '@/streaming/util/segment'\nimport type { SegmentReference } from '@/streaming/SegmentReference'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\nimport {\n getMediaPeriodAtTime,\n type MediaPeriod,\n} from '@/streaming/MediaTimeline'\nimport type {\n PrefetchState,\n QualitySelector,\n} from '@/streaming/abr/QualitySelector'\n\n/**\n * The interval to check if additional segments should be prefetched.\n */\nexport const PREFETCH_POLL_THROTTLE = 1\n\nexport interface SegmentControllerImplDeps {\n readonly playbackController: ReadonlyPlaybackController\n\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n\n readonly qualitySelector: QualitySelector\n}\n\nexport interface SegmentControllerImplOptions {\n /**\n * The amount of time ahead of the playhead to prefetch when the track is active.\n * Default: 240\n */\n readonly prefetchActive: number\n\n /**\n * The amount of time to prefetch when the track is not active.\n * Default: 20\n */\n readonly prefetchInactive: number\n\n /**\n * The number of seconds behind the playhead to retain segments.\n * Default: 30\n */\n readonly retainTail: number\n}\n\nexport const defaultSegmentControllerBaseOptions: SegmentControllerImplOptions =\n {\n prefetchActive: 180,\n prefetchInactive: 20,\n retainTail: 30,\n }\n\n/**\n * Default SegmentController implementation.\n * Provides segments for a given time.\n * Handles segment prefetching and caching.\n *\n * Uses mediaTimelineTransformed to resolve segments directly from the MediaTimeline.\n */\nexport class SegmentControllerImpl\n extends EventHostImpl<SegmentControllerEventMap>\n implements SegmentController\n{\n get [Symbol.toStringTag](): string {\n return 'SegmentControllerImpl'\n }\n\n private _active = false\n get active(): boolean {\n return this._active\n }\n\n private readonly _fetchedRanges = /* @__PURE__ */ new RangesImpl()\n private _startTime = 0\n\n /**\n * A map of decoder id to init segment slots.\n * This allows representations with seamless bitstream switching to share initialization segments without\n * making unnecessary requests or decoder re-initializations.\n */\n private readonly cachedInitSegments = /* @__PURE__ */ new Map<string, SegmentDataSlot>()\n private readonly cachedSegments: SegmentReference<SegmentDataSlot>[] = []\n\n private readonly disposer = /* @__PURE__ */ createDisposer()\n readonly options: SegmentControllerImplOptions\n\n private prefetchingPriority: Mutable<SegmentPrefetchPriority> =\n /* @__PURE__ */ clone(defaultTrackPriority)\n\n /**\n * True if the last segment in the prefetch range has been cached.\n */\n private ended = false\n private prefetching = false\n private _error: Error | null = null\n\n private timeUpdateSub: Unsubscribe | null = null\n private seekingSub: Unsubscribe | null = null\n\n // When disposed, aborts in-flight operations.\n private readonly abort = /* @__PURE__ */ new Abort()\n\n /**\n * Cached last period lookup for fast repeated access.\n */\n private _cachedPeriod: MediaPeriod | null = null\n\n constructor(\n readonly deps: SegmentControllerImplDeps,\n readonly contentType: ContentType,\n options?: Partial<SegmentControllerImplOptions>\n ) {\n super()\n logDebug(this, 'constructed')\n const { add } = this.disposer\n this.options = {\n ...defaultSegmentControllerBaseOptions,\n ...options,\n }\n add(\n deps.mediaTimelineTransformed.onData(() => {\n // If the media timeline changes, re-check ended state.\n this.ended = false\n this._cachedPeriod = null\n this.pollPrefetch()\n this.dispatch('change', {})\n })\n )\n\n add(\n getNetworkState().on('online', () => {\n logDebug(this, 'online, resetting prefetch')\n this.reset()\n })\n )\n }\n\n get error(): Error | null {\n return this._error\n }\n\n async getDuration(): Promise<number | null> {\n const timeline = await this.deps.mediaTimelineTransformed.value\n if (timeline.getDuration) return timeline.getDuration()\n const periods = timeline.periods\n if (periods.length === 0) return null\n const last = periods[periods.length - 1]\n return last.endTime === Infinity ? null : last.endTime\n }\n\n /**\n * Gets the period at the given time, using a cache for the last returned period.\n */\n private async getPeriodAtTime(time: number): Promise<MediaPeriod | null> {\n if (\n this._cachedPeriod &&\n time >= this._cachedPeriod.startTime &&\n time < this._cachedPeriod.endTime\n ) {\n return this._cachedPeriod\n }\n const timeline = await this.deps.mediaTimelineTransformed.value\n const period = getMediaPeriodAtTime(timeline, time)\n if (period) this._cachedPeriod = period\n return period\n }\n\n /**\n * Configures this segment provider and initiates prefetching.\n * This may be called multiple times, for example when re-using a cached track a new track priority and start time\n * can be provided.\n */\n configure(options: Partial<PrefetchOptions>) {\n if (options.startTime != null) this._startTime = options.startTime\n if (options.trackPrefetchPriority != null)\n this.prefetchingPriority.trackPriority =\n options.trackPrefetchPriority\n this.ended = false\n this.pollPrefetch()\n }\n\n get startTime(): number {\n return this._startTime\n }\n\n get trackPrefetchPriority(): number {\n return this.prefetchingPriority.trackPriority\n }\n\n /**\n * Returns the range that should be prefetched.\n */\n private get prefetchRange(): Range {\n return this.active\n ? this.prefetchRangeActive\n : this.prefetchRangeInactive\n }\n\n /**\n * Returns the range that should be prefetched when inactive.\n * This range will not be removed during sweeps unless `clear` is called.\n */\n private get prefetchRangeInactive(): Range {\n const prefetchFrom = this.startTime\n const prefetchTo = prefetchFrom + this.options.prefetchInactive\n return [prefetchFrom, prefetchTo]\n }\n\n /**\n * Returns the range that should be prefetched while active.\n */\n private get prefetchRangeActive(): Range {\n const prefetchFrom = this.deps.playbackController.currentTime\n const prefetchTo = prefetchFrom + this.options.prefetchActive\n return [prefetchFrom, prefetchTo]\n }\n\n /**\n * Clears data segments no longer within the current prefetch range.\n * Init segments will not be changed.\n */\n private sweepCachedSegments() {\n // The inactive range (typically first couple segments of a track) will not be removed.\n const inactiveRange = this.prefetchRangeInactive\n\n // The active range prefetch expanded to include the retain tail will not be removed if the track is active.\n const activeRange = this.active\n ? ([\n this.prefetchRangeActive[0] - this.options.retainTail,\n this.prefetchRangeActive[1],\n ] as const)\n : null\n let n = this.cachedSegments.length\n for (let i = 0; i < n; i++) {\n const cachedSegment = this.cachedSegments[i]\n // Check if the cached segment is still within our retain window.\n const { startTime, endTime } = cachedSegment\n const cachedRange = [startTime, endTime] as const\n if (\n !rangeIntersects(inactiveRange, cachedRange) &&\n !(activeRange && rangeIntersects(activeRange, cachedRange))\n ) {\n // No longer need the segment. Does nothing if inactive.\n cachedSegment.data.clear()\n this.cachedSegments.splice(i, 1)\n logDebug(\n this,\n 'removing cached segment at: ',\n cachedSegment.startTime\n )\n i--\n n--\n }\n }\n }\n\n /**\n * Gets the next time to prefetch, or null if the prefetch range has been filled.\n */\n private getNextTimeToPrefetch(): number | null {\n const [prefetchFrom, prefetchTo] = this.prefetchRange\n // fetchedRanges are directly from the segments, safe to use when getting next segment.\n const currentRange = this.fetchedRanges.getRangeAt(prefetchFrom)\n const nextTime = currentRange == null ? prefetchFrom : currentRange[1]\n if (nextTime >= prefetchTo - Number.EPSILON) return null\n return nextTime\n }\n\n private pollPrefetch = /* @__PURE__ */ this.disposer.add(\n /* @__PURE__ */ throttle(\n () => {\n if (this.error) return\n this.sweepCachedSegments()\n if (this.ended || this.prefetching) return\n\n const nextTime = this.getNextTimeToPrefetch()\n if (nextTime == null) return // Prefetched the full range\n this.prefetching = true\n // Enqueue the prefetch.\n enqueueSegmentPrefetch(\n async () => {\n this.abort.throwIfAborted()\n // Quality selection is done at the time of getSegment(), which is called when\n // a slot is created. Defer slot creation until request is about to be made.\n logDebug(this, `Prefetching`, nextTime.toFixed(4))\n const slot = await this.getSlotAtTime(nextTime)\n this.abort.throwIfAborted()\n if (!slot) {\n logDebug(this, 'prefetch ended')\n this.ended = true\n return\n }\n await withAbort(\n Promise.all([\n slot.initData.request(),\n slot.data.request(),\n ]),\n this.abort\n )\n },\n this.contentType,\n this.prefetchingPriority\n )\n .catch(this.prefetchErrorHandler)\n .finally(() => {\n this.prefetching = false\n if (!this.disposed) this.pollPrefetch()\n })\n },\n PREFETCH_POLL_THROTTLE,\n {\n leading: true,\n trailing: true,\n }\n )\n )\n\n private prefetchErrorHandler = (error: any) => {\n // Only log the error for prefetch failures, it will get reported if/when it is attempted\n // to be buffered.\n if (!isSilentError(error)) {\n logError(this, 'Error prefetching segment', error)\n this._error = error\n }\n }\n\n get fetchedRanges(): ReadonlyRanges {\n return this._fetchedRanges\n }\n\n /**\n * Gets the number of seconds currently prefetched.\n */\n get fetchedTime(): number {\n const time = this.active\n ? this.deps.playbackController.currentTime\n : this._startTime\n const currentRange = this.fetchedRanges.getRangeAt(time)\n if (!currentRange) return 0\n return currentRange[1] - time\n }\n\n private _streamingQuality: MediaQualityMetadata | null = null\n\n get streamingQuality(): MediaQualityMetadata | null {\n return this._streamingQuality\n }\n\n private set streamingQuality(value: MediaQualityMetadata | null) {\n const previous = this._streamingQuality\n if (value?.qualityId === previous?.qualityId) return\n this._streamingQuality = value\n logDebug(this, 'streamingQualityChange', value)\n this.dispatch('streamingQualityChange', {\n previous,\n current: value,\n })\n }\n\n getSegment(\n time: number,\n abort?: ReadonlyAbort\n ): Promise<SegmentReference<ArrayBuffer> | null> {\n logDebug(this, `requesting segment at time: ${time.toFixed(4)}`)\n const segmentReferencePromise = withAbort(\n this._getSegment(Math.max(0, time)),\n abort\n )\n\n // When a segment is actively needed, block the prefetch queue until the active segment promise settles:\n enqueueSegmentPrefetch(\n () => segmentReferencePromise,\n this.contentType,\n immediatePrefetchPriority\n ).catch(noop)\n return segmentReferencePromise\n }\n\n private async _getSegment(\n time: number\n ): Promise<SegmentReference<ArrayBuffer> | null> {\n const streamingSlot = await this.getSlotAtTime(time)\n if (!streamingSlot) return null\n logDebug(\n this,\n `init status: ${streamingSlot.initData.status}, data status: ${streamingSlot.data.status}`\n )\n // If prefetch failed, try again now that the segment is actively needed:\n this.resetSlot(streamingSlot)\n\n const initAndDataPromise = Promise.all([\n streamingSlot.initData.request(),\n streamingSlot.data.request(),\n ])\n\n // If the requested time is close to the start of the next segment, immediately start prefetching the next\n // segment, and not resolving until both are cached.\n let minBufferPrefetch: Promise<void> = Promise.resolve()\n const minBufferTime = await this.getMinBufferTime()\n if (streamingSlot.endTime - time < minBufferTime) {\n minBufferPrefetch = this.prefetchImmediate(\n streamingSlot.endTime\n ).catch(noop) // Ignore error until it is the next segment needed\n }\n const [initData, data] = await initAndDataPromise\n await minBufferPrefetch\n return {\n ...streamingSlot,\n initData,\n data,\n }\n }\n\n /**\n * Gets the minimum buffer time from the timeline.\n * Falls back to a reasonable default.\n */\n private async getMinBufferTime(): Promise<number> {\n const timeline = await this.deps.mediaTimelineTransformed.value\n return timeline.minBufferTime\n }\n\n /**\n * Prefetches the segment at the given time. Does not use the background scheduler.\n *\n * @param time\n */\n private async prefetchImmediate(time: number): Promise<void> {\n const slot = await this.getSlotAtTime(time)\n if (!slot) return\n await Promise.all([slot.initData.request(), slot.data.request()])\n }\n\n /**\n * Gets a streaming segment slot that spans the given time, or null if there is no media at that time.\n * Slots will be cached until they slide out of the retention range or `clear` is called.\n */\n private async getSlotAtTime(\n time: number\n ): Promise<SegmentReference<SegmentDataSlot> | null> {\n // Check if there is a cached slot.\n const cachedSegment = getSegmentAtTime(\n time,\n this.cachedSegments,\n SEGMENT_START_AFFORDANCE\n )\n if (cachedSegment) return cachedSegment\n\n const newSlot = await withAbort(\n this.createSlotForTime(time),\n this.abort\n )\n this.abort.throwIfAborted()\n\n if (!newSlot) return null\n newSlot.data.onStatusChange = () => {\n // When the data segment settles, update the fetched ranges.\n if (newSlot.data.status === SegmentStatus.RESOLVED)\n this._fetchedRanges.add(newSlot.startTime, newSlot.endTime)\n else if (newSlot.data.status === SegmentStatus.INACTIVE)\n this._fetchedRanges.remove(newSlot.startTime, newSlot.endTime)\n this.dispatch('fetchedRangesChange', {})\n }\n\n // Insert the slot, in order.\n const insertionIndex = getSegmentInsertionIndexAtTime(\n newSlot.startTime,\n this.cachedSegments\n )\n\n // Slot creation is asynchronous, to allow requesting index ranges. Check if a slot for this time was already\n // created.\n if (insertionIndex > 0) {\n const cachedSegment = this.cachedSegments[insertionIndex - 1]\n if (closeTo(newSlot.startTime, cachedSegment.startTime)) {\n return cachedSegment\n }\n }\n logDebug(\n this,\n `created slot at ${insertionIndex} for time ${newSlot.startTime.toFixed(4)}`\n )\n this.cachedSegments.splice(insertionIndex, 0, newSlot)\n return newSlot\n }\n\n /**\n * Gets a cached init segment slot for the given decoder id. If a slot is not cached, create one.\n */\n private getOrCreateInitSlot(\n decoderId: string,\n segmentDataProvider: SegmentDataProvider\n ): SegmentDataSlot {\n return getOrSet(this.cachedInitSegments, decoderId, () => {\n return new SegmentDataSlot(segmentDataProvider)\n })\n }\n\n /**\n * Creates a slot that spans the given time, or returns null if there is no media at that time.\n * Uses the mediaTimelineTransformed to resolve segments directly.\n */\n private async createSlotForTime(\n time: number\n ): Promise<SegmentReference<SegmentDataSlot> | null> {\n const period = await this.getPeriodAtTime(time)\n if (!period) return null\n\n // Filter qualities to this content type.\n const filteredQualities = period.qualities.filter(\n (q) => q.metadata.contentType === this.contentType\n )\n if (filteredQualities.length === 0) return null\n\n // Gets the preceding segment encoding metadata for quality selection.\n let previousQuality: MediaQualityMetadata | null = null\n const previousIndex =\n getSegmentInsertionIndexAtTime(time, this.cachedSegments) - 1\n if (previousIndex >= 0)\n previousQuality = this.cachedSegments[previousIndex].quality\n\n const prefetchState: PrefetchState = {\n fetchedTime: this.fetchedTime,\n previousQuality,\n active: this.active,\n }\n\n const metadataArray = filteredQualities.map((q) => q.metadata)\n const index = this.deps.qualitySelector.selectQuality(\n metadataArray,\n prefetchState\n )\n const selectedQuality = filteredQualities[index]\n\n const segment = await selectedQuality.getSegment(\n time,\n SEGMENT_START_AFFORDANCE\n )\n this.abort.throwIfAborted()\n this.streamingQuality = segment?.quality ?? null\n if (!segment) return null\n\n return {\n ...segment,\n quality: segment.quality,\n initData: this.getOrCreateInitSlot(\n segment.quality.decoderId,\n segment.initData\n ),\n data: new SegmentDataSlot(segment.data),\n }\n }\n\n /**\n * Indicates that this segment provider is providing segments for an active track and should be prioritized\n * accordingly.\n * Time ranges to be prefetched will change to the active prefetch window.\n */\n activate(): void {\n if (this._active) return\n logDebug(this, 'activate')\n this._active = true\n this.pollPrefetch()\n const playbackController = this.deps.playbackController\n this.timeUpdateSub = playbackController.on(\n 'timeUpdate',\n this.pollPrefetch\n )\n this.seekingSub = playbackController.on('seeking', () => {\n this.ended = false\n this._error = null\n this.pollPrefetch()\n })\n }\n\n /**\n * Deactivates the segment provider.\n * This clears cached segments not within the inactive prefetch range.\n * Time ranges to be prefetched will change to the inactive prefetch window.\n */\n deactivate(): void {\n if (!this._active) return\n logDebug(this, 'deactivate')\n this._active = false\n this.sweepCachedSegments()\n this.timeUpdateSub!()\n this.timeUpdateSub = null\n this.seekingSub!()\n this.seekingSub = null\n }\n\n clear(): void {\n logDebug(this, 'clear')\n this.cachedSegments.forEach((slot) => {\n slot.data.onStatusChange = null\n slot.data.clear()\n slot.initData.clear()\n })\n this.cachedSegments.length = 0\n this.cachedInitSegments.clear()\n this._fetchedRanges.clear()\n this.ended = false\n this._error = null\n this._cachedPeriod = null\n if (!this.disposed) this.pollPrefetch()\n this.dispatch('fetchedRangesChange', {})\n }\n\n reset(): void {\n logDebug(this, 'reset')\n this.cachedSegments.forEach((slot) => this.resetSlot(slot))\n this._error = null\n this.pollPrefetch()\n }\n\n /**\n * Resets the slot if it's in an error state.\n * @param slot\n */\n private resetSlot(slot: SegmentReference<SegmentDataSlot>) {\n if (slot.data.status === SegmentStatus.ERRED) {\n logDebug(this, 'resetting failed segment at time:', slot.startTime)\n this.ended = false\n slot.data.clear()\n }\n if (slot.initData.status === SegmentStatus.ERRED) {\n logDebug(this, 'resetting failed init segment')\n this.ended = false\n slot.initData.clear()\n }\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n logDebug(this, 'disposing')\n super.dispose()\n this.disposer.dispose()\n this.deactivate()\n this.clear()\n this.abort.abort()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Disposable, Maybe } from '@amazon/vinyl-util'\nimport {\n createAbortSlot,\n isSilentError,\n type ReadonlyAbort,\n} from '@amazon/vinyl-util'\n\nexport enum SegmentStatus {\n /**\n * This segment has not been requested.\n */\n INACTIVE = 'inactive',\n\n /**\n * The segment has been requested but not yet completed.\n */\n PENDING = 'pending',\n\n /**\n * The segment has finished requesting.\n */\n RESOLVED = 'resolved',\n\n /**\n * The segment failed to load.\n */\n ERRED = 'erred',\n}\n\n/**\n * A function that returns a promise to segment data.\n */\nexport type SegmentDataProvider = (\n abort?: Maybe<ReadonlyAbort>\n) => Promise<ArrayBuffer>\n\n/**\n * A SegmentSlot is a holder for a segment buffer. It may be requested, cleared, and its status observed.\n */\nexport class SegmentDataSlot implements Disposable {\n /**\n * Called when the status has changed.\n */\n onStatusChange: (() => void) | null = null\n\n private _status: SegmentStatus = SegmentStatus.INACTIVE\n private readonly abortSlot = /* @__PURE__ */ createAbortSlot()\n\n private bufferPromise: Promise<ArrayBuffer> | null = null\n\n constructor(private readonly requestSegmentData: SegmentDataProvider) {}\n\n /**\n * This segment's request status.\n */\n get status(): SegmentStatus {\n return this._status\n }\n\n private set status(value: SegmentStatus) {\n this._status = value\n if (this.onStatusChange) this.onStatusChange()\n }\n\n /**\n * Aborts the request if the status is currently {@link SegmentStatus.PENDING}, and clears the cached buffer.\n * The status will go back to {@link SegmentStatus.INACTIVE} and the segment may be requested again in the future.\n */\n clear(): void {\n if (this.status === SegmentStatus.INACTIVE) return\n this.abortSlot.abort()\n this.bufferPromise = null\n this.status = SegmentStatus.INACTIVE\n }\n\n /**\n * Begins the segment request now if it has not already been requested.\n * The promise returned will settle after this slot's status has updated and onStatusChange callback invoked.\n */\n request(): Promise<ArrayBuffer> {\n if (!this.bufferPromise) {\n this.status = SegmentStatus.PENDING\n\n // Chains status handling to the promise returned by requestSegment.\n this.bufferPromise = this.requestSegmentData(this.abortSlot.value)\n .then((result) => {\n this.status = SegmentStatus.RESOLVED\n return result\n })\n .catch((error) => {\n if (isSilentError(error)) {\n // Allows this data slot to be requested again.\n this.bufferPromise = null\n this.status = SegmentStatus.INACTIVE\n } else {\n // A higher severity error, do not try again.\n this.status = SegmentStatus.ERRED\n }\n throw error\n })\n }\n return this.bufferPromise\n }\n\n /**\n * Clears this segment and removes its handler.\n */\n dispose(): void {\n this.clear()\n this.onStatusChange = null\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Task, TaskQueue } from '@amazon/vinyl-util'\nimport {\n type Comparator,\n compareBy,\n createTaskQueue,\n globalRef,\n} from '@amazon/vinyl-util'\nimport type { ContentType } from './MediaQualityMetadata'\n\n/**\n * Properties affecting segment prefetch priority.\n * Each track when prefetching will only add one segment to the prefetch queue at a time.\n */\nexport interface SegmentPrefetchPriority {\n /**\n * The track's prefetch priority.\n */\n readonly trackPriority: number\n\n /**\n * The starting time of the segment.\n */\n readonly segmentStartTime: number\n\n /**\n * The time position prefetching starts for this segment's track.\n */\n readonly prefetchStartTime: number\n}\n\nexport const defaultTrackPriority = {\n // Default priority is lowest, but not used. Use enqueueSegmentPrefetch to enqueue.\n trackPriority: 0,\n segmentStartTime: 9007199254740991, // Number.MAX_SAFE_INTEGER,\n prefetchStartTime: 0,\n} as const satisfies SegmentPrefetchPriority\n\n/**\n * Highest priority; used to block prefetching while an actively-needed operation is enqueued.\n */\nexport const immediatePrefetchPriority = {\n trackPriority: 9007199254740991, // Number.MAX_SAFE_INTEGER,\n segmentStartTime: 0,\n prefetchStartTime: 0,\n}\n\n/**\n * A comparator for segment prefetching.\n * Given tracks A, B, and C with track priorities 1, 2, and 3 respectively:\n * The expected prefetch order will be:\n *\n * A0\n * B0 // \"lean forward\" case\n * C0 // \"lean forward\" case\n * A1 ... An\n * B1 ... Bn\n * C1 ... Cn\n *\n * Note that background prefetching is in parallel to prefetching for the active track.\n */\nexport const segmentPriorityComparatorRef = /* @__PURE__ */ globalRef<\n Comparator<SegmentPrefetchPriority>\n>(() => {\n return compareBy(\n (e) => {\n // First segments always take priority over subsequent ones.\n return e.segmentStartTime <= e.prefetchStartTime ? 0 : 1\n },\n // Next, consider track priority.\n (e) => -e.trackPriority\n )\n})\n\n// Task queues for each content type\nexport const prefetchPriorityQueuesRef = /* @__PURE__ */ globalRef<\n Record<ContentType, TaskQueue<SegmentPrefetchPriority>>\n>(() => {\n return {\n video: createTaskQueue<SegmentPrefetchPriority>(\n segmentPriorityComparatorRef.value,\n defaultTrackPriority\n ),\n audio: createTaskQueue<SegmentPrefetchPriority>(\n segmentPriorityComparatorRef.value,\n defaultTrackPriority\n ),\n text: createTaskQueue<SegmentPrefetchPriority>(\n segmentPriorityComparatorRef.value,\n defaultTrackPriority\n ),\n }\n})\n\n/**\n * Enqueues a task to request a streaming segment for a specific content type.\n * This should only be used for low priority background requests. Active tracks should request without\n * prioritization for the immediately needed segment.\n * Tracks are expected to prefetch one segment at a time, in order.\n *\n * @param requestTask\n * @param contentType\n * @param priority\n */\nexport function enqueueSegmentPrefetch(\n requestTask: Task<any>,\n contentType: ContentType,\n priority: SegmentPrefetchPriority\n): Promise<void> {\n return prefetchPriorityQueuesRef.value[contentType].enqueue(\n requestTask,\n priority\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { sortedInsertionIndex } from '@amazon/vinyl-util'\nimport type { MediaSegmentMetadata } from '@/streaming/SegmentReference'\n\n/**\n * Returns the segment whose range covers `time` (`startTime <= time < endTime`), or\n * \u2014 when `affordance > 0` \u2014 the next segment if `time` falls within `affordance`\n * seconds before its `startTime`. Returns `null` if neither applies.\n *\n * Note: with `affordance > 0`, when `time` lies in the last `affordance` seconds of a\n * segment that does cover it, the *next* segment is returned instead. This is\n * deliberate \u2014 callers use `affordance` to absorb sub-second boundary differences\n * across qualities \u2014 but it means the result is not strictly the segment containing\n * `time`. Callers needing exact containment should pass `affordance = 0`.\n *\n * @param time Lookup time, in seconds.\n * @param segments Segments sorted by `startTime` ascending.\n * @param affordance Forward-snap tolerance in seconds: if `time` falls just before a\n * segment's `startTime` (within `affordance`), that segment is returned. The original\n * `time` is still compared against `endTime`, so coverage never extends past it.\n */\nexport function getSegmentAtTime<T extends MediaSegmentMetadata>(\n time: number,\n segments: readonly T[],\n affordance = 0\n): T | null {\n const index =\n getSegmentInsertionIndexAtTime(time + affordance, segments) - 1\n if (index < 0) return null\n const segment = segments[index]\n return time >= segment.endTime ? null : segment\n}\n\n/**\n * Returns the count of segments whose `startTime <= time` \u2014 i.e. the index at which a\n * segment with that `startTime` would be inserted to keep the array sorted ascending.\n *\n * @param time Lookup time, in seconds.\n * @param segments Segments sorted by `startTime` ascending.\n */\nexport function getSegmentInsertionIndexAtTime(\n time: number,\n segments: readonly MediaSegmentMetadata[]\n): number {\n return sortedInsertionIndex(\n segments,\n time,\n (time, element) => time - element.startTime\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaSourceController } from '@/streaming/buffering/MediaSourceController'\nimport type { PlaybackController } from '@/playback/PlaybackController'\nimport type { QualitySelector } from '@/streaming/abr/QualitySelector'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { type ContentStreamImplDeps } from '@/streaming/ContentStream'\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\nimport {\n SourceBufferControllerImpl,\n type SourceBufferControllerImplDeps,\n} from '@/streaming/buffering/SourceBufferController'\nimport {\n BufferingControllerImpl,\n type BufferingControllerImplDeps,\n} from '@/streaming/buffering/BufferingController'\nimport {\n SegmentControllerImpl,\n type SegmentControllerImplDeps,\n} from '@/streaming/SegmentControllerImpl'\nimport { type Maybe, memoize } from '@amazon/vinyl-util'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport type { ContentStreamingOptions } from '@/streaming/ContentStreamingOptions'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\n\n/**\n * Dependencies needed for a new content stream provided by the dash track.\n */\nexport interface DashContentStreamTrackDeps {\n readonly mediaSourceController: MediaSourceController\n readonly playbackController: PlaybackController\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n readonly qualitySelector: QualitySelector\n}\n\n/**\n * Returns a function to produce the Factories needed for a new ContentStreamImpl.\n */\nexport function createDashContentStreamFactories(\n options: Maybe<ContentStreamingOptions>\n) {\n return (deps: DashContentStreamTrackDeps) =>\n memoize(\n (contentType: ContentType) => {\n return validateFactories({\n ...externalDependencies(deps),\n sourceBufferControllerFactory:\n (deps: SourceBufferControllerImplDeps) => () =>\n new SourceBufferControllerImpl(deps, contentType),\n bufferingController: (deps: BufferingControllerImplDeps) =>\n new BufferingControllerImpl(\n deps,\n contentType,\n options?.buffering\n ),\n segmentController: (deps: SegmentControllerImplDeps) =>\n new SegmentControllerImpl(\n deps,\n contentType,\n options?.segmentController\n ),\n } as const) satisfies Factories<ContentStreamImplDeps>\n },\n (contentType) => contentType\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n PrefetchState,\n QualitySelector,\n} from '@/streaming/abr/QualitySelector'\nimport {\n clamp,\n createDisposer,\n createLogPrefix,\n type Disposable,\n getNetworkMetrics,\n type LogTarget,\n lerp,\n} from '@amazon/vinyl-util'\nimport {\n boolean,\n enumOf,\n number,\n object,\n type ObjectSchema,\n} from '@amazon/vinyl-validation'\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\n\nexport interface QualitySelectorImplOptions {\n /**\n * If at least this amount of time (in seconds) is currently fetched, don't consider an ABR-down.\n * Also used as the upper bound for interpolating between {@link bandwidthMultiplierLow} and\n * {@link bandwidthMultiplierHigh} based on the current fetched time.\n * Default: 15\n */\n readonly highBufferThreshold?: number\n\n /**\n * If less than this amount of time (in seconds) is currently fetched, don't consider an ABR-up.\n * Default: 4\n */\n readonly lowBufferThreshold?: number\n\n /**\n * Defines the strategy used for quality selection.\n *\n * Default: BEST (ABR will be enabled)\n */\n readonly strategy?: AbrStrategy\n\n /**\n * A multiplier applied to the estimated bandwidth when the fetched buffer is empty (0 seconds).\n * Lower values are more conservative (reduce the bandwidth used for quality selection) and help\n * avoid rebuffers when the buffer is low.\n *\n * As the fetched buffer fills toward {@link highBufferThreshold}, the effective multiplier\n * linearly interpolates between this value and {@link bandwidthMultiplierHigh}.\n *\n * Default: 0.4\n */\n readonly bandwidthMultiplierLow?: number\n\n /**\n * A multiplier applied to the estimated bandwidth when the fetched buffer is at or above\n * {@link highBufferThreshold}. Higher values are more optimistic and allow selection of higher\n * qualities once enough data is buffered to absorb short-term bandwidth dips.\n *\n * As the fetched buffer fills from 0 toward {@link highBufferThreshold}, the effective multiplier\n * linearly interpolates between {@link bandwidthMultiplierLow} and this value.\n *\n * Default: 0.9\n */\n readonly bandwidthMultiplierHigh?: number\n\n /**\n * When true, avoids changing codecs when considering choosing a higher audio bitrate\n * than what is currently playing. A decoder re-initialization is often an audible change,\n * so consumers that prefer to avoid audible artifacts may enable this. ABR-down is still\n * allowed across decoders because the subtle audio artifact is more desirable than a rebuffer.\n * Default: false\n */\n readonly restrictDecoderChangeOnAudioAbrUp?: boolean\n}\n\nexport enum AbrStrategy {\n /**\n * Selects lowest quality, regardless of bandwidth conditions.\n */\n LOWEST = 'lowest',\n\n /**\n * Selects highest quality, regardless of bandwidth conditions.\n */\n HIGHEST = 'highest',\n\n /**\n * Selects the best quality based on user bandwidth data.\n * Uses an EWMA estimation.\n */\n BEST = 'best',\n\n /**\n * Selects the initial quality based on bandwidth information, but will not change qualities mid-stream.\n *\n * May choose new quality after streaming clear, such as after a seek.\n */\n FIXED = 'fixed',\n}\n\nexport const qualitySelectorImplOptionsValidator: ObjectSchema<QualitySelectorImplOptions> =\n /* @__PURE__ */ object({\n highBufferThreshold: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n lowBufferThreshold: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n strategy: /* @__PURE__ */ /* @__PURE__ */ enumOf(AbrStrategy).optional(),\n bandwidthMultiplierLow: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n bandwidthMultiplierHigh: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n restrictDecoderChangeOnAudioAbrUp: /* @__PURE__ */ /* @__PURE__ */ boolean().optional(),\n })\n\nexport const defaultQualitySelectorImplOptions = {\n highBufferThreshold: 15,\n lowBufferThreshold: 4,\n strategy: AbrStrategy.BEST,\n bandwidthMultiplierLow: 0.4,\n bandwidthMultiplierHigh: 0.9,\n restrictDecoderChangeOnAudioAbrUp: false,\n} as const satisfies QualitySelectorImplOptions\n\nexport interface QualitySelectorImplDeps {\n readonly options: ObservableValue<QualitySelectorImplOptions>\n}\n\nexport class QualitySelectorImpl\n implements QualitySelector, LogTarget, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'QualitySelectorImpl'\n }\n\n readonly logPrefix = /* @__PURE__ */ createLogPrefix(this)\n private _options: Required<QualitySelectorImplOptions> =\n defaultQualitySelectorImplOptions\n\n private disposer = /* @__PURE__ */ createDisposer()\n\n constructor(deps: QualitySelectorImplDeps) {\n const { add } = this.disposer\n add(\n deps.options.onData((v) => {\n this._options = { ...defaultQualitySelectorImplOptions, ...v }\n })\n )\n }\n\n get options(): Required<QualitySelectorImplOptions> {\n return this._options\n }\n\n selectQuality(\n qualities: readonly MediaQualityMetadata[],\n prefetchState: PrefetchState\n ): number {\n const {\n strategy,\n highBufferThreshold,\n lowBufferThreshold,\n bandwidthMultiplierLow,\n bandwidthMultiplierHigh,\n restrictDecoderChangeOnAudioAbrUp,\n } = this.options\n const previousQuality = prefetchState.previousQuality\n // previousIndex will be -1 if the previously playing quality is not within the current qualities list.\n const previousIndex =\n previousQuality == null\n ? -1\n : qualities.findIndex(\n (quality) =>\n quality.qualityId === previousQuality.qualityId\n )\n\n if (strategy === AbrStrategy.LOWEST) {\n return qualities.length - 1\n } else if (strategy === AbrStrategy.HIGHEST) {\n return 0\n } else if (strategy === AbrStrategy.FIXED) {\n if (previousIndex >= 0) return previousIndex\n }\n\n const fetchedTime = prefetchState.fetchedTime\n const bandwidthEstimate = getNetworkMetrics().estimatedDownlinkBandwidth\n // Interpolate the bandwidth multiplier between the low and high values based on how much\n // buffer is currently fetched. An empty buffer uses bandwidthMultiplierLow (conservative)\n // to reduce rebuffer risk; a buffer at or above highBufferThreshold uses\n // bandwidthMultiplierHigh (optimistic) since buffered data can absorb short-term dips.\n // The interpolation is linear with respect to the buffer ratio.\n // If the track is not active (i.e. prefetch), always use the high multiplier.\n const bufferRatio =\n highBufferThreshold > 0\n ? clamp(fetchedTime / highBufferThreshold, 0, 1)\n : 1\n const bandwidthMultiplier = prefetchState.active\n ? lerp(bandwidthMultiplierLow, bandwidthMultiplierHigh, bufferRatio)\n : bandwidthMultiplierHigh\n\n // Choose bandwidth based on pessimistic network information.\n // If the track is active, take the lesser of the latest recorded bandwidth stat and the weighted\n // average to allow for fast ABR-down in variable conditions.\n const bandwidth =\n (prefetchState.active\n ? Math.min(bandwidthEstimate.ewmaLow, bandwidthEstimate.latest)\n : bandwidthEstimate.ewmaLow) * bandwidthMultiplier\n\n let restrictDecoderId: string | null = null\n let restrictSwitchingGroupIds: readonly string[] | null = null\n if (previousQuality && previousIndex >= 0) {\n // Restrict to qualities whose groupId is in the previous quality's switching group.\n // Null switchingGroupIds means no switching constraint.\n if (previousQuality.switchingGroupIds != null) {\n restrictSwitchingGroupIds = previousQuality.switchingGroupIds\n }\n\n // Intra-track ABR rules\n if (\n previousQuality.bandwidthTotal &&\n bandwidth < previousQuality.bandwidthTotal\n ) {\n // Measured bandwidth lower than current streaming bandwidth.\n if (fetchedTime >= highBufferThreshold) {\n // Do not ABR-down inter-track when there is ample fetched data.\n return previousIndex\n }\n } else {\n if (fetchedTime < lowBufferThreshold) {\n // Do not ABR-up inter-track when there is not enough fetched data.\n return previousIndex\n }\n\n // Measured bandwidth is at least current streaming bandwidth.\n // Restrict to the previous decoder id for audio to avoid an audible artifact\n // from decoder re-initialization.\n if (\n restrictDecoderChangeOnAudioAbrUp &&\n previousQuality.contentType === 'audio'\n ) {\n restrictDecoderId = previousQuality.decoderId\n }\n }\n }\n const index = qualities.findIndex((quality) => {\n if (\n restrictSwitchingGroupIds != null &&\n !restrictSwitchingGroupIds.includes(quality.groupId)\n )\n return false\n if (\n restrictDecoderId != null &&\n quality.decoderId !== restrictDecoderId\n )\n return false\n return (\n quality.bandwidthTotal == null ||\n quality.bandwidthTotal <= bandwidth\n )\n })\n return index === -1 ? qualities.length - 1 : index\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n DashTrackDeps,\n DashTrackLoadOptions,\n} from '@/track/dash/DashTrack'\nimport { type Maybe, type RequestInterceptor } from '@amazon/vinyl-util'\nimport { pickFirstBaseUrlSelector } from '@/track/dash/util/uriResolution'\nimport { createDefaultDashManifestTransformer } from '@/track/dash/createDefaultDashManifestTransformer'\nimport { createMediaSource } from '@/util/media/mediaSource'\nimport {\n createDefaultDashMediaQualityMetadataResolver,\n type DashMediaQualityMetadataResolverDeps,\n} from '@/track/dash/DashMediaQualityMetadataResolver'\nimport {\n MediaSourceControllerImpl,\n type MediaSourceControllerImplDeps,\n} from '@/streaming/buffering/MediaSourceController'\nimport type { PlaybackController } from '@/playback/PlaybackController'\nimport {\n type DashManifestController,\n DashManifestControllerImpl,\n type DashManifestControllerImplDeps,\n} from '@/track/dash/DashManifestController'\nimport { createDashContentStreamFactories } from '@/track/dash/createDashContentStreamFactories'\nimport type { DrmKeySystemResolver } from '@/drm/DrmKeySystemResolver'\nimport type { DrmController } from '@/drm/DrmController'\nimport type { Capabilities } from '@/client/Capabilities'\nimport {\n QualitySelectorImpl,\n type QualitySelectorImplOptions,\n} from '@/streaming/abr/QualitySelectorImpl'\nimport type { PlaybackSource } from '@/playback/PlaybackSource'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport { createDashManifestProvider } from '@/track/dash/createDashManifestProvider'\nimport { createContentStreamFactory } from '@/streaming/ContentStream'\nimport type { ContentStreamingOptions } from '@/streaming/ContentStreamingOptions'\nimport { createDashContentTypesValue } from '@/track/dash/createDashContentTypesValue'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { VinylOptions } from '@/vinyl/VinylOptions'\nimport {\n buildDashMediaTimeline,\n type BuildDashMediaTimelineDeps,\n} from '@/track/dash/buildDashMediaTimeline'\nimport { createDefaultMediaTimelineTransformer } from '@/streaming/createDefaultMediaTimelineTransformer'\nimport type { DashManifestData } from '@/track/dash/DashManifestProvider'\n\n/**\n * Player-level dependencies needed for the Dash-specific factories.\n */\nexport interface DashFactoryDeps {\n readonly options: ObservableValue<{\n readonly abr: QualitySelectorImplOptions\n readonly preferredAudioLanguage: string | null\n }>\n readonly playbackController: PlaybackController\n readonly playbackSource: PlaybackSource\n readonly drmKeySystemResolver: DrmKeySystemResolver\n readonly requestInterceptor: RequestInterceptor\n readonly drmController: DrmController\n readonly capabilities: Capabilities\n}\n\nexport type DashInitOptions = {\n readonly streaming?: Maybe<ContentStreamingOptions>\n}\n\n/**\n * Returns a function that provides default dependency factories required for\n * a new DashTrack.\n */\nexport function createDashFactories(options: Maybe<DashInitOptions>) {\n return (\n // Player-level dependencies\n deps: DashFactoryDeps\n ) => {\n return (loadOptions: DashTrackLoadOptions) =>\n validateFactories({\n // Track-level dependencies\n ...externalDependencies(deps),\n\n contentTypesValue: createDashContentTypesValue,\n baseUrlSelector: () => pickFirstBaseUrlSelector,\n segmentRequestInit: () => loadOptions.segmentRequestInit,\n manifestProvider: createDashManifestProvider(loadOptions),\n manifestController: (\n deps: DashManifestControllerImplDeps\n ): DashManifestController =>\n new DashManifestControllerImpl(deps),\n mediaSourceFactory: () => createMediaSource,\n mediaQualityMetadataResolver: (\n deps: DashMediaQualityMetadataResolverDeps\n ) => createDefaultDashMediaQualityMetadataResolver(deps),\n mediaSourceController: (deps: MediaSourceControllerImplDeps) =>\n new MediaSourceControllerImpl(deps),\n\n createContentStreamFactories: createDashContentStreamFactories(\n options?.streaming\n ),\n contentStreamFactory: createContentStreamFactory,\n\n qualitySelector: (deps: {\n options: ObservableValue<Pick<VinylOptions, 'abr'>>\n }) =>\n new QualitySelectorImpl({\n options: deps.options.pick('abr'),\n }),\n manifestTransformed: createDefaultDashManifestTransformer,\n mediaTimeline: (\n deps: BuildDashMediaTimelineDeps & {\n readonly manifestTransformed: ObservableValue<\n Promise<DashManifestData>\n >\n }\n ) =>\n deps.manifestTransformed.map(async (manifestPromise) => {\n const data = await manifestPromise\n return buildDashMediaTimeline(deps, data)\n }),\n mediaTimelineTransformed: createDefaultMediaTimelineTransformer,\n } as const) satisfies Factories<DashTrackDeps>\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe } from '@amazon/vinyl-util'\nimport type { RequestInitOptions } from '@amazon/vinyl-util'\nimport type {\n MutableRequestParams,\n RequestInterceptor,\n} from '@amazon/vinyl-util'\nimport { noop } from '@amazon/vinyl-util'\nimport { clone, getLocation, resolveUrl } from '@amazon/vinyl-util'\nimport { requestWithRetry } from '@amazon/vinyl-util'\nimport { parseDashManifest } from '@amazon/vinyl-mpd-parser'\nimport type { DashManifestProvider } from '@/track/dash/DashManifestProvider'\n\n/**\n * Creates a DashManifestProvider which performs a request to retrieve a dash manifest.\n * Can be a relative path.\n *\n * Usage example:\n *\n * ```createRequesterDashManifestProvider('https://example.com/manifest.mpd')```\n * @param input The resource location of the dash manifest.\n * @param init Optional request options such as headers.\n * @param requestInterceptor An optional transformer to mutate request parameters before the request is made.\n */\nexport function urlDashManifestProvider(\n input: string,\n init?: Maybe<RequestInitOptions>,\n requestInterceptor: RequestInterceptor = noop\n): DashManifestProvider {\n return async (abort) => {\n const params: MutableRequestParams = {\n input: resolveUrl(input, getLocation().href),\n init: clone(init) ?? {},\n }\n requestInterceptor(params)\n const response = await requestWithRetry(params.input, params.init, {\n abort,\n })\n const xml = await response.text()\n const manifest = parseDashManifest(xml)\n const baseInput = response.url || params.input\n return {\n manifest,\n baseUrl: resolveUrl('./', baseInput),\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DashTrackLoadOptions } from '@/track/dash/DashTrack'\nimport { urlDashManifestProvider } from '@/track/dash/urlDashManifestProvider'\nimport type { RequestInterceptor } from '@amazon/vinyl-util'\n\n/**\n * Creates a DashManifestProvider which uses the manifestProvider set on the loadOptions, or a urlDashManifestProvider\n * if unset, which will use the loadOptions.uri as the manifest location.\n *\n * @param loadOptions\n */\nexport function createDashManifestProvider(loadOptions: DashTrackLoadOptions) {\n return (deps: { readonly requestInterceptor: RequestInterceptor }) => {\n return loadOptions.manifestProvider\n ? loadOptions.manifestProvider\n : urlDashManifestProvider(\n loadOptions.uri,\n loadOptions.requestInit,\n deps.requestInterceptor\n )\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createDisposer,\n type Disposable,\n EventHostImpl,\n type Maybe,\n type ReadonlyEventHost,\n type ReadonlyRanges,\n redispatchEvents,\n} from '@amazon/vinyl-util'\nimport type { StreamingEventMap } from '@/streaming/StreamingEventMap'\nimport type { SegmentController } from '@/streaming/SegmentController'\nimport type { BufferingController } from '@/streaming/buffering/BufferingController'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport { createContainer, type Factories } from '@amazon/vinyl-di'\n\n/**\n * Creates a new ContentStream for the given content type.\n */\nexport type ContentStreamFactory = (contentType: ContentType) => ContentStream\n\nexport interface ContentStream\n extends ReadonlyEventHost<StreamingEventMap>, Disposable {\n /**\n * The content type for this stream.\n * E.g. 'audio' or 'video'\n */\n readonly contentType: ContentType\n\n /**\n * The prefetched time ranges.\n */\n readonly fetchedRanges: ReadonlyRanges\n\n /**\n * The quality currently being requested.\n */\n readonly streamingQuality: MediaQualityMetadata | null\n\n /**\n * The quality of the currently buffered media for this stream.\n */\n readonly bufferingQuality: MediaQualityMetadata | null\n\n /**\n * The quality for the currently buffered media at currentTime for this stream.\n */\n readonly playbackQuality: MediaQualityMetadata | null\n\n /**\n * The error, if in an error state.\n */\n readonly error: Error | null\n\n /**\n * True if the last segment has been appended.\n */\n readonly bufferingEnded: boolean\n\n /**\n * Starts prefetching with the given priority and prefetch start time.\n * @param options\n */\n preload(options: ContentStreamPreloadOptions): void\n\n clearPrefetch(): void\n\n /**\n * Resets the track to recover from error states.\n * Resets both the segment controller and buffering controller to clear failed segments and error conditions.\n */\n reset(): void\n\n /**\n * Activates the content stream, activating sub-controllers.\n */\n activate(options: ContentStreamActivateOptions): void\n\n /**\n * Deactivates the content stream, deactivating sub-controllers.\n */\n deactivate(): void\n}\n\nexport interface ContentStreamPreloadOptions {\n /**\n * Track priority for prefetching.\n * Higher values take precedence.\n */\n readonly prefetchPriority: number\n\n /**\n * The media presentation time (in seconds) to begin prefetching.\n */\n readonly startTime?: Maybe<number>\n}\n\nexport interface ContentStreamActivateOptions {\n /**\n * The media presentation time (in seconds) to seek to.\n */\n readonly startTime?: Maybe<number>\n}\n\nexport interface ContentStreamImplDeps {\n readonly bufferingController: BufferingController\n readonly segmentController: SegmentController\n}\n\nexport class ContentStreamImpl\n extends EventHostImpl<StreamingEventMap>\n implements ContentStream\n{\n private disposer = /* @__PURE__ */ createDisposer()\n private readonly segmentController: SegmentController\n private readonly bufferingController: BufferingController\n\n constructor(\n dependencyFactories: Factories<ContentStreamImplDeps>,\n readonly contentType: ContentType\n ) {\n super()\n const { add } = this.disposer\n const deps = add(createContainer(dependencyFactories)).dependencies\n\n this.segmentController = deps.segmentController\n redispatchEvents(this, this.segmentController, ['fetchedRangesChange'])\n\n this.bufferingController = deps.bufferingController\n redispatchEvents(this, this.segmentController, [\n 'streamingQualityChange',\n ])\n redispatchEvents(this, this.bufferingController, [\n 'bufferingQualityChange',\n 'playbackQualityChange',\n 'bufferingEnded',\n 'error',\n ])\n }\n\n preload(options: ContentStreamPreloadOptions) {\n this.segmentController.configure({\n startTime: options.startTime ?? 0,\n trackPrefetchPriority: options.prefetchPriority,\n })\n }\n\n get fetchedRanges(): ReadonlyRanges {\n return this.segmentController.fetchedRanges\n }\n\n get streamingQuality(): MediaQualityMetadata | null {\n return this.segmentController.streamingQuality ?? null\n }\n\n get bufferingQuality(): MediaQualityMetadata | null {\n return this.bufferingController.bufferingQuality ?? null\n }\n\n get playbackQuality(): MediaQualityMetadata | null {\n return this.bufferingController.playbackQuality ?? null\n }\n\n get bufferingEnded(): boolean {\n return this.bufferingController.bufferingEnded\n }\n\n get error(): Error | null {\n return this.bufferingController.error ?? this.segmentController.error\n }\n\n /**\n * Clears all fetched fragments and source buffers. Streaming will resume.\n * This should be called if a change has been made where the user would expect an immediate change,\n * for example, changing streaming quality from SD to HD.\n */\n clearPrefetch() {\n this.segmentController.clear()\n this.bufferingController.clear()\n }\n\n /**\n * Resets the track to recover from error states.\n * Resets both the segment controller and buffering controller to clear failed segments and error conditions.\n */\n reset(): void {\n this.segmentController.reset()\n this.bufferingController.reset()\n }\n\n activate(options: ContentStreamActivateOptions): void {\n this.segmentController.configure({\n startTime: options.startTime ?? 0,\n })\n this.segmentController.activate()\n this.bufferingController.activate()\n }\n\n deactivate(): void {\n this.segmentController.deactivate()\n this.bufferingController.deactivate()\n }\n\n dispose(): void {\n super.dispose()\n this.disposer.dispose()\n }\n}\n\n/**\n * The `Factory` to create a function which satisfies `ContentStreamFactory`.\n */\nexport function createContentStreamFactory(deps: {\n readonly createContentStreamFactories: (\n contentType: ContentType\n ) => Factories<ContentStreamImplDeps>\n}) {\n return ((contentType: ContentType) => {\n return new ContentStreamImpl(\n deps.createContentStreamFactories(contentType),\n contentType\n )\n }) satisfies ContentStreamFactory\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DashManifestData } from '@/track/dash/DashManifestProvider'\nimport type { DashMediaQualityMetadataResolver } from '@/track/dash/DashMediaQualityMetadataResolver'\nimport { flattenRepresentations } from '@/track/dash/util/mpd'\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\nimport type { ContentTypesValue } from '@/streaming/ContentTypesValue'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { DashManifest } from '@amazon/vinyl-mpd-parser'\n\nexport interface DashContentTypesValueDeps {\n readonly manifestTransformed: ObservableValue<Promise<DashManifestData>>\n readonly mediaQualityMetadataResolver: DashMediaQualityMetadataResolver\n}\n\n/**\n * Creates an ObservableValue for the types of streams that are available in the\n * filtered dash manifest.\n */\nexport function createDashContentTypesValue(\n deps: DashContentTypesValueDeps\n): ContentTypesValue {\n return deps.manifestTransformed.map(async (manifestAndPath) => {\n return getContentTypes(deps, (await manifestAndPath).manifest)\n })\n}\n\n/**\n * Determines the types of streams that are available in the filtered dash\n * manifest.\n *\n * Given a Dash manifest, this will resolve to the set of content types present.\n */\nfunction getContentTypes(\n deps: DashContentTypesValueDeps,\n manifest: DashManifest\n): Set<ContentType> {\n const contentTypes = new Set<ContentType>()\n for (const period of manifest.MPD.Period) {\n if (!period.AdaptationSet) continue\n const mediaMetadata = flattenRepresentations(period).map(\n deps.mediaQualityMetadataResolver\n )\n for (const { contentType } of mediaMetadata) {\n if (contentType) contentTypes.add(contentType)\n }\n }\n return contentTypes\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe, MaybePromise } from '@amazon/vinyl-util'\nimport {\n ErrorOrigin,\n getSidxSampleTimes,\n parseSidxBox,\n ValidationError,\n} from '@amazon/vinyl-util'\nimport type {\n ByteRange,\n MultipleSegmentBaseType,\n RepresentationType,\n SegmentBaseType,\n SegmentListType,\n SegmentTemplateType,\n SegmentTimelineType,\n} from '@amazon/vinyl-mpd-parser'\nimport {\n calculatePeriodTimeRange,\n getSegmentBase,\n getSegmentList,\n getSegmentTemplate,\n type PeriodRange,\n sampleToMpdTime,\n} from '@/track/dash/util/mpd'\nimport {\n type DashUriResolveDeps,\n resolveDashUri,\n segmentTemplateUrl,\n} from '@/track/dash/util/uriResolution'\nimport {\n createSegmentDataProvider,\n type CreateSegmentDataProviderDeps,\n} from '@/track/createSegmentDataProvider'\nimport { getSegmentAtTime } from '@/streaming/util/segment'\nimport type {\n MediaSegmentReference,\n SegmentReference,\n} from '@/streaming/SegmentReference'\nimport type { SegmentDataProvider } from '@/streaming/SegmentDataSlot'\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\nimport type { DashMediaQualityMetadataResolver } from '@/track/dash/DashMediaQualityMetadataResolver'\n\nexport interface DashSegmentProviderDeps\n extends DashUriResolveDeps, CreateSegmentDataProviderDeps {\n /**\n * Produces abstract metadata from a dash representation.\n */\n readonly mediaQualityMetadataResolver: DashMediaQualityMetadataResolver\n}\n\nexport interface DashRepresentationSegmentProvider {\n /**\n * Gets a segment reference within this representation for the given time, in seconds, relative to the period.\n *\n * @param time\n * @param affordance Forward-snap tolerance in seconds: if `time` falls just before a\n * segment's start (within `affordance`), that segment is returned. Defaults to `0`.\n */\n getSegment(\n time: number,\n affordance?: number\n ): Promise<SegmentReference<SegmentDataProvider> | null>\n}\n\ninterface GetTimelineOptions {\n readonly baseUrl: string\n readonly representation: RepresentationType\n readonly periodTimeRange: PeriodRange\n}\n\n/**\n * Metadata and a data provider for a segment.\n */\ntype DataSegmentRef = MediaSegmentReference<SegmentDataProvider>\n\n/**\n * Creates a representation timeline for the given representation.\n */\nexport function createDashRepresentationSegmentProvider(\n deps: DashSegmentProviderDeps,\n baseUrl: string,\n representation: RepresentationType\n): DashRepresentationSegmentProvider {\n const quality: MediaQualityMetadata =\n deps.mediaQualityMetadataResolver(representation)\n const options: GetTimelineOptions = {\n baseUrl,\n periodTimeRange: calculatePeriodTimeRange(representation.parent.parent),\n representation,\n }\n\n // 5.3.9.1 General\n // The elements SegmentBase, SegmentTemplate and SegmentList may be present in the\n // Representation element itself. In addition, to express default values, they may be present in the\n // Period and AdaptationSet element. At each level at most one of the three, SegmentBase,\n // SegmentTemplate and SegmentList, shall be present. Further, if SegmentTemplate or SegmentList is present on\n // one level of the hierarchy, then the other one shall not be present on any lower hierarchy level.\n\n const segmentTemplate = getSegmentTemplate(representation)\n const segmentList = getSegmentList(representation)\n const segmentBase = getSegmentBase(representation)\n\n let segmentsPromise: MaybePromise<\n readonly MediaSegmentReference<SegmentDataProvider>[]\n > | null = null\n\n let initUri: Maybe<string>\n let initRange: Maybe<ByteRange>\n\n if (segmentTemplate?.initialization) {\n initUri = segmentTemplateUrl(segmentTemplate.initialization, {\n representation,\n })\n }\n\n const commonSegmentBase = segmentTemplate ?? segmentList ?? segmentBase\n if (!commonSegmentBase)\n throw new ValidationError(\n 'Manifest must have one of SegmentList, SegmentTemplate, or SegmentBase',\n ErrorOrigin.MEDIA\n )\n\n if (commonSegmentBase.Initialization) {\n initUri = commonSegmentBase.Initialization.sourceURL\n initRange = commonSegmentBase.Initialization.range\n }\n\n if (!initUri && !initRange)\n throw new ValidationError(\n 'Missing initialization range',\n ErrorOrigin.MEDIA\n )\n\n const { url: initUrl, serviceLocation: initServiceLocation } =\n resolveDashUri(deps, { baseUrl, representation, uri: initUri })\n const initData = createSegmentDataProvider(deps, {\n url: initUrl,\n mediaRange: initRange,\n serviceId: initServiceLocation,\n reportDownlinkMetrics: false,\n })\n\n let getSegmentReferences: () => MaybePromise<\n readonly MediaSegmentReference<SegmentDataProvider>[]\n >\n\n // If an index range is present, use that to calculate segment data.\n // The index location may be defined in several locations:\n // SegmentBase.indexRange, SegmentBase.RepresentationIndex, or SegmentTemplate.index\n // One of segmentList, segmentTemplate, or segmentBase is guaranteed to be set.\n if (segmentList) {\n getSegmentReferences = () =>\n createSegmentsFromSegmentList(deps, {\n ...options,\n segmentList,\n })\n } else if (segmentTemplate) {\n getSegmentReferences = () =>\n createSegmentsFromSegmentTemplate(deps, {\n ...options,\n segmentTemplate,\n })\n } else if (segmentBase) {\n getSegmentReferences = () =>\n createSegmentsFromSegmentBase(deps, {\n ...options,\n segmentBase,\n })\n }\n\n return {\n async getSegment(\n time: number,\n affordance = 0\n ): Promise<SegmentReference<SegmentDataProvider> | null> {\n if (!segmentsPromise) segmentsPromise = getSegmentReferences()\n const segments = await Promise.resolve(segmentsPromise).catch(\n (error) => {\n // When the segments list fails (for example the sidx range request fails),\n // retry on the next request.\n segmentsPromise = null\n throw error\n }\n )\n const segment = getSegmentAtTime(time, segments, affordance)\n if (!segment) return null\n return {\n quality,\n ...segment,\n initData,\n }\n },\n }\n}\n\n/**\n * Creates a segment list when the representation has a SegmentList.\n */\nfunction createSegmentsFromSegmentList(\n deps: DashSegmentProviderDeps,\n options: GetTimelineOptions & {\n readonly segmentList: SegmentListType\n }\n): readonly DataSegmentRef[] {\n const { baseUrl, periodTimeRange, representation, segmentList } = options\n const segmentUrls = segmentList.SegmentURL\n if (segmentUrls) {\n // Fabricate a segment timeline from the segment duration.\n const timescale = getTimescale(segmentList)\n const sampleTimes = calculateSegmentSampleTimes({\n multipleSegmentBase: segmentList,\n periodTimeRange,\n numSegments: segmentUrls.length,\n })\n const presentationTimeOffset = segmentList.presentationTimeOffset ?? 0\n\n return createTimeline(\n {\n sampleTimes,\n presentationTimeOffset,\n periodTimeRange,\n timescale,\n },\n (i) => {\n const segmentUrl = segmentUrls[i]\n const { url, serviceLocation } = resolveDashUri(deps, {\n baseUrl,\n uri: segmentUrl.media,\n representation,\n })\n return createSegmentDataProvider(deps, {\n url,\n mediaRange: segmentUrl.mediaRange,\n serviceId: serviceLocation,\n reportDownlinkMetrics: true,\n })\n }\n )\n } else {\n if (segmentList.href) {\n throw new ValidationError(\n 'SegmentList.href currently unsupported',\n ErrorOrigin.MEDIA\n )\n } else {\n throw new ValidationError(\n 'could not determine segments from SegmentList',\n ErrorOrigin.MEDIA\n )\n }\n }\n}\n\n/**\n * SegmentTemplate contains URIs with template tokens, as defined in 5.3.9.4.4.\n *\n * @see segmentTemplateUrl\n */\nfunction createSegmentsFromSegmentTemplate(\n deps: DashSegmentProviderDeps,\n options: GetTimelineOptions & {\n readonly segmentTemplate: SegmentTemplateType\n }\n): readonly DataSegmentRef[] {\n const { baseUrl, periodTimeRange, representation, segmentTemplate } =\n options\n if (!segmentTemplate.media) {\n throw new ValidationError(\n 'SegmentTemplate.media required',\n ErrorOrigin.MEDIA\n )\n }\n const media = segmentTemplate.media\n const presentationTimeOffset = segmentTemplate.presentationTimeOffset ?? 0\n\n const sampleTimes = calculateSegmentSampleTimes({\n multipleSegmentBase: segmentTemplate,\n periodTimeRange,\n })\n\n const timescale = getTimescale(segmentTemplate)\n let segmentNumber = segmentTemplate.startNumber ?? 1\n return createTimeline(\n {\n timescale,\n presentationTimeOffset,\n periodTimeRange,\n sampleTimes,\n },\n (_, sampleTime) => {\n const uri = segmentTemplateUrl(media, {\n representation,\n sampleTime,\n segmentNumber: segmentNumber++,\n })\n const { url, serviceLocation } = resolveDashUri(deps, {\n baseUrl,\n uri,\n representation,\n })\n return createSegmentDataProvider(deps, {\n url,\n serviceId: serviceLocation,\n reportDownlinkMetrics: true,\n })\n }\n )\n}\n\n/**\n * When SegmentBase is provided, get the timeline from the index range.\n */\nasync function createSegmentsFromSegmentBase(\n deps: DashSegmentProviderDeps,\n options: GetTimelineOptions & {\n readonly segmentBase: SegmentBaseType\n }\n): Promise<readonly DataSegmentRef[]> {\n const { baseUrl, periodTimeRange, representation, segmentBase } = options\n if (segmentBase.indexRange) {\n // Load the sidx box from the mp4.\n const indexRange = segmentBase.indexRange\n const { url: indexUrl, serviceLocation: indexServiceLocation } =\n resolveDashUri(deps, { baseUrl, representation })\n const sidx = parseSidxBox(\n await createSegmentDataProvider(deps, {\n url: indexUrl,\n mediaRange: indexRange,\n serviceId: indexServiceLocation,\n reportDownlinkMetrics: false,\n })()\n )\n\n const sampleTimes = getSidxSampleTimes(sidx)\n let rangeStart = Number(sidx.firstOffset) + indexRange[1]! + 1\n return createTimeline(\n {\n sampleTimes,\n periodTimeRange,\n presentationTimeOffset: segmentBase.presentationTimeOffset ?? 0,\n timescale: sidx.timescale,\n },\n (i) => {\n const segmentReference = sidx.references[i]\n const size = segmentReference.referencedSize\n const provider = createSegmentDataProvider(deps, {\n url: indexUrl,\n mediaRange: [rangeStart, rangeStart + size - 1],\n serviceId: indexServiceLocation,\n reportDownlinkMetrics: true,\n })\n rangeStart += size\n return provider\n }\n )\n } else {\n throw new ValidationError('Manifest missing segments')\n }\n}\n\n/**\n * Returns an array of start times, in timescale units for the segments in the given multiple segment base.\n * The last time in the list will be the end time, in timescale units.\n */\nfunction calculateSegmentSampleTimes(options: {\n readonly multipleSegmentBase: MultipleSegmentBaseType\n readonly periodTimeRange: PeriodRange\n readonly numSegments?: Maybe<number>\n}): readonly number[] {\n const { multipleSegmentBase, periodTimeRange } = options\n const timescale = getTimescale(multipleSegmentBase)\n\n let startTimes: readonly number[]\n if (multipleSegmentBase.SegmentTimeline) {\n startTimes = calculateSampleTimesFromSegmentTimeline(\n multipleSegmentBase.SegmentTimeline\n )\n } else {\n // Fabricate a segment timeline from the segment duration.\n const sampleDuration = getSampleDuration(multipleSegmentBase) // The unscaled duration\n startTimes = calculateFixedSegmentSampleTimes({\n timescale,\n periodTimeRange,\n sampleDuration,\n numSegments: options.numSegments,\n })\n }\n return startTimes\n}\n\n/**\n * Given a SegmentTimeline element, calculates the sample start times of each segment, in timescale units.\n * The last time in the list will be the end time, in timescale units.\n */\nfunction calculateSampleTimesFromSegmentTimeline(\n segmentTimeline: SegmentTimelineType\n): readonly number[] {\n const out: number[] = new Array((segmentTimeline.S?.length ?? 0) + 1)\n let startTime = 0\n let c = 0\n\n segmentTimeline.S?.forEach((s) => {\n // If the start time 't' is defined, use it, otherwise use the calculated current time\n startTime = s.t != null ? s.t : startTime\n\n // Calculate segment details for the number of repeats\n for (let i = 0; i <= s.r; i++) {\n out[c++] = startTime\n startTime += s.d\n }\n })\n out[c++] = startTime\n return out\n}\n\n/**\n * Creates media segment sample start times, in timescale units, with a given duration.\n * The last time in the list will be the duration, in timescale units.\n *\n * @param options\n */\nfunction calculateFixedSegmentSampleTimes(options: {\n readonly sampleDuration: number\n readonly timescale: number\n readonly periodTimeRange: PeriodRange\n readonly numSegments?: Maybe<number>\n}): readonly number[] {\n const { sampleDuration, timescale } = options\n const [periodStart, periodEnd] = options.periodTimeRange\n if (periodEnd == null)\n throw new ValidationError(\n 'MPD.mediaPresentationDuration or Period.duration required',\n ErrorOrigin.MEDIA\n )\n const numSegments =\n options.numSegments ??\n Math.ceil((periodEnd - periodStart) / (sampleDuration / timescale))\n const out: number[] = new Array(numSegments + 1)\n let startTime = 0\n for (let i = 0; i < numSegments; i++) {\n out[i] = startTime\n startTime += sampleDuration\n }\n out[numSegments] = periodEnd * timescale\n return out\n}\n\n/**\n * Creates a timeline of DataSegmentRef objects from a sample timeline list and a data provider factory.\n *\n * @param sampleTimes The list of sample times, in timescale units, to convert into MPD presentation times.\n * @param periodTimeRange The time range of the period, in seconds.\n * @param presentationTimeOffset The presentation time offset, in samples per second.\n * @param timescale The timescale units, in samples per second.\n * @param dataProviderFactory Creates the data provider for the segment at the given index and sample start time.\n */\nfunction createTimeline(\n {\n sampleTimes,\n periodTimeRange,\n presentationTimeOffset,\n timescale,\n }: {\n sampleTimes: readonly number[]\n periodTimeRange: PeriodRange\n presentationTimeOffset: number\n timescale: number\n },\n dataProviderFactory: (i: number, sampleTime: number) => SegmentDataProvider\n): readonly DataSegmentRef[] {\n const [periodStart, periodEnd] = periodTimeRange\n const mpdTimes = sampleTimes.map((sampleTime) => {\n return sampleToMpdTime(\n sampleTime,\n periodStart,\n presentationTimeOffset,\n timescale\n )\n })\n const n = mpdTimes.length - 1\n const out = new Array<DataSegmentRef>(n)\n for (let i = 0; i < n; i++) {\n const startTime = mpdTimes[i]\n const endTime = mpdTimes[i + 1]\n out[i] = {\n data: dataProviderFactory(i, sampleTimes[i]),\n timestampOffset: startTime,\n startTime: Math.max(periodStart, startTime),\n endTime: periodEnd == null ? endTime : Math.min(periodEnd, endTime),\n }\n }\n return out\n}\n\n/**\n * Validates that timescale is set, returning it.\n *\n * @param multipleSegmentBase\n */\nfunction getTimescale(multipleSegmentBase: MultipleSegmentBaseType): number {\n if (!multipleSegmentBase.timescale)\n throw new ValidationError('invalid timescale', ErrorOrigin.MEDIA)\n return multipleSegmentBase.timescale\n}\n\n/**\n * Validates that duration is set, returning it.\n *\n * @param multipleSegmentBase\n */\nfunction getSampleDuration(\n multipleSegmentBase: MultipleSegmentBaseType\n): number {\n if (!multipleSegmentBase.duration)\n throw new ValidationError('invalid duration', ErrorOrigin.MEDIA)\n return multipleSegmentBase.duration\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n Maybe,\n Mutable,\n MutableRequestParams,\n ReadonlyAbort,\n RequestInitOptions,\n RequestInterceptor,\n Timestamp,\n} from '@amazon/vinyl-util'\nimport {\n getHostname,\n last,\n networkMetricsController,\n normalizeHeadersInit,\n requestWithRetry,\n} from '@amazon/vinyl-util'\nimport { type ByteRange, stringifyByteRange } from '@amazon/vinyl-mpd-parser'\nimport type { SegmentDataProvider } from '@/streaming/SegmentDataSlot'\n\nexport interface CreateSegmentDataProviderDeps {\n readonly requestInterceptor: RequestInterceptor\n readonly segmentRequestInit: Maybe<RequestInitOptions>\n}\n\nexport interface CreateSegmentDataProviderOptions {\n readonly url: string\n readonly mediaRange?: Maybe<ByteRange>\n readonly serviceId?: Maybe<string>\n /**\n * If true, reports downlink transfer speeds to network metrics.\n */\n readonly reportDownlinkMetrics: boolean\n}\n\nexport function createSegmentDataProvider(\n deps: CreateSegmentDataProviderDeps,\n options: CreateSegmentDataProviderOptions\n): SegmentDataProvider {\n return async (abort?: Maybe<ReadonlyAbort>) => {\n const init: Mutable<RequestInitOptions> = {\n ...deps.segmentRequestInit,\n }\n if (options.mediaRange) {\n init.headers = {\n ...normalizeHeadersInit(init.headers),\n Range: `bytes=${stringifyByteRange(options.mediaRange)}`,\n }\n }\n\n const params: MutableRequestParams = {\n input: options.url,\n init,\n }\n deps.requestInterceptor(params)\n\n const serviceId = options.serviceId ?? getHostname(options.url)\n const requestStart = Date.now()\n const response = await requestWithRetry(params.input, params.init, {\n serviceId,\n abort,\n })\n const responseEnd = Date.now()\n\n const arrayBuffer = await response.arrayBuffer()\n const contentEnd = Date.now()\n\n let responseStart: Timestamp | null = null\n if ('getEntriesByName' in performance) {\n const lastRequest: any = last(\n performance.getEntriesByName(params.input)\n )\n if (lastRequest) {\n // Resource timing information was available, use it to get a more accurate response start time. A\n // value of 0 means timing information was denied, likely due to a cross-origin request without\n // Timing-Allow-Origin response headers.\n if (lastRequest.responseStart) {\n responseStart =\n performance.timeOrigin + lastRequest.responseStart\n }\n }\n }\n\n if (options.reportDownlinkMetrics) {\n networkMetricsController.value.addDownlinkTransferEntry({\n bytes: arrayBuffer.byteLength,\n serviceId,\n requestStart,\n responseStart,\n responseEnd,\n contentEnd,\n })\n }\n return arrayBuffer\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DashManifestData } from '@/track/dash/DashManifestProvider'\nimport type {\n MediaPeriod,\n MediaQualityData,\n MediaTimeline,\n} from '@/streaming/MediaTimeline'\nimport type { RepresentationType } from '@amazon/vinyl-mpd-parser'\nimport {\n calculateDuration,\n calculatePeriodEnd,\n calculatePeriodStart,\n flattenRepresentations,\n} from '@/track/dash/util/mpd'\nimport {\n createDashRepresentationSegmentProvider,\n type DashSegmentProviderDeps,\n} from '@/track/dash/timeline/DashRepresentationSegmentProvider'\n\nexport type BuildDashMediaTimelineDeps = DashSegmentProviderDeps\n\n/**\n * Builds a MediaTimeline from a Dash manifest.\n */\nexport function buildDashMediaTimeline(\n deps: BuildDashMediaTimelineDeps,\n data: DashManifestData\n): MediaTimeline {\n const { manifest, baseUrl } = data\n const periods: MediaPeriod[] = manifest.MPD.Period.map((period) => {\n const startTime = calculatePeriodStart(period)\n const endTime = calculatePeriodEnd(period) ?? Infinity\n const representations = flattenRepresentations(period)\n const qualities: MediaQualityData[] = representations.map(\n (representation: RepresentationType): MediaQualityData => {\n const metadata =\n deps.mediaQualityMetadataResolver(representation)\n const segmentProvider = createDashRepresentationSegmentProvider(\n deps,\n baseUrl,\n representation\n )\n return {\n metadata,\n getSegment: (time: number, affordance?: number) =>\n segmentProvider.getSegment(time, affordance),\n }\n }\n )\n return { startTime, endTime, qualities }\n })\n const duration = calculateDuration(manifest)\n return {\n periods,\n minBufferTime: manifest.MPD.minBufferTime,\n getDuration: () => Promise.resolve(duration),\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { combineData } from '@amazon/vinyl-observable'\nimport type { Capabilities } from '@/client/Capabilities'\nimport type { DrmController } from '@/drm/DrmController'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\nimport {\n filterTimelineQualities,\n filterTimelineQualitiesAsync,\n} from '@/streaming/mediaTimelineFilter'\nimport { createLanguageFilter } from '@/streaming/mediaTimelineLanguageFilter'\nimport {\n canPlayMimeType,\n throwMimeTypesUnsupported,\n} from '@/track/filters/resourceTypeFilter'\nimport {\n canPlayKeySystem,\n throwKeySystemsUnsupported,\n} from '@/track/filters/keySystemFilter'\nimport {\n supportsAudioSamplingRate,\n throwSamplingRatesUnsupported,\n} from '@/track/filters/sampleRateFilter'\nimport { throwLanguagesUnsupported } from '@/track/filters/languageFilter'\n\nexport interface DefaultMediaTimelineTransformerDeps {\n readonly capabilities: Capabilities\n readonly drmController: DrmController\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly options: ObservableValue<{\n readonly preferredAudioLanguage: string | null\n }>\n}\n\n/**\n * The default media timeline transformer filters out unplayable qualities\n * and applies language preferences. Shared by Dash and HLS.\n */\nexport function createDefaultMediaTimelineTransformer(\n deps: DefaultMediaTimelineTransformerDeps\n): ObservableValue<Promise<MediaTimeline>> {\n async function transformTimeline(\n timeline: MediaTimeline\n ): Promise<MediaTimeline> {\n let t = filterTimelineQualities(\n (quality) => canPlayMimeType(deps, quality),\n throwMimeTypesUnsupported,\n timeline\n )\n t = await filterTimelineQualitiesAsync(\n (quality) => canPlayKeySystem(deps, quality),\n throwKeySystemsUnsupported,\n t\n )\n t = filterTimelineQualities(\n (quality, index, array) =>\n supportsAudioSamplingRate(deps, quality, index, array),\n throwSamplingRatesUnsupported,\n t\n )\n t = filterTimelineQualities(\n createLanguageFilter(\n deps.options.value.preferredAudioLanguage,\n 'audio'\n ),\n throwLanguagesUnsupported,\n t\n )\n return t\n }\n\n return combineData({\n timeline: deps.mediaTimeline,\n preferredAudioLanguage: deps.options.pick('preferredAudioLanguage'),\n }).map(async ({ timeline }) => {\n return transformTimeline(await timeline)\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n MediaPeriod,\n MediaQualityData,\n MediaTimeline,\n} from '@/streaming/MediaTimeline'\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\nimport type {\n FilterPredicate,\n FilterPredicateAsync,\n Maybe,\n} from '@amazon/vinyl-util'\nimport { map, memoize } from '@amazon/vinyl-util'\n\n/**\n * Filters qualities in a MediaTimeline using a synchronous predicate.\n * If filtering would remove all qualities from any period, throws via `throwError`.\n */\nexport function filterTimelineQualities(\n filter: Maybe<FilterPredicate<MediaQualityMetadata>>,\n throwError: () => never,\n timeline: MediaTimeline\n): MediaTimeline {\n if (!filter) return timeline\n const mapMetadataArray = memoize(\n (qualities: readonly MediaQualityData[]) =>\n map(qualities, (q) => q.metadata),\n (qualities) => qualities,\n 1\n )\n\n const periods = timeline.periods.map((period) => {\n const filtered = period.qualities.filter((q, index) =>\n filter(q.metadata, index, mapMetadataArray(period.qualities))\n )\n return { ...period, qualities: filtered }\n })\n\n if (periods.some((p) => p.qualities.length === 0)) {\n throwError()\n }\n\n return { ...timeline, periods }\n}\n\n/**\n * Filters qualities in a MediaTimeline using an asynchronous predicate.\n * If filtering would remove all qualities from any period, throws via `throwError`.\n */\nexport async function filterTimelineQualitiesAsync(\n filter: FilterPredicateAsync<MediaQualityMetadata>,\n throwError: () => never,\n timeline: MediaTimeline\n): Promise<MediaTimeline> {\n const mapMetadataArray = memoize(\n (qualities: readonly MediaQualityData[]) =>\n map(qualities, (q) => q.metadata),\n (qualities) => qualities,\n 1\n )\n\n const periods: MediaPeriod[] = []\n for (const period of timeline.periods) {\n const filtered: MediaQualityData[] = []\n const metadataArray = mapMetadataArray(period.qualities)\n for (let i = 0; i < period.qualities.length; i++) {\n if (await filter(period.qualities[i].metadata, i, metadataArray)) {\n filtered.push(period.qualities[i])\n }\n }\n periods.push({ ...period, qualities: filtered })\n }\n\n if (periods.some((p) => p.qualities.length === 0)) {\n throwError()\n }\n\n return { ...timeline, periods }\n}\n\n/**\n * Creates a language filter predicate for use with filterTimelineQualities.\n */\nexport { createLanguageFilter } from '@/streaming/mediaTimelineLanguageFilter'\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\nimport type { FilterPredicate } from '@amazon/vinyl-util'\nimport { memoize } from '@amazon/vinyl-util'\nimport {\n findBestLanguageMatch,\n languageRelatedness,\n} from '@/track/filters/languageFilter'\n\n/**\n * Creates a filter predicate that keeps qualities matching the preferred language.\n * The best language match is computed per period (per unique array reference),\n * so periods with different available languages are handled independently.\n *\n * Qualities not matching the content type or without a language tag are always kept.\n *\n * @param preferredLanguage BCP 47 language tag, or null to keep all.\n * @param contentType Only filter qualities matching this content type (e.g. 'audio').\n */\nexport function createLanguageFilter(\n preferredLanguage: string | null,\n contentType: string\n): FilterPredicate<MediaQualityMetadata> | null {\n if (!preferredLanguage) return null\n\n // Finds the best language for the period by relevance.\n // If no languages are related, the first language will be chosen.\n const bestRelevanceForPeriod = memoize(\n (array: ArrayLike<MediaQualityMetadata>) => {\n const langs = Array.from(array)\n .filter((q) => q.contentType === contentType && q.lang)\n .map((q) => q.lang!)\n return languageRelatedness(\n preferredLanguage,\n findBestLanguageMatch(preferredLanguage, langs)!\n )\n },\n (array) => array,\n 1\n )\n\n return (quality, _index, array) => {\n if (quality.contentType !== contentType) return true\n if (!quality.lang) return true\n const bestScore = bestRelevanceForPeriod(array)\n return languageRelatedness(preferredLanguage, quality.lang) >= bestScore\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { compareBy, max, MediaUnsupportedError } from '@amazon/vinyl-util'\n\nexport function throwLanguagesUnsupported(): never {\n throw new MediaUnsupportedError(\n 'No content matching preferred language',\n 'language'\n )\n}\n\n/**\n * Map from ISO 639-2 (3-letter) to ISO 639-1 (2-letter) codes.\n * Covers the most common languages encountered in streaming media.\n */\nconst iso3to2 = /* @__PURE__ */ new Map<string, string>([\n ['aar', 'aa'],\n ['abk', 'ab'],\n ['afr', 'af'],\n ['aka', 'ak'],\n ['amh', 'am'],\n ['ara', 'ar'],\n ['arg', 'an'],\n ['asm', 'as'],\n ['ava', 'av'],\n ['ave', 'ae'],\n ['aym', 'ay'],\n ['aze', 'az'],\n ['bak', 'ba'],\n ['bam', 'bm'],\n ['bel', 'be'],\n ['ben', 'bn'],\n ['bis', 'bi'],\n ['bod', 'bo'],\n ['bos', 'bs'],\n ['bre', 'br'],\n ['bul', 'bg'],\n ['cat', 'ca'],\n ['ces', 'cs'],\n ['cha', 'ch'],\n ['che', 'ce'],\n ['chu', 'cu'],\n ['chv', 'cv'],\n ['cor', 'kw'],\n ['cos', 'co'],\n ['cre', 'cr'],\n ['cym', 'cy'],\n ['dan', 'da'],\n ['deu', 'de'],\n ['div', 'dv'],\n ['dzo', 'dz'],\n ['ell', 'el'],\n ['eng', 'en'],\n ['epo', 'eo'],\n ['est', 'et'],\n ['eus', 'eu'],\n ['ewe', 'ee'],\n ['fao', 'fo'],\n ['fas', 'fa'],\n ['fij', 'fj'],\n ['fin', 'fi'],\n ['fra', 'fr'],\n ['fry', 'fy'],\n ['ful', 'ff'],\n ['gla', 'gd'],\n ['gle', 'ga'],\n ['glg', 'gl'],\n ['glv', 'gv'],\n ['grn', 'gn'],\n ['guj', 'gu'],\n ['hat', 'ht'],\n ['hau', 'ha'],\n ['heb', 'he'],\n ['her', 'hz'],\n ['hin', 'hi'],\n ['hmo', 'ho'],\n ['hrv', 'hr'],\n ['hun', 'hu'],\n ['hye', 'hy'],\n ['ibo', 'ig'],\n ['ido', 'io'],\n ['iii', 'ii'],\n ['iku', 'iu'],\n ['ile', 'ie'],\n ['ina', 'ia'],\n ['ind', 'id'],\n ['ipk', 'ik'],\n ['isl', 'is'],\n ['ita', 'it'],\n ['jav', 'jv'],\n ['jpn', 'ja'],\n ['kal', 'kl'],\n ['kan', 'kn'],\n ['kas', 'ks'],\n ['kat', 'ka'],\n ['kau', 'kr'],\n ['kaz', 'kk'],\n ['khm', 'km'],\n ['kik', 'ki'],\n ['kin', 'rw'],\n ['kir', 'ky'],\n ['kom', 'kv'],\n ['kon', 'kg'],\n ['kor', 'ko'],\n ['kua', 'kj'],\n ['kur', 'ku'],\n ['lao', 'lo'],\n ['lat', 'la'],\n ['lav', 'lv'],\n ['lim', 'li'],\n ['lin', 'ln'],\n ['lit', 'lt'],\n ['ltz', 'lb'],\n ['lub', 'lu'],\n ['lug', 'lg'],\n ['mah', 'mh'],\n ['mal', 'ml'],\n ['mar', 'mr'],\n ['mkd', 'mk'],\n ['mlg', 'mg'],\n ['mlt', 'mt'],\n ['mon', 'mn'],\n ['mri', 'mi'],\n ['msa', 'ms'],\n ['mya', 'my'],\n ['nau', 'na'],\n ['nav', 'nv'],\n ['nbl', 'nr'],\n ['nde', 'nd'],\n ['ndo', 'ng'],\n ['nep', 'ne'],\n ['nld', 'nl'],\n ['nno', 'nn'],\n ['nob', 'nb'],\n ['nor', 'no'],\n ['nya', 'ny'],\n ['oci', 'oc'],\n ['oji', 'oj'],\n ['ori', 'or'],\n ['orm', 'om'],\n ['oss', 'os'],\n ['pan', 'pa'],\n ['pli', 'pi'],\n ['pol', 'pl'],\n ['por', 'pt'],\n ['pus', 'ps'],\n ['que', 'qu'],\n ['roh', 'rm'],\n ['ron', 'ro'],\n ['run', 'rn'],\n ['rus', 'ru'],\n ['sag', 'sg'],\n ['san', 'sa'],\n ['sin', 'si'],\n ['slk', 'sk'],\n ['slv', 'sl'],\n ['sme', 'se'],\n ['smo', 'sm'],\n ['sna', 'sn'],\n ['snd', 'sd'],\n ['som', 'so'],\n ['sot', 'st'],\n ['spa', 'es'],\n ['sqi', 'sq'],\n ['srd', 'sc'],\n ['srp', 'sr'],\n ['ssw', 'ss'],\n ['sun', 'su'],\n ['swa', 'sw'],\n ['swe', 'sv'],\n ['tah', 'ty'],\n ['tam', 'ta'],\n ['tat', 'tt'],\n ['tel', 'te'],\n ['tgk', 'tg'],\n ['tgl', 'tl'],\n ['tha', 'th'],\n ['tir', 'ti'],\n ['ton', 'to'],\n ['tsn', 'tn'],\n ['tso', 'ts'],\n ['tuk', 'tk'],\n ['tur', 'tr'],\n ['twi', 'tw'],\n ['uig', 'ug'],\n ['ukr', 'uk'],\n ['urd', 'ur'],\n ['uzb', 'uz'],\n ['ven', 've'],\n ['vie', 'vi'],\n ['vol', 'vo'],\n ['wln', 'wa'],\n ['wol', 'wo'],\n ['xho', 'xh'],\n ['yid', 'yi'],\n ['yor', 'yo'],\n ['zha', 'za'],\n ['zho', 'zh'],\n ['zul', 'zu'],\n // Bibliographic codes (ISO 639-2/B) that differ from terminological codes\n ['alb', 'sq'],\n ['arm', 'hy'],\n ['baq', 'eu'],\n ['bur', 'my'],\n ['chi', 'zh'],\n ['cze', 'cs'],\n ['dut', 'nl'],\n ['fre', 'fr'],\n ['geo', 'ka'],\n ['ger', 'de'],\n ['gre', 'el'],\n ['ice', 'is'],\n ['mac', 'mk'],\n ['mao', 'mi'],\n ['may', 'ms'],\n ['per', 'fa'],\n ['rum', 'ro'],\n ['slo', 'sk'],\n ['tib', 'bo'],\n ['wel', 'cy'],\n])\n\n/**\n * Normalizes a BCP 47 / RFC 5646 language tag.\n *\n * - Converts ISO 639-2 (3-letter) codes to ISO 639-1 (2-letter)\n * - Forces language to lowercase, region to uppercase\n * - Discards script/dialect subtags beyond language-REGION\n *\n * Examples: `eng` \u2192 `en`, `en-us` \u2192 `en-US`, `fra-CA` \u2192 `fr-CA`\n */\nexport function normalizeLanguage(locale: string): string {\n const parts = locale.split('-')\n let language = (parts[0] || '').toLowerCase()\n language = iso3to2.get(language) || language\n const region = parts[1] ? parts[1].toUpperCase() : ''\n return region ? `${language}-${region}` : language\n}\n\n/**\n * Computes a relatedness score between two language codes.\n * Higher is better. 0 means unrelated.\n *\n * - 4: exact match after normalization (e.g. `en-US` vs `en-US`)\n * - 3: candidate is parent of target (e.g. `en` vs `en-US`)\n * - 2: candidate is sibling of target (e.g. `en-CA` vs `en-US`)\n * - 1: candidate is child of target (e.g. `en-US` vs `en`)\n * - 0: unrelated\n */\nexport function languageRelatedness(target: string, candidate: string): number {\n const t = normalizeLanguage(target)\n const c = normalizeLanguage(candidate)\n\n if (c === t) return 4\n\n const tParts = t.split('-')\n const cParts = c.split('-')\n\n if (tParts[0] !== cParts[0]) return 0\n\n // candidate is parent of target: candidate has no region, target does\n if (cParts.length === 1 && tParts.length === 2) return 3\n\n // candidate is sibling: both have regions (different, since exact match already checked)\n if (cParts.length === 2 && tParts.length === 2) return 2\n\n // candidate is child of target: target has no region, candidate does\n return 1 // tParts.length === 1 && cParts.length === 2\n}\n\n/**\n * Finds the best language match from a set of available languages.\n * Returns the best matching language, or undefined if the set is empty.\n * When no language is related, the first available language is returned.\n */\nexport function findBestLanguageMatch(\n target: string,\n available: ArrayLike<string>\n): string | undefined {\n return max(\n available,\n compareBy((lang) => languageRelatedness(target, lang))\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Capabilities } from '@/client/Capabilities'\nimport type { MediaFormatMetadata } from '@/streaming/MediaQualityMetadata'\nimport { MediaUnsupportedError } from '@amazon/vinyl-util'\n\nexport function throwMimeTypesUnsupported(): never {\n throw new MediaUnsupportedError(\n 'No resource type supported (container/codec).',\n 'resource-type'\n )\n}\n\n/**\n * Returns true when the media's codec and container is supported.\n */\nexport function canPlayMimeType(\n deps: { readonly capabilities: Capabilities },\n metadata: MediaFormatMetadata\n): boolean {\n if (!metadata.mimeType) return false\n return deps.capabilities.canPlayTypeMse(metadata.mimeType)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\nimport { type DrmController } from '@/drm/DrmController'\nimport { MediaUnsupportedError } from '@amazon/vinyl-util'\n\nexport function throwKeySystemsUnsupported(): never {\n throw new MediaUnsupportedError('No key system supported.', 'key-system')\n}\n\n/**\n * Returns true when the media's key system is supported or the representation has no content protection.\n */\nexport async function canPlayKeySystem(\n deps: { readonly drmController: DrmController },\n metadata: MediaQualityMetadata\n): Promise<boolean> {\n if (!metadata.contentProtections.length) return true // Is not content protected.\n return (await deps.drmController.isSupported(metadata)).supported\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaQualityMetadata } from '@/streaming/MediaQualityMetadata'\nimport {\n hasBrowser,\n Browser,\n last,\n MediaUnsupportedError,\n every,\n map,\n min,\n} from '@amazon/vinyl-util'\nimport type { Capabilities } from '@/client/Capabilities'\n\nexport function throwSamplingRatesUnsupported(): never {\n throw new MediaUnsupportedError('No supported sample rate', 'sampling-rate')\n}\n\n/**\n * Returns true when the media's sampling rate is supported.\n * If Firefox (which does not support >48kHz), filter out all sampling rates above the supported sampling rate.\n * All other browsers filter out all sampling rates above the supported sampling rate unless this will filter all\n * and then do not filter the lowest sampling rate.\n */\nexport function supportsAudioSamplingRate(\n deps: { readonly capabilities: Capabilities },\n metadata: MediaQualityMetadata,\n _index: number,\n array: ArrayLike<MediaQualityMetadata>\n): boolean {\n const isFirefox = hasBrowser(Browser.FIREFOX)\n const maxSampleRate = deps.capabilities.sampleRate\n const samplingRate = last(metadata.audioSamplingRate)\n\n if (!samplingRate || !maxSampleRate) return true // sampling rate not set\n\n if (isFirefox) {\n // Firefox: filter out all sampling rates above 48_000 Hz\n return samplingRate <= 48_000\n }\n\n // Other browsers: filter out all sampling rates above supported unless this will filter all\n if (samplingRate <= maxSampleRate) return true\n\n // Check if filtering all would remove everything\n const allAboveMax = every(array, (item) => {\n const itemSamplingRate = last(item.audioSamplingRate)\n return itemSamplingRate != null && itemSamplingRate > maxSampleRate\n })\n\n if (allAboveMax) {\n // Find the lowest sampling rate and only allow that one\n const samplingRates = map(array, (item) =>\n last(item.audioSamplingRate)\n ).filter((rate): rate is number => rate != null)\n const lowestSamplingRate = min(samplingRates)\n return samplingRate === lowestSamplingRate\n }\n\n return false\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AlternativeRendition,\n VariantStream,\n} from '@amazon/vinyl-hls-parser'\nimport type { MediaQualityMetadata } from '../../streaming/MediaQualityMetadata'\nimport { codecToContentType, contentTypeToMimeType } from '../mse/codec'\n\nexport type HlsMediaQualityMetadataResolver = (\n variant: VariantStream,\n renditions: readonly AlternativeRendition[]\n) => MediaQualityMetadata\n\nexport function createDefaultHlsMediaQualityMetadataResolver(): HlsMediaQualityMetadataResolver {\n return (variant, renditions) => {\n const codecs = variant.codecs || null\n // Use the first codec to determine the primary content type.\n const contentType = codecs\n ? codecToContentType(codecs.split(',')[0])\n : null\n\n // Find matching audio rendition for language.\n const audioRendition = variant.audioGroup\n ? renditions.find(\n (r) => r.type === 'AUDIO' && r.groupId === variant.audioGroup\n )\n : undefined\n\n // Use the variant URI as the decoderId so each quality forces a decoder\n // re-initialization on switch.\n return {\n qualityId: `${variant.bandwidth}-${codecs ?? ''}`,\n decoderId: variant.uri,\n groupId: '0',\n switchingGroupIds: null,\n mimeType: contentType\n ? contentTypeToMimeType(contentType, codecs)\n : null,\n contentType,\n codecs,\n bandwidth: null,\n bandwidthTotal: variant.bandwidth,\n audioSamplingRate: null,\n width: variant.width ?? null,\n height: variant.height ?? null,\n frameRate: variant.frameRate\n ? ([variant.frameRate, 1] as const)\n : null,\n lang: audioRendition?.language ?? null,\n contentProtections: [],\n encryptionScheme: null,\n initDataType: null,\n supplementalProperties: {},\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { data } from '@amazon/vinyl-observable'\nimport { createAbortSlot, createDisposer, logDebug } from '@amazon/vinyl-util'\nimport type { ManifestController } from '../../streaming/ManifestController'\nimport type {\n HlsManifestData,\n HlsManifestProvider,\n} from './HlsManifestProvider'\n\nexport type HlsManifestController = ManifestController<Promise<HlsManifestData>>\n\nexport class HlsManifestControllerImpl implements HlsManifestController {\n get [Symbol.toStringTag](): string {\n return 'HlsManifestControllerImpl'\n }\n\n get logPrefix(): string {\n return 'HlsManifestControllerImpl'\n }\n\n private readonly _data = /* @__PURE__ */ data<Promise<HlsManifestData>>(\n /* @__PURE__ */ Promise.reject(/* @__PURE__ */ new Error('manifest not loaded'))\n )\n private _error: Error | null = null\n private readonly abortSlot = /* @__PURE__ */ createAbortSlot()\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n constructor(private readonly manifestProvider: HlsManifestProvider) {\n // Suppress unhandled rejection on the initial placeholder.\n this._data.value.catch(() => {})\n this.refresh()\n }\n\n /**\n * The most recent error from the manifest provider, or null.\n */\n get error(): Error | null {\n return this._error\n }\n\n refresh(): void {\n logDebug(this, 'refresh')\n this.abortSlot.abort()\n this._error = null\n const promise = this.manifestProvider(this.abortSlot.value)\n promise.catch((error: Error) => {\n this._error = error\n })\n this._data.value = promise\n }\n\n reset(): void {\n logDebug(this, 'reset')\n if (this._error) {\n this.refresh()\n }\n }\n\n get value(): Promise<HlsManifestData> {\n return this._data.value\n }\n\n get changeId(): number {\n return this._data.changeId\n }\n\n getValue(): Promise<HlsManifestData> {\n return this._data.getValue()\n }\n\n onData(\n callback: (\n value: Promise<HlsManifestData>,\n previous?: Promise<HlsManifestData>\n ) => void\n ): () => void {\n return this._data.onData(callback)\n }\n\n map<U>(fn: (value: Promise<HlsManifestData>) => U) {\n return this._data.map(fn)\n }\n\n pick<K extends keyof NonNullable<Promise<HlsManifestData>>>(key: K) {\n return this._data.pick(key)\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n this.abortSlot.abort()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HlsTrackLoadOptions, HlsTrackDeps } from './HlsTrack'\nimport type { Maybe, RequestInterceptor } from '@amazon/vinyl-util'\nimport { createMediaSource } from '../../util/media/mediaSource'\nimport { createDefaultHlsMediaQualityMetadataResolver } from './HlsMediaQualityMetadataResolver'\nimport {\n MediaSourceControllerImpl,\n type MediaSourceControllerImplDeps,\n} from '../../streaming/buffering/MediaSourceController'\nimport { HlsManifestControllerImpl } from './HlsManifestController'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport { createUrlHlsManifestProvider } from './createUrlHlsManifestProvider'\nimport type { ContentStreamingOptions } from '../../streaming/ContentStreamingOptions'\nimport { createHlsContentTypesValue } from './createHlsContentTypesValue'\nimport { createHlsContentStreamFactories } from './createHlsContentStreamFactories'\nimport { createContentStreamFactory } from '../../streaming/ContentStream'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { PlaybackController } from '../../playback/PlaybackController'\nimport type { DrmKeySystemResolver } from '../../drm/DrmKeySystemResolver'\nimport type { DrmController } from '../../drm/DrmController'\nimport type { Capabilities } from '../../client/Capabilities'\nimport type { PlaybackSource } from '../../playback/PlaybackSource'\nimport type { QualitySelectorImplOptions } from '../../streaming/abr/QualitySelectorImpl'\nimport { QualitySelectorImpl } from '../../streaming/abr/QualitySelectorImpl'\nimport type { VinylOptions } from '../../vinyl/VinylOptions'\nimport { createDefaultHlsManifestTransformer } from './createDefaultHlsManifestTransformer'\nimport {\n buildHlsMediaTimeline,\n type BuildHlsMediaTimelineDeps,\n} from './buildHlsMediaTimeline'\nimport { createDefaultMediaTimelineTransformer } from '../../streaming/createDefaultMediaTimelineTransformer'\nimport type { HlsManifestData } from './HlsManifestProvider'\n\nexport interface HlsFactoryDeps {\n readonly options: ObservableValue<{\n readonly abr: QualitySelectorImplOptions\n readonly preferredAudioLanguage: string | null\n }>\n readonly playbackController: PlaybackController\n readonly playbackSource: PlaybackSource\n readonly drmKeySystemResolver: DrmKeySystemResolver\n readonly requestInterceptor: RequestInterceptor\n readonly drmController: DrmController\n readonly capabilities: Capabilities\n}\n\nexport type HlsInitOptions = {\n readonly streaming?: Maybe<ContentStreamingOptions>\n}\n\nexport function createHlsFactories(options: Maybe<HlsInitOptions>) {\n return (deps: HlsFactoryDeps) => {\n return (loadOptions: HlsTrackLoadOptions) => {\n const manifestProvider =\n loadOptions.manifestProvider ||\n createUrlHlsManifestProvider(\n loadOptions.uri,\n loadOptions.requestInit || undefined\n )\n\n return validateFactories({\n ...externalDependencies(deps),\n\n contentTypesValue: createHlsContentTypesValue,\n\n manifestController: () =>\n new HlsManifestControllerImpl(manifestProvider),\n\n manifestTransformed: createDefaultHlsManifestTransformer,\n\n mediaQualityMetadataResolver: () =>\n createDefaultHlsMediaQualityMetadataResolver(),\n\n mediaSourceFactory: () => createMediaSource,\n\n mediaSourceController: (deps: MediaSourceControllerImplDeps) =>\n new MediaSourceControllerImpl(deps),\n\n segmentRequestInit: () => loadOptions.segmentRequestInit,\n\n createContentStreamFactories: createHlsContentStreamFactories(\n options?.streaming\n ),\n contentStreamFactory: createContentStreamFactory,\n\n qualitySelector: (deps: {\n options: ObservableValue<Pick<VinylOptions, 'abr'>>\n }) =>\n new QualitySelectorImpl({\n options: deps.options.pick('abr'),\n }),\n\n mediaTimeline: (\n deps: BuildHlsMediaTimelineDeps & {\n readonly manifestTransformed: ObservableValue<\n Promise<HlsManifestData>\n >\n }\n ) =>\n deps.manifestTransformed.map(async (manifestPromise) => {\n const data = await manifestPromise\n return buildHlsMediaTimeline(deps, data)\n }),\n mediaTimelineTransformed: createDefaultMediaTimelineTransformer,\n } as const) satisfies Factories<HlsTrackDeps>\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MainPlaylist, MediaPlaylist } from '@amazon/vinyl-hls-parser'\nimport { parseMainPlaylist, parseMediaPlaylist } from '@amazon/vinyl-hls-parser'\nimport type {\n Maybe,\n ReadonlyAbort,\n RequestInitOptions,\n} from '@amazon/vinyl-util'\nimport { memoize, requestWithRetry, resolveUrl } from '@amazon/vinyl-util'\nimport type {\n HlsManifestData,\n HlsManifestProvider,\n} from './HlsManifestProvider'\n\nexport function createUrlHlsManifestProvider(\n url: string,\n requestInit?: RequestInitOptions\n): HlsManifestProvider {\n return async (abort?: ReadonlyAbort): Promise<HlsManifestData> => {\n const mainResponse = await requestWithRetry(url, requestInit, {\n abort,\n })\n const mainText = await mainResponse.text()\n const mainPlaylist = parseMainPlaylist(mainText)\n\n // Use the response URL (after redirects) as the base for resolving\n // relative URIs in the manifest.\n const baseUrl = mainResponse.url || url\n\n const getMediaPlaylist = memoize(\n (uri: string) =>\n fetchMediaPlaylist({\n uri,\n baseUrl,\n defines: mainPlaylist.defines,\n requestInit,\n abort,\n }),\n (uri) => uri\n )\n\n return {\n mainPlaylist,\n baseUrl,\n getMediaPlaylist,\n }\n }\n}\n\nexport interface FetchMediaPlaylistOptions {\n /** The variant URI to resolve against the base URL. */\n readonly uri: string\n /** The base URL for resolving relative URIs. */\n readonly baseUrl: string\n /** Variable definitions from the main playlist. */\n readonly defines: MainPlaylist['defines']\n /** Optional request configuration. */\n readonly requestInit?: Maybe<RequestInitOptions>\n /** Optional abort signal. */\n readonly abort?: Maybe<ReadonlyAbort>\n}\n\n/**\n * Fetches and parses an HLS media playlist from a variant URI.\n */\nexport async function fetchMediaPlaylist(\n options: FetchMediaPlaylistOptions\n): Promise<MediaPlaylist> {\n const { uri, baseUrl, defines, requestInit, abort } = options\n const variantUrl = resolveUrl(uri, baseUrl)\n const response = await requestWithRetry(variantUrl, requestInit, { abort })\n const text = await response.text()\n return parseMediaPlaylist(text, defines)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ContentType } from '../../streaming/MediaQualityMetadata'\nimport type { ContentTypesValue } from '../../streaming/ContentTypesValue'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { HlsManifestData } from './HlsManifestProvider'\nimport type { MainPlaylist } from '@amazon/vinyl-hls-parser'\nimport { codecsToContentTypes } from '../mse/codec'\n\nexport interface HlsContentTypesValueDeps {\n readonly manifestTransformed: ObservableValue<Promise<HlsManifestData>>\n}\n\n/**\n * Creates an ObservableValue for the content types present in the HLS manifest.\n *\n * Per RFC 8216 \u00A74.3.4.2, content types are determined from:\n * 1. The CODECS attribute on EXT-X-STREAM-INF (variant streams)\n * 2. The TYPE attribute on EXT-X-MEDIA (alternative renditions)\n */\nexport function createHlsContentTypesValue(\n deps: HlsContentTypesValueDeps\n): ContentTypesValue {\n return deps.manifestTransformed.map(async (manifestData) => {\n return getContentTypes((await manifestData).mainPlaylist)\n })\n}\n\nfunction getContentTypes(mainPlaylist: MainPlaylist): Set<ContentType> {\n const contentTypes = new Set<ContentType>()\n\n // Derive content types from variant CODECS attributes.\n // Only audio and video are relevant for MSE; text (subtitles/CC) is not\n // appended via SourceBuffer in HLS.\n for (const variant of mainPlaylist.variants) {\n if (variant.codecs) {\n for (const type of codecsToContentTypes(variant.codecs)) {\n if (type === 'audio' || type === 'video') {\n contentTypes.add(type)\n }\n }\n }\n }\n\n // Add audio/video from separate renditions not already covered by variant codecs.\n for (const rendition of mainPlaylist.alternativeRenditions) {\n if (rendition.type === 'AUDIO') contentTypes.add('audio')\n if (rendition.type === 'VIDEO') contentTypes.add('video')\n }\n\n return contentTypes\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaSourceController } from '@/streaming/buffering/MediaSourceController'\nimport type { PlaybackController } from '@/playback/PlaybackController'\nimport type { QualitySelector } from '@/streaming/abr/QualitySelector'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { type ContentStreamImplDeps } from '@/streaming/ContentStream'\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\nimport {\n SourceBufferControllerImpl,\n type SourceBufferControllerImplDeps,\n} from '@/streaming/buffering/SourceBufferController'\nimport {\n BufferingControllerImpl,\n type BufferingControllerImplDeps,\n} from '@/streaming/buffering/BufferingController'\nimport {\n SegmentControllerImpl,\n type SegmentControllerImplDeps,\n} from '@/streaming/SegmentControllerImpl'\nimport { type Maybe, memoize } from '@amazon/vinyl-util'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport type { ContentStreamingOptions } from '@/streaming/ContentStreamingOptions'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\n\nexport interface HlsContentStreamTrackDeps {\n readonly mediaSourceController: MediaSourceController\n readonly playbackController: PlaybackController\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n readonly qualitySelector: QualitySelector\n}\n\nexport function createHlsContentStreamFactories(\n options: Maybe<ContentStreamingOptions>\n) {\n return (deps: HlsContentStreamTrackDeps) =>\n memoize(\n (contentType: ContentType) => {\n return validateFactories({\n ...externalDependencies(deps),\n sourceBufferControllerFactory:\n (deps: SourceBufferControllerImplDeps) => () =>\n new SourceBufferControllerImpl(deps, contentType),\n bufferingController: (deps: BufferingControllerImplDeps) =>\n new BufferingControllerImpl(\n deps,\n contentType,\n options?.buffering\n ),\n segmentController: (deps: SegmentControllerImplDeps) =>\n new SegmentControllerImpl(\n deps,\n contentType,\n options?.segmentController\n ),\n } as const) satisfies Factories<ContentStreamImplDeps>\n },\n (contentType) => contentType\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { HlsManifestData } from '@/track/hls/HlsManifestProvider'\n\nexport interface HlsManifestTransformerDeps {\n readonly manifestController: ObservableValue<Promise<HlsManifestData>>\n}\n\n/**\n * The default HLS manifest transformer sorts variants by bandwidth descending (highest quality first).\n * Quality and language filtering is handled by the media timeline transformer.\n */\nexport function createDefaultHlsManifestTransformer(\n deps: HlsManifestTransformerDeps\n): ObservableValue<Promise<HlsManifestData>> {\n return deps.manifestController.map(async (v) => {\n const data = await v\n const sorted = [...data.mainPlaylist.variants].sort(\n (a, b) => b.bandwidth - a.bandwidth\n )\n return {\n ...data,\n mainPlaylist: {\n ...data.mainPlaylist,\n variants: sorted,\n },\n }\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ByteRange } from '@amazon/vinyl-mpd-parser'\nimport type { HlsByteRange } from '@amazon/vinyl-hls-parser'\n\n/** Converts an HLS byte range (`{offset, length}`) to a `ByteRange` (`[start, end]`). */\nexport function hlsByteRangeToMediaRange(byteRange: HlsByteRange): ByteRange {\n return [byteRange.offset, byteRange.offset + byteRange.length - 1]\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HlsSegment } from '@amazon/vinyl-hls-parser'\nimport type { MediaSegmentReference } from '@/streaming/SegmentReference'\nimport type { SegmentDataProvider } from '@/streaming/SegmentDataSlot'\nimport {\n createSegmentDataProvider,\n type CreateSegmentDataProviderDeps,\n} from '@/track/createSegmentDataProvider'\nimport { hlsByteRangeToMediaRange } from './hlsByteRangeToMediaRange'\nimport { resolveUrl } from '@amazon/vinyl-util'\n\n/**\n * Builds a timeline of MediaSegmentReferences from an HLS media playlist's\n * segment list. Cumulative durations are used to compute start/end times.\n */\nexport function buildSegmentTimeline(\n deps: CreateSegmentDataProviderDeps,\n baseUrl: string,\n segments: readonly HlsSegment[]\n): readonly MediaSegmentReference<SegmentDataProvider>[] {\n const out: MediaSegmentReference<SegmentDataProvider>[] = new Array(\n segments.length\n )\n let time = 0\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i]\n const startTime = time\n const endTime = time + seg.duration\n const url = resolveUrl(seg.uri, baseUrl)\n out[i] = {\n timestampOffset: startTime,\n startTime,\n endTime,\n data: createSegmentDataProvider(deps, {\n url,\n mediaRange: seg.byteRange\n ? hlsByteRangeToMediaRange(seg.byteRange)\n : undefined,\n reportDownlinkMetrics: true,\n }),\n }\n time = endTime\n }\n return out\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HlsManifestData } from '@/track/hls/HlsManifestProvider'\nimport type { HlsMediaQualityMetadataResolver } from '@/track/hls/HlsMediaQualityMetadataResolver'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport type {\n MediaPeriod,\n MediaQualityData,\n MediaTimeline,\n} from '@/streaming/MediaTimeline'\nimport type { SegmentReference } from '@/streaming/SegmentReference'\nimport type { SegmentDataProvider } from '@/streaming/SegmentDataSlot'\nimport { buildSegmentTimeline } from '@/track/hls/util/hlsSegmentTime'\nimport { getSegmentAtTime } from '@/streaming/util/segment'\nimport { resolveUrl } from '@amazon/vinyl-util'\nimport { codecToContentType, contentTypeToMimeType } from '@/track/mse/codec'\nimport {\n createSegmentDataProvider,\n type CreateSegmentDataProviderDeps,\n} from '@/track/createSegmentDataProvider'\nimport { hlsByteRangeToMediaRange } from '@/track/hls/util/hlsByteRangeToMediaRange'\nimport { createTransmuxer } from '@amazon/vinyl-transmux'\n\nexport interface BuildHlsMediaTimelineDeps extends CreateSegmentDataProviderDeps {\n readonly mediaQualityMetadataResolver: HlsMediaQualityMetadataResolver\n}\n\n/**\n * Builds a MediaTimeline from an HLS manifest.\n * HLS has a single implicit period spanning the full duration.\n */\nexport function buildHlsMediaTimeline(\n deps: BuildHlsMediaTimelineDeps,\n data: HlsManifestData\n): MediaTimeline {\n const { mainPlaylist, baseUrl } = data\n const renditions = mainPlaylist.alternativeRenditions\n\n // HLS duration requires fetching a media playlist, so compute it lazily.\n const DEFAULT_MIN_BUFFER_TIME = 10\n\n const qualities: MediaQualityData[] = mainPlaylist.variants.flatMap(\n (variant) => {\n const baseMetadata = deps.mediaQualityMetadataResolver(\n variant,\n renditions\n )\n\n // Determine which content types this variant carries.\n const codecs = variant.codecs?.split(',') ?? []\n const contentTypes = new Set(\n codecs\n .map((c) => codecToContentType(c))\n .filter((t): t is ContentType => t != null)\n )\n // If no codecs, default to audio (e.g. TS streams).\n if (contentTypes.size === 0) contentTypes.add('audio')\n\n // Create one quality per content type, with narrowed mimeType.\n return [...contentTypes].map((contentType) => {\n const codec =\n codecs.find((c) => codecToContentType(c) === contentType) ??\n null\n const metadata: MediaQualityMetadata = {\n ...baseMetadata,\n contentType,\n mimeType: contentTypeToMimeType(contentType, codec),\n codecs: codec,\n }\n const transmuxer = createTransmuxer()\n\n return {\n metadata,\n async getSegment(\n time: number,\n affordance = 0\n ): Promise<SegmentReference<SegmentDataProvider> | null> {\n // For an audio quality on a variant that also carries video,\n // the audio is delivered through a separate rendition group\n // (variant URI is video-only). Use the rendition URI in that\n // case. Otherwise the variant URI itself contains the audio.\n let playlistUri = variant.uri\n if (\n metadata.contentType === 'audio' &&\n variant.audioGroup &&\n contentTypes.has('video')\n ) {\n const rendition = renditions.find(\n (r) =>\n r.type === 'AUDIO' &&\n r.groupId === variant.audioGroup &&\n r.uri\n )\n if (rendition?.uri) playlistUri = rendition.uri\n }\n const playlist =\n await data.getMediaPlaylist(playlistUri)\n const playlistBaseUrl = resolveUrl(playlistUri, baseUrl)\n const segments = buildSegmentTimeline(\n deps,\n playlistBaseUrl,\n playlist.segments\n )\n const segment = getSegmentAtTime(\n time,\n segments,\n affordance\n )\n if (!segment) return null\n\n // fMP4: use #EXT-X-MAP init segment directly.\n const hlsMap = playlist.segments[0]?.map\n if (hlsMap) {\n return {\n quality: metadata,\n ...segment,\n initData: createSegmentDataProvider(deps, {\n url: resolveUrl(\n hlsMap.uri,\n playlistBaseUrl\n ),\n mediaRange: hlsMap.byteRange\n ? hlsByteRangeToMediaRange(\n hlsMap.byteRange\n )\n : undefined,\n reportDownlinkMetrics: false,\n }),\n }\n }\n\n // MPEG-TS/ADTS: transmux to fMP4.\n const transmuxedQuality: MediaQualityMetadata = {\n ...metadata,\n mimeType: contentTypeToMimeType(\n metadata.contentType!,\n metadata.codecs\n ),\n }\n const rawDataProvider = segment.data\n return {\n quality: transmuxedQuality,\n ...segment,\n data: async (abort) => {\n const raw = await rawDataProvider(abort)\n return transmuxer.transmux(raw).mediaSegment\n },\n initData: async (abort) => {\n const raw = await rawDataProvider(abort)\n return transmuxer.transmux(raw).initSegment\n },\n }\n },\n } satisfies MediaQualityData\n })\n }\n )\n\n const period: MediaPeriod = {\n startTime: 0,\n endTime: Infinity,\n qualities,\n }\n\n let cachedDuration: number | null = null\n\n return {\n periods: [period],\n minBufferTime: DEFAULT_MIN_BUFFER_TIME,\n async getDuration() {\n if (cachedDuration != null) return cachedDuration\n if (mainPlaylist.variants.length === 0) return null\n try {\n const playlist = await data.getMediaPlaylist(\n mainPlaylist.variants[0].uri\n )\n let total = 0\n for (const seg of playlist.segments) total += seg.duration\n cachedDuration = total > 0 ? total : null\n } catch {\n return null\n }\n return cachedDuration\n },\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n bufferToByteArray,\n type Disposable,\n DisposedError,\n ErrorOrigin,\n EventHostImpl,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport {\n type CommonEme,\n type CommonMediaKeys,\n type CommonMediaKeySession,\n CommonMediaKeySessionError,\n type CommonMediaKeySessionEventMap,\n type CommonMediaKeySystemAccess,\n MediaKeySessionErrorType,\n} from './CommonEme'\nimport type { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport { type EncryptedInitData } from './EncryptedInitData'\nimport type { MSMediaKeyMessageEvent } from '@/drm/dom/MSMediaKeys'\nimport { DrmError } from '@/drm/error/DrmError'\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\n\ndeclare global {\n interface HTMLMediaElementEventMap extends HTMLElementEventMap {\n readonly msneedkey: MSMediaKeyNeededEvent\n }\n\n interface MSMediaKeyNeededEvent extends Event {\n readonly initDataType: string\n readonly initData: Uint8Array<ArrayBuffer> | null\n }\n}\n\n/**\n * A CommonEme implementation of MS prefixed Encrypted Media Extensions as supported by IE11/Edge.\n */\nexport class MsCommonEme implements CommonEme {\n requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess> {\n for (const config of supportedConfigurations) {\n const capabilities = [\n ...(config.audioCapabilities ?? []),\n ...(config.videoCapabilities ?? []),\n ]\n for (const capability of capabilities) {\n if (\n MSMediaKeys.isTypeSupported(\n keySystem,\n capability.contentType\n )\n ) {\n return Promise.resolve(\n new MsCommonMediaKeySystemAccess(keySystem)\n )\n }\n }\n }\n return Promise.reject(\n new DrmError(\n `keySystem not supported: ${keySystem}`,\n { keySystem },\n ErrorOrigin.DRM\n )\n )\n }\n\n /**\n * Listens to the element for an encrypted event, returning a disposable handle.\n */\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: MediaEncryptedEvent) => void\n ): Unsubscribe {\n const event = 'msneedkey'\n element.addEventListener(event, handler as EventListener)\n return () =>\n element.removeEventListener(event, handler as EventListener)\n }\n}\n\nexport class MsCommonMediaKeySystemAccess implements CommonMediaKeySystemAccess {\n constructor(readonly keySystem: DrmKeySystem) {}\n\n createMediaKeys(): Promise<CommonMediaKeys> {\n const msMediaKeys = new MSMediaKeys(this.keySystem)\n return Promise.resolve(\n new MsCommonMediaKeys(this.keySystem, msMediaKeys)\n )\n }\n}\n\n/**\n * @private\n */\nexport class MsCommonMediaKeys implements CommonMediaKeys {\n constructor(\n public readonly keySystem: DrmKeySystem,\n public readonly mediaKeys: MSMediaKeys\n ) {}\n\n /**\n * Sets the media keys on the given element.\n */\n setOnElement(element: HTMLMediaElement): Promise<void> {\n element.msSetMediaKeys!(this.mediaKeys)\n return Promise.resolve()\n }\n\n /**\n * Clears the media keys from the given element.\n */\n clearFromElement(element: HTMLMediaElement): Promise<void> {\n element.msSetMediaKeys!(null)\n return Promise.resolve()\n }\n\n setServerCertificate(_certificate: BufferSource): Promise<boolean> {\n return Promise.resolve(false)\n }\n\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession {\n const session = this.mediaKeys.createSession(\n mimeType,\n bufferToByteArray(initData)\n )\n return new MsCommonMediaKeySession(\n session,\n mimeType,\n initDataType,\n initData\n )\n }\n}\n\n/**\n * @private\n */\nexport class MsCommonMediaKeySession\n extends EventHostImpl<CommonMediaKeySessionEventMap>\n implements CommonMediaKeySession, Disposable\n{\n private _disposed: boolean = false\n\n constructor(\n private readonly session: MSMediaKeySession,\n readonly mimeType: string,\n readonly initDataType: DrmInitDataType,\n readonly initData: EncryptedInitData\n ) {\n super()\n session.addEventListener('mskeymessage', this.messageHandler)\n session.addEventListener('mskeyerror', this.errorHandler)\n }\n\n private readonly messageHandler = (event: MSMediaKeyMessageEvent) => {\n this.dispatch('message', {\n message: event.message.buffer as ArrayBuffer,\n })\n }\n\n private readonly errorHandler = (): void => {\n if (this.session.error) {\n const e = this.session.error\n const error = new CommonMediaKeySessionError(\n e.code,\n msErrorCodeToStr(e.code),\n e.systemCode,\n msErrorCodeToStr(e.systemCode)\n )\n this.dispatch('error', { error, target: this })\n }\n }\n\n update(key: ArrayBuffer): Promise<void> {\n if (this.disposed) return Promise.reject(new DisposedError())\n this.session.update(new Uint8Array(key))\n return Promise.resolve()\n }\n\n get disposed(): boolean {\n return this._disposed\n }\n\n dispose(): void {\n super.dispose()\n this._disposed = true\n this.session.close()\n this.session.removeEventListener('mskeymessage', this.messageHandler)\n this.session.removeEventListener('mskeyerror', this.errorHandler)\n }\n}\n\n/**\n * Returns a string for the WebKit media key error.\n */\nexport function msErrorCodeToStr(code: number): MediaKeySessionErrorType {\n switch (code) {\n case MSMediaKeyError.MS_MEDIA_KEYERR_CLIENT:\n return MediaKeySessionErrorType.CLIENT\n case MSMediaKeyError.MS_MEDIA_KEYERR_DOMAIN:\n return MediaKeySessionErrorType.DOMAIN\n case MSMediaKeyError.MS_MEDIA_KEYERR_HARDWARECHANGE:\n return MediaKeySessionErrorType.HARDWARECHANGE\n case MSMediaKeyError.MS_MEDIA_KEYERR_OUTPUT:\n return MediaKeySessionErrorType.OUTPUT\n case MSMediaKeyError.MS_MEDIA_KEYERR_SERVICE:\n return MediaKeySessionErrorType.SERVICE\n case MSMediaKeyError.MS_MEDIA_KEYERR_UNKNOWN:\n default:\n return MediaKeySessionErrorType.UNKNOWN\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * An common interface to unify multiple EME implementations.\n * @module\n */\n\nimport type { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport type { Json, ReadonlyEventHost, Unsubscribe } from '@amazon/vinyl-util'\nimport { ErrorLevel, ErrorOrigin, ReportableError } from '@amazon/vinyl-util'\nimport type { EncryptedInitData } from '@/drm/commonEme/EncryptedInitData'\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\nimport type { BasicErrorEvent } from '@/event/BasicErrorEvent'\n\n/**\n * Top-level Common EME methods for initiating encrypted audio session.\n *\n * Created to unify standard and non-standard EME interfaces.\n */\nexport interface CommonEme {\n requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess>\n\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: CommonMediaEncryptedEvent) => void\n ): Unsubscribe\n}\n\nexport interface CommonMediaEncryptedEvent {\n /**\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaEncryptedEvent/initData)\n */\n readonly initData: EncryptedInitData | null\n\n /**\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaEncryptedEvent/initDataType)\n */\n readonly initDataType: string\n}\n\n/**\n * This provides a common interface for MediaKeySystemAccess EME implementations.\n */\nexport interface CommonMediaKeySystemAccess {\n readonly keySystem: DrmKeySystem\n createMediaKeys(): Promise<CommonMediaKeys>\n}\n\n/**\n * This provides a common interface for MediaKeys EME implementations.\n */\nexport interface CommonMediaKeys {\n readonly keySystem: DrmKeySystem\n\n /**\n * Sets the media keys on the given element.\n * @param element\n */\n setOnElement(element: HTMLMediaElement): Promise<void>\n\n /**\n * Clears the media keys from the given element.\n * This is only allowed if the element's src isn't set.\n * https://bugs.chromium.org/p/chromium/issues/detail?id=462365#c7\n * @param element\n */\n clearFromElement(element: HTMLMediaElement): Promise<void>\n\n /**\n * Sets the server certificate on the media keys.\n *\n * A Promise that resolves to a boolean. If the Key System implementation\n * represented by this object's content decryption module's implementation\n * value does not support server certificates, return a promise resolved\n * with false.\n *\n * @param certificate The server certificate data.\n */\n setServerCertificate(certificate: BufferSource): Promise<boolean>\n\n /**\n * Creates the key session.\n *\n * @param mimeType\n * @param initDataType\n * @param initData The initialization data from the 'encrypted' event.\n */\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession\n}\n\n/**\n * Common media key session events\n */\nexport interface CommonMediaKeySessionEventMap {\n /**\n * Dispatched when a message is generated by the content decryption module.\n */\n readonly message: CommonMediaKeyMessageEvent\n\n /**\n * Dispatched when an error occurs.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Dispatched when the session is forcibly closed by the CDM.\n */\n readonly closed: CommonMediaKeySessionClosedEvent\n}\n\n/**\n * This provides a common interface for MediaKeySession EME implementations.\n */\nexport interface CommonMediaKeySession extends ReadonlyEventHost<CommonMediaKeySessionEventMap> {\n readonly mimeType: string\n readonly initDataType: DrmInitDataType\n readonly initData: EncryptedInitData\n\n /**\n * Updates the session with the license data.\n * @param key\n */\n update(key: ArrayBuffer): Promise<void>\n\n /**\n * Returns true if the session has been disposed.\n */\n get disposed(): boolean\n\n /**\n * Closes the session, and removes session handling and event listeners, freeing this session\n * handler for GC.\n *\n * Note: The audio source should be cleared first.\n */\n dispose(): void\n}\n\n/**\n * A media key session error, translated from the specific media key session implementation.\n */\nexport class CommonMediaKeySessionError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'CommonMediaKeySessionError'\n }\n\n constructor(\n readonly code: number,\n readonly codeStr: MediaKeySessionErrorType,\n readonly systemCode: number,\n readonly systemCodeStr: MediaKeySessionErrorType\n ) {\n super(codeStr, ErrorOrigin.DRM, ErrorLevel.WARN)\n Object.setPrototypeOf(this, CommonMediaKeySessionError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n code: this.code,\n codeStr: this.codeStr,\n systemCode: this.systemCode,\n systemCodeStr: this.systemCodeStr,\n }\n }\n}\n\n/**\n * Common media key message event body.\n */\nexport interface CommonMediaKeyMessageEvent {\n readonly message: ArrayBuffer\n}\n\nexport interface CommonMediaKeySessionClosedEvent {\n /**\n * The reason the session was closed.\n */\n readonly reason: MediaKeySessionClosedReason\n}\n\n/**\n * String representations of session error codes.\n */\nexport enum MediaKeySessionErrorType {\n CLIENT = 'CLIENT',\n DOMAIN = 'DOMAIN',\n HARDWARECHANGE = 'HARDWARECHANGE',\n OUTPUT = 'OUTPUT',\n SERVICE = 'SERVICE',\n UNKNOWN = 'UNKNOWN',\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ErrorOrigin, type Json } from '@amazon/vinyl-util'\nimport { ErrorLevel, ReportableError } from '@amazon/vinyl-util'\n\n/**\n * An error originating from the DrmController.\n * If an error comes from a key session, `extra.error` will be set with the original error and origin will be DRM.\n */\nexport class DrmError<ExtraType = any> extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'DrmError'\n }\n\n constructor(\n readonly message: string,\n private readonly extra: ExtraType | null = null,\n readonly origin: string = ErrorOrigin.DRM,\n readonly level: ErrorLevel = ErrorLevel.FATAL\n ) {\n super(message, origin, level)\n Object.setPrototypeOf(this, DrmError.prototype)\n }\n\n toJSON(): Json {\n return { ...super.toJSON(), extra: this.extra }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type Disposable,\n DisposedError,\n EventHostImpl,\n noop,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport type {\n CommonEme,\n CommonMediaEncryptedEvent,\n CommonMediaKeyMessageEvent,\n CommonMediaKeys,\n CommonMediaKeySession,\n CommonMediaKeySessionEventMap,\n CommonMediaKeySystemAccess,\n} from './CommonEme'\nimport type { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport { type EncryptedInitData } from './EncryptedInitData'\nimport { createDrmErrorHandler } from './createDrmErrorHandler'\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\n\n/**\n * A CommonEme implementation of unprefixed Encrypted Media Extensions.\n */\nexport class StandardCommonEme implements CommonEme {\n async requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess> {\n const access = await navigator\n .requestMediaKeySystemAccess(keySystem, supportedConfigurations)\n .catch(createDrmErrorHandler())\n return new StandardCommonMediaKeySystemAccess(keySystem, access)\n }\n\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: CommonMediaEncryptedEvent) => void\n ): Unsubscribe {\n element.addEventListener('encrypted', handler)\n return () => element.removeEventListener('encrypted', handler)\n }\n}\n\n/**\n * CommonMediaKeySystemAccess for unprefixed EME implementations.\n */\nexport class StandardCommonMediaKeySystemAccess implements CommonMediaKeySystemAccess {\n constructor(\n public readonly keySystem: DrmKeySystem,\n private readonly access: MediaKeySystemAccess\n ) {}\n\n /**\n * @return {Promise<CommonMediaKeys>}\n */\n async createMediaKeys(): Promise<CommonMediaKeys> {\n const mediaKeys = await this.access\n .createMediaKeys()\n .catch(createDrmErrorHandler())\n return new StandardCommonMediaKeys(this.keySystem, mediaKeys)\n }\n}\n\n/**\n * CommonMediaKeys for unprefixed EME implementations.\n */\nexport class StandardCommonMediaKeys implements CommonMediaKeys {\n constructor(\n public readonly keySystem: DrmKeySystem,\n private readonly mediaKeys: MediaKeys\n ) {}\n\n setOnElement(element: HTMLMediaElement): Promise<void> {\n return element.setMediaKeys(this.mediaKeys)\n }\n\n clearFromElement(element: HTMLMediaElement): Promise<void> {\n return element.setMediaKeys(null)\n }\n\n async setServerCertificate(certificate: BufferSource): Promise<boolean> {\n return this.mediaKeys.setServerCertificate(certificate)\n }\n\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession {\n return new StandardCommonMediaKeySession(\n this.mediaKeys.createSession('temporary'),\n mimeType,\n initDataType,\n initData\n )\n }\n}\n\n/**\n * CommonMediaKeySession for unprefixed EME implementations.\n */\nexport class StandardCommonMediaKeySession\n extends EventHostImpl<CommonMediaKeySessionEventMap>\n implements CommonMediaKeySession, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'StandardCommonMediaKeySession'\n }\n\n private _disposed = false\n\n private readonly messageHandler = (event: CommonMediaKeyMessageEvent) => {\n this.dispatch('message', {\n message: event.message,\n })\n }\n\n constructor(\n private readonly session: MediaKeySession,\n readonly mimeType: string,\n readonly initDataType: DrmInitDataType,\n readonly initData: EncryptedInitData\n ) {\n super()\n session.addEventListener('message', this.messageHandler)\n if ((session as any).closed) {\n // Compatibility: React Native MSE does not provide a 'closed' promise.\n session.closed\n .then((reason) => {\n this.dispatch('closed', {\n reason,\n })\n })\n .catch(noop)\n }\n this.generateRequest().catch((error) => {\n this.dispatch('error', {\n error,\n target: this,\n })\n })\n }\n\n private generateRequest(): Promise<void> {\n const initData = this.initData\n return this.session\n .generateRequest(\n this.initDataType,\n initData instanceof ArrayBuffer ? initData : initData.buffer\n )\n .catch(createDrmErrorHandler())\n }\n\n update(key: ArrayBufferLike): Promise<void> {\n if (this.disposed) throw new DisposedError()\n return this.session.update(key as ArrayBuffer)\n }\n\n get disposed(): boolean {\n return this._disposed\n }\n\n dispose(): void {\n super.dispose()\n this._disposed = true\n this.session.removeEventListener('message', this.messageHandler)\n this.session.close().catch(noop)\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { DrmError } from '@/drm/error/DrmError'\nimport { ErrorLevel, ErrorOrigin, toJson } from '@amazon/vinyl-util'\n\nexport function createDrmErrorHandler(\n level: ErrorLevel = ErrorLevel.FATAL\n): (error: Error) => never {\n return (error) => {\n throw new DrmError(\n error.message,\n { error: toJson(error) },\n ErrorOrigin.DRM,\n level\n )\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Unsubscribe } from '@amazon/vinyl-util'\nimport {\n bufferToByteArray,\n type Disposable,\n DisposedError,\n ErrorOrigin,\n EventHostImpl,\n} from '@amazon/vinyl-util'\nimport type {\n CommonEme,\n CommonMediaEncryptedEvent,\n CommonMediaKeys,\n CommonMediaKeySession,\n CommonMediaKeySessionEventMap,\n CommonMediaKeySystemAccess,\n} from './CommonEme'\nimport {\n CommonMediaKeySessionError,\n MediaKeySessionErrorType,\n} from './CommonEme'\nimport type { WebKitMediaKeyMessageEvent } from '@/drm/dom/WebKitMediaKeys'\nimport type { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport { DrmError } from '@/drm/error/DrmError'\nimport type { EncryptedInitData } from '@/drm/commonEme/EncryptedInitData'\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\n\ndeclare global {\n interface HTMLMediaElementEventMap extends HTMLElementEventMap {\n readonly webkitneedkey: WebKitMediaKeyNeededEvent\n }\n\n interface WebKitMediaKeyNeededEvent extends Event {\n readonly initDataType: string\n readonly initData: Uint8Array<ArrayBuffer> | null\n }\n}\n\n/**\n * A CommonEme implementation of WebKit-prefixed Encrypted Media Extensions.\n */\nexport class WebKitCommonEme implements CommonEme {\n requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess> {\n for (const config of supportedConfigurations) {\n const capabilities = [\n ...(config.audioCapabilities ?? []),\n ...(config.videoCapabilities ?? []),\n ]\n for (const capability of capabilities) {\n if (\n WebKitMediaKeys.isTypeSupported(\n keySystem,\n capability.contentType\n )\n ) {\n return Promise.resolve(\n new WebKitCommonMediaKeySystemAccess(keySystem)\n )\n }\n }\n }\n return Promise.reject(\n new DrmError(\n `keySystem not supported: ${keySystem}`,\n { keySystem },\n ErrorOrigin.DRM\n )\n )\n }\n\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: CommonMediaEncryptedEvent) => void\n ): Unsubscribe {\n element.addEventListener('webkitneedkey', handler)\n return () => element.removeEventListener('webkitneedkey', handler)\n }\n}\n\nexport class WebKitCommonMediaKeySystemAccess implements CommonMediaKeySystemAccess {\n constructor(public readonly keySystem: DrmKeySystem) {}\n\n createMediaKeys(): Promise<CommonMediaKeys> {\n const webKitMediaKeys = new WebKitMediaKeys(this.keySystem)\n const webkitCommonMediaKeys = new WebKitCommonMediaKeys(\n this.keySystem,\n webKitMediaKeys\n )\n return Promise.resolve(webkitCommonMediaKeys)\n }\n}\n\n/** @private */\nexport class WebKitCommonMediaKeys implements CommonMediaKeys {\n constructor(\n public readonly keySystem: DrmKeySystem,\n public readonly mediaKeys: WebKitMediaKeys\n ) {}\n\n /**\n * Sets the media keys on the given element.\n */\n setOnElement(element: HTMLMediaElement): Promise<void> {\n element.webkitSetMediaKeys!(this.mediaKeys)\n return Promise.resolve()\n }\n\n /**\n * Clears the media keys from the given element.\n */\n clearFromElement(element: HTMLMediaElement): Promise<void> {\n element.webkitSetMediaKeys!(null)\n return Promise.resolve()\n }\n\n setServerCertificate(_certificate: BufferSource): Promise<boolean> {\n return Promise.resolve(false)\n }\n\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession {\n const session = this.mediaKeys.createSession(\n mimeType,\n bufferToByteArray(initData)\n )\n return new WebKitCommonMediaKeySession(\n session,\n mimeType,\n initDataType,\n initData\n )\n }\n}\n\n/** @private */\nexport class WebKitCommonMediaKeySession\n extends EventHostImpl<CommonMediaKeySessionEventMap>\n implements CommonMediaKeySession, Disposable\n{\n private _disposed: boolean = false\n\n constructor(\n private readonly session: WebKitMediaKeySession,\n readonly mimeType: string,\n readonly initDataType: DrmInitDataType,\n readonly initData: EncryptedInitData\n ) {\n super()\n session.addEventListener('webkitkeymessage', this.messageHandler)\n session.addEventListener('webkitkeyerror', this.errorHandler)\n }\n\n private readonly messageHandler = (event: WebKitMediaKeyMessageEvent) => {\n this.dispatch('message', {\n message: event.message.buffer as ArrayBuffer,\n })\n }\n\n private readonly errorHandler = () => {\n if (this.session.error) {\n const e = this.session.error\n const error = new CommonMediaKeySessionError(\n e.code,\n webkitErrorCodeToStr(e.code),\n e.systemCode,\n webkitErrorCodeToStr(e.systemCode)\n )\n this.dispatch('error', { error, target: this })\n }\n }\n\n update(key: ArrayBuffer): Promise<void> {\n if (this.disposed) return Promise.reject(new DisposedError())\n this.session.update(new Uint8Array(key))\n return Promise.resolve()\n }\n\n get disposed() {\n return this._disposed\n }\n\n dispose(): void {\n super.dispose()\n this._disposed = true\n this.session.removeEventListener(\n 'webkitkeymessage',\n this.messageHandler\n )\n this.session.removeEventListener('webkitkeyerror', this.errorHandler)\n // Do not wait on close, and ignore errors.\n this.session.close()\n }\n}\n\n/**\n * Returns a string for the WebKit media key error.\n */\nexport function webkitErrorCodeToStr(code: number): MediaKeySessionErrorType {\n switch (code) {\n case WebKitMediaKeyError.MEDIA_KEYERR_CLIENT:\n return MediaKeySessionErrorType.CLIENT\n case WebKitMediaKeyError.MEDIA_KEYERR_DOMAIN:\n return MediaKeySessionErrorType.DOMAIN\n case WebKitMediaKeyError.MEDIA_KEYERR_HARDWARECHANGE:\n return MediaKeySessionErrorType.HARDWARECHANGE\n case WebKitMediaKeyError.MEDIA_KEYERR_OUTPUT:\n return MediaKeySessionErrorType.OUTPUT\n case WebKitMediaKeyError.MEDIA_KEYERR_SERVICE:\n return MediaKeySessionErrorType.SERVICE\n case WebKitMediaKeyError.MEDIA_KEYERR_UNKNOWN:\n default:\n return MediaKeySessionErrorType.UNKNOWN\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { MsCommonEme } from './MsCommonEme'\nimport { StandardCommonEme } from './StandardCommonEme'\nimport { WebKitCommonEme } from './WebKitCommonEme'\nimport type { CommonEme } from '@/drm/commonEme/CommonEme'\nimport { globalRef } from '@amazon/vinyl-util'\n\n/**\n * Common EME Factory provides the first supported implementation of CommonEme.\n * The priority is WebKit, Standard, then MS.\n *\n * Note: WebKit if present is currently prioritized over standard for legacy reasons. This may be an obsolete\n * requirement. https://jira.music.amazon.dev/browse/PLAYBACK-6072 ticket to investigate.\n */\nexport function commonEmeFactory(): CommonEme | null {\n if (supportsWebKitEme()) return new WebKitCommonEme()\n if (supportsStandardEme()) return new StandardCommonEme()\n if (supportsMsEme()) return new MsCommonEme()\n return null\n}\n\n/**\n * Tests for Standard Eme support.\n */\nexport function supportsStandardEme(): boolean {\n return mediaKeySupportRef.value.standardEme\n}\n\n/**\n * Tests for WebKitEme support.\n */\nexport function supportsWebKitEme(): boolean {\n return mediaKeySupportRef.value.webkitEme\n}\n\n/**\n * Tests for MsEme support.\n */\nexport function supportsMsEme(): boolean {\n return mediaKeySupportRef.value.msEme\n}\n\nexport type MediaKeySupport = {\n readonly standardEme: boolean\n readonly webkitEme: boolean\n readonly msEme: boolean\n}\n\nexport const mediaKeySupportRef = /* @__PURE__ */ globalRef<MediaKeySupport>(() => {\n return {\n standardEme: typeof MediaKeys !== 'undefined',\n webkitEme: typeof WebKitMediaKeys !== 'undefined',\n msEme: typeof (global as any).MSMediaKeys !== 'undefined',\n }\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AbortError,\n base64ToByteArray,\n buffersEqual,\n bufferToByteArray,\n clone,\n type Comparator,\n compareBy,\n createDisposer,\n ErrorOrigin,\n EventHostImpl,\n isSilentError,\n logDebug,\n logVerbose,\n type Maybe,\n memoize,\n noop,\n normalizeHeadersInit,\n type ReadonlyAbort,\n remove,\n resolveValueProvider,\n withTimeout,\n} from '@amazon/vinyl-util'\nimport { instanceOf, object, type ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n type DrmMediaKeySystemOptions,\n type DrmOptions,\n DrmRobustness,\n type InitDataTransformer,\n} from '@/drm/DrmOptions'\nimport type {\n DrmController,\n DrmControllerEventMap,\n DrmKeySystemSupport,\n} from '@/drm/DrmController'\nimport type {\n CommonEme,\n CommonMediaEncryptedEvent,\n CommonMediaKeyMessageEvent,\n CommonMediaKeys,\n CommonMediaKeySession,\n CommonMediaKeySystemAccess,\n} from '@/drm/commonEme/CommonEme'\nimport { DrmError } from '@/drm/error/DrmError'\nimport type { EncryptedInitData } from '@/drm/commonEme/EncryptedInitData'\nimport { DrmKeySystem, isPlayReady } from '@/drm/DrmKeySystem'\nimport type { DrmInitDataType } from '@/streaming/DrmInitDataType'\nimport type {\n ContentType,\n MediaFormatMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport { unpackPlayReadyChallenge } from '@/drm/util/unpackPlayReadyChallenge'\nimport type {\n LicenseProvider,\n ServerCertificate,\n} from '@/drm/licenseProvider/LicenseProvider'\nimport { defaultLicenseProvider } from '@/drm/licenseProvider/defaultLicenseProvider'\nimport { extractContentId } from '@/drm/util/extractContentId'\nimport { createFairPlaySessionInitData } from '@/drm/util/createFairPlaySessionInitData'\n\n/**\n * The number of seconds a license request will be allowed before timing out.\n * This should be higher than the network timeout.\n *\n * In practice, network requests will time out before this, and a license timeout\n * indicates a stalled promise result from the license provider.\n */\nexport const LICENSE_TIMEOUT = 90\nconst LICENSE_TIMEOUT_MESSAGE = 'License provider timed out after {time}s'\n\n/**\n * Dependencies for creating DrmController.\n */\nexport interface DrmControllerImplDeps {\n readonly media: HTMLMediaElement\n readonly commonEme: CommonEme | null\n}\n\nexport interface DrmControllerMessageProps {\n readonly mediaKeys: CommonMediaKeys\n readonly session: CommonMediaKeySession\n readonly event: CommonMediaKeyMessageEvent\n}\n\nexport class DrmControllerImpl\n extends EventHostImpl<DrmControllerEventMap>\n implements DrmController\n{\n get [Symbol.toStringTag](): string {\n return 'DrmControllerImpl'\n }\n\n private readonly optionsBase: DrmOptions\n private options: DrmOptions\n\n private mediaKeys: CommonMediaKeys | null = null\n private mediaKeysPromise: Promise<CommonMediaKeys> | null = null\n private readonly sessions: CommonMediaKeySession[] = []\n\n private _error: Error | null = null\n private drmInfo: MediaFormatMetadata | null = null\n private sessionAbort: ReadonlyAbort | null = null\n\n private pendingMessageProps: DrmControllerMessageProps | null = null\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n constructor(\n private readonly deps: DrmControllerImplDeps,\n options?: Maybe<Partial<DrmOptions>>\n ) {\n super()\n this.optionsBase = { keySystems: {}, ...options }\n this.options = this.optionsBase\n\n if (this.deps.commonEme) {\n this.disposer.add(\n this.deps.commonEme.addEncryptedListener(\n this.deps.media,\n this.handleEncryptedEvent\n )\n )\n }\n }\n\n configure(options: Maybe<Partial<DrmOptions>>): void {\n this.options = {\n ...this.optionsBase,\n ...options,\n keySystems: {\n ...this.optionsBase.keySystems,\n ...options?.keySystems,\n },\n }\n }\n\n private get licenseProvider(): LicenseProvider {\n return this.options.licenseProvider ?? defaultLicenseProvider\n }\n\n get error(): Error | null {\n return this._error\n }\n\n isEmeSupported(): boolean {\n return this.deps.commonEme != null\n }\n\n async isSupported(\n drmInfo: MediaFormatMetadata\n ): Promise<DrmKeySystemSupport> {\n const accessParamsList = this.createMediaKeySystemAccessParams(drmInfo)\n for (const params of accessParamsList) {\n const result = await this.checkIsSupportedCached(params)\n if (result.supported) return result\n }\n return { supported: false, persistentState: false }\n }\n\n private checkIsSupportedCached = /* @__PURE__ */ memoize(\n async (\n params: MediaKeySystemAccessParams\n ): Promise<DrmKeySystemSupport> => {\n try {\n await this.deps.commonEme!.requestMediaKeySystemAccess(\n params.keySystem,\n [params.config]\n )\n logVerbose(\n this,\n 'requestMediaKeySystemAccess supported',\n params\n )\n return {\n supported: true,\n persistentState:\n params.config.persistentState === 'required',\n }\n } catch (_) {\n logVerbose(this, 'requestMediaKeySystemAccess rejected', params)\n return { supported: false, persistentState: false }\n }\n },\n (options) => options.cacheKey,\n 20 // capacity\n )\n\n private readonly handleEncryptedEvent = (\n event: CommonMediaEncryptedEvent\n ) => {\n if (this.disposed) return\n ;(async () => {\n const { initData, initDataType } = event\n if (!initData) {\n // https://www.w3.org/TR/2014/WD-encrypted-media-20140218/#dom-mediakeyneededevent\n // https://www.w3.org/TR/encrypted-media/#initialization-data\n // Initialization data could not be obtained, possibly due to cross-origin policy issues.\n throw new DrmError(\n 'encrypted event provided null initData. Check CORS policies.'\n )\n }\n logDebug(\n this,\n `encrypted, initDataType: ${initDataType}, initData.byteLength: ${initData.byteLength}`\n )\n if (!this.drmInfo?.contentProtections.length) {\n throw new DrmError(\n 'Encrypted content not configured with content protections.'\n )\n }\n await this.maybeCreateSession(\n this.drmInfo,\n initDataType,\n initData,\n this.sessionAbort\n )\n })().catch(this.handleError)\n }\n\n /**\n * Resolves to media keys attached to the element.\n * The media keys will only be created and set once until `clearMediaKeys` is next called.\n */\n private async attachMediaKeys(\n drmInfo: MediaFormatMetadata\n ): Promise<CommonMediaKeys> {\n if (!this.mediaKeysPromise) {\n this.mediaKeysPromise = (async () => {\n logDebug(this, 'creating media keys')\n const access = await this.createAccess(drmInfo)\n const mediaKeys = await access.createMediaKeys()\n this.abortIfDisposed()\n this.mediaKeys = mediaKeys\n await mediaKeys.setOnElement(this.deps.media)\n logDebug(this, `set media keys on element`)\n this.dispatch('mediaKeysSet', {\n keySystem: mediaKeys.keySystem,\n })\n return mediaKeys\n })()\n }\n return this.mediaKeysPromise\n }\n\n /**\n * Creates a session for the given initialization data if none currently exists.\n * This will be done either after an 'encrypted' event or when drm metadata contains initialization data.\n * The new session will be added to the current sessions list.\n */\n private async maybeCreateSession(\n drmInfo: MediaFormatMetadata,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData,\n abort?: Maybe<ReadonlyAbort>\n ): Promise<CommonMediaKeySession> {\n if (!hasMimeType(drmInfo)) {\n throw new DrmError('Encrypted content must have a mimeType.')\n }\n\n const mediaKeys = await this.attachMediaKeys(drmInfo)\n this.abortIfDisposed()\n\n // Resolve server certificate from configuration\n const keySystemOptions =\n this.options.keySystems[mediaKeys.keySystem] ??\n this.options.keySystems['*']\n const licenseServerOptionsProvider = keySystemOptions?.licenseServer\n const licenseServerOptions = await resolveValueProvider(\n licenseServerOptionsProvider ?? {}\n )\n this.abortIfDisposed()\n const existingSession = this.getSessionByInitData(initData)\n if (existingSession) {\n logDebug(this, 'reusing session')\n return existingSession\n } else {\n const newSession = await this.createNewSession(\n licenseServerOptions.serverCertificate,\n mediaKeys,\n initData,\n initDataType,\n drmInfo,\n keySystemOptions?.initDataTransformer\n )\n this.sessions.push(newSession)\n this.dispatch('sessionCreate', {\n initDataType: newSession.initDataType,\n mimeType: newSession.mimeType,\n })\n newSession.on('closed', () => this.closeSession(newSession))\n abort?.onAborted(() => {\n logDebug(this, 'abort session')\n this.closeSession(newSession)\n })\n return newSession\n }\n }\n\n initializeForPlayback(\n drmInfo: MediaFormatMetadata | null,\n abort?: ReadonlyAbort\n ): void {\n logDebug(this, 'initializeForPlayback', drmInfo)\n if (drmInfo?.contentProtections.length) {\n this.createSessionFromInitData(drmInfo, abort).catch(\n this.handleError\n )\n }\n }\n\n setBufferingDrmInfo(\n drmInfo: MediaFormatMetadata | null,\n abort?: ReadonlyAbort\n ): void {\n logDebug(this, 'setBufferingDrmInfo', drmInfo)\n // Reset 'encrypted' error reporting\n this.reset()\n this.drmInfo = drmInfo\n this.sessionAbort = abort ?? null\n }\n\n /**\n * If the drm metadata contains initialization data for the current key system, create a new session.\n * Otherwise, wait for the 'encrypted' event for the initialization data.\n */\n private async createSessionFromInitData(\n drmInfo: MediaFormatMetadata,\n abort?: ReadonlyAbort\n ) {\n if (!this.deps.commonEme) {\n this.handleError(new DrmError('DRM not supported.'))\n return\n }\n const mediaKeys = await this.attachMediaKeys(drmInfo)\n const drmProtection =\n drmInfo.contentProtections.find((cP) => {\n return cP.keySystem === mediaKeys.keySystem\n }) ?? null\n\n if (!drmProtection) {\n // Media keys have been initialized, but content is not encrypted with the current keySystem.\n throw new DrmError(\n `Encrypted content does not support set keySystem: '${mediaKeys.keySystem}'.`,\n { drmInfo }\n )\n }\n if (drmProtection.pssh) {\n await this.maybeCreateSession(\n drmInfo,\n drmInfo.initDataType ?? 'cenc',\n base64ToByteArray(drmProtection.pssh),\n abort\n )\n }\n }\n\n /**\n * Creates a CommonMediaKeySystemAccess object from the given content protection settings.\n */\n private async createAccess(\n drmInfo: MediaFormatMetadata\n ): Promise<CommonMediaKeySystemAccess> {\n const accessParamsList = this.createMediaKeySystemAccessParams(drmInfo)\n for (const { keySystem, config } of accessParamsList) {\n try {\n const access =\n await this.deps.commonEme!.requestMediaKeySystemAccess(\n keySystem,\n [config]\n )\n logDebug(\n this,\n `created media key system access for keySystem: ${access.keySystem}}`,\n config\n )\n return access\n } catch (_) {\n // ignore\n }\n }\n throw new DrmError(\n `No keySystem supported`,\n {\n contentProtections: drmInfo as any,\n attemptedKeySystems: accessParamsList.map(\n (arr) => arr.keySystem\n ),\n },\n ErrorOrigin.DRM\n )\n }\n\n /**\n * Creates a list of the MediaKeySystemAccess configurations to try for the given media format options.\n */\n private createMediaKeySystemAccessParams(\n drmInfo: MediaFormatMetadata\n ): readonly MediaKeySystemAccessParams[] {\n const keySystems = drmInfo.contentProtections\n .map((protection) => protection.keySystem)\n .sort(this.keySystemComparator)\n\n return keySystems.map((keySystem): MediaKeySystemAccessParams => {\n const mediaOptions = this.getMediaKeySystemOptions(\n keySystem,\n drmInfo.contentType\n )\n const capability: MediaKeySystemMediaCapability = {\n robustness:\n mediaOptions?.robustness ?? DrmRobustness.SW_SECURE_CRYPTO,\n encryptionScheme: drmInfo.encryptionScheme,\n }\n if (drmInfo.mimeType) {\n capability.contentType = drmInfo.mimeType\n }\n const config: MediaKeySystemConfiguration = {\n initDataTypes: [drmInfo.initDataType ?? 'cenc'],\n }\n const contentType = drmInfo.contentType\n if (contentType === 'video') {\n config.videoCapabilities = [capability]\n } else if (contentType === 'audio') {\n config.audioCapabilities = [capability]\n }\n return {\n keySystem,\n config,\n // Concatenate a list of inputs to use as a cache key for isSupported checks.\n cacheKey: [\n keySystem,\n drmInfo.mimeType,\n drmInfo.contentType,\n capability.robustness,\n drmInfo.encryptionScheme,\n drmInfo.initDataType,\n ]\n .map(String)\n .join('|'),\n }\n })\n }\n\n private getMediaKeySystemOptions(\n keySystem: DrmKeySystem,\n contentType: Maybe<ContentType>\n ): DrmMediaKeySystemOptions | undefined {\n const keySystems = this.options.keySystems\n const keySystemOptions = keySystems[keySystem] ?? keySystems['*']\n if (!keySystemOptions) return undefined\n switch (contentType) {\n case 'video':\n return keySystemOptions.video\n case 'audio':\n return keySystemOptions.audio\n default:\n return undefined\n }\n }\n\n /**\n * Creates a new key session and adds a message handler.\n */\n private async createNewSession(\n serverCertificate: Maybe<ServerCertificate>,\n mediaKeys: CommonMediaKeys,\n initData: EncryptedInitData,\n initDataType: DrmInitDataType,\n drmInfo: MediaFormatMetadata & { readonly mimeType: string },\n initDataTransformer?: InitDataTransformer\n ): Promise<CommonMediaKeySession> {\n const certBytes = serverCertificate\n ? typeof serverCertificate === 'string'\n ? base64ToByteArray(serverCertificate)\n : bufferToByteArray(serverCertificate)\n : null\n\n if (certBytes) {\n await mediaKeys.setServerCertificate(certBytes)\n }\n\n // Default initDataTransformer handles FAIR_PLAY_1_0 by packing the\n // skd init data with the content ID and server certificate.\n // FAIR_PLAY_1_0 always uses initDataType 'skd', so the default\n // does not need to explicitly check initDataType.\n const transform =\n initDataTransformer ??\n defaultInitDataTransformer(mediaKeys.keySystem, certBytes)\n initData = transform(bufferToByteArray(initData), initDataType, drmInfo)\n\n logDebug(this, 'createSession', drmInfo.mimeType, initDataType)\n const session = mediaKeys.createSession(\n drmInfo.mimeType,\n initDataType,\n initData\n )\n session.on('message', (event) => {\n withTimeout(\n this.messageHandler({\n mediaKeys: mediaKeys,\n session: session,\n event: event,\n }),\n LICENSE_TIMEOUT,\n LICENSE_TIMEOUT_MESSAGE\n ).catch(this.handleError)\n })\n session.on('error', (event) => {\n this.closeSession(session)\n this.handleError(event.error)\n })\n return session\n }\n\n /**\n * Invoked when the content decryption module needs to interact with the license server.\n */\n private async messageHandler(\n messageProps: DrmControllerMessageProps\n ): Promise<void> {\n const { mediaKeys, session, event } = messageProps\n messageEventValidator.assert(event)\n this.pendingMessageProps = messageProps\n\n const keySystem = mediaKeys.keySystem\n logDebug(this, 'message', keySystem, event.message.byteLength)\n\n const keySystemOptions = this.options.keySystems[keySystem]\n const licenseServerOptionsProvider = keySystemOptions?.licenseServer\n\n // Get the license server configuration for the current key system.\n const licenseServerOptions =\n clone(await resolveValueProvider(licenseServerOptionsProvider)) ??\n {}\n\n let challenge: BodyInit = event.message\n if (isPlayReady(keySystem)) {\n const unpacked = unpackPlayReadyChallenge(challenge)\n challenge = unpacked.challenge\n if (licenseServerOptions.init == null)\n licenseServerOptions.init = {}\n licenseServerOptions.init.headers = {\n ...normalizeHeadersInit(\n licenseServerOptions.init.headers ?? {}\n ),\n ...unpacked.headers,\n }\n }\n const key = await this.licenseProvider(\n keySystem,\n licenseServerOptions,\n challenge\n )\n this.pendingMessageProps = null\n if (session.disposed) return\n logDebug(this, 'update')\n await session.update(key)\n }\n\n //--------------------------------------------\n // Session management\n //--------------------------------------------\n\n /**\n * Closes all active DRM sessions.\n * This should not be called unless the audio source has been cleared.\n */\n closeSessions() {\n logDebug(this, `clearing ${this.sessions.length} sessions`)\n while (this.sessions.length) this.closeSession(this.sessions[0])\n }\n\n private closeSession(session: CommonMediaKeySession) {\n logDebug(this, 'closeSession')\n session.dispose()\n remove(this.sessions, session)\n this.dispatch('sessionClose', {\n initDataType: session.initDataType,\n mimeType: session.mimeType,\n })\n }\n\n /**\n * A handler which dispatches an error event.\n * Only one error event will be emitted per unique PSSH.\n * When track protections is set again, another error event may be emitted.\n */\n private readonly handleError = (error: Error) => {\n if (!this._error && !isSilentError(error)) {\n this._error = error\n this.dispatch('error', { error, target: this })\n }\n }\n\n /**\n * Returns the number of currently active sessions.\n */\n get activeSessions(): number {\n return this.sessions.length\n }\n\n /**\n * Clears the media keys from the element if they were set.\n */\n private clearMediaKeys() {\n this.closeSessions()\n if (this.mediaKeys) {\n logDebug(this, 'clearing media keys')\n this.mediaKeys.clearFromElement(this.deps.media).catch(noop)\n this.mediaKeys = null\n }\n this.mediaKeysPromise = null\n }\n\n protected abortIfDisposed() {\n if (this.disposed) throw new AbortError()\n }\n\n reset() {\n if (!this._error) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n if (this.pendingMessageProps) {\n const mediaError = this.deps.media.error\n if (mediaError && mediaError.code === mediaError.MEDIA_ERR_DECODE) {\n // Media is in a failed decoding state, cannot recover from a failed license request.\n // The PlaybackController will attempt a reset.\n logDebug(\n this,\n 'media in an error state, will not retry failed license challenge'\n )\n this.pendingMessageProps = null\n } else {\n logDebug(this, 'retrying failed license challenge')\n this.messageHandler(this.pendingMessageProps).catch(\n this.handleError\n )\n }\n }\n this.dispatch('reset', {})\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n logDebug(this, 'dispose')\n super.dispose()\n this.clearMediaKeys()\n this.disposer.dispose()\n }\n\n private getSessionByInitData(\n initData: EncryptedInitData\n ): CommonMediaKeySession | null {\n return (\n this.sessions.find((session) => {\n return buffersEqual(session.initData, initData)\n }) ?? null\n )\n }\n\n /**\n * Sort the key systems first by their priority, then by the presence of a license uri.\n */\n private readonly keySystemComparator: Comparator<DrmKeySystem> = /* @__PURE__ */ compareBy(\n (keySystem: DrmKeySystem) => {\n return -(this.options.keySystems[keySystem]?.priority ?? 0)\n },\n (keySystem: DrmKeySystem) => {\n return this.options.keySystems[keySystem]?.licenseServer != null\n ? 0\n : 1\n }\n )\n}\n\ninterface MediaKeySystemAccessParams {\n readonly keySystem: DrmKeySystem\n readonly config: MediaKeySystemConfiguration\n readonly cacheKey: string\n}\n\nconst messageEventValidator: ObjectSchema<CommonMediaKeyMessageEvent> = /* @__PURE__ */ object({\n message: /* @__PURE__ */ instanceOf(ArrayBuffer),\n})\n\nfunction hasMimeType(\n drmInfo: MediaFormatMetadata\n): drmInfo is MediaFormatMetadata & { readonly mimeType: string } {\n return drmInfo.mimeType != null\n}\n\n/**\n * Default initDataTransformer. For FAIR_PLAY_1_0, packs the skd init data\n * with the extracted content ID and server certificate into the format\n * expected by WebKit-prefixed EME. FAIR_PLAY_1_0 always uses initDataType\n * 'skd', so we only need to check the key system.\n * For all other key systems, returns init data unchanged.\n */\nfunction defaultInitDataTransformer(\n keySystem: DrmKeySystem,\n certBytes: Uint8Array<ArrayBuffer> | null\n): InitDataTransformer {\n return (initData: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer> => {\n if (keySystem === DrmKeySystem.FAIR_PLAY_1_0) {\n if (!certBytes) {\n throw new DrmError('FairPlay requires certificate data')\n }\n const contentId = extractContentId(initData)\n return createFairPlaySessionInitData(initData, contentId, certBytes)\n }\n return initData\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n base64ToByteArray,\n bufferToUtf16,\n logDebug,\n type LogTarget,\n type ReadonlyRecord,\n} from '@amazon/vinyl-util'\nimport type { XmlElement } from '@amazon/vinyl-xml'\nimport {\n attrInt,\n attrString,\n charactersString,\n element,\n elements,\n parseXml,\n parseXmlHandler,\n type XmlRules,\n} from '@amazon/vinyl-xml'\n\n/**\n * The final challenge buffer and headers for a playready license challenge.\n */\nexport interface UnpackedPlayReadyChallenge {\n readonly challenge: ArrayBuffer\n readonly headers: ReadonlyRecord<string, string>\n}\n\nconst logTarget: LogTarget = {\n logPrefix: 'unpackPlayReadyChallenge',\n}\n\n/**\n * IE and Edge wraps playready license challenges in PlayReadyKeyMessage xml.\n * Not all PlayReady clients do this.\n * Checks if the challenge is wrapped, and if so, returns the set headers and unwrapped challenge.\n * Otherwise, returns the challenge as-is with the required content type header.\n *\n * @param challenge The array buffer from the 'message' cdm event.\n */\nexport function unpackPlayReadyChallenge(\n challenge: ArrayBuffer\n): UnpackedPlayReadyChallenge {\n const xml = challenge.byteLength % 2 === 0 ? bufferToUtf16(challenge) : ''\n if (!xml.includes('PlayReadyKeyMessage')) {\n logDebug(logTarget, 'not wrapped')\n // A client that does not wrap the challenge.\n return {\n challenge,\n headers: {\n 'Content-Type': 'text/xml; charset=utf-8',\n },\n }\n }\n logDebug(logTarget, 'unpacking challenge')\n const message = parsePlayReadyKeyMessage(xml)\n const licenseAcquisition = message.PlayReadyKeyMessage.LicenseAcquisition\n const unpackedChallenge = base64ToByteArray(\n licenseAcquisition.Challenge._content\n ).buffer\n const headers: Record<string, string> = {}\n for (const element of licenseAcquisition.HttpHeaders.HttpHeader) {\n headers[element.name._content] = element.value._content\n }\n return {\n challenge: unpackedChallenge,\n headers,\n }\n}\n\ninterface PlayReadyMessage {\n readonly PlayReadyKeyMessage: PlayReadyKeyMessageType\n}\n\ninterface PlayReadyKeyMessageType {\n readonly type?: string\n readonly LicenseAcquisition: LicenseAcquisitionType\n}\n\ninterface LicenseAcquisitionType {\n readonly Version: number\n readonly Challenge: ChallengeType\n readonly HttpHeaders: HttpHeadersType\n}\n\ninterface ContentType {\n readonly _content: string\n}\n\ninterface ChallengeType extends ContentType {\n readonly encoding?: string\n}\n\ninterface HttpHeadersType {\n readonly HttpHeader: readonly HttpHeaderType[]\n}\n\ninterface HttpHeaderType {\n readonly name: ContentType\n readonly value: ContentType\n}\n\nconst challengeType: XmlRules<ChallengeType> = {\n _content: charactersString,\n encoding: attrString,\n}\n\nconst contentType: XmlRules<ContentType> = {\n _content: charactersString,\n}\n\nconst headerType: XmlRules<HttpHeaderType> = {\n name: /* @__PURE__ */ element(contentType, { required: true }),\n value: /* @__PURE__ */ element(contentType, { required: true }),\n}\n\nconst httpHeadersType: XmlRules<HttpHeadersType> = {\n HttpHeader: /* @__PURE__ */ elements(headerType, { useEmptyArrays: true }),\n}\n\nconst licenseAcquisitionType: XmlRules<LicenseAcquisitionType> = {\n Challenge: /* @__PURE__ */ element(challengeType, { required: true }),\n HttpHeaders: /* @__PURE__ */ element(httpHeadersType, { required: true }),\n Version: /* @__PURE__ */ attrInt({ required: true }),\n}\n\nconst playReadyKeyMessageType: XmlRules<PlayReadyKeyMessageType> = {\n LicenseAcquisition: /* @__PURE__ */ element(licenseAcquisitionType, { required: true }),\n type: /* @__PURE__ */ attrString(),\n}\n\nconst playReadyMessageRules: XmlRules<PlayReadyMessage> = {\n PlayReadyKeyMessage: /* @__PURE__ */ element(playReadyKeyMessageType, {\n required: true,\n }),\n}\n\n/**\n * A Content handler for a PlayReady SOAP message.\n */\nconst playReadyXmlHandler = /* @__PURE__ */ parseXmlHandler(playReadyMessageRules)\n\nexport function parsePlayReadyKeyMessage(\n xmlStr: string\n): PlayReadyMessage & XmlElement<PlayReadyMessage> {\n return parseXml(xmlStr, playReadyXmlHandler)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyAbort } from '@amazon/vinyl-util'\nimport { requestWithRetry, ValidationError } from '@amazon/vinyl-util'\nimport type { DrmKeySystem } from '@/drm/DrmKeySystem'\nimport type { LicenseProvider, LicenseServerOptions } from './LicenseProvider'\n\n/**\n * A basic LicenseProvider which uses the configuration set for the current key system,\n * transmits a challenge as the body, and returns an array buffer.\n *\n * @param keySystem The key system for the current license challenge.\n * @param serverOptions The resolved configuration. The default DrmController\n * implementation provides this from the `drm` configuration set when creating\n * a new player.\n * @param challenge The license challenge, provided by the CDM (Content Decryption\n * Module)\n * @param abort (optional) When aborted, should cancel any active requests.\n */\nexport const defaultLicenseProvider: LicenseProvider = async (\n keySystem: DrmKeySystem,\n serverOptions: LicenseServerOptions,\n challenge: ArrayBuffer,\n abort?: ReadonlyAbort\n): Promise<ArrayBuffer> => {\n if (serverOptions.url == null) {\n throw new ValidationError(\n `Missing licenseServer url in DRM configuration for keySystem: ${keySystem}`\n )\n }\n const res = await requestWithRetry(\n serverOptions.url,\n {\n method: 'POST',\n ...serverOptions.init,\n body: challenge,\n },\n { abort }\n )\n return await res.arrayBuffer()\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ValidationError } from '@amazon/vinyl-util'\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport { bufferToUtf16 } from '@amazon/vinyl-util'\n\n/**\n * Extract contentId from event data encoded as UTF16.\n *\n * @param initData Expected byte array representing a UTF-16 string in the form\n * `skd://0b5689bb-4171-97e5-c280-99f7abe4004f`\n */\nexport function extractContentId(initData: Uint8Array<ArrayBuffer>): string {\n const bufferStr = bufferToUtf16(initData.buffer)\n const matches = bufferStr.match(/skd:\\/\\/(.+)$/)\n if (!matches) {\n throw new ValidationError('No contentId match', ErrorOrigin.MEDIA)\n }\n return matches[1]\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { utf16ToUint16Array } from '@amazon/vinyl-util'\n\n/**\n * Create the payload for EME media key session from `encrypted` / `*needkey` event data and DRM\n * certificate.\n * Note: This code is taken from the official FairPlay SDK example.\n *\n * @param initData\n * @param contentId\n * @param certificateData certificate data as a Uint8Array\n */\nexport function createFairPlaySessionInitData(\n initData: Uint8Array,\n contentId: string,\n certificateData: Uint8Array\n): Uint8Array<ArrayBuffer> {\n const contentIdUint16 = utf16ToUint16Array(contentId)\n const certificateDataUint8 = certificateData\n\n let offset = 0\n const buffer = new ArrayBuffer(\n initData.byteLength +\n 4 + // contentId length\n contentIdUint16.byteLength +\n 4 + // certificateDataUint8 length\n certificateDataUint8.byteLength\n )\n\n const initDataArray = new Uint8Array(buffer, offset, initData.byteLength)\n initDataArray.set(initData)\n offset += initData.byteLength\n\n const dataView = new DataView(buffer)\n dataView.setUint32(offset, contentIdUint16.byteLength, true)\n offset += 4\n\n const idArray = new Uint16Array(buffer, offset, contentIdUint16.length)\n idArray.set(contentIdUint16)\n offset += idArray.byteLength\n\n dataView.setUint32(offset, certificateDataUint8.byteLength, true)\n offset += 4\n\n const certArray = new Uint8Array(\n buffer,\n offset,\n certificateDataUint8.byteLength\n )\n certArray.set(certificateDataUint8)\n\n return new Uint8Array(buffer, 0, buffer.byteLength)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type ReadonlyRecord } from '@amazon/vinyl-util'\nimport {\n DrmKeySystem,\n FAIR_PLAY_KEY_SYSTEMS,\n PLAY_READY_KEY_SYSTEMS,\n} from '@/drm/DrmKeySystem'\nimport { ContentProtectionScheme } from '@amazon/vinyl-mpd-parser'\n\n/**\n * Given a ContentProtection schemeIdUri, returns the {@link DrmKeySystem} it represents.\n * Not all scheme ids will match to a DrmKeySystem. If none are matched, null is returned.\n * For example, CENC 'urn:mpeg:dash:mp4protection:2011' has no key system and shouldn't be used\n * to create a key session.\n */\nexport type DrmKeySystemResolver = (\n schemeIdUri: string\n) => readonly DrmKeySystem[]\n\nlet _defaultSchemeToKeySystem: ReadonlyRecord<\n string,\n readonly DrmKeySystem[]\n> | null = null\n\nexport function getDefaultSchemeToKeySystem(): ReadonlyRecord<\n string,\n readonly DrmKeySystem[]\n> {\n if (_defaultSchemeToKeySystem == null) {\n _defaultSchemeToKeySystem = {\n [ContentProtectionScheme.CLEAR_KEY]: [DrmKeySystem.CLEAR_KEY],\n [ContentProtectionScheme.FAIR_PLAY]: FAIR_PLAY_KEY_SYSTEMS,\n [ContentProtectionScheme.PLAY_READY]: PLAY_READY_KEY_SYSTEMS,\n [ContentProtectionScheme.WIDEVINE]: [DrmKeySystem.WIDEVINE],\n } as const\n }\n return _defaultSchemeToKeySystem\n}\n\nexport const defaultDrmKeySystemResolver: DrmKeySystemResolver = (\n schemeIdUri: string\n) => {\n return getDefaultSchemeToKeySystem()[schemeIdUri.toLowerCase()] ?? []\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { createDisposer, type LogTarget } from '@amazon/vinyl-util'\nimport {\n logDebug,\n createLogPrefix,\n EventHostImpl,\n closeTo,\n} from '@amazon/vinyl-util'\nimport type {\n LoudnessNormalizationController,\n LoudnessNormalizationControllerEventMap,\n} from './LoudnessNormalizationController'\nimport {\n defaultLoudnessNormalizationControllerImplOptions,\n type LoudnessNormalizationControllerImplOptions,\n} from './LoudnessNormalizationControllerImplOptions'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\n\nexport type LoudnessNormalizationControllerImplDeps = {\n readonly options: ObservableValue<LoudnessNormalizationControllerImplOptions>\n}\n\nconst DECIBEL_EXPONENT_BASE = /* @__PURE__ */ Math.pow(10, 1 / 10)\nconst MAX_GAIN_LEVEL = 1.0\n\n/**\n * Applies gain adjustment based on track loudness metadata from manifest.\n * This controller normalizes audio loudness to a target level for consistent playback volume.\n */\nexport class LoudnessNormalizationControllerImpl\n extends EventHostImpl<LoudnessNormalizationControllerEventMap>\n implements LoudnessNormalizationController, LogTarget\n{\n get [Symbol.toStringTag](): string {\n return 'LoudnessNormalizationControllerImpl'\n }\n readonly logPrefix = /* @__PURE__ */ createLogPrefix(this)\n\n private _gain: number = MAX_GAIN_LEVEL\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n private trackLoudness: number | null = null\n private _options: Required<LoudnessNormalizationControllerImplOptions> =\n defaultLoudnessNormalizationControllerImplOptions\n\n constructor(\n private readonly deps: LoudnessNormalizationControllerImplDeps\n ) {\n super()\n const { add } = this.disposer\n add(\n deps.options.onData((value) => {\n this._options = {\n ...defaultLoudnessNormalizationControllerImplOptions,\n ...value,\n }\n this.updateGain()\n })\n )\n }\n\n get options(): Required<LoudnessNormalizationControllerImplOptions> {\n return this._options\n }\n\n setTrackLoudness(value: number | null): void {\n this.trackLoudness = value\n this.updateGain()\n }\n\n /**\n * Returns the loudness gain value which needs to be applied, for current track playback.\n */\n public get gain(): number {\n return this._gain\n }\n\n /**\n * Sets the loudness gain value for current track playback.\n *\n * @param value New gain value to apply\n */\n private set gain(value: number) {\n const previousGain = this._gain\n // Emit change event if gain value changed\n if (!closeTo(previousGain, value)) {\n this._gain = value\n logDebug(this, 'loudness gain adjustment:', {\n trackLoudness: this.trackLoudness,\n targetLufs: this.options.targetLufs,\n gain: value,\n })\n this.dispatch('change', {})\n }\n }\n\n /**\n * Update gain value based on current track loudness and target loudness.\n */\n private updateGain(): void {\n const { targetLufs, maxGainDb, enabled } = this.options\n const trackLoudness = this.trackLoudness\n if (trackLoudness == null) {\n return\n }\n if (trackLoudness <= targetLufs || !enabled) {\n this.clear()\n return\n }\n // Calculate gain reduction for louder tracks\n const dbReduction = Math.min(trackLoudness - targetLufs, maxGainDb)\n this.gain =\n MAX_GAIN_LEVEL / Math.pow(DECIBEL_EXPONENT_BASE, dbReduction)\n }\n\n /**\n * Resets the loudness gain Value to max gain value.\n */\n clear(): void {\n this.gain = MAX_GAIN_LEVEL\n }\n\n dispose(): void {\n super.dispose()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport { boolean, number, object } from '@amazon/vinyl-validation'\n\n/**\n * Options for configuring the loudness normalization controller.\n */\nexport interface LoudnessNormalizationControllerImplOptions {\n /**\n * If true, applies loudness Normalization to the current track played.\n * Default: false\n */\n readonly enabled: boolean\n\n /**\n * Target loudness level in LUFS (Loudness Units relative to Full Scale).\n * Default: -14.0 dB\n */\n readonly targetLufs?: number\n\n /**\n * Maximum gain reduction to apply in dB.\n * Default: 10 Db\n */\n readonly maxGainDb?: number\n}\n\nexport const defaultLoudnessNormalizationControllerImplOptions = {\n enabled: false,\n targetLufs: -14.0,\n maxGainDb: 10.0,\n} as const satisfies LoudnessNormalizationControllerImplOptions\n\nexport const loudnessNormalizationControllerImplOptionsValidator: ObjectSchema<LoudnessNormalizationControllerImplOptions> =\n /* @__PURE__ */ object({\n enabled: /* @__PURE__ */ boolean(),\n targetLufs: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n maxGainDb: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n })\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n type Clearable,\n createDisposer,\n type Disposable,\n ErrorOrigin,\n EventHostImpl,\n getNetworkState,\n logDebug,\n onAny,\n type ReadonlyEventHost,\n ReportableError,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport type { PlaybackController } from '@/playback/PlaybackController'\n\nexport interface AutoResetControllerEventMap {\n /**\n * Notifies that playback errors should be reset and retried.\n */\n readonly reset: AnyRecord\n}\n\n/**\n * Notifies when playback should be reset and retried.\n *\n * The controller monitors for retry opportunities after an error is set:\n * - Immediately on network 'online' events\n * - After a timeout interval if online\n * - Immediately on user playback actions (play, pause, seeking, playing)\n *\n * Each error triggers a single timeout. If another error occurs after a reset,\n * setError() should be called again to schedule the next retry attempt.\n */\nexport interface AutoResetController\n extends ReadonlyEventHost<AutoResetControllerEventMap>, Clearable {\n /**\n * Sets the current playback error and begins monitoring for retry opportunities.\n *\n * Only SERVICE_INTERNAL ReportableErrors are monitored. Subsequent calls while\n * an error is already set are ignored until the error is cleared via reset or clear().\n *\n * After a reset, if another error occurs, this method should be called again\n * to schedule the next retry attempt.\n *\n * @param error The error to monitor for retry opportunities\n */\n setError(error: Error): void\n}\n\nexport interface AutoResetControllerImplDeps {\n readonly playbackController: PlaybackController\n}\n\nexport interface AutoResetControllerImplOptions {\n /**\n * If false, disables auto reset behavior.\n * default: true\n */\n readonly enabled: boolean\n\n /**\n * The total number of times to reset when there has not been successful\n * playback.\n *\n * E.g. a retryInterval of 30 and maxRetries of 30 will retry for 15 minutes before stopping.\n *\n * default: 30\n */\n readonly maxRetries: number\n\n /**\n * The number of seconds between retries.\n *\n * When an error is set, a single timeout is scheduled for this interval.\n * If the retry limit hasn't been reached and the device is online, a reset\n * event is emitted. For subsequent errors after reset, setError() must be\n * called again to schedule the next retry timeout.\n */\n readonly retryInterval: number\n}\n\nexport const defaultResetControllerOptions = {\n enabled: true,\n maxRetries: 30,\n retryInterval: 30,\n} as const satisfies AutoResetControllerImplOptions\n\nexport class AutoResetControllerImpl\n extends EventHostImpl<AutoResetControllerEventMap>\n implements AutoResetController, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'AutoResetControllerImpl'\n }\n\n private readonly options: AutoResetControllerImplOptions\n private _error: Error | null = null\n private watchSub: Unsubscribe | null = null\n private currentRetry = 0\n private disposer = /* @__PURE__ */ createDisposer()\n\n constructor(\n readonly deps: AutoResetControllerImplDeps,\n options?: Partial<AutoResetControllerImplOptions>\n ) {\n super()\n logDebug(this, 'constructor')\n this.options = {\n ...defaultResetControllerOptions,\n ...options,\n }\n\n this.disposer.add(\n onAny(\n deps.playbackController,\n ['play', 'pause', 'seeking', 'playing'],\n (_event) => {\n // On certain user-initiated playback events, reset the currentRetry count and emit a reset event\n // if in an error state.\n this.currentRetry = 0\n this.reset()\n }\n )\n )\n }\n\n setError(error: Error): void {\n if (!this.options.enabled || this._error) return\n if (\n error instanceof ReportableError &&\n error.origin === ErrorOrigin.SERVICE_INTERNAL\n ) {\n this._error = error\n this.setWatching(true)\n }\n }\n\n private setWatching(value: boolean): void {\n logDebug(this, 'setWatching', value)\n this.watchSub?.()\n this.watchSub = null\n if (!value) return\n const networkState = getNetworkState()\n const { add, dispose: watchSub } = createDisposer()\n this.watchSub = watchSub\n add(\n networkState.on('online', () => {\n logDebug(this, 'online, emitting reset')\n this.reset()\n })\n )\n\n const intervalId = setTimeout(() => {\n if (this.currentRetry++ < this.options.maxRetries) {\n if (networkState.onLine) {\n logDebug(this, 'interval, emitting reset')\n this.reset()\n }\n } else {\n logDebug(this, 'max retries exhausted, pausing playback')\n this.setWatching(false)\n }\n }, this.options.retryInterval * 1000)\n add(() => clearTimeout(intervalId))\n }\n\n private reset(): void {\n if (!this._error) return\n this.clear()\n this.dispatch('reset', {})\n }\n\n clear() {\n if (!this._error) return\n this._error = null\n this.setWatching(false)\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n this.disposer.dispose()\n this.clear()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n defaultQualitySelectorImplOptions,\n type QualitySelectorImplOptions,\n qualitySelectorImplOptionsValidator,\n} from '@/streaming/abr/QualitySelectorImpl'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport { object, string } from '@amazon/vinyl-validation'\nimport {\n defaultLoudnessNormalizationControllerImplOptions,\n type LoudnessNormalizationControllerImplOptions,\n loudnessNormalizationControllerImplOptionsValidator,\n} from '@/playback/loudness/LoudnessNormalizationControllerImplOptions'\n\nexport interface VinylOptions {\n /**\n * Configuration for the default adaptive bitrate selector.\n */\n readonly abr: QualitySelectorImplOptions\n\n readonly loudnessNormalization: LoudnessNormalizationControllerImplOptions\n\n /**\n * Preferred language for audio content, using a code as defined by RFC 5646 (e.g. 'en', 'ja').\n * When set, only adaptation sets / variants matching this language (or without a language tag)\n * are kept. Null means no language preference (all languages are kept).\n */\n readonly preferredAudioLanguage: string | null\n}\n\nexport const defaultVinylOptions: VinylOptions = {\n abr: defaultQualitySelectorImplOptions,\n loudnessNormalization: defaultLoudnessNormalizationControllerImplOptions,\n preferredAudioLanguage: null,\n}\n\nexport const vinylOptionsValidator: ObjectSchema<VinylOptions> = /* @__PURE__ */ object({\n abr: qualitySelectorImplOptionsValidator,\n loudnessNormalization: loudnessNormalizationControllerImplOptionsValidator,\n preferredAudioLanguage: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Client } from '@/client/Client'\nimport {\n type AnyRecord,\n createDisposer,\n type Disposable,\n emptyRanges,\n equalDeep,\n EventHostImpl,\n logDebug,\n logInfo,\n type ReadonlyRanges,\n type ReadonlySet,\n redispatchEvents,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport {\n createContainer,\n type Factories,\n type ValidFactoryOverrides,\n} from '@amazon/vinyl-di'\nimport { playerRegistryRef } from '@/global/PlayerRegistry'\nimport type { PlaybackController } from '@/playback/PlaybackController'\nimport {\n ALL_PLAYBACK_STATE_EVENTS,\n type PlaybackControllerEventMap,\n type PlaybackNetworkState,\n type PlaybackReadyState,\n} from '@/playback/ReadonlyPlaybackController'\nimport type { VinylTrackLoadOptions } from '@/track/createVinylTrackFactories'\nimport { type ReadonlyTrack, type TrackUri } from '@/track/Track'\nimport {\n ALL_TRACK_CONTROLLER_EVENTS,\n type TrackController,\n type TrackControllerEventMap,\n} from '@/track/TrackController'\nimport type {\n InferLoadOptionsFromFactory,\n TrackLoadOptions,\n} from '@/track/TrackFactory'\nimport type {\n DefaultVinylFactories,\n InferVinylOverrideDependencyType,\n VinylDependencyOptions,\n} from './createVinylFactories'\nimport { createVinylFactories } from './createVinylFactories'\nimport type { VinylDeps } from './VinylDeps'\nimport type { Capabilities } from '@/client/Capabilities'\nimport { initializeVinylGlobal } from '@/global/initializeVinylGlobal'\nimport {\n ALL_CONTENT_TYPES,\n type ContentType,\n type MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport type { ReadonlyPlaybackStreamingState } from '@/vinyl/ReadonlyPlaybackStreamingState'\nimport type { DrmController } from '@/drm/DrmController'\nimport {\n ALL_STREAMING_EVENTS,\n type StreamingEventMap,\n} from '@/streaming/StreamingEventMap'\nimport type {\n InferObservableValueType,\n MutableValue,\n} from '@amazon/vinyl-observable'\nimport type { VinylOptions } from '@/vinyl/VinylOptions'\n\n/**\n * Events the Vinyl Player emits.\n */\nexport interface VinylPlayerEventMap<\n TrackLoadOptionsType extends TrackLoadOptions = VinylTrackLoadOptions,\n>\n extends\n PlaybackControllerEventMap,\n TrackControllerEventMap<TrackLoadOptionsType>,\n StreamingEventMap {}\n\n/**\n * A Vinyl Media Player.\n *\n * Unless custom dependencies need to be provided, use {@link createVinylPlayer} to construct\n * a new player implementation.\n */\nexport class VinylPlayer<\n TrackLoadOptionsType extends TrackLoadOptions = VinylTrackLoadOptions,\n OptionsType = VinylOptions,\n>\n extends EventHostImpl<VinylPlayerEventMap<TrackLoadOptionsType>>\n implements\n PlaybackController,\n TrackController<TrackLoadOptionsType>,\n ReadonlyPlaybackStreamingState,\n Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'VinylPlayer'\n }\n\n protected readonly deps: VinylDeps<TrackLoadOptionsType, OptionsType>\n\n private get drmController(): DrmController {\n return this.deps.drmController\n }\n\n private get playbackController(): PlaybackController {\n return this.deps.playbackController\n }\n\n private get trackController(): TrackController<TrackLoadOptionsType> {\n return this.deps.trackController\n }\n\n /**\n * Provides information about the client, such as device and browser capabilities.\n */\n readonly client: Client\n\n private _error: Error | null = null\n\n protected readonly disposer = /* @__PURE__ */ createDisposer()\n\n /**\n * Constructs a new VinylPlayer with the given dependency factories.\n * This constructor is protected, use {@link createVinylPlayer} to construct a new player.\n *\n * @param factories\n * @see createVinylPlayer\n */\n protected constructor(\n factories: Factories<VinylDeps<TrackLoadOptionsType, OptionsType>>\n ) {\n initializeVinylGlobal()\n super()\n const add = this.disposer.add\n this.deps = add(createContainer(factories)).dependencies\n\n this.client = {\n capabilities: this.deps.capabilities,\n }\n playerRegistryRef.value.addPlayer(this)\n this.redispatchSubControllerEvents()\n this.redispatchCurrentTrackEvents()\n this.initializeAutoResetHandling()\n this.initializePreferredLanguageHandling()\n }\n\n protected redispatchSubControllerEvents(): void {\n const add = this.disposer.add\n add(\n redispatchEvents(\n this,\n this.playbackController,\n ALL_PLAYBACK_STATE_EVENTS.filter(notResetEvent)\n )\n )\n add(\n redispatchEvents(\n this,\n this.trackController,\n ALL_TRACK_CONTROLLER_EVENTS\n )\n )\n add(redispatchEvents(this, this.drmController, ['error']))\n\n this.on('error', (event) => {\n this._error = event.error\n })\n }\n\n /**\n * Certain track events are redispatched on the player for the current track.\n */\n protected redispatchCurrentTrackEvents() {\n let sub: Unsubscribe | null = null\n const add = this.disposer.add\n add(\n this.trackController.on('currentTrackChange', (event) => {\n sub?.()\n sub = null\n if (event.current) {\n sub = redispatchEvents(\n this,\n event.current,\n ALL_STREAMING_EVENTS.filter(notResetEvent)\n )\n }\n this.dispatch('fetchedRangesChange', {})\n\n // Emit a quality change event for every stream that has changed\n // for streaming, buffering, and playback\n for (const contentType of ALL_CONTENT_TYPES) {\n for (const [\n eventType,\n getterName,\n ] of qualityEventsAndGetters) {\n const previous =\n event.previous?.[getterName](contentType) ?? null\n const current =\n event.current?.[getterName](contentType) ?? null\n if (previous !== current) {\n this.dispatch(eventType, {\n previous,\n current,\n })\n }\n }\n }\n\n // Emit qualities change events on track switch\n const prevQualities = event.previous?.qualities ?? null\n const curQualities = event.current?.qualities ?? null\n if (prevQualities !== curQualities && curQualities) {\n this.dispatch('qualitiesChange', {\n previous: prevQualities ?? [],\n current: curQualities,\n })\n }\n const prevUnfiltered =\n event.previous?.qualitiesUnfiltered ?? null\n const curUnfiltered = event.current?.qualitiesUnfiltered ?? null\n if (prevUnfiltered !== curUnfiltered && curUnfiltered) {\n this.dispatch('qualitiesUnfilteredChange', {\n previous: prevUnfiltered ?? [],\n current: curUnfiltered,\n })\n }\n })\n )\n }\n\n private initializeAutoResetHandling() {\n // Initializes the binding between the player and the reset handler.\n // On an error, notify the auto reset controller which will\n // monitor network changes and periodically request a reset.\n const { add } = this.disposer\n const { autoResetController } = this.deps\n this.on('error', (event) => {\n autoResetController.setError(event.error)\n })\n add(autoResetController.on('reset', () => this.reset()))\n }\n\n private initializePreferredLanguageHandling() {\n const { add } = this.disposer\n // When the preferred language changes, clear the prefetch to immediately switch.\n add(\n (this.deps.options as MutableValue<VinylOptions>)\n .pick('preferredAudioLanguage')\n .onData((_value, previous) => {\n if (previous !== undefined) this.clearPrefetch()\n })\n )\n }\n\n /**\n * Returns the current player options.\n * Use `configure` to set.\n */\n get options(): OptionsType {\n return this.deps.options.value\n }\n\n /**\n * Sets options on this player.\n * Options will be merged shallowly, for example,\n * `configure({ abr: { strategy: AbrStrategy.BEST }})` will replace all previous `abr` options, and not\n * change other options such as `loudnessNormalization`.\n *\n * @param options\n */\n configure(options: Partial<OptionsType>): void {\n logDebug(this, 'configure', options)\n const newValue = { ...this.options, ...options }\n if (!equalDeep(newValue, this.options)) {\n this.deps.options.value = newValue\n }\n }\n\n get capabilities(): Capabilities {\n return this.deps.capabilities\n }\n\n //----------------------------------------------------\n // PlaybackController delegate methods\n //----------------------------------------------------\n\n get buffered(): ReadonlyRanges {\n return this.playbackController.buffered\n }\n\n get canPlay(): boolean {\n return this.playbackController.canPlay\n }\n\n get canPlayThrough(): boolean {\n return this.playbackController.canPlayThrough\n }\n\n get currentTime(): number {\n return this.playbackController.currentTime\n }\n\n get currentTimePercent(): number {\n return this.playbackController.currentTimePercent\n }\n\n get defaultPlaybackRate(): number {\n return this.playbackController.defaultPlaybackRate\n }\n\n set defaultPlaybackRate(value: number) {\n this.playbackController.defaultPlaybackRate = value\n }\n\n get duration(): number {\n return this.playbackController.duration\n }\n\n get ended(): boolean {\n return this.playbackController.ended\n }\n\n /**\n * The last error reported.\n */\n get error(): Error | null {\n return this._error\n }\n\n get hasMetadata(): boolean {\n return this.playbackController.hasMetadata\n }\n\n get loop(): boolean {\n return this.playbackController.loop\n }\n\n set loop(value: boolean) {\n this.playbackController.loop = value\n }\n\n get muted(): boolean {\n return this.playbackController.muted\n }\n\n set muted(value: boolean) {\n this.playbackController.muted = value\n }\n\n get networkState(): PlaybackNetworkState {\n return this.playbackController.networkState\n }\n\n get paused(): boolean {\n return this.playbackController.paused\n }\n\n get playbackRate(): number {\n return this.playbackController.playbackRate\n }\n\n set playbackRate(value: number) {\n this.playbackController.playbackRate = value\n }\n\n get playIsPending(): boolean {\n return this.playbackController.playIsPending\n }\n\n get playing(): boolean {\n return this.playbackController.playing\n }\n\n get preservesPitch(): boolean {\n return this.playbackController.preservesPitch\n }\n\n set preservesPitch(value: boolean) {\n this.playbackController.preservesPitch = value\n }\n\n get readyState(): PlaybackReadyState {\n return this.playbackController.readyState\n }\n\n get seekable(): ReadonlyRanges {\n return this.playbackController.seekable\n }\n\n get seeking(): boolean {\n return this.playbackController.seeking\n }\n\n get volume(): number {\n return this.playbackController.volume\n }\n\n set volume(value: number) {\n this.playbackController.volume = value\n }\n\n get waiting(): boolean {\n return this.playbackController.waiting\n }\n\n pause(): void {\n this.playbackController.pause()\n }\n\n play(): Promise<void> {\n return this.playbackController.play()\n }\n\n seekTo(time: number, tolerance?: number): Promise<void> {\n return this.playbackController.seekTo(time, tolerance)\n }\n\n reset() {\n if (!this._error) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.drmController.reset()\n this.playbackController.reset()\n this.trackController.reset()\n this.dispatch('reset', {})\n }\n\n //----------------------------------------------------\n // TrackController delegate methods\n //----------------------------------------------------\n\n get currentTrack(): ReadonlyTrack | null {\n return this.trackController.currentTrack\n }\n\n get queue(): readonly TrackLoadOptionsType[] {\n return this.trackController.queue\n }\n\n preload(...loadOptionsList: TrackLoadOptionsType[]): void {\n this.trackController.preload(...loadOptionsList)\n }\n\n load(...loadOptionsList: TrackLoadOptionsType[]): void {\n this.trackController.load(...loadOptionsList)\n }\n\n enqueue(...loadOptionsList: TrackLoadOptionsType[]): void {\n this.trackController.enqueue(...loadOptionsList)\n }\n\n unload(): void {\n this.trackController.unload()\n }\n\n hasNext(): boolean {\n return this.trackController.hasNext()\n }\n\n next(): void {\n return this.trackController.next()\n }\n\n isTrackCached(uri: TrackUri): boolean {\n return this.trackController.isTrackCached(uri)\n }\n\n getCachedTrack(uri: TrackUri): ReadonlyTrack | null {\n return this.trackController.getCachedTrack(uri)\n }\n\n getCachedTracks(): IterableIterator<ReadonlyTrack> {\n return this.trackController.getCachedTracks()\n }\n\n clearPrefetch(): void {\n this.trackController.clearPrefetch()\n }\n\n clearTrackCache(): void {\n this.trackController.clearTrackCache()\n }\n\n clearQueue(): void {\n this.trackController.clearQueue()\n }\n\n //----------------------------------------------------\n // CurrentTrackStreamingState methods\n //----------------------------------------------------\n\n /**\n * Returns the fetched ranges of the current track.\n * If there is no current track, empty ranges will be returned.\n *\n * Listen to {@link VinylPlayerEventMap.fetchedRangesChange} for changes.\n */\n get fetchedRanges(): ReadonlyRanges {\n return this.currentTrack?.fetchedRanges ?? emptyRanges\n }\n\n /**\n * Returns the time of the prefetch end.\n * If no data has been prefetched for the current track, 0 will be returned.\n *\n * The time given will be in seconds according to the media timeline.\n * It will represent the ending time of the continuous prefetch range from the current playhead time.\n */\n get fetchedTime(): number {\n const time = this.playbackController.currentTime\n const range = this.fetchedRanges.getRangeAt(time)\n if (!range) return 0\n return range[1]\n }\n\n /**\n * Returns current fetched time as a percent of the total duration.\n *\n * @return A number between 0-1\n */\n get fetchedTimePercent(): number {\n return this.duration > 0 ? this.fetchedTime / this.duration : 0\n }\n\n /**\n * Returns the current content types for active streams.\n */\n get contentTypes(): ReadonlySet<ContentType> {\n return this.currentTrack?.contentTypes ?? emptyContentTypes\n }\n\n /**\n * The available qualities for the current period of the current track, after filtering.\n * Null if no track is active or the timeline is not yet available.\n */\n get qualities(): readonly MediaQualityMetadata[] | null {\n return this.currentTrack?.qualities ?? null\n }\n\n /**\n * The available unfiltered qualities for the current period of the current track.\n * Null if no track is active or the timeline is not yet available.\n */\n get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null {\n return this.currentTrack?.qualitiesUnfiltered ?? null\n }\n\n /**\n * @deprecated Use `getStreamingQuality('audio')`\n */\n get streamingQuality(): MediaQualityMetadata | null {\n return this.getStreamingQuality('audio')\n }\n\n /**\n * @deprecated Use `getBufferingQuality('audio')\n */\n get bufferingQuality(): MediaQualityMetadata | null {\n return this.getStreamingQuality('audio')\n }\n\n /**\n * @deprecated Use `getPlaybackQuality('audio')\n */\n get playbackQuality(): MediaQualityMetadata | null {\n return this.getPlaybackQuality('audio')\n }\n\n /**\n * The streaming quality for the current track.\n * Note that this does not represent the quality of inactive preloading tracks.\n */\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.currentTrack?.getStreamingQuality(contentType) ?? null\n }\n\n /**\n * The currently buffering quality, or null if no data is buffered.\n */\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.currentTrack?.getBufferingQuality(contentType) ?? null\n }\n\n /**\n * The currently playing quality, or null if no media is playing.\n */\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.currentTrack?.getPlaybackQuality(contentType) ?? null\n }\n\n //----------------------------------------------------\n\n /**\n * Returns true if this player has been disposed.\n */\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n /**\n * Disposes this player and sub-systems.\n */\n dispose(): void {\n logDebug(this, 'dispose')\n super.dispose()\n this.disposer.dispose()\n playerRegistryRef.value.removePlayer(this)\n }\n}\n\n/**\n * Constructs a new {@link VinylPlayer}.\n *\n * @param options Configuration for default dependencies.\n * @param factoryOverrides Dependency factory overrides.\n */\nexport function createVinylPlayer<\n DependencyOverridesType extends Factories | undefined,\n>(\n options: VinylDependencyOptions,\n factoryOverrides?: ValidFactoryOverrides<\n VinylDeps<any, AnyRecord>,\n DefaultVinylFactories,\n DependencyOverridesType\n >\n): VinylPlayer<\n // The player will accept the load options for the track factories, accounting for overrides.\n InferLoadOptionsFromFactory<\n InferVinylOverrideDependencyType<\n NoInfer<DependencyOverridesType>,\n 'trackFactory'\n >\n >,\n // Infer the options type.\n InferObservableValueType<\n InferVinylOverrideDependencyType<\n NoInfer<DependencyOverridesType>,\n 'options'\n >\n >\n> {\n const player = new (VinylPlayer as any)({\n ...createVinylFactories(options),\n ...factoryOverrides,\n })\n logInfo(player, `VinylPlayer initialized`)\n return player\n}\n\n/**\n * Do not redispatch reset events, only emit the reset event when `player.reset` is called.\n * @param type\n */\nfunction notResetEvent<T extends string>(type: T): type is Exclude<T, 'reset'> {\n return type !== 'reset'\n}\n\nconst qualityEventsAndGetters = [\n ['streamingQualityChange', 'getStreamingQuality'],\n ['bufferingQualityChange', 'getBufferingQuality'],\n ['playbackQualityChange', 'getPlaybackQuality'],\n] as const\n\nconst emptyContentTypes = /* @__PURE__ */ new Set<ContentType>()\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AnyRecord, Disposable } from '@amazon/vinyl-util'\nimport {\n globalRef,\n globalTarget,\n IllegalStateError,\n logWarn,\n remove,\n substitute,\n} from '@amazon/vinyl-util'\n\n/**\n * @private\n */\nconst locale = {\n maxPlayersWarning: `{count} Vinyl Players have been constructed without disposal. Check that player.dispose is properly being called, then increase the maxPlayersWarning option if this was intentional.`,\n} as const\n\n/**\n * A registry of all non-disposed Vinyl players.\n * Used for debugging and cleanup validation.\n */\nexport interface PlayerRegistry {\n /**\n * Returns the non-disposed Vinyl players.\n */\n readonly players: readonly AnyRecord[]\n\n /**\n * Adds a player reference. All players must be removed before disposing VinylGlobal.\n *\n * @param player\n */\n addPlayer(player: AnyRecord): void\n\n /**\n * Removes a player reference.\n *\n * @param player\n */\n removePlayer(player: AnyRecord): void\n}\n\nexport const DEFAULT_MAX_PLAYERS = 5\n\n/**\n * A registry of non-disposed players.\n * Used for leak detection and debugging diagnostics.\n */\nexport class PlayerRegistryImpl implements PlayerRegistry, Disposable {\n private _players: AnyRecord[] = []\n\n private gaveMaxPlayersWarning = false\n\n constructor(\n /**\n * The number of concurrent players before a warning is logged.\n * default: 5\n */\n public maxPlayersWarning: number = DEFAULT_MAX_PLAYERS\n ) {}\n\n get players(): readonly AnyRecord[] {\n return this._players\n }\n\n addPlayer(player: AnyRecord): void {\n this._players.push(player)\n const n = this._players.length\n if (n > this.maxPlayersWarning && !this.gaveMaxPlayersWarning) {\n this.gaveMaxPlayersWarning = true\n logWarn(\n globalTarget,\n substitute(locale.maxPlayersWarning, { count: n })\n )\n }\n }\n\n removePlayer(player: AnyRecord): void {\n remove(this._players, player)\n }\n\n /**\n * @throws An IllegalStateError if all players have not been removed.\n */\n dispose() {\n if (this._players.length)\n throw new IllegalStateError(\n 'All players must be removed before disposing VinylGlobal'\n )\n }\n}\n\nexport const playerRegistryRef = /* @__PURE__ */ globalRef<PlayerRegistry>(\n () => new PlayerRegistryImpl()\n)\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { initializeLogging } from '@amazon/vinyl-util'\nimport { vinylGlobalRef } from '@/global/globalRef'\n\nexport function initializeVinylGlobal() {\n initializeLogging()\n vinylGlobalRef.initialize()\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n getNetworkMetrics,\n getUserAgentInfo,\n globalRef,\n historyLogHandler,\n toDisposable,\n} from '@amazon/vinyl-util'\nimport { playerRegistryRef } from './PlayerRegistry'\nimport { vinylVersion } from './environment'\n\ndeclare global {\n /**\n * A reference to Vinyl's global state, easily accessible via console.\n */\n var vinylGlobal: any\n}\n\n/**\n * For console debugging, gives access to currently active players, logs, and client information.\n */\nexport class VinylGlobal {\n get players() {\n return playerRegistryRef.value.players\n }\n\n /**\n * Returns the first player.\n */\n get player() {\n return playerRegistryRef.value.players[0]\n }\n\n get logs() {\n return historyLogHandler.value?.history\n }\n\n get version() {\n return vinylVersion.str\n }\n\n get userAgentInfo() {\n return getUserAgentInfo()\n }\n\n get network() {\n return getNetworkMetrics()\n }\n\n /**\n * Returns the EWMA low estimate for the client's current bandwidth.\n */\n get bandwidth() {\n return this.network.estimatedDownlinkBandwidth.ewmaLow\n }\n}\n\n/**\n * Set the global vinylGlobal reference for easier console debugging.\n * Intentionally typed as AnyRecord to prevent API usage from code. This is\n * intended only for console debugging and the API may change at any time.\n */\nexport const vinylGlobalRef = /* @__PURE__ */ globalRef((): AnyRecord => {\n global.vinylGlobal = new VinylGlobal()\n return toDisposable(() => {\n delete global.vinylGlobal\n })\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { parseVersion } from '@amazon/vinyl-util'\n\n/**\n * process.env.VINYL_VERSION will be null in node unit tests, but in the built library it is\n * replaced by the webpack DefinePlugin with the package.version.\n */\nexport const vinylVersion = /* @__PURE__ */ parseVersion(\n /* istanbul ignore next */\n process.env.VINYL_VERSION ?? '0.0.0.0'\n)\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ChangeEvent } from '@/event/ChangeEvent'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '@/streaming/MediaQualityMetadata'\nimport type { BasicErrorEvent } from '@/event/BasicErrorEvent'\nimport type { AnyRecord } from '@amazon/vinyl-util'\n\n/**\n * Events a track dispatches related to streaming quality and status.\n */\nexport interface StreamingEventMap {\n /**\n * The actively streamed content types have changed.\n */\n readonly contentTypesChange: ChangeEvent<ReadonlySet<ContentType>>\n\n /**\n * fetchedRanges have been updated.\n */\n readonly fetchedRangesChange: AnyRecord\n\n /**\n * Dispatched when the currently streaming quality changes.\n * This is dispatched when a new streaming quality has been requested.\n */\n readonly streamingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * Dispatched when the currently buffering quality changes.\n * This is dispatched before the segment is appended.\n */\n readonly bufferingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * The currently playing quality has changed.\n */\n readonly playbackQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * The last segment has finished appending.\n */\n readonly bufferingEnded: AnyRecord\n\n /**\n * Dispatched when a streaming error occurs.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Emitted when the error state has been reset.\n */\n readonly reset: AnyRecord\n\n /**\n * The available qualities for the current period have changed.\n */\n readonly qualitiesChange: ChangeEvent<readonly MediaQualityMetadata[]>\n\n /**\n * The available unfiltered qualities for the current period have changed.\n */\n readonly qualitiesUnfilteredChange: ChangeEvent<\n readonly MediaQualityMetadata[]\n >\n}\n\n/**\n * All streaming-related events a track may emit.\n * These will be bubbled by the player.\n */\nexport const ALL_STREAMING_EVENTS = [\n 'contentTypesChange',\n 'fetchedRangesChange',\n 'streamingQualityChange',\n 'bufferingQualityChange',\n 'playbackQualityChange',\n 'bufferingEnded',\n 'error',\n 'reset',\n 'qualitiesChange',\n 'qualitiesUnfilteredChange',\n] as const satisfies readonly (keyof StreamingEventMap)[]\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyPlaybackController } from '@/playback/ReadonlyPlaybackController'\nimport {\n SegmentControllerImpl,\n type SegmentControllerImplOptions,\n} from '@/streaming/SegmentControllerImpl'\nimport type { ContentType } from '@/streaming/MediaQualityMetadata'\nimport type { SegmentController } from '@/streaming/SegmentController'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from '@/streaming/MediaTimeline'\nimport type { QualitySelector } from '@/streaming/abr/QualitySelector'\n\nexport type SegmentControllerFactory = (deps: {\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n readonly qualitySelector: QualitySelector\n}) => SegmentController\n\nexport interface SegmentControllerFactoryDeps {\n readonly playbackController: ReadonlyPlaybackController\n}\n\nexport function createSegmentControllerFactory(\n playerDeps: SegmentControllerFactoryDeps,\n contentType: ContentType,\n options?: Partial<SegmentControllerImplOptions>\n) {\n return (trackDeps: {\n readonly mediaTimelineTransformed: ObservableValue<\n Promise<MediaTimeline>\n >\n readonly qualitySelector: QualitySelector\n }) => {\n return new SegmentControllerImpl(\n {\n ...playerDeps,\n ...trackDeps,\n },\n contentType,\n options\n )\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n consoleLogHandler,\n historyLogHandler,\n LogLevel,\n type PartialDeep,\n setLogLevel,\n} from '@amazon/vinyl-util'\nimport type { ValueSchema } from '@amazon/vinyl-validation'\nimport {\n isOneOf,\n number,\n object,\n type ObjectSchema,\n} from '@amazon/vinyl-validation'\nimport { PlayerRegistryImpl, playerRegistryRef } from './PlayerRegistry'\n\n/**\n * Configuration for VinylGlobal.\n */\nexport interface VinylGlobalOptions {\n /**\n * The number of concurrent players before a warning is logged.\n * default: 5\n */\n readonly maxPlayersWarning: number\n\n /**\n * Logging configuration\n */\n readonly logging: {\n readonly history: {\n /**\n * Limits the history log level.\n */\n readonly logLevel: LogLevel\n\n /**\n * Sets the logging history size.\n */\n readonly maxHistorySize: number\n }\n\n /**\n * Gates all log handlers to logs of at least this level.\n */\n readonly logLevel: LogLevel\n\n readonly console: {\n /**\n * Gates console logs\n */\n readonly logLevel: LogLevel\n }\n }\n}\n\nconst logLevelValidator: ValueSchema<LogLevel> = /* @__PURE__ */ (() =>\n isOneOf(\n LogLevel.VERBOSE,\n LogLevel.DEBUG,\n LogLevel.INFO,\n LogLevel.WARN,\n LogLevel.ERROR,\n LogLevel.NONE\n ))()\n\n/**\n * A validator for VinylGlobalOptions applications can set for Vinyl.\n */\nconst vinylGlobalOptionsValidator: ObjectSchema<VinylGlobalOptions> = /* @__PURE__ */ object({\n logging: /* @__PURE__ */ object({\n console: /* @__PURE__ */ object({\n logLevel: logLevelValidator,\n }),\n history: /* @__PURE__ */ object({\n logLevel: logLevelValidator,\n maxHistorySize: /* @__PURE__ */ number(),\n }),\n logLevel: logLevelValidator,\n }),\n maxPlayersWarning: /* @__PURE__ */ number(),\n})\n\nconst vinylGlobalOptionsPartialValidator: ObjectSchema<\n PartialDeep<VinylGlobalOptions>\n> = /* @__PURE__ */ vinylGlobalOptionsValidator.partialDeep()\n\n/**\n * Applies configuration to the current vinyl global options.\n *\n * @param options\n */\nexport function configureVinylGlobal(options: PartialDeep<VinylGlobalOptions>) {\n vinylGlobalOptionsPartialValidator.assert(options)\n // Logging configuration\n if (options.logging) {\n const logging = options.logging\n if (logging.logLevel != null) setLogLevel(logging.logLevel)\n if (logging.history) {\n const history = logging.history\n if (historyLogHandler.value) {\n if (history.maxHistorySize != null)\n historyLogHandler.value.maxHistorySize =\n history.maxHistorySize\n if (history.logLevel != null)\n historyLogHandler.value.logLevel = history.logLevel\n }\n }\n if (logging.console?.logLevel != null) {\n if (consoleLogHandler.value) {\n consoleLogHandler.value.logLevel = logging.console.logLevel\n }\n }\n }\n\n if (\n options.maxPlayersWarning != null &&\n playerRegistryRef.value instanceof PlayerRegistryImpl\n ) {\n playerRegistryRef.value.maxPlayersWarning = options.maxPlayersWarning\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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nD;AAAA,IACJ;AACA,UAAI,aAAQ,YAAR,mBAAiB,aAAY,MAAM;AACnC,UAAI,sCAAkB,OAAO;AACzB,8CAAkB,MAAM,WAAW,QAAQ,QAAQ;AAAA,MACvD;AAAA,IACJ;AAAA,EACJ;AAEA,MACI,QAAQ,qBAAqB,QAC7B,kBAAkB,iBAAiB,oBACrC;AACE,sBAAkB,MAAM,oBAAoB,QAAQ;AAAA,EACxD;AACJ;",
|
|
6
|
-
"names": ["data", "CanPlayTypeResult", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "PlayedReason", "WaitedReason", "PlaybackReadyState", "PlaybackNetworkState", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_validation", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_validation", "DrmKeySystem", "import_vinyl_validation", "DrmRobustness", "import_vinyl_util", "contentType", "import_vinyl_util", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_validation", "import_vinyl_util", "record", "src", "contentType", "import_vinyl_util", "import_vinyl_validation", "loadOptionsValidator", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_util", "import_vinyl_util", "time", "period", "contentType", "loadOptionsValidator", "import_vinyl_util", "import_vinyl_validation", "loadOptionsValidator", "import_vinyl_util", "element", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "time", "period", "_a", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "_a", "import_vinyl_util", "contentType", "contentType", "fullMimeType", "import_vinyl_util", "contentType", "_a", "_b", "import_vinyl_util", "
|
|
3
|
+
"sources": ["../src/index.ts", "../src/vinyl/playerConfigFactory.ts", "../src/client/Capabilities.ts", "../src/util/media/mediaSource.ts", "../src/util/media/getAudioContext.ts", "../src/client/CapabilitiesImpl.ts", "../src/vinyl/createVinylFactories.ts", "../src/patch/media/patchMediaElement.ts", "../src/patch/media/patches/createUnreliablePlaybackEventsPatch.ts", "../src/patch/media/patches/createPreventStallsPatch.ts", "../src/playback/PlaybackControllerImpl.ts", "../src/playback/PlaybackController.ts", "../src/playback/ReadonlyPlaybackController.ts", "../src/playback/error/InvalidSeekError.ts", "../src/playback/logging/playbackStateLoggingHandler.ts", "../src/event/ChangeEvent.ts", "../src/playback/nextHasMetadata.ts", "../src/playback/error/ReportableMediaError.ts", "../src/playback/logging/mediaErrorToJson.ts", "../src/playback/PlaybackSourceImpl.ts", "../src/track/TrackFactory.ts", "../src/track/source/SourceObjectTrack.ts", "../src/track/TrackBase.ts", "../src/drm/DrmOptions.ts", "../src/drm/DrmKeySystem.ts", "../src/drm/licenseProvider/LicenseProvider.ts", "../src/track/source/FixedPlaybackQuality.ts", "../src/track/source/SourceTrackBase.ts", "../src/streaming/MediaQualityMetadata.ts", "../src/streaming/DescriptorRecord.ts", "../src/track/source/SourceTrack.ts", "../src/track/dash/DashTrack.ts", "../src/track/mse/MseTrack.ts", "../src/streaming/MediaTimeline.ts", "../src/track/hls/HlsTrack.ts", "../src/track/createVinylTrackFactories.ts", "../src/track/TrackController.ts", "../src/patch/media/MediaElementPatchOptions.ts", "../src/vinyl/VinylPatchOptions.ts", "../src/track/dash/util/mpd.ts", "../src/track/dash/util/uriResolution.ts", "../src/track/dash/createDefaultDashManifestTransformer.ts", "../src/track/dash/manifestTransformUtils.ts", "../src/track/dash/DashMediaQualityMetadataResolver.ts", "../src/track/mse/codec.ts", "../src/track/dash/util/mimeType.ts", "../src/drm/CencEncryptionScheme.ts", "../src/streaming/buffering/MediaSourceController.ts", "../src/util/media/sourceBuffer.ts", "../src/streaming/buffering/error/SourceBufferError.ts", "../src/track/dash/DashManifestController.ts", "../src/streaming/buffering/SourceBufferController.ts", "../src/streaming/buffering/BufferingController.ts", "../src/streaming/SegmentController.ts", "../src/streaming/SegmentControllerImpl.ts", "../src/streaming/SegmentDataSlot.ts", "../src/streaming/SegmentPrefetch.ts", "../src/streaming/util/segment.ts", "../src/track/dash/createDashContentStreamFactories.ts", "../src/streaming/abr/QualitySelectorImpl.ts", "../src/track/dash/createDashFactories.ts", "../src/track/dash/urlDashManifestProvider.ts", "../src/track/dash/createDashManifestProvider.ts", "../src/streaming/ContentStream.ts", "../src/track/dash/createDashContentTypesValue.ts", "../src/track/dash/timeline/DashRepresentationSegmentProvider.ts", "../src/track/createSegmentDataProvider.ts", "../src/track/dash/buildDashMediaTimeline.ts", "../src/streaming/createDefaultMediaTimelineTransformer.ts", "../src/streaming/mediaTimelineFilter.ts", "../src/streaming/mediaTimelineLanguageFilter.ts", "../src/track/filters/languageFilter.ts", "../src/track/filters/resourceTypeFilter.ts", "../src/track/filters/keySystemFilter.ts", "../src/track/filters/sampleRateFilter.ts", "../src/track/hls/HlsMediaQualityMetadataResolver.ts", "../src/track/hls/HlsManifestController.ts", "../src/track/hls/createHlsFactories.ts", "../src/track/hls/createUrlHlsManifestProvider.ts", "../src/track/hls/createHlsContentTypesValue.ts", "../src/track/hls/createHlsContentStreamFactories.ts", "../src/track/hls/createDefaultHlsManifestTransformer.ts", "../src/track/hls/util/hlsByteRangeToMediaRange.ts", "../src/track/hls/util/hlsSegmentTime.ts", "../src/track/hls/buildHlsMediaTimeline.ts", "../src/drm/commonEme/MsCommonEme.ts", "../src/drm/commonEme/CommonEme.ts", "../src/drm/error/DrmError.ts", "../src/drm/commonEme/StandardCommonEme.ts", "../src/drm/commonEme/createDrmErrorHandler.ts", "../src/drm/commonEme/WebKitCommonEme.ts", "../src/drm/commonEme/CommonEmeFactory.ts", "../src/drm/DrmControllerImpl.ts", "../src/drm/util/unpackPlayReadyChallenge.ts", "../src/drm/licenseProvider/defaultLicenseProvider.ts", "../src/drm/util/extractContentId.ts", "../src/drm/util/createFairPlaySessionInitData.ts", "../src/drm/DrmKeySystemResolver.ts", "../src/playback/loudness/LoudnessNormalizationControllerImpl.ts", "../src/playback/loudness/LoudnessNormalizationControllerImplOptions.ts", "../src/track/AutoResetController.ts", "../src/vinyl/VinylOptions.ts", "../src/vinyl/VinylPlayer.ts", "../src/global/PlayerRegistry.ts", "../src/global/initializeVinylGlobal.ts", "../src/global/globalRef.ts", "../src/global/environment.ts", "../src/streaming/StreamingEventMap.ts", "../src/track/dash/createSegmentControllerFactory.ts", "../src/global/configureVinylGlobal.ts"],
|
|
4
|
+
"sourcesContent": ["/** Auto-generated from build scripts */\nexport * from './vinyl/playerConfigFactory'\nexport * from './vinyl/createVinylFactories'\nexport * from './vinyl/VinylPlayer'\nexport * from './vinyl/VinylPatchOptions'\nexport * from './vinyl/VinylOptions'\nexport * from './vinyl/VinylDeps'\nexport * from './vinyl/ReadonlyPlaybackStreamingState'\nexport * from './util/media/sourceBuffer'\nexport * from './util/media/mediaSource'\nexport * from './util/media/getAudioContext'\nexport * from './track/createVinylTrackFactories'\nexport * from './track/createSegmentDataProvider'\nexport * from './track/TrackFactory'\nexport * from './track/TrackController'\nexport * from './track/TrackBase'\nexport * from './track/Track'\nexport * from './track/AutoResetController'\nexport * from './track/source/SourceTrackBase'\nexport * from './track/source/SourceTrack'\nexport * from './track/source/SourceObjectTrack'\nexport * from './track/source/FixedPlaybackQuality'\nexport * from './track/mse/codec'\nexport * from './track/mse/MseTrack'\nexport * from './track/hls/createUrlHlsManifestProvider'\nexport * from './track/hls/createHlsFactories'\nexport * from './track/hls/createHlsContentTypesValue'\nexport * from './track/hls/createHlsContentStreamFactories'\nexport * from './track/hls/createDefaultHlsManifestTransformer'\nexport * from './track/hls/buildHlsMediaTimeline'\nexport * from './track/hls/HlsTrack'\nexport * from './track/hls/HlsMediaQualityMetadataResolver'\nexport * from './track/hls/HlsManifestProvider'\nexport * from './track/hls/HlsManifestController'\nexport * from './track/hls/util/hlsSegmentTime'\nexport * from './track/hls/util/hlsByteRangeToMediaRange'\nexport * from './track/filters/sampleRateFilter'\nexport * from './track/filters/resourceTypeFilter'\nexport * from './track/filters/languageFilter'\nexport * from './track/filters/keySystemFilter'\nexport * from './track/dash/urlDashManifestProvider'\nexport * from './track/dash/manifestTransformUtils'\nexport * from './track/dash/createSegmentControllerFactory'\nexport * from './track/dash/createDefaultDashManifestTransformer'\nexport * from './track/dash/createDashManifestProvider'\nexport * from './track/dash/createDashFactories'\nexport * from './track/dash/createDashContentTypesValue'\nexport * from './track/dash/createDashContentStreamFactories'\nexport * from './track/dash/buildDashMediaTimeline'\nexport * from './track/dash/DashTrack'\nexport * from './track/dash/DashMediaQualityMetadataResolver'\nexport * from './track/dash/DashManifestProvider'\nexport * from './track/dash/DashManifestController'\nexport * from './track/dash/util/uriResolution'\nexport * from './track/dash/util/mpd'\nexport * from './track/dash/util/mimeType'\nexport * from './track/dash/timeline/DashRepresentationSegmentProvider'\nexport * from './streaming/mediaTimelineLanguageFilter'\nexport * from './streaming/mediaTimelineFilter'\nexport * from './streaming/createDefaultMediaTimelineTransformer'\nexport * from './streaming/StreamingEventMap'\nexport * from './streaming/SegmentReference'\nexport * from './streaming/SegmentPrefetch'\nexport * from './streaming/SegmentDataSlot'\nexport * from './streaming/SegmentControllerImpl'\nexport * from './streaming/SegmentController'\nexport * from './streaming/MediaTimeline'\nexport * from './streaming/MediaQualityMetadata'\nexport * from './streaming/ManifestController'\nexport * from './streaming/DrmInitDataType'\nexport * from './streaming/DescriptorRecord'\nexport * from './streaming/ContentTypesValue'\nexport * from './streaming/ContentStreamingOptions'\nexport * from './streaming/ContentStream'\nexport * from './streaming/util/segment'\nexport * from './streaming/buffering/SourceBufferController'\nexport * from './streaming/buffering/MediaSourceController'\nexport * from './streaming/buffering/BufferingController'\nexport * from './streaming/buffering/error/SourceBufferError'\nexport * from './streaming/abr/QualitySelectorImpl'\nexport * from './streaming/abr/QualitySelector'\nexport * from './playback/nextHasMetadata'\nexport * from './playback/ReadonlyPlaybackController'\nexport * from './playback/PlaybackSourceImpl'\nexport * from './playback/PlaybackSource'\nexport * from './playback/PlaybackControllerImpl'\nexport * from './playback/PlaybackController'\nexport * from './playback/loudness/LoudnessNormalizationControllerImplOptions'\nexport * from './playback/loudness/LoudnessNormalizationControllerImpl'\nexport * from './playback/loudness/LoudnessNormalizationController'\nexport * from './playback/logging/playbackStateLoggingHandler'\nexport * from './playback/logging/mediaErrorToJson'\nexport * from './playback/error/ReportableMediaError'\nexport * from './playback/error/InvalidSeekError'\nexport * from './patch/media/patchMediaElement'\nexport * from './patch/media/MediaElementPatchOptions'\nexport * from './patch/media/HtmlMediaElementPatch'\nexport * from './patch/media/patches/createUnreliablePlaybackEventsPatch'\nexport * from './patch/media/patches/createPreventStallsPatch'\nexport * from './global/initializeVinylGlobal'\nexport * from './global/globalRef'\nexport * from './global/environment'\nexport * from './global/configureVinylGlobal'\nexport * from './global/PlayerRegistry'\nexport * from './event/ChangeEvent'\nexport * from './event/BasicErrorEvent'\nexport * from './drm/DrmOptions'\nexport * from './drm/DrmKeySystemResolver'\nexport * from './drm/DrmKeySystem'\nexport * from './drm/DrmControllerImpl'\nexport * from './drm/DrmController'\nexport * from './drm/CencEncryptionScheme'\nexport * from './drm/util/unpackPlayReadyChallenge'\nexport * from './drm/util/extractContentId'\nexport * from './drm/util/createFairPlaySessionInitData'\nexport * from './drm/licenseProvider/defaultLicenseProvider'\nexport * from './drm/licenseProvider/LicenseProvider'\nexport * from './drm/error/DrmError'\nexport * from './drm/dom/WebKitMediaKeys'\nexport * from './drm/dom/MSMediaKeys'\nexport * from './drm/dom/HTMLMediaElement'\nexport * from './drm/commonEme/createDrmErrorHandler'\nexport * from './drm/commonEme/WebKitCommonEme'\nexport * from './drm/commonEme/StandardCommonEme'\nexport * from './drm/commonEme/MsCommonEme'\nexport * from './drm/commonEme/EncryptedInitData'\nexport * from './drm/commonEme/CommonEmeFactory'\nexport * from './drm/commonEme/CommonEme'\nexport * from './client/Client'\nexport * from './client/CapabilitiesImpl'\nexport * from './client/Capabilities'\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { data, type MutableValue } from '@amazon/vinyl-observable'\nimport type { AddDisposable, AnyRecord } from '@amazon/vinyl-util'\nimport type { Validator } from '@amazon/vinyl-validation'\n\nexport function playerConfigFactory<T>(\n defaults: T,\n validator: Validator<T>\n): (_deps: AnyRecord, add: AddDisposable) => MutableValue<T> {\n return (_deps, add) => {\n const config = data<T>(defaults)\n add(\n config.onData((data) => {\n // Throws if data does not pass validation\n validator.assert(data)\n })\n )\n return config\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DrmKeySystem } from '../drm/DrmKeySystem'\nimport type { DrmKeySystemSupport } from '../drm/DrmController'\n\nexport enum CanPlayTypeResult {\n /**\n * The media cannot be played on the current device.\n */\n NO = 'no',\n\n /**\n * There is not enough information to determine whether the media can play.\n */\n MAYBE = 'maybe',\n\n /**\n * The media is probably playable on this device.\n */\n PROBABLY = 'probably',\n}\n\n/**\n * Detected capabilities of the device.\n */\nexport interface Capabilities {\n /**\n * Returns true if Media Source Extensions are supported.\n *\n * Note that this does not test DRM or any DRM key systems.\n */\n readonly mse: boolean\n\n /**\n * Returns true if Encrypted Media Extensions are supported.\n */\n readonly eme: boolean\n\n /**\n * Returns true if native Dynamic Adaptive Streaming is supported.\n *\n * (Legacy Edge 12-18 and XBox One)\n * Note that this is not the same as supporting a dash track.\n */\n readonly dash: boolean\n\n /**\n * Returns true if native HTTP Live Streaming is supported.\n *\n * iOS 7.0+, Safari 8.0+\n * Note that this does not do FairPlay detection.\n */\n readonly hls: boolean\n\n /**\n * Returns the sample rate, in samples per second, that this platform supports.\n * Returns null if the sample rate cannot be determined.\n */\n readonly sampleRate: number | null\n\n /**\n * Returns a string that specifies whether the client can play a given media resource type for progressive\n * content.\n *\n * @param type A string specifying the MIME type of the media and (optionally) a codecs\n * parameter containing a comma-separated list of the supported codecs.\n */\n canPlayType(type: string): CanPlayTypeResult\n\n /**\n * Returns a boolean that specifies whether the client can play a given media resource type for streaming\n * content with media source extensions.\n *\n * @param type A string specifying the MIME type of the media and (optionally) a codecs\n * parameter containing a comma-separated list of the supported codecs.\n */\n canPlayTypeMse(type: string): boolean\n\n /**\n * Returns a promise describing support for the given key system.\n *\n * @param keySystem\n */\n supportsKeySystem(keySystem: DrmKeySystem): Promise<DrmKeySystemSupport>\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { MediaUnsupportedError } from '@amazon/vinyl-util'\nimport type { Unsubscribe } from '@amazon/vinyl-util'\nimport type { SignalOptions } from '@amazon/vinyl-util'\nimport { withTimeout } from '@amazon/vinyl-util'\n\ndeclare global {\n var ManagedMediaSource: typeof MediaSource | undefined\n}\n\n/**\n * Returns true if the UA supports media source extensions.\n */\nexport function supportsMse(): boolean {\n return (\n typeof ManagedMediaSource === 'function' ||\n typeof MediaSource === 'function'\n )\n}\n\n/**\n * Returns ManagedMediaSource or MediaSource.\n */\nfunction getMediaSourceCtor(): typeof MediaSource {\n if (typeof ManagedMediaSource === 'function') return ManagedMediaSource\n else return MediaSource\n}\n\n/**\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaSource/isTypeSupported_static)\n */\nexport function isTypeSupported(type: string): boolean {\n assertMseSupported()\n return getMediaSourceCtor().isTypeSupported(type)\n}\n\n/**\n * Constructs a new ManagedMediaSource or MediaSource.\n */\nexport function createMediaSource(): MediaSource {\n assertMseSupported()\n return new (getMediaSourceCtor())()\n}\n\n/**\n * Throws a MediaUnsupportedError if MSE is not supported.\n */\nexport function assertMseSupported(): void {\n if (!supportsMse())\n throw new MediaUnsupportedError(\n 'Media Source Extensions not supported',\n 'mse-unsupported'\n )\n}\n\n/**\n * Invokes a callback when the media source is open.\n * The callback will be invoked immediately if already open.\n */\nexport function onMediaSourceOpen(\n mediaSource: MediaSource,\n callback: () => void,\n options?: SignalOptions\n): Unsubscribe {\n const open = mediaSource.readyState === 'open'\n if (open) callback()\n const handler = () => callback()\n if (!options?.once || !open) {\n // compatibility note: MediaSource.addEventListener is more widely supported than onsourceopen\n // https://caniuse.com/mdn-api_mediasource_sourceopen_event\n mediaSource.addEventListener('sourceopen', handler, options)\n return () => mediaSource.removeEventListener('sourceopen', handler)\n } else {\n return () => {}\n }\n}\n\n/**\n * Invokes a callback when the media source is next ended.\n * The callback will be invoked immediately if already ended.\n */\nexport function onMediaSourceEnded(\n mediaSource: MediaSource,\n callback: () => void,\n options?: SignalOptions\n): Unsubscribe {\n const ended = mediaSource.readyState === 'ended'\n if (ended) callback()\n const handler = () => callback()\n if (!options?.once || !ended) {\n mediaSource.addEventListener('sourceended', handler, options)\n return () => mediaSource.removeEventListener('sourceended', handler)\n } else {\n return () => {}\n }\n}\n\n/**\n * Returns a Promise that resolves when the media source is next in an 'ended' state.\n *\n * @param mediaSource\n * @param timeout The number of seconds before rejecting with a TimeoutError.\n * @param timeoutMessage\n */\nexport function nextMediaSourceEnded(\n mediaSource: MediaSource,\n timeout: number = 5,\n timeoutMessage?: string\n): Promise<void> {\n return withTimeout(\n new Promise((resolve) => {\n onMediaSourceEnded(mediaSource, resolve, { once: true })\n }),\n timeout,\n timeoutMessage\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { globalRef, lazy } from '@amazon/vinyl-util'\n\ntype MaybeAudioContext = typeof AudioContext | undefined\n\ndeclare global {\n var webkitAudioContext: MaybeAudioContext\n}\n\n/**\n * Creates a new AudioContext.\n * Returns null if not supported on this platform.\n */\nexport function createAudioContext(): AudioContext | null {\n const ctor =\n (global.AudioContext as MaybeAudioContext) ?? global.webkitAudioContext\n return ctor ? new ctor() : null\n}\n\n/**\n * Some devices have a hard limit to how many audio context objects can be created.\n * Uses a lazy instance to ensure only one context is created, even within integ tests.\n */\nconst audioContextSingleton = /* @__PURE__ */ lazy(createAudioContext)\n\n/**\n * The audio context global reference.\n */\nexport const audioContextRef = /* @__PURE__ */ globalRef<AudioContext | null>(\n () => audioContextSingleton.value\n)\n\n/**\n * Returns an AudioContext singleton, or returns null if not supported on this platform.\n *\n * If the first time this is called is outside a user gesture, the AudioContext will be unable to start in a\n * running state.\n */\nexport function getAudioContext(): AudioContext | null {\n return audioContextRef.value\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type DrmKeySystem } from '../drm/DrmKeySystem'\nimport type { Capabilities } from './Capabilities'\nimport { CanPlayTypeResult } from './Capabilities'\nimport { isTypeSupported, supportsMse } from '../util/media/mediaSource'\nimport { getAudioContext } from '../util/media/getAudioContext'\nimport type { DrmController, DrmKeySystemSupport } from '../drm/DrmController'\n\n/**\n * Dependencies for CapabilitiesImpl.\n */\nexport interface CapabilitiesImplDeps {\n readonly media: HTMLMediaElement\n readonly drmController: DrmController\n}\n\n/**\n * Client support detection.\n */\nexport class CapabilitiesImpl implements Capabilities {\n constructor(private readonly deps: CapabilitiesImplDeps) {}\n\n get mse(): boolean {\n return supportsMse()\n }\n\n get dash(): boolean {\n return this.canPlayType('application/dash+xml') !== CanPlayTypeResult.NO\n }\n\n get hls(): boolean {\n return (\n this.canPlayType('application/vnd.apple.mpegurl') !==\n CanPlayTypeResult.NO\n )\n }\n\n get eme(): boolean {\n return this.deps.drmController.isEmeSupported()\n }\n\n get sampleRate(): number | null {\n return getAudioContext()?.sampleRate ?? null\n }\n\n canPlayType(type: string): CanPlayTypeResult {\n const media: HTMLMediaElement = this.deps.media\n if (typeof media.canPlayType === 'undefined')\n return CanPlayTypeResult.NO\n const str = media.canPlayType(type)\n switch (str) {\n case '':\n return CanPlayTypeResult.NO\n case 'maybe':\n return CanPlayTypeResult.MAYBE\n case 'probably':\n return CanPlayTypeResult.PROBABLY\n }\n }\n\n canPlayTypeMse(type: string): boolean {\n return isTypeSupported(type)\n }\n\n async supportsKeySystem(\n keySystem: DrmKeySystem\n ): Promise<DrmKeySystemSupport> {\n // Take the most commonly supported codec and media format, check the DrmController if\n // it is supported with the given key system.\n return this.deps.drmController.isSupported({\n initDataType: 'cenc',\n encryptionScheme: 'cenc',\n contentType: 'audio',\n mimeType: 'audio/mp4; codecs=\"mp4a.40.2\"',\n contentProtections: [{ keySystem }],\n })\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { CapabilitiesImplDeps } from '../client/CapabilitiesImpl'\nimport { CapabilitiesImpl } from '../client/CapabilitiesImpl'\nimport type { Merge, PartialDeep, PatchedRef } from '@amazon/vinyl-util'\nimport { mergeDeep, noop } from '@amazon/vinyl-util'\nimport { patchMediaElement } from '../patch/media/patchMediaElement'\nimport type {\n PlaybackControllerImplDeps,\n PlaybackControllerImplOptions,\n} from '../playback/PlaybackControllerImpl'\nimport { PlaybackControllerImpl } from '../playback/PlaybackControllerImpl'\nimport type { PlaybackSourceImplDeps } from '../playback/PlaybackSourceImpl'\nimport { PlaybackSourceImpl } from '../playback/PlaybackSourceImpl'\nimport {\n createVinylTrackFactories,\n type VinylTrackFactoryDeps,\n} from '../track/createVinylTrackFactories'\nimport type {\n TrackControllerImplDeps,\n TrackControllerImplOptions,\n} from '../track/TrackController'\nimport { TrackControllerImpl } from '../track/TrackController'\nimport { createTrackFactory } from '../track/TrackFactory'\nimport type { VinylDeps } from './VinylDeps'\nimport type { VinylPatchOptions } from './VinylPatchOptions'\nimport { defaultPatchOptions } from './VinylPatchOptions'\nimport { type QualitySelectorImplOptions } from '../streaming/abr/QualitySelectorImpl'\nimport { createDashFactories } from '../track/dash/createDashFactories'\nimport { createHlsFactories } from '../track/hls/createHlsFactories'\nimport { type DrmOptions } from '../drm/DrmOptions'\nimport { commonEmeFactory } from '../drm/commonEme/CommonEmeFactory'\nimport {\n DrmControllerImpl,\n type DrmControllerImplDeps,\n} from '../drm/DrmControllerImpl'\nimport { defaultDrmKeySystemResolver } from '../drm/DrmKeySystemResolver'\nimport { LoudnessNormalizationControllerImpl } from '../playback/loudness/LoudnessNormalizationControllerImpl'\nimport {\n AutoResetControllerImpl,\n type AutoResetControllerImplDeps,\n type AutoResetControllerImplOptions,\n} from '../track/AutoResetController'\nimport type { Dependencies, Factories } from '@amazon/vinyl-di'\nimport { validateFactories } from '@amazon/vinyl-di'\nimport type { ContentStreamingOptions } from '../streaming/ContentStreamingOptions'\nimport {\n defaultVinylOptions,\n type VinylOptions,\n vinylOptionsValidator,\n} from './VinylOptions'\nimport { playerConfigFactory } from './playerConfigFactory'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\n\n/**\n * Configuration used by the default dependency factories for Vinyl.\n *\n * These options are used during player construction, changes after construction will have no\n * effect.\n */\nexport interface VinylDependencyOptions {\n /**\n * The media element.\n */\n readonly media: HTMLMediaElement\n\n /**\n * Flags for patches that should be applied browser-specifically.\n * These will be defaulted based on the user-agent.\n */\n readonly patches?: PartialDeep<VinylPatchOptions>\n\n /**\n * Configuration for the track controller.\n */\n readonly trackController?: Partial<TrackControllerImplOptions>\n\n /**\n * Configuration for the playback controller.\n */\n readonly playbackController?: Partial<PlaybackControllerImplOptions>\n\n /**\n * Configuration for segmented streaming tracks (hls / dash).\n */\n readonly streaming?: PartialDeep<ContentStreamingOptions>\n\n /**\n * Configuration for all drm-related components.\n */\n readonly drm?: Partial<DrmOptions>\n\n /**\n * Configuration for adaptive bitrate switching.\n */\n readonly abr?: PartialDeep<QualitySelectorImplOptions>\n\n /**\n * Configuration for auto-reset behavior.\n */\n readonly autoReset?: Partial<AutoResetControllerImplOptions>\n}\n\n/**\n * Creates the dependency factories for a standard player.\n *\n * @param options\n */\nexport function createVinylFactories(options: VinylDependencyOptions) {\n const patches = mergeDeep([\n defaultPatchOptions.value,\n options.patches ?? {},\n ])\n return validateFactories({\n options: playerConfigFactory<VinylOptions>(\n defaultVinylOptions,\n vinylOptionsValidator\n ),\n patchedMedia: (): PatchedRef<HTMLMediaElement> => {\n // Patches the media element if necessary.\n return patchMediaElement(options.media, patches.media)\n },\n media: (deps: {\n readonly patchedMedia: {\n readonly patched: HTMLMediaElement\n }\n }): HTMLMediaElement => deps.patchedMedia.patched,\n playbackController: (deps: PlaybackControllerImplDeps) =>\n new PlaybackControllerImpl(deps, options.playbackController),\n playbackSource: (deps: PlaybackSourceImplDeps) =>\n new PlaybackSourceImpl(deps),\n loudnessNormalizationController: (deps: {\n options: ObservableValue<\n Pick<VinylOptions, 'loudnessNormalization'>\n >\n }) =>\n new LoudnessNormalizationControllerImpl({\n options: deps.options.pick('loudnessNormalization'),\n }),\n capabilities: (deps: CapabilitiesImplDeps) =>\n new CapabilitiesImpl(deps),\n requestInterceptor: () => noop,\n trackFactory: (deps: VinylTrackFactoryDeps) =>\n createTrackFactory(createVinylTrackFactories(deps)),\n trackController: (deps: TrackControllerImplDeps<any>) =>\n new TrackControllerImpl<any>(deps, options.trackController),\n drmKeySystemResolver: () => defaultDrmKeySystemResolver,\n drmController: (deps: DrmControllerImplDeps) =>\n new DrmControllerImpl(deps, options.drm),\n commonEme: commonEmeFactory,\n autoResetController: (deps: AutoResetControllerImplDeps) =>\n new AutoResetControllerImpl(deps, options.autoReset),\n createDashFactories: createDashFactories(options),\n createHlsFactories: createHlsFactories(options),\n } as const) satisfies Factories<VinylDeps>\n}\n\n/**\n * The dependency map type of the default player dependency factories.\n */\nexport type DefaultVinylFactories = ReturnType<typeof createVinylFactories>\n\n/**\n * Provides the dependency type for a dependency with merged overrides.\n */\nexport type InferVinylOverrideDependencyType<\n Overrides,\n K extends keyof DefaultVinylFactories,\n> = Dependencies<\n Overrides extends Factories\n ? Merge<DefaultVinylFactories, Overrides>\n : DefaultVinylFactories\n>[K]\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type PatchedRef, patchTargetFromFlags } from '@amazon/vinyl-util'\nimport type { MediaElementPatchOptions } from './MediaElementPatchOptions'\nimport { createUnreliablePlaybackEventsPatch } from './patches/createUnreliablePlaybackEventsPatch'\nimport { createPreventStallsPatch } from './patches/createPreventStallsPatch'\n\n/**\n * Applies patches corresponding to the patch flags on the given media element.\n *\n * Adds logging for fabricated or squelched events.\n */\nexport function patchMediaElement<\n T extends HTMLMediaElement = HTMLMediaElement,\n>(media: T, options: MediaElementPatchOptions): PatchedRef<T> {\n return patchTargetFromFlags(\n media,\n options,\n ['unreliablePlaybackEvents', createUnreliablePlaybackEventsPatch],\n ['preventStalls', createPreventStallsPatch]\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Browser, hasBrowser, type Timestamp } from '@amazon/vinyl-util'\nimport {\n closeTo,\n createDisposer,\n DomEventHost,\n onAny,\n SignalImpl,\n} from '@amazon/vinyl-util'\nimport type { HtmlMediaElementPatch } from '../HtmlMediaElementPatch'\n\n/**\n * The interval (in seconds) to poll for time progress in a media element.\n *\n * @private\n */\nexport const UNRELIABLE_EVENTS_POLL_INTERVAL = 0.2\n\n/**\n * Minimum amount of time playback must be stalled before fabricating a waiting event.\n */\nexport const MIN_STALLED_BEFORE_FAB = 0.8\n\n/**\n * Minimum amount of time playback must be progressing before fabricating a playing event.\n */\nexport const MIN_PLAYING_BEFORE_FAB = 0.4\n\n/**\n * If currentTime does not change larger than this value, it will be considered to be stalled.\n */\nconst MIN_PLAYING_DELTA = 0.05\n\n/**\n * If currentTime changes beyond this tolerance the apparent state will be considered to be seeking.\n */\nconst MIN_SEEKING_DELTA = 0.5\n\nenum PlayHeadState {\n /**\n * The last time update was an increment from the previous.\n */\n PLAYING,\n\n /**\n * The last time update was close to the previous.\n */\n STOPPED,\n\n /**\n * The last time update was a non-incremental change.\n */\n SEEKING,\n}\n\n/**\n * Playback events such as playing, canPlay, and waiting are unreliable on this platform.\n * Watch playback state and fabricate events when necessary.\n */\nexport function createUnreliablePlaybackEventsPatch(\n media: HTMLMediaElement\n): HtmlMediaElementPatch {\n const { add, dispose } = createDisposer()\n const domEvents = add(new DomEventHost<HTMLMediaElementEventMap>(media))\n const eventFabricated = add(new SignalImpl<Event>())\n\n // The timestamp of the last change.\n let stateChangedAt: Timestamp = Date.now()\n\n // The current observed state based on the play head progress.\n let currentApparentState: PlayHeadState = PlayHeadState.STOPPED\n\n /**\n * @param state The new apparent state.\n * @param changedAt The timestamp the apparent state was changed.\n */\n function setApparentState(\n state: PlayHeadState,\n changedAt: Timestamp = Date.now()\n ) {\n if (currentApparentState !== state) {\n currentApparentState = state\n stateChangedAt = changedAt\n }\n }\n\n /**\n * Returns the number of seconds since the last state change.\n */\n function elapsedStateTime(): number {\n return (Date.now() - stateChangedAt) / 1000\n }\n\n let lastTimestamp: Timestamp = Date.now()\n let lastTime = media.currentTime\n\n let waiting = false\n let seeking = false\n\n onAny(\n domEvents,\n ['emptied', 'ended', 'pause', 'playing', 'seeking'],\n () => {\n waiting = false\n }\n )\n\n let playing = false\n onAny(\n domEvents,\n ['emptied', 'ended', 'pause', 'seeking', 'waiting'],\n () => {\n playing = false\n }\n )\n\n domEvents.on('seeking', () => {\n seeking = true\n })\n domEvents.on('seeked', () => {\n seeking = false\n setApparentState(PlayHeadState.SEEKING)\n })\n domEvents.on('play', () => {\n // Resets the timer so that the !paused state does not immediately trigger a 'waiting' event.\n stateChangedAt = Date.now()\n })\n\n // All events that can affect the ready state.\n // canplay and canplaythrough are handled in the overridden events map.\n const readyStateEvents = [\n 'emptied',\n 'loadeddata',\n 'loadedmetadata',\n 'waiting',\n ] as const\n let lastReadyStateEvent = 'emptied'\n add(\n onAny(domEvents, readyStateEvents, (_, type) => {\n lastReadyStateEvent = type\n })\n )\n\n const checkApparentState = () => {\n const progressed = (media.currentTime - lastTime) / media.playbackRate\n const now = Date.now()\n if (Math.abs(progressed) > MIN_SEEKING_DELTA) {\n setApparentState(PlayHeadState.SEEKING, lastTimestamp)\n } else if (progressed >= MIN_PLAYING_DELTA) {\n setApparentState(PlayHeadState.PLAYING, lastTimestamp)\n } else if (closeTo(progressed, 0, MIN_PLAYING_DELTA)) {\n setApparentState(PlayHeadState.STOPPED, lastTimestamp)\n }\n lastTime = media.currentTime\n lastTimestamp = now\n\n if (\n !playing &&\n !seeking &&\n !media.paused &&\n !media.ended &&\n media.readyState >= media.HAVE_FUTURE_DATA &&\n currentApparentState === PlayHeadState.PLAYING &&\n elapsedStateTime() >= MIN_PLAYING_BEFORE_FAB\n ) {\n // The play head is progressing but a playing event was never observed.\n waiting = false\n playing = true\n\n if (\n lastReadyStateEvent !== 'canplay' &&\n lastReadyStateEvent !== 'canplaythrough'\n ) {\n lastReadyStateEvent = 'canplay'\n eventFabricated.dispatch(new CustomEvent('canplay'))\n }\n if (media.readyState >= media.HAVE_ENOUGH_DATA) {\n if (lastReadyStateEvent !== 'canplaythrough') {\n lastReadyStateEvent = 'canplaythrough'\n eventFabricated.dispatch(new CustomEvent('canplaythrough'))\n }\n }\n eventFabricated.dispatch(new CustomEvent('playing'))\n }\n if (\n !waiting &&\n !media.paused &&\n !media.ended &&\n currentApparentState === PlayHeadState.STOPPED &&\n elapsedStateTime() >= MIN_STALLED_BEFORE_FAB\n ) {\n waiting = true\n playing = false\n // currentTime is not changing; playback has stopped but no 'waiting' event\n // was observed.\n eventFabricated.dispatch(new CustomEvent('waiting'))\n }\n }\n\n const playbackWatchIntervalId = setInterval(\n checkApparentState,\n UNRELIABLE_EVENTS_POLL_INTERVAL * 1000\n )\n add(() => {\n clearInterval(playbackWatchIntervalId)\n })\n return {\n eventFabricated,\n properties: {\n /**\n * Platforms that have unreliable waiting events, also have unreliable ready state\n * when the end of buffered data has been reached. If the media is in a waiting state,\n * the highest ready state that is possible is HAVE_METADATA.\n */\n readyState: {\n get() {\n return waiting\n ? Math.min(media.readyState, media.HAVE_METADATA)\n : media.readyState\n },\n },\n },\n events: {\n canplay(event) {\n // Do not emit the canplay event if one was fabricated.\n const eventOrNull =\n lastReadyStateEvent === 'canplay' ? null : event\n lastReadyStateEvent = 'canplay'\n return eventOrNull\n },\n\n canplaythrough(event) {\n // Do not emit the canplaythrough event if one was fabricated.\n const eventOrNull =\n lastReadyStateEvent === 'canplaythrough' ? null : event\n lastReadyStateEvent = 'canplaythrough'\n return eventOrNull\n },\n\n playing(event) {\n if (playing) {\n // Do not emit the playing event if one was fabricated.\n return null\n }\n setApparentState(PlayHeadState.PLAYING)\n playing = true\n return event\n },\n\n waiting(event) {\n if (waiting) {\n // Do not emit the waiting event if one was fabricated.\n return null\n }\n waiting = true\n setApparentState(PlayHeadState.STOPPED)\n return event\n },\n },\n\n dispose,\n }\n}\n\n/**\n * Chrome <= 53 has unreliable waiting events.\n * Safari, and Edge Legacy miss playing events after seeking.\n */\nexport function requiresUnreliablePlaybackEventsPatch(): boolean {\n return (\n hasBrowser(Browser.SAFARI) ||\n hasBrowser(Browser.EDGE_LEGACY) ||\n hasBrowser(Browser.CHROMIUM, null, '53')\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n Browser,\n closeTo,\n createDisposer,\n createLogPrefix,\n DomEventHost,\n hasBrowser,\n logInfo,\n type LogTarget,\n logWarn,\n noop,\n} from '@amazon/vinyl-util'\nimport type { HtmlMediaElementPatch } from '../HtmlMediaElementPatch'\n\n/**\n * The number of timeupdate events stuck at the same position before attempting to jiggle the playhead.\n * @private\n */\nexport const MAX_UNCHANGED_COUNT = 10\n\n/**\n * On affected UAs, playback can become stuck. timeupdate events are observed but playback position is never changing.\n * This patch applies a workaround which will pause and play again after max number of timeupdate events with no\n * actual time progression.\n */\nexport function createPreventStallsPatch(\n media: HTMLMediaElement\n): HtmlMediaElementPatch {\n const { add, dispose } = createDisposer()\n const domEvents = add(new DomEventHost<HTMLMediaElementEventMap>(media))\n const pathTarget: LogTarget = {\n logPrefix: createLogPrefix('createPreventStallsPatch'),\n }\n let unchangedCount = 0\n let attemptedFix = false\n let previousTime = media.currentTime\n domEvents.on('timeupdate', () => {\n if (media.paused) return\n if (closeTo(media.currentTime, previousTime, 0.01)) {\n if (++unchangedCount >= MAX_UNCHANGED_COUNT && !attemptedFix) {\n logWarn(\n pathTarget,\n `Detected stall at time ${media.currentTime}, attempting fix`\n )\n attemptedFix = true\n unchangedCount = 0\n media.pause()\n media.play().catch(noop)\n }\n } else {\n if (attemptedFix) {\n logInfo(pathTarget, 'stall ended')\n attemptedFix = false\n } // Unstuck\n unchangedCount = 0\n previousTime = media.currentTime\n }\n })\n\n return {\n dispose,\n }\n}\n\n/**\n * Returns true if stall detection should be enabled for the current user agent.\n */\nexport function requiresPreventStallsPatch(): boolean {\n return hasBrowser(Browser.EDGE_LEGACY)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n Abort,\n AbortError,\n Browser,\n clamp,\n closeTo,\n createDisposer,\n createTimeRangesReader,\n DomEventHost,\n ErrorLevel,\n ErrorOrigin,\n EventHostImpl,\n getUserAgentInfo,\n hasBrowser,\n logDebug,\n logInfo,\n logWarn,\n nextEventAsPromise,\n onAny,\n ownKeys,\n type ReadonlyEventHost,\n type ReadonlyRanges,\n TimeoutSlot,\n toLowerCase,\n withAbort,\n withTimeout,\n} from '@amazon/vinyl-util'\nimport { LIVE_DURATION, type PlaybackController } from './PlaybackController'\nimport {\n type PlaybackControllerEventMap,\n PlaybackReadyState,\n playedReasons,\n waitedReasons,\n} from './ReadonlyPlaybackController'\nimport { InvalidSeekError } from './error/InvalidSeekError'\nimport { playbackStateLoggingHandler } from './logging/playbackStateLoggingHandler'\nimport { createChangeEventTrigger } from '../event/ChangeEvent'\nimport { nextHasMetadata } from './nextHasMetadata'\nimport type { LoudnessNormalizationController } from './loudness/LoudnessNormalizationController'\nimport { ReportableMediaError } from './error/ReportableMediaError'\n\nexport interface PlaybackControllerImplOptions {\n /**\n * An affordance when comparing the last currentTime and the new currentTime after a seek.\n * Most browsers have around 30-40 time updates per second, but some constrained devices only\n * have a few. This value needs to be large enough where the last timeupdate in a looping track\n * is at currentTime >= duration - LOOP_TIME_AFFORDANCE.\n * Default: 2\n */\n readonly loopTimeAffordance: number\n\n /**\n * The minimum number of seconds before the end of the next seekable range allowed for a seek\n * operation. Some browsers will never complete a seek operation if the seek is too close to\n * this end range.\n * Default: getMinSeekableBufferDefault() which is between 0.5 and 5, browser dependent.\n */\n readonly minSeekableBuffer: number\n\n /**\n * The number of seconds before the promise returned by play() is rejected regardless whether\n * the media element response has settled.\n * Default: 30\n */\n readonly playTimeout: number\n\n /**\n * The number of seconds before the promise returned by seek() is rejected.\n * Default: 30\n */\n readonly seekTimeout: number\n}\n\nexport const defaultPlaybackControllerImplOptions = {\n loopTimeAffordance: 2,\n minSeekableBuffer: -1, // Default comes from getMinSeekableBufferDefault()\n playTimeout: 30,\n seekTimeout: 30,\n} as const satisfies PlaybackControllerImplOptions\n\n/**\n * Safari and Edge Legacy cannot reliably seek close to the end of a seekable range.\n * Firefox can but if the playhead reaches the end of track before the media stream is closed, an 'ended' event\n * will never fire.\n */\nexport function getMinSeekableBufferDefault() {\n return !hasBrowser(Browser.CHROMIUM) ? 5 : 2\n}\n\nexport interface PlaybackControllerImplDeps {\n readonly media: HTMLMediaElement\n readonly loudnessNormalizationController: LoudnessNormalizationController\n}\n\nexport class PlaybackControllerImpl\n extends EventHostImpl<PlaybackControllerEventMap>\n implements PlaybackController\n{\n private readonly loudnessNormalizationController: LoudnessNormalizationController\n get [Symbol.toStringTag](): string {\n return 'PlaybackControllerImpl'\n }\n\n private _error: Error | null = null\n private readonly media: HTMLMediaElement\n private readonly domEvents: DomEventHost<HTMLMediaElementEventMap>\n private readonly disposer = /* @__PURE__ */ createDisposer()\n private _playing = false\n private _seeking = false\n private _waiting = false\n\n // default user volume (0.0 to 1.0 scale)\n private userVolume: number = 1.0\n private _pendingPlay: Promise<void> | null = null\n private playAbort: Abort | null = null\n private disposeAbort = /* @__PURE__ */ new Abort()\n\n readonly options: PlaybackControllerImplOptions\n\n constructor(\n deps: PlaybackControllerImplDeps,\n options?: Partial<PlaybackControllerImplOptions>\n ) {\n super()\n this.options = {\n ...defaultPlaybackControllerImplOptions,\n minSeekableBuffer: getMinSeekableBufferDefault(),\n ...options,\n }\n this.loudnessNormalizationController =\n deps.loudnessNormalizationController\n logInfo(this, 'constructed', this.options)\n this.media = deps.media\n\n const { add } = this.disposer\n add(() => {\n this.disposeAbort.abort()\n this.disposeAbort.dispose()\n })\n\n this.domEvents = add(\n new DomEventHost<HTMLMediaElementEventMap>(deps.media)\n )\n\n // Log media events.\n add(playbackStateLoggingHandler(this))\n\n // Reports media errors\n this.domEvents.on('error', (_) => {\n const error = new ReportableMediaError(this.media.error)\n if (error.level === ErrorLevel.SILENT) {\n // Not a fatal error, log and ignore\n logInfo(this, error.message)\n return\n }\n this._error = error\n this.dispatch('error', {\n target: this,\n error,\n })\n })\n\n this.initializeEvents()\n\n // Listen for loudness normalization changes\n add(\n this.loudnessNormalizationController.on('change', () => {\n this.refreshVolume()\n })\n )\n }\n\n /**\n * Updates volume with loudness gain, on the mediaElement.\n * @private\n */\n private refreshVolume(): void {\n const effectiveVolume =\n this.userVolume * this.loudnessNormalizationController.gain\n this.media.volume = Math.min(1.0, effectiveVolume) // valid range (0-1)\n logDebug(this, 'refreshVolume', {\n userVolume: this.userVolume,\n lnGain: this.loudnessNormalizationController.gain,\n effectiveVolume: this.media.volume,\n })\n }\n\n /**\n * Listens to select events on the media element, redispatching as playback state events.\n * @private\n */\n private initializeEvents() {\n this.initializePlainEvents()\n this.initializeChangeEvents()\n this.initializeOperationEvents()\n this.initializeMutedEvent()\n this.initializeLoopedEvent()\n this.initializeReadyStateChangeEvent()\n }\n\n /**\n * Re-dispatches the plain DOM events without extra information.\n *\n * @private\n */\n private initializePlainEvents() {\n // Re-dispatch html media element events exposed on the playback controller as empty events.\n for (const key of [\n 'abort',\n 'canPlay',\n 'canPlayThrough',\n 'emptied',\n 'ended',\n 'loadStart',\n 'loadedData',\n 'loadedMetadata',\n 'pause',\n 'play',\n 'playing',\n 'seeking',\n 'waiting',\n 'waitingForKey',\n ] as const) {\n this.domEvents.on(toLowerCase(key), () => this.dispatch(key, {}))\n }\n\n // Keep specific event information for progress events.\n\n this.domEvents.on('progress', (e) => {\n this.dispatch('progress', { loaded: e.loaded, total: e.total })\n })\n }\n\n /**\n * Delegates the DOM events with additional information about what the previous and current\n * values are.\n * @private\n */\n private initializeChangeEvents() {\n const changeEventGetters = {\n durationChange: () => this.duration,\n timeUpdate: () => this.currentTime,\n volumeChange: () => this.volume,\n rateChange: () => this.playbackRate,\n } as const\n for (const key of ownKeys(changeEventGetters)) {\n this.domEvents.on(\n toLowerCase(key),\n createChangeEventTrigger(changeEventGetters[key], (event) => {\n this.dispatch(key, event)\n })\n )\n }\n }\n\n /**\n * Operation events provide an easy way to listen for the terminus of a state.\n * For example after a 'waiting' event, there are several different events that indicate that\n * the waiting has finished, and this API provides those events conflated into a single\n * 'waited' event.\n * @private\n */\n private initializeOperationEvents() {\n // seeking state + seeked event\n // media element has a seeked event, add operation details and set state.\n this.operationEvent(\n this.domEvents,\n 'seeking',\n // A seeked event may not be emitted in certain cases such as changing tracks before the seek can finish.\n ['seeked', 'emptied'],\n () => (this._seeking = true),\n (info) => {\n this._seeking = false\n this.dispatch('seeked', info)\n }\n )\n\n // waiting state + waited event\n this.operationEvent(\n this,\n 'waiting',\n waitedReasons,\n () => (this._waiting = true),\n (info) => {\n this._waiting = false\n this.dispatch('waited', info)\n }\n )\n\n // playing state + played event\n let startedTime = 0\n this.operationEvent(\n this,\n 'playing',\n playedReasons,\n () => {\n this._playing = true\n startedTime = this.currentTime\n },\n (info) => {\n this._playing = false\n this.dispatch('played', {\n ...info,\n playbackTime: this.currentTime - startedTime,\n })\n }\n )\n }\n\n /**\n * When going into a state from a beginEvent, dispatches endEvent when any of the endEvents\n * is dispatched.\n *\n * This allows consumers of the playback state to listen for the exit of a state without\n * needing to know every event that ends that state.\n *\n * @param host The event host emitting the primary events.\n * @param beginEvent The event that enters a state.\n * @param endEvents A list of events that exits the entered state.\n * @param onBegin Invoked when the operation has begun.\n * @param onEnd Invoked when the operation has completed.\n */\n private operationEvent<EventMap, const EndEvent extends keyof EventMap>(\n host: ReadonlyEventHost<EventMap>,\n beginEvent: keyof EventMap,\n endEvents: readonly EndEvent[],\n onBegin: () => void,\n onEnd: (info: {\n started: number\n ended: number\n duration: number\n reason: EndEvent\n }) => void\n ) {\n let startedAt = 0\n let started = false\n host.on(beginEvent, () => {\n onBegin()\n started = true\n startedAt = Date.now()\n })\n onAny(host, endEvents, (_, event) => {\n if (started) {\n started = false\n const now = Date.now()\n onEnd({\n started: startedAt,\n ended: now,\n duration: (now - startedAt) / 1000,\n reason: event,\n })\n }\n })\n }\n\n /**\n * Dispatches a 'mutedChange' event when 'muted' state has changed.\n *\n * The DOM element only provides a 'volumeChange' event, which is filtered to watch when\n * muted has changed.\n *\n * @private\n */\n private initializeMutedEvent() {\n const { add } = this.disposer\n let previousMuted = this.muted\n\n // Dispatches a mutedChange event if the muted property changed since the last check.\n const maybeDispatchMutedChange = () => {\n if (this.muted === previousMuted) return\n previousMuted = this.muted\n this.dispatch('mutedChange', {\n previous: !this.muted,\n current: this.muted,\n })\n }\n const mutedTimeoutSlot = add(new TimeoutSlot())\n this.on('volumeChange', () => {\n maybeDispatchMutedChange()\n // The volumechange event may be emitted before the muted property change.\n // This has been observed on legacy edge and as a rare occurrence for Chrome.\n mutedTimeoutSlot.set(maybeDispatchMutedChange, 0.2)\n })\n }\n\n /**\n * Dispatches a looped event if loop is true and playback wraps back to the start.\n * Safari emits timeupdate events at duration and then 0 before the seeking event\n * Other browsers emit the seeking before the timeupdate near zero.\n * Firefox timeupdate after the loop is near zero, not exactly.\n *\n * @private\n */\n private initializeLoopedEvent() {\n let lastTime = 0\n this.on('timeUpdate', () => {\n if (\n this.loop &&\n !this.paused &&\n this.currentTime <= this.options.loopTimeAffordance &&\n lastTime >= this.duration - this.options.loopTimeAffordance\n ) {\n if (getUserAgentInfo().browserLike?.name === Browser.FIREFOX) {\n // Firefox does not emit a 'playing' event after a loop, fabricate one.\n logDebug(this, 'fabricating Firefox playing event on loop')\n this.dispatch('playing', {})\n }\n this.dispatch('looped', {})\n }\n lastTime = this.currentTime\n })\n }\n\n get buffered(): ReadonlyRanges {\n return createTimeRangesReader(this.media.buffered)\n }\n\n get currentTime(): number {\n return this.media.currentTime\n }\n\n get currentTimePercent(): number {\n return this.duration > 0 ? this.currentTime / this.duration : 0\n }\n\n get defaultPlaybackRate(): number {\n return this.media.defaultPlaybackRate\n }\n\n set defaultPlaybackRate(value: number) {\n logDebug(this, `defaultPlaybackRate set to ${value}`)\n this.media.defaultPlaybackRate = value\n }\n\n get duration(): number {\n if (this.media.duration >= LIVE_DURATION)\n return Number.POSITIVE_INFINITY\n return this.media.duration\n }\n\n get ended(): boolean {\n return this.media.ended\n }\n\n get error(): Error | null {\n return this._error\n }\n\n get loop(): boolean {\n return this.media.loop\n }\n\n set loop(value: boolean) {\n logDebug(this, `loop set to ${value}`)\n this.media.loop = value\n }\n\n get muted(): boolean {\n return this.media.muted\n }\n\n set muted(value: boolean) {\n logDebug(this, `muted set to ${value}`)\n this.media.muted = value\n }\n\n get networkState(): number {\n return this.media.networkState\n }\n\n get paused(): boolean {\n return this.media.paused\n }\n\n get playbackRate(): number {\n return this.media.playbackRate\n }\n\n set playbackRate(value: number) {\n logDebug(this, `playbackRate set to ${value}`)\n this.media.playbackRate = value\n }\n\n get playing(): boolean {\n return this._playing\n }\n\n get preservesPitch(): boolean {\n return this.media.preservesPitch\n }\n\n set preservesPitch(value: boolean) {\n logDebug(this, `preservesPitch set to ${value}`)\n this.media.preservesPitch = value\n }\n\n get readyState(): PlaybackReadyState {\n return this.media.readyState\n }\n\n get seekable(): ReadonlyRanges {\n return createTimeRangesReader(this.media.seekable)\n }\n\n get seeking(): boolean {\n return this._seeking\n }\n\n get volume(): number {\n return this.userVolume\n }\n\n set volume(value: number) {\n logDebug(this, `volume set to ${value}`)\n this.userVolume = value\n this.refreshVolume()\n }\n\n get waiting(): boolean {\n return this._waiting\n }\n\n pause(): void {\n logDebug(this, 'pause')\n this.playAbort?.abort(\n new AbortError(\n 'The play() request was interrupted by a call to pause().'\n )\n )\n this.pendingPlay = null\n this.media.pause()\n }\n\n private get pendingPlay(): Promise<void> | null {\n return this._pendingPlay\n }\n\n private set pendingPlay(value: Promise<void> | null) {\n this._pendingPlay = value\n this.dispatch('playIsPendingChange', {\n previous: value == null,\n current: value != null,\n })\n }\n\n play(): Promise<void> {\n logDebug(this, 'play')\n if (!this.pendingPlay) {\n const playAbort = new Abort()\n this.playAbort = playAbort\n this.pendingPlay = withAbort(\n (async () => {\n await nextHasMetadata(this)\n playAbort.throwIfAborted()\n await withTimeout(\n this.media.play(),\n this.options.playTimeout,\n 'play() timed out after {time}s',\n ErrorOrigin.INTERNAL,\n ErrorLevel.SILENT\n )\n })(),\n playAbort\n )\n .catch((reason) => {\n this.dispatch('playRejected', { reason })\n throw reason\n })\n .finally(() => {\n this.pendingPlay = null\n this.playAbort = null\n })\n }\n return this.pendingPlay\n }\n\n get canPlay(): boolean {\n return this.readyState >= PlaybackReadyState.HAVE_FUTURE_DATA\n }\n\n get canPlayThrough(): boolean {\n return this.readyState >= PlaybackReadyState.HAVE_ENOUGH_DATA\n }\n\n get hasMetadata(): boolean {\n return this.readyState >= PlaybackReadyState.HAVE_METADATA\n }\n\n get playIsPending(): boolean {\n return this.pendingPlay != null\n }\n\n async seekTo(time: number, tolerance = 0.5): Promise<void> {\n logDebug(this, `seekTo: ${time}`)\n const nextEvent = <K extends keyof PlaybackControllerEventMap>(\n type: K\n ): Promise<PlaybackControllerEventMap[K]> => {\n return withAbort(\n withTimeout(\n nextEventAsPromise(this, type),\n this.options.seekTimeout,\n `seek timed out on ${type} event after {time}s`,\n ErrorOrigin.INTERNAL,\n ErrorLevel.WARN\n ),\n this.disposeAbort\n )\n }\n\n // Cannot seek until there are seekable ranges.\n if (!this.hasMetadata) {\n await nextEvent('loadedMetadata')\n }\n\n const seekable = this.seekable\n const range = seekable.getRangeAt(\n clamp(time, 0, this.duration),\n tolerance\n )\n if (range == null) {\n logWarn(\n this,\n `seekTo: seek outside of seekable ranges, seek ignored`\n )\n throw new InvalidSeekError(time, seekable, tolerance)\n }\n const clampedTime = Math.max(\n Math.min(time, range[1] - this.options.minSeekableBuffer),\n range[0]\n )\n\n // No-op check\n\n logDebug(\n this,\n `seekTo operation, requested: ${time}, actual: ${clampedTime}`\n )\n\n if (closeTo(clampedTime, this.currentTime, tolerance)) {\n // Within tolerance of the currentTime, no seek needed.\n logDebug(\n this,\n `seekTo: requested: ${time}, actual: ${clampedTime} no-op`\n )\n } else {\n const seeking = nextEvent('seeking')\n this.media.currentTime = clampedTime\n await seeking\n const seekedEvent = await nextEvent('seeked')\n if (seekedEvent.reason === 'emptied') {\n // Seek finished due to track unloading. Abort any pending seek.\n throw new AbortError()\n }\n }\n }\n\n /**\n * Dispatches a readyStateChange event when {@link readyState} changes.\n * @private\n */\n private initializeReadyStateChangeEvent() {\n let previous = this.readyState\n onAny(\n this,\n [\n 'canPlay',\n 'canPlayThrough',\n 'emptied',\n 'loadedData',\n 'loadedMetadata',\n 'waiting',\n ],\n () => {\n const current = this.readyState\n if (previous !== current) {\n this.dispatch('readyStateChange', {\n previous,\n current,\n })\n previous = this.readyState\n }\n }\n )\n }\n\n reset() {\n if (this._error == null) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.dispatch('reset', {})\n }\n\n /**\n * True if this controller has been disposed.\n */\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.disposer.dispose()\n }\n}\n\n/**\n * Returns true if the play rejection reason is a not allowed error. This indicates that play\n * should be retried within a user interaction stack.\n * @param reason\n */\nexport function isNotAllowedError(\n reason: any\n): reason is { name: 'NotAllowedError' } {\n return reason?.name === 'NotAllowedError'\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyPlaybackController } from './ReadonlyPlaybackController'\n\nexport interface PlaybackController extends ReadonlyPlaybackController {\n defaultPlaybackRate: number\n loop: boolean\n muted: boolean\n playbackRate: number\n preservesPitch: boolean\n volume: number\n\n /**\n * Pauses playback of the media, if the media is already in a paused state\n * this method will have no effect.\n * If a play is pending, the play will be aborted and the promise returned by play() will be\n * rejected.\n *\n * @see pendingPlay\n * @see play\n */\n pause(): void\n\n /**\n * Attempts to begin playback of the media. It returns a Promise which is resolved when\n * playback has been successfully started.\n *\n * Failure to begin playback for any reason, such as permission issues or interruption via\n * pause, results in the promise being rejected.\n *\n * The first time play() is invoked, except muted video, should be in response to a user\n * interaction such as a button click.\n *\n * @see isNotAllowedError\n */\n play(): Promise<void>\n\n /**\n * Safely seeks to the given time.\n * The seek will begin only after {@link readyState} is at least\n * {@link PlaybackReadyState.HAVE_METADATA}.\n * If a previous seek was still pending, the previous seek will be ignored.\n * Returns a Promise that resolves when the seek has completed. If the seek is interrupted\n * by another seek, the promise will be rejected with an `AbortError`.\n * If the seek is not to a seekable range, the promise will reject with an {@link InvalidSeekError}.\n *\n * @param time The value, in seconds, to set the playback time.\n * @param tolerance The amount of tolerance to have when the time is outside the seekable\n * ranges to snap, in seconds. If time is outside all seekable ranges beyond this tolerance,\n * the seek will be ignored. Default: 0.5\n */\n seekTo(time: number, tolerance?: number): Promise<void>\n\n /**\n * Resets the error state.\n */\n reset(): void\n}\n\n/**\n * The maximum duration media can be before it is considered 'live'.\n */\nexport const LIVE_DURATION = 4294967296 // 2 ** 32\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AnyRecord,\n ReadonlyEventHost,\n ReadonlyRanges,\n Timestamp,\n} from '@amazon/vinyl-util'\nimport type { ChangeEvent } from '../event/ChangeEvent'\nimport type { BasicErrorEvent } from '../event/BasicErrorEvent'\n\nexport interface ProgressEvent {\n readonly loaded: number\n readonly total: number\n}\n\nexport interface OperationCompletedEvent<K> {\n /**\n * The timestamp the operation began.\n */\n readonly started: Timestamp\n\n /**\n * The timestamp the operation completed.\n */\n readonly ended: Timestamp\n\n /**\n * The total number of seconds the operation took.\n */\n readonly duration: number\n\n /**\n * The reason the operation completed.\n */\n readonly reason: K\n}\n\nexport interface PlayedEvent extends OperationCompletedEvent<PlayedReason> {\n /**\n * The total number of seconds elapsed for the track (using `currentTime`).\n */\n readonly playbackTime: number\n}\n\n/**\n * The reason playback has stopped.\n * These are source event types from the media element that all indicate playback has stopped.\n * @see PlaybackControllerEventMap\n */\nexport enum PlayedReason {\n EMPTIED = 'emptied',\n /**\n * Note - 'ended' reason is generally unused, however it is not part of the w3c spec to guarantee a 'pause' event\n * before 'ended'.\n */\n ENDED = 'ended',\n PAUSE = 'pause',\n SEEKING = 'seeking',\n WAITING = 'waiting',\n}\n\n/**\n * A list of all events that cause the 2nd-order 'played' event.\n */\nexport const playedReasons = [\n PlayedReason.EMPTIED,\n PlayedReason.ENDED,\n PlayedReason.PAUSE,\n PlayedReason.SEEKING,\n PlayedReason.WAITING,\n] as const satisfies readonly PlayedReason[]\n\nexport interface PlayRejectedEvent {\n /**\n * The reason for the play() rejection.\n *\n * @see #isNotAllowedError\n */\n reason: any\n}\n\nexport interface PlaybackControllerEventMap {\n /**\n * Fired when the resource was not fully loaded, but not as the result of an error.\n */\n readonly abort: AnyRecord\n\n /**\n * Fired when the user agent can play the media, but estimates that not enough data has been\n * loaded to play the media up to its end without having to stop for further buffering of\n * content.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_FUTURE_DATA}\n */\n readonly canPlay: AnyRecord\n\n /**\n * Fired when the user agent can play the media, and estimates that enough data has been\n * loaded to play the media up to its end without having to stop for further buffering of content.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_ENOUGH_DATA}\n */\n readonly canPlayThrough: AnyRecord\n\n /**\n * Fired when the duration attribute has been updated.\n */\n readonly durationChange: ChangeEvent<number>\n\n /**\n * Fired when the media has become empty; for example, this event is sent if the media has\n * already been loaded (or partially loaded), and the load() method is called to reload it.\n *\n * readyState will be {@link PlaybackReadyState.HAVE_NOTHING}\n */\n readonly emptied: AnyRecord\n\n /**\n * Fired when playback or streaming has stopped because the end of the media was reached or\n * because no further data is available.\n */\n readonly ended: AnyRecord\n\n /**\n * Dispatched when the media element dispatches an error.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Fired when {@link ReadonlyPlaybackController.playIsPending} has changed.\n */\n readonly playIsPendingChange: ChangeEvent<boolean>\n\n /**\n * Fired when the frame at the current playback position of the media has finished loading;\n * often the first frame.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_CURRENT_DATA}\n */\n readonly loadedData: AnyRecord\n\n /**\n * Fired when the metadata has been loaded.\n *\n * readyState will be at least {@link PlaybackReadyState.HAVE_METADATA}\n */\n readonly loadedMetadata: AnyRecord\n\n /**\n * Fired when the browser has started to load a resource.\n */\n readonly loadStart: AnyRecord\n\n /**\n * Fired when {@link ReadonlyPlaybackController.loop} is true and playback has looped to track beginning.\n */\n readonly looped: AnyRecord\n\n /**\n * Fired when the mute status has changed.\n */\n readonly mutedChange: ChangeEvent<boolean>\n\n /**\n * Fired when a request to pause an activity is handled and the activity has entered its paused\n * state, most commonly after the media has been paused through a call to the element's\n * pause() method.\n */\n readonly pause: AnyRecord\n\n /**\n * Fired when the paused property is changed from true to false, as a result of the play\n * method, or the autoplay attribute.\n */\n readonly play: AnyRecord\n\n /**\n * Fired if play() has been attempted, but rejected.\n */\n readonly playRejected: PlayRejectedEvent\n\n /**\n * Fired when playback has stopped, for any reason.\n *\n * When media begins playing, a `playing` event is emitted. If playback stops due to 'pause',\n * 'seeking', 'emptied', 'waiting', or 'ended', then `played` will be fired.\n */\n readonly played: PlayedEvent\n\n /**\n * Fired after playback is first started, and whenever it is restarted. For example, it is\n * fired when playback resumes after having been paused or delayed due to lack of data.\n */\n readonly playing: AnyRecord\n\n /**\n * Fired periodically as the browser loads a resource.\n */\n readonly progress: ProgressEvent\n\n /**\n * Fired when the playback rate has changed.\n */\n readonly rateChange: ChangeEvent<number>\n\n /**\n * Fired when {@link ReadonlyPlaybackController.readyState} has changed.\n *\n * This is fired when any of the following events have fired:\n * {@link loadedData},\n * {@link loadedMetadata}\n * {@link canPlay}\n * {@link canPlayThrough}\n * {@link emptied}\n * {@link waiting}\n */\n readonly readyStateChange: ChangeEvent<PlaybackReadyState>\n\n /**\n * Fired when a seek operation completed, the current playback position has changed, and the\n * Boolean seeking attribute is changed to false.\n */\n readonly seeked: OperationCompletedEvent<'seeked' | 'playing' | 'emptied'>\n\n /**\n * Fired when a seek operation starts, meaning the Boolean seeking attribute has changed to\n * true and the media is seeking a new position.\n */\n readonly seeking: AnyRecord\n\n /**\n * Fired when the time indicated by the currentTime attribute has been updated.\n */\n readonly timeUpdate: ChangeEvent<number>\n\n /**\n * Fired when the volume has changed.\n */\n readonly volumeChange: ChangeEvent<number>\n\n /**\n * Fired when playback has stopped because of a temporary lack of data.\n *\n * Note: this includes during initial loading or after a seek and data is needed to buffer.\n * Will not be emitted when paused.\n */\n readonly waiting: AnyRecord\n\n /**\n * Fired when waiting has completed.\n * This will be emitted after a waiting event when playback has resumed, paused, or unloaded.\n */\n readonly waited: OperationCompletedEvent<WaitedReason>\n\n /**\n * Playback is blocked waiting for a key.\n */\n readonly waitingForKey: AnyRecord\n\n /**\n * Emitted when the error state has been reset.\n */\n readonly reset: AnyRecord\n}\n\n/**\n * Reasons why a 'waiting' operation has ended.\n */\nexport enum WaitedReason {\n PLAYING = 'playing',\n PAUSE = 'pause',\n EMPTIED = 'emptied',\n SEEKING = 'seeking',\n}\n\n/**\n * A list of all events that cause the 2nd-order 'waited' event.\n */\nexport const waitedReasons = [\n WaitedReason.PLAYING,\n WaitedReason.PAUSE,\n WaitedReason.EMPTIED,\n WaitedReason.SEEKING,\n] as const satisfies readonly WaitedReason[]\n\nexport const ALL_PLAYBACK_STATE_EVENTS = [\n 'abort',\n 'canPlay',\n 'canPlayThrough',\n 'durationChange',\n 'emptied',\n 'ended',\n 'error',\n 'playIsPendingChange',\n 'loadedData',\n 'loadedMetadata',\n 'loadStart',\n 'looped',\n 'mutedChange',\n 'pause',\n 'play',\n 'playRejected',\n 'played',\n 'playing',\n 'progress',\n 'rateChange',\n 'readyStateChange',\n 'reset',\n 'seeked',\n 'seeking',\n 'timeUpdate',\n 'volumeChange',\n 'waited',\n 'waiting',\n 'waitingForKey',\n] as const satisfies readonly (keyof PlaybackControllerEventMap)[]\n\nexport enum PlaybackReadyState {\n /**\n * No information is available about the media resource.\n *\n * readyState will be this after `emptied`\n */\n HAVE_NOTHING = 0,\n\n /**\n * Enough of the media resource has been retrieved that the metadata attributes are initialized\n * Seeking will no longer raise an exception.\n *\n * readyState will be at least this after `loadedMetadata`\n */\n HAVE_METADATA = 1,\n\n /**\n * Data is available for the current playback position, but not enough to actually play more\n * than one frame.\n *\n * readyState will be at least this after `loadedData`\n */\n HAVE_CURRENT_DATA = 2,\n\n /**\n * Data for the current playback position as well as for at least a little bit of time into the\n * future is available (in other words, at least two frames of video, for example).\n *\n * readyState will be at least this after `canPlay`\n */\n HAVE_FUTURE_DATA = 3,\n\n /**\n * Enough data is available\u2014and the download rate is high enough\u2014that the media can be played\n * through to the end without interruption.\n *\n * readyState will be at least this after `canPlayThrough`\n */\n HAVE_ENOUGH_DATA = 4,\n}\n\n/**\n * An enumeration of possible networkState values on a media element.\n */\nexport enum PlaybackNetworkState {\n /**\n * There is no data yet. Also, readyState is HAVE_NOTHING.\n */\n NETWORK_EMPTY = 0,\n\n /**\n * HTMLMediaElement is active and has selected a resource, but is not using the network.\n */\n NETWORK_IDLE = 1,\n\n /**\n * The browser is downloading HTMLMediaElement data.\n */\n NETWORK_LOADING = 2,\n\n /**\n * No HTMLMediaElement src found.\n */\n NETWORK_NO_SOURCE = 3,\n}\n\nexport interface ReadonlyPlaybackController extends ReadonlyEventHost<PlaybackControllerEventMap> {\n /**\n * Returns a new static normalized ReadonlyRanges object that represents the ranges of the\n * media resource, if any, that the user agent has buffered at the moment the buffered\n * property is accessed.\n *\n * Note: `ReadonlyRanges` is a view to the DOM `TimeRanges` object.\n */\n readonly buffered: ReadonlyRanges\n\n /**\n * True if the {@link readyState} is {@link PlaybackReadyState.HAVE_FUTURE_DATA}\n * This will be true after a {@link PlaybackControllerEventMap.canPlay} event.\n *\n * Note that security permissions may not allow a track to load past metadata before there has\n * been a user interaction. This should not be relied upon before invoking\n * {@link PlaybackController.play}.\n */\n readonly canPlay: boolean\n\n /**\n * True if the {@link readyState} is {@link PlaybackReadyState.HAVE_ENOUGH_DATA}\n * This will be true after a {@link PlaybackControllerEventMap.canPlayThrough} event.\n *\n * Note that security permissions may not allow a track to load past metadata before there has\n * been a user interaction. This should not be relied upon before invoking\n * {@link PlaybackController.play}.\n */\n readonly canPlayThrough: boolean\n\n /**\n * The current playback time in seconds.\n * When changed, a 'timeUpdate' event is emitted.\n */\n readonly currentTime: number\n\n /**\n * Returns current time as a percent of the total duration.\n *\n * @return A number between 0-1\n */\n readonly currentTimePercent: number\n\n /**\n * The default playback rate when the user is not using fast forward or reverse for a\n * video or audio resource.\n */\n readonly defaultPlaybackRate: number\n\n /**\n * The length of the element's media in seconds.\n * Observe changes with `durationChange` events.\n */\n readonly duration: number\n\n /**\n * Indicates whether the media element has ended playback.\n */\n readonly ended: boolean\n\n /**\n * The Error object for the most recent error, or null if there has not been an error.\n * When an error event is received by the element, you can determine details about what\n * happened by examining this object.\n */\n readonly error: Error | null\n\n /**\n * True if the {@link readyState} is at least {@link PlaybackReadyState.HAVE_METADATA}\n *\n * This will be true after a {@link PlaybackControllerEventMap.loadedMetadata} event and\n * false after an {@link PlaybackControllerEventMap.emptied} event.\n */\n readonly hasMetadata: boolean\n\n /**\n * Controls whether the media element should start over when it reaches the end.\n */\n readonly loop: boolean\n\n /**\n * Indicates whether the media element muted.\n * Observe changes with `mutedChange` events.\n */\n readonly muted: boolean\n\n /**\n * Indicates the current state of the fetching of media over the network.\n */\n readonly networkState: PlaybackNetworkState\n\n /**\n * Indicates whether the media element is paused.\n * Observe changes with `play` and `pause` events.\n */\n readonly paused: boolean\n\n /**\n * Sets the rate at which the media is being played back. This is used to implement user\n * controls for fast-forward, slow motion, and so forth. The normal playback rate is\n * multiplied by this value to obtain the current rate, so a value of 1.0 indicates normal\n * speed.\n */\n readonly playbackRate: number\n\n /**\n * True if playback has started, is not paused, stalled, or seeking.\n * Observe changes with 'playing' and 'played' events.\n */\n readonly playing: boolean\n\n /**\n * True if `play` has been called and the returned promise is currently in a pending state.\n * Observe changes with {@link PlaybackControllerEventMap.playIsPendingChange} events.\n */\n readonly playIsPending: boolean\n\n /**\n * Determines whether the browser should adjust the pitch of the audio to compensate\n * for changes to the playback rate.\n * Default: true\n */\n readonly preservesPitch: boolean\n\n /**\n * Indicates the readiness state of the media.\n * Observe changes with {@link PlaybackControllerEventMap.readyStateChange} events.\n */\n readonly readyState: PlaybackReadyState\n\n /**\n * Returns a new static normalized `ReadonlyRanges` object that represents the ranges of the\n * media resource, if any, that the user agent is able to seek to at the time seekable\n * property is accessed.\n *\n * Note: `ReadonlyRanges` is a view to the DOM `TimeRanges` object.\n */\n readonly seekable: ReadonlyRanges\n\n /**\n * True if the element is currently seeking.\n * Observe changes with `seeking` and `seeked` events.\n */\n readonly seeking: boolean\n\n /**\n * The volume level for audio portions of the media element.\n * Observe changes with `volumeChange` events.\n */\n readonly volume: number\n\n /**\n * True if playback is stopped due to waiting for data.\n * Observe changes with `waiting` and `waited` events.\n */\n readonly waiting: boolean\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ErrorLevel, type Json, ReportableError } from '@amazon/vinyl-util'\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport type { ReadonlyRanges } from '@amazon/vinyl-util'\n\n/**\n * An error indicating a seek was out of range.\n * This will have an error level of `ErrorLevel.WARN`.\n * This indicates a bad seek request, but is recoverable.\n */\nexport class InvalidSeekError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'InvalidSeekError'\n }\n\n constructor(\n readonly time: number,\n readonly seekable: ReadonlyRanges,\n readonly tolerance: number\n ) {\n super(\n `Could not seek to time: ${time}, outside of seekable ranges ${seekable} with tolerance ${tolerance}`,\n ErrorOrigin.API,\n ErrorLevel.WARN\n )\n Object.setPrototypeOf(this, InvalidSeekError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n time: this.time,\n seekable: Array.from(this.seekable),\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Disposable } from '@amazon/vinyl-util'\nimport { createDisposer } from '@amazon/vinyl-util'\nimport { logDebug } from '@amazon/vinyl-util'\nimport type { ReadonlyPlaybackController } from '../ReadonlyPlaybackController'\nimport { ALL_PLAYBACK_STATE_EVENTS } from '../ReadonlyPlaybackController'\nimport { throttle } from '@amazon/vinyl-util'\nimport { substitute } from '@amazon/vinyl-util'\nimport { createLogPrefix, type LogTarget } from '@amazon/vinyl-util'\n\n/**\n * The number of seconds to throttle timeupdate logs.\n * Logs will not be emitted for timeupdate events less than this interval.\n */\nexport const TIMEUPDATE_THROTTLE = 5\n\n/**\n * @private\n */\nconst locale = {\n /**\n * The timeupdate log message when grouping several updates together.\n *\n * Param start - start time\n * Param end - end time\n * Param count - number of events\n */\n timeupdateLogBatch: 'timeUpdate {start}-{end} x{count}',\n} as const\n\n/**\n * Logs all playback state events.\n *\n * @param playbackState The event host with playback events to observe.\n * @return Returns a disposable handle to remove all added handlers.\n */\nexport function playbackStateLoggingHandler(\n playbackState: ReadonlyPlaybackController\n): Disposable {\n const target: LogTarget = {\n logPrefix: createLogPrefix('Playback'),\n }\n const disposer = createDisposer()\n const { add } = disposer\n\n // Log time update events so that sequential time updates are debounced.\n let timeUpdateCount = 0\n let startTime: number | null = null\n\n /**\n * Logs the cumulated timeupdate event counts, resetting the window.\n */\n const logTimeupdateBatch = () => {\n if (startTime == null) return\n const currentTime = playbackState.currentTime\n logDebug(\n target,\n substitute(locale.timeupdateLogBatch, {\n start: startTime.toFixed(1),\n end: currentTime.toFixed(1),\n count: timeUpdateCount,\n })\n )\n timeUpdateCount = 0\n startTime = null\n }\n\n /**\n * Throttles timeupdate logs to the given interval.\n */\n const logTimeupdateBatchThrottled = add(\n throttle(logTimeupdateBatch, TIMEUPDATE_THROTTLE, { trailing: true })\n )\n\n add(\n playbackState.on('timeUpdate', () => {\n timeUpdateCount++\n if (startTime == null) startTime = playbackState.currentTime\n logTimeupdateBatchThrottled()\n })\n )\n\n for (const type of ALL_PLAYBACK_STATE_EVENTS) {\n if (type === 'timeUpdate') continue\n add(\n playbackState.on(type, (event) => {\n logTimeupdateBatch()\n logDebug(target, type, event)\n })\n )\n }\n\n return disposer\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface ChangeEvent<T> {\n readonly previous: T | null\n readonly current: T\n}\n\n/**\n * Creates a function, which when invoked, will call `inner` with a new ChangeEvent.\n *\n * @param getter\n * @param inner\n */\nexport function createChangeEventTrigger<T>(\n getter: () => T,\n inner: (event: ChangeEvent<T>) => void\n): () => void {\n let current = getter()\n return () => {\n const event: ChangeEvent<T> = {\n previous: current,\n current: getter(),\n }\n current = event.current\n inner(event)\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n PlaybackControllerEventMap,\n ReadonlyPlaybackController,\n} from './ReadonlyPlaybackController'\nimport {\n type AnyRecord,\n nextEventAsPromise,\n type NextEventAsPromiseOptions,\n} from '@amazon/vinyl-util'\n\nexport function nextHasMetadata(\n controller: ReadonlyPlaybackController,\n options?: NextEventAsPromiseOptions<\n PlaybackControllerEventMap,\n 'loadedMetadata'\n >\n): Promise<AnyRecord> {\n if (controller.hasMetadata) return Promise.resolve({})\n return nextEventAsPromise(controller, 'loadedMetadata', options)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n ErrorLevel,\n ErrorOrigin,\n type Json,\n type Maybe,\n ReportableError,\n} from '@amazon/vinyl-util'\nimport { mediaErrorToJson } from '../logging/mediaErrorToJson'\n\n/**\n * An error from the media element\n */\nexport class ReportableMediaError extends ReportableError {\n // Copied from MediaError to ensure compatibility in Node\n static readonly MEDIA_ERR_ABORTED = 1\n static readonly MEDIA_ERR_NETWORK = 2\n static readonly MEDIA_ERR_DECODE = 3\n static readonly MEDIA_ERR_SRC_NOT_SUPPORTED = 4\n\n get [Symbol.toStringTag](): string {\n return 'ReportableMediaError'\n }\n\n readonly reason: string\n readonly code: number\n\n constructor(error: Maybe<MediaError>) {\n const { name, code, message } = mediaErrorToJson(error)\n const level =\n error == null || code === ReportableMediaError.MEDIA_ERR_ABORTED\n ? ErrorLevel.SILENT\n : ErrorLevel.FATAL\n super(message, ErrorOrigin.MEDIA, level)\n this.reason = name\n this.code = code\n Object.setPrototypeOf(this, ReportableMediaError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n reason: this.reason,\n code: this.code,\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe } from '@amazon/vinyl-util'\n\nexport function mediaErrorToJson(error: Maybe<MediaError>): {\n readonly name: string\n readonly message: string\n readonly code: number\n} {\n let message: string = 'An unknown media error has occurred.'\n let name: string = 'UNKNOWN_MEDIA_ERROR'\n let code = -1\n if (error) {\n code = error.code\n switch (error.code) {\n case error.MEDIA_ERR_ABORTED: {\n message = `The requesting of the associated resource was aborted by the user's request.`\n name = 'MEDIA_ERR_ABORTED'\n break\n }\n case error.MEDIA_ERR_NETWORK: {\n message = 'A network error occurred.'\n name = 'MEDIA_ERR_NETWORK'\n break\n }\n case error.MEDIA_ERR_DECODE: {\n name = 'MEDIA_ERR_DECODE'\n message =\n 'An error occurred while trying to decode the media resource.'\n break\n }\n case error.MEDIA_ERR_SRC_NOT_SUPPORTED: {\n name = 'MEDIA_ERR_SRC_NOT_SUPPORTED'\n message = 'The associated resource was not supported.'\n break\n }\n }\n }\n return {\n name,\n message,\n code,\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { CrossOrigin, PlaybackSource } from './PlaybackSource'\n\nexport interface PlaybackSourceImplDeps {\n readonly media: HTMLMediaElement\n}\n\nexport class PlaybackSourceImpl implements PlaybackSource {\n protected readonly media: HTMLMediaElement\n\n constructor(deps: PlaybackSourceImplDeps) {\n this.media = deps.media\n }\n\n get crossOrigin(): CrossOrigin {\n return this.media.crossOrigin as CrossOrigin\n }\n\n set crossOrigin(value: CrossOrigin) {\n this.media.crossOrigin = value\n }\n\n get currentSrc(): string {\n return this.media.currentSrc\n }\n\n load(): void {\n this.media.load()\n }\n\n get src(): string {\n return this.media.src\n }\n\n set src(value: string | null) {\n if (!value) this.media.removeAttribute('src')\n else this.media.src = value\n }\n\n get srcObject(): MediaStream | null {\n return this.media.srcObject as MediaStream | null\n }\n\n set srcObject(value: MediaStream | null) {\n this.media.srcObject = value\n }\n\n get disableRemotePlayback(): boolean {\n return this.media.disableRemotePlayback\n }\n\n set disableRemotePlayback(value: boolean) {\n this.media.disableRemotePlayback = value\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AnyRecord, Maybe, ReadonlyRecord } from '@amazon/vinyl-util'\nimport { ErrorOrigin, ownKeys } from '@amazon/vinyl-util'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n isOneOf,\n object,\n string,\n type ValueSchema,\n} from '@amazon/vinyl-validation'\n\nimport type { Track, TrackTypeId, TrackUri } from './Track'\n\nexport interface TrackLoadOptions {\n /**\n * The track type, used to map to a track factory.\n */\n readonly type: TrackTypeId\n\n /**\n * The track identifier.\n */\n readonly uri: TrackUri\n\n /**\n * The track configuration.\n */\n readonly config?: Maybe<AnyRecord>\n}\n\nexport const trackLoadOptionsValidator: ObjectSchema<TrackLoadOptions> = /* @__PURE__ */ object(\n {\n type: /* @__PURE__ */ string(),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n config: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).maybe().optional(),\n }\n)\n\n/**\n * Produces a new Track for the given configuration options.\n */\nexport interface TrackFactory<TrackLoadOptionsType extends TrackLoadOptions> {\n /**\n * Throws a validation error if the track options are invalid.\n */\n validate(options: TrackLoadOptionsType): void\n\n /**\n * Constructs a new track from the provided load options.\n */\n createTrack(options: TrackLoadOptionsType): Track\n}\n\nexport type InferLoadOptionsFromFactory<T extends TrackFactory<any>> =\n T extends TrackFactory<infer LoadOptions> ? LoadOptions : never\n\nexport type CombinedTrackFactoryOptions<\n T extends ReadonlyRecord<TrackTypeId, TrackFactory<TrackLoadOptions>>,\n> = InferLoadOptionsFromFactory<T[keyof T]>\n\nexport type TrackFactoryRecord = ReadonlyRecord<\n TrackTypeId,\n TrackFactory<TrackLoadOptions>\n>\n\n/**\n * Validates that the keys of the track factory record match the track type\n * for the track factory.\n */\nexport type ValidTrackFactoryRecord<T extends TrackFactoryRecord> = {\n readonly [K in keyof T]: K extends InferLoadOptionsFromFactory<T[K]>['type']\n ? T[K]\n : never\n}\n\n/**\n * Given a map of TrackTypeId => TrackFactory, returns a track factory\n * that supports any of the provided track types.\n * The factory will be mapped by the track load options `type` property.\n *\n * @param factories\n */\nexport function createTrackFactory<T extends TrackFactoryRecord>(\n factories: ValidTrackFactoryRecord<T>\n): TrackFactory<CombinedTrackFactoryOptions<T>> {\n // Validates that the track type attempting to be created exists in the factory map.\n const typeValidator: ValueSchema<keyof T> = isOneOf(...ownKeys(factories))\n return {\n validate(options): void {\n typeValidator.assert(options.type, ErrorOrigin.API)\n factories[options.type].validate(options)\n },\n\n createTrack(options): Track {\n return factories[options.type].createTrack(options)\n },\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { PlaybackSource } from '../../playback/PlaybackSource'\nimport type { Track, TrackTypeId, TrackUri } from '../Track'\nimport { type TrackBaseDeps } from '../TrackBase'\nimport {\n type TrackFactory,\n type TrackLoadOptions,\n trackLoadOptionsValidator,\n} from '../TrackFactory'\nimport { ErrorOrigin, type Maybe } from '@amazon/vinyl-util'\nimport { func, isOneOf, type ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n SourceTrackBase,\n type SourceTrackBaseOptions,\n sourceTrackBaseOptionsValidator,\n} from './SourceTrackBase'\n\n/**\n * Dependencies for a SourceObjectTrack.\n */\nexport interface SourceObjectTrackDeps extends TrackBaseDeps {\n readonly playbackSource: PlaybackSource\n}\n\nexport interface SourceObjectTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'srcObject'\n\n /**\n * A function to produce a MediaStream, or Promise<MediaStream>.\n */\n readonly srcObjectProvider: (\n uri: TrackUri\n ) => Promise<MediaStream> | MediaStream\n\n /**\n * Configuration options for the SourceObjectTrack.\n * Will be provided on preload and activate.\n */\n readonly config?: Maybe<SourceTrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<SourceObjectTrackLoadOptions> =\n /* @__PURE__ */ trackLoadOptionsValidator.extend({\n srcObjectProvider: /* @__PURE__ */ func(),\n type: /* @__PURE__ */ isOneOf('srcObject'),\n config: /* @__PURE__ */ /* @__PURE__ */ sourceTrackBaseOptionsValidator.maybe().optional(),\n })\n\nexport function createSourceObjectTrackFactory(\n deps: SourceObjectTrackDeps\n): TrackFactory<SourceObjectTrackLoadOptions> {\n return {\n validate(options: SourceObjectTrackLoadOptions): void {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(options: SourceObjectTrackLoadOptions): Track {\n return new SourceObjectTrack(\n options.uri,\n options.type,\n Promise.resolve(options.srcObjectProvider(options.uri)),\n deps\n )\n },\n }\n}\n\n// TODO: Accept a provider function instead of a Promise for srcObject to support reset.\nexport class SourceObjectTrack extends SourceTrackBase<MediaStream> {\n get [Symbol.toStringTag](): string {\n return 'SourceObjectTrack'\n }\n\n constructor(\n uri: TrackUri,\n type: TrackTypeId,\n srcObject: Promise<MediaStream>,\n protected readonly deps: SourceObjectTrackDeps\n ) {\n super(uri, type, srcObject, deps)\n }\n\n protected setSrc(src: MediaStream) {\n this.deps.playbackSource.srcObject = src\n }\n\n protected clearSrc(): void {\n this.deps.playbackSource.srcObject = null\n this.deps.playbackSource.load()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport { any, number, object } from '@amazon/vinyl-validation'\nimport {\n createAbortSlot,\n createDisposer,\n emptyRanges,\n EventHostImpl,\n isSilentError,\n logDebug,\n type Maybe,\n noop,\n type ReadonlyRanges,\n type ReadonlySet,\n} from '@amazon/vinyl-util'\nimport type { PlaybackController } from '../playback/PlaybackController'\nimport type {\n Track,\n TrackEventMap,\n TrackPreloadOptions,\n TrackTypeId,\n TrackUri,\n} from './Track'\nimport { type DrmController } from '../drm/DrmController'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '../streaming/MediaQualityMetadata'\nimport { type DrmOptions, drmOptionsValidator } from '../drm/DrmOptions'\n\n/**\n * Dependencies for TrackBase.\n */\nexport interface TrackBaseDeps {\n /**\n * When the track is activated, playback will seek to the track's start time.\n */\n readonly playbackController: PlaybackController\n\n /**\n * DrmController manages track encryption.\n */\n readonly drmController: DrmController\n}\n\n/**\n * General configuration for tracks set in track load options.\n */\nexport interface TrackBaseOptions {\n /**\n * The time to seek to when the track has been activated.\n * For MSE tracks this will affect pre-fetching.\n */\n readonly startTime?: Maybe<number>\n\n /**\n * Extra application data to associate with the track.\n */\n readonly extra?: any\n\n /**\n * DRM Configuration overrides for this track.\n */\n readonly drm?: Partial<DrmOptions>\n}\n\nexport const trackBaseOptionsValidator: ObjectSchema<TrackBaseOptions> = /* @__PURE__ */ object(\n {\n extra: /* @__PURE__ */ /* @__PURE__ */ any().optional(),\n startTime: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ number().maybe().optional(),\n drm: /* @__PURE__ */ /* @__PURE__ */ drmOptionsValidator.partial().optional(),\n }\n)\n\n/**\n * A base class for all tracks.\n */\nexport abstract class TrackBase<\n EventMap extends TrackEventMap = TrackEventMap,\n LoadOptionsType extends TrackBaseOptions = TrackBaseOptions,\n>\n extends EventHostImpl<EventMap>\n implements Track<LoadOptionsType>\n{\n get [Symbol.toStringTag](): string {\n return 'TrackBase'\n }\n\n /**\n * The current load options, if this is an active track.\n */\n protected loadOptions: LoadOptionsType | null = null\n\n protected readonly errorHandler = (error: any): void => {\n if (this._error) return // Already in an error state\n if (!isSilentError(error)) {\n this._error = error\n this.dispatch('error', {\n target: this,\n error,\n })\n }\n }\n protected readonly disposer = /* @__PURE__ */ createDisposer()\n protected drmSessionAbort = /* @__PURE__ */ createAbortSlot()\n\n get fetchedRanges(): ReadonlyRanges {\n return emptyRanges\n }\n\n abstract get contentTypes(): ReadonlySet<ContentType>\n\n abstract get qualities(): readonly MediaQualityMetadata[] | null\n abstract get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null\n\n abstract getStreamingQuality(\n contentType: ContentType\n ): MediaQualityMetadata | null\n abstract getBufferingQuality(\n contentType: ContentType\n ): MediaQualityMetadata | null\n abstract getPlaybackQuality(\n contentType: ContentType\n ): MediaQualityMetadata | null\n\n /**\n * Sets on handleError, cleared on 'reset'.\n */\n protected _error: Error | null = null\n\n private _active = false\n\n protected constructor(\n /**\n * The identifier of this track, used as the key in the track cache.\n */\n readonly uri: TrackUri,\n\n /**\n * The track type.\n */\n readonly type: TrackTypeId,\n\n protected readonly deps: TrackBaseDeps\n ) {\n super()\n }\n\n get error(): Error | null {\n return this._error\n }\n\n preload(\n _trackOptions: TrackPreloadOptions,\n _loadOptions: LoadOptionsType\n ): void {}\n\n get extra(): any {\n return this.loadOptions?.extra ?? null\n }\n\n get active(): boolean {\n return this._active\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n activate(loadOptions: LoadOptionsType): void {\n if (this._active) return\n this.loadOptions = loadOptions\n this.reset() // Reset error state on activate\n this._active = true\n logDebug(this, 'activate', this.uri)\n this.deps.playbackController\n .seekTo(loadOptions.startTime ?? 0)\n .catch(noop)\n this.deps.drmController.configure(loadOptions.drm)\n this.onActivated(loadOptions)\n }\n\n /**\n * The track has been activated.\n * Operations on shared resources such as the playback controller may only be done while the\n * track is currently active. For example if there is a loading operation before the\n * playback source is set, isActive must be checked before the property is changed.\n */\n abstract onActivated(loadOptions: LoadOptionsType): void\n\n deactivate(): void {\n if (!this._active) return\n this._active = false\n this.loadOptions = null\n logDebug(this, 'deactivate', this.uri)\n this.deps.playbackController.pause()\n this.onDeactivated()\n this.closeDrmSessions()\n }\n\n abstract onDeactivated(): void\n\n toString(): string {\n return `[${this[Symbol.toStringTag]}#${this.uri}]`\n }\n\n protected closeDrmSessions() {\n this.drmSessionAbort.abort()\n }\n\n abstract clearPrefetch(): void\n\n /**\n * Resets the track to recover from error states.\n * Base implementation does nothing.\n *\n * Overrides should dispatch 'reset' after resetting error state.\n */\n reset(): void {\n if (this._error == null) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.dispatch('reset', {})\n }\n\n dispose() {\n if (this.active) this.deactivate()\n else this.closeDrmSessions() // closes sessions created from prefetch.\n this.disposer.dispose()\n super.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyRecord, ValueProvider } from '@amazon/vinyl-util'\nimport type { DrmInitDataType } from '../streaming/DrmInitDataType'\nimport type { MediaFormatMetadata } from '../streaming/MediaQualityMetadata'\nimport {\n enumOf,\n func,\n isOneOf,\n number,\n object,\n type ObjectSchema,\n record,\n recordValues,\n string,\n type ValueSchema,\n} from '@amazon/vinyl-validation'\nimport { DrmKeySystem, drmKeySystemValidator } from './DrmKeySystem'\nimport {\n type LicenseProvider,\n type LicenseServerOptions,\n licenseServerOptionsValidator,\n} from './licenseProvider/LicenseProvider'\n\n/**\n * DrmRobustness is the requested security level for audio or video decryption.\n */\nexport enum DrmRobustness {\n SW_SECURE_CRYPTO = 'SW_SECURE_CRYPTO',\n SW_SECURE_DECODE = 'SW_SECURE_DECODE',\n HW_SECURE_CRYPTO = 'HW_SECURE_CRYPTO',\n HW_SECURE_DECODE = 'HW_SECURE_DECODE',\n HW_SECURE_ALL = 'HW_SECURE_ALL',\n}\n\n/**\n * DrmConfig configures DrmController and LicenseProvider.\n */\nexport interface DrmOptions {\n readonly keySystems: {\n readonly [p in DrmKeySystem]?: DrmKeySystemOptions\n } & {\n readonly [DrmKeySystem.CLEAR_KEY]?: DrmClearKeySystemOptions\n } & {\n /**\n * A wildcard to match any key system when there wasn't a match.\n */\n readonly ['*']?: DrmKeySystemOptions\n }\n\n /**\n *\n * If not set, the license provider from the player dependencies will\n * be used.\n */\n readonly licenseProvider?: LicenseProvider\n}\n\n/**\n * Clear key system options that extend base DRM key system options with clear\n * key mappings. Used for unencrypted content or testing scenarios where keys\n * are provided in plain text.\n */\nexport type DrmClearKeySystemOptions = DrmKeySystemOptions & {\n readonly keys: ReadonlyRecord<string, string>\n}\n\nexport interface DrmKeySystemOptions {\n /**\n * License server configuration used to make license requests.\n */\n readonly licenseServer?: ValueProvider<LicenseServerOptions>\n\n /**\n * Audio-specific DRM configuration.\n */\n readonly audio?: DrmMediaKeySystemOptions\n\n /**\n * Video-specific DRM configuration.\n */\n readonly video?: DrmMediaKeySystemOptions\n\n /**\n * Key systems with a higher priority take precedence.\n * If two key systems have equal priority, the order will be as it appears\n * in DrmInfo (provided by the manifest).\n */\n readonly priority?: number\n\n /**\n * Transform applied to init data before session creation.\n * Always invoked for every key system. The default implementation\n * handles {@link DrmKeySystem.FAIR_PLAY_1_0} by packing the init data,\n * content ID, and server certificate into the format expected by\n * WebKit-prefixed EME. For all other key systems, returns init data\n * unchanged.\n */\n readonly initDataTransformer?: InitDataTransformer\n}\n\n/**\n * Transforms raw init data before it is passed to the CDM for session creation.\n *\n * @param initData - The raw initialization data.\n * @param initDataType - The initialization data type (e.g. 'cenc', 'skd').\n * @param drmInfo - The media format metadata for the current content.\n * @returns The transformed init data to pass to the CDM.\n */\nexport type InitDataTransformer = (\n initData: Uint8Array<ArrayBuffer>,\n initDataType: DrmInitDataType,\n drmInfo: MediaFormatMetadata\n) => Uint8Array<ArrayBuffer>\n\nexport interface DrmMediaKeySystemOptions {\n readonly robustness?: DrmRobustness\n}\n\nexport const drmRobustnessValidator: ValueSchema<DrmRobustness> =\n /* @__PURE__ */ enumOf(DrmRobustness)\n\nexport const drmMediaKeySystemOptionsValidator: ObjectSchema<DrmMediaKeySystemOptions> =\n /* @__PURE__ */ object({\n robustness: /* @__PURE__ */ drmRobustnessValidator.optional(),\n })\n\nexport const drmKeySystemOptionsValidator: ObjectSchema<DrmKeySystemOptions> =\n /* @__PURE__ */ object({\n licenseServer: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().or(licenseServerOptionsValidator).optional(),\n audio: /* @__PURE__ */ drmMediaKeySystemOptionsValidator.optional(),\n video: /* @__PURE__ */ drmMediaKeySystemOptionsValidator.optional(),\n priority: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n initDataTransformer: /* @__PURE__ */ /* @__PURE__ */ func().optional(),\n })\n\nexport const drmClearKeySystemOptionsValidator: ObjectSchema<DrmClearKeySystemOptions> =\n /* @__PURE__ */ drmKeySystemOptionsValidator.extend({\n keys: /* @__PURE__ */ recordValues(/* @__PURE__ */ string()),\n })\n\nexport const drmOptionsValidator: ObjectSchema<DrmOptions> = /* @__PURE__ */ object({\n keySystems: /* @__PURE__ */ /* @__PURE__ */ record(\n /* @__PURE__ */ drmKeySystemValidator.or(/* @__PURE__ */ isOneOf('*')),\n /* @__PURE__ */ drmKeySystemOptionsValidator.optional()\n ).and(\n /* @__PURE__ */ object<{\n readonly [DrmKeySystem.CLEAR_KEY]?: DrmClearKeySystemOptions\n }>({\n [DrmKeySystem.CLEAR_KEY]:\n /* @__PURE__ */ drmClearKeySystemOptionsValidator.optional(),\n })\n ),\n\n licenseProvider: /* @__PURE__ */ /* @__PURE__ */ func().optional(),\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ValueSchema } from '@amazon/vinyl-validation'\nimport { string } from '@amazon/vinyl-validation'\n\nexport enum DrmKeySystem {\n /**\n * Plain text encryption.\n */\n CLEAR_KEY = 'org.w3.clearkey',\n\n /**\n * Google's Widevine.\n */\n WIDEVINE = 'com.widevine.alpha',\n\n /**\n * Microsoft's PlayReady.\n *\n * - Deprecated.\n * - Will be removed in a future release.\n * - Non-compliant with any version of the EME specification.\n */\n PLAY_READY = 'com.microsoft.playready',\n\n /**\n * Microsoft's PlayReady for Chromecast.\n *\n * - Deprecated.\n * - Will be removed in a future release.\n * - Non-compliant with any version of the EME specification.\n */\n PLAY_READY_CHROMECAST = 'com.chromecast.playready',\n\n /**\n * Microsoft's PlayReady.\n *\n * - Security Level 2000.\n * - Best effort compliance with latest EME specification.\n */\n PLAY_READY_RECOMMENDATION = 'com.microsoft.playready.recommendation',\n\n /**\n * Microsoft's PlayReady.\n *\n * - Supported on devices with required hardware.\n * - Security Level 3000.\n * - Best effort compliance with latest EME specification.\n */\n PLAY_READY_3000 = 'com.microsoft.playready.recommendation.3000',\n\n /**\n * Apple's Fairplay for modern EME.\n */\n FAIR_PLAY = 'com.apple.fps',\n\n /**\n * Apple's Fairplay for legacy Apple Media Keys.\n */\n FAIR_PLAY_1_0 = 'com.apple.fps.1_0',\n}\n\n/**\n * Validates that the key system value is a string.\n * While DrmKeySystem is an enum to be useful for providing known key systems,\n * avoid strict validation to allow for unknown key systems.\n */\nexport const drmKeySystemValidator =\n /* @__PURE__ */ /* @__PURE__ */ string().notEmpty() as ValueSchema<DrmKeySystem>\n\nexport const PLAY_READY_KEY_SYSTEMS: readonly DrmKeySystem[] = [\n DrmKeySystem.PLAY_READY,\n DrmKeySystem.PLAY_READY_CHROMECAST,\n DrmKeySystem.PLAY_READY_RECOMMENDATION,\n DrmKeySystem.PLAY_READY_3000,\n] as const\n\nexport function isPlayReady(keySystem: DrmKeySystem): boolean {\n return PLAY_READY_KEY_SYSTEMS.includes(keySystem)\n}\n\nexport const FAIR_PLAY_KEY_SYSTEMS: readonly DrmKeySystem[] = [\n DrmKeySystem.FAIR_PLAY,\n DrmKeySystem.FAIR_PLAY_1_0,\n] as const\n\nexport function isFairPlay(keySystem: DrmKeySystem): boolean {\n return FAIR_PLAY_KEY_SYSTEMS.includes(keySystem)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type Maybe, type ReadonlyAbort } from '@amazon/vinyl-util'\nimport type { DrmKeySystem } from '../DrmKeySystem'\nimport {\n any,\n instanceOf,\n object,\n type ObjectSchema,\n string,\n} from '@amazon/vinyl-validation'\n\n/**\n * LicenseProvider handles requesting DRM licenses for specific key systems.\n */\nexport type LicenseProvider = (\n keySystem: DrmKeySystem,\n serverOptions: LicenseServerOptions,\n challenge: ArrayBuffer,\n abort?: ReadonlyAbort\n) => Promise<ArrayBuffer>\n\n/**\n * Basic license server configuration.\n * The license provider is given the matching configuration for the selected\n * key system.\n */\nexport interface LicenseServerOptions {\n /**\n * The license server URL.\n * This is required when using the default license provider.\n */\n readonly url?: Maybe<string | URL>\n\n /**\n * License request init options.\n */\n readonly init?: Maybe<RequestInit>\n\n /**\n * If set, provides the server certificate.\n * An ArrayBufferLike object containing the server certificate.\n * The contents are Key System-specific.\n * If a `string` is provided, the value will be considered to be Base 64.\n */\n readonly serverCertificate?: Maybe<ServerCertificate>\n}\n\n/**\n * An ArrayBufferLike object containing the server certificate.\n * The contents are Key System-specific.\n * If a `string` is provided, the value will be considered to be Base 64.\n */\nexport type ServerCertificate = ArrayBuffer | string\n\nexport const licenseServerOptionsValidator: ObjectSchema<LicenseServerOptions> =\n /* @__PURE__ */ object({\n url: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().or(/* @__PURE__ */ instanceOf(URL)).maybe().optional(),\n init: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).cast<RequestInit>().maybe().optional(),\n serverCertificate: /* @__PURE__ */ /* @__PURE__ */ any().optional(),\n })\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { TrackEventMap } from '../Track'\nimport type { Unsubscribe } from '@amazon/vinyl-util'\nimport { EventHostImpl, type ReadonlySet } from '@amazon/vinyl-util'\nimport { PlaybackReadyState } from '../../playback/ReadonlyPlaybackController'\nimport type { PlaybackController } from '../../playback/PlaybackController'\nimport type { ChangeEvent } from '../../event/ChangeEvent'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '../../streaming/MediaQualityMetadata'\n\n/**\n * FixedPlaybackQuality has a singular quality for selection.\n *\n * streamingQuality will always be the fixed quality.\n *\n * bufferingQuality will be the fixed quality when active, otherwise null.\n *\n * playbackQuality will be the fixed quality when active and data is buffered, otherwise null.\n */\nexport class FixedPlaybackQuality extends EventHostImpl<\n Pick<\n TrackEventMap,\n | 'streamingQualityChange'\n | 'bufferingQualityChange'\n | 'playbackQualityChange'\n >\n> {\n private _fixedQuality!: MediaQualityMetadata\n private _contentTypes = /* @__PURE__ */ new Set<ContentType>()\n\n private _isActive = false\n get active(): boolean {\n return this._isActive\n }\n\n constructor(\n fixedQuality: MediaQualityMetadata,\n private readonly deps: {\n readonly playbackController: PlaybackController\n }\n ) {\n super()\n this.fixedQuality = fixedQuality\n }\n\n get contentTypes(): ReadonlySet<ContentType> {\n return this._contentTypes\n }\n\n get fixedQuality(): MediaQualityMetadata {\n return this._fixedQuality\n }\n\n set fixedQuality(value: MediaQualityMetadata) {\n const previous = this._fixedQuality\n this._fixedQuality = value\n this._contentTypes = new Set()\n if (value.contentType) this._contentTypes.add(value.contentType)\n this.dispatch('streamingQualityChange', {\n previous,\n current: this._fixedQuality,\n })\n if (this.active) {\n this.bufferingQuality = value\n if (\n this.deps.playbackController.readyState >=\n PlaybackReadyState.HAVE_CURRENT_DATA\n ) {\n this.playbackQuality = value\n }\n }\n }\n\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n if (contentType !== this._fixedQuality.contentType) return null\n return this._fixedQuality\n }\n\n private _bufferingQuality: MediaQualityMetadata | null = null\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n if (contentType !== this._bufferingQuality?.contentType) return null\n return this._bufferingQuality\n }\n\n private set bufferingQuality(value: MediaQualityMetadata | null) {\n const previous = this._bufferingQuality\n if (previous === value) return\n this._bufferingQuality = value\n this.dispatch('bufferingQualityChange', {\n previous,\n current: this._bufferingQuality,\n })\n }\n\n private _playbackQuality: MediaQualityMetadata | null = null\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n if (contentType !== this._playbackQuality?.contentType) return null\n return this._playbackQuality\n }\n\n private set playbackQuality(value: MediaQualityMetadata | null) {\n const previous = this._playbackQuality\n if (previous === value) return\n this._playbackQuality = value\n this.dispatch('playbackQualityChange', {\n previous,\n current: this._playbackQuality,\n })\n }\n\n private readyStateChangeSub: Unsubscribe | null = null\n activate() {\n if (this._isActive) return\n this._isActive = true\n this.bufferingQuality = this._fixedQuality\n const pC = this.deps.playbackController\n this.readyStateChangeSub = pC.on(\n 'readyStateChange',\n this.onReadyStateChange\n )\n if (pC.readyState >= PlaybackReadyState.HAVE_CURRENT_DATA) {\n this.playbackQuality = this._fixedQuality\n }\n }\n\n deactivate() {\n if (!this._isActive) return\n this._isActive = false\n this.readyStateChangeSub!()\n this.readyStateChangeSub = null\n this.bufferingQuality = null\n this.playbackQuality = null\n }\n\n private onReadyStateChange = (event: ChangeEvent<PlaybackReadyState>) => {\n const hasData = event.current >= PlaybackReadyState.HAVE_CURRENT_DATA\n this.playbackQuality = hasData ? this._fixedQuality : null\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n TrackBase,\n type TrackBaseDeps,\n type TrackBaseOptions,\n trackBaseOptionsValidator,\n} from '../TrackBase'\nimport type {\n TrackEventMap,\n TrackPreloadOptions,\n TrackTypeId,\n TrackUri,\n} from '../Track'\nimport { FixedPlaybackQuality } from './FixedPlaybackQuality'\nimport {\n logDebug,\n type Maybe,\n type ReadonlySet,\n redispatchEvents,\n} from '@amazon/vinyl-util'\nimport {\n type ContentType,\n createEmptyMediaQualityMetadata,\n type MediaQualityMetadata,\n mediaQualityMetadataValidator,\n} from '../../streaming/MediaQualityMetadata'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\n\nexport interface SourceTrackBaseOptions extends TrackBaseOptions {\n /**\n * Quality metadata.\n * May be used to configure DRM (for native HLS), codec, or other track metadata.\n */\n readonly qualityMetadata?: Maybe<Partial<MediaQualityMetadata>>\n}\n\nexport const sourceTrackBaseOptionsValidator: ObjectSchema<SourceTrackBaseOptions> =\n /* @__PURE__ */ trackBaseOptionsValidator.extend({\n qualityMetadata: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ mediaQualityMetadataValidator\n .partial()\n .maybe()\n .optional(),\n })\n\nconst emptyMediaQualityMetadata: MediaQualityMetadata =\n /* @__PURE__ */ createEmptyMediaQualityMetadata()\n\nexport abstract class SourceTrackBase<\n SrcType,\n EventMap extends TrackEventMap = TrackEventMap,\n LoadOptionsType extends SourceTrackBaseOptions = SourceTrackBaseOptions,\n> extends TrackBase<EventMap, LoadOptionsType> {\n private readonly fixedPlaybackQuality: FixedPlaybackQuality\n private _resolvedSrc: SrcType | null = null\n\n protected constructor(\n uri: TrackUri,\n type: TrackTypeId,\n public readonly src: Promise<SrcType>,\n protected readonly deps: TrackBaseDeps\n ) {\n super(uri, type, deps)\n const add = this.disposer.add\n this.src\n .then((src) => {\n this._resolvedSrc = src\n if (this.active) this.setSrc(src)\n })\n .catch(this.errorHandler)\n this.fixedPlaybackQuality = add(\n new FixedPlaybackQuality(emptyMediaQualityMetadata, deps)\n )\n this.fixedPlaybackQuality.on('bufferingQualityChange', (event) => {\n this.deps.drmController.setBufferingDrmInfo(\n event.current,\n this.drmSessionAbort.value\n )\n })\n redispatchEvents(this, this.fixedPlaybackQuality, [\n 'streamingQualityChange',\n 'bufferingQualityChange',\n 'playbackQualityChange',\n ])\n }\n\n preload(trackOptions: TrackPreloadOptions, loadOptions: LoadOptionsType) {\n super.preload(trackOptions, loadOptions)\n this.fixedPlaybackQuality.fixedQuality = {\n ...emptyMediaQualityMetadata,\n ...loadOptions.qualityMetadata,\n }\n }\n\n get contentTypes(): ReadonlySet<ContentType> {\n return this.fixedPlaybackQuality.contentTypes\n }\n\n get qualities(): readonly MediaQualityMetadata[] | null {\n return null\n }\n\n get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null {\n return null\n }\n\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.fixedPlaybackQuality.getStreamingQuality(contentType)\n }\n\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.fixedPlaybackQuality.getBufferingQuality(contentType)\n }\n\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.fixedPlaybackQuality.getPlaybackQuality(contentType)\n }\n\n onActivated(): void {\n this.fixedPlaybackQuality.activate()\n this.deps.drmController.initializeForPlayback(\n this.fixedPlaybackQuality.fixedQuality,\n this.drmSessionAbort.value\n )\n if (this._resolvedSrc != null) this.setSrc(this._resolvedSrc)\n }\n\n protected abstract setSrc(src: SrcType): void\n protected abstract clearSrc(): void\n\n onDeactivated(): void {\n if (this._resolvedSrc != null) this.clearSrc()\n this.fixedPlaybackQuality.deactivate()\n }\n\n clearPrefetch() {\n // Source tracks do not prefetch\n logDebug(this, 'clearPrefetch no-op')\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createShortUid,\n type Maybe,\n type MutableDeep,\n} from '@amazon/vinyl-util'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n array,\n enumOf,\n isOneOf,\n number,\n object,\n string,\n tuple,\n} from '@amazon/vinyl-validation'\nimport {\n type DescriptorRecord,\n descriptorRecordValidator,\n descriptorValidator,\n} from './DescriptorRecord'\n\nimport type { DrmInitDataType } from './DrmInitDataType'\nimport type { CencEncryptionScheme } from '../drm/CencEncryptionScheme'\nimport { DrmKeySystem } from '../drm/DrmKeySystem'\nimport type { FrameRate } from '@amazon/vinyl-mpd-parser'\n\nexport type ContentType = 'audio' | 'video' | 'text'\n\nexport const ALL_CONTENT_TYPES = [\n 'video',\n 'audio',\n 'text',\n] as const satisfies ContentType[]\n\n/**\n * Contains media formatting and encryption metadata.\n */\nexport interface MediaFormatMetadata {\n /**\n * The content type of the representation, e.g. 'audio', 'video', 'text'\n * Must be non-null for segmented media.\n */\n readonly contentType: ContentType | null\n\n /**\n * The full MIME type of the media.\n *\n * Must be non-null for segmented media.\n */\n readonly mimeType: string | null\n\n /**\n * The initialization data format.\n */\n readonly initDataType: DrmInitDataType | null\n\n /**\n * The method of encryption, or null.\n */\n readonly encryptionScheme: CencEncryptionScheme | null\n\n /**\n * Protection schemes used in this media.\n */\n readonly contentProtections: readonly DrmProtection[]\n}\n\n/**\n * Protection information for a key system.\n * Media may have more than one protection system.\n */\nexport interface DrmProtection {\n /**\n * The key system used in the encryption.\n */\n readonly keySystem: DrmKeySystem\n\n /**\n * The initialization key, in base 64.\n */\n readonly pssh?: Maybe<string>\n\n /**\n * PlayReady object.\n */\n readonly pro?: Maybe<string>\n}\n\nexport const drmProtectionValidator: ObjectSchema<DrmProtection> =\n /* @__PURE__ */ descriptorValidator.extend({\n keySystem: /* @__PURE__ */ enumOf(DrmKeySystem),\n pro: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n pssh: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n })\n\nexport const mediaFormatMetadataValidator: ObjectSchema<MediaFormatMetadata> =\n /* @__PURE__ */ object({\n contentProtections: /* @__PURE__ */ /* @__PURE__ */ array(drmProtectionValidator).readonly(),\n contentType: /* @__PURE__ */ /* @__PURE__ */ isOneOf('audio', 'video', 'text').orNull(),\n initDataType: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n encryptionScheme: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n mimeType: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n })\n\n/**\n * Metadata representing attributes of a media representation.\n */\nexport interface MediaQualityMetadata extends MediaFormatMetadata {\n /**\n * Provides a decoding identifier. If this value changes from the previously buffered\n * segment, the initialization segment must be buffered before appending the media segment.\n * Unique to the track.\n */\n readonly decoderId: string\n\n /**\n * The quality id identifies the quality representation.\n * Unique to the track.\n */\n readonly qualityId: string\n\n /**\n * Optional string specifying the codec(s) used for this representation. The format follows the RFC 6381 codec\n * string format.\n */\n readonly codecs: string | null\n\n /**\n * The average bandwidth in bits per second required for playing this representation.\n * For HLS, and non-segmented media this will be null.\n */\n readonly bandwidth: number | null\n\n /**\n * The peak bandwidth in bits per second required for playing this representation\n * with its cumulative A/V content streams.\n *\n * Guaranteed to be set for segmented media.\n */\n readonly bandwidthTotal: number | null\n\n /**\n * Audio sampling rate(s) in samples per second.\n * An array of either one or two decimal integer values. If there are two elements this represents a minimum and\n * maximum sampling rate of the audio media.\n */\n readonly audioSamplingRate: readonly number[] | null\n\n /**\n * Frame rate for video representations, specified either as a ratio of integers, e.g. [30000, 1001]\n */\n readonly frameRate: FrameRate | null\n\n /**\n * For video representations, the width of the video in pixels.\n */\n readonly width: number | null\n\n /**\n * For video representations, the height of the video in pixels.\n */\n readonly height: number | null\n\n /**\n * Information that may enhance playback or presentation.\n */\n readonly supplementalProperties: DescriptorRecord\n\n /**\n * Specifies the language of the content, using a code as defined by RFC 5646.\n */\n readonly lang: string | null\n\n /**\n * Identifies the group this quality belongs to (e.g. the adaptation set).\n */\n readonly groupId: string\n\n /**\n * The group IDs that this quality is permitted to switch to during playback.\n * Derived from the DASH `urn:mpeg:dash:adaptation-set-switching:2016` supplemental property.\n * Includes the quality's own groupId.\n * Null means no switching constraint (all groups are permitted).\n * An array restricts switching to only the listed group IDs.\n * Default behavior:\n * - DASH: restricted to own group unless adaptation-set-switching property is present.\n * - HLS: restricted to variants with the same base codec and language.\n */\n readonly switchingGroupIds: readonly string[] | null\n}\n\n/**\n * Creates a new, empty media format metadata object.\n */\nexport function createEmptyMediaFormatMetadata(): MutableDeep<MediaFormatMetadata> {\n return {\n contentType: null,\n mimeType: null,\n initDataType: null,\n encryptionScheme: null,\n contentProtections: [],\n }\n}\n\n/**\n * Creates a new empty media quality metadata object.\n */\nexport function createEmptyMediaQualityMetadata(): MutableDeep<MediaQualityMetadata> {\n return {\n ...createEmptyMediaFormatMetadata(),\n decoderId: createShortUid(),\n qualityId: createShortUid(),\n codecs: null,\n bandwidth: null,\n bandwidthTotal: null,\n supplementalProperties: {},\n audioSamplingRate: null,\n frameRate: null,\n height: null,\n width: null,\n lang: null,\n groupId: createShortUid(),\n switchingGroupIds: null,\n }\n}\n\nexport const mediaQualityMetadataValidator: ObjectSchema<MediaQualityMetadata> =\n /* @__PURE__ */ mediaFormatMetadataValidator.extend({\n audioSamplingRate: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ array(/* @__PURE__ */ number()).readonly().orNull(),\n bandwidth: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n bandwidthTotal: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n codecs: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n decoderId: /* @__PURE__ */ string(),\n frameRate: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ tuple(/* @__PURE__ */ number(), /* @__PURE__ */ number()).readonly().orNull(),\n height: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n qualityId: /* @__PURE__ */ string(),\n supplementalProperties: descriptorRecordValidator,\n width: /* @__PURE__ */ /* @__PURE__ */ number().orNull(),\n lang: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n groupId: /* @__PURE__ */ string(),\n switchingGroupIds: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ array(/* @__PURE__ */ string()).readonly().orNull(),\n })\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n array,\n object,\n type ObjectSchema,\n record,\n type RecordSchema,\n string,\n} from '@amazon/vinyl-validation'\nimport { first, type Maybe, type ReadonlyRecord } from '@amazon/vinyl-util'\nimport { type Uri } from '@amazon/vinyl-xml'\n\n/**\n * A map of scheme URIs to a descriptor list.\n */\nexport type DescriptorRecord = ReadonlyRecord<\n Uri,\n readonly Descriptor[] | undefined\n>\n\n/**\n * A generic descriptor providing extended information.\n */\nexport interface Descriptor {\n /**\n * An optional unique identifier for the descriptor.\n */\n readonly id?: Maybe<string>\n\n /**\n * An optional value associated with the descriptor, whose interpretation depends on the scheme.\n */\n readonly value?: Maybe<string>\n}\n\n/**\n * Gets The first matching descriptor value from a record with a matching URI and optional id.\n *\n * @param record The descriptor record.\n * @param uri The URI key.\n * @param id An optional id. If provided the descriptor must have a matching id.\n */\nexport function getDescriptorValue(\n record: DescriptorRecord,\n uri: Uri,\n id?: Maybe<string>\n): string | null {\n let arr = record[uri]\n if (!arr) return null\n if (id !== undefined) arr = arr.filter((descriptor) => descriptor.id === id)\n return first(arr)?.value ?? null\n}\n\nexport const descriptorValidator: ObjectSchema<Descriptor> = /* @__PURE__ */ object({\n id: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n value: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ string().maybe().optional(),\n})\n\nexport const descriptorRecordValidator: RecordSchema<DescriptorRecord> = /* @__PURE__ */ record<\n Uri,\n readonly Descriptor[] | undefined\n>(/* @__PURE__ */ string(), /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ array(descriptorValidator).readonly().orUndefined())\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Track, TrackTypeId, TrackUri } from '../Track'\nimport { type TrackBaseDeps } from '../TrackBase'\nimport {\n type TrackFactory,\n type TrackLoadOptions,\n trackLoadOptionsValidator,\n} from '../TrackFactory'\nimport { ErrorOrigin, type Maybe } from '@amazon/vinyl-util'\nimport {\n func,\n isOneOf,\n type ObjectSchema,\n string,\n} from '@amazon/vinyl-validation'\nimport {\n SourceTrackBase,\n type SourceTrackBaseOptions,\n sourceTrackBaseOptionsValidator,\n} from './SourceTrackBase'\nimport type { PlaybackSource } from '../../playback/PlaybackSource'\n\n/**\n * Dependencies for a SourceTrack.\n */\nexport interface SourceTrackDeps extends TrackBaseDeps {\n readonly playbackSource: PlaybackSource\n}\n\nexport interface SourceTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'src'\n\n /**\n * If set, will be called to provide the track src.\n * Otherwise, the uri will be used.\n */\n readonly srcProvider?: Maybe<(uri: TrackUri) => Promise<string> | string>\n\n /**\n * Configuration options for the SourceTrack.\n * Will be provided on preload and activate.\n */\n readonly config?: Maybe<SourceTrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<SourceTrackLoadOptions> =\n /* @__PURE__ */ trackLoadOptionsValidator.extend({\n config: /* @__PURE__ */ /* @__PURE__ */ sourceTrackBaseOptionsValidator.maybe().optional(),\n srcProvider: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().maybe().optional(),\n type: /* @__PURE__ */ isOneOf('src'),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n })\n\nexport function createSourceTrackFactory(\n deps: SourceTrackDeps\n): TrackFactory<SourceTrackLoadOptions> {\n return {\n validate(options: SourceTrackLoadOptions) {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(options: SourceTrackLoadOptions): Track {\n return new SourceTrack(\n options.uri,\n options.type,\n options.srcProvider\n ? Promise.resolve(options.srcProvider(options.uri))\n : Promise.resolve(options.uri),\n deps\n )\n },\n }\n}\n\n// TODO: Accept a provider function instead of a Promise for src to support reset.\nexport class SourceTrack extends SourceTrackBase<string> {\n get [Symbol.toStringTag](): string {\n return 'SourceTrack'\n }\n\n constructor(\n uri: TrackUri,\n type: TrackTypeId,\n src: Promise<string>,\n protected readonly deps: SourceTrackDeps\n ) {\n super(uri, type, src, deps)\n }\n\n protected setSrc(src: string) {\n this.deps.playbackSource.src = src\n }\n\n protected clearSrc() {\n this.deps.playbackSource.src = null\n this.deps.playbackSource.load()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type TrackBaseOptions, trackBaseOptionsValidator } from '../TrackBase'\nimport {\n type DashManifestProvider,\n type DashManifestData,\n} from './DashManifestProvider'\nimport type { DashManifestController } from './DashManifestController'\nimport type { TrackFactory, TrackLoadOptions } from '../TrackFactory'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport {\n ErrorOrigin,\n type Maybe,\n type RequestInitOptions,\n} from '@amazon/vinyl-util'\nimport {\n func,\n isOneOf,\n object,\n type ObjectSchema,\n string,\n} from '@amazon/vinyl-validation'\nimport type { Track } from '../Track'\nimport { type Factories } from '@amazon/vinyl-di'\nimport type { DashMediaQualityMetadataResolver } from './DashMediaQualityMetadataResolver'\nimport { MseTrack, type MseTrackDeps } from '../mse/MseTrack'\nimport type { MediaTimeline } from '../../streaming/MediaTimeline'\n\nexport interface DashTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'dash'\n\n /**\n * If set, will be used to resolve the dash manifest.\n * Otherwise, the uri will be assumed to represent a URL to an MPD.\n * The manifest provider is not expected to cache results.\n */\n readonly manifestProvider?: Maybe<DashManifestProvider>\n\n /**\n * If a manifest provider is not set, the uri will be used to fetch a manifest.\n * This can be set to provide Request initialization options such as headers or request method.\n */\n readonly requestInit?: Maybe<RequestInitOptions>\n\n /**\n * Request initialization options for segment requests, such as headers.\n * Range headers set by the player for byte-range requests will not be overridden.\n */\n readonly segmentRequestInit?: Maybe<RequestInitOptions>\n\n /**\n * Configuration options for the DashTrack.\n * Will be set before the track is activated.\n */\n readonly config?: Maybe<TrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<DashTrackLoadOptions> = /* @__PURE__ */ object({\n config: /* @__PURE__ */ /* @__PURE__ */ trackBaseOptionsValidator.maybe().optional(),\n manifestProvider: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().maybe().optional(),\n requestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).cast<RequestInitOptions>().maybe().optional(),\n segmentRequestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({})\n .cast<RequestInitOptions>()\n .maybe()\n .optional(),\n type: /* @__PURE__ */ isOneOf('dash'),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n})\n\nexport type DashTrackFactoryDeps = {\n readonly createDashFactories: (\n loadOptions: DashTrackLoadOptions\n ) => Factories<DashTrackDeps>\n}\n\nexport function createDashTrackFactory(\n deps: DashTrackFactoryDeps\n): TrackFactory<DashTrackLoadOptions> {\n return {\n validate(options: DashTrackLoadOptions) {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(loadOptions: DashTrackLoadOptions): Track {\n return new MseTrack(\n loadOptions.uri,\n loadOptions.type,\n deps.createDashFactories(loadOptions)\n )\n },\n }\n}\n\nexport interface DashTrackDeps extends MseTrackDeps {\n readonly manifestController: DashManifestController\n readonly mediaQualityMetadataResolver: DashMediaQualityMetadataResolver\n readonly manifestTransformed: ObservableValue<Promise<DashManifestData>>\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n TrackBase,\n type TrackBaseDeps,\n type TrackBaseOptions,\n} from '../TrackBase'\nimport {\n Abort,\n equalDeep,\n type Fun,\n IntersectionRanges,\n logDebug,\n type ReadonlyRanges,\n type ReadonlySet,\n redispatchEvents,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport type { TrackPreloadOptions, TrackTypeId, TrackUri } from '../Track'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '../../streaming/MediaQualityMetadata'\nimport { createContainer, type Factories } from '@amazon/vinyl-di'\nimport type {\n ContentStream,\n ContentStreamActivateOptions,\n ContentStreamPreloadOptions,\n} from '../../streaming/ContentStream'\nimport type { MediaSourceController } from '../../streaming/buffering/MediaSourceController'\nimport type { PlaybackSource } from '../../playback/PlaybackSource'\nimport type { ContentTypesValue } from '../../streaming/ContentTypesValue'\nimport type { ManifestController } from '../../streaming/ManifestController'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from '../../streaming/MediaTimeline'\nimport {\n getMediaPeriodAtTime,\n type MediaPeriod,\n} from '../../streaming/MediaTimeline'\n\nexport type MseTrackDeps = TrackBaseDeps & {\n readonly contentTypesValue: ContentTypesValue\n readonly contentStreamFactory: (contentType: ContentType) => ContentStream\n readonly manifestController: ManifestController<unknown>\n readonly mediaSourceController: MediaSourceController\n readonly playbackSource: PlaybackSource\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n}\n\ntype FunctionKeys<T> = {\n [P in keyof T]: T[P] extends Fun ? P : never\n}[keyof T]\n\n/**\n * An MseTrack uses media source extensions for streaming.\n */\nexport class MseTrack extends TrackBase {\n get [Symbol.toStringTag](): string {\n return 'MseTrack'\n }\n\n declare protected readonly deps: MseTrackDeps\n\n private readonly streams: ContentStream[] = []\n private readonly disposeAbort = /* @__PURE__ */ new Abort()\n private lastPreloadOptions: ContentStreamPreloadOptions | null = null\n private activateOptions: ContentStreamActivateOptions | null = null\n private readonly allFetchedRanges: ReadonlyRanges[] = []\n private readonly _fetchedRanges = /* @__PURE__ */ new IntersectionRanges(\n this.allFetchedRanges,\n { useCache: true }\n )\n private _contentTypes: ReadonlySet<ContentType> = /* @__PURE__ */ new Set()\n\n private _qualities: readonly MediaQualityMetadata[] | null = null\n private _qualitiesUnfiltered: readonly MediaQualityMetadata[] | null = null\n private timeUpdateSub: Unsubscribe | null = null\n private _cachedPeriod: MediaPeriod | null = null\n\n constructor(\n uri: TrackUri,\n type: TrackTypeId,\n dependencyFactories: Factories<MseTrackDeps>\n ) {\n const depsContainer = createContainer(dependencyFactories)\n const deps = depsContainer.dependencies\n super(uri, type, deps)\n logDebug(this, 'constructed')\n const { add } = this.disposer\n add(depsContainer)\n this.deps = deps\n\n add(\n deps.contentTypesValue.onData((contentTypesPromise) => {\n contentTypesPromise\n .then((contentTypes) => {\n if (this.disposer.disposed) return\n if (equalDeep(this.contentTypes, contentTypes)) return // no-op\n logDebug(this, 'content types:', contentTypes)\n this.clearStreams()\n for (const contentType of contentTypes) {\n this.createStream(contentType)\n }\n // Sets the content types and dispatches a change event:\n this.contentTypes = contentTypes\n })\n .catch(this.errorHandler)\n })\n )\n\n // DRM\n this.on('streamingQualityChange', (event) => {\n if (this.activateOptions) {\n this.deps.drmController.initializeForPlayback(\n event.current,\n this.disposeAbort\n )\n }\n })\n\n this.on('bufferingQualityChange', (event) => {\n this.deps.drmController.setBufferingDrmInfo(\n event.current,\n this.disposeAbort\n )\n })\n\n // Listen for timeline changes to update qualities.\n add(\n deps.mediaTimelineTransformed.onData(() => {\n this._cachedPeriod = null\n this.updateQualities()\n })\n )\n add(\n deps.mediaTimeline.onData(() => {\n this._cachedPeriod = null\n this.updateQualitiesUnfiltered()\n })\n )\n }\n\n /**\n * Updates the cached qualities list from the transformed timeline for the current period.\n */\n private updateQualities(): void {\n const time = this.deps.playbackController.currentTime\n this.deps.mediaTimelineTransformed.value\n .then((timeline) => {\n if (this.disposer.disposed) return\n const period = getMediaPeriodAtTime(timeline, time)\n this._cachedPeriod = period\n const newQualities = period\n ? period.qualities.map((q) => q.metadata)\n : null\n if (!equalDeep(newQualities, this._qualities)) {\n const previous = this._qualities\n this._qualities = newQualities\n if (newQualities) {\n this.dispatch('qualitiesChange', {\n previous: previous ?? [],\n current: newQualities,\n })\n }\n }\n })\n .catch(this.errorHandler)\n }\n\n /**\n * Updates the cached unfiltered qualities list from the raw timeline for the current period.\n */\n private updateQualitiesUnfiltered(): void {\n const time = this.deps.playbackController.currentTime\n this.deps.mediaTimeline.value\n .then((timeline) => {\n if (this.disposer.disposed) return\n const period = getMediaPeriodAtTime(timeline, time)\n const newQualities = period\n ? period.qualities.map((q) => q.metadata)\n : null\n if (!equalDeep(newQualities, this._qualitiesUnfiltered)) {\n const previous = this._qualitiesUnfiltered\n this._qualitiesUnfiltered = newQualities\n if (newQualities) {\n this.dispatch('qualitiesUnfilteredChange', {\n previous: previous ?? [],\n current: newQualities,\n })\n }\n }\n })\n .catch(this.errorHandler)\n }\n\n /**\n * Creates and adds a content stream for the given content type.\n *\n * @param contentType\n */\n protected createStream(contentType: ContentType): void {\n const stream = this.deps.contentStreamFactory(contentType)\n redispatchEvents(this, stream, [\n 'fetchedRangesChange',\n 'streamingQualityChange',\n 'bufferingQualityChange',\n 'playbackQualityChange',\n ])\n stream.on('bufferingEnded', () => {\n if (this.bufferingEnded) {\n this.deps.mediaSourceController.endOfStream()\n this.dispatch('bufferingEnded', {})\n }\n })\n stream.on('fetchedRangesChange', () => {\n this._fetchedRanges.invalidate()\n })\n stream.on('error', (event) => {\n if (!this._error) {\n // Set error state and bubble event\n this._error = event.error\n this.dispatch('error', event)\n }\n })\n\n // The fetched ranges of the track is the intersection of all content stream fetched ranges.\n this.allFetchedRanges.push(stream.fetchedRanges)\n this._fetchedRanges.invalidate()\n\n this.streams.push(stream)\n if (this.lastPreloadOptions) {\n stream.preload(this.lastPreloadOptions)\n }\n if (this.activateOptions) {\n stream.activate(this.activateOptions)\n }\n }\n\n preload(trackOptions: TrackPreloadOptions, loadOptions: TrackBaseOptions) {\n const options = {\n startTime: loadOptions.startTime,\n prefetchPriority: trackOptions.prefetchPriority,\n }\n this.lastPreloadOptions = options\n this.callOnStreams('preload', options)\n }\n\n get contentTypes(): ReadonlySet<ContentType> {\n return this._contentTypes\n }\n\n set contentTypes(value: ReadonlySet<ContentType>) {\n const previous = this._contentTypes\n this._contentTypes = value\n this.dispatch('contentTypesChange', {\n previous,\n current: value,\n })\n }\n\n get qualities(): readonly MediaQualityMetadata[] | null {\n return this._qualities\n }\n\n get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null {\n return this._qualitiesUnfiltered\n }\n\n get fetchedRanges(): ReadonlyRanges {\n return this._fetchedRanges\n }\n\n /**\n * Clears all fetched fragments and source buffers. Streaming will resume.\n * This should be called if a change has been made where the user would expect an immediate change,\n * for example, changing streaming quality from SD to HD.\n */\n clearPrefetch() {\n logDebug(this, 'clearPrefetch')\n this.callOnStreams('clearPrefetch')\n }\n\n /**\n * Resets the track to recover from error states.\n * Resets both the segment controller and buffering controller to clear failed segments and error conditions.\n */\n reset(): void {\n if (!this.error) {\n logDebug(this, 'reset no-op')\n return\n }\n this.deps.manifestController.reset()\n this.callOnStreams('reset')\n super.reset()\n }\n\n onActivated(loadOptions: TrackBaseOptions): void {\n this.activateOptions = loadOptions\n // AirPlay not supported using managed media sources\n this.deps.playbackSource.disableRemotePlayback = true\n\n this.streams.forEach((stream) => {\n this.deps.drmController.initializeForPlayback(\n stream.streamingQuality,\n this.disposeAbort\n )\n })\n this.deps.playbackSource.src =\n this.deps.mediaSourceController.createUrl()\n this.callOnStreams('activate', loadOptions)\n\n // Listen for timeUpdate to detect period changes.\n this.timeUpdateSub = this.deps.playbackController.on(\n 'timeUpdate',\n () => {\n const time = this.deps.playbackController.currentTime\n const cached = this._cachedPeriod\n if (\n cached &&\n time >= cached.startTime &&\n time < cached.endTime\n ) {\n return\n }\n this.updateQualities()\n this.updateQualitiesUnfiltered()\n }\n )\n }\n\n onDeactivated(): void {\n this.activateOptions = null\n this.timeUpdateSub?.()\n this.timeUpdateSub = null\n this.callOnStreams('deactivate')\n\n this.deps.playbackSource.src = null\n this.deps.playbackSource.load()\n }\n\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.getStream(contentType)?.streamingQuality ?? null\n }\n\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.getStream(contentType)?.bufferingQuality ?? null\n }\n\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.getStream(contentType)?.playbackQuality ?? null\n }\n\n /**\n * Calls the specified method on all streams with the provided arguments.\n */\n private callOnStreams<K extends FunctionKeys<ContentStream>>(\n functionName: K,\n ...args: Parameters<ContentStream[K]>\n ) {\n this.streams.forEach((stream) => {\n ;(stream[functionName] as Fun)(...args)\n })\n }\n\n private getStream(contentType: ContentType): ContentStream | undefined {\n return this.streams.find((s) => s.contentType === contentType)\n }\n\n private clearStreams() {\n this.callOnStreams('dispose')\n this.streams.length = 0\n this.allFetchedRanges.length = 0\n this._fetchedRanges.invalidate()\n }\n\n get bufferingEnded(): boolean {\n return this.streams.every((stream) => stream.bufferingEnded)\n }\n\n dispose(): void {\n logDebug(this, 'dispose')\n this.timeUpdateSub?.()\n this.timeUpdateSub = null\n this.clearStreams()\n super.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { SegmentReference } from './SegmentReference'\nimport type { SegmentDataProvider } from './SegmentDataSlot'\nimport type { MediaQualityMetadata } from './MediaQualityMetadata'\nimport { sortedInsertionIndex } from '@amazon/vinyl-util'\n\n/**\n * Represents a single quality within a period, providing access to its metadata\n * and segment data.\n */\nexport interface MediaQualityData {\n readonly metadata: MediaQualityMetadata\n\n /**\n * Gets the segment reference at the given time, or null if the time is outside the range.\n * @param time The time, in seconds, relative to the presentation timeline.\n * @param affordance Forward-snap tolerance in seconds: if `time` falls just before a\n * segment's start (within `affordance`), that segment is returned. Defaults to `0`.\n */\n getSegment(\n time: number,\n affordance?: number\n ): Promise<SegmentReference<SegmentDataProvider> | null>\n}\n\n/**\n * Represents a period within the media timeline.\n */\nexport interface MediaPeriod {\n readonly startTime: number\n readonly endTime: number\n readonly qualities: readonly MediaQualityData[]\n}\n\n/**\n * Represents the full media timeline, composed of one or more periods.\n */\nexport interface MediaTimeline {\n readonly periods: readonly MediaPeriod[]\n\n /**\n * The minimum duration of the buffer that a client should maintain for uninterrupted playback.\n */\n readonly minBufferTime: number\n\n /**\n * The total duration of the media, in seconds.\n * Returns `Infinity` for live streams.\n * Rejects when there are no segments to derive a duration from.\n */\n getDuration(): Promise<number>\n}\n\n/**\n * Gets the period spanning the given presentation time.\n */\nexport function getMediaPeriodAtTime(\n timeline: MediaTimeline,\n time: number\n): MediaPeriod | null {\n const index =\n sortedInsertionIndex(timeline.periods, time, (time, period) => {\n return time - period.startTime\n }) - 1\n if (index < 0) return null\n const period = timeline.periods[index]\n return time >= period.endTime ? null : period\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe, RequestInitOptions } from '@amazon/vinyl-util'\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport type { TrackLoadOptions, TrackFactory } from '../TrackFactory'\nimport type { TrackBaseOptions } from '../TrackBase'\nimport type { Track } from '../Track'\nimport type { HlsManifestProvider } from './HlsManifestProvider'\nimport type { HlsManifestController } from './HlsManifestController'\nimport type { HlsManifestData } from './HlsManifestProvider'\nimport type { HlsMediaQualityMetadataResolver } from './HlsMediaQualityMetadataResolver'\nimport type { MseTrackDeps } from '../mse/MseTrack'\nimport { MseTrack } from '../mse/MseTrack'\nimport {\n func,\n isOneOf,\n object,\n string,\n type ObjectSchema,\n} from '@amazon/vinyl-validation'\nimport { trackBaseOptionsValidator } from '../TrackBase'\nimport type { Factories } from '@amazon/vinyl-di'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from '../../streaming/MediaTimeline'\n\nexport interface HlsTrackLoadOptions extends TrackLoadOptions {\n readonly type: 'hls'\n readonly manifestProvider?: Maybe<HlsManifestProvider>\n readonly requestInit?: Maybe<RequestInitOptions>\n readonly segmentRequestInit?: Maybe<RequestInitOptions>\n readonly config?: Maybe<TrackBaseOptions>\n}\n\nconst loadOptionsValidator: ObjectSchema<HlsTrackLoadOptions> = /* @__PURE__ */ object({\n config: /* @__PURE__ */ /* @__PURE__ */ trackBaseOptionsValidator.maybe().optional(),\n manifestProvider: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ func().maybe().optional(),\n requestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({}).cast<RequestInitOptions>().maybe().optional(),\n segmentRequestInit: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ object({})\n .cast<RequestInitOptions>()\n .maybe()\n .optional(),\n type: /* @__PURE__ */ isOneOf('hls'),\n uri: /* @__PURE__ */ /* @__PURE__ */ string().notEmpty(),\n})\n\nexport interface HlsTrackDeps extends MseTrackDeps {\n readonly manifestController: HlsManifestController\n readonly manifestTransformed: ObservableValue<Promise<HlsManifestData>>\n readonly mediaQualityMetadataResolver: HlsMediaQualityMetadataResolver\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n}\n\nexport type HlsTrackFactoryDeps = {\n readonly createHlsFactories: (\n loadOptions: HlsTrackLoadOptions\n ) => Factories<HlsTrackDeps>\n}\n\nexport function createHlsTrackFactory(\n deps: HlsTrackFactoryDeps\n): TrackFactory<HlsTrackLoadOptions> {\n return {\n validate(options: HlsTrackLoadOptions) {\n loadOptionsValidator.assert(options, ErrorOrigin.API)\n },\n\n createTrack(loadOptions: HlsTrackLoadOptions): Track {\n return new MseTrack(\n loadOptions.uri,\n loadOptions.type,\n deps.createHlsFactories(loadOptions)\n )\n },\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createSourceObjectTrackFactory,\n type SourceObjectTrackDeps,\n type SourceObjectTrackLoadOptions,\n} from './source/SourceObjectTrack'\nimport {\n createSourceTrackFactory,\n type SourceTrackDeps,\n type SourceTrackLoadOptions,\n} from './source/SourceTrack'\nimport type { TrackTypeId } from './Track'\nimport type { TrackFactory } from './TrackFactory'\nimport type { ReadonlyRecord } from '@amazon/vinyl-util'\nimport {\n createDashTrackFactory,\n type DashTrackFactoryDeps,\n type DashTrackLoadOptions,\n} from './dash/DashTrack'\nimport {\n createHlsTrackFactory,\n type HlsTrackFactoryDeps,\n type HlsTrackLoadOptions,\n} from './hls/HlsTrack'\n\nexport interface VinylTrackFactoryDeps\n extends\n SourceTrackDeps,\n SourceObjectTrackDeps,\n DashTrackFactoryDeps,\n HlsTrackFactoryDeps {}\n\nexport type VinylTrackLoadOptions =\n | SourceObjectTrackLoadOptions\n | SourceTrackLoadOptions\n | DashTrackLoadOptions\n | HlsTrackLoadOptions\n\n/**\n * Provides a map of track type id to their respective loaders.\n * @param deps\n */\nexport function createVinylTrackFactories(deps: VinylTrackFactoryDeps) {\n return {\n src: createSourceTrackFactory(deps),\n srcObject: createSourceObjectTrackFactory(deps),\n dash: createDashTrackFactory(deps),\n hls: createHlsTrackFactory(deps),\n } as const satisfies ReadonlyRecord<\n TrackTypeId,\n TrackFactory<VinylTrackLoadOptions>\n >\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n countElements,\n createDisposer,\n type Disposable,\n EventHostImpl,\n first,\n getOrSet,\n logDebug,\n logInfo,\n LruCache,\n type Maybe,\n noop,\n type ReadonlyEventHost,\n type TimeoutId,\n} from '@amazon/vinyl-util'\nimport type { PlaybackController } from '../playback/PlaybackController'\nimport type { ReadonlyTrack, Track, TrackUri } from './Track'\nimport type { TrackFactory, TrackLoadOptions } from './TrackFactory'\nimport type { ChangeEvent } from '../event/ChangeEvent'\n\nexport interface TrackControllerEventMap<\n TrackLoadOptionsType extends TrackLoadOptions,\n> {\n /**\n * Emitted when the current track is changing.\n * This is emitted before the previous track has been deactivated and\n * new track has been activated.\n */\n readonly currentTrackChanging: ChangeEvent<ReadonlyTrack | null>\n\n /**\n * Emitted when the current track has changed.\n * If there is a queue change, the currentTrackChange event is always emitted first.\n * This is emitted after the previous track has been deactivated and\n * new track has been activated.\n */\n readonly currentTrackChange: ChangeEvent<ReadonlyTrack | null>\n\n /**\n * Dispatched when the queue has changed.\n */\n readonly queueChange: ChangeEvent<readonly TrackLoadOptionsType[]>\n\n /**\n * Emitted when the last track of the playback queue has ended.\n * When the last track in a queue has ended, the track will not change and therefore a `currentTrackChange`\n * event will not be emitted.\n */\n readonly queueEnded: AnyRecord\n}\n\nexport const ALL_TRACK_CONTROLLER_EVENTS = [\n 'currentTrackChanging',\n 'currentTrackChange',\n 'queueChange',\n 'queueEnded',\n] as const satisfies readonly (keyof TrackControllerEventMap<any>)[]\n\n/**\n * A readonly interface to the track controller.\n */\nexport interface ReadonlyTrackController<\n TrackLoadOptionsType extends TrackLoadOptions,\n> extends ReadonlyEventHost<TrackControllerEventMap<TrackLoadOptionsType>> {\n /**\n * Returns the current track.\n */\n readonly currentTrack: ReadonlyTrack | null\n\n /**\n * Returns the current queue of TrackLoadOptions.\n * Observe 'queueChange' for changes to this queue.\n */\n readonly queue: readonly TrackLoadOptionsType[]\n\n /**\n * Returns true if there is at least one track in the queue.\n */\n hasNext(): boolean\n\n /**\n * Returns true if the track with the given URI is cached.\n */\n isTrackCached(uri: TrackUri): boolean\n\n /**\n * Returns the cached track for the given URI, or null if the track is not cached.\n */\n getCachedTrack(uri: TrackUri): ReadonlyTrack | null\n\n /**\n * Returns an iterator of currently cached tracks.\n */\n getCachedTracks(): IterableIterator<ReadonlyTrack>\n}\n\n/**\n * Responsible for queuing track load configurations.\n * This is the authority for which is the current track.\n */\nexport interface TrackController<\n TrackLoadOptionsType extends TrackLoadOptions,\n> extends ReadonlyTrackController<TrackLoadOptionsType> {\n /**\n * Preloads the given list of tracks.\n * The tracks provided will not be enqueued.\n * The track controller's cache size will automatically increase to accommodate the request.\n *\n * Prefetch priority note:\n * Tracks have a prefetch priority, later calls to preload will have a higher precedence than previous calls.\n * Previous tracks given to `preload` will drop off when they are evicted from the cache. This is dependent on\n * cache size.\n *\n * @param loadOptionsList\n */\n preload(...loadOptionsList: readonly TrackLoadOptionsType[]): void\n\n /**\n * Sets the current queue to the provided track list.\n * When the track ends, the next will be played.\n *\n * `load` does not begin playback. Call `play()` after a load to start playback.\n * Browser autoplay policies may require the first call to `play()` to be in response to a user interaction\n * such as a click, touch, keypress, or voice event.\n *\n * Note that if the current track is the first track provided in the list, that track will be restarted.\n * To set the queue without unloading the current track, use {@link clearQueue} followed by {@link enqueue}.\n *\n * @param loadOptionsList A list of load configuration objects to set as a playback queue.\n */\n load(...loadOptionsList: readonly TrackLoadOptionsType[]): void\n\n /**\n * Unloads the active track and clears the queue.\n * This is the same as calling {@link load} with zero parameters.\n */\n unload(): void\n\n /**\n * Appends the given tracks to the current queue.\n *\n * @param loadOptionsList The track load configurations to append.\n */\n enqueue(...loadOptionsList: readonly TrackLoadOptionsType[]): void\n\n /**\n * Activates the next track in the queue.\n * If the media is not paused the next track will begin playing automatically.\n *\n * @see ReadonlyTrackController.hasNext\n */\n next(): void\n\n /**\n * Clears all fetched fragments and source buffers.\n * Playback will be interrupted, and streaming will resume again when data has been fetched and buffered.\n * This should be called if a change has been made where the user would expect an immediate change,\n * for example, changing streaming quality from SD to HD.\n *\n * Does not unload manifests.\n */\n clearPrefetch(): void\n\n /**\n * Clears the track cache and unloads the current track.\n */\n clearTrackCache(): void\n\n /**\n * Clears the current queue.\n * Does not stop the current track or affect the prefetched cache.\n */\n clearQueue(): void\n\n /**\n * Resets the current track's error state.\n */\n reset(): void\n}\n\nexport interface TrackControllerImplDeps<\n TrackLoadOptionsType extends TrackLoadOptions,\n> {\n readonly trackFactory: TrackFactory<TrackLoadOptionsType>\n\n readonly playbackController: PlaybackController\n}\n\nexport interface TrackControllerImplOptions {\n /**\n * When tracks are queued, the number of tracks to prefetch ahead of the current track.\n * Default: 2\n */\n readonly trackPrefetchCount: number\n\n /**\n * The number of seconds before load calls will time out if the first track's metadata is not loaded within\n * this time.\n * Default: 60\n */\n readonly loadTimeout: number\n\n /**\n * The number of tracks that may be preloaded at one time (not counting queue prefetch).\n * This extends the track cache capacity and allows a certain number of tracks no longer in the queue to remain\n * cached.\n *\n * Default: 2\n */\n readonly preloadCapacity: number\n}\n\nconst defaultTrackControllerImplOptions = {\n trackPrefetchCount: 2,\n loadTimeout: 60,\n preloadCapacity: 2,\n} as const satisfies TrackControllerImplOptions\n\n/**\n * Track priority will be assigned based on calls to `preload`.\n * Segment background prefetching is shared if there are multiple players instances (in the rare case there would be\n * multiple players). Having a global incrementing trackPriority prevents one player from starving another.\n */\nexport const trackPriority = {\n value: 0,\n}\n\nexport class TrackControllerImpl<TrackLoadOptionsType extends TrackLoadOptions>\n extends EventHostImpl<TrackControllerEventMap<TrackLoadOptionsType>>\n implements TrackController<TrackLoadOptionsType>, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'TrackControllerImpl'\n }\n\n // When tracks are preloaded, the cache capacity may expand automatically to accommodate.\n private _autoPreloadCapacity = 0\n private readonly trackCache = /* @__PURE__ */ new LruCache<string, Track>(0)\n private _queue: readonly TrackLoadOptionsType[] = []\n private _current: TrackLoadOptionsType | null = null\n private readonly disposer = /* @__PURE__ */ createDisposer()\n private _options: TrackControllerImplOptions =\n defaultTrackControllerImplOptions\n\n private trackEndedTimeoutId: TimeoutId | null = null\n\n constructor(\n private readonly deps: TrackControllerImplDeps<TrackLoadOptionsType>,\n initialOptions?: Partial<TrackControllerImplOptions>\n ) {\n super()\n const { add } = this.disposer\n\n this.trackCache.onEvicting = (track) => {\n // Do not evict tracks within the prefetch range.\n return (\n this.prefetched.find((value) => value.uri === track.uri) == null\n )\n }\n\n this.trackCache.onEvict = (track) => {\n logDebug(this, `Disposing track: ${track.uri}`)\n track.dispose()\n return true\n }\n\n add(\n deps.playbackController.on('ended', () => {\n this.trackEndedTimeoutId = setTimeout(() => {\n // Adds a frame delay to allow applications an opportunity to respond to 'ended' events before the\n // track is changed.\n this.trackEndedTimeoutId = null\n if (this.hasNext()) {\n this.next()\n } else {\n logInfo(this, 'queueEnded')\n this.dispatch('queueEnded', {})\n }\n })\n })\n )\n this.configure(initialOptions)\n }\n\n private clearTrackEndedTimeout() {\n if (this.trackEndedTimeoutId) {\n clearTimeout(this.trackEndedTimeoutId)\n this.trackEndedTimeoutId = null\n }\n }\n\n /**\n * Returns the currently set configuration.\n */\n get options(): TrackControllerImplOptions {\n return this._options\n }\n\n /**\n * Configures this track queue from the provided partial options.\n *\n * @param options\n */\n configure(options: Maybe<Partial<TrackControllerImplOptions>>) {\n logDebug(this, 'configure', options)\n this._options = {\n ...this._options,\n ...options,\n }\n this.checkCacheCapacity()\n }\n\n /**\n * Checks if the cache capacity needs to be changed.\n */\n private checkCacheCapacity() {\n const capacity =\n this.preloadCapacity + this._options.trackPrefetchCount + 1\n if (capacity !== this.trackCache.capacity) {\n logDebug(this, 'track cache capacity changed:', capacity)\n this.trackCache.capacity = capacity\n }\n }\n\n get queue(): readonly TrackLoadOptionsType[] {\n return this._queue\n }\n\n /**\n * Returns the subset of the queue that should be prefetched.\n * @private\n */\n private get prefetched(): readonly TrackLoadOptionsType[] {\n const tracks: TrackLoadOptionsType[] = []\n if (this._current) tracks.push(this._current)\n tracks.push(...this._queue.slice(0, this.options.trackPrefetchCount))\n return tracks\n }\n\n isTrackCached(uri: TrackUri): boolean {\n return this.trackCache.has(uri)\n }\n\n getCachedTrack(uri: TrackUri): ReadonlyTrack | null {\n return this.trackCache.get(uri) ?? null\n }\n\n getCachedTracks(): IterableIterator<ReadonlyTrack> {\n return this.trackCache.values()\n }\n\n /**\n * Returns the current preload capacity.\n * This automatically increases when preload is called with more tracks than the current capacity.\n */\n get preloadCapacity(): number {\n return Math.max(\n this._autoPreloadCapacity,\n this._options.preloadCapacity\n )\n }\n\n private validateLoadOptions = (loadOptions: TrackLoadOptionsType) =>\n this.deps.trackFactory.validate(loadOptions)\n\n preload(...loadOptionsList: readonly TrackLoadOptionsType[]): void {\n logDebug(this, `preload ${loadOptionsList.length} items`)\n loadOptionsList.forEach(this.validateLoadOptions)\n this._preload(loadOptionsList)\n }\n\n private _preload(loadOptionsList: readonly TrackLoadOptionsType[]): void {\n const prefetched = this.prefetched\n // Calculate the required preload capacity as the number of tracks requested that are not within the\n // prefetch window. If this value is greater than the current preloadCapacity, increase the cache size.\n const requiredPreloadCapacity = countElements(\n loadOptionsList,\n (loadOptions) => {\n return (\n prefetched.find((element) => {\n return element.uri === loadOptions.uri\n }) == null\n )\n }\n )\n if (this._autoPreloadCapacity < requiredPreloadCapacity) {\n this._autoPreloadCapacity = requiredPreloadCapacity\n this.checkCacheCapacity()\n }\n // Tracks requested to preload will have a priority where the first track in the list (next track) has\n // the highest precedence. (Higher priority values take precedence)\n trackPriority.value += loadOptionsList.length\n let priority = trackPriority.value\n for (const loadOptions of loadOptionsList) {\n const track = this.getOrCreateTrack(loadOptions.uri, loadOptions)\n track.preload(\n {\n prefetchPriority: priority--,\n },\n loadOptions.config ?? {}\n )\n }\n }\n\n load(...loadOptionsList: readonly TrackLoadOptionsType[]): void {\n logDebug(this, `load ${loadOptionsList.length} items`)\n loadOptionsList.forEach(this.validateLoadOptions)\n this.clearTrackEndedTimeout()\n this._current = loadOptionsList[0] ?? null\n const previousQueue = this._queue\n this._queue = loadOptionsList.slice(1)\n this._preload(this.prefetched)\n this.activateCurrent()\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n unload() {\n this.load()\n }\n\n enqueue(...loadOptionsList: readonly TrackLoadOptionsType[]): void {\n logDebug(this, `enqueue ${loadOptionsList.length} items`)\n loadOptionsList.forEach(this.validateLoadOptions)\n const previousQueue = this._queue\n this._queue = this._queue.concat(loadOptionsList)\n this._preload(this.prefetched)\n if (this.currentTrack == null && this.hasNext()) this.next()\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n hasNext(): boolean {\n return this._queue.length > 0\n }\n\n next(): void {\n this.clearTrackEndedTimeout()\n const playbackController = this.deps.playbackController\n const shouldPlay =\n playbackController.ended || !playbackController.paused\n const next = first(this._queue)\n const previousQueue = this._queue\n this._queue = this._queue.slice(1)\n this._current = next ?? null\n logDebug(this, 'next, nextTrack:', this._current)\n if (\n this.options.trackPrefetchCount > 0 &&\n this._queue.length >= this.options.trackPrefetchCount\n ) {\n this._preload([this._queue[this.options.trackPrefetchCount - 1]])\n }\n this.activateCurrent()\n if (shouldPlay) void playbackController.play().catch(noop)\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n clearTrackCache() {\n logDebug(this, 'clearTrackCache')\n this.clearTrackEndedTimeout()\n const previousQueue = this._queue\n this._queue = []\n this.trackCache.forEach((track) => {\n track.dispose()\n })\n this.trackCache.clear()\n this._autoPreloadCapacity = 0\n this.checkCacheCapacity()\n this.clearCurrentTrack()\n this.dispatch('queueChange', {\n previous: previousQueue,\n current: this._queue,\n })\n }\n\n clearPrefetch(): void {\n for (const cachedTrack of this.trackCache.values()) {\n cachedTrack.clearPrefetch()\n }\n }\n\n clearQueue(): void {\n this.clearTrackEndedTimeout()\n const previous = this._queue\n this._queue = []\n this.dispatch('queueChange', {\n previous,\n current: this._queue,\n })\n }\n\n /**\n * If the given track id is the current track or in the cache, returns that track.\n * Otherwise, constructs a new track, adds it to the cache, and returns it.\n *\n * @param uri The unique resource identifier.\n * @param loadOptions\n * @private\n */\n private getOrCreateTrack(\n uri: TrackUri,\n loadOptions: TrackLoadOptionsType\n ): Track {\n return getOrSet(this.trackCache, uri, () => {\n const newTrack = this.deps.trackFactory.createTrack(loadOptions)\n this.trackCache.set(uri, newTrack)\n return newTrack\n })\n }\n\n /**\n * Get the current track from cache or create a new track, then activates that track.\n */\n private activateCurrent(): void {\n const loadOptions = this._current\n if (!loadOptions) {\n this.clearCurrentTrack()\n return\n }\n this.setCurrentTrack(\n this.getOrCreateTrack(loadOptions.uri, loadOptions),\n loadOptions\n )\n }\n\n private _currentTrack: Track | null = null\n get currentTrack(): ReadonlyTrack | null {\n return this._currentTrack\n }\n\n /**\n * Sets the current track. If the given track is already current, it will be de-activated and re-activated and\n * the currentTrackChange event will still be emitted.\n * The same track may be in the queue multiple times.\n */\n private setCurrentTrack(\n value: Track | null,\n loadOptions: TrackLoadOptionsType | null\n ) {\n const previousTrack = this._currentTrack\n this.dispatch('currentTrackChanging', {\n previous: previousTrack,\n current: value,\n })\n this._currentTrack = value\n if (previousTrack?.active === true) previousTrack.deactivate()\n const loadOptionsConfig = loadOptions?.config ?? {}\n if (value?.active === false) value.activate(loadOptionsConfig)\n logDebug(\n this,\n `currentTrackChange, previous: ${previousTrack} current: ${value}`\n )\n this.dispatch('currentTrackChange', {\n previous: previousTrack,\n current: value,\n })\n }\n\n private clearCurrentTrack() {\n this.setCurrentTrack(null, null)\n }\n\n reset() {\n this._currentTrack?.reset()\n }\n\n dispose() {\n logDebug(this, 'dispose')\n super.dispose()\n this.clearTrackCache()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { lazy } from '@amazon/vinyl-util'\nimport { requiresUnreliablePlaybackEventsPatch } from './patches/createUnreliablePlaybackEventsPatch'\nimport { requiresPreventStallsPatch } from './patches/createPreventStallsPatch'\n\nexport interface MediaElementPatchOptions {\n /**\n * Playback events 'playing' and 'waiting' are unreliable after seeking.\n *\n * Risks for false positive: LOW. Timing of emitted playing events may be subtly\n * different, but they will not be duplicated.\n * Risks for false negative: MEDIUM. Certain playback events on affected platforms will be missed.\n */\n readonly unreliablePlaybackEvents?: boolean\n\n /**\n * The affected user agent gets into a state where playback can become stalled and needs help getting unstuck.\n */\n readonly preventStalls?: boolean\n}\n\n/**\n * Aggregates flags for toggling patches.\n */\nexport const defaultMediaElementPatchOptions = /* @__PURE__ */ lazy<\n Required<MediaElementPatchOptions>\n>(() => {\n return {\n unreliablePlaybackEvents: requiresUnreliablePlaybackEventsPatch(),\n preventStalls: requiresPreventStallsPatch(),\n } as const satisfies Required<MediaElementPatchOptions>\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaElementPatchOptions } from '../patch/media/MediaElementPatchOptions'\nimport { defaultMediaElementPatchOptions } from '../patch/media/MediaElementPatchOptions'\nimport { lazy } from '@amazon/vinyl-util'\n\n/**\n * Flags for applying patches.\n * Default flags will be applied based on user agent, but may be overridden during player creation.\n */\nexport interface VinylPatchOptions {\n readonly media: MediaElementPatchOptions\n}\n\nexport const defaultPatchOptions = /* @__PURE__ */ lazy<VinylPatchOptions>(() => {\n return {\n media: defaultMediaElementPatchOptions.value,\n } as const satisfies VinylPatchOptions\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { last, merge, sortedInsertionIndex } from '@amazon/vinyl-util'\n\nimport {\n type AdaptationSetType,\n type DashManifest,\n type MPDtype,\n type PeriodType,\n type RepresentationType,\n type SegmentBaseType,\n type SegmentListType,\n type SegmentTemplateType,\n} from '@amazon/vinyl-mpd-parser'\n\n// TODO: For dynamic MPDs, availability time offsets should be summed.\n\n/**\n * Calculates the inherited SegmentList for the given representation. Or returns undefined if no SegmentList is\n * present in the hierarchy.\n */\nexport function getSegmentList(\n representation: RepresentationType\n): SegmentListType | undefined {\n return mergeIfAnyDefined(\n representation.parent.parent.SegmentList,\n representation.parent.SegmentList,\n representation.SegmentList\n )\n}\n\n/**\n * Calculates the inherited SegmentTemplate for the given representation. Or returns undefined if no SegmentTemplate is\n * present in the hierarchy.\n */\nexport function getSegmentTemplate(\n representation: RepresentationType\n): SegmentTemplateType | undefined {\n return mergeIfAnyDefined(\n representation.parent.parent.SegmentTemplate,\n representation.parent.SegmentTemplate,\n representation.SegmentTemplate\n )\n}\n\n/**\n * Calculates the inherited SegmentBase for the given representation. Or returns undefined if no SegmentBase is\n * present in the hierarchy.\n */\nexport function getSegmentBase(\n representation: RepresentationType\n): SegmentBaseType | undefined {\n return mergeIfAnyDefined(\n representation.parent.parent.SegmentBase,\n representation.parent.SegmentBase,\n representation.SegmentBase\n )\n}\n\n/**\n * Returns the representation's ancestry: [MPD, Period, AdaptationSet, Representation]\n */\nexport function getRepresentationAncestry(\n representation: RepresentationType\n): readonly [MPDtype, PeriodType, AdaptationSetType, RepresentationType] {\n const adaptationSet = representation.parent\n const period = adaptationSet.parent\n const mpd = period.parent\n return [mpd, period, adaptationSet, representation]\n}\n\n/**\n * Merges the properties of all sources into a new object.\n * Used to calculate inherited properties.\n * If all sources are undefined, returns undefined.\n */\nfunction mergeIfAnyDefined<T>(...sources: T[]): T | undefined {\n if (!sources.some((source) => source)) return undefined\n return merge(...sources)\n}\n\nexport type PeriodRange = readonly [number, number | null]\n\n/**\n * Calculates the period start and end time.\n */\nexport function calculatePeriodTimeRange(period: PeriodType): PeriodRange {\n return [calculatePeriodStart(period), calculatePeriodEnd(period)]\n}\n\n/**\n * Calculates the start time of the given period.\n *\n * In a static presentation, the first period SHALL start at the zero point of the MPD timeline (with a\n * Period@start value of 0 seconds).\n */\nexport function calculatePeriodStart(period: PeriodType): number {\n return period.start ?? 0\n}\n\n/**\n * In a static presentation, the last period SHALL have a Period@duration.\n *\n * In a dynamic presentation, the first period SHALL start at or after the zero point of the MPD timeline (with a\n * Period@start value of 0 seconds or greater).\n *\n * In a dynamic presentation, the last period MAY have a Period@duration, in which case it has a fixed duration. If\n * without Period@duration, the last period in a dynamic presentation has an unlimited duration (that may later be\n * shortened by an MPD update).\n */\nexport function calculatePeriodEnd(period: PeriodType): number | null {\n if (period.start != null && period.duration != null)\n return period.start + period.duration\n\n const mpd = period.parent\n const periodIndex = mpd.Period.indexOf(period)\n if (periodIndex < mpd.Period.length - 1)\n return calculatePeriodStart(mpd.Period[periodIndex + 1])\n else return mpd.mediaPresentationDuration ?? null\n}\n\n/**\n * Converts a sample time to an MPD-relative time.\n *\n * The samples within a representation exist on a linear sample timeline defined by the encoder. This function maps\n * those sample times onto the MPD timeline.\n *\n * https://dashif-documents.azurewebsites.net/Guidelines-TimingModel/master/Guidelines-TimingModel.html\n *\n * @param sampleTime The sample start time, in timescale units, relative to the media.\n * @param periodStart The presentation start time of the period, relative to the MPD timeline.\n * @param presentationTimeOffset Specifies a presentation time offset in the media timeline relative to the start\n * of the Period, in timescale units, used to adjust the timing of media presentation.\n * @param timescale The timescale, in units per second.\n */\nexport function sampleToMpdTime(\n sampleTime: number,\n periodStart: number,\n presentationTimeOffset: number,\n timescale: number\n): number {\n return periodStart + (sampleTime - presentationTimeOffset) / timescale\n}\n\n/**\n * Gets the period spanning the given presentation time.\n */\nexport function getPeriodAtTime(\n manifest: DashManifest,\n time: number\n): PeriodType | null {\n const index =\n sortedInsertionIndex(manifest.MPD.Period, time, (time, period) => {\n return time - calculatePeriodStart(period)\n }) - 1\n if (index < 0) return null\n const period = manifest.MPD.Period[index]\n const periodEnd = calculatePeriodEnd(period)\n return periodEnd != null && time >= periodEnd ? null : period\n}\n\n/**\n * Flattens representations across all adaptation sets for the given Period.\n */\nexport function flattenRepresentations(\n period: PeriodType\n): RepresentationType[] {\n const out: RepresentationType[] = []\n period.AdaptationSet?.forEach((adaptationSet) => {\n adaptationSet.Representation?.forEach((representation) => {\n out.push(representation)\n })\n })\n return out\n}\n\n/**\n * Calculates the manifest duration, either from the mediaPresentationDuration or the last period end time.\n * Returns `Infinity` for live (dynamic) presentations.\n * Throws if duration cannot be determined.\n */\nexport function calculateDuration(manifest: DashManifest): number {\n if (manifest.MPD.type === 'dynamic') return Infinity\n const mpdDuration = manifest.MPD.mediaPresentationDuration\n if (mpdDuration != null) return mpdDuration\n const lastPeriod = last(manifest.MPD.Period)\n if (!lastPeriod) {\n throw new Error('Unable to determine manifest duration: no periods')\n }\n const end = calculatePeriodEnd(lastPeriod)\n if (end == null) {\n throw new Error('Unable to determine manifest duration')\n }\n return end\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { BaseURLType, RepresentationType } from '@amazon/vinyl-mpd-parser'\nimport { getRepresentationAncestry } from './mpd'\nimport type { Uri } from '@amazon/vinyl-xml'\nimport type { Maybe } from '@amazon/vinyl-util'\nimport {\n ErrorOrigin,\n IllegalArgumentError,\n resolveUrl,\n substituteIdentifiers,\n ValidationError,\n} from '@amazon/vinyl-util'\n\n/**\n * Selects a base URL alternate.\n */\nexport interface BaseUrlSelector {\n /**\n * Given a list of Dash base URLs, chooses which one will be used.\n *\n * @param baseUrls A list of Dash base URL objects for a single scope.\n * Guaranteed to not be empty.\n */\n selectBaseUrl(baseUrls: readonly BaseURLType[]): BaseURLType\n}\n\nexport const pickFirstBaseUrlSelector: BaseUrlSelector = {\n selectBaseUrl(baseUrls: readonly BaseURLType[]): BaseURLType {\n return baseUrls[0]\n },\n}\n\nexport interface DashUriResolveDeps {\n /**\n * Selects the BaseURL from provided alternates.\n */\n readonly baseUrlSelector: BaseUrlSelector\n}\n\nexport interface ResolvedDashUri {\n /**\n * The absolute URL.\n */\n readonly url: string\n\n /**\n * The service location.\n * @see BaseURL.serviceLocation\n */\n readonly serviceLocation: string | null\n}\n\nexport interface DashUriResolveOptions {\n /**\n * The URI to resolve.\n */\n readonly uri?: Maybe<Uri>\n\n /**\n * The representation to use as the scope for BaseURL resolution.\n */\n readonly representation: RepresentationType\n\n /**\n * The resource location of the manifest.\n */\n readonly baseUrl: string\n}\n\n/**\n * Resolves the base URL. Walks down the ancestry, concatenating BaseURL paths according to\n * MPEG-DASH ISO/IEC 23009-1 standard, section 5.6.4.\n *\n * The BaseURL elements are used to define the base URL against which relative URLs specified in the manifest are\n * resolved. This can occur at multiple levels within the manifest (e.g., at the Period, Adaptation Set, or\n * Representation level).\n * Relative URLs are resolved according to standard URL resolution rules, as defined by RFC 3986. This involves\n * resolving the relative URL against the effective base URL, which could be the URL of the manifest itself or\n * a <BaseURL> specified at a higher level in the manifest hierarchy.\n *\n * Manifest URL as Base: If no <BaseURL> is specified, the URL from which the DASH manifest (MPD file) was\n * retrieved acts as the base URL for resolving any relative URLs.\n *\n * https://standards.iso.org/ittf/PubliclyAvailableStandards/index.html\n *\n * Note: URL resolution is not a simple concatenation, the `URL` class is used to resolve relative URLs per RFC\n * 3986:2005.\n *\n * @return Returns a resolved BaseURL object with calculated values according to inheritance rules.\n */\nexport function resolveDashUri(\n deps: DashUriResolveDeps,\n options: DashUriResolveOptions\n): ResolvedDashUri {\n const { representation, baseUrl, uri } = options\n const baseUrlSelector = deps.baseUrlSelector\n\n const scopeChain = getRepresentationAncestry(representation)\n\n let resolved = baseUrl\n let serviceLocation: string | null = null\n scopeChain.forEach((scope) => {\n if (scope.BaseURL && scope.BaseURL.length) {\n const selectedBaseUrl = baseUrlSelector.selectBaseUrl(scope.BaseURL)\n resolved = resolveUrl(selectedBaseUrl._content, resolved)\n if (selectedBaseUrl.serviceLocation)\n serviceLocation = selectedBaseUrl.serviceLocation\n }\n })\n if (uri != null) {\n resolved = resolveUrl(uri, resolved)\n } else if (resolved === baseUrl) {\n throw new ValidationError(\n 'media missing URI or BaseURL',\n ErrorOrigin.MEDIA\n )\n }\n return { url: resolved, serviceLocation }\n}\n\nexport interface SegmentTemplateUriOptions {\n /**\n * The sequence number of the segment. Will replace `$Number$` in url templates.\n */\n readonly segmentNumber?: Maybe<number>\n\n /**\n * The sample time of the segment. Will replace `$Time$` in url templates.\n */\n readonly sampleTime?: Maybe<number>\n\n /**\n * The representation, will use the id and bandwidth for replacement tokens.\n */\n readonly representation: RepresentationType\n}\n\n/**\n * Supported segment template tokens\n *\n * Does not currently support SubNumber.\n */\ninterface SegmentTemplateTokens {\n /**\n * This placeholder is replaced by the ID of the representation.\n */\n readonly RepresentationID: string\n\n /**\n * This placeholder is replaced by the sequence number of the segment.\n */\n readonly Number: number\n\n /**\n * This placeholder is replaced by the calculated sample time of the segment.\n */\n readonly Time: number\n\n /**\n * Replaced by the bandwidth attribute of the representation.\n */\n readonly Bandwidth: number\n}\n\n/**\n * Creates a segment url using segment template tokens, as defined in 5.3.9.4.4.\n */\nexport function segmentTemplateUrl(\n uri: Uri,\n options: SegmentTemplateUriOptions\n): Uri {\n try {\n return substituteIdentifiers(uri, {\n Bandwidth: options.representation.bandwidth,\n Number: options.segmentNumber ?? 0,\n RepresentationID: options.representation.id,\n Time: options.sampleTime ?? 0,\n } as const satisfies SegmentTemplateTokens)\n } catch (error) {\n if (error instanceof IllegalArgumentError) {\n // An IllegalArgumentError here indicates that a template URL provided was unsupported.\n throw new ValidationError(error.message, ErrorOrigin.MEDIA)\n } else {\n throw error\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { DashManifestData } from './DashManifestProvider'\nimport type {\n AdaptationSetType,\n DashManifest,\n RepresentationType,\n} from '@amazon/vinyl-mpd-parser'\nimport { type Comparator, compareBy } from '@amazon/vinyl-util'\nimport {\n sortDashAdaptationSets,\n sortDashRepresentations,\n} from './manifestTransformUtils'\n\nexport interface DashManifestTransformerDeps {\n readonly manifestController: ObservableValue<Promise<DashManifestData>>\n}\n\n/**\n * The default dash manifest transformer sorts adaptation sets and representations.\n * Quality filtering is handled by the media timeline transformer.\n */\nexport function createDefaultDashManifestTransformer(\n deps: DashManifestTransformerDeps\n): ObservableValue<Promise<DashManifestData>> {\n return deps.manifestController.map(async (manifestAndPath) => {\n const { manifest, baseUrl } = await manifestAndPath\n let m: DashManifest = sortDashAdaptationSets(\n createDefaultAdaptationSetComparator(),\n manifest\n )\n m = sortDashRepresentations(createDefaultRepresentationComparator(), m)\n return { baseUrl, manifest: m }\n })\n}\n\n/**\n * The default adaptation set comparator orders by descending selectionPriority.\n */\nexport function createDefaultAdaptationSetComparator(): Comparator<AdaptationSetType> {\n return compareBy((adaptationSet) => -adaptationSet.selectionPriority)\n}\n\n/**\n * The default representation comparator orders by ascending quality ranking and descending bandwidth.\n */\nexport function createDefaultRepresentationComparator(): Comparator<RepresentationType> {\n return compareBy(\n (representation) => representation.qualityRanking,\n (representation) => -representation.bandwidth\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AdaptationSetType,\n DashManifest,\n RepresentationType,\n} from '@amazon/vinyl-mpd-parser'\nimport type { DashManifestData } from './DashManifestProvider'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport {\n clone,\n type Comparator,\n type FilterPredicate,\n type MaybePromise,\n} from '@amazon/vinyl-util'\n\n/**\n * Returns true if the given Dash manifest has unfiltered representations in every Period.\n */\nexport function manifestIsPlayable(manifest: DashManifest): boolean {\n return manifest.MPD.Period.every((period) =>\n period.AdaptationSet?.some(\n (adaptationSet) => adaptationSet.Representation?.length\n )\n )\n}\n\n/**\n * Filters dash representations using a synchronous predicate.\n */\nexport function filterDashRepresentations(\n filter: FilterPredicate<RepresentationType>,\n throwError: () => never,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n if (period.AdaptationSet) {\n for (const adaptationSet of period.AdaptationSet) {\n if (adaptationSet.Representation) {\n adaptationSet.Representation =\n adaptationSet.Representation.filter(filter)\n }\n }\n }\n }\n\n if (!manifestIsPlayable(result)) {\n throwError()\n }\n\n return result\n}\n\n/**\n * Filters dash adaptation sets using a synchronous predicate.\n */\nexport function filterDashAdaptationSets(\n filter: FilterPredicate<AdaptationSetType>,\n throwError: () => never,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n if (period.AdaptationSet) {\n period.AdaptationSet = period.AdaptationSet.filter(filter)\n }\n }\n\n if (!manifestIsPlayable(result)) {\n throwError()\n }\n\n return result\n}\n\n/**\n * Sorts dash adaptation sets using a comparator.\n */\nexport function sortDashAdaptationSets(\n comparator: Comparator<AdaptationSetType>,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n period.AdaptationSet?.sort(comparator)\n }\n\n return result\n}\n\n/**\n * Sorts dash representations using a comparator.\n */\nexport function sortDashRepresentations(\n comparator: Comparator<RepresentationType>,\n manifest: DashManifest\n): DashManifest {\n const result = clone(manifest)\n\n for (const period of result.MPD.Period) {\n if (period.AdaptationSet) {\n for (const adaptationSet of period.AdaptationSet) {\n if (adaptationSet.Representation) {\n adaptationSet.Representation.sort(comparator)\n }\n }\n }\n }\n\n return result\n}\n\n/**\n * Maps a manifest transformation function over a DashManifestData observable.\n * Handles the boilerplate of extracting manifest/baseUrl and reconstructing the result.\n */\nexport function mapManifestTransform(\n manifestController: ObservableValue<Promise<DashManifestData>>,\n transformManifest: (manifest: DashManifest) => MaybePromise<DashManifest>\n): ObservableValue<Promise<DashManifestData>> {\n return manifestController.map(async (manifestAndPath) => {\n const { manifest, baseUrl } = await manifestAndPath\n return {\n baseUrl,\n manifest: await transformManifest(manifest),\n }\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n ErrorOrigin,\n type ExtractValues,\n getOrSet,\n getOrSetProp,\n memoize,\n type MutableDeep,\n sortedInsertionIndex,\n ValidationError,\n} from '@amazon/vinyl-util'\nimport {\n type AdaptationSetType,\n type ContentProtection,\n ContentProtectionScheme,\n type DescriptorType,\n type PeriodType,\n type RepresentationBaseType,\n type RepresentationType,\n} from '@amazon/vinyl-mpd-parser'\nimport type {\n ContentType,\n DrmProtection,\n MediaQualityMetadata,\n} from '../../streaming/MediaQualityMetadata'\nimport { type DrmKeySystemResolver } from '../../drm/DrmKeySystemResolver'\nimport { getRepresentationMimeInfo } from './util/mimeType'\nimport type { DescriptorRecord } from '../../streaming/DescriptorRecord'\nimport type { DrmInitDataType } from '../../streaming/DrmInitDataType'\nimport {\n type CencEncryptionScheme,\n parseCencEncryptionScheme,\n} from '../../drm/CencEncryptionScheme'\n\n/**\n * DASH supplemental property scheme URI for adaptation set switching.\n * @see https://dashif.org/docs/DASH-IF-IOP-v4.3.pdf Section 3.8\n */\nexport const ADAPTATION_SET_SWITCHING_SCHEME =\n 'urn:mpeg:dash:adaptation-set-switching:2016'\n\n/**\n * Creates abstract MediaQualityMetadata from a Dash Representation.\n */\nexport type DashMediaQualityMetadataResolver = (\n representation: RepresentationType\n) => MediaQualityMetadata\n\n/**\n * Returns a dash metadata resolver that calculates media encoding metadata from the representation.\n * The most recently used representations will return cached results.\n */\nexport function createDefaultDashMediaQualityMetadataResolver(\n deps: DashMediaQualityMetadataResolverDeps\n): DashMediaQualityMetadataResolver {\n return memoize(\n (representation) =>\n createMediaQualityMetadataFromDashRepresentation(\n representation,\n deps\n ),\n (representation) => representation,\n 30\n )\n}\n\nexport interface DashMediaQualityMetadataResolverDeps {\n readonly drmKeySystemResolver: DrmKeySystemResolver\n}\n\nexport function createMediaQualityMetadataFromDashRepresentation(\n representation: RepresentationType,\n deps: DashMediaQualityMetadataResolverDeps\n): MediaQualityMetadata {\n const { contentType, mimeType } = getRepresentationMimeInfo(representation)\n if (!contentType || !mimeType)\n throw new ValidationError(\n 'mimeType cannot be inferred',\n ErrorOrigin.MEDIA\n )\n const adaptationSet = representation.parent\n const period = adaptationSet.parent\n const mpd = period.parent\n\n const periodId = period.id ?? `$${mpd.Period.indexOf(period)}`\n const adaptationSetId =\n adaptationSet.id ?? `$${period.AdaptationSet!.indexOf(adaptationSet)}`\n const qualityId = `${periodId}_${adaptationSetId}_${representation.id}`\n // Representations within the same adaptation set where bitstreamSwitching is true can be changed without\n // reinitializing the decoder.\n let decoderId = `${periodId}_${adaptationSetId}`\n const bitstreamSwitching =\n adaptationSet.bitstreamSwitching ?? period.bitstreamSwitching\n if (!bitstreamSwitching) decoderId += `_${representation.id}`\n\n // Resolve the adaptation set switching group. Adaptation sets that declare\n // urn:mpeg:dash:adaptation-set-switching:2016 with each other's IDs form a switching group,\n // meaning their representations are permitted to switch between each other.\n const groupId = `${periodId}_${adaptationSetId}`\n const switchingGroupIds = resolveAdaptationSetSwitchingGroupIds(\n adaptationSet,\n periodId,\n adaptationSetId\n )\n\n // Pick a representation base property which may be inherited from the adaptation set.\n function pick<K extends keyof RepresentationBaseType>(\n key: K\n ): NonNullable<RepresentationBaseType[K]> | null {\n return representation[key] ?? adaptationSet[key] ?? null\n }\n\n // Combines the descriptors for the given key into a map of scheme URI to Descriptor lists.\n type DescriptorProps = keyof ExtractValues<\n Required<RepresentationBaseType>,\n readonly DescriptorType[]\n >\n function mergeDescriptors(key: DescriptorProps): DescriptorRecord {\n const arr1 = adaptationSet[key] ?? []\n const arr2 = representation[key] ?? []\n return mapDescriptors([...arr1, ...arr2])\n }\n\n const contentProtections = [\n ...(adaptationSet.ContentProtection ?? []),\n ...(representation.ContentProtection ?? []),\n ]\n\n // Get the encryption scheme from the parsed CENC ContentProtection value.\n let initDataType: DrmInitDataType | null = null\n let encryptionScheme: CencEncryptionScheme | null = null\n for (let i = contentProtections.length - 1; i >= 0; i--) {\n const cP = contentProtections[i]\n if (cP.schemeIdUri === ContentProtectionScheme.CENC) {\n initDataType = 'cenc'\n encryptionScheme =\n parseCencEncryptionScheme(cP.value)?.scheme ?? null\n break\n }\n }\n\n return {\n qualityId,\n decoderId,\n groupId,\n switchingGroupIds,\n mimeType,\n contentType,\n codecs: pick('codecs'),\n bandwidth: representation.bandwidth,\n bandwidthTotal: estimatePeakBandwidth(representation, contentType),\n audioSamplingRate: pick('audioSamplingRate'),\n frameRate: pick('frameRate'),\n width: pick('width'),\n height: pick('height'),\n lang: adaptationSet.lang ?? null,\n contentProtections: contentProtections.flatMap((cP) =>\n contentProtectionToMetadata(cP, deps)\n ),\n encryptionScheme,\n initDataType,\n supplementalProperties: mergeDescriptors('SupplementalProperty'),\n }\n}\n\n/**\n * Estimates the total bandwidth a representation would use when paired with\n * proportionally matched qualities from sibling content types.\n *\n * For each sibling content type, the representation's relative position within its own\n * content type's sorted bandwidth list is mapped to the corresponding position in the\n * sibling's list. This produces realistic pairings \u2014 e.g. with video [v1,v2,v3,v4] and\n * audio [a1,a2], v1 pairs with a1, v2 with a1, v3 with a2, v4 with a2.\n */\nexport function estimatePeakBandwidth(\n representation: RepresentationType,\n contentType: ContentType\n): number {\n const sortedByType = getPeriodSortedBandwidths(representation.parent.parent)\n const own = sortedByType.get(contentType)\n if (!own || own.length === 0) return representation.bandwidth\n // Find the closest match in the descending-sorted array. indexOf would return -1\n // when the representation's bandwidth was collapsed by the 10% dedup threshold.\n const ownIndex = Math.max(\n 0,\n sortedInsertionIndex(own, representation.bandwidth, (a, b) => b - a) - 1\n )\n const position = own.length <= 1 ? 0 : ownIndex / (own.length - 1)\n let total = representation.bandwidth\n for (const [ct, bandwidths] of sortedByType) {\n if (ct === contentType) continue\n const peerIndex = Math.min(\n Math.round(position * (bandwidths.length - 1)),\n bandwidths.length - 1\n )\n total += bandwidths[peerIndex]\n }\n return total\n}\n\n/**\n * Returns sorted (descending) bandwidth arrays per content type for a period.\n * Bandwidths within 10% of an existing entry are collapsed to reduce noise\n * from near-duplicate quality tiers.\n * Cached by period reference.\n */\nexport const getPeriodSortedBandwidths = /* @__PURE__ */ memoize(\n (period: PeriodType): ReadonlyMap<ContentType, readonly number[]> => {\n const byType = new Map<ContentType, number[]>()\n for (const as of period.AdaptationSet ?? []) {\n for (const rep of as.Representation ?? []) {\n const contentType = getRepresentationMimeInfo(rep).contentType\n if (!contentType) continue\n const arr = getOrSet(byType, contentType, () => [])\n if (\n !arr.some(\n (existing) =>\n Math.abs(existing - rep.bandwidth) / existing < 0.1\n )\n ) {\n const index = sortedInsertionIndex(\n arr,\n rep.bandwidth,\n (a, b) => b - a\n )\n arr.splice(index, 0, rep.bandwidth)\n }\n }\n }\n return byType\n },\n (period) => period,\n 5\n)\n\n/**\n * Converts a Dash ContentProtection element to a list of DrmProtection metadata.\n */\nexport function contentProtectionToMetadata(\n contentProtection: ContentProtection,\n deps: DashMediaQualityMetadataResolverDeps\n): readonly DrmProtection[] {\n const keySystems = deps.drmKeySystemResolver(contentProtection.schemeIdUri)\n return keySystems.map((keySystem) => {\n return {\n keySystem,\n pssh: contentProtection.pssh?._content ?? null,\n pro: contentProtection.pro?._content ?? null,\n }\n })\n}\n\n/**\n * Creates a DescriptorRecord from the Dash list of DescriptorType objects.\n * @param descriptors\n */\nfunction mapDescriptors(\n descriptors: readonly DescriptorType[]\n): DescriptorRecord {\n const out: MutableDeep<DescriptorRecord> = {}\n for (const descriptor of descriptors) {\n const arr = getOrSetProp(out, descriptor.schemeIdUri, () => [])!\n arr.push({\n id: descriptor.id ?? null,\n value: descriptor.value ?? null,\n })\n }\n return out\n}\n\n/**\n * Resolves the group IDs that the given adaptation set is permitted to switch to.\n *\n * Per DASH spec, adaptation sets declare `urn:mpeg:dash:adaptation-set-switching:2016` with a\n * comma-separated list of other adaptation set IDs they can switch to.\n *\n * Always includes the adaptation set's own groupId. If no switching property is present,\n * returns only the adaptation set's own groupId.\n */\nfunction resolveAdaptationSetSwitchingGroupIds(\n adaptationSet: AdaptationSetType,\n periodId: string,\n adaptationSetId: string | number\n): readonly string[] | null {\n const selfGroupId = `${periodId}_${adaptationSetId}`\n const switchingProp = adaptationSet.SupplementalProperty?.find(\n (p) => p.schemeIdUri === ADAPTATION_SET_SWITCHING_SCHEME\n )\n if (!switchingProp) return [selfGroupId]\n\n const value = switchingProp.value?.trim()\n if (!value) return [selfGroupId]\n\n const targetIds = value.split(',').map((s) => s.trim())\n return [selfGroupId, ...targetIds.map((id) => `${periodId}_${id}`)]\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ContentType } from '../../streaming/MediaQualityMetadata'\n\n/**\n * RFC 6381 codec prefixes for video content.\n */\nconst VIDEO_CODEC_PREFIXES = [\n 'avc1',\n 'avc3',\n 'hvc1',\n 'hev1',\n 'vp09',\n 'av01',\n 'dvh1',\n 'dvhe',\n] as const\n\n/**\n * RFC 6381 codec prefixes for audio content.\n */\nconst AUDIO_CODEC_PREFIXES = ['mp4a', 'ac-3', 'ec-3', 'opus', 'flac'] as const\n\n/**\n * RFC 6381 codec prefixes for text/subtitle content.\n */\nconst TEXT_CODEC_PREFIXES = ['stpp', 'wvtt'] as const\n\n/**\n * Returns the ContentType for a single RFC 6381 codec string, or null if\n * unrecognized.\n */\nexport function codecToContentType(codec: string): ContentType | null {\n const lower = codec.trim().toLowerCase()\n for (const p of VIDEO_CODEC_PREFIXES) {\n if (lower.startsWith(p)) return 'video'\n }\n for (const p of AUDIO_CODEC_PREFIXES) {\n if (lower.startsWith(p)) return 'audio'\n }\n for (const p of TEXT_CODEC_PREFIXES) {\n if (lower.startsWith(p)) return 'text'\n }\n return null\n}\n\n/**\n * Splits a comma-separated CODECS attribute value and returns the set of\n * ContentType values present.\n */\nexport function codecsToContentTypes(codecs: string): Set<ContentType> {\n const types = new Set<ContentType>()\n for (const codec of codecs.split(',')) {\n const type = codecToContentType(codec)\n if (type) types.add(type)\n }\n return types\n}\n\n/**\n * Returns the full MIME type string for a content type, optionally with codecs.\n */\nexport function contentTypeToMimeType(\n contentType: ContentType,\n codecs: string | null\n): string {\n const base = contentType === 'video' ? 'video/mp4' : 'audio/mp4'\n return codecs ? `${base}; codecs=\"${codecs}\"` : base\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { RepresentationType } from '@amazon/vinyl-mpd-parser'\nimport type { ContentType } from '../../../streaming/MediaQualityMetadata'\nimport { codecToContentType } from '../../mse/codec'\n\nexport interface RepresentationMimeInfo {\n readonly mimeType: string | null\n readonly contentType: ContentType | null\n}\n\n/**\n * Returns the full mime type with codecs and the inferred content type from the\n * provided representation.\n */\nexport function getRepresentationMimeInfo(\n representation: RepresentationType\n): RepresentationMimeInfo {\n const adaptationSet = representation.parent\n let mimeType = representation.mimeType ?? adaptationSet.mimeType\n const codecs = representation.codecs ?? adaptationSet.codecs\n if (!mimeType) {\n const contentType =\n (adaptationSet.contentType as ContentType | undefined) ??\n (codecs ? codecToContentType(codecs.split(',')[0]) : null)\n switch (contentType) {\n case 'audio':\n mimeType = 'audio/mp4'\n break\n case 'video':\n mimeType = 'video/mp4'\n break\n default:\n return { mimeType: null, contentType: null }\n }\n const fullMimeType = codecs\n ? `${mimeType}; codecs=\"${codecs}\"`\n : mimeType\n return { mimeType: fullMimeType, contentType }\n }\n const fullMimeType = codecs ? `${mimeType}; codecs=\"${codecs}\"` : mimeType\n let contentType: ContentType | null =\n (adaptationSet.contentType as ContentType | undefined) ?? null\n if (!contentType) {\n if (mimeType.startsWith('audio/')) contentType = 'audio'\n else if (mimeType.startsWith('video/')) contentType = 'video'\n else if (\n mimeType.startsWith('text/') ||\n mimeType === 'application/json' ||\n mimeType === 'application/xml'\n )\n contentType = 'text'\n }\n return { mimeType: fullMimeType, contentType }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type Maybe,\n parseIntSafe,\n type ReadonlyRecord,\n} from '@amazon/vinyl-util'\n\n/**\n * https://www.w3.org/TR/encrypted-media-2/#dom-mediakeysystemmediacapability-encryptionscheme\n */\nexport type CencEncryptionScheme =\n /**\n * AES-CTR mode full sample and video NAL subsample encryption.\n */\n | 'cenc'\n\n /**\n * AES-CBC mode partial video NAL pattern encryption. For video, the spec allows various encryption patterns.\n */\n | 'cbcs'\n\n /**\n * The same as \"cbcs\" mode, but with a specific encrypt:skip pattern of 1:9 for video.\n */\n | 'cbcs-1-9'\n | string\n\nexport interface CencEncryptionSchemeAndVersion {\n readonly scheme: CencEncryptionScheme\n readonly version: number | null\n}\n\nconst encryptionSchemeRegex = /([a-z]{4})(?::([\\da-f]{1,8}))?/\n\nconst protectionSchemeCodes: ReadonlyRecord<\n string,\n CencEncryptionScheme | undefined\n> = {\n ['cbcs']: 'cbcs',\n ['cenc']: 'cenc',\n}\n\n/**\n * 5.8.5.2.2 The MP4 Protection Scheme\n *\n * For Representations based on ISO/IEC 14496-12, the following URI is defined to indicate protection\n * schemes identified by the Scheme Type within the Scheme Type Box of the Protection Scheme\n * Information Box of the file:\n * urn:mpeg:dash:mp4protection:2011\n * In this scheme, the `value` attribute shall present and shall be the 4CC contained in the Scheme Type\n * Box, suitably percent-encoded according to IETF RFC 8141, and may include the version number. The\n * 4CC and the version number, if present, shall be separated by a \":\". The version number shall be encoded\n * as up to 8 hexadecimal digits, where the leading '0's may be omitted.\n *\n * @param value\n */\nexport function parseCencEncryptionScheme(\n value: Maybe<string>\n): CencEncryptionSchemeAndVersion | null {\n if (!value) return null\n const match = encryptionSchemeRegex.exec(value)\n if (!match) return null\n const version = parseIntSafe(match[2], 16)\n const scheme = protectionSchemeCodes[match[1]]\n if (!scheme) return null\n return {\n scheme,\n version,\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n closeTo,\n createDisposer,\n type Disposable,\n DomEventHost,\n ErrorLevel,\n ErrorOrigin,\n EventHostImpl,\n isSilentError,\n type Json,\n logDebug,\n type LogTarget,\n type ReadonlyEventHost,\n type ReadonlySet,\n ReportableError,\n toJson,\n toLowerCase,\n} from '@amazon/vinyl-util'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { ContentTypesValue } from '../ContentTypesValue'\nimport type { BasicErrorEvent } from '../../event/BasicErrorEvent'\nimport type { ContentType } from '../MediaQualityMetadata'\nimport type { MediaTimeline } from '../MediaTimeline'\nimport { LIVE_DURATION } from '../../playback/PlaybackController'\nimport { nextSourceBufferIdle } from '../../util/media/sourceBuffer'\n\n/**\n * Chrome 52 has decoding errors when duration is set to the mediaPresentationDuration.\n * Adds a slight padding as a workaround.\n * @private\n */\nexport const DURATION_PADDING = 0.1\n\nexport interface SourceBufferRef extends Disposable {\n /**\n * The source buffer.\n */\n readonly value: SourceBuffer\n}\n\nexport interface MediaSourceControllerEventMap {\n /**\n * The media source has entered a 'closed' state.\n */\n readonly sourceClose: AnyRecord\n\n /**\n * The media source has entered an 'ended' state.\n */\n readonly sourceEnded: AnyRecord\n\n /**\n * The media source has entered an 'open' state.\n */\n readonly sourceOpen: AnyRecord\n\n /**\n * All source buffers have been created, the media source duration has been set, and data\n * may be appended.\n */\n readonly readyToAppend: AnyRecord\n\n /**\n * An error has occurred.\n */\n readonly error: BasicErrorEvent\n}\n\nexport interface ReadonlyMediaSourceController extends ReadonlyEventHost<MediaSourceControllerEventMap> {\n /**\n * Returns the parent media source ready state.\n */\n readonly readyState: ReadyState\n\n /**\n * True if all source buffers have been created and data may be appended.\n */\n readonly readyToAppend: boolean\n}\n\nexport interface MediaSourceController extends ReadonlyMediaSourceController {\n /**\n * Constructs a new SourceBuffer with the given content type and mime type.\n */\n createSourceBuffer(\n contentType: ContentType,\n mimeType: string\n ): SourceBufferRef\n\n /**\n * Signals the end of the stream.\n * @param error A string representing an error to throw when the end of the stream is reached.\n */\n endOfStream(error?: EndOfStreamError): void\n\n /**\n * Creates an Object URL to use as the source for this stream.\n */\n createUrl(): string\n}\n\nexport interface MediaSourceControllerImplDeps {\n /**\n * Creates a new media source.\n */\n readonly mediaSourceFactory: () => MediaSource\n\n /**\n * Provides the streams that must be created before appending.\n */\n readonly contentTypesValue: ContentTypesValue\n\n /**\n * The media timeline used to determine duration.\n */\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n}\n\nexport class MediaSourceControllerImpl\n extends EventHostImpl<MediaSourceControllerEventMap>\n implements MediaSourceController, LogTarget\n{\n get [Symbol.toStringTag](): string {\n return 'MediaSourceControllerImpl'\n }\n\n private readonly sourceBuffers = /* @__PURE__ */ new Set<SourceBuffer>()\n\n private readonly mediaSource: MediaSource\n private readonly disposer = /* @__PURE__ */ createDisposer()\n private contentTypes: ReadonlySet<ContentType> | null = null\n private durationSet = false\n\n /**\n * Token for the in-flight duration update; used to discard stale results when\n * the timeline changes or the source closes mid-fetch.\n */\n private durationToken = 0\n\n constructor(private readonly deps: MediaSourceControllerImplDeps) {\n super()\n this.mediaSource = deps.mediaSourceFactory()\n this.initializeEvents()\n this.disposer.add(\n deps.contentTypesValue.onData((value) => {\n this.contentTypes = null\n value\n .then((contentTypes) => {\n this.contentTypes = contentTypes\n this.checkReady()\n })\n .catch(this.errorHandler)\n })\n )\n }\n\n private get sourceBufferCount(): number {\n return this.sourceBuffers.size\n }\n\n private readonly errorHandler = (error: any) => {\n if (isSilentError(error)) return\n this.dispatch('error', {\n target: this,\n error,\n })\n }\n\n /**\n * Subscription to mediaTimelineTransformed; only attached while the media source is open\n * so the timeline pipeline isn't forced to evaluate before the source has opened.\n */\n private timelineSub: (() => void) | null = null\n\n private initializeEvents(): void {\n const domEvents = new DomEventHost<MediaSourceEventMap>(\n this.mediaSource\n )\n for (const key of [\n 'sourceClose',\n 'sourceOpen',\n 'sourceEnded',\n ] as const) {\n domEvents.on(toLowerCase(key), () => this.dispatch(key, {}))\n }\n this.timelineSub = this.deps.mediaTimelineTransformed.onData(() => {\n this.refreshDuration().catch(this.errorHandler)\n })\n this.on('sourceOpen', () => {\n this.refreshDuration().catch(this.errorHandler)\n })\n this.on('sourceClose', () => {\n this.durationSet = false\n ++this.durationToken\n })\n }\n\n /**\n * Sets the duration on the media source from the current media timeline.\n * Live streams use LIVE_DURATION since not all browsers support +Infinity duration.\n *\n * MSE throws InvalidStateError if duration is set while any source buffer is updating,\n * so we wait for all tracked source buffers to be idle first.\n */\n private async refreshDuration(): Promise<void> {\n const timelinePromise = this.deps.mediaTimelineTransformed.value\n const token = ++this.durationToken\n const timeline = await timelinePromise\n const duration = await timeline.getDuration()\n const value =\n duration === Infinity ? LIVE_DURATION : duration + DURATION_PADDING\n await Promise.all(Array.from(this.sourceBuffers, nextSourceBufferIdle))\n if (\n token !== this.durationToken ||\n this.mediaSource.readyState !== 'open' ||\n closeTo(this.mediaSource.duration, value, 0.1)\n )\n return\n logDebug(this, `setting duration: ${value}`)\n this.mediaSource.duration = value\n this.durationSet = true\n this.checkReady()\n }\n\n get readyState(): ReadyState {\n return this.mediaSource.readyState\n }\n\n createSourceBuffer(\n contentType: ContentType,\n mimeType: string\n ): SourceBufferRef {\n const mediaSource = this.mediaSource\n logDebug(\n this,\n 'create source buffer',\n contentType,\n mimeType,\n mediaSource.readyState,\n 'sourceBufferCount:',\n this.sourceBufferCount\n )\n let sourceBuffer: SourceBuffer\n try {\n sourceBuffer = mediaSource.addSourceBuffer(mimeType)\n } catch (error: any) {\n throw new MediaSourceError('error creating source buffer', error)\n }\n sourceBuffer.mode = 'sequence'\n this.sourceBuffers.add(sourceBuffer)\n this.checkReady()\n\n const dispose = () => {\n logDebug(\n this,\n 'removing source buffer from media source',\n mediaSource.readyState\n )\n if (mediaSource.readyState !== 'closed') {\n mediaSource.removeSourceBuffer(sourceBuffer)\n }\n this.sourceBuffers.delete(sourceBuffer)\n }\n\n return {\n value: sourceBuffer,\n dispose,\n }\n }\n\n /**\n * Emits a 'readyToAppend' event if all source buffers have been created and the duration\n * has been applied to the media source.\n */\n private readonly checkReady = () => {\n if (this.readyToAppend) this.dispatch('readyToAppend', {})\n }\n\n endOfStream(error?: EndOfStreamError) {\n logDebug(this, 'endOfStream, error:', error)\n this.mediaSource.endOfStream(error)\n }\n\n createUrl(): string {\n return URL.createObjectURL(this.mediaSource)\n }\n\n get readyToAppend(): boolean {\n return (\n this.durationSet &&\n this.contentTypes?.size === this.sourceBufferCount\n )\n }\n\n dispose() {\n super.dispose()\n this.timelineSub?.()\n this.timelineSub = null\n this.disposer.dispose()\n }\n}\n\nexport class MediaSourceError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'MediaSourceError'\n }\n\n constructor(\n message: string,\n private readonly reason: Error\n ) {\n super(message, ErrorOrigin.INTERNAL, ErrorLevel.FATAL)\n Object.setPrototypeOf(this, MediaSourceError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n reason: toJson(this.reason),\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { promise } from '@amazon/vinyl-util'\nimport type { Maybe } from '@amazon/vinyl-util'\nimport { SourceBufferError } from '../../streaming/buffering/error/SourceBufferError'\nimport { AbortError } from '@amazon/vinyl-util'\n\n/**\n * Returns a promise that resolves when the given source buffer is next idle.\n * If the source buffer errs, the promise will be rejected with a {@link SourceBufferError}.\n *\n * @param sourceBuffer\n */\nexport function nextSourceBufferIdle(\n sourceBuffer: Maybe<SourceBuffer>\n): Promise<void> {\n if (!sourceBuffer) return Promise.resolve()\n if (!sourceBuffer.updating) return Promise.resolve()\n return promise((resolve, reject) => {\n const removeListeners = () => {\n sourceBuffer.removeEventListener('error', onErred)\n sourceBuffer.removeEventListener('abort', onAborted)\n sourceBuffer.removeEventListener('update', onEnded)\n }\n const onEnded = () => {\n removeListeners()\n resolve()\n }\n const onErred = (_event: any) => {\n removeListeners()\n reject(new SourceBufferError())\n }\n const onAborted = () => {\n removeListeners()\n reject(new AbortError())\n }\n sourceBuffer.addEventListener('error', onErred)\n sourceBuffer.addEventListener('abort', onAborted)\n sourceBuffer.addEventListener('update', onEnded)\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport { ReportableError } from '@amazon/vinyl-util'\n\n/**\n * An error emitted from the SourceBuffer.\n */\nexport class SourceBufferError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'SourceBufferError'\n }\n\n constructor(\n message = `A SourceBuffer error has occurred.`,\n origin = ErrorOrigin.MEDIA\n ) {\n super(message, origin)\n Object.setPrototypeOf(this, SourceBufferError.prototype)\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { data } from '@amazon/vinyl-observable'\nimport { createAbortSlot, createDisposer, logDebug } from '@amazon/vinyl-util'\nimport type {\n DashManifestData,\n DashManifestProvider,\n} from './DashManifestProvider'\nimport type { ManifestController } from '../../streaming/ManifestController'\n\nexport type DashManifestController = ManifestController<\n Promise<DashManifestData>\n>\n\nexport interface DashManifestControllerImplDeps {\n /**\n * Resolves the untransformed manifest.\n */\n readonly manifestProvider: DashManifestProvider\n}\n\nexport class DashManifestControllerImpl implements DashManifestController {\n get [Symbol.toStringTag](): string {\n return 'DashManifestControllerImpl'\n }\n\n get logPrefix(): string {\n return 'DashManifestControllerImpl'\n }\n\n private readonly _data = /* @__PURE__ */ data<Promise<DashManifestData>>(\n /* @__PURE__ */ Promise.reject(/* @__PURE__ */ new Error('manifest not loaded'))\n )\n private _error: Error | null = null\n private readonly abortSlot = /* @__PURE__ */ createAbortSlot()\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n constructor(readonly deps: DashManifestControllerImplDeps) {\n // Suppress unhandled rejection on the initial placeholder.\n this._data.value.catch(() => {})\n this.refresh()\n }\n\n /**\n * The most recent error from the manifest provider, or null.\n * This may be a silent error, such as an AbortError.\n */\n get error(): Error | null {\n return this._error\n }\n\n /**\n * Reloads the manifest. Aborts any in-flight request and clears any\n * previous error before starting a new fetch.\n */\n refresh() {\n logDebug(this, 'refresh')\n this.abort()\n this._error = null\n const promise = this.deps.manifestProvider(this.abortSlot.value)\n promise.catch((error: Error) => {\n this._error = error\n })\n this._data.value = promise\n }\n\n /**\n * If the manifest is in an error state, triggers a refresh.\n */\n reset() {\n logDebug(this, 'reset')\n if (this._error) {\n this.refresh()\n }\n }\n\n get value() {\n return this._data.value\n }\n\n get changeId() {\n return this._data.changeId\n }\n\n getValue() {\n return this._data.getValue()\n }\n\n onData(\n callback: (\n value: Promise<DashManifestData>,\n previous: Promise<DashManifestData> | undefined\n ) => void\n ) {\n return this._data.onData(callback)\n }\n\n map<U>(transform: (value: Promise<DashManifestData>) => U) {\n return this._data.map(transform)\n }\n\n pick<K extends keyof NonNullable<Promise<DashManifestData>>>(prop: K) {\n return this._data.pick(prop)\n }\n\n private abort() {\n this.abortSlot.abort()\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.abort()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createLogPrefix,\n createTaskQueue,\n createTimeRangesReader,\n type Disposable,\n emptyRanges,\n ErrorOrigin,\n IllegalStateError,\n logDebug,\n type LogTarget,\n nextEventAsPromise,\n type ReadonlyRanges,\n type Task,\n} from '@amazon/vinyl-util'\nimport { nextSourceBufferIdle } from '../../util/media/sourceBuffer'\nimport { SourceBufferError } from './error/SourceBufferError'\nimport type {\n MediaSourceController,\n SourceBufferRef,\n} from './MediaSourceController'\nimport type { ContentType } from '../MediaQualityMetadata'\n\n// Prevents unintentionally dropped keyframes\nexport const APPEND_WINDOW_START_OFFSET = 0.05\nexport const APPEND_WINDOW_END_OFFSET = 0.01\n\n// The number of seconds before aborting the wait for media source controller's readyToAppend event.\nexport const READY_TO_APPEND_TIMEOUT = 30\n\nexport type SourceBufferControllerFactory = () => SourceBufferController\n\nexport interface SourceBufferController extends Disposable {\n readonly buffered: ReadonlyRanges\n\n /**\n * Returns true if an operation is currently running.\n */\n isBusy(): boolean\n\n /**\n * Enqueues an operation.\n * Guaranteed to be invoked when the source buffer is not updating.\n */\n enqueue<T = void>(task: Task<T>): Promise<T>\n\n /**\n * Enqueues appending an initialization segment, reinitializing the decoder.\n */\n appendInit(data: ArrayBuffer, mimeType: string): Promise<void>\n\n /**\n * Enqueues appending a media segment.\n * An `appendInit` call must precede appending media segments.\n * A promise is returned that will resolve when the task is complete.\n */\n append(data: ArrayBuffer): Promise<void>\n\n /**\n * Sets the timestampOffset on the backing source buffer.\n */\n setTimestampOffset(timestampOffset: number): Promise<void>\n\n /**\n * Sets the append window on the backing source buffer.\n * Keyframes outside this range will be discarded.\n */\n setAppendWindow(\n appendWindowStart?: number,\n appendWindowEnd?: number\n ): Promise<void>\n\n /**\n * Removes media segments within a specific time range from the SourceBuffer.\n */\n remove(startTime: number, endTime: number): Promise<void>\n\n /**\n * Aborts any pending buffers and clears all buffered ranges.\n */\n clear(): Promise<void>\n}\n\nexport interface SourceBufferControllerImplDeps {\n /**\n * Produces the source buffer for appending.\n */\n readonly mediaSourceController: MediaSourceController\n}\n\n/**\n * The SourceBufferController manages a single source buffer. It provides queued commands for appending and clearing\n * data.\n */\nexport class SourceBufferControllerImpl\n implements LogTarget, SourceBufferController, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'SourceBufferController'\n }\n\n private sourceBufferRef: SourceBufferRef | null = null\n\n private mimeType: string | null = null\n private queue = /* @__PURE__ */ createTaskQueue()\n\n readonly logPrefix = /* @__PURE__ */ createLogPrefix(this)\n private readonly mediaSourceController: MediaSourceController\n\n constructor(\n deps: SourceBufferControllerImplDeps,\n readonly contentType: ContentType\n ) {\n logDebug(this, 'constructed, contentType:', contentType)\n this.mediaSourceController = deps.mediaSourceController\n }\n\n private get sourceBuffer(): SourceBuffer | null {\n return this.sourceBufferRef && this.sourceBufferRef.value\n }\n\n private _buffered: ReadonlyRanges | null = null\n get buffered(): ReadonlyRanges {\n if (this._buffered == null) {\n if (!this.sourceBuffer) this._buffered = emptyRanges\n else\n this._buffered = createTimeRangesReader(\n this.sourceBuffer.buffered\n )\n }\n return this._buffered\n }\n\n /**\n * Clears the cached buffered ranges. They will be recreated next access.\n */\n private clearBufferedCache = () => {\n this._buffered = null\n }\n\n isBusy(): boolean {\n return this.queue.running > 0\n }\n\n enqueue<T = void>(task: Task<T>): Promise<T> {\n return this.queue.enqueue(task)\n }\n\n async appendInit(data: ArrayBuffer, mimeType: string): Promise<void> {\n return this.queue.enqueue(async (abort) => {\n if (this.mimeType !== mimeType) {\n if (this.sourceBuffer && 'changeType' in this.sourceBuffer) {\n // There is an existing source buffer and its mime type can be changed.\n logDebug(this, 'changeType', mimeType)\n this.sourceBuffer.changeType(mimeType)\n } else {\n // There is either no existing source buffer or a new buffer must be created\n // with the new mime type.\n this.sourceBufferRef?.dispose()\n const newSourceBufferRef =\n this.mediaSourceController.createSourceBuffer(\n this.contentType,\n mimeType\n )\n // Do not append to the source buffer until all streams have been created:\n if (!this.mediaSourceController.readyToAppend)\n await nextEventAsPromise(\n this.mediaSourceController,\n 'readyToAppend',\n { timeout: READY_TO_APPEND_TIMEOUT, abort }\n ).catch((error) => {\n // The readyToAppend was aborted or timed out, dispose the source buffer\n newSourceBufferRef.dispose()\n throw error\n })\n this.sourceBufferRef = newSourceBufferRef\n }\n this.mimeType = mimeType\n }\n const sourceBuffer = this.sourceBuffer!\n logDebug(this, `appending init ${data.byteLength} bytes`)\n sourceBuffer.appendBuffer(data)\n await this.nextIdle()\n logDebug(this, 'appended init')\n })\n }\n\n async append(data: ArrayBuffer): Promise<void> {\n return this.queue.enqueue(async () => {\n logDebug(this, `appending ${data.byteLength} bytes`)\n const sourceBuffer = this.sourceBuffer\n if (!sourceBuffer)\n throw new SourceBufferError(\n 'media segment provided before init segment',\n ErrorOrigin.INTERNAL\n )\n sourceBuffer.appendBuffer(data)\n await this.nextIdle()\n logDebug(this, 'appended', this.buffered)\n })\n }\n\n setTimestampOffset(timestampOffset: number): Promise<void> {\n return this.queue.enqueue(() => {\n const sourceBuffer = this.sourceBuffer\n if (!sourceBuffer)\n throw new IllegalStateError(\n 'source buffer must be initialized before setting timestamp offset'\n )\n logDebug(this, 'timestampOffset:', timestampOffset.toFixed(4))\n sourceBuffer.timestampOffset = timestampOffset\n })\n }\n\n setAppendWindow(\n appendWindowStart: number = 0,\n appendWindowEnd: number = Number.POSITIVE_INFINITY\n ): Promise<void> {\n return this.queue.enqueue(() => {\n const sourceBuffer = this.sourceBuffer\n if (!sourceBuffer)\n throw new IllegalStateError(\n 'source buffer must be initialized before setting append window'\n )\n const finalAppendWindowStart = Math.max(\n 0,\n appendWindowStart - APPEND_WINDOW_START_OFFSET\n )\n const finalAppendWindowEnd =\n appendWindowEnd + APPEND_WINDOW_END_OFFSET\n logDebug(\n this,\n 'appendWindow:',\n finalAppendWindowStart.toFixed(4),\n finalAppendWindowEnd.toFixed(4)\n )\n\n // start may not be greater than end, even temporarily.\n // Avoids the error: \"Failed to set the 'appendWindow___' property\"\n sourceBuffer.appendWindowStart = 0\n sourceBuffer.appendWindowEnd = finalAppendWindowEnd\n sourceBuffer.appendWindowStart = finalAppendWindowStart\n })\n }\n\n remove(startTime: number, endTime: number): Promise<void> {\n return this.queue.enqueue(async () => {\n if (endTime > startTime) {\n logDebug(this, `removing range: ${startTime}-${endTime}`)\n this.sourceBuffer?.remove(startTime, endTime)\n await this.nextIdle()\n logDebug(this, 'removed, new buffered:', this.buffered)\n }\n })\n }\n\n /**\n * Returns a promise that resolves when the source buffer is no longer updating.\n * @private\n */\n private nextIdle = (): Promise<void> =>\n nextSourceBufferIdle(this.sourceBuffer).finally(this.clearBufferedCache)\n\n async clear(): Promise<void> {\n await this.remove(0, Number.POSITIVE_INFINITY)\n }\n\n /**\n * Aborts any pending operations and disposes the backed SourceBuffer.\n */\n dispose() {\n logDebug(this, 'dispose')\n this.queue.abort()\n this.sourceBufferRef?.dispose()\n this.sourceBufferRef = null\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n type Clearable,\n createAbortSlot,\n createDisposer,\n createTaskQueue,\n type Disposable,\n type Disposer,\n EventHostImpl,\n getLogLevel,\n isSilentError,\n LinkedList,\n logDebug,\n LogLevel,\n logVerbose,\n logWarn,\n type ReadonlyEventHost,\n throttle,\n} from '@amazon/vinyl-util'\nimport type { ReadonlyPlaybackController } from '../../playback/ReadonlyPlaybackController'\nimport type { SourceBufferController } from './SourceBufferController'\nimport type { ReadonlySegmentController } from '../SegmentController'\nimport type { SegmentReference } from '../SegmentReference'\nimport type { BasicErrorEvent } from '../../event/BasicErrorEvent'\nimport type { ChangeEvent } from '../../event/ChangeEvent'\nimport type { ContentType, MediaQualityMetadata } from '../MediaQualityMetadata'\nimport { type MediaSourceController } from './MediaSourceController'\nimport { SEGMENT_START_AFFORDANCE } from '../SegmentController'\n\n/**\n * The interval to throttle polling the buffer.\n * Reset after a seek.\n * @private\n */\nexport const POLL_BUFFER_THROTTLE = 0.1\n\n/**\n * If segments are too large to append, reduces the max append size.\n */\nexport const QUOTA_REACHED_SCALE = 0.8\n\n/**\n * If quota exceeded errors are hit, the max append size will not be reduced below this value and the buffering\n * controller will be set to an erred state.\n */\nexport const MIN_APPEND_SIZE = 524288 // 512 * 1024\n\n/**\n * If the content type does not match a config setting.\n */\nexport const DEFAULT_MAX_APPEND_SIZE = 10485760 // 10 * 1024 * 1024\n\nexport interface BufferingControllerEventMap {\n /**\n * Dispatched when an error of severity warning or fatal occurred while buffering.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Dispatched when the currently playing media encoding has changed.\n */\n readonly playbackQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * Dispatched when the currently buffering quality changes.\n * This is dispatched before the segment is appended.\n */\n readonly bufferingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * The last segment has finished appending.\n */\n readonly bufferingEnded: AnyRecord\n}\n\nexport interface BufferingController\n extends\n ReadonlyEventHost<BufferingControllerEventMap>,\n Clearable,\n Disposable {\n /**\n * The last error emitted.\n * Buffering will halt if this controller is in an error state.\n * Deactivating this controller will reset the error state.\n */\n readonly error: Error | null\n\n /**\n * The currently buffering media quality.\n * This is set immediately before a segment of a new quality is appended.\n *\n * Listen to {@link BufferingControllerEventMap.bufferingQualityChange} events for changes.\n */\n readonly bufferingQuality: MediaQualityMetadata | null\n\n /**\n * The currently playing media quality.\n *\n * Listen to {@link BufferingControllerEventMap.playbackQualityChange} events for changes.\n */\n readonly playbackQuality: MediaQualityMetadata | null\n\n /**\n * True if this buffering controller is active.\n */\n readonly active: boolean\n\n /**\n * True if the stream has buffered the last segment.\n */\n readonly bufferingEnded: boolean\n\n /**\n * Begins buffering.\n */\n activate(): void\n\n /**\n * Stops buffering.\n */\n deactivate(): void\n\n /**\n * If this controller is in an error state, resets and tries again.\n */\n reset(): void\n}\n\n/**\n * The measured source buffer quotas.\n */\nconst sourceBufferQuotas = /* @__PURE__ */ new Map<string, number>()\n\n/**\n * Clears the current estimated source buffer quota.\n * @private\n */\nexport function clearSourceBufferQuota() {\n sourceBufferQuotas.clear()\n}\n\n/**\n * Returns the measured source buffer quota for the given content type.\n * Will return null if the quota was never reached.\n *\n * @param contentType\n */\nexport function getSourceBufferQuota(contentType: ContentType): number | null {\n return sourceBufferQuotas.get(contentType) ?? null\n}\n\nexport interface BufferingControllerImplDeps {\n readonly mediaSourceController: MediaSourceController\n readonly segmentController: ReadonlySegmentController\n readonly playbackController: ReadonlyPlaybackController\n readonly sourceBufferControllerFactory: () => SourceBufferController\n}\nexport interface BufferingControllerImplOptions {\n /**\n * When the buffer falls below this time threshold, the next segment will be requested from the\n * segment controller and appended.\n * Default: 4s\n */\n readonly minBuffer: number\n\n /**\n * The maximum number of bytes to append at a time per content type.\n * Default: { audio: 1MiB, video: 15MiB }\n */\n readonly maxAppendSize: Partial<Record<ContentType, number>>\n}\n\nconst defaultBufferingControllerOptions = {\n minBuffer: 4.0,\n maxAppendSize: {\n audio: 10485760, // 10 * 1024 * 1024\n video: 157286400, // 150 * 1024 * 1024\n },\n} as const satisfies BufferingControllerImplOptions\n\n/**\n * The buffering controller is responsible for requesting and appending segments to the source\n * buffer controller.\n */\nexport class BufferingControllerImpl\n extends EventHostImpl<BufferingControllerEventMap>\n implements BufferingController, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'BufferingControllerImpl'\n }\n\n readonly options: BufferingControllerImplOptions\n private readonly mediaSourceController: MediaSourceController\n private readonly playbackController: ReadonlyPlaybackController\n private readonly segmentController: ReadonlySegmentController\n\n private sourceBufferController: SourceBufferController | null = null\n private decoderId: string | null = null\n\n /**\n * The currently buffered segments.\n */\n private buffered = /* @__PURE__ */ new LinkedList<SegmentReference<ArrayBuffer>>()\n private appendOffset = 0\n\n /**\n * The currently buffering quality.\n */\n private _bufferingQuality: MediaQualityMetadata | null = null\n\n /**\n * If true and in a bufferingEnded state, the segment provider will be queried again.\n * This will be set to true after the segment controller reports a change event, indicating that there may be new\n * segments to append.\n */\n private reopen = false\n private _error: Error | null = null\n private _bufferingEnded = false\n\n private readonly queue = /* @__PURE__ */ createTaskQueue()\n\n private disposer = /* @__PURE__ */ createDisposer()\n private _active = false\n private activateDisposer: Disposer | null = null\n\n private readonly segmentAbort = /* @__PURE__ */ createAbortSlot()\n\n constructor(\n readonly deps: BufferingControllerImplDeps,\n readonly contentType: ContentType,\n options?: Partial<BufferingControllerImplOptions>\n ) {\n super()\n this.options = {\n ...defaultBufferingControllerOptions,\n ...options,\n }\n logDebug(this, 'constructed', this.options)\n this.mediaSourceController = deps.mediaSourceController\n this.playbackController = deps.playbackController\n this.segmentController = deps.segmentController\n }\n\n get active(): boolean {\n return this._active\n }\n\n /**\n * Activates the buffering controller, watching the playhead and segment controller.\n */\n activate() {\n if (this._active) return\n this._active = true\n logDebug(this, 'activate')\n this.activateDisposer = createDisposer()\n const { add } = this.activateDisposer\n this.sourceBufferController = add(\n this.deps.sourceBufferControllerFactory()\n )\n add(this.playbackController.on('timeUpdate', this.pollBuffer))\n add(\n this.playbackController.on('seeking', () => {\n this.clear()\n })\n )\n\n const onMediaSourceOpen = () => {\n logDebug(this, 'media source opened')\n this.pollBufferImmediate()\n }\n if (this.mediaSourceOpen) {\n onMediaSourceOpen()\n } else {\n add(this.mediaSourceController.on('sourceOpen', onMediaSourceOpen))\n }\n add(\n this.segmentController.on('change', () => {\n this.reopen = true\n this.pollBufferImmediate()\n })\n )\n }\n\n deactivate() {\n if (!this._active) return\n logDebug(this, 'deactivate')\n this.abortCurrentSegment()\n this.resetBufferedState()\n this.activateDisposer!.dispose()\n this.activateDisposer = null\n this.sourceBufferController = null\n this._active = false\n }\n\n reset(): void {\n if (!this._error) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.pollBufferImmediate()\n }\n\n /**\n * Returns true if there are active operations.\n */\n get busy(): boolean {\n return this.queue.running > 0\n }\n\n /**\n * Resets the throttle and polls the buffer on the next frame.\n */\n private pollBufferImmediate = () => {\n this.pollBuffer.reset()\n setTimeout(() => {\n if (this.active) this.pollBuffer()\n })\n }\n\n /**\n * If buffered time reaches below minBuffer, request the segment for the next unbuffered\n * time and append.\n * @private\n */\n private readonly pollBuffer = /* @__PURE__ */ this.disposer.add(\n /* @__PURE__ */ throttle(\n () => {\n const time = this.playbackController.currentTime\n if (getLogLevel() === LogLevel.VERBOSE) {\n logVerbose(\n this,\n `pollBuffer time: ${time}, bufferedTime: ${this.getBufferedTime()}, busy: ${this.busy}, error: ${this.error != null}, readyState: ${this.mediaSourceController.readyState}`\n )\n }\n this.refreshHead()\n if (!this.shouldAppend()) return\n this.reopen = false\n this.queue\n .enqueue(() => this.appendNext())\n .catch(this.handleError)\n // An append has finished. Poll again on the next frame.\n // The append either completed successfully, erred fatally (setting an error state),\n // or erred silently (an abort).\n .finally(this.pollBufferImmediate)\n },\n POLL_BUFFER_THROTTLE,\n {\n leading: true,\n trailing: true,\n }\n )\n )\n\n private shouldAppend(): boolean {\n return (\n this.active &&\n !this.busy &&\n !this.error &&\n !this.mediaSourceClosed &&\n (!this.bufferingEnded || this.reopen) &&\n // Return true if the current buffer is less than the minimum buffer and the playhead has not reached duration.\n this.getBufferedTime() <= this.options.minBuffer\n )\n }\n\n /**\n * The buffered segment at the playhead.\n */\n private get head(): SegmentReference<ArrayBuffer> | undefined {\n return this.buffered.head?.value\n }\n\n /**\n * The most recently buffered segment.\n */\n private get tail(): SegmentReference<ArrayBuffer> | undefined {\n return this.buffered.tail?.value\n }\n\n protected async appendNext(): Promise<void> {\n logVerbose(this, 'appendNext')\n const sourceBufferController = this.sourceBufferController!\n const time = this.playbackController.currentTime\n\n const tail = this.tail\n let streamingSegment: SegmentReference<ArrayBuffer> | null\n // If appendOffset is less than the last buffered segment size, this indicates a partial append, continue\n // buffering the last segment.\n if (tail && this.appendOffset < tail.data.byteLength) {\n streamingSegment = tail\n } else {\n streamingSegment = await this.segmentController.getSegment(\n // If buffering is a continuation from the previous segment, use its end time.\n // Otherwise, start streaming from slightly behind the playhead.\n tail?.endTime ?? time - SEGMENT_START_AFFORDANCE,\n this.segmentAbort.value\n )\n logVerbose(this, 'streamingSegment', streamingSegment)\n if (streamingSegment) this.appendOffset = 0\n }\n if (!streamingSegment) {\n await sourceBufferController.enqueue(() => {\n if (this.mediaSourceOpen) this.endBuffering()\n })\n return\n }\n this.bufferingQuality = streamingSegment.quality\n if (this.decoderId !== streamingSegment.quality.decoderId) {\n // Append the initialization segment before the media segment if the decoder\n // needs (re)-initialization.\n this.decoderId = null\n await sourceBufferController.appendInit(\n streamingSegment.initData,\n streamingSegment.quality.mimeType!\n )\n this.decoderId = streamingSegment.quality.decoderId\n }\n // Set the timestamp offset only if appending from an unbuffered position.\n if (!tail) {\n await sourceBufferController.setTimestampOffset(\n streamingSegment.timestampOffset\n )\n }\n\n const maxAppendSize = this.getMaxAppendSize(\n streamingSegment.quality.contentType!\n )\n\n const currentBitrate =\n streamingSegment.data.byteLength /\n (streamingSegment.endTime - streamingSegment.startTime)\n const appendSize =\n maxAppendSize - currentBitrate * this.getBufferedTime()\n if (appendSize <= 0) {\n // current buffered data is filling entire quota\n return\n }\n\n const byteLength = streamingSegment.data.byteLength\n if (byteLength > appendSize) {\n const newOffset = this.appendOffset + appendSize\n const chunk = streamingSegment.data.slice(\n this.appendOffset,\n newOffset\n )\n await sourceBufferController.append(chunk)\n if (this.appendOffset === 0) {\n this.buffered.push(streamingSegment)\n }\n this.appendOffset = newOffset\n logVerbose(\n this,\n `appended chunk, this.appendOffset: ${this.appendOffset}`\n )\n } else {\n await sourceBufferController.append(streamingSegment.data)\n this.appendOffset = streamingSegment.data.byteLength\n this.buffered.push(streamingSegment)\n }\n if (!tail) this.refreshHead() // Update quality immediately if buffer was empty\n }\n\n private abortCurrentSegment() {\n this.segmentAbort.abort()\n }\n\n /**\n * Checks if the playhead has progressed past the current head segment and shifts the linked list.\n * Updates the playback quality if changed.\n */\n private refreshHead() {\n const head = this.head\n const tail = this.tail\n const time = this.playbackController.currentTime\n if (head && time >= head.endTime && head !== tail) {\n // The playhead has passed the end of the head segment.\n this.buffered.shift()\n }\n this.playbackQuality = this.head?.quality ?? null\n }\n\n private getMaxAppendSize(contentType: ContentType): number {\n const maxAppendSize =\n this.options.maxAppendSize[contentType] ?? DEFAULT_MAX_APPEND_SIZE\n const sourceBufferQuota = sourceBufferQuotas.get(contentType)\n return sourceBufferQuota == null\n ? maxAppendSize\n : Math.min(sourceBufferQuota, maxAppendSize)\n }\n\n private _playbackQuality: MediaQualityMetadata | null = null\n\n get playbackQuality(): MediaQualityMetadata | null {\n return this._playbackQuality\n }\n\n /**\n * Returns the quality currently buffering.\n */\n get bufferingQuality(): MediaQualityMetadata | null {\n return this._bufferingQuality\n }\n\n private set bufferingQuality(value: MediaQualityMetadata | null) {\n const previous = this._bufferingQuality\n if (value?.qualityId === previous?.qualityId) return\n this._bufferingQuality = value\n logDebug(this, 'bufferingQualityChange', value)\n this.dispatch('bufferingQualityChange', {\n previous,\n current: value,\n })\n }\n\n /**\n * Sets the current playback quality and emits a playbackQualityChange event.\n * No-ops if quality id has not changed.\n */\n private set playbackQuality(value: MediaQualityMetadata | null) {\n const previous = this._playbackQuality\n if (value?.qualityId === previous?.qualityId) return\n this._playbackQuality = value\n logDebug(this, 'playbackQualityChange', value)\n this.dispatch('playbackQualityChange', {\n previous,\n current: value,\n })\n }\n\n /**\n * The last error emitted.\n * Buffering will halt if this controller is in an error state.\n * Deactivating this controller will reset the error state.\n */\n get error(): Error | null {\n return this._error\n }\n\n /**\n * Returns true if the media source's ready state is 'open'\n */\n private get mediaSourceOpen(): boolean {\n return this.mediaSourceController.readyState === 'open'\n }\n\n /**\n * Returns true if the media source's ready state is 'closed'\n */\n private get mediaSourceClosed(): boolean {\n return this.mediaSourceController.readyState === 'closed'\n }\n\n /**\n * Returns true if the last segment has been appended.\n */\n get bufferingEnded(): boolean {\n return this._bufferingEnded\n }\n\n private readonly handleError = (error: Error) => {\n if ('name' in error && error.name === 'QuotaExceededError') {\n const contentType = this.bufferingQuality?.contentType\n if (contentType) {\n const newAppendSize =\n this.getMaxAppendSize(contentType) * QUOTA_REACHED_SCALE\n if (newAppendSize >= MIN_APPEND_SIZE) {\n sourceBufferQuotas.set(contentType, newAppendSize)\n logWarn(\n this,\n 'QuotaExceededError, new source buffer limit:',\n (newAppendSize / 1024 / 1024).toFixed(1) + ' MiB'\n )\n const sourceBufferController = this.sourceBufferController\n if (sourceBufferController) {\n this.clear()\n }\n return // If the quota size was successfully reduced, do not err and try again.\n }\n }\n }\n if (!isSilentError(error)) {\n // Set this controller to an error state. If in an error state, buffering will\n // not continue.\n this._error = error\n this.dispatch('error', {\n target: this,\n error,\n })\n }\n }\n\n /**\n * Returns the amount of time buffered at the current media position.\n * @private\n */\n getBufferedTime(): number {\n if (!this.active) return 0\n const time = this.playbackController.currentTime\n const range = this.sourceBufferController!.buffered.getRangeAt(time)\n if (!range) return 0\n return range[1] - time\n }\n\n /**\n * Cancels any currently buffering fragments and clears the source buffer.\n */\n clear(): void {\n if (!this.active) return\n logDebug(this, 'clear')\n this.abortCurrentSegment()\n // Enqueue clearing the buffer and buffered list.\n this.queue\n .enqueue(this.finishAndClearBuffers)\n .catch(this.handleError)\n .finally(() => {\n this.resetBufferedState()\n this.pollBufferImmediate()\n })\n }\n\n private endBuffering(): void {\n logDebug(this, 'bufferingEnded')\n this._bufferingEnded = true\n this.bufferingQuality = null\n this.dispatch('bufferingEnded', {})\n }\n\n private resetBufferedState() {\n this.decoderId = null\n this.appendOffset = 0\n this.buffered.clear()\n this._bufferingEnded = false\n this.bufferingQuality = null\n this.playbackQuality = null\n }\n\n /**\n * Finish any partial appends and clear the source buffer.\n */\n private finishAndClearBuffers = async () => {\n if (!this.active) return\n logVerbose(this, 'finishAndClearBuffers')\n await this.sourceBufferController!.clear()\n logVerbose(this, 'finishAndClearBuffers complete')\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.deactivate()\n super.dispose()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AnyRecord,\n Disposable,\n ReadonlyAbort,\n ReadonlyEventHost,\n ReadonlyRanges,\n} from '@amazon/vinyl-util'\nimport type { SegmentReference } from './SegmentReference'\nimport type { ChangeEvent } from '../event/ChangeEvent'\nimport type { MediaQualityMetadata } from './MediaQualityMetadata'\n\n/**\n * Forward-snap tolerance, in seconds, applied when looking up a segment by time.\n *\n * If the requested time falls within this window before a segment's `startTime`,\n * that segment is returned rather than treating the gap as uncovered. This absorbs\n * small alignment differences between qualities, where one quality's segment may\n * begin a few milliseconds later than another's at the same logical boundary.\n *\n * Pass to `getSegmentAtTime` (and `MediaQualityData.getSegment`) as the `affordance`\n * argument. Callers resuming streaming after a seek should also bias the requested\n * time *behind* the playhead by at least this amount, so any subsequent appends\n * cover the playhead without leaving a gap. The `SegmentController` clamps negative\n * request times to `0`, so callers don't need to guard against the bias going below\n * the start of the timeline.\n */\nexport const SEGMENT_START_AFFORDANCE = 0.2\n\nexport interface SegmentControllerEventMap {\n /**\n * fetchedRanges have been updated.\n */\n readonly fetchedRangesChange: AnyRecord\n\n /**\n * Emitted when the timeline has changed.\n */\n readonly change: AnyRecord\n\n /**\n * Dispatched when the current streaming quality changes.\n * This is dispatched when a new quality is requested.\n */\n readonly streamingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n}\n\n/**\n * The SegmentController provides segments to buffer for the given time.\n * It is expected to prefetch segments based on the expectation of when the segments will be\n * needed next.\n */\nexport interface ReadonlySegmentController extends ReadonlyEventHost<SegmentControllerEventMap> {\n readonly error: Error | null\n\n /**\n * The time ranges currently fetched.\n */\n readonly fetchedRanges: ReadonlyRanges\n\n /**\n * The most recently requested quality metadata.\n */\n readonly streamingQuality: MediaQualityMetadata | null\n\n /**\n * Returns a Promise for a segment covering the given time, with quality chosen by\n * the configured `QualitySelector`. Resolves to `null` if no media exists at that\n * time. Negative `time` values are clamped to `0`.\n *\n * The lookup forward-snaps by `SEGMENT_START_AFFORDANCE`: if `time` falls within\n * that window before a segment's `startTime`, that segment is returned. This\n * absorbs sub-second segment-boundary differences across qualities so an ABR\n * switch doesn't replay or skip media at the boundary.\n *\n * Calling this also blocks the prefetch queue until the returned promise settles,\n * so the active request is prioritized over background prefetching.\n *\n * @param time The time, in seconds, the requested segment should span.\n * @param abort Aborts the returned promise (rejecting with `AbortError`) and\n * releases the prefetch-queue lock. The underlying network request may continue\n * so its result can still populate the cache.\n */\n getSegment(\n time: number,\n abort?: ReadonlyAbort\n ): Promise<SegmentReference<ArrayBuffer> | null>\n}\n\n/**\n * Configuration the track is expected to provide to the SegmentController.\n */\nexport interface PrefetchOptions {\n /**\n * The prefetching priority of the track. Higher numbers take precedence.\n */\n readonly trackPrefetchPriority: number\n\n /**\n * When the track is inactive, the starting time to prefetch from.\n */\n readonly startTime: number\n}\n\n/**\n * Provides segments for a given time.\n * Handles segment prefetching and caching.\n */\nexport interface SegmentController\n extends ReadonlySegmentController, Disposable {\n /**\n * Configures this segment provider.\n */\n configure(options: Partial<PrefetchOptions>): void\n\n /**\n * Clears the cached segments.\n * Currently pending segment promises will be rejected with an abort reason.\n */\n clear(): void\n\n /**\n * Indicates that this segment provider is providing segments for an active track and should be prioritized\n * accordingly.\n */\n activate(): void\n\n /**\n * Indicates that this segment provider is providing segments for an inactive track.\n */\n deactivate(): void\n\n /**\n * Resets failed segments to a pending state.\n */\n reset(): void\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Mutable, Unsubscribe } from '@amazon/vinyl-util'\nimport {\n Abort,\n clone,\n closeTo,\n createDisposer,\n EventHostImpl,\n getNetworkState,\n getOrSet,\n isSilentError,\n logDebug,\n logError,\n noop,\n type Range,\n rangeIntersects,\n RangesImpl,\n type ReadonlyAbort,\n type ReadonlyRanges,\n throttle,\n withAbort,\n} from '@amazon/vinyl-util'\nimport type { ReadonlyPlaybackController } from '../playback/ReadonlyPlaybackController'\nimport {\n type PrefetchOptions,\n SEGMENT_START_AFFORDANCE,\n type SegmentController,\n type SegmentControllerEventMap,\n} from './SegmentController'\nimport {\n type SegmentDataProvider,\n SegmentDataSlot,\n SegmentStatus,\n} from './SegmentDataSlot'\nimport {\n defaultTrackPriority,\n enqueueSegmentPrefetch,\n immediatePrefetchPriority,\n type SegmentPrefetchPriority,\n} from './SegmentPrefetch'\nimport {\n getSegmentAtTime,\n getSegmentInsertionIndexAtTime,\n} from './util/segment'\nimport type { SegmentReference } from './SegmentReference'\nimport type { ContentType, MediaQualityMetadata } from './MediaQualityMetadata'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from './MediaTimeline'\nimport { getMediaPeriodAtTime, type MediaPeriod } from './MediaTimeline'\nimport type { PrefetchState, QualitySelector } from './abr/QualitySelector'\n\n/**\n * The interval to check if additional segments should be prefetched.\n */\nexport const PREFETCH_POLL_THROTTLE = 1\n\nexport interface SegmentControllerImplDeps {\n readonly playbackController: ReadonlyPlaybackController\n\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n\n readonly qualitySelector: QualitySelector\n}\n\nexport interface SegmentControllerImplOptions {\n /**\n * The amount of time ahead of the playhead to prefetch when the track is active.\n * Default: 240\n */\n readonly prefetchActive: number\n\n /**\n * The amount of time to prefetch when the track is not active.\n * Default: 20\n */\n readonly prefetchInactive: number\n\n /**\n * The number of seconds behind the playhead to retain segments.\n * Default: 30\n */\n readonly retainTail: number\n}\n\nexport const defaultSegmentControllerBaseOptions: SegmentControllerImplOptions =\n {\n prefetchActive: 180,\n prefetchInactive: 20,\n retainTail: 30,\n }\n\n/**\n * Default SegmentController implementation.\n * Provides segments for a given time.\n * Handles segment prefetching and caching.\n *\n * Uses mediaTimelineTransformed to resolve segments directly from the MediaTimeline.\n */\nexport class SegmentControllerImpl\n extends EventHostImpl<SegmentControllerEventMap>\n implements SegmentController\n{\n get [Symbol.toStringTag](): string {\n return 'SegmentControllerImpl'\n }\n\n private _active = false\n get active(): boolean {\n return this._active\n }\n\n private readonly _fetchedRanges = /* @__PURE__ */ new RangesImpl()\n private _startTime = 0\n\n /**\n * A map of decoder id to init segment slots.\n * This allows representations with seamless bitstream switching to share initialization segments without\n * making unnecessary requests or decoder re-initializations.\n */\n private readonly cachedInitSegments = /* @__PURE__ */ new Map<string, SegmentDataSlot>()\n private readonly cachedSegments: SegmentReference<SegmentDataSlot>[] = []\n\n private readonly disposer = /* @__PURE__ */ createDisposer()\n readonly options: SegmentControllerImplOptions\n\n private prefetchingPriority: Mutable<SegmentPrefetchPriority> =\n /* @__PURE__ */ clone(defaultTrackPriority)\n\n /**\n * True if the last segment in the prefetch range has been cached.\n */\n private ended = false\n private prefetching = false\n private _error: Error | null = null\n\n private timeUpdateSub: Unsubscribe | null = null\n private seekingSub: Unsubscribe | null = null\n\n // When disposed, aborts in-flight operations.\n private readonly abort = /* @__PURE__ */ new Abort()\n\n /**\n * Cached last period lookup for fast repeated access.\n */\n private _cachedPeriod: MediaPeriod | null = null\n\n constructor(\n readonly deps: SegmentControllerImplDeps,\n readonly contentType: ContentType,\n options?: Partial<SegmentControllerImplOptions>\n ) {\n super()\n logDebug(this, 'constructed')\n const { add } = this.disposer\n this.options = {\n ...defaultSegmentControllerBaseOptions,\n ...options,\n }\n add(\n deps.mediaTimelineTransformed.onData(() => {\n // If the media timeline changes, re-check ended state.\n this.ended = false\n this._cachedPeriod = null\n this.pollPrefetch()\n this.dispatch('change', {})\n })\n )\n\n add(\n getNetworkState().on('online', () => {\n logDebug(this, 'online, resetting prefetch')\n this.reset()\n })\n )\n }\n\n get error(): Error | null {\n return this._error\n }\n\n /**\n * Gets the period at the given time, using a cache for the last returned period.\n */\n private async getPeriodAtTime(time: number): Promise<MediaPeriod | null> {\n if (\n this._cachedPeriod &&\n time >= this._cachedPeriod.startTime &&\n time < this._cachedPeriod.endTime\n ) {\n return this._cachedPeriod\n }\n const timeline = await this.deps.mediaTimelineTransformed.value\n const period = getMediaPeriodAtTime(timeline, time)\n if (period) this._cachedPeriod = period\n return period\n }\n\n /**\n * Configures this segment provider and initiates prefetching.\n * This may be called multiple times, for example when re-using a cached track a new track priority and start time\n * can be provided.\n */\n configure(options: Partial<PrefetchOptions>) {\n if (options.startTime != null) this._startTime = options.startTime\n if (options.trackPrefetchPriority != null)\n this.prefetchingPriority.trackPriority =\n options.trackPrefetchPriority\n this.ended = false\n this.pollPrefetch()\n }\n\n get startTime(): number {\n return this._startTime\n }\n\n get trackPrefetchPriority(): number {\n return this.prefetchingPriority.trackPriority\n }\n\n /**\n * Returns the range that should be prefetched.\n */\n private get prefetchRange(): Range {\n return this.active\n ? this.prefetchRangeActive\n : this.prefetchRangeInactive\n }\n\n /**\n * Returns the range that should be prefetched when inactive.\n * This range will not be removed during sweeps unless `clear` is called.\n */\n private get prefetchRangeInactive(): Range {\n const prefetchFrom = this.startTime\n const prefetchTo = prefetchFrom + this.options.prefetchInactive\n return [prefetchFrom, prefetchTo]\n }\n\n /**\n * Returns the range that should be prefetched while active.\n */\n private get prefetchRangeActive(): Range {\n const prefetchFrom = this.deps.playbackController.currentTime\n const prefetchTo = prefetchFrom + this.options.prefetchActive\n return [prefetchFrom, prefetchTo]\n }\n\n /**\n * Clears data segments no longer within the current prefetch range.\n * Init segments will not be changed.\n */\n private sweepCachedSegments() {\n // The inactive range (typically first couple segments of a track) will not be removed.\n const inactiveRange = this.prefetchRangeInactive\n\n // The active range prefetch expanded to include the retain tail will not be removed if the track is active.\n const activeRange = this.active\n ? ([\n this.prefetchRangeActive[0] - this.options.retainTail,\n this.prefetchRangeActive[1],\n ] as const)\n : null\n let n = this.cachedSegments.length\n for (let i = 0; i < n; i++) {\n const cachedSegment = this.cachedSegments[i]\n // Check if the cached segment is still within our retain window.\n const { startTime, endTime } = cachedSegment\n const cachedRange = [startTime, endTime] as const\n if (\n !rangeIntersects(inactiveRange, cachedRange) &&\n !(activeRange && rangeIntersects(activeRange, cachedRange))\n ) {\n // No longer need the segment. Does nothing if inactive.\n cachedSegment.data.clear()\n this.cachedSegments.splice(i, 1)\n logDebug(\n this,\n 'removing cached segment at: ',\n cachedSegment.startTime\n )\n i--\n n--\n }\n }\n }\n\n /**\n * Gets the next time to prefetch, or null if the prefetch range has been filled.\n */\n private getNextTimeToPrefetch(): number | null {\n const [prefetchFrom, prefetchTo] = this.prefetchRange\n // fetchedRanges are directly from the segments, safe to use when getting next segment.\n const currentRange = this.fetchedRanges.getRangeAt(prefetchFrom)\n const nextTime = currentRange == null ? prefetchFrom : currentRange[1]\n if (nextTime >= prefetchTo - Number.EPSILON) return null\n return nextTime\n }\n\n private pollPrefetch = /* @__PURE__ */ this.disposer.add(\n /* @__PURE__ */ throttle(\n () => {\n if (this.error) return\n this.sweepCachedSegments()\n if (this.ended || this.prefetching) return\n\n const nextTime = this.getNextTimeToPrefetch()\n if (nextTime == null) return // Prefetched the full range\n this.prefetching = true\n // Enqueue the prefetch.\n enqueueSegmentPrefetch(\n async () => {\n this.abort.throwIfAborted()\n // Quality selection is done at the time of getSegment(), which is called when\n // a slot is created. Defer slot creation until request is about to be made.\n logDebug(this, `Prefetching`, nextTime.toFixed(4))\n const slot = await this.getSlotAtTime(nextTime)\n this.abort.throwIfAborted()\n if (!slot) {\n logDebug(this, 'prefetch ended')\n this.ended = true\n return\n }\n await withAbort(\n Promise.all([\n slot.initData.request(),\n slot.data.request(),\n ]),\n this.abort\n )\n },\n this.contentType,\n this.prefetchingPriority\n )\n .catch(this.prefetchErrorHandler)\n .finally(() => {\n this.prefetching = false\n if (!this.disposed) this.pollPrefetch()\n })\n },\n PREFETCH_POLL_THROTTLE,\n {\n leading: true,\n trailing: true,\n }\n )\n )\n\n private prefetchErrorHandler = (error: any) => {\n // Only log the error for prefetch failures, it will get reported if/when it is attempted\n // to be buffered.\n if (!isSilentError(error)) {\n logError(this, 'Error prefetching segment', error)\n this._error = error\n }\n }\n\n get fetchedRanges(): ReadonlyRanges {\n return this._fetchedRanges\n }\n\n /**\n * Gets the number of seconds currently prefetched.\n */\n get fetchedTime(): number {\n const time = this.active\n ? this.deps.playbackController.currentTime\n : this._startTime\n const currentRange = this.fetchedRanges.getRangeAt(time)\n if (!currentRange) return 0\n return currentRange[1] - time\n }\n\n private _streamingQuality: MediaQualityMetadata | null = null\n\n get streamingQuality(): MediaQualityMetadata | null {\n return this._streamingQuality\n }\n\n private set streamingQuality(value: MediaQualityMetadata | null) {\n const previous = this._streamingQuality\n if (value?.qualityId === previous?.qualityId) return\n this._streamingQuality = value\n logDebug(this, 'streamingQualityChange', value)\n this.dispatch('streamingQualityChange', {\n previous,\n current: value,\n })\n }\n\n getSegment(\n time: number,\n abort?: ReadonlyAbort\n ): Promise<SegmentReference<ArrayBuffer> | null> {\n logDebug(this, `requesting segment at time: ${time.toFixed(4)}`)\n const segmentReferencePromise = withAbort(\n this._getSegment(Math.max(0, time)),\n abort\n )\n\n // When a segment is actively needed, block the prefetch queue until the active segment promise settles:\n enqueueSegmentPrefetch(\n () => segmentReferencePromise,\n this.contentType,\n immediatePrefetchPriority\n ).catch(noop)\n return segmentReferencePromise\n }\n\n private async _getSegment(\n time: number\n ): Promise<SegmentReference<ArrayBuffer> | null> {\n const streamingSlot = await this.getSlotAtTime(time)\n if (!streamingSlot) return null\n logDebug(\n this,\n `init status: ${streamingSlot.initData.status}, data status: ${streamingSlot.data.status}`\n )\n // If prefetch failed, try again now that the segment is actively needed:\n this.resetSlot(streamingSlot)\n\n const initAndDataPromise = Promise.all([\n streamingSlot.initData.request(),\n streamingSlot.data.request(),\n ])\n\n // If the requested time is close to the start of the next segment, immediately start prefetching the next\n // segment, and not resolving until both are cached.\n let minBufferPrefetch: Promise<void> = Promise.resolve()\n const minBufferTime = await this.getMinBufferTime()\n if (streamingSlot.endTime - time < minBufferTime) {\n minBufferPrefetch = this.prefetchImmediate(\n streamingSlot.endTime\n ).catch(noop) // Ignore error until it is the next segment needed\n }\n const [initData, data] = await initAndDataPromise\n await minBufferPrefetch\n return {\n ...streamingSlot,\n initData,\n data,\n }\n }\n\n /**\n * Gets the minimum buffer time from the timeline.\n * Falls back to a reasonable default.\n */\n private async getMinBufferTime(): Promise<number> {\n const timeline = await this.deps.mediaTimelineTransformed.value\n return timeline.minBufferTime\n }\n\n /**\n * Prefetches the segment at the given time. Does not use the background scheduler.\n *\n * @param time\n */\n private async prefetchImmediate(time: number): Promise<void> {\n const slot = await this.getSlotAtTime(time)\n if (!slot) return\n await Promise.all([slot.initData.request(), slot.data.request()])\n }\n\n /**\n * Gets a streaming segment slot that spans the given time, or null if there is no media at that time.\n * Slots will be cached until they slide out of the retention range or `clear` is called.\n */\n private async getSlotAtTime(\n time: number\n ): Promise<SegmentReference<SegmentDataSlot> | null> {\n // Check if there is a cached slot.\n const cachedSegment = getSegmentAtTime(\n time,\n this.cachedSegments,\n SEGMENT_START_AFFORDANCE\n )\n if (cachedSegment) return cachedSegment\n\n const newSlot = await withAbort(\n this.createSlotForTime(time),\n this.abort\n )\n this.abort.throwIfAborted()\n\n if (!newSlot) return null\n newSlot.data.onStatusChange = () => {\n // When the data segment settles, update the fetched ranges.\n if (newSlot.data.status === SegmentStatus.RESOLVED)\n this._fetchedRanges.add(newSlot.startTime, newSlot.endTime)\n else if (newSlot.data.status === SegmentStatus.INACTIVE)\n this._fetchedRanges.remove(newSlot.startTime, newSlot.endTime)\n this.dispatch('fetchedRangesChange', {})\n }\n\n // Insert the slot, in order.\n const insertionIndex = getSegmentInsertionIndexAtTime(\n newSlot.startTime,\n this.cachedSegments\n )\n\n // Slot creation is asynchronous, to allow requesting index ranges. Check if a slot for this time was already\n // created.\n if (insertionIndex > 0) {\n const cachedSegment = this.cachedSegments[insertionIndex - 1]\n if (closeTo(newSlot.startTime, cachedSegment.startTime)) {\n return cachedSegment\n }\n }\n logDebug(\n this,\n `created slot at ${insertionIndex} for time ${newSlot.startTime.toFixed(4)}`\n )\n this.cachedSegments.splice(insertionIndex, 0, newSlot)\n return newSlot\n }\n\n /**\n * Gets a cached init segment slot for the given decoder id. If a slot is not cached, create one.\n */\n private getOrCreateInitSlot(\n decoderId: string,\n segmentDataProvider: SegmentDataProvider\n ): SegmentDataSlot {\n return getOrSet(this.cachedInitSegments, decoderId, () => {\n return new SegmentDataSlot(segmentDataProvider)\n })\n }\n\n /**\n * Creates a slot that spans the given time, or returns null if there is no media at that time.\n * Uses the mediaTimelineTransformed to resolve segments directly.\n */\n private async createSlotForTime(\n time: number\n ): Promise<SegmentReference<SegmentDataSlot> | null> {\n const period = await this.getPeriodAtTime(time)\n if (!period) return null\n\n // Filter qualities to this content type.\n const filteredQualities = period.qualities.filter(\n (q) => q.metadata.contentType === this.contentType\n )\n if (filteredQualities.length === 0) return null\n\n // Gets the preceding segment encoding metadata for quality selection.\n let previousQuality: MediaQualityMetadata | null = null\n const previousIndex =\n getSegmentInsertionIndexAtTime(time, this.cachedSegments) - 1\n if (previousIndex >= 0)\n previousQuality = this.cachedSegments[previousIndex].quality\n\n const prefetchState: PrefetchState = {\n fetchedTime: this.fetchedTime,\n previousQuality,\n active: this.active,\n }\n\n const metadataArray = filteredQualities.map((q) => q.metadata)\n const index = this.deps.qualitySelector.selectQuality(\n metadataArray,\n prefetchState\n )\n const selectedQuality = filteredQualities[index]\n\n const segment = await selectedQuality.getSegment(\n time,\n SEGMENT_START_AFFORDANCE\n )\n this.abort.throwIfAborted()\n this.streamingQuality = segment?.quality ?? null\n if (!segment) return null\n\n return {\n ...segment,\n quality: segment.quality,\n initData: this.getOrCreateInitSlot(\n segment.quality.decoderId,\n segment.initData\n ),\n data: new SegmentDataSlot(segment.data),\n }\n }\n\n /**\n * Indicates that this segment provider is providing segments for an active track and should be prioritized\n * accordingly.\n * Time ranges to be prefetched will change to the active prefetch window.\n */\n activate(): void {\n if (this._active) return\n logDebug(this, 'activate')\n this._active = true\n this.pollPrefetch()\n const playbackController = this.deps.playbackController\n this.timeUpdateSub = playbackController.on(\n 'timeUpdate',\n this.pollPrefetch\n )\n this.seekingSub = playbackController.on('seeking', () => {\n this.ended = false\n this._error = null\n this.pollPrefetch()\n })\n }\n\n /**\n * Deactivates the segment provider.\n * This clears cached segments not within the inactive prefetch range.\n * Time ranges to be prefetched will change to the inactive prefetch window.\n */\n deactivate(): void {\n if (!this._active) return\n logDebug(this, 'deactivate')\n this._active = false\n this.sweepCachedSegments()\n this.timeUpdateSub!()\n this.timeUpdateSub = null\n this.seekingSub!()\n this.seekingSub = null\n }\n\n clear(): void {\n logDebug(this, 'clear')\n this.cachedSegments.forEach((slot) => {\n slot.data.onStatusChange = null\n slot.data.clear()\n slot.initData.clear()\n })\n this.cachedSegments.length = 0\n this.cachedInitSegments.clear()\n this._fetchedRanges.clear()\n this.ended = false\n this._error = null\n this._cachedPeriod = null\n if (!this.disposed) this.pollPrefetch()\n this.dispatch('fetchedRangesChange', {})\n }\n\n reset(): void {\n logDebug(this, 'reset')\n this.cachedSegments.forEach((slot) => this.resetSlot(slot))\n this._error = null\n this.pollPrefetch()\n }\n\n /**\n * Resets the slot if it's in an error state.\n * @param slot\n */\n private resetSlot(slot: SegmentReference<SegmentDataSlot>) {\n if (slot.data.status === SegmentStatus.ERRED) {\n logDebug(this, 'resetting failed segment at time:', slot.startTime)\n this.ended = false\n slot.data.clear()\n }\n if (slot.initData.status === SegmentStatus.ERRED) {\n logDebug(this, 'resetting failed init segment')\n this.ended = false\n slot.initData.clear()\n }\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n logDebug(this, 'disposing')\n super.dispose()\n this.disposer.dispose()\n this.deactivate()\n this.clear()\n this.abort.abort()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Disposable, Maybe } from '@amazon/vinyl-util'\nimport {\n createAbortSlot,\n isSilentError,\n type ReadonlyAbort,\n} from '@amazon/vinyl-util'\n\nexport enum SegmentStatus {\n /**\n * This segment has not been requested.\n */\n INACTIVE = 'inactive',\n\n /**\n * The segment has been requested but not yet completed.\n */\n PENDING = 'pending',\n\n /**\n * The segment has finished requesting.\n */\n RESOLVED = 'resolved',\n\n /**\n * The segment failed to load.\n */\n ERRED = 'erred',\n}\n\n/**\n * A function that returns a promise to segment data.\n */\nexport type SegmentDataProvider = (\n abort?: Maybe<ReadonlyAbort>\n) => Promise<ArrayBuffer>\n\n/**\n * A SegmentSlot is a holder for a segment buffer. It may be requested, cleared, and its status observed.\n */\nexport class SegmentDataSlot implements Disposable {\n /**\n * Called when the status has changed.\n */\n onStatusChange: (() => void) | null = null\n\n private _status: SegmentStatus = SegmentStatus.INACTIVE\n private readonly abortSlot = /* @__PURE__ */ createAbortSlot()\n\n private bufferPromise: Promise<ArrayBuffer> | null = null\n\n constructor(private readonly requestSegmentData: SegmentDataProvider) {}\n\n /**\n * This segment's request status.\n */\n get status(): SegmentStatus {\n return this._status\n }\n\n private set status(value: SegmentStatus) {\n this._status = value\n if (this.onStatusChange) this.onStatusChange()\n }\n\n /**\n * Aborts the request if the status is currently {@link SegmentStatus.PENDING}, and clears the cached buffer.\n * The status will go back to {@link SegmentStatus.INACTIVE} and the segment may be requested again in the future.\n */\n clear(): void {\n if (this.status === SegmentStatus.INACTIVE) return\n this.abortSlot.abort()\n this.bufferPromise = null\n this.status = SegmentStatus.INACTIVE\n }\n\n /**\n * Begins the segment request now if it has not already been requested.\n * The promise returned will settle after this slot's status has updated and onStatusChange callback invoked.\n */\n request(): Promise<ArrayBuffer> {\n if (!this.bufferPromise) {\n this.status = SegmentStatus.PENDING\n\n // Chains status handling to the promise returned by requestSegment.\n this.bufferPromise = this.requestSegmentData(this.abortSlot.value)\n .then((result) => {\n this.status = SegmentStatus.RESOLVED\n return result\n })\n .catch((error) => {\n if (isSilentError(error)) {\n // Allows this data slot to be requested again.\n this.bufferPromise = null\n this.status = SegmentStatus.INACTIVE\n } else {\n // A higher severity error, do not try again.\n this.status = SegmentStatus.ERRED\n }\n throw error\n })\n }\n return this.bufferPromise\n }\n\n /**\n * Clears this segment and removes its handler.\n */\n dispose(): void {\n this.clear()\n this.onStatusChange = null\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Task, TaskQueue } from '@amazon/vinyl-util'\nimport {\n type Comparator,\n compareBy,\n createTaskQueue,\n globalRef,\n} from '@amazon/vinyl-util'\nimport type { ContentType } from './MediaQualityMetadata'\n\n/**\n * Properties affecting segment prefetch priority.\n * Each track when prefetching will only add one segment to the prefetch queue at a time.\n */\nexport interface SegmentPrefetchPriority {\n /**\n * The track's prefetch priority.\n */\n readonly trackPriority: number\n\n /**\n * The starting time of the segment.\n */\n readonly segmentStartTime: number\n\n /**\n * The time position prefetching starts for this segment's track.\n */\n readonly prefetchStartTime: number\n}\n\nexport const defaultTrackPriority = {\n // Default priority is lowest, but not used. Use enqueueSegmentPrefetch to enqueue.\n trackPriority: 0,\n segmentStartTime: 9007199254740991, // Number.MAX_SAFE_INTEGER,\n prefetchStartTime: 0,\n} as const satisfies SegmentPrefetchPriority\n\n/**\n * Highest priority; used to block prefetching while an actively-needed operation is enqueued.\n */\nexport const immediatePrefetchPriority = {\n trackPriority: 9007199254740991, // Number.MAX_SAFE_INTEGER,\n segmentStartTime: 0,\n prefetchStartTime: 0,\n}\n\n/**\n * A comparator for segment prefetching.\n * Given tracks A, B, and C with track priorities 1, 2, and 3 respectively:\n * The expected prefetch order will be:\n *\n * A0\n * B0 // \"lean forward\" case\n * C0 // \"lean forward\" case\n * A1 ... An\n * B1 ... Bn\n * C1 ... Cn\n *\n * Note that background prefetching is in parallel to prefetching for the active track.\n */\nexport const segmentPriorityComparatorRef = /* @__PURE__ */ globalRef<\n Comparator<SegmentPrefetchPriority>\n>(() => {\n return compareBy(\n (e) => {\n // First segments always take priority over subsequent ones.\n return e.segmentStartTime <= e.prefetchStartTime ? 0 : 1\n },\n // Next, consider track priority.\n (e) => -e.trackPriority\n )\n})\n\n// Task queues for each content type\nexport const prefetchPriorityQueuesRef = /* @__PURE__ */ globalRef<\n Record<ContentType, TaskQueue<SegmentPrefetchPriority>>\n>(() => {\n return {\n video: createTaskQueue<SegmentPrefetchPriority>(\n segmentPriorityComparatorRef.value,\n defaultTrackPriority\n ),\n audio: createTaskQueue<SegmentPrefetchPriority>(\n segmentPriorityComparatorRef.value,\n defaultTrackPriority\n ),\n text: createTaskQueue<SegmentPrefetchPriority>(\n segmentPriorityComparatorRef.value,\n defaultTrackPriority\n ),\n }\n})\n\n/**\n * Enqueues a task to request a streaming segment for a specific content type.\n * This should only be used for low priority background requests. Active tracks should request without\n * prioritization for the immediately needed segment.\n * Tracks are expected to prefetch one segment at a time, in order.\n *\n * @param requestTask\n * @param contentType\n * @param priority\n */\nexport function enqueueSegmentPrefetch(\n requestTask: Task<any>,\n contentType: ContentType,\n priority: SegmentPrefetchPriority\n): Promise<void> {\n return prefetchPriorityQueuesRef.value[contentType].enqueue(\n requestTask,\n priority\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { sortedInsertionIndex } from '@amazon/vinyl-util'\nimport type { MediaSegmentMetadata } from '../SegmentReference'\n\n/**\n * Returns the segment whose range covers `time` (`startTime <= time < endTime`), or\n * \u2014 when `affordance > 0` \u2014 the next segment if `time` falls within `affordance`\n * seconds before its `startTime`. Returns `null` if neither applies.\n *\n * Note: with `affordance > 0`, when `time` lies in the last `affordance` seconds of a\n * segment that does cover it, the *next* segment is returned instead. This is\n * deliberate \u2014 callers use `affordance` to absorb sub-second boundary differences\n * across qualities \u2014 but it means the result is not strictly the segment containing\n * `time`. Callers needing exact containment should pass `affordance = 0`.\n *\n * @param time Lookup time, in seconds.\n * @param segments Segments sorted by `startTime` ascending.\n * @param affordance Forward-snap tolerance in seconds: if `time` falls just before a\n * segment's `startTime` (within `affordance`), that segment is returned. The original\n * `time` is still compared against `endTime`, so coverage never extends past it.\n */\nexport function getSegmentAtTime<T extends MediaSegmentMetadata>(\n time: number,\n segments: readonly T[],\n affordance = 0\n): T | null {\n const index =\n getSegmentInsertionIndexAtTime(time + affordance, segments) - 1\n if (index < 0) return null\n const segment = segments[index]\n return time >= segment.endTime ? null : segment\n}\n\n/**\n * Returns the count of segments whose `startTime <= time` \u2014 i.e. the index at which a\n * segment with that `startTime` would be inserted to keep the array sorted ascending.\n *\n * @param time Lookup time, in seconds.\n * @param segments Segments sorted by `startTime` ascending.\n */\nexport function getSegmentInsertionIndexAtTime(\n time: number,\n segments: readonly MediaSegmentMetadata[]\n): number {\n return sortedInsertionIndex(\n segments,\n time,\n (time, element) => time - element.startTime\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaSourceController } from '../../streaming/buffering/MediaSourceController'\nimport type { PlaybackController } from '../../playback/PlaybackController'\nimport type { QualitySelector } from '../../streaming/abr/QualitySelector'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { type ContentStreamImplDeps } from '../../streaming/ContentStream'\nimport type { ContentType } from '../../streaming/MediaQualityMetadata'\nimport {\n SourceBufferControllerImpl,\n type SourceBufferControllerImplDeps,\n} from '../../streaming/buffering/SourceBufferController'\nimport {\n BufferingControllerImpl,\n type BufferingControllerImplDeps,\n} from '../../streaming/buffering/BufferingController'\nimport {\n SegmentControllerImpl,\n type SegmentControllerImplDeps,\n} from '../../streaming/SegmentControllerImpl'\nimport { type Maybe, memoize } from '@amazon/vinyl-util'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport type { ContentStreamingOptions } from '../../streaming/ContentStreamingOptions'\nimport type { MediaTimeline } from '../../streaming/MediaTimeline'\n\n/**\n * Dependencies needed for a new content stream provided by the dash track.\n */\nexport interface DashContentStreamTrackDeps {\n readonly mediaSourceController: MediaSourceController\n readonly playbackController: PlaybackController\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n readonly qualitySelector: QualitySelector\n}\n\n/**\n * Returns a function to produce the Factories needed for a new ContentStreamImpl.\n */\nexport function createDashContentStreamFactories(\n options: Maybe<ContentStreamingOptions>\n) {\n return (deps: DashContentStreamTrackDeps) =>\n memoize(\n (contentType: ContentType) => {\n return validateFactories({\n ...externalDependencies(deps),\n sourceBufferControllerFactory:\n (deps: SourceBufferControllerImplDeps) => () =>\n new SourceBufferControllerImpl(deps, contentType),\n bufferingController: (deps: BufferingControllerImplDeps) =>\n new BufferingControllerImpl(\n deps,\n contentType,\n options?.buffering\n ),\n segmentController: (deps: SegmentControllerImplDeps) =>\n new SegmentControllerImpl(\n deps,\n contentType,\n options?.segmentController\n ),\n } as const) satisfies Factories<ContentStreamImplDeps>\n },\n (contentType) => contentType\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { PrefetchState, QualitySelector } from './QualitySelector'\nimport {\n clamp,\n createDisposer,\n createLogPrefix,\n type Disposable,\n getNetworkMetrics,\n type LogTarget,\n lerp,\n type Maybe,\n} from '@amazon/vinyl-util'\nimport {\n boolean,\n enumOf,\n number,\n object,\n type ObjectSchema,\n} from '@amazon/vinyl-validation'\nimport type { MediaQualityMetadata } from '../MediaQualityMetadata'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\n\nexport interface QualitySelectorImplOptions {\n /**\n * If at least this amount of time (in seconds) is currently fetched, don't consider an ABR-down.\n * Also used as the upper bound for interpolating between {@link bandwidthMultiplierLow} and\n * {@link bandwidthMultiplierHigh} based on the current fetched time.\n * Default: 15\n */\n readonly highBufferThreshold?: number\n\n /**\n * If less than this amount of time (in seconds) is currently fetched, don't consider an ABR-up.\n * Default: 4\n */\n readonly lowBufferThreshold?: number\n\n /**\n * Defines the strategy used for quality selection.\n *\n * Default: BEST (ABR will be enabled)\n */\n readonly strategy?: AbrStrategy\n\n /**\n * A multiplier applied to the estimated bandwidth when the fetched buffer is empty (0 seconds).\n * Lower values are more conservative (reduce the bandwidth used for quality selection) and help\n * avoid rebuffers when the buffer is low.\n *\n * As the fetched buffer fills toward {@link highBufferThreshold}, the effective multiplier\n * linearly interpolates between this value and {@link bandwidthMultiplierHigh}.\n *\n * Default: 0.4\n */\n readonly bandwidthMultiplierLow?: number\n\n /**\n * A multiplier applied to the estimated bandwidth when the fetched buffer is at or above\n * {@link highBufferThreshold}. Higher values are more optimistic and allow selection of higher\n * qualities once enough data is buffered to absorb short-term bandwidth dips.\n *\n * As the fetched buffer fills from 0 toward {@link highBufferThreshold}, the effective multiplier\n * linearly interpolates between {@link bandwidthMultiplierLow} and this value.\n *\n * Default: 0.9\n */\n readonly bandwidthMultiplierHigh?: number\n\n /**\n * When true, avoids changing codecs when considering choosing a higher audio bitrate\n * than what is currently playing. A decoder re-initialization is often an audible change,\n * so consumers that prefer to avoid audible artifacts may enable this. ABR-down is still\n * allowed across decoders because the subtle audio artifact is more desirable than a rebuffer.\n * Default: false\n */\n readonly restrictDecoderChangeOnAudioAbrUp?: boolean\n\n /**\n * Maximum bandwidth in bits per second a quality may use to be selectable.\n *\n * Soft cap: if no qualities fit within the limit (including when set to 0),\n * the quality with the lowest bandwidth is selected so playback is still\n * possible.\n *\n * Has no effect when {@link strategy} is {@link AbrStrategy.LOWEST} or\n * {@link AbrStrategy.HIGHEST}, since those strategies pin the selection\n * regardless of bandwidth.\n *\n * Default: null (no limit).\n */\n readonly maxBandwidth?: Maybe<number>\n}\n\nexport enum AbrStrategy {\n /**\n * Selects lowest quality, regardless of bandwidth conditions.\n */\n LOWEST = 'lowest',\n\n /**\n * Selects highest quality, regardless of bandwidth conditions.\n */\n HIGHEST = 'highest',\n\n /**\n * Selects the best quality based on user bandwidth data.\n * Uses an EWMA estimation.\n */\n BEST = 'best',\n\n /**\n * Selects the initial quality based on bandwidth information, but will not change qualities mid-stream.\n *\n * May choose new quality after streaming clear, such as after a seek.\n */\n FIXED = 'fixed',\n}\n\nexport const qualitySelectorImplOptionsValidator: ObjectSchema<QualitySelectorImplOptions> =\n /* @__PURE__ */ object({\n highBufferThreshold: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n lowBufferThreshold: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n strategy: /* @__PURE__ */ /* @__PURE__ */ enumOf(AbrStrategy).optional(),\n bandwidthMultiplierLow: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n bandwidthMultiplierHigh: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n restrictDecoderChangeOnAudioAbrUp: /* @__PURE__ */ /* @__PURE__ */ boolean().optional(),\n maxBandwidth: /* @__PURE__ */ /* @__PURE__ */ /* @__PURE__ */ number().maybe().optional(),\n })\n\nexport const defaultQualitySelectorImplOptions = {\n highBufferThreshold: 15,\n lowBufferThreshold: 4,\n strategy: AbrStrategy.BEST,\n bandwidthMultiplierLow: 0.4,\n bandwidthMultiplierHigh: 0.9,\n restrictDecoderChangeOnAudioAbrUp: false,\n maxBandwidth: null,\n} as const satisfies QualitySelectorImplOptions\n\nexport interface QualitySelectorImplDeps {\n readonly options: ObservableValue<QualitySelectorImplOptions>\n}\n\nexport class QualitySelectorImpl\n implements QualitySelector, LogTarget, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'QualitySelectorImpl'\n }\n\n readonly logPrefix = /* @__PURE__ */ createLogPrefix(this)\n private _options: Required<QualitySelectorImplOptions> =\n defaultQualitySelectorImplOptions\n\n private disposer = /* @__PURE__ */ createDisposer()\n\n constructor(deps: QualitySelectorImplDeps) {\n const { add } = this.disposer\n add(\n deps.options.onData((v) => {\n this._options = { ...defaultQualitySelectorImplOptions, ...v }\n })\n )\n }\n\n get options(): Required<QualitySelectorImplOptions> {\n return this._options\n }\n\n selectQuality(\n qualities: readonly MediaQualityMetadata[],\n prefetchState: PrefetchState\n ): number {\n const {\n strategy,\n highBufferThreshold,\n lowBufferThreshold,\n bandwidthMultiplierLow,\n bandwidthMultiplierHigh,\n restrictDecoderChangeOnAudioAbrUp,\n maxBandwidth,\n } = this.options\n const previousQuality = prefetchState.previousQuality\n // previousIndex will be -1 if the previously playing quality is not within the current qualities list.\n const previousIndex =\n previousQuality == null\n ? -1\n : qualities.findIndex(\n (quality) =>\n quality.qualityId === previousQuality.qualityId\n )\n\n if (strategy === AbrStrategy.LOWEST) {\n return qualities.length - 1\n } else if (strategy === AbrStrategy.HIGHEST) {\n return 0\n } else if (strategy === AbrStrategy.FIXED) {\n if (previousIndex >= 0) return previousIndex\n }\n\n const fetchedTime = prefetchState.fetchedTime\n const bandwidthEstimate = getNetworkMetrics().estimatedDownlinkBandwidth\n // Interpolate the bandwidth multiplier between the low and high values based on how much\n // buffer is currently fetched. An empty buffer uses bandwidthMultiplierLow (conservative)\n // to reduce rebuffer risk; a buffer at or above highBufferThreshold uses\n // bandwidthMultiplierHigh (optimistic) since buffered data can absorb short-term dips.\n // The interpolation is linear with respect to the buffer ratio.\n // If the track is not active (i.e. prefetch), always use the high multiplier.\n const bufferRatio =\n highBufferThreshold > 0\n ? clamp(fetchedTime / highBufferThreshold, 0, 1)\n : 1\n const bandwidthMultiplier = prefetchState.active\n ? lerp(bandwidthMultiplierLow, bandwidthMultiplierHigh, bufferRatio)\n : bandwidthMultiplierHigh\n\n // Choose bandwidth based on pessimistic network information.\n // If the track is active, take the lesser of the latest recorded bandwidth stat and the weighted\n // average to allow for fast ABR-down in variable conditions.\n let bandwidth =\n (prefetchState.active\n ? Math.min(bandwidthEstimate.ewmaLow, bandwidthEstimate.latest)\n : bandwidthEstimate.ewmaLow) * bandwidthMultiplier\n\n // Apply the maxBandwidth cap as a soft upper bound on the bandwidth budget.\n if (maxBandwidth != null && maxBandwidth < bandwidth) {\n bandwidth = maxBandwidth\n }\n\n let restrictDecoderId: string | null = null\n let restrictSwitchingGroupIds: readonly string[] | null = null\n if (previousQuality && previousIndex >= 0) {\n // Restrict to qualities whose groupId is in the previous quality's switching group.\n // Null switchingGroupIds means no switching constraint.\n if (previousQuality.switchingGroupIds != null) {\n restrictSwitchingGroupIds = previousQuality.switchingGroupIds\n }\n\n // Intra-track ABR rules\n if (\n previousQuality.bandwidthTotal &&\n bandwidth < previousQuality.bandwidthTotal\n ) {\n // Measured bandwidth lower than current streaming bandwidth.\n if (fetchedTime >= highBufferThreshold) {\n // Do not ABR-down inter-track when there is ample fetched data.\n return previousIndex\n }\n } else {\n if (fetchedTime < lowBufferThreshold) {\n // Do not ABR-up inter-track when there is not enough fetched data.\n return previousIndex\n }\n\n // Measured bandwidth is at least current streaming bandwidth.\n // Restrict to the previous decoder id for audio to avoid an audible artifact\n // from decoder re-initialization.\n if (\n restrictDecoderChangeOnAudioAbrUp &&\n previousQuality.contentType === 'audio'\n ) {\n restrictDecoderId = previousQuality.decoderId\n }\n }\n }\n const index = qualities.findIndex((quality) => {\n if (\n restrictSwitchingGroupIds != null &&\n !restrictSwitchingGroupIds.includes(quality.groupId)\n )\n return false\n if (\n restrictDecoderId != null &&\n quality.decoderId !== restrictDecoderId\n )\n return false\n return (\n quality.bandwidthTotal == null ||\n quality.bandwidthTotal <= bandwidth\n )\n })\n return index === -1 ? qualities.length - 1 : index\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose() {\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DashTrackDeps, DashTrackLoadOptions } from './DashTrack'\nimport { type Maybe, type RequestInterceptor } from '@amazon/vinyl-util'\nimport { pickFirstBaseUrlSelector } from './util/uriResolution'\nimport { createDefaultDashManifestTransformer } from './createDefaultDashManifestTransformer'\nimport { createMediaSource } from '../../util/media/mediaSource'\nimport {\n createDefaultDashMediaQualityMetadataResolver,\n type DashMediaQualityMetadataResolverDeps,\n} from './DashMediaQualityMetadataResolver'\nimport {\n MediaSourceControllerImpl,\n type MediaSourceControllerImplDeps,\n} from '../../streaming/buffering/MediaSourceController'\nimport type { PlaybackController } from '../../playback/PlaybackController'\nimport {\n type DashManifestController,\n DashManifestControllerImpl,\n type DashManifestControllerImplDeps,\n} from './DashManifestController'\nimport { createDashContentStreamFactories } from './createDashContentStreamFactories'\nimport type { DrmKeySystemResolver } from '../../drm/DrmKeySystemResolver'\nimport type { DrmController } from '../../drm/DrmController'\nimport type { Capabilities } from '../../client/Capabilities'\nimport {\n QualitySelectorImpl,\n type QualitySelectorImplOptions,\n} from '../../streaming/abr/QualitySelectorImpl'\nimport type { PlaybackSource } from '../../playback/PlaybackSource'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport { createDashManifestProvider } from './createDashManifestProvider'\nimport { createContentStreamFactory } from '../../streaming/ContentStream'\nimport type { ContentStreamingOptions } from '../../streaming/ContentStreamingOptions'\nimport { createDashContentTypesValue } from './createDashContentTypesValue'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { VinylOptions } from '../../vinyl/VinylOptions'\nimport {\n buildDashMediaTimeline,\n type BuildDashMediaTimelineDeps,\n} from './buildDashMediaTimeline'\nimport { createDefaultMediaTimelineTransformer } from '../../streaming/createDefaultMediaTimelineTransformer'\nimport type { DashManifestData } from './DashManifestProvider'\n\n/**\n * Player-level dependencies needed for the Dash-specific factories.\n */\nexport interface DashFactoryDeps {\n readonly options: ObservableValue<{\n readonly abr: QualitySelectorImplOptions\n readonly preferredAudioLanguage: string | null\n }>\n readonly playbackController: PlaybackController\n readonly playbackSource: PlaybackSource\n readonly drmKeySystemResolver: DrmKeySystemResolver\n readonly requestInterceptor: RequestInterceptor\n readonly drmController: DrmController\n readonly capabilities: Capabilities\n}\n\nexport type DashInitOptions = {\n readonly streaming?: Maybe<ContentStreamingOptions>\n}\n\n/**\n * Returns a function that provides default dependency factories required for\n * a new DashTrack.\n */\nexport function createDashFactories(options: Maybe<DashInitOptions>) {\n return (\n // Player-level dependencies\n deps: DashFactoryDeps\n ) => {\n return (loadOptions: DashTrackLoadOptions) =>\n validateFactories({\n // Track-level dependencies\n ...externalDependencies(deps),\n\n contentTypesValue: createDashContentTypesValue,\n baseUrlSelector: () => pickFirstBaseUrlSelector,\n segmentRequestInit: () => loadOptions.segmentRequestInit,\n manifestProvider: createDashManifestProvider(loadOptions),\n manifestController: (\n deps: DashManifestControllerImplDeps\n ): DashManifestController =>\n new DashManifestControllerImpl(deps),\n mediaSourceFactory: () => createMediaSource,\n mediaQualityMetadataResolver: (\n deps: DashMediaQualityMetadataResolverDeps\n ) => createDefaultDashMediaQualityMetadataResolver(deps),\n mediaSourceController: (deps: MediaSourceControllerImplDeps) =>\n new MediaSourceControllerImpl(deps),\n\n createContentStreamFactories: createDashContentStreamFactories(\n options?.streaming\n ),\n contentStreamFactory: createContentStreamFactory,\n\n qualitySelector: (deps: {\n options: ObservableValue<Pick<VinylOptions, 'abr'>>\n }) =>\n new QualitySelectorImpl({\n options: deps.options.pick('abr'),\n }),\n manifestTransformed: createDefaultDashManifestTransformer,\n mediaTimeline: (\n deps: BuildDashMediaTimelineDeps & {\n readonly manifestTransformed: ObservableValue<\n Promise<DashManifestData>\n >\n }\n ) =>\n deps.manifestTransformed.map(async (manifestPromise) => {\n const data = await manifestPromise\n return buildDashMediaTimeline(deps, data)\n }),\n mediaTimelineTransformed: createDefaultMediaTimelineTransformer,\n } as const) satisfies Factories<DashTrackDeps>\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe } from '@amazon/vinyl-util'\nimport type { RequestInitOptions } from '@amazon/vinyl-util'\nimport type {\n MutableRequestParams,\n RequestInterceptor,\n} from '@amazon/vinyl-util'\nimport { noop } from '@amazon/vinyl-util'\nimport { clone, getLocation, resolveUrl } from '@amazon/vinyl-util'\nimport { requestWithRetry } from '@amazon/vinyl-util'\nimport { parseDashManifest } from '@amazon/vinyl-mpd-parser'\nimport type { DashManifestProvider } from './DashManifestProvider'\n\n/**\n * Creates a DashManifestProvider which performs a request to retrieve a dash manifest.\n * Can be a relative path.\n *\n * Usage example:\n *\n * ```createRequesterDashManifestProvider('https://example.com/manifest.mpd')```\n * @param input The resource location of the dash manifest.\n * @param init Optional request options such as headers.\n * @param requestInterceptor An optional transformer to mutate request parameters before the request is made.\n */\nexport function urlDashManifestProvider(\n input: string,\n init?: Maybe<RequestInitOptions>,\n requestInterceptor: RequestInterceptor = noop\n): DashManifestProvider {\n return async (abort) => {\n const params: MutableRequestParams = {\n input: resolveUrl(input, getLocation().href),\n init: clone(init) ?? {},\n }\n requestInterceptor(params)\n const response = await requestWithRetry(params.input, params.init, {\n abort,\n })\n const xml = await response.text()\n const manifest = parseDashManifest(xml)\n const baseInput = response.url || params.input\n return {\n manifest,\n baseUrl: resolveUrl('./', baseInput),\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DashTrackLoadOptions } from './DashTrack'\nimport { urlDashManifestProvider } from './urlDashManifestProvider'\nimport type { RequestInterceptor } from '@amazon/vinyl-util'\n\n/**\n * Creates a DashManifestProvider which uses the manifestProvider set on the loadOptions, or a urlDashManifestProvider\n * if unset, which will use the loadOptions.uri as the manifest location.\n *\n * @param loadOptions\n */\nexport function createDashManifestProvider(loadOptions: DashTrackLoadOptions) {\n return (deps: { readonly requestInterceptor: RequestInterceptor }) => {\n return loadOptions.manifestProvider\n ? loadOptions.manifestProvider\n : urlDashManifestProvider(\n loadOptions.uri,\n loadOptions.requestInit,\n deps.requestInterceptor\n )\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createDisposer,\n type Disposable,\n EventHostImpl,\n type Maybe,\n type ReadonlyEventHost,\n type ReadonlyRanges,\n redispatchEvents,\n} from '@amazon/vinyl-util'\nimport type { StreamingEventMap } from './StreamingEventMap'\nimport type { SegmentController } from './SegmentController'\nimport type { BufferingController } from './buffering/BufferingController'\nimport type { ContentType, MediaQualityMetadata } from './MediaQualityMetadata'\nimport { createContainer, type Factories } from '@amazon/vinyl-di'\n\n/**\n * Creates a new ContentStream for the given content type.\n */\nexport type ContentStreamFactory = (contentType: ContentType) => ContentStream\n\nexport interface ContentStream\n extends ReadonlyEventHost<StreamingEventMap>, Disposable {\n /**\n * The content type for this stream.\n * E.g. 'audio' or 'video'\n */\n readonly contentType: ContentType\n\n /**\n * The prefetched time ranges.\n */\n readonly fetchedRanges: ReadonlyRanges\n\n /**\n * The quality currently being requested.\n */\n readonly streamingQuality: MediaQualityMetadata | null\n\n /**\n * The quality of the currently buffered media for this stream.\n */\n readonly bufferingQuality: MediaQualityMetadata | null\n\n /**\n * The quality for the currently buffered media at currentTime for this stream.\n */\n readonly playbackQuality: MediaQualityMetadata | null\n\n /**\n * The error, if in an error state.\n */\n readonly error: Error | null\n\n /**\n * True if the last segment has been appended.\n */\n readonly bufferingEnded: boolean\n\n /**\n * Starts prefetching with the given priority and prefetch start time.\n * @param options\n */\n preload(options: ContentStreamPreloadOptions): void\n\n clearPrefetch(): void\n\n /**\n * Resets the track to recover from error states.\n * Resets both the segment controller and buffering controller to clear failed segments and error conditions.\n */\n reset(): void\n\n /**\n * Activates the content stream, activating sub-controllers.\n */\n activate(options: ContentStreamActivateOptions): void\n\n /**\n * Deactivates the content stream, deactivating sub-controllers.\n */\n deactivate(): void\n}\n\nexport interface ContentStreamPreloadOptions {\n /**\n * Track priority for prefetching.\n * Higher values take precedence.\n */\n readonly prefetchPriority: number\n\n /**\n * The media presentation time (in seconds) to begin prefetching.\n */\n readonly startTime?: Maybe<number>\n}\n\nexport interface ContentStreamActivateOptions {\n /**\n * The media presentation time (in seconds) to seek to.\n */\n readonly startTime?: Maybe<number>\n}\n\nexport interface ContentStreamImplDeps {\n readonly bufferingController: BufferingController\n readonly segmentController: SegmentController\n}\n\nexport class ContentStreamImpl\n extends EventHostImpl<StreamingEventMap>\n implements ContentStream\n{\n private disposer = /* @__PURE__ */ createDisposer()\n private readonly segmentController: SegmentController\n private readonly bufferingController: BufferingController\n\n constructor(\n dependencyFactories: Factories<ContentStreamImplDeps>,\n readonly contentType: ContentType\n ) {\n super()\n const { add } = this.disposer\n const deps = add(createContainer(dependencyFactories)).dependencies\n\n this.segmentController = deps.segmentController\n redispatchEvents(this, this.segmentController, ['fetchedRangesChange'])\n\n this.bufferingController = deps.bufferingController\n redispatchEvents(this, this.segmentController, [\n 'streamingQualityChange',\n ])\n redispatchEvents(this, this.bufferingController, [\n 'bufferingQualityChange',\n 'playbackQualityChange',\n 'bufferingEnded',\n 'error',\n ])\n }\n\n preload(options: ContentStreamPreloadOptions) {\n this.segmentController.configure({\n startTime: options.startTime ?? 0,\n trackPrefetchPriority: options.prefetchPriority,\n })\n }\n\n get fetchedRanges(): ReadonlyRanges {\n return this.segmentController.fetchedRanges\n }\n\n get streamingQuality(): MediaQualityMetadata | null {\n return this.segmentController.streamingQuality ?? null\n }\n\n get bufferingQuality(): MediaQualityMetadata | null {\n return this.bufferingController.bufferingQuality ?? null\n }\n\n get playbackQuality(): MediaQualityMetadata | null {\n return this.bufferingController.playbackQuality ?? null\n }\n\n get bufferingEnded(): boolean {\n return this.bufferingController.bufferingEnded\n }\n\n get error(): Error | null {\n return this.bufferingController.error ?? this.segmentController.error\n }\n\n /**\n * Clears all fetched fragments and source buffers. Streaming will resume.\n * This should be called if a change has been made where the user would expect an immediate change,\n * for example, changing streaming quality from SD to HD.\n */\n clearPrefetch() {\n this.segmentController.clear()\n this.bufferingController.clear()\n }\n\n /**\n * Resets the track to recover from error states.\n * Resets both the segment controller and buffering controller to clear failed segments and error conditions.\n */\n reset(): void {\n this.segmentController.reset()\n this.bufferingController.reset()\n }\n\n activate(options: ContentStreamActivateOptions): void {\n this.segmentController.configure({\n startTime: options.startTime ?? 0,\n })\n this.segmentController.activate()\n this.bufferingController.activate()\n }\n\n deactivate(): void {\n this.segmentController.deactivate()\n this.bufferingController.deactivate()\n }\n\n dispose(): void {\n super.dispose()\n this.disposer.dispose()\n }\n}\n\n/**\n * The `Factory` to create a function which satisfies `ContentStreamFactory`.\n */\nexport function createContentStreamFactory(deps: {\n readonly createContentStreamFactories: (\n contentType: ContentType\n ) => Factories<ContentStreamImplDeps>\n}) {\n return ((contentType: ContentType) => {\n return new ContentStreamImpl(\n deps.createContentStreamFactories(contentType),\n contentType\n )\n }) satisfies ContentStreamFactory\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DashManifestData } from './DashManifestProvider'\nimport type { DashMediaQualityMetadataResolver } from './DashMediaQualityMetadataResolver'\nimport { flattenRepresentations } from './util/mpd'\nimport type { ContentType } from '../../streaming/MediaQualityMetadata'\nimport type { ContentTypesValue } from '../../streaming/ContentTypesValue'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { DashManifest } from '@amazon/vinyl-mpd-parser'\n\nexport interface DashContentTypesValueDeps {\n readonly manifestTransformed: ObservableValue<Promise<DashManifestData>>\n readonly mediaQualityMetadataResolver: DashMediaQualityMetadataResolver\n}\n\n/**\n * Creates an ObservableValue for the types of streams that are available in the\n * filtered dash manifest.\n */\nexport function createDashContentTypesValue(\n deps: DashContentTypesValueDeps\n): ContentTypesValue {\n return deps.manifestTransformed.map(async (manifestAndPath) => {\n return getContentTypes(deps, (await manifestAndPath).manifest)\n })\n}\n\n/**\n * Determines the types of streams that are available in the filtered dash\n * manifest.\n *\n * Given a Dash manifest, this will resolve to the set of content types present.\n */\nfunction getContentTypes(\n deps: DashContentTypesValueDeps,\n manifest: DashManifest\n): Set<ContentType> {\n const contentTypes = new Set<ContentType>()\n for (const period of manifest.MPD.Period) {\n if (!period.AdaptationSet) continue\n const mediaMetadata = flattenRepresentations(period).map(\n deps.mediaQualityMetadataResolver\n )\n for (const { contentType } of mediaMetadata) {\n if (contentType) contentTypes.add(contentType)\n }\n }\n return contentTypes\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Maybe, MaybePromise } from '@amazon/vinyl-util'\nimport {\n ErrorOrigin,\n getSidxSampleTimes,\n parseSidxBox,\n ValidationError,\n} from '@amazon/vinyl-util'\nimport type {\n ByteRange,\n MultipleSegmentBaseType,\n RepresentationType,\n SegmentBaseType,\n SegmentListType,\n SegmentTemplateType,\n SegmentTimelineType,\n} from '@amazon/vinyl-mpd-parser'\nimport {\n calculatePeriodTimeRange,\n getSegmentBase,\n getSegmentList,\n getSegmentTemplate,\n type PeriodRange,\n sampleToMpdTime,\n} from '../util/mpd'\nimport {\n type DashUriResolveDeps,\n resolveDashUri,\n segmentTemplateUrl,\n} from '../util/uriResolution'\nimport {\n createSegmentDataProvider,\n type CreateSegmentDataProviderDeps,\n} from '../../createSegmentDataProvider'\nimport { getSegmentAtTime } from '../../../streaming/util/segment'\nimport type {\n MediaSegmentReference,\n SegmentReference,\n} from '../../../streaming/SegmentReference'\nimport type { SegmentDataProvider } from '../../../streaming/SegmentDataSlot'\nimport type { MediaQualityMetadata } from '../../../streaming/MediaQualityMetadata'\nimport type { DashMediaQualityMetadataResolver } from '../DashMediaQualityMetadataResolver'\n\nexport interface DashSegmentProviderDeps\n extends DashUriResolveDeps, CreateSegmentDataProviderDeps {\n /**\n * Produces abstract metadata from a dash representation.\n */\n readonly mediaQualityMetadataResolver: DashMediaQualityMetadataResolver\n}\n\nexport interface DashRepresentationSegmentProvider {\n /**\n * Gets a segment reference within this representation for the given time, in seconds, relative to the period.\n *\n * @param time\n * @param affordance Forward-snap tolerance in seconds: if `time` falls just before a\n * segment's start (within `affordance`), that segment is returned. Defaults to `0`.\n */\n getSegment(\n time: number,\n affordance?: number\n ): Promise<SegmentReference<SegmentDataProvider> | null>\n}\n\ninterface GetTimelineOptions {\n readonly baseUrl: string\n readonly representation: RepresentationType\n readonly periodTimeRange: PeriodRange\n}\n\n/**\n * Metadata and a data provider for a segment.\n */\ntype DataSegmentRef = MediaSegmentReference<SegmentDataProvider>\n\n/**\n * Creates a representation timeline for the given representation.\n */\nexport function createDashRepresentationSegmentProvider(\n deps: DashSegmentProviderDeps,\n baseUrl: string,\n representation: RepresentationType\n): DashRepresentationSegmentProvider {\n const quality: MediaQualityMetadata =\n deps.mediaQualityMetadataResolver(representation)\n const options: GetTimelineOptions = {\n baseUrl,\n periodTimeRange: calculatePeriodTimeRange(representation.parent.parent),\n representation,\n }\n\n // 5.3.9.1 General\n // The elements SegmentBase, SegmentTemplate and SegmentList may be present in the\n // Representation element itself. In addition, to express default values, they may be present in the\n // Period and AdaptationSet element. At each level at most one of the three, SegmentBase,\n // SegmentTemplate and SegmentList, shall be present. Further, if SegmentTemplate or SegmentList is present on\n // one level of the hierarchy, then the other one shall not be present on any lower hierarchy level.\n\n const segmentTemplate = getSegmentTemplate(representation)\n const segmentList = getSegmentList(representation)\n const segmentBase = getSegmentBase(representation)\n\n let segmentsPromise: MaybePromise<\n readonly MediaSegmentReference<SegmentDataProvider>[]\n > | null = null\n\n let initUri: Maybe<string>\n let initRange: Maybe<ByteRange>\n\n if (segmentTemplate?.initialization) {\n initUri = segmentTemplateUrl(segmentTemplate.initialization, {\n representation,\n })\n }\n\n const commonSegmentBase = segmentTemplate ?? segmentList ?? segmentBase\n if (!commonSegmentBase)\n throw new ValidationError(\n 'Manifest must have one of SegmentList, SegmentTemplate, or SegmentBase',\n ErrorOrigin.MEDIA\n )\n\n if (commonSegmentBase.Initialization) {\n initUri = commonSegmentBase.Initialization.sourceURL\n initRange = commonSegmentBase.Initialization.range\n }\n\n if (!initUri && !initRange)\n throw new ValidationError(\n 'Missing initialization range',\n ErrorOrigin.MEDIA\n )\n\n const { url: initUrl, serviceLocation: initServiceLocation } =\n resolveDashUri(deps, { baseUrl, representation, uri: initUri })\n const initData = createSegmentDataProvider(deps, {\n url: initUrl,\n mediaRange: initRange,\n serviceId: initServiceLocation,\n reportDownlinkMetrics: false,\n })\n\n let getSegmentReferences: () => MaybePromise<\n readonly MediaSegmentReference<SegmentDataProvider>[]\n >\n\n // If an index range is present, use that to calculate segment data.\n // The index location may be defined in several locations:\n // SegmentBase.indexRange, SegmentBase.RepresentationIndex, or SegmentTemplate.index\n // One of segmentList, segmentTemplate, or segmentBase is guaranteed to be set.\n if (segmentList) {\n getSegmentReferences = () =>\n createSegmentsFromSegmentList(deps, {\n ...options,\n segmentList,\n })\n } else if (segmentTemplate) {\n getSegmentReferences = () =>\n createSegmentsFromSegmentTemplate(deps, {\n ...options,\n segmentTemplate,\n })\n } else if (segmentBase) {\n getSegmentReferences = () =>\n createSegmentsFromSegmentBase(deps, {\n ...options,\n segmentBase,\n })\n }\n\n return {\n async getSegment(\n time: number,\n affordance = 0\n ): Promise<SegmentReference<SegmentDataProvider> | null> {\n if (!segmentsPromise) segmentsPromise = getSegmentReferences()\n const segments = await Promise.resolve(segmentsPromise).catch(\n (error) => {\n // When the segments list fails (for example the sidx range request fails),\n // retry on the next request.\n segmentsPromise = null\n throw error\n }\n )\n const segment = getSegmentAtTime(time, segments, affordance)\n if (!segment) return null\n return {\n quality,\n ...segment,\n initData,\n }\n },\n }\n}\n\n/**\n * Creates a segment list when the representation has a SegmentList.\n */\nfunction createSegmentsFromSegmentList(\n deps: DashSegmentProviderDeps,\n options: GetTimelineOptions & {\n readonly segmentList: SegmentListType\n }\n): readonly DataSegmentRef[] {\n const { baseUrl, periodTimeRange, representation, segmentList } = options\n const segmentUrls = segmentList.SegmentURL\n if (segmentUrls) {\n // Fabricate a segment timeline from the segment duration.\n const timescale = getTimescale(segmentList)\n const sampleTimes = calculateSegmentSampleTimes({\n multipleSegmentBase: segmentList,\n periodTimeRange,\n numSegments: segmentUrls.length,\n })\n const presentationTimeOffset = segmentList.presentationTimeOffset ?? 0\n\n return createTimeline(\n {\n sampleTimes,\n presentationTimeOffset,\n periodTimeRange,\n timescale,\n },\n (i) => {\n const segmentUrl = segmentUrls[i]\n const { url, serviceLocation } = resolveDashUri(deps, {\n baseUrl,\n uri: segmentUrl.media,\n representation,\n })\n return createSegmentDataProvider(deps, {\n url,\n mediaRange: segmentUrl.mediaRange,\n serviceId: serviceLocation,\n reportDownlinkMetrics: true,\n })\n }\n )\n } else {\n if (segmentList.href) {\n throw new ValidationError(\n 'SegmentList.href currently unsupported',\n ErrorOrigin.MEDIA\n )\n } else {\n throw new ValidationError(\n 'could not determine segments from SegmentList',\n ErrorOrigin.MEDIA\n )\n }\n }\n}\n\n/**\n * SegmentTemplate contains URIs with template tokens, as defined in 5.3.9.4.4.\n *\n * @see segmentTemplateUrl\n */\nfunction createSegmentsFromSegmentTemplate(\n deps: DashSegmentProviderDeps,\n options: GetTimelineOptions & {\n readonly segmentTemplate: SegmentTemplateType\n }\n): readonly DataSegmentRef[] {\n const { baseUrl, periodTimeRange, representation, segmentTemplate } =\n options\n if (!segmentTemplate.media) {\n throw new ValidationError(\n 'SegmentTemplate.media required',\n ErrorOrigin.MEDIA\n )\n }\n const media = segmentTemplate.media\n const presentationTimeOffset = segmentTemplate.presentationTimeOffset ?? 0\n\n const sampleTimes = calculateSegmentSampleTimes({\n multipleSegmentBase: segmentTemplate,\n periodTimeRange,\n })\n\n const timescale = getTimescale(segmentTemplate)\n let segmentNumber = segmentTemplate.startNumber ?? 1\n return createTimeline(\n {\n timescale,\n presentationTimeOffset,\n periodTimeRange,\n sampleTimes,\n },\n (_, sampleTime) => {\n const uri = segmentTemplateUrl(media, {\n representation,\n sampleTime,\n segmentNumber: segmentNumber++,\n })\n const { url, serviceLocation } = resolveDashUri(deps, {\n baseUrl,\n uri,\n representation,\n })\n return createSegmentDataProvider(deps, {\n url,\n serviceId: serviceLocation,\n reportDownlinkMetrics: true,\n })\n }\n )\n}\n\n/**\n * When SegmentBase is provided, get the timeline from the index range.\n */\nasync function createSegmentsFromSegmentBase(\n deps: DashSegmentProviderDeps,\n options: GetTimelineOptions & {\n readonly segmentBase: SegmentBaseType\n }\n): Promise<readonly DataSegmentRef[]> {\n const { baseUrl, periodTimeRange, representation, segmentBase } = options\n if (segmentBase.indexRange) {\n // Load the sidx box from the mp4.\n const indexRange = segmentBase.indexRange\n const { url: indexUrl, serviceLocation: indexServiceLocation } =\n resolveDashUri(deps, { baseUrl, representation })\n const sidx = parseSidxBox(\n await createSegmentDataProvider(deps, {\n url: indexUrl,\n mediaRange: indexRange,\n serviceId: indexServiceLocation,\n reportDownlinkMetrics: false,\n })()\n )\n\n const sampleTimes = getSidxSampleTimes(sidx)\n let rangeStart = Number(sidx.firstOffset) + indexRange[1]! + 1\n return createTimeline(\n {\n sampleTimes,\n periodTimeRange,\n presentationTimeOffset: segmentBase.presentationTimeOffset ?? 0,\n timescale: sidx.timescale,\n },\n (i) => {\n const segmentReference = sidx.references[i]\n const size = segmentReference.referencedSize\n const provider = createSegmentDataProvider(deps, {\n url: indexUrl,\n mediaRange: [rangeStart, rangeStart + size - 1],\n serviceId: indexServiceLocation,\n reportDownlinkMetrics: true,\n })\n rangeStart += size\n return provider\n }\n )\n } else {\n throw new ValidationError('Manifest missing segments')\n }\n}\n\n/**\n * Returns an array of start times, in timescale units for the segments in the given multiple segment base.\n * The last time in the list will be the end time, in timescale units.\n */\nfunction calculateSegmentSampleTimes(options: {\n readonly multipleSegmentBase: MultipleSegmentBaseType\n readonly periodTimeRange: PeriodRange\n readonly numSegments?: Maybe<number>\n}): readonly number[] {\n const { multipleSegmentBase, periodTimeRange } = options\n const timescale = getTimescale(multipleSegmentBase)\n\n let startTimes: readonly number[]\n if (multipleSegmentBase.SegmentTimeline) {\n startTimes = calculateSampleTimesFromSegmentTimeline(\n multipleSegmentBase.SegmentTimeline\n )\n } else {\n // Fabricate a segment timeline from the segment duration.\n const sampleDuration = getSampleDuration(multipleSegmentBase) // The unscaled duration\n startTimes = calculateFixedSegmentSampleTimes({\n timescale,\n periodTimeRange,\n sampleDuration,\n numSegments: options.numSegments,\n })\n }\n return startTimes\n}\n\n/**\n * Given a SegmentTimeline element, calculates the sample start times of each segment, in timescale units.\n * The last time in the list will be the end time, in timescale units.\n */\nfunction calculateSampleTimesFromSegmentTimeline(\n segmentTimeline: SegmentTimelineType\n): readonly number[] {\n const out: number[] = new Array((segmentTimeline.S?.length ?? 0) + 1)\n let startTime = 0\n let c = 0\n\n segmentTimeline.S?.forEach((s) => {\n // If the start time 't' is defined, use it, otherwise use the calculated current time\n startTime = s.t != null ? s.t : startTime\n\n // Calculate segment details for the number of repeats\n for (let i = 0; i <= s.r; i++) {\n out[c++] = startTime\n startTime += s.d\n }\n })\n out[c++] = startTime\n return out\n}\n\n/**\n * Creates media segment sample start times, in timescale units, with a given duration.\n * The last time in the list will be the duration, in timescale units.\n *\n * @param options\n */\nfunction calculateFixedSegmentSampleTimes(options: {\n readonly sampleDuration: number\n readonly timescale: number\n readonly periodTimeRange: PeriodRange\n readonly numSegments?: Maybe<number>\n}): readonly number[] {\n const { sampleDuration, timescale } = options\n const [periodStart, periodEnd] = options.periodTimeRange\n if (periodEnd == null)\n throw new ValidationError(\n 'MPD.mediaPresentationDuration or Period.duration required',\n ErrorOrigin.MEDIA\n )\n const numSegments =\n options.numSegments ??\n Math.ceil((periodEnd - periodStart) / (sampleDuration / timescale))\n const out: number[] = new Array(numSegments + 1)\n let startTime = 0\n for (let i = 0; i < numSegments; i++) {\n out[i] = startTime\n startTime += sampleDuration\n }\n out[numSegments] = periodEnd * timescale\n return out\n}\n\n/**\n * Creates a timeline of DataSegmentRef objects from a sample timeline list and a data provider factory.\n *\n * @param sampleTimes The list of sample times, in timescale units, to convert into MPD presentation times.\n * @param periodTimeRange The time range of the period, in seconds.\n * @param presentationTimeOffset The presentation time offset, in samples per second.\n * @param timescale The timescale units, in samples per second.\n * @param dataProviderFactory Creates the data provider for the segment at the given index and sample start time.\n */\nfunction createTimeline(\n {\n sampleTimes,\n periodTimeRange,\n presentationTimeOffset,\n timescale,\n }: {\n sampleTimes: readonly number[]\n periodTimeRange: PeriodRange\n presentationTimeOffset: number\n timescale: number\n },\n dataProviderFactory: (i: number, sampleTime: number) => SegmentDataProvider\n): readonly DataSegmentRef[] {\n const [periodStart, periodEnd] = periodTimeRange\n const mpdTimes = sampleTimes.map((sampleTime) => {\n return sampleToMpdTime(\n sampleTime,\n periodStart,\n presentationTimeOffset,\n timescale\n )\n })\n const n = mpdTimes.length - 1\n const out = new Array<DataSegmentRef>(n)\n for (let i = 0; i < n; i++) {\n const startTime = mpdTimes[i]\n const endTime = mpdTimes[i + 1]\n out[i] = {\n data: dataProviderFactory(i, sampleTimes[i]),\n timestampOffset: startTime,\n startTime: Math.max(periodStart, startTime),\n endTime: periodEnd == null ? endTime : Math.min(periodEnd, endTime),\n }\n }\n return out\n}\n\n/**\n * Validates that timescale is set, returning it.\n *\n * @param multipleSegmentBase\n */\nfunction getTimescale(multipleSegmentBase: MultipleSegmentBaseType): number {\n if (!multipleSegmentBase.timescale)\n throw new ValidationError('invalid timescale', ErrorOrigin.MEDIA)\n return multipleSegmentBase.timescale\n}\n\n/**\n * Validates that duration is set, returning it.\n *\n * @param multipleSegmentBase\n */\nfunction getSampleDuration(\n multipleSegmentBase: MultipleSegmentBaseType\n): number {\n if (!multipleSegmentBase.duration)\n throw new ValidationError('invalid duration', ErrorOrigin.MEDIA)\n return multipleSegmentBase.duration\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n Maybe,\n Mutable,\n MutableRequestParams,\n ReadonlyAbort,\n RequestInitOptions,\n RequestInterceptor,\n Timestamp,\n} from '@amazon/vinyl-util'\nimport {\n getHostname,\n last,\n networkMetricsController,\n normalizeHeadersInit,\n requestWithRetry,\n} from '@amazon/vinyl-util'\nimport { type ByteRange, stringifyByteRange } from '@amazon/vinyl-mpd-parser'\nimport type { SegmentDataProvider } from '../streaming/SegmentDataSlot'\n\nexport interface CreateSegmentDataProviderDeps {\n readonly requestInterceptor: RequestInterceptor\n readonly segmentRequestInit: Maybe<RequestInitOptions>\n}\n\nexport interface CreateSegmentDataProviderOptions {\n readonly url: string\n readonly mediaRange?: Maybe<ByteRange>\n readonly serviceId?: Maybe<string>\n /**\n * If true, reports downlink transfer speeds to network metrics.\n */\n readonly reportDownlinkMetrics: boolean\n}\n\nexport function createSegmentDataProvider(\n deps: CreateSegmentDataProviderDeps,\n options: CreateSegmentDataProviderOptions\n): SegmentDataProvider {\n return async (abort?: Maybe<ReadonlyAbort>) => {\n const init: Mutable<RequestInitOptions> = {\n ...deps.segmentRequestInit,\n }\n if (options.mediaRange) {\n init.headers = {\n ...normalizeHeadersInit(init.headers),\n Range: `bytes=${stringifyByteRange(options.mediaRange)}`,\n }\n }\n\n const params: MutableRequestParams = {\n input: options.url,\n init,\n }\n deps.requestInterceptor(params)\n\n const serviceId = options.serviceId ?? getHostname(options.url)\n const requestStart = Date.now()\n const response = await requestWithRetry(params.input, params.init, {\n serviceId,\n abort,\n })\n const responseEnd = Date.now()\n\n const arrayBuffer = await response.arrayBuffer()\n const contentEnd = Date.now()\n\n let responseStart: Timestamp | null = null\n if ('getEntriesByName' in performance) {\n const lastRequest: any = last(\n performance.getEntriesByName(params.input)\n )\n if (lastRequest) {\n // Resource timing information was available, use it to get a more accurate response start time. A\n // value of 0 means timing information was denied, likely due to a cross-origin request without\n // Timing-Allow-Origin response headers.\n if (lastRequest.responseStart) {\n responseStart =\n performance.timeOrigin + lastRequest.responseStart\n }\n }\n }\n\n if (options.reportDownlinkMetrics) {\n networkMetricsController.value.addDownlinkTransferEntry({\n bytes: arrayBuffer.byteLength,\n serviceId,\n requestStart,\n responseStart,\n responseEnd,\n contentEnd,\n })\n }\n return arrayBuffer\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DashManifestData } from './DashManifestProvider'\nimport type {\n MediaPeriod,\n MediaQualityData,\n MediaTimeline,\n} from '../../streaming/MediaTimeline'\nimport type { RepresentationType } from '@amazon/vinyl-mpd-parser'\nimport {\n calculateDuration,\n calculatePeriodEnd,\n calculatePeriodStart,\n flattenRepresentations,\n} from './util/mpd'\nimport {\n createDashRepresentationSegmentProvider,\n type DashSegmentProviderDeps,\n} from './timeline/DashRepresentationSegmentProvider'\n\nexport type BuildDashMediaTimelineDeps = DashSegmentProviderDeps\n\n/**\n * Builds a MediaTimeline from a Dash manifest.\n */\nexport function buildDashMediaTimeline(\n deps: BuildDashMediaTimelineDeps,\n data: DashManifestData\n): MediaTimeline {\n const { manifest, baseUrl } = data\n const periods: MediaPeriod[] = manifest.MPD.Period.map((period) => {\n const startTime = calculatePeriodStart(period)\n const endTime = calculatePeriodEnd(period) ?? Infinity\n const representations = flattenRepresentations(period)\n const qualities: MediaQualityData[] = representations.map(\n (representation: RepresentationType): MediaQualityData => {\n const metadata =\n deps.mediaQualityMetadataResolver(representation)\n const segmentProvider = createDashRepresentationSegmentProvider(\n deps,\n baseUrl,\n representation\n )\n return {\n metadata,\n getSegment: (time: number, affordance?: number) =>\n segmentProvider.getSegment(time, affordance),\n }\n }\n )\n return { startTime, endTime, qualities }\n })\n const duration = calculateDuration(manifest)\n return {\n periods,\n minBufferTime: manifest.MPD.minBufferTime,\n getDuration: () => Promise.resolve(duration),\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { combineData } from '@amazon/vinyl-observable'\nimport type { Capabilities } from '../client/Capabilities'\nimport type { DrmController } from '../drm/DrmController'\nimport type { MediaTimeline } from './MediaTimeline'\nimport {\n filterTimelineQualities,\n filterTimelineQualitiesAsync,\n} from './mediaTimelineFilter'\nimport { createLanguageFilter } from './mediaTimelineLanguageFilter'\nimport {\n canPlayMimeType,\n throwMimeTypesUnsupported,\n} from '../track/filters/resourceTypeFilter'\nimport {\n canPlayKeySystem,\n throwKeySystemsUnsupported,\n} from '../track/filters/keySystemFilter'\nimport {\n supportsAudioSamplingRate,\n throwSamplingRatesUnsupported,\n} from '../track/filters/sampleRateFilter'\nimport { throwLanguagesUnsupported } from '../track/filters/languageFilter'\n\nexport interface DefaultMediaTimelineTransformerDeps {\n readonly capabilities: Capabilities\n readonly drmController: DrmController\n readonly mediaTimeline: ObservableValue<Promise<MediaTimeline>>\n readonly options: ObservableValue<{\n readonly preferredAudioLanguage: string | null\n }>\n}\n\n/**\n * The default media timeline transformer filters out unplayable qualities\n * and applies language preferences. Shared by Dash and HLS.\n */\nexport function createDefaultMediaTimelineTransformer(\n deps: DefaultMediaTimelineTransformerDeps\n): ObservableValue<Promise<MediaTimeline>> {\n async function transformTimeline(\n timeline: MediaTimeline\n ): Promise<MediaTimeline> {\n let t = filterTimelineQualities(\n (quality) => canPlayMimeType(deps, quality),\n throwMimeTypesUnsupported,\n timeline\n )\n t = await filterTimelineQualitiesAsync(\n (quality) => canPlayKeySystem(deps, quality),\n throwKeySystemsUnsupported,\n t\n )\n t = filterTimelineQualities(\n (quality, index, array) =>\n supportsAudioSamplingRate(deps, quality, index, array),\n throwSamplingRatesUnsupported,\n t\n )\n t = filterTimelineQualities(\n createLanguageFilter(\n deps.options.value.preferredAudioLanguage,\n 'audio'\n ),\n throwLanguagesUnsupported,\n t\n )\n return t\n }\n\n return combineData({\n timeline: deps.mediaTimeline,\n preferredAudioLanguage: deps.options.pick('preferredAudioLanguage'),\n }).map(async ({ timeline }) => {\n return transformTimeline(await timeline)\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n MediaPeriod,\n MediaQualityData,\n MediaTimeline,\n} from './MediaTimeline'\nimport type { MediaQualityMetadata } from './MediaQualityMetadata'\nimport type {\n FilterPredicate,\n FilterPredicateAsync,\n Maybe,\n} from '@amazon/vinyl-util'\nimport { map, memoize } from '@amazon/vinyl-util'\n\n/**\n * Filters qualities in a MediaTimeline using a synchronous predicate.\n * If filtering would remove all qualities from any period, throws via `throwError`.\n */\nexport function filterTimelineQualities(\n filter: Maybe<FilterPredicate<MediaQualityMetadata>>,\n throwError: () => never,\n timeline: MediaTimeline\n): MediaTimeline {\n if (!filter) return timeline\n const mapMetadataArray = memoize(\n (qualities: readonly MediaQualityData[]) =>\n map(qualities, (q) => q.metadata),\n (qualities) => qualities,\n 1\n )\n\n const periods = timeline.periods.map((period) => {\n const filtered = period.qualities.filter((q, index) =>\n filter(q.metadata, index, mapMetadataArray(period.qualities))\n )\n return { ...period, qualities: filtered }\n })\n\n if (periods.some((p) => p.qualities.length === 0)) {\n throwError()\n }\n\n return { ...timeline, periods }\n}\n\n/**\n * Filters qualities in a MediaTimeline using an asynchronous predicate.\n * If filtering would remove all qualities from any period, throws via `throwError`.\n */\nexport async function filterTimelineQualitiesAsync(\n filter: FilterPredicateAsync<MediaQualityMetadata>,\n throwError: () => never,\n timeline: MediaTimeline\n): Promise<MediaTimeline> {\n const mapMetadataArray = memoize(\n (qualities: readonly MediaQualityData[]) =>\n map(qualities, (q) => q.metadata),\n (qualities) => qualities,\n 1\n )\n\n const periods: MediaPeriod[] = []\n for (const period of timeline.periods) {\n const filtered: MediaQualityData[] = []\n const metadataArray = mapMetadataArray(period.qualities)\n for (let i = 0; i < period.qualities.length; i++) {\n if (await filter(period.qualities[i].metadata, i, metadataArray)) {\n filtered.push(period.qualities[i])\n }\n }\n periods.push({ ...period, qualities: filtered })\n }\n\n if (periods.some((p) => p.qualities.length === 0)) {\n throwError()\n }\n\n return { ...timeline, periods }\n}\n\n/**\n * Creates a language filter predicate for use with filterTimelineQualities.\n */\nexport { createLanguageFilter } from './mediaTimelineLanguageFilter'\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaQualityMetadata } from './MediaQualityMetadata'\nimport type { FilterPredicate } from '@amazon/vinyl-util'\nimport { memoize } from '@amazon/vinyl-util'\nimport {\n findBestLanguageMatch,\n languageRelatedness,\n} from '../track/filters/languageFilter'\n\n/**\n * Creates a filter predicate that keeps qualities matching the preferred language.\n * The best language match is computed per period (per unique array reference),\n * so periods with different available languages are handled independently.\n *\n * Qualities not matching the content type or without a language tag are always kept.\n *\n * @param preferredLanguage BCP 47 language tag, or null to keep all.\n * @param contentType Only filter qualities matching this content type (e.g. 'audio').\n */\nexport function createLanguageFilter(\n preferredLanguage: string | null,\n contentType: string\n): FilterPredicate<MediaQualityMetadata> | null {\n if (!preferredLanguage) return null\n\n // Finds the best language for the period by relevance.\n // If no languages are related, the first language will be chosen.\n const bestRelevanceForPeriod = memoize(\n (array: ArrayLike<MediaQualityMetadata>) => {\n const langs = Array.from(array)\n .filter((q) => q.contentType === contentType && q.lang)\n .map((q) => q.lang!)\n return languageRelatedness(\n preferredLanguage,\n findBestLanguageMatch(preferredLanguage, langs)!\n )\n },\n (array) => array,\n 1\n )\n\n return (quality, _index, array) => {\n if (quality.contentType !== contentType) return true\n if (!quality.lang) return true\n const bestScore = bestRelevanceForPeriod(array)\n return languageRelatedness(preferredLanguage, quality.lang) >= bestScore\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { compareBy, max, MediaUnsupportedError } from '@amazon/vinyl-util'\n\nexport function throwLanguagesUnsupported(): never {\n throw new MediaUnsupportedError(\n 'No content matching preferred language',\n 'language'\n )\n}\n\n/**\n * Map from ISO 639-2 (3-letter) to ISO 639-1 (2-letter) codes.\n * Covers the most common languages encountered in streaming media.\n */\nconst iso3to2 = /* @__PURE__ */ new Map<string, string>([\n ['aar', 'aa'],\n ['abk', 'ab'],\n ['afr', 'af'],\n ['aka', 'ak'],\n ['amh', 'am'],\n ['ara', 'ar'],\n ['arg', 'an'],\n ['asm', 'as'],\n ['ava', 'av'],\n ['ave', 'ae'],\n ['aym', 'ay'],\n ['aze', 'az'],\n ['bak', 'ba'],\n ['bam', 'bm'],\n ['bel', 'be'],\n ['ben', 'bn'],\n ['bis', 'bi'],\n ['bod', 'bo'],\n ['bos', 'bs'],\n ['bre', 'br'],\n ['bul', 'bg'],\n ['cat', 'ca'],\n ['ces', 'cs'],\n ['cha', 'ch'],\n ['che', 'ce'],\n ['chu', 'cu'],\n ['chv', 'cv'],\n ['cor', 'kw'],\n ['cos', 'co'],\n ['cre', 'cr'],\n ['cym', 'cy'],\n ['dan', 'da'],\n ['deu', 'de'],\n ['div', 'dv'],\n ['dzo', 'dz'],\n ['ell', 'el'],\n ['eng', 'en'],\n ['epo', 'eo'],\n ['est', 'et'],\n ['eus', 'eu'],\n ['ewe', 'ee'],\n ['fao', 'fo'],\n ['fas', 'fa'],\n ['fij', 'fj'],\n ['fin', 'fi'],\n ['fra', 'fr'],\n ['fry', 'fy'],\n ['ful', 'ff'],\n ['gla', 'gd'],\n ['gle', 'ga'],\n ['glg', 'gl'],\n ['glv', 'gv'],\n ['grn', 'gn'],\n ['guj', 'gu'],\n ['hat', 'ht'],\n ['hau', 'ha'],\n ['heb', 'he'],\n ['her', 'hz'],\n ['hin', 'hi'],\n ['hmo', 'ho'],\n ['hrv', 'hr'],\n ['hun', 'hu'],\n ['hye', 'hy'],\n ['ibo', 'ig'],\n ['ido', 'io'],\n ['iii', 'ii'],\n ['iku', 'iu'],\n ['ile', 'ie'],\n ['ina', 'ia'],\n ['ind', 'id'],\n ['ipk', 'ik'],\n ['isl', 'is'],\n ['ita', 'it'],\n ['jav', 'jv'],\n ['jpn', 'ja'],\n ['kal', 'kl'],\n ['kan', 'kn'],\n ['kas', 'ks'],\n ['kat', 'ka'],\n ['kau', 'kr'],\n ['kaz', 'kk'],\n ['khm', 'km'],\n ['kik', 'ki'],\n ['kin', 'rw'],\n ['kir', 'ky'],\n ['kom', 'kv'],\n ['kon', 'kg'],\n ['kor', 'ko'],\n ['kua', 'kj'],\n ['kur', 'ku'],\n ['lao', 'lo'],\n ['lat', 'la'],\n ['lav', 'lv'],\n ['lim', 'li'],\n ['lin', 'ln'],\n ['lit', 'lt'],\n ['ltz', 'lb'],\n ['lub', 'lu'],\n ['lug', 'lg'],\n ['mah', 'mh'],\n ['mal', 'ml'],\n ['mar', 'mr'],\n ['mkd', 'mk'],\n ['mlg', 'mg'],\n ['mlt', 'mt'],\n ['mon', 'mn'],\n ['mri', 'mi'],\n ['msa', 'ms'],\n ['mya', 'my'],\n ['nau', 'na'],\n ['nav', 'nv'],\n ['nbl', 'nr'],\n ['nde', 'nd'],\n ['ndo', 'ng'],\n ['nep', 'ne'],\n ['nld', 'nl'],\n ['nno', 'nn'],\n ['nob', 'nb'],\n ['nor', 'no'],\n ['nya', 'ny'],\n ['oci', 'oc'],\n ['oji', 'oj'],\n ['ori', 'or'],\n ['orm', 'om'],\n ['oss', 'os'],\n ['pan', 'pa'],\n ['pli', 'pi'],\n ['pol', 'pl'],\n ['por', 'pt'],\n ['pus', 'ps'],\n ['que', 'qu'],\n ['roh', 'rm'],\n ['ron', 'ro'],\n ['run', 'rn'],\n ['rus', 'ru'],\n ['sag', 'sg'],\n ['san', 'sa'],\n ['sin', 'si'],\n ['slk', 'sk'],\n ['slv', 'sl'],\n ['sme', 'se'],\n ['smo', 'sm'],\n ['sna', 'sn'],\n ['snd', 'sd'],\n ['som', 'so'],\n ['sot', 'st'],\n ['spa', 'es'],\n ['sqi', 'sq'],\n ['srd', 'sc'],\n ['srp', 'sr'],\n ['ssw', 'ss'],\n ['sun', 'su'],\n ['swa', 'sw'],\n ['swe', 'sv'],\n ['tah', 'ty'],\n ['tam', 'ta'],\n ['tat', 'tt'],\n ['tel', 'te'],\n ['tgk', 'tg'],\n ['tgl', 'tl'],\n ['tha', 'th'],\n ['tir', 'ti'],\n ['ton', 'to'],\n ['tsn', 'tn'],\n ['tso', 'ts'],\n ['tuk', 'tk'],\n ['tur', 'tr'],\n ['twi', 'tw'],\n ['uig', 'ug'],\n ['ukr', 'uk'],\n ['urd', 'ur'],\n ['uzb', 'uz'],\n ['ven', 've'],\n ['vie', 'vi'],\n ['vol', 'vo'],\n ['wln', 'wa'],\n ['wol', 'wo'],\n ['xho', 'xh'],\n ['yid', 'yi'],\n ['yor', 'yo'],\n ['zha', 'za'],\n ['zho', 'zh'],\n ['zul', 'zu'],\n // Bibliographic codes (ISO 639-2/B) that differ from terminological codes\n ['alb', 'sq'],\n ['arm', 'hy'],\n ['baq', 'eu'],\n ['bur', 'my'],\n ['chi', 'zh'],\n ['cze', 'cs'],\n ['dut', 'nl'],\n ['fre', 'fr'],\n ['geo', 'ka'],\n ['ger', 'de'],\n ['gre', 'el'],\n ['ice', 'is'],\n ['mac', 'mk'],\n ['mao', 'mi'],\n ['may', 'ms'],\n ['per', 'fa'],\n ['rum', 'ro'],\n ['slo', 'sk'],\n ['tib', 'bo'],\n ['wel', 'cy'],\n])\n\n/**\n * Normalizes a BCP 47 / RFC 5646 language tag.\n *\n * - Converts ISO 639-2 (3-letter) codes to ISO 639-1 (2-letter)\n * - Forces language to lowercase, region to uppercase\n * - Discards script/dialect subtags beyond language-REGION\n *\n * Examples: `eng` \u2192 `en`, `en-us` \u2192 `en-US`, `fra-CA` \u2192 `fr-CA`\n */\nexport function normalizeLanguage(locale: string): string {\n const parts = locale.split('-')\n let language = (parts[0] || '').toLowerCase()\n language = iso3to2.get(language) || language\n const region = parts[1] ? parts[1].toUpperCase() : ''\n return region ? `${language}-${region}` : language\n}\n\n/**\n * Computes a relatedness score between two language codes.\n * Higher is better. 0 means unrelated.\n *\n * - 4: exact match after normalization (e.g. `en-US` vs `en-US`)\n * - 3: candidate is parent of target (e.g. `en` vs `en-US`)\n * - 2: candidate is sibling of target (e.g. `en-CA` vs `en-US`)\n * - 1: candidate is child of target (e.g. `en-US` vs `en`)\n * - 0: unrelated\n */\nexport function languageRelatedness(target: string, candidate: string): number {\n const t = normalizeLanguage(target)\n const c = normalizeLanguage(candidate)\n\n if (c === t) return 4\n\n const tParts = t.split('-')\n const cParts = c.split('-')\n\n if (tParts[0] !== cParts[0]) return 0\n\n // candidate is parent of target: candidate has no region, target does\n if (cParts.length === 1 && tParts.length === 2) return 3\n\n // candidate is sibling: both have regions (different, since exact match already checked)\n if (cParts.length === 2 && tParts.length === 2) return 2\n\n // candidate is child of target: target has no region, candidate does\n return 1 // tParts.length === 1 && cParts.length === 2\n}\n\n/**\n * Finds the best language match from a set of available languages.\n * Returns the best matching language, or undefined if the set is empty.\n * When no language is related, the first available language is returned.\n */\nexport function findBestLanguageMatch(\n target: string,\n available: ArrayLike<string>\n): string | undefined {\n return max(\n available,\n compareBy((lang) => languageRelatedness(target, lang))\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Capabilities } from '../../client/Capabilities'\nimport type { MediaFormatMetadata } from '../../streaming/MediaQualityMetadata'\nimport { MediaUnsupportedError } from '@amazon/vinyl-util'\n\nexport function throwMimeTypesUnsupported(): never {\n throw new MediaUnsupportedError(\n 'No resource type supported (container/codec).',\n 'resource-type'\n )\n}\n\n/**\n * Returns true when the media's codec and container is supported.\n */\nexport function canPlayMimeType(\n deps: { readonly capabilities: Capabilities },\n metadata: MediaFormatMetadata\n): boolean {\n if (!metadata.mimeType) return false\n return deps.capabilities.canPlayTypeMse(metadata.mimeType)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaQualityMetadata } from '../../streaming/MediaQualityMetadata'\nimport { type DrmController } from '../../drm/DrmController'\nimport { MediaUnsupportedError } from '@amazon/vinyl-util'\n\nexport function throwKeySystemsUnsupported(): never {\n throw new MediaUnsupportedError('No key system supported.', 'key-system')\n}\n\n/**\n * Returns true when the media's key system is supported or the representation has no content protection.\n */\nexport async function canPlayKeySystem(\n deps: { readonly drmController: DrmController },\n metadata: MediaQualityMetadata\n): Promise<boolean> {\n if (!metadata.contentProtections.length) return true // Is not content protected.\n return (await deps.drmController.isSupported(metadata)).supported\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaQualityMetadata } from '../../streaming/MediaQualityMetadata'\nimport {\n hasBrowser,\n Browser,\n last,\n MediaUnsupportedError,\n every,\n map,\n min,\n} from '@amazon/vinyl-util'\nimport type { Capabilities } from '../../client/Capabilities'\n\nexport function throwSamplingRatesUnsupported(): never {\n throw new MediaUnsupportedError('No supported sample rate', 'sampling-rate')\n}\n\n/**\n * Returns true when the media's sampling rate is supported.\n * If Firefox (which does not support >48kHz), filter out all sampling rates above the supported sampling rate.\n * All other browsers filter out all sampling rates above the supported sampling rate unless this will filter all\n * and then do not filter the lowest sampling rate.\n */\nexport function supportsAudioSamplingRate(\n deps: { readonly capabilities: Capabilities },\n metadata: MediaQualityMetadata,\n _index: number,\n array: ArrayLike<MediaQualityMetadata>\n): boolean {\n const isFirefox = hasBrowser(Browser.FIREFOX)\n const maxSampleRate = deps.capabilities.sampleRate\n const samplingRate = last(metadata.audioSamplingRate)\n\n if (!samplingRate || !maxSampleRate) return true // sampling rate not set\n\n if (isFirefox) {\n // Firefox: filter out all sampling rates above 48_000 Hz\n return samplingRate <= 48_000\n }\n\n // Other browsers: filter out all sampling rates above supported unless this will filter all\n if (samplingRate <= maxSampleRate) return true\n\n // Check if filtering all would remove everything\n const allAboveMax = every(array, (item) => {\n const itemSamplingRate = last(item.audioSamplingRate)\n return itemSamplingRate != null && itemSamplingRate > maxSampleRate\n })\n\n if (allAboveMax) {\n // Find the lowest sampling rate and only allow that one\n const samplingRates = map(array, (item) =>\n last(item.audioSamplingRate)\n ).filter((rate): rate is number => rate != null)\n const lowestSamplingRate = min(samplingRates)\n return samplingRate === lowestSamplingRate\n }\n\n return false\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AlternativeRendition,\n VariantStream,\n} from '@amazon/vinyl-hls-parser'\nimport type { MediaQualityMetadata } from '../../streaming/MediaQualityMetadata'\nimport { codecToContentType, contentTypeToMimeType } from '../mse/codec'\n\nexport type HlsMediaQualityMetadataResolver = (\n variant: VariantStream,\n renditions: readonly AlternativeRendition[]\n) => MediaQualityMetadata\n\nexport function createDefaultHlsMediaQualityMetadataResolver(): HlsMediaQualityMetadataResolver {\n return (variant, renditions) => {\n const codecs = variant.codecs || null\n // Use the first codec to determine the primary content type.\n const contentType = codecs\n ? codecToContentType(codecs.split(',')[0])\n : null\n\n // Find matching audio rendition for language.\n const audioRendition = variant.audioGroup\n ? renditions.find(\n (r) => r.type === 'AUDIO' && r.groupId === variant.audioGroup\n )\n : undefined\n\n // Use the variant URI as the decoderId so each quality forces a decoder\n // re-initialization on switch.\n return {\n qualityId: `${variant.bandwidth}-${codecs ?? ''}`,\n decoderId: variant.uri,\n groupId: '0',\n switchingGroupIds: null,\n mimeType: contentType\n ? contentTypeToMimeType(contentType, codecs)\n : null,\n contentType,\n codecs,\n bandwidth: null,\n bandwidthTotal: variant.bandwidth,\n audioSamplingRate: null,\n width: variant.width ?? null,\n height: variant.height ?? null,\n frameRate: variant.frameRate\n ? ([variant.frameRate, 1] as const)\n : null,\n lang: audioRendition?.language ?? null,\n contentProtections: [],\n encryptionScheme: null,\n initDataType: null,\n supplementalProperties: {},\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { data } from '@amazon/vinyl-observable'\nimport { createAbortSlot, createDisposer, logDebug } from '@amazon/vinyl-util'\nimport type { ManifestController } from '../../streaming/ManifestController'\nimport type {\n HlsManifestData,\n HlsManifestProvider,\n} from './HlsManifestProvider'\n\nexport type HlsManifestController = ManifestController<Promise<HlsManifestData>>\n\nexport class HlsManifestControllerImpl implements HlsManifestController {\n get [Symbol.toStringTag](): string {\n return 'HlsManifestControllerImpl'\n }\n\n get logPrefix(): string {\n return 'HlsManifestControllerImpl'\n }\n\n private readonly _data = /* @__PURE__ */ data<Promise<HlsManifestData>>(\n /* @__PURE__ */ Promise.reject(/* @__PURE__ */ new Error('manifest not loaded'))\n )\n private _error: Error | null = null\n private readonly abortSlot = /* @__PURE__ */ createAbortSlot()\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n constructor(private readonly manifestProvider: HlsManifestProvider) {\n // Suppress unhandled rejection on the initial placeholder.\n this._data.value.catch(() => {})\n this.refresh()\n }\n\n /**\n * The most recent error from the manifest provider, or null.\n */\n get error(): Error | null {\n return this._error\n }\n\n refresh(): void {\n logDebug(this, 'refresh')\n this.abortSlot.abort()\n this._error = null\n const promise = this.manifestProvider(this.abortSlot.value)\n promise.catch((error: Error) => {\n this._error = error\n })\n this._data.value = promise\n }\n\n reset(): void {\n logDebug(this, 'reset')\n if (this._error) {\n this.refresh()\n }\n }\n\n get value(): Promise<HlsManifestData> {\n return this._data.value\n }\n\n get changeId(): number {\n return this._data.changeId\n }\n\n getValue(): Promise<HlsManifestData> {\n return this._data.getValue()\n }\n\n onData(\n callback: (\n value: Promise<HlsManifestData>,\n previous?: Promise<HlsManifestData>\n ) => void\n ): () => void {\n return this._data.onData(callback)\n }\n\n map<U>(fn: (value: Promise<HlsManifestData>) => U) {\n return this._data.map(fn)\n }\n\n pick<K extends keyof NonNullable<Promise<HlsManifestData>>>(key: K) {\n return this._data.pick(key)\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n this.abortSlot.abort()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HlsTrackLoadOptions, HlsTrackDeps } from './HlsTrack'\nimport type { Maybe, RequestInterceptor } from '@amazon/vinyl-util'\nimport { createMediaSource } from '../../util/media/mediaSource'\nimport { createDefaultHlsMediaQualityMetadataResolver } from './HlsMediaQualityMetadataResolver'\nimport {\n MediaSourceControllerImpl,\n type MediaSourceControllerImplDeps,\n} from '../../streaming/buffering/MediaSourceController'\nimport { HlsManifestControllerImpl } from './HlsManifestController'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport { createUrlHlsManifestProvider } from './createUrlHlsManifestProvider'\nimport type { ContentStreamingOptions } from '../../streaming/ContentStreamingOptions'\nimport { createHlsContentTypesValue } from './createHlsContentTypesValue'\nimport { createHlsContentStreamFactories } from './createHlsContentStreamFactories'\nimport { createContentStreamFactory } from '../../streaming/ContentStream'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { PlaybackController } from '../../playback/PlaybackController'\nimport type { DrmKeySystemResolver } from '../../drm/DrmKeySystemResolver'\nimport type { DrmController } from '../../drm/DrmController'\nimport type { Capabilities } from '../../client/Capabilities'\nimport type { PlaybackSource } from '../../playback/PlaybackSource'\nimport type { QualitySelectorImplOptions } from '../../streaming/abr/QualitySelectorImpl'\nimport { QualitySelectorImpl } from '../../streaming/abr/QualitySelectorImpl'\nimport type { VinylOptions } from '../../vinyl/VinylOptions'\nimport { createDefaultHlsManifestTransformer } from './createDefaultHlsManifestTransformer'\nimport {\n buildHlsMediaTimeline,\n type BuildHlsMediaTimelineDeps,\n} from './buildHlsMediaTimeline'\nimport { createDefaultMediaTimelineTransformer } from '../../streaming/createDefaultMediaTimelineTransformer'\nimport type { HlsManifestData } from './HlsManifestProvider'\n\nexport interface HlsFactoryDeps {\n readonly options: ObservableValue<{\n readonly abr: QualitySelectorImplOptions\n readonly preferredAudioLanguage: string | null\n }>\n readonly playbackController: PlaybackController\n readonly playbackSource: PlaybackSource\n readonly drmKeySystemResolver: DrmKeySystemResolver\n readonly requestInterceptor: RequestInterceptor\n readonly drmController: DrmController\n readonly capabilities: Capabilities\n}\n\nexport type HlsInitOptions = {\n readonly streaming?: Maybe<ContentStreamingOptions>\n}\n\nexport function createHlsFactories(options: Maybe<HlsInitOptions>) {\n return (deps: HlsFactoryDeps) => {\n return (loadOptions: HlsTrackLoadOptions) => {\n const manifestProvider =\n loadOptions.manifestProvider ||\n createUrlHlsManifestProvider(\n loadOptions.uri,\n loadOptions.requestInit || undefined\n )\n\n return validateFactories({\n ...externalDependencies(deps),\n\n contentTypesValue: createHlsContentTypesValue,\n\n manifestController: () =>\n new HlsManifestControllerImpl(manifestProvider),\n\n manifestTransformed: createDefaultHlsManifestTransformer,\n\n mediaQualityMetadataResolver: () =>\n createDefaultHlsMediaQualityMetadataResolver(),\n\n mediaSourceFactory: () => createMediaSource,\n\n mediaSourceController: (deps: MediaSourceControllerImplDeps) =>\n new MediaSourceControllerImpl(deps),\n\n segmentRequestInit: () => loadOptions.segmentRequestInit,\n\n createContentStreamFactories: createHlsContentStreamFactories(\n options?.streaming\n ),\n contentStreamFactory: createContentStreamFactory,\n\n qualitySelector: (deps: {\n options: ObservableValue<Pick<VinylOptions, 'abr'>>\n }) =>\n new QualitySelectorImpl({\n options: deps.options.pick('abr'),\n }),\n\n mediaTimeline: (\n deps: BuildHlsMediaTimelineDeps & {\n readonly manifestTransformed: ObservableValue<\n Promise<HlsManifestData>\n >\n }\n ) =>\n deps.manifestTransformed.map(async (manifestPromise) => {\n const data = await manifestPromise\n return buildHlsMediaTimeline(deps, data)\n }),\n mediaTimelineTransformed: createDefaultMediaTimelineTransformer,\n } as const) satisfies Factories<HlsTrackDeps>\n }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MainPlaylist, MediaPlaylist } from '@amazon/vinyl-hls-parser'\nimport { parseMainPlaylist, parseMediaPlaylist } from '@amazon/vinyl-hls-parser'\nimport type {\n Maybe,\n ReadonlyAbort,\n RequestInitOptions,\n} from '@amazon/vinyl-util'\nimport { memoize, requestWithRetry, resolveUrl } from '@amazon/vinyl-util'\nimport type {\n HlsManifestData,\n HlsManifestProvider,\n} from './HlsManifestProvider'\n\nexport function createUrlHlsManifestProvider(\n url: string,\n requestInit?: RequestInitOptions\n): HlsManifestProvider {\n return async (abort?: ReadonlyAbort): Promise<HlsManifestData> => {\n const mainResponse = await requestWithRetry(url, requestInit, {\n abort,\n })\n const mainText = await mainResponse.text()\n const mainPlaylist = parseMainPlaylist(mainText)\n\n // Use the response URL (after redirects) as the base for resolving\n // relative URIs in the manifest.\n const baseUrl = mainResponse.url || url\n\n const getMediaPlaylist = memoize(\n (uri: string) =>\n fetchMediaPlaylist({\n uri,\n baseUrl,\n defines: mainPlaylist.defines,\n requestInit,\n abort,\n }),\n (uri) => uri\n )\n\n return {\n mainPlaylist,\n baseUrl,\n getMediaPlaylist,\n }\n }\n}\n\nexport interface FetchMediaPlaylistOptions {\n /** The variant URI to resolve against the base URL. */\n readonly uri: string\n /** The base URL for resolving relative URIs. */\n readonly baseUrl: string\n /** Variable definitions from the main playlist. */\n readonly defines: MainPlaylist['defines']\n /** Optional request configuration. */\n readonly requestInit?: Maybe<RequestInitOptions>\n /** Optional abort signal. */\n readonly abort?: Maybe<ReadonlyAbort>\n}\n\n/**\n * Fetches and parses an HLS media playlist from a variant URI.\n */\nexport async function fetchMediaPlaylist(\n options: FetchMediaPlaylistOptions\n): Promise<MediaPlaylist> {\n const { uri, baseUrl, defines, requestInit, abort } = options\n const variantUrl = resolveUrl(uri, baseUrl)\n const response = await requestWithRetry(variantUrl, requestInit, { abort })\n const text = await response.text()\n return parseMediaPlaylist(text, defines)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ContentType } from '../../streaming/MediaQualityMetadata'\nimport type { ContentTypesValue } from '../../streaming/ContentTypesValue'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { HlsManifestData } from './HlsManifestProvider'\nimport type { MainPlaylist } from '@amazon/vinyl-hls-parser'\nimport { codecsToContentTypes } from '../mse/codec'\n\nexport interface HlsContentTypesValueDeps {\n readonly manifestTransformed: ObservableValue<Promise<HlsManifestData>>\n}\n\n/**\n * Creates an ObservableValue for the content types present in the HLS manifest.\n *\n * Per RFC 8216 \u00A74.3.4.2, content types are determined from:\n * 1. The CODECS attribute on EXT-X-STREAM-INF (variant streams)\n * 2. The TYPE attribute on EXT-X-MEDIA (alternative renditions)\n */\nexport function createHlsContentTypesValue(\n deps: HlsContentTypesValueDeps\n): ContentTypesValue {\n return deps.manifestTransformed.map(async (manifestData) => {\n return getContentTypes((await manifestData).mainPlaylist)\n })\n}\n\nfunction getContentTypes(mainPlaylist: MainPlaylist): Set<ContentType> {\n const contentTypes = new Set<ContentType>()\n\n // Derive content types from variant CODECS attributes.\n // Only audio and video are relevant for MSE; text (subtitles/CC) is not\n // appended via SourceBuffer in HLS.\n for (const variant of mainPlaylist.variants) {\n if (variant.codecs) {\n for (const type of codecsToContentTypes(variant.codecs)) {\n if (type === 'audio' || type === 'video') {\n contentTypes.add(type)\n }\n }\n }\n }\n\n // Add audio/video from separate renditions not already covered by variant codecs.\n for (const rendition of mainPlaylist.alternativeRenditions) {\n if (rendition.type === 'AUDIO') contentTypes.add('audio')\n if (rendition.type === 'VIDEO') contentTypes.add('video')\n }\n\n return contentTypes\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MediaSourceController } from '../../streaming/buffering/MediaSourceController'\nimport type { PlaybackController } from '../../playback/PlaybackController'\nimport type { QualitySelector } from '../../streaming/abr/QualitySelector'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport { type ContentStreamImplDeps } from '../../streaming/ContentStream'\nimport type { ContentType } from '../../streaming/MediaQualityMetadata'\nimport {\n SourceBufferControllerImpl,\n type SourceBufferControllerImplDeps,\n} from '../../streaming/buffering/SourceBufferController'\nimport {\n BufferingControllerImpl,\n type BufferingControllerImplDeps,\n} from '../../streaming/buffering/BufferingController'\nimport {\n SegmentControllerImpl,\n type SegmentControllerImplDeps,\n} from '../../streaming/SegmentControllerImpl'\nimport { type Maybe, memoize } from '@amazon/vinyl-util'\nimport {\n externalDependencies,\n type Factories,\n validateFactories,\n} from '@amazon/vinyl-di'\nimport type { ContentStreamingOptions } from '../../streaming/ContentStreamingOptions'\nimport type { MediaTimeline } from '../../streaming/MediaTimeline'\n\nexport interface HlsContentStreamTrackDeps {\n readonly mediaSourceController: MediaSourceController\n readonly playbackController: PlaybackController\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n readonly qualitySelector: QualitySelector\n}\n\nexport function createHlsContentStreamFactories(\n options: Maybe<ContentStreamingOptions>\n) {\n return (deps: HlsContentStreamTrackDeps) =>\n memoize(\n (contentType: ContentType) => {\n return validateFactories({\n ...externalDependencies(deps),\n sourceBufferControllerFactory:\n (deps: SourceBufferControllerImplDeps) => () =>\n new SourceBufferControllerImpl(deps, contentType),\n bufferingController: (deps: BufferingControllerImplDeps) =>\n new BufferingControllerImpl(\n deps,\n contentType,\n options?.buffering\n ),\n segmentController: (deps: SegmentControllerImplDeps) =>\n new SegmentControllerImpl(\n deps,\n contentType,\n options?.segmentController\n ),\n } as const) satisfies Factories<ContentStreamImplDeps>\n },\n (contentType) => contentType\n )\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { HlsManifestData } from './HlsManifestProvider'\n\nexport interface HlsManifestTransformerDeps {\n readonly manifestController: ObservableValue<Promise<HlsManifestData>>\n}\n\n/**\n * The default HLS manifest transformer sorts variants by bandwidth descending (highest quality first).\n * Quality and language filtering is handled by the media timeline transformer.\n */\nexport function createDefaultHlsManifestTransformer(\n deps: HlsManifestTransformerDeps\n): ObservableValue<Promise<HlsManifestData>> {\n return deps.manifestController.map(async (v) => {\n const data = await v\n const sorted = [...data.mainPlaylist.variants].sort(\n (a, b) => b.bandwidth - a.bandwidth\n )\n return {\n ...data,\n mainPlaylist: {\n ...data.mainPlaylist,\n variants: sorted,\n },\n }\n })\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ByteRange } from '@amazon/vinyl-mpd-parser'\nimport type { HlsByteRange } from '@amazon/vinyl-hls-parser'\n\n/** Converts an HLS byte range (`{offset, length}`) to a `ByteRange` (`[start, end]`). */\nexport function hlsByteRangeToMediaRange(byteRange: HlsByteRange): ByteRange {\n return [byteRange.offset, byteRange.offset + byteRange.length - 1]\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HlsSegment } from '@amazon/vinyl-hls-parser'\nimport type { MediaSegmentReference } from '../../../streaming/SegmentReference'\nimport type { SegmentDataProvider } from '../../../streaming/SegmentDataSlot'\nimport {\n createSegmentDataProvider,\n type CreateSegmentDataProviderDeps,\n} from '../../createSegmentDataProvider'\nimport { hlsByteRangeToMediaRange } from './hlsByteRangeToMediaRange'\nimport { resolveUrl } from '@amazon/vinyl-util'\n\n/**\n * Builds a timeline of MediaSegmentReferences from an HLS media playlist's\n * segment list. Cumulative durations are used to compute start/end times.\n */\nexport function buildSegmentTimeline(\n deps: CreateSegmentDataProviderDeps,\n baseUrl: string,\n segments: readonly HlsSegment[]\n): readonly MediaSegmentReference<SegmentDataProvider>[] {\n const out: MediaSegmentReference<SegmentDataProvider>[] = new Array(\n segments.length\n )\n let time = 0\n for (let i = 0; i < segments.length; i++) {\n const seg = segments[i]\n const startTime = time\n const endTime = time + seg.duration\n const url = resolveUrl(seg.uri, baseUrl)\n out[i] = {\n timestampOffset: startTime,\n startTime,\n endTime,\n data: createSegmentDataProvider(deps, {\n url,\n mediaRange: seg.byteRange\n ? hlsByteRangeToMediaRange(seg.byteRange)\n : undefined,\n reportDownlinkMetrics: true,\n }),\n }\n time = endTime\n }\n return out\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HlsManifestData } from './HlsManifestProvider'\nimport type { HlsMediaQualityMetadataResolver } from './HlsMediaQualityMetadataResolver'\nimport type {\n ContentType,\n MediaQualityMetadata,\n} from '../../streaming/MediaQualityMetadata'\nimport type {\n MediaPeriod,\n MediaQualityData,\n MediaTimeline,\n} from '../../streaming/MediaTimeline'\nimport type { SegmentReference } from '../../streaming/SegmentReference'\nimport type { SegmentDataProvider } from '../../streaming/SegmentDataSlot'\nimport { buildSegmentTimeline } from './util/hlsSegmentTime'\nimport { getSegmentAtTime } from '../../streaming/util/segment'\nimport { resolveUrl } from '@amazon/vinyl-util'\nimport { codecToContentType, contentTypeToMimeType } from '../mse/codec'\nimport {\n createSegmentDataProvider,\n type CreateSegmentDataProviderDeps,\n} from '../createSegmentDataProvider'\nimport { hlsByteRangeToMediaRange } from './util/hlsByteRangeToMediaRange'\nimport { createTransmuxer } from '@amazon/vinyl-transmux'\n\nexport interface BuildHlsMediaTimelineDeps extends CreateSegmentDataProviderDeps {\n readonly mediaQualityMetadataResolver: HlsMediaQualityMetadataResolver\n}\n\n/**\n * Builds a MediaTimeline from an HLS manifest.\n * HLS has a single implicit period spanning the full duration.\n */\nexport function buildHlsMediaTimeline(\n deps: BuildHlsMediaTimelineDeps,\n data: HlsManifestData\n): MediaTimeline {\n const { mainPlaylist, baseUrl } = data\n const renditions = mainPlaylist.alternativeRenditions\n\n // HLS duration requires fetching a media playlist, so compute it lazily.\n const DEFAULT_MIN_BUFFER_TIME = 10\n\n const qualities: MediaQualityData[] = mainPlaylist.variants.flatMap(\n (variant) => {\n const baseMetadata = deps.mediaQualityMetadataResolver(\n variant,\n renditions\n )\n\n // Determine which content types this variant carries.\n const codecs = variant.codecs?.split(',') ?? []\n const contentTypes = new Set(\n codecs\n .map((c) => codecToContentType(c))\n .filter((t): t is ContentType => t != null)\n )\n // If no codecs, default to audio (e.g. TS streams).\n if (contentTypes.size === 0) contentTypes.add('audio')\n\n // Create one quality per content type, with narrowed mimeType.\n return [...contentTypes].map((contentType) => {\n const codec =\n codecs.find((c) => codecToContentType(c) === contentType) ??\n null\n const metadata: MediaQualityMetadata = {\n ...baseMetadata,\n contentType,\n mimeType: contentTypeToMimeType(contentType, codec),\n codecs: codec,\n }\n const transmuxer = createTransmuxer()\n\n return {\n metadata,\n async getSegment(\n time: number,\n affordance = 0\n ): Promise<SegmentReference<SegmentDataProvider> | null> {\n // For an audio quality on a variant that also carries video,\n // the audio is delivered through a separate rendition group\n // (variant URI is video-only). Use the rendition URI in that\n // case. Otherwise the variant URI itself contains the audio.\n let playlistUri = variant.uri\n if (\n metadata.contentType === 'audio' &&\n variant.audioGroup &&\n contentTypes.has('video')\n ) {\n const rendition = renditions.find(\n (r) =>\n r.type === 'AUDIO' &&\n r.groupId === variant.audioGroup &&\n r.uri\n )\n if (rendition?.uri) playlistUri = rendition.uri\n }\n const playlist =\n await data.getMediaPlaylist(playlistUri)\n const playlistBaseUrl = resolveUrl(playlistUri, baseUrl)\n const segments = buildSegmentTimeline(\n deps,\n playlistBaseUrl,\n playlist.segments\n )\n const segment = getSegmentAtTime(\n time,\n segments,\n affordance\n )\n if (!segment) return null\n\n // fMP4: use #EXT-X-MAP init segment directly.\n const hlsMap = playlist.segments[0]?.map\n if (hlsMap) {\n return {\n quality: metadata,\n ...segment,\n initData: createSegmentDataProvider(deps, {\n url: resolveUrl(\n hlsMap.uri,\n playlistBaseUrl\n ),\n mediaRange: hlsMap.byteRange\n ? hlsByteRangeToMediaRange(\n hlsMap.byteRange\n )\n : undefined,\n reportDownlinkMetrics: false,\n }),\n }\n }\n\n // MPEG-TS/ADTS: transmux to fMP4.\n const transmuxedQuality: MediaQualityMetadata = {\n ...metadata,\n mimeType: contentTypeToMimeType(\n metadata.contentType!,\n metadata.codecs\n ),\n }\n const rawDataProvider = segment.data\n return {\n quality: transmuxedQuality,\n ...segment,\n data: async (abort) => {\n const raw = await rawDataProvider(abort)\n return transmuxer.transmux(raw).mediaSegment\n },\n initData: async (abort) => {\n const raw = await rawDataProvider(abort)\n return transmuxer.transmux(raw).initSegment\n },\n }\n },\n } satisfies MediaQualityData\n })\n }\n )\n\n const period: MediaPeriod = {\n startTime: 0,\n endTime: Infinity,\n qualities,\n }\n\n let cachedDuration: number | null = null\n\n return {\n periods: [period],\n minBufferTime: DEFAULT_MIN_BUFFER_TIME,\n async getDuration() {\n if (cachedDuration != null) return cachedDuration\n if (mainPlaylist.variants.length === 0) {\n throw new Error('Unable to determine HLS duration: no variants')\n }\n const playlist = await data.getMediaPlaylist(\n mainPlaylist.variants[0].uri\n )\n // Live playlists (no EXT-X-ENDLIST) have unbounded duration.\n if (!playlist.ended) return Infinity\n if (playlist.segments.length === 0) {\n throw new Error(\n 'Unable to determine HLS duration: no segments in media playlist'\n )\n }\n let total = 0\n for (const seg of playlist.segments) total += seg.duration\n cachedDuration = total\n return cachedDuration\n },\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n bufferToByteArray,\n type Disposable,\n DisposedError,\n ErrorOrigin,\n EventHostImpl,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport {\n type CommonEme,\n type CommonMediaKeys,\n type CommonMediaKeySession,\n CommonMediaKeySessionError,\n type CommonMediaKeySessionEventMap,\n type CommonMediaKeySystemAccess,\n MediaKeySessionErrorType,\n} from './CommonEme'\nimport type { DrmKeySystem } from '../DrmKeySystem'\nimport { type EncryptedInitData } from './EncryptedInitData'\nimport type { MSMediaKeyMessageEvent } from '../dom/MSMediaKeys'\nimport { DrmError } from '../error/DrmError'\nimport type { DrmInitDataType } from '../../streaming/DrmInitDataType'\n\ndeclare global {\n interface HTMLMediaElementEventMap extends HTMLElementEventMap {\n readonly msneedkey: MSMediaKeyNeededEvent\n }\n\n interface MSMediaKeyNeededEvent extends Event {\n readonly initDataType: string\n readonly initData: Uint8Array<ArrayBuffer> | null\n }\n}\n\n/**\n * A CommonEme implementation of MS prefixed Encrypted Media Extensions as supported by IE11/Edge.\n */\nexport class MsCommonEme implements CommonEme {\n requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess> {\n for (const config of supportedConfigurations) {\n const capabilities = [\n ...(config.audioCapabilities ?? []),\n ...(config.videoCapabilities ?? []),\n ]\n for (const capability of capabilities) {\n if (\n MSMediaKeys.isTypeSupported(\n keySystem,\n capability.contentType\n )\n ) {\n return Promise.resolve(\n new MsCommonMediaKeySystemAccess(keySystem)\n )\n }\n }\n }\n return Promise.reject(\n new DrmError(\n `keySystem not supported: ${keySystem}`,\n { keySystem },\n ErrorOrigin.DRM\n )\n )\n }\n\n /**\n * Listens to the element for an encrypted event, returning a disposable handle.\n */\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: MediaEncryptedEvent) => void\n ): Unsubscribe {\n const event = 'msneedkey'\n element.addEventListener(event, handler as EventListener)\n return () =>\n element.removeEventListener(event, handler as EventListener)\n }\n}\n\nexport class MsCommonMediaKeySystemAccess implements CommonMediaKeySystemAccess {\n constructor(readonly keySystem: DrmKeySystem) {}\n\n createMediaKeys(): Promise<CommonMediaKeys> {\n const msMediaKeys = new MSMediaKeys(this.keySystem)\n return Promise.resolve(\n new MsCommonMediaKeys(this.keySystem, msMediaKeys)\n )\n }\n}\n\n/**\n * @private\n */\nexport class MsCommonMediaKeys implements CommonMediaKeys {\n constructor(\n public readonly keySystem: DrmKeySystem,\n public readonly mediaKeys: MSMediaKeys\n ) {}\n\n /**\n * Sets the media keys on the given element.\n */\n setOnElement(element: HTMLMediaElement): Promise<void> {\n element.msSetMediaKeys!(this.mediaKeys)\n return Promise.resolve()\n }\n\n /**\n * Clears the media keys from the given element.\n */\n clearFromElement(element: HTMLMediaElement): Promise<void> {\n element.msSetMediaKeys!(null)\n return Promise.resolve()\n }\n\n setServerCertificate(_certificate: BufferSource): Promise<boolean> {\n return Promise.resolve(false)\n }\n\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession {\n const session = this.mediaKeys.createSession(\n mimeType,\n bufferToByteArray(initData)\n )\n return new MsCommonMediaKeySession(\n session,\n mimeType,\n initDataType,\n initData\n )\n }\n}\n\n/**\n * @private\n */\nexport class MsCommonMediaKeySession\n extends EventHostImpl<CommonMediaKeySessionEventMap>\n implements CommonMediaKeySession, Disposable\n{\n private _disposed: boolean = false\n\n constructor(\n private readonly session: MSMediaKeySession,\n readonly mimeType: string,\n readonly initDataType: DrmInitDataType,\n readonly initData: EncryptedInitData\n ) {\n super()\n session.addEventListener('mskeymessage', this.messageHandler)\n session.addEventListener('mskeyerror', this.errorHandler)\n }\n\n private readonly messageHandler = (event: MSMediaKeyMessageEvent) => {\n this.dispatch('message', {\n message: event.message.buffer as ArrayBuffer,\n })\n }\n\n private readonly errorHandler = (): void => {\n if (this.session.error) {\n const e = this.session.error\n const error = new CommonMediaKeySessionError(\n e.code,\n msErrorCodeToStr(e.code),\n e.systemCode,\n msErrorCodeToStr(e.systemCode)\n )\n this.dispatch('error', { error, target: this })\n }\n }\n\n update(key: ArrayBuffer): Promise<void> {\n if (this.disposed) return Promise.reject(new DisposedError())\n this.session.update(new Uint8Array(key))\n return Promise.resolve()\n }\n\n get disposed(): boolean {\n return this._disposed\n }\n\n dispose(): void {\n super.dispose()\n this._disposed = true\n this.session.close()\n this.session.removeEventListener('mskeymessage', this.messageHandler)\n this.session.removeEventListener('mskeyerror', this.errorHandler)\n }\n}\n\n/**\n * Returns a string for the WebKit media key error.\n */\nexport function msErrorCodeToStr(code: number): MediaKeySessionErrorType {\n switch (code) {\n case MSMediaKeyError.MS_MEDIA_KEYERR_CLIENT:\n return MediaKeySessionErrorType.CLIENT\n case MSMediaKeyError.MS_MEDIA_KEYERR_DOMAIN:\n return MediaKeySessionErrorType.DOMAIN\n case MSMediaKeyError.MS_MEDIA_KEYERR_HARDWARECHANGE:\n return MediaKeySessionErrorType.HARDWARECHANGE\n case MSMediaKeyError.MS_MEDIA_KEYERR_OUTPUT:\n return MediaKeySessionErrorType.OUTPUT\n case MSMediaKeyError.MS_MEDIA_KEYERR_SERVICE:\n return MediaKeySessionErrorType.SERVICE\n case MSMediaKeyError.MS_MEDIA_KEYERR_UNKNOWN:\n default:\n return MediaKeySessionErrorType.UNKNOWN\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * An common interface to unify multiple EME implementations.\n * @module\n */\n\nimport type { DrmKeySystem } from '../DrmKeySystem'\nimport type { Json, ReadonlyEventHost, Unsubscribe } from '@amazon/vinyl-util'\nimport { ErrorLevel, ErrorOrigin, ReportableError } from '@amazon/vinyl-util'\nimport type { EncryptedInitData } from './EncryptedInitData'\nimport type { DrmInitDataType } from '../../streaming/DrmInitDataType'\nimport type { BasicErrorEvent } from '../../event/BasicErrorEvent'\n\n/**\n * Top-level Common EME methods for initiating encrypted audio session.\n *\n * Created to unify standard and non-standard EME interfaces.\n */\nexport interface CommonEme {\n requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess>\n\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: CommonMediaEncryptedEvent) => void\n ): Unsubscribe\n}\n\nexport interface CommonMediaEncryptedEvent {\n /**\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaEncryptedEvent/initData)\n */\n readonly initData: EncryptedInitData | null\n\n /**\n * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaEncryptedEvent/initDataType)\n */\n readonly initDataType: string\n}\n\n/**\n * This provides a common interface for MediaKeySystemAccess EME implementations.\n */\nexport interface CommonMediaKeySystemAccess {\n readonly keySystem: DrmKeySystem\n createMediaKeys(): Promise<CommonMediaKeys>\n}\n\n/**\n * This provides a common interface for MediaKeys EME implementations.\n */\nexport interface CommonMediaKeys {\n readonly keySystem: DrmKeySystem\n\n /**\n * Sets the media keys on the given element.\n * @param element\n */\n setOnElement(element: HTMLMediaElement): Promise<void>\n\n /**\n * Clears the media keys from the given element.\n * This is only allowed if the element's src isn't set.\n * https://bugs.chromium.org/p/chromium/issues/detail?id=462365#c7\n * @param element\n */\n clearFromElement(element: HTMLMediaElement): Promise<void>\n\n /**\n * Sets the server certificate on the media keys.\n *\n * A Promise that resolves to a boolean. If the Key System implementation\n * represented by this object's content decryption module's implementation\n * value does not support server certificates, return a promise resolved\n * with false.\n *\n * @param certificate The server certificate data.\n */\n setServerCertificate(certificate: BufferSource): Promise<boolean>\n\n /**\n * Creates the key session.\n *\n * @param mimeType\n * @param initDataType\n * @param initData The initialization data from the 'encrypted' event.\n */\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession\n}\n\n/**\n * Common media key session events\n */\nexport interface CommonMediaKeySessionEventMap {\n /**\n * Dispatched when a message is generated by the content decryption module.\n */\n readonly message: CommonMediaKeyMessageEvent\n\n /**\n * Dispatched when an error occurs.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Dispatched when the session is forcibly closed by the CDM.\n */\n readonly closed: CommonMediaKeySessionClosedEvent\n}\n\n/**\n * This provides a common interface for MediaKeySession EME implementations.\n */\nexport interface CommonMediaKeySession extends ReadonlyEventHost<CommonMediaKeySessionEventMap> {\n readonly mimeType: string\n readonly initDataType: DrmInitDataType\n readonly initData: EncryptedInitData\n\n /**\n * Updates the session with the license data.\n * @param key\n */\n update(key: ArrayBuffer): Promise<void>\n\n /**\n * Returns true if the session has been disposed.\n */\n get disposed(): boolean\n\n /**\n * Closes the session, and removes session handling and event listeners, freeing this session\n * handler for GC.\n *\n * Note: The audio source should be cleared first.\n */\n dispose(): void\n}\n\n/**\n * A media key session error, translated from the specific media key session implementation.\n */\nexport class CommonMediaKeySessionError extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'CommonMediaKeySessionError'\n }\n\n constructor(\n readonly code: number,\n readonly codeStr: MediaKeySessionErrorType,\n readonly systemCode: number,\n readonly systemCodeStr: MediaKeySessionErrorType\n ) {\n super(codeStr, ErrorOrigin.DRM, ErrorLevel.WARN)\n Object.setPrototypeOf(this, CommonMediaKeySessionError.prototype)\n }\n\n toJSON(): Json {\n return {\n ...super.toJSON(),\n code: this.code,\n codeStr: this.codeStr,\n systemCode: this.systemCode,\n systemCodeStr: this.systemCodeStr,\n }\n }\n}\n\n/**\n * Common media key message event body.\n */\nexport interface CommonMediaKeyMessageEvent {\n readonly message: ArrayBuffer\n}\n\nexport interface CommonMediaKeySessionClosedEvent {\n /**\n * The reason the session was closed.\n */\n readonly reason: MediaKeySessionClosedReason\n}\n\n/**\n * String representations of session error codes.\n */\nexport enum MediaKeySessionErrorType {\n CLIENT = 'CLIENT',\n DOMAIN = 'DOMAIN',\n HARDWARECHANGE = 'HARDWARECHANGE',\n OUTPUT = 'OUTPUT',\n SERVICE = 'SERVICE',\n UNKNOWN = 'UNKNOWN',\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ErrorOrigin, type Json } from '@amazon/vinyl-util'\nimport { ErrorLevel, ReportableError } from '@amazon/vinyl-util'\n\n/**\n * An error originating from the DrmController.\n * If an error comes from a key session, `extra.error` will be set with the original error and origin will be DRM.\n */\nexport class DrmError<ExtraType = any> extends ReportableError {\n get [Symbol.toStringTag](): string {\n return 'DrmError'\n }\n\n constructor(\n readonly message: string,\n private readonly extra: ExtraType | null = null,\n readonly origin: string = ErrorOrigin.DRM,\n readonly level: ErrorLevel = ErrorLevel.FATAL\n ) {\n super(message, origin, level)\n Object.setPrototypeOf(this, DrmError.prototype)\n }\n\n toJSON(): Json {\n return { ...super.toJSON(), extra: this.extra }\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type Disposable,\n DisposedError,\n EventHostImpl,\n noop,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport type {\n CommonEme,\n CommonMediaEncryptedEvent,\n CommonMediaKeyMessageEvent,\n CommonMediaKeys,\n CommonMediaKeySession,\n CommonMediaKeySessionEventMap,\n CommonMediaKeySystemAccess,\n} from './CommonEme'\nimport type { DrmKeySystem } from '../DrmKeySystem'\nimport { type EncryptedInitData } from './EncryptedInitData'\nimport { createDrmErrorHandler } from './createDrmErrorHandler'\nimport type { DrmInitDataType } from '../../streaming/DrmInitDataType'\n\n/**\n * A CommonEme implementation of unprefixed Encrypted Media Extensions.\n */\nexport class StandardCommonEme implements CommonEme {\n async requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess> {\n const access = await navigator\n .requestMediaKeySystemAccess(keySystem, supportedConfigurations)\n .catch(createDrmErrorHandler())\n return new StandardCommonMediaKeySystemAccess(keySystem, access)\n }\n\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: CommonMediaEncryptedEvent) => void\n ): Unsubscribe {\n element.addEventListener('encrypted', handler)\n return () => element.removeEventListener('encrypted', handler)\n }\n}\n\n/**\n * CommonMediaKeySystemAccess for unprefixed EME implementations.\n */\nexport class StandardCommonMediaKeySystemAccess implements CommonMediaKeySystemAccess {\n constructor(\n public readonly keySystem: DrmKeySystem,\n private readonly access: MediaKeySystemAccess\n ) {}\n\n /**\n * @return {Promise<CommonMediaKeys>}\n */\n async createMediaKeys(): Promise<CommonMediaKeys> {\n const mediaKeys = await this.access\n .createMediaKeys()\n .catch(createDrmErrorHandler())\n return new StandardCommonMediaKeys(this.keySystem, mediaKeys)\n }\n}\n\n/**\n * CommonMediaKeys for unprefixed EME implementations.\n */\nexport class StandardCommonMediaKeys implements CommonMediaKeys {\n constructor(\n public readonly keySystem: DrmKeySystem,\n private readonly mediaKeys: MediaKeys\n ) {}\n\n setOnElement(element: HTMLMediaElement): Promise<void> {\n return element.setMediaKeys(this.mediaKeys)\n }\n\n clearFromElement(element: HTMLMediaElement): Promise<void> {\n return element.setMediaKeys(null)\n }\n\n async setServerCertificate(certificate: BufferSource): Promise<boolean> {\n return this.mediaKeys.setServerCertificate(certificate)\n }\n\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession {\n return new StandardCommonMediaKeySession(\n this.mediaKeys.createSession('temporary'),\n mimeType,\n initDataType,\n initData\n )\n }\n}\n\n/**\n * CommonMediaKeySession for unprefixed EME implementations.\n */\nexport class StandardCommonMediaKeySession\n extends EventHostImpl<CommonMediaKeySessionEventMap>\n implements CommonMediaKeySession, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'StandardCommonMediaKeySession'\n }\n\n private _disposed = false\n\n private readonly messageHandler = (event: CommonMediaKeyMessageEvent) => {\n this.dispatch('message', {\n message: event.message,\n })\n }\n\n constructor(\n private readonly session: MediaKeySession,\n readonly mimeType: string,\n readonly initDataType: DrmInitDataType,\n readonly initData: EncryptedInitData\n ) {\n super()\n session.addEventListener('message', this.messageHandler)\n if ((session as any).closed) {\n // Compatibility: React Native MSE does not provide a 'closed' promise.\n session.closed\n .then((reason) => {\n this.dispatch('closed', {\n reason,\n })\n })\n .catch(noop)\n }\n this.generateRequest().catch((error) => {\n this.dispatch('error', {\n error,\n target: this,\n })\n })\n }\n\n private generateRequest(): Promise<void> {\n const initData = this.initData\n return this.session\n .generateRequest(\n this.initDataType,\n initData instanceof ArrayBuffer ? initData : initData.buffer\n )\n .catch(createDrmErrorHandler())\n }\n\n update(key: ArrayBufferLike): Promise<void> {\n if (this.disposed) throw new DisposedError()\n return this.session.update(key as ArrayBuffer)\n }\n\n get disposed(): boolean {\n return this._disposed\n }\n\n dispose(): void {\n super.dispose()\n this._disposed = true\n this.session.removeEventListener('message', this.messageHandler)\n this.session.close().catch(noop)\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { DrmError } from '../error/DrmError'\nimport { ErrorLevel, ErrorOrigin, toJson } from '@amazon/vinyl-util'\n\nexport function createDrmErrorHandler(\n level: ErrorLevel = ErrorLevel.FATAL\n): (error: Error) => never {\n return (error) => {\n throw new DrmError(\n error.message,\n { error: toJson(error) },\n ErrorOrigin.DRM,\n level\n )\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Unsubscribe } from '@amazon/vinyl-util'\nimport {\n bufferToByteArray,\n type Disposable,\n DisposedError,\n ErrorOrigin,\n EventHostImpl,\n} from '@amazon/vinyl-util'\nimport type {\n CommonEme,\n CommonMediaEncryptedEvent,\n CommonMediaKeys,\n CommonMediaKeySession,\n CommonMediaKeySessionEventMap,\n CommonMediaKeySystemAccess,\n} from './CommonEme'\nimport {\n CommonMediaKeySessionError,\n MediaKeySessionErrorType,\n} from './CommonEme'\nimport type { WebKitMediaKeyMessageEvent } from '../dom/WebKitMediaKeys'\nimport type { DrmKeySystem } from '../DrmKeySystem'\nimport { DrmError } from '../error/DrmError'\nimport type { EncryptedInitData } from './EncryptedInitData'\nimport type { DrmInitDataType } from '../../streaming/DrmInitDataType'\n\ndeclare global {\n interface HTMLMediaElementEventMap extends HTMLElementEventMap {\n readonly webkitneedkey: WebKitMediaKeyNeededEvent\n }\n\n interface WebKitMediaKeyNeededEvent extends Event {\n readonly initDataType: string\n readonly initData: Uint8Array<ArrayBuffer> | null\n }\n}\n\n/**\n * A CommonEme implementation of WebKit-prefixed Encrypted Media Extensions.\n */\nexport class WebKitCommonEme implements CommonEme {\n requestMediaKeySystemAccess(\n keySystem: DrmKeySystem,\n supportedConfigurations: readonly MediaKeySystemConfiguration[]\n ): Promise<CommonMediaKeySystemAccess> {\n for (const config of supportedConfigurations) {\n const capabilities = [\n ...(config.audioCapabilities ?? []),\n ...(config.videoCapabilities ?? []),\n ]\n for (const capability of capabilities) {\n if (\n WebKitMediaKeys.isTypeSupported(\n keySystem,\n capability.contentType\n )\n ) {\n return Promise.resolve(\n new WebKitCommonMediaKeySystemAccess(keySystem)\n )\n }\n }\n }\n return Promise.reject(\n new DrmError(\n `keySystem not supported: ${keySystem}`,\n { keySystem },\n ErrorOrigin.DRM\n )\n )\n }\n\n addEncryptedListener(\n element: HTMLMediaElement,\n handler: (event: CommonMediaEncryptedEvent) => void\n ): Unsubscribe {\n element.addEventListener('webkitneedkey', handler)\n return () => element.removeEventListener('webkitneedkey', handler)\n }\n}\n\nexport class WebKitCommonMediaKeySystemAccess implements CommonMediaKeySystemAccess {\n constructor(public readonly keySystem: DrmKeySystem) {}\n\n createMediaKeys(): Promise<CommonMediaKeys> {\n const webKitMediaKeys = new WebKitMediaKeys(this.keySystem)\n const webkitCommonMediaKeys = new WebKitCommonMediaKeys(\n this.keySystem,\n webKitMediaKeys\n )\n return Promise.resolve(webkitCommonMediaKeys)\n }\n}\n\n/** @private */\nexport class WebKitCommonMediaKeys implements CommonMediaKeys {\n constructor(\n public readonly keySystem: DrmKeySystem,\n public readonly mediaKeys: WebKitMediaKeys\n ) {}\n\n /**\n * Sets the media keys on the given element.\n */\n setOnElement(element: HTMLMediaElement): Promise<void> {\n element.webkitSetMediaKeys!(this.mediaKeys)\n return Promise.resolve()\n }\n\n /**\n * Clears the media keys from the given element.\n */\n clearFromElement(element: HTMLMediaElement): Promise<void> {\n element.webkitSetMediaKeys!(null)\n return Promise.resolve()\n }\n\n setServerCertificate(_certificate: BufferSource): Promise<boolean> {\n return Promise.resolve(false)\n }\n\n createSession(\n mimeType: string,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData\n ): CommonMediaKeySession {\n const session = this.mediaKeys.createSession(\n mimeType,\n bufferToByteArray(initData)\n )\n return new WebKitCommonMediaKeySession(\n session,\n mimeType,\n initDataType,\n initData\n )\n }\n}\n\n/** @private */\nexport class WebKitCommonMediaKeySession\n extends EventHostImpl<CommonMediaKeySessionEventMap>\n implements CommonMediaKeySession, Disposable\n{\n private _disposed: boolean = false\n\n constructor(\n private readonly session: WebKitMediaKeySession,\n readonly mimeType: string,\n readonly initDataType: DrmInitDataType,\n readonly initData: EncryptedInitData\n ) {\n super()\n session.addEventListener('webkitkeymessage', this.messageHandler)\n session.addEventListener('webkitkeyerror', this.errorHandler)\n }\n\n private readonly messageHandler = (event: WebKitMediaKeyMessageEvent) => {\n this.dispatch('message', {\n message: event.message.buffer as ArrayBuffer,\n })\n }\n\n private readonly errorHandler = () => {\n if (this.session.error) {\n const e = this.session.error\n const error = new CommonMediaKeySessionError(\n e.code,\n webkitErrorCodeToStr(e.code),\n e.systemCode,\n webkitErrorCodeToStr(e.systemCode)\n )\n this.dispatch('error', { error, target: this })\n }\n }\n\n update(key: ArrayBuffer): Promise<void> {\n if (this.disposed) return Promise.reject(new DisposedError())\n this.session.update(new Uint8Array(key))\n return Promise.resolve()\n }\n\n get disposed() {\n return this._disposed\n }\n\n dispose(): void {\n super.dispose()\n this._disposed = true\n this.session.removeEventListener(\n 'webkitkeymessage',\n this.messageHandler\n )\n this.session.removeEventListener('webkitkeyerror', this.errorHandler)\n // Do not wait on close, and ignore errors.\n this.session.close()\n }\n}\n\n/**\n * Returns a string for the WebKit media key error.\n */\nexport function webkitErrorCodeToStr(code: number): MediaKeySessionErrorType {\n switch (code) {\n case WebKitMediaKeyError.MEDIA_KEYERR_CLIENT:\n return MediaKeySessionErrorType.CLIENT\n case WebKitMediaKeyError.MEDIA_KEYERR_DOMAIN:\n return MediaKeySessionErrorType.DOMAIN\n case WebKitMediaKeyError.MEDIA_KEYERR_HARDWARECHANGE:\n return MediaKeySessionErrorType.HARDWARECHANGE\n case WebKitMediaKeyError.MEDIA_KEYERR_OUTPUT:\n return MediaKeySessionErrorType.OUTPUT\n case WebKitMediaKeyError.MEDIA_KEYERR_SERVICE:\n return MediaKeySessionErrorType.SERVICE\n case WebKitMediaKeyError.MEDIA_KEYERR_UNKNOWN:\n default:\n return MediaKeySessionErrorType.UNKNOWN\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { MsCommonEme } from './MsCommonEme'\nimport { StandardCommonEme } from './StandardCommonEme'\nimport { WebKitCommonEme } from './WebKitCommonEme'\nimport type { CommonEme } from './CommonEme'\nimport { globalRef } from '@amazon/vinyl-util'\n\n/**\n * Common EME Factory provides the first supported implementation of CommonEme.\n * The priority is WebKit, Standard, then MS.\n *\n * Note: WebKit if present is currently prioritized over standard for legacy reasons. This may be an obsolete\n * requirement. https://jira.music.amazon.dev/browse/PLAYBACK-6072 ticket to investigate.\n */\nexport function commonEmeFactory(): CommonEme | null {\n if (supportsWebKitEme()) return new WebKitCommonEme()\n if (supportsStandardEme()) return new StandardCommonEme()\n if (supportsMsEme()) return new MsCommonEme()\n return null\n}\n\n/**\n * Tests for Standard Eme support.\n */\nexport function supportsStandardEme(): boolean {\n return mediaKeySupportRef.value.standardEme\n}\n\n/**\n * Tests for WebKitEme support.\n */\nexport function supportsWebKitEme(): boolean {\n return mediaKeySupportRef.value.webkitEme\n}\n\n/**\n * Tests for MsEme support.\n */\nexport function supportsMsEme(): boolean {\n return mediaKeySupportRef.value.msEme\n}\n\nexport type MediaKeySupport = {\n readonly standardEme: boolean\n readonly webkitEme: boolean\n readonly msEme: boolean\n}\n\nexport const mediaKeySupportRef = /* @__PURE__ */ globalRef<MediaKeySupport>(() => {\n return {\n standardEme: typeof MediaKeys !== 'undefined',\n webkitEme: typeof WebKitMediaKeys !== 'undefined',\n msEme: typeof (global as any).MSMediaKeys !== 'undefined',\n }\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n AbortError,\n base64ToByteArray,\n buffersEqual,\n bufferToByteArray,\n clone,\n type Comparator,\n compareBy,\n createDisposer,\n ErrorOrigin,\n EventHostImpl,\n isSilentError,\n logDebug,\n logVerbose,\n type Maybe,\n memoize,\n noop,\n normalizeHeadersInit,\n type ReadonlyAbort,\n remove,\n resolveValueProvider,\n withTimeout,\n} from '@amazon/vinyl-util'\nimport { instanceOf, object, type ObjectSchema } from '@amazon/vinyl-validation'\nimport {\n type DrmMediaKeySystemOptions,\n type DrmOptions,\n DrmRobustness,\n type InitDataTransformer,\n} from './DrmOptions'\nimport type {\n DrmController,\n DrmControllerEventMap,\n DrmKeySystemSupport,\n} from './DrmController'\nimport type {\n CommonEme,\n CommonMediaEncryptedEvent,\n CommonMediaKeyMessageEvent,\n CommonMediaKeys,\n CommonMediaKeySession,\n CommonMediaKeySystemAccess,\n} from './commonEme/CommonEme'\nimport { DrmError } from './error/DrmError'\nimport type { EncryptedInitData } from './commonEme/EncryptedInitData'\nimport { DrmKeySystem, isPlayReady } from './DrmKeySystem'\nimport type { DrmInitDataType } from '../streaming/DrmInitDataType'\nimport type {\n ContentType,\n MediaFormatMetadata,\n} from '../streaming/MediaQualityMetadata'\nimport { unpackPlayReadyChallenge } from './util/unpackPlayReadyChallenge'\nimport type {\n LicenseProvider,\n ServerCertificate,\n} from './licenseProvider/LicenseProvider'\nimport { defaultLicenseProvider } from './licenseProvider/defaultLicenseProvider'\nimport { extractContentId } from './util/extractContentId'\nimport { createFairPlaySessionInitData } from './util/createFairPlaySessionInitData'\n\n/**\n * The number of seconds a license request will be allowed before timing out.\n * This should be higher than the network timeout.\n *\n * In practice, network requests will time out before this, and a license timeout\n * indicates a stalled promise result from the license provider.\n */\nexport const LICENSE_TIMEOUT = 90\nconst LICENSE_TIMEOUT_MESSAGE = 'License provider timed out after {time}s'\n\n/**\n * Dependencies for creating DrmController.\n */\nexport interface DrmControllerImplDeps {\n readonly media: HTMLMediaElement\n readonly commonEme: CommonEme | null\n}\n\nexport interface DrmControllerMessageProps {\n readonly mediaKeys: CommonMediaKeys\n readonly session: CommonMediaKeySession\n readonly event: CommonMediaKeyMessageEvent\n}\n\nexport class DrmControllerImpl\n extends EventHostImpl<DrmControllerEventMap>\n implements DrmController\n{\n get [Symbol.toStringTag](): string {\n return 'DrmControllerImpl'\n }\n\n private readonly optionsBase: DrmOptions\n private options: DrmOptions\n\n private mediaKeys: CommonMediaKeys | null = null\n private mediaKeysPromise: Promise<CommonMediaKeys> | null = null\n private readonly sessions: CommonMediaKeySession[] = []\n\n private _error: Error | null = null\n private drmInfo: MediaFormatMetadata | null = null\n private sessionAbort: ReadonlyAbort | null = null\n\n private pendingMessageProps: DrmControllerMessageProps | null = null\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n constructor(\n private readonly deps: DrmControllerImplDeps,\n options?: Maybe<Partial<DrmOptions>>\n ) {\n super()\n this.optionsBase = { keySystems: {}, ...options }\n this.options = this.optionsBase\n\n if (this.deps.commonEme) {\n this.disposer.add(\n this.deps.commonEme.addEncryptedListener(\n this.deps.media,\n this.handleEncryptedEvent\n )\n )\n }\n }\n\n configure(options: Maybe<Partial<DrmOptions>>): void {\n this.options = {\n ...this.optionsBase,\n ...options,\n keySystems: {\n ...this.optionsBase.keySystems,\n ...options?.keySystems,\n },\n }\n }\n\n private get licenseProvider(): LicenseProvider {\n return this.options.licenseProvider ?? defaultLicenseProvider\n }\n\n get error(): Error | null {\n return this._error\n }\n\n isEmeSupported(): boolean {\n return this.deps.commonEme != null\n }\n\n async isSupported(\n drmInfo: MediaFormatMetadata\n ): Promise<DrmKeySystemSupport> {\n const accessParamsList = this.createMediaKeySystemAccessParams(drmInfo)\n for (const params of accessParamsList) {\n const result = await this.checkIsSupportedCached(params)\n if (result.supported) return result\n }\n return { supported: false, persistentState: false }\n }\n\n private checkIsSupportedCached = /* @__PURE__ */ memoize(\n async (\n params: MediaKeySystemAccessParams\n ): Promise<DrmKeySystemSupport> => {\n try {\n await this.deps.commonEme!.requestMediaKeySystemAccess(\n params.keySystem,\n [params.config]\n )\n logVerbose(\n this,\n 'requestMediaKeySystemAccess supported',\n params\n )\n return {\n supported: true,\n persistentState:\n params.config.persistentState === 'required',\n }\n } catch (_) {\n logVerbose(this, 'requestMediaKeySystemAccess rejected', params)\n return { supported: false, persistentState: false }\n }\n },\n (options) => options.cacheKey,\n 20 // capacity\n )\n\n private readonly handleEncryptedEvent = (\n event: CommonMediaEncryptedEvent\n ) => {\n if (this.disposed) return\n ;(async () => {\n const { initData, initDataType } = event\n if (!initData) {\n // https://www.w3.org/TR/2014/WD-encrypted-media-20140218/#dom-mediakeyneededevent\n // https://www.w3.org/TR/encrypted-media/#initialization-data\n // Initialization data could not be obtained, possibly due to cross-origin policy issues.\n throw new DrmError(\n 'encrypted event provided null initData. Check CORS policies.'\n )\n }\n logDebug(\n this,\n `encrypted, initDataType: ${initDataType}, initData.byteLength: ${initData.byteLength}`\n )\n if (!this.drmInfo?.contentProtections.length) {\n throw new DrmError(\n 'Encrypted content not configured with content protections.'\n )\n }\n await this.maybeCreateSession(\n this.drmInfo,\n initDataType,\n initData,\n this.sessionAbort\n )\n })().catch(this.handleError)\n }\n\n /**\n * Resolves to media keys attached to the element.\n * The media keys will only be created and set once until `clearMediaKeys` is next called.\n */\n private async attachMediaKeys(\n drmInfo: MediaFormatMetadata\n ): Promise<CommonMediaKeys> {\n if (!this.mediaKeysPromise) {\n this.mediaKeysPromise = (async () => {\n logDebug(this, 'creating media keys')\n const access = await this.createAccess(drmInfo)\n const mediaKeys = await access.createMediaKeys()\n this.abortIfDisposed()\n this.mediaKeys = mediaKeys\n await mediaKeys.setOnElement(this.deps.media)\n logDebug(this, `set media keys on element`)\n this.dispatch('mediaKeysSet', {\n keySystem: mediaKeys.keySystem,\n })\n return mediaKeys\n })()\n }\n return this.mediaKeysPromise\n }\n\n /**\n * Creates a session for the given initialization data if none currently exists.\n * This will be done either after an 'encrypted' event or when drm metadata contains initialization data.\n * The new session will be added to the current sessions list.\n */\n private async maybeCreateSession(\n drmInfo: MediaFormatMetadata,\n initDataType: DrmInitDataType,\n initData: EncryptedInitData,\n abort?: Maybe<ReadonlyAbort>\n ): Promise<CommonMediaKeySession> {\n if (!hasMimeType(drmInfo)) {\n throw new DrmError('Encrypted content must have a mimeType.')\n }\n\n const mediaKeys = await this.attachMediaKeys(drmInfo)\n this.abortIfDisposed()\n\n // Resolve server certificate from configuration\n const keySystemOptions =\n this.options.keySystems[mediaKeys.keySystem] ??\n this.options.keySystems['*']\n const licenseServerOptionsProvider = keySystemOptions?.licenseServer\n const licenseServerOptions = await resolveValueProvider(\n licenseServerOptionsProvider ?? {}\n )\n this.abortIfDisposed()\n const existingSession = this.getSessionByInitData(initData)\n if (existingSession) {\n logDebug(this, 'reusing session')\n return existingSession\n } else {\n const newSession = await this.createNewSession(\n licenseServerOptions.serverCertificate,\n mediaKeys,\n initData,\n initDataType,\n drmInfo,\n keySystemOptions?.initDataTransformer\n )\n this.sessions.push(newSession)\n this.dispatch('sessionCreate', {\n initDataType: newSession.initDataType,\n mimeType: newSession.mimeType,\n })\n newSession.on('closed', () => this.closeSession(newSession))\n abort?.onAborted(() => {\n logDebug(this, 'abort session')\n this.closeSession(newSession)\n })\n return newSession\n }\n }\n\n initializeForPlayback(\n drmInfo: MediaFormatMetadata | null,\n abort?: ReadonlyAbort\n ): void {\n logDebug(this, 'initializeForPlayback', drmInfo)\n if (drmInfo?.contentProtections.length) {\n this.createSessionFromInitData(drmInfo, abort).catch(\n this.handleError\n )\n }\n }\n\n setBufferingDrmInfo(\n drmInfo: MediaFormatMetadata | null,\n abort?: ReadonlyAbort\n ): void {\n logDebug(this, 'setBufferingDrmInfo', drmInfo)\n // Reset 'encrypted' error reporting\n this.reset()\n this.drmInfo = drmInfo\n this.sessionAbort = abort ?? null\n }\n\n /**\n * If the drm metadata contains initialization data for the current key system, create a new session.\n * Otherwise, wait for the 'encrypted' event for the initialization data.\n */\n private async createSessionFromInitData(\n drmInfo: MediaFormatMetadata,\n abort?: ReadonlyAbort\n ) {\n if (!this.deps.commonEme) {\n this.handleError(new DrmError('DRM not supported.'))\n return\n }\n const mediaKeys = await this.attachMediaKeys(drmInfo)\n const drmProtection =\n drmInfo.contentProtections.find((cP) => {\n return cP.keySystem === mediaKeys.keySystem\n }) ?? null\n\n if (!drmProtection) {\n // Media keys have been initialized, but content is not encrypted with the current keySystem.\n throw new DrmError(\n `Encrypted content does not support set keySystem: '${mediaKeys.keySystem}'.`,\n { drmInfo }\n )\n }\n if (drmProtection.pssh) {\n await this.maybeCreateSession(\n drmInfo,\n drmInfo.initDataType ?? 'cenc',\n base64ToByteArray(drmProtection.pssh),\n abort\n )\n }\n }\n\n /**\n * Creates a CommonMediaKeySystemAccess object from the given content protection settings.\n */\n private async createAccess(\n drmInfo: MediaFormatMetadata\n ): Promise<CommonMediaKeySystemAccess> {\n const accessParamsList = this.createMediaKeySystemAccessParams(drmInfo)\n for (const { keySystem, config } of accessParamsList) {\n try {\n const access =\n await this.deps.commonEme!.requestMediaKeySystemAccess(\n keySystem,\n [config]\n )\n logDebug(\n this,\n `created media key system access for keySystem: ${access.keySystem}}`,\n config\n )\n return access\n } catch (_) {\n // ignore\n }\n }\n throw new DrmError(\n `No keySystem supported`,\n {\n contentProtections: drmInfo as any,\n attemptedKeySystems: accessParamsList.map(\n (arr) => arr.keySystem\n ),\n },\n ErrorOrigin.DRM\n )\n }\n\n /**\n * Creates a list of the MediaKeySystemAccess configurations to try for the given media format options.\n */\n private createMediaKeySystemAccessParams(\n drmInfo: MediaFormatMetadata\n ): readonly MediaKeySystemAccessParams[] {\n const keySystems = drmInfo.contentProtections\n .map((protection) => protection.keySystem)\n .sort(this.keySystemComparator)\n\n return keySystems.map((keySystem): MediaKeySystemAccessParams => {\n const mediaOptions = this.getMediaKeySystemOptions(\n keySystem,\n drmInfo.contentType\n )\n const capability: MediaKeySystemMediaCapability = {\n robustness:\n mediaOptions?.robustness ?? DrmRobustness.SW_SECURE_CRYPTO,\n encryptionScheme: drmInfo.encryptionScheme,\n }\n if (drmInfo.mimeType) {\n capability.contentType = drmInfo.mimeType\n }\n const config: MediaKeySystemConfiguration = {\n initDataTypes: [drmInfo.initDataType ?? 'cenc'],\n }\n const contentType = drmInfo.contentType\n if (contentType === 'video') {\n config.videoCapabilities = [capability]\n } else if (contentType === 'audio') {\n config.audioCapabilities = [capability]\n }\n return {\n keySystem,\n config,\n // Concatenate a list of inputs to use as a cache key for isSupported checks.\n cacheKey: [\n keySystem,\n drmInfo.mimeType,\n drmInfo.contentType,\n capability.robustness,\n drmInfo.encryptionScheme,\n drmInfo.initDataType,\n ]\n .map(String)\n .join('|'),\n }\n })\n }\n\n private getMediaKeySystemOptions(\n keySystem: DrmKeySystem,\n contentType: Maybe<ContentType>\n ): DrmMediaKeySystemOptions | undefined {\n const keySystems = this.options.keySystems\n const keySystemOptions = keySystems[keySystem] ?? keySystems['*']\n if (!keySystemOptions) return undefined\n switch (contentType) {\n case 'video':\n return keySystemOptions.video\n case 'audio':\n return keySystemOptions.audio\n default:\n return undefined\n }\n }\n\n /**\n * Creates a new key session and adds a message handler.\n */\n private async createNewSession(\n serverCertificate: Maybe<ServerCertificate>,\n mediaKeys: CommonMediaKeys,\n initData: EncryptedInitData,\n initDataType: DrmInitDataType,\n drmInfo: MediaFormatMetadata & { readonly mimeType: string },\n initDataTransformer?: InitDataTransformer\n ): Promise<CommonMediaKeySession> {\n const certBytes = serverCertificate\n ? typeof serverCertificate === 'string'\n ? base64ToByteArray(serverCertificate)\n : bufferToByteArray(serverCertificate)\n : null\n\n if (certBytes) {\n await mediaKeys.setServerCertificate(certBytes)\n }\n\n // Default initDataTransformer handles FAIR_PLAY_1_0 by packing the\n // skd init data with the content ID and server certificate.\n // FAIR_PLAY_1_0 always uses initDataType 'skd', so the default\n // does not need to explicitly check initDataType.\n const transform =\n initDataTransformer ??\n defaultInitDataTransformer(mediaKeys.keySystem, certBytes)\n initData = transform(bufferToByteArray(initData), initDataType, drmInfo)\n\n logDebug(this, 'createSession', drmInfo.mimeType, initDataType)\n const session = mediaKeys.createSession(\n drmInfo.mimeType,\n initDataType,\n initData\n )\n session.on('message', (event) => {\n withTimeout(\n this.messageHandler({\n mediaKeys: mediaKeys,\n session: session,\n event: event,\n }),\n LICENSE_TIMEOUT,\n LICENSE_TIMEOUT_MESSAGE\n ).catch(this.handleError)\n })\n session.on('error', (event) => {\n this.closeSession(session)\n this.handleError(event.error)\n })\n return session\n }\n\n /**\n * Invoked when the content decryption module needs to interact with the license server.\n */\n private async messageHandler(\n messageProps: DrmControllerMessageProps\n ): Promise<void> {\n const { mediaKeys, session, event } = messageProps\n messageEventValidator.assert(event)\n this.pendingMessageProps = messageProps\n\n const keySystem = mediaKeys.keySystem\n logDebug(this, 'message', keySystem, event.message.byteLength)\n\n const keySystemOptions = this.options.keySystems[keySystem]\n const licenseServerOptionsProvider = keySystemOptions?.licenseServer\n\n // Get the license server configuration for the current key system.\n const licenseServerOptions =\n clone(await resolveValueProvider(licenseServerOptionsProvider)) ??\n {}\n\n let challenge: BodyInit = event.message\n if (isPlayReady(keySystem)) {\n const unpacked = unpackPlayReadyChallenge(challenge)\n challenge = unpacked.challenge\n if (licenseServerOptions.init == null)\n licenseServerOptions.init = {}\n licenseServerOptions.init.headers = {\n ...normalizeHeadersInit(\n licenseServerOptions.init.headers ?? {}\n ),\n ...unpacked.headers,\n }\n }\n const key = await this.licenseProvider(\n keySystem,\n licenseServerOptions,\n challenge\n )\n this.pendingMessageProps = null\n if (session.disposed) return\n logDebug(this, 'update')\n await session.update(key)\n }\n\n //--------------------------------------------\n // Session management\n //--------------------------------------------\n\n /**\n * Closes all active DRM sessions.\n * This should not be called unless the audio source has been cleared.\n */\n closeSessions() {\n logDebug(this, `clearing ${this.sessions.length} sessions`)\n while (this.sessions.length) this.closeSession(this.sessions[0])\n }\n\n private closeSession(session: CommonMediaKeySession) {\n logDebug(this, 'closeSession')\n session.dispose()\n remove(this.sessions, session)\n this.dispatch('sessionClose', {\n initDataType: session.initDataType,\n mimeType: session.mimeType,\n })\n }\n\n /**\n * A handler which dispatches an error event.\n * Only one error event will be emitted per unique PSSH.\n * When track protections is set again, another error event may be emitted.\n */\n private readonly handleError = (error: Error) => {\n if (!this._error && !isSilentError(error)) {\n this._error = error\n this.dispatch('error', { error, target: this })\n }\n }\n\n /**\n * Returns the number of currently active sessions.\n */\n get activeSessions(): number {\n return this.sessions.length\n }\n\n /**\n * Clears the media keys from the element if they were set.\n */\n private clearMediaKeys() {\n this.closeSessions()\n if (this.mediaKeys) {\n logDebug(this, 'clearing media keys')\n this.mediaKeys.clearFromElement(this.deps.media).catch(noop)\n this.mediaKeys = null\n }\n this.mediaKeysPromise = null\n }\n\n protected abortIfDisposed() {\n if (this.disposed) throw new AbortError()\n }\n\n reset() {\n if (!this._error) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n if (this.pendingMessageProps) {\n const mediaError = this.deps.media.error\n if (mediaError && mediaError.code === mediaError.MEDIA_ERR_DECODE) {\n // Media is in a failed decoding state, cannot recover from a failed license request.\n // The PlaybackController will attempt a reset.\n logDebug(\n this,\n 'media in an error state, will not retry failed license challenge'\n )\n this.pendingMessageProps = null\n } else {\n logDebug(this, 'retrying failed license challenge')\n this.messageHandler(this.pendingMessageProps).catch(\n this.handleError\n )\n }\n }\n this.dispatch('reset', {})\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n logDebug(this, 'dispose')\n super.dispose()\n this.clearMediaKeys()\n this.disposer.dispose()\n }\n\n private getSessionByInitData(\n initData: EncryptedInitData\n ): CommonMediaKeySession | null {\n return (\n this.sessions.find((session) => {\n return buffersEqual(session.initData, initData)\n }) ?? null\n )\n }\n\n /**\n * Sort the key systems first by their priority, then by the presence of a license uri.\n */\n private readonly keySystemComparator: Comparator<DrmKeySystem> = /* @__PURE__ */ compareBy(\n (keySystem: DrmKeySystem) => {\n return -(this.options.keySystems[keySystem]?.priority ?? 0)\n },\n (keySystem: DrmKeySystem) => {\n return this.options.keySystems[keySystem]?.licenseServer != null\n ? 0\n : 1\n }\n )\n}\n\ninterface MediaKeySystemAccessParams {\n readonly keySystem: DrmKeySystem\n readonly config: MediaKeySystemConfiguration\n readonly cacheKey: string\n}\n\nconst messageEventValidator: ObjectSchema<CommonMediaKeyMessageEvent> = /* @__PURE__ */ object({\n message: /* @__PURE__ */ instanceOf(ArrayBuffer),\n})\n\nfunction hasMimeType(\n drmInfo: MediaFormatMetadata\n): drmInfo is MediaFormatMetadata & { readonly mimeType: string } {\n return drmInfo.mimeType != null\n}\n\n/**\n * Default initDataTransformer. For FAIR_PLAY_1_0, packs the skd init data\n * with the extracted content ID and server certificate into the format\n * expected by WebKit-prefixed EME. FAIR_PLAY_1_0 always uses initDataType\n * 'skd', so we only need to check the key system.\n * For all other key systems, returns init data unchanged.\n */\nfunction defaultInitDataTransformer(\n keySystem: DrmKeySystem,\n certBytes: Uint8Array<ArrayBuffer> | null\n): InitDataTransformer {\n return (initData: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer> => {\n if (keySystem === DrmKeySystem.FAIR_PLAY_1_0) {\n if (!certBytes) {\n throw new DrmError('FairPlay requires certificate data')\n }\n const contentId = extractContentId(initData)\n return createFairPlaySessionInitData(initData, contentId, certBytes)\n }\n return initData\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n base64ToByteArray,\n bufferToUtf16,\n logDebug,\n type LogTarget,\n type ReadonlyRecord,\n} from '@amazon/vinyl-util'\nimport type { XmlElement } from '@amazon/vinyl-xml'\nimport {\n attrInt,\n attrString,\n charactersString,\n element,\n elements,\n parseXml,\n parseXmlHandler,\n type XmlRules,\n} from '@amazon/vinyl-xml'\n\n/**\n * The final challenge buffer and headers for a playready license challenge.\n */\nexport interface UnpackedPlayReadyChallenge {\n readonly challenge: ArrayBuffer\n readonly headers: ReadonlyRecord<string, string>\n}\n\nconst logTarget: LogTarget = {\n logPrefix: 'unpackPlayReadyChallenge',\n}\n\n/**\n * IE and Edge wraps playready license challenges in PlayReadyKeyMessage xml.\n * Not all PlayReady clients do this.\n * Checks if the challenge is wrapped, and if so, returns the set headers and unwrapped challenge.\n * Otherwise, returns the challenge as-is with the required content type header.\n *\n * @param challenge The array buffer from the 'message' cdm event.\n */\nexport function unpackPlayReadyChallenge(\n challenge: ArrayBuffer\n): UnpackedPlayReadyChallenge {\n const xml = challenge.byteLength % 2 === 0 ? bufferToUtf16(challenge) : ''\n if (!xml.includes('PlayReadyKeyMessage')) {\n logDebug(logTarget, 'not wrapped')\n // A client that does not wrap the challenge.\n return {\n challenge,\n headers: {\n 'Content-Type': 'text/xml; charset=utf-8',\n },\n }\n }\n logDebug(logTarget, 'unpacking challenge')\n const message = parsePlayReadyKeyMessage(xml)\n const licenseAcquisition = message.PlayReadyKeyMessage.LicenseAcquisition\n const unpackedChallenge = base64ToByteArray(\n licenseAcquisition.Challenge._content\n ).buffer\n const headers: Record<string, string> = {}\n for (const element of licenseAcquisition.HttpHeaders.HttpHeader) {\n headers[element.name._content] = element.value._content\n }\n return {\n challenge: unpackedChallenge,\n headers,\n }\n}\n\ninterface PlayReadyMessage {\n readonly PlayReadyKeyMessage: PlayReadyKeyMessageType\n}\n\ninterface PlayReadyKeyMessageType {\n readonly type?: string\n readonly LicenseAcquisition: LicenseAcquisitionType\n}\n\ninterface LicenseAcquisitionType {\n readonly Version: number\n readonly Challenge: ChallengeType\n readonly HttpHeaders: HttpHeadersType\n}\n\ninterface ContentType {\n readonly _content: string\n}\n\ninterface ChallengeType extends ContentType {\n readonly encoding?: string\n}\n\ninterface HttpHeadersType {\n readonly HttpHeader: readonly HttpHeaderType[]\n}\n\ninterface HttpHeaderType {\n readonly name: ContentType\n readonly value: ContentType\n}\n\nconst challengeType: XmlRules<ChallengeType> = {\n _content: charactersString,\n encoding: attrString,\n}\n\nconst contentType: XmlRules<ContentType> = {\n _content: charactersString,\n}\n\nconst headerType: XmlRules<HttpHeaderType> = {\n name: /* @__PURE__ */ element(contentType, { required: true }),\n value: /* @__PURE__ */ element(contentType, { required: true }),\n}\n\nconst httpHeadersType: XmlRules<HttpHeadersType> = {\n HttpHeader: /* @__PURE__ */ elements(headerType, { useEmptyArrays: true }),\n}\n\nconst licenseAcquisitionType: XmlRules<LicenseAcquisitionType> = {\n Challenge: /* @__PURE__ */ element(challengeType, { required: true }),\n HttpHeaders: /* @__PURE__ */ element(httpHeadersType, { required: true }),\n Version: /* @__PURE__ */ attrInt({ required: true }),\n}\n\nconst playReadyKeyMessageType: XmlRules<PlayReadyKeyMessageType> = {\n LicenseAcquisition: /* @__PURE__ */ element(licenseAcquisitionType, { required: true }),\n type: /* @__PURE__ */ attrString(),\n}\n\nconst playReadyMessageRules: XmlRules<PlayReadyMessage> = {\n PlayReadyKeyMessage: /* @__PURE__ */ element(playReadyKeyMessageType, {\n required: true,\n }),\n}\n\n/**\n * A Content handler for a PlayReady SOAP message.\n */\nconst playReadyXmlHandler = /* @__PURE__ */ parseXmlHandler(playReadyMessageRules)\n\nexport function parsePlayReadyKeyMessage(\n xmlStr: string\n): PlayReadyMessage & XmlElement<PlayReadyMessage> {\n return parseXml(xmlStr, playReadyXmlHandler)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyAbort } from '@amazon/vinyl-util'\nimport { requestWithRetry, ValidationError } from '@amazon/vinyl-util'\nimport type { DrmKeySystem } from '../DrmKeySystem'\nimport type { LicenseProvider, LicenseServerOptions } from './LicenseProvider'\n\n/**\n * A basic LicenseProvider which uses the configuration set for the current key system,\n * transmits a challenge as the body, and returns an array buffer.\n *\n * @param keySystem The key system for the current license challenge.\n * @param serverOptions The resolved configuration. The default DrmController\n * implementation provides this from the `drm` configuration set when creating\n * a new player.\n * @param challenge The license challenge, provided by the CDM (Content Decryption\n * Module)\n * @param abort (optional) When aborted, should cancel any active requests.\n */\nexport const defaultLicenseProvider: LicenseProvider = async (\n keySystem: DrmKeySystem,\n serverOptions: LicenseServerOptions,\n challenge: ArrayBuffer,\n abort?: ReadonlyAbort\n): Promise<ArrayBuffer> => {\n if (serverOptions.url == null) {\n throw new ValidationError(\n `Missing licenseServer url in DRM configuration for keySystem: ${keySystem}`\n )\n }\n const res = await requestWithRetry(\n serverOptions.url,\n {\n method: 'POST',\n ...serverOptions.init,\n body: challenge,\n },\n { abort }\n )\n return await res.arrayBuffer()\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ValidationError } from '@amazon/vinyl-util'\nimport { ErrorOrigin } from '@amazon/vinyl-util'\nimport { bufferToUtf16 } from '@amazon/vinyl-util'\n\n/**\n * Extract contentId from event data encoded as UTF16.\n *\n * @param initData Expected byte array representing a UTF-16 string in the form\n * `skd://0b5689bb-4171-97e5-c280-99f7abe4004f`\n */\nexport function extractContentId(initData: Uint8Array<ArrayBuffer>): string {\n const bufferStr = bufferToUtf16(initData.buffer)\n const matches = bufferStr.match(/skd:\\/\\/(.+)$/)\n if (!matches) {\n throw new ValidationError('No contentId match', ErrorOrigin.MEDIA)\n }\n return matches[1]\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { utf16ToUint16Array } from '@amazon/vinyl-util'\n\n/**\n * Create the payload for EME media key session from `encrypted` / `*needkey` event data and DRM\n * certificate.\n * Note: This code is taken from the official FairPlay SDK example.\n *\n * @param initData\n * @param contentId\n * @param certificateData certificate data as a Uint8Array\n */\nexport function createFairPlaySessionInitData(\n initData: Uint8Array,\n contentId: string,\n certificateData: Uint8Array\n): Uint8Array<ArrayBuffer> {\n const contentIdUint16 = utf16ToUint16Array(contentId)\n const certificateDataUint8 = certificateData\n\n let offset = 0\n const buffer = new ArrayBuffer(\n initData.byteLength +\n 4 + // contentId length\n contentIdUint16.byteLength +\n 4 + // certificateDataUint8 length\n certificateDataUint8.byteLength\n )\n\n const initDataArray = new Uint8Array(buffer, offset, initData.byteLength)\n initDataArray.set(initData)\n offset += initData.byteLength\n\n const dataView = new DataView(buffer)\n dataView.setUint32(offset, contentIdUint16.byteLength, true)\n offset += 4\n\n const idArray = new Uint16Array(buffer, offset, contentIdUint16.length)\n idArray.set(contentIdUint16)\n offset += idArray.byteLength\n\n dataView.setUint32(offset, certificateDataUint8.byteLength, true)\n offset += 4\n\n const certArray = new Uint8Array(\n buffer,\n offset,\n certificateDataUint8.byteLength\n )\n certArray.set(certificateDataUint8)\n\n return new Uint8Array(buffer, 0, buffer.byteLength)\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type ReadonlyRecord } from '@amazon/vinyl-util'\nimport {\n DrmKeySystem,\n FAIR_PLAY_KEY_SYSTEMS,\n PLAY_READY_KEY_SYSTEMS,\n} from './DrmKeySystem'\nimport { ContentProtectionScheme } from '@amazon/vinyl-mpd-parser'\n\n/**\n * Given a ContentProtection schemeIdUri, returns the {@link DrmKeySystem} it represents.\n * Not all scheme ids will match to a DrmKeySystem. If none are matched, null is returned.\n * For example, CENC 'urn:mpeg:dash:mp4protection:2011' has no key system and shouldn't be used\n * to create a key session.\n */\nexport type DrmKeySystemResolver = (\n schemeIdUri: string\n) => readonly DrmKeySystem[]\n\nlet _defaultSchemeToKeySystem: ReadonlyRecord<\n string,\n readonly DrmKeySystem[]\n> | null = null\n\nexport function getDefaultSchemeToKeySystem(): ReadonlyRecord<\n string,\n readonly DrmKeySystem[]\n> {\n if (_defaultSchemeToKeySystem == null) {\n _defaultSchemeToKeySystem = {\n [ContentProtectionScheme.CLEAR_KEY]: [DrmKeySystem.CLEAR_KEY],\n [ContentProtectionScheme.FAIR_PLAY]: FAIR_PLAY_KEY_SYSTEMS,\n [ContentProtectionScheme.PLAY_READY]: PLAY_READY_KEY_SYSTEMS,\n [ContentProtectionScheme.WIDEVINE]: [DrmKeySystem.WIDEVINE],\n } as const\n }\n return _defaultSchemeToKeySystem\n}\n\nexport const defaultDrmKeySystemResolver: DrmKeySystemResolver = (\n schemeIdUri: string\n) => {\n return getDefaultSchemeToKeySystem()[schemeIdUri.toLowerCase()] ?? []\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { createDisposer, type LogTarget } from '@amazon/vinyl-util'\nimport {\n logDebug,\n createLogPrefix,\n EventHostImpl,\n closeTo,\n} from '@amazon/vinyl-util'\nimport type {\n LoudnessNormalizationController,\n LoudnessNormalizationControllerEventMap,\n} from './LoudnessNormalizationController'\nimport {\n defaultLoudnessNormalizationControllerImplOptions,\n type LoudnessNormalizationControllerImplOptions,\n} from './LoudnessNormalizationControllerImplOptions'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\n\nexport type LoudnessNormalizationControllerImplDeps = {\n readonly options: ObservableValue<LoudnessNormalizationControllerImplOptions>\n}\n\nconst DECIBEL_EXPONENT_BASE = /* @__PURE__ */ Math.pow(10, 1 / 10)\nconst MAX_GAIN_LEVEL = 1.0\n\n/**\n * Applies gain adjustment based on track loudness metadata from manifest.\n * This controller normalizes audio loudness to a target level for consistent playback volume.\n */\nexport class LoudnessNormalizationControllerImpl\n extends EventHostImpl<LoudnessNormalizationControllerEventMap>\n implements LoudnessNormalizationController, LogTarget\n{\n get [Symbol.toStringTag](): string {\n return 'LoudnessNormalizationControllerImpl'\n }\n readonly logPrefix = /* @__PURE__ */ createLogPrefix(this)\n\n private _gain: number = MAX_GAIN_LEVEL\n private readonly disposer = /* @__PURE__ */ createDisposer()\n\n private trackLoudness: number | null = null\n private _options: Required<LoudnessNormalizationControllerImplOptions> =\n defaultLoudnessNormalizationControllerImplOptions\n\n constructor(\n private readonly deps: LoudnessNormalizationControllerImplDeps\n ) {\n super()\n const { add } = this.disposer\n add(\n deps.options.onData((value) => {\n this._options = {\n ...defaultLoudnessNormalizationControllerImplOptions,\n ...value,\n }\n this.updateGain()\n })\n )\n }\n\n get options(): Required<LoudnessNormalizationControllerImplOptions> {\n return this._options\n }\n\n setTrackLoudness(value: number | null): void {\n this.trackLoudness = value\n this.updateGain()\n }\n\n /**\n * Returns the loudness gain value which needs to be applied, for current track playback.\n */\n public get gain(): number {\n return this._gain\n }\n\n /**\n * Sets the loudness gain value for current track playback.\n *\n * @param value New gain value to apply\n */\n private set gain(value: number) {\n const previousGain = this._gain\n // Emit change event if gain value changed\n if (!closeTo(previousGain, value)) {\n this._gain = value\n logDebug(this, 'loudness gain adjustment:', {\n trackLoudness: this.trackLoudness,\n targetLufs: this.options.targetLufs,\n gain: value,\n })\n this.dispatch('change', {})\n }\n }\n\n /**\n * Update gain value based on current track loudness and target loudness.\n */\n private updateGain(): void {\n const { targetLufs, maxGainDb, enabled } = this.options\n const trackLoudness = this.trackLoudness\n if (trackLoudness == null) {\n return\n }\n if (trackLoudness <= targetLufs || !enabled) {\n this.clear()\n return\n }\n // Calculate gain reduction for louder tracks\n const dbReduction = Math.min(trackLoudness - targetLufs, maxGainDb)\n this.gain =\n MAX_GAIN_LEVEL / Math.pow(DECIBEL_EXPONENT_BASE, dbReduction)\n }\n\n /**\n * Resets the loudness gain Value to max gain value.\n */\n clear(): void {\n this.gain = MAX_GAIN_LEVEL\n }\n\n dispose(): void {\n super.dispose()\n this.disposer.dispose()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport { boolean, number, object } from '@amazon/vinyl-validation'\n\n/**\n * Options for configuring the loudness normalization controller.\n */\nexport interface LoudnessNormalizationControllerImplOptions {\n /**\n * If true, applies loudness Normalization to the current track played.\n * Default: false\n */\n readonly enabled: boolean\n\n /**\n * Target loudness level in LUFS (Loudness Units relative to Full Scale).\n * Default: -14.0 dB\n */\n readonly targetLufs?: number\n\n /**\n * Maximum gain reduction to apply in dB.\n * Default: 10 Db\n */\n readonly maxGainDb?: number\n}\n\nexport const defaultLoudnessNormalizationControllerImplOptions = {\n enabled: false,\n targetLufs: -14.0,\n maxGainDb: 10.0,\n} as const satisfies LoudnessNormalizationControllerImplOptions\n\nexport const loudnessNormalizationControllerImplOptionsValidator: ObjectSchema<LoudnessNormalizationControllerImplOptions> =\n /* @__PURE__ */ object({\n enabled: /* @__PURE__ */ boolean(),\n targetLufs: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n maxGainDb: /* @__PURE__ */ /* @__PURE__ */ number().optional(),\n })\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n type Clearable,\n createDisposer,\n type Disposable,\n EventHostImpl,\n getNetworkState,\n logDebug,\n onAny,\n type ReadonlyEventHost,\n RequestError,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport type { PlaybackController } from '../playback/PlaybackController'\nimport type { ChangeEvent } from '../event/ChangeEvent'\n\nexport interface AutoResetControllerEventMap {\n /**\n * Notifies that playback errors should be reset and retried.\n */\n readonly reset: AnyRecord\n\n /**\n * Dispatched when {@link AutoResetController.resetPending} changes.\n */\n readonly resetPendingChange: ChangeEvent<boolean>\n}\n\n/**\n * Notifies when playback should be reset and retried after a transient,\n * potentially-recoverable error.\n *\n * Once an eligible error is set, the controller watches for opportunities\n * to emit a `reset` event:\n * - Immediately when the network transitions back to online\n * - After a timeout interval, if online and retries are not exhausted\n * - Immediately on user playback actions (play, pause, seeking, playing)\n *\n * Each error triggers a single retry timeout. If another error occurs\n * after a reset, {@link AutoResetController.setError} should be called again\n * to schedule the next retry attempt.\n */\nexport interface AutoResetController\n extends ReadonlyEventHost<AutoResetControllerEventMap>, Clearable {\n /**\n * Sets the current playback error and, if eligible, begins watching for\n * retry opportunities.\n *\n * An error is eligible when it is a {@link RequestError} that did not\n * receive an HTTP response (i.e. `response == null`), indicating a\n * transient network failure such as connection loss or DNS failure.\n * All other errors \u2014 including HTTP failures with a response (4xx/5xx),\n * and non-RequestError errors \u2014 are ignored, since those are unlikely\n * to recover on their own.\n *\n * Subsequent calls while an error is already set are ignored until the\n * error is cleared via a reset emission or {@link Clearable.clear}.\n *\n * After a reset, if another eligible error occurs, this method should\n * be called again to schedule the next retry attempt.\n *\n * @param error The error to monitor for retry opportunities\n */\n setError(error: Error): void\n\n /**\n * True while an eligible error is being watched and a `reset` event\n * may still be emitted. Becomes false once the error is cleared, a\n * reset is emitted, or all retries are exhausted.\n *\n * Listen to `resetPendingChange` events for changes.\n */\n readonly resetPending: boolean\n}\n\nexport interface AutoResetControllerImplDeps {\n readonly playbackController: PlaybackController\n}\n\nexport interface AutoResetControllerImplOptions {\n /**\n * If false, disables auto reset behavior.\n * default: true\n */\n readonly enabled: boolean\n\n /**\n * The total number of times to reset when there has not been successful\n * playback.\n *\n * E.g. a retryInterval of 30 and maxRetries of 30 will retry for 15 minutes before stopping.\n *\n * default: 30\n */\n readonly maxRetries: number\n\n /**\n * The number of seconds between retries.\n *\n * When an error is set, a single timeout is scheduled for this interval.\n * If the retry limit hasn't been reached and the device is online, a reset\n * event is emitted. For subsequent errors after reset, setError() must be\n * called again to schedule the next retry timeout.\n */\n readonly retryInterval: number\n}\n\nexport const defaultResetControllerOptions = {\n enabled: true,\n maxRetries: 30,\n retryInterval: 30,\n} as const satisfies AutoResetControllerImplOptions\n\nexport class AutoResetControllerImpl\n extends EventHostImpl<AutoResetControllerEventMap>\n implements AutoResetController, Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'AutoResetControllerImpl'\n }\n\n private readonly options: AutoResetControllerImplOptions\n private _error: Error | null = null\n private watchSub: Unsubscribe | null = null\n private currentRetry = 0\n private disposer = /* @__PURE__ */ createDisposer()\n\n constructor(\n readonly deps: AutoResetControllerImplDeps,\n options?: Partial<AutoResetControllerImplOptions>\n ) {\n super()\n logDebug(this, 'constructor')\n this.options = {\n ...defaultResetControllerOptions,\n ...options,\n }\n\n this.disposer.add(\n onAny(\n deps.playbackController,\n ['play', 'pause', 'seeking', 'playing'],\n (_event) => {\n // On certain user-initiated playback events, reset the currentRetry count and emit a reset event\n // if in an error state.\n this.currentRetry = 0\n this.reset()\n }\n )\n )\n }\n\n setError(error: Error): void {\n if (!this.options.enabled || this._error) return\n if (error instanceof RequestError && error.response == null) {\n this._error = error\n this.setResetPending(true)\n }\n }\n\n get resetPending(): boolean {\n return this.watchSub != null\n }\n\n private setResetPending(value: boolean): void {\n if (this.resetPending === value) {\n logDebug(this, 'setResetPending', value, 'no-op')\n return\n }\n logDebug(this, 'setResetPending', value)\n this.watchSub?.()\n this.watchSub = null\n if (value) {\n const networkState = getNetworkState()\n const { add, dispose: watchSub } = createDisposer()\n this.watchSub = watchSub\n add(\n networkState.on('online', () => {\n logDebug(this, 'online, emitting reset')\n this.reset()\n })\n )\n\n const intervalId = setTimeout(() => {\n if (this.currentRetry++ < this.options.maxRetries) {\n if (networkState.onLine) {\n logDebug(this, 'interval, emitting reset')\n this.reset()\n }\n } else {\n logDebug(this, 'max retries exhausted, pausing playback')\n this.setResetPending(false)\n }\n }, this.options.retryInterval * 1000)\n add(() => clearTimeout(intervalId))\n }\n this.dispatch('resetPendingChange', {\n previous: !value,\n current: value,\n })\n }\n\n private reset(): void {\n if (!this._error) return\n this.clear()\n this.dispatch('reset', {})\n }\n\n clear() {\n if (!this._error) return\n this._error = null\n this.setResetPending(false)\n }\n\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n dispose(): void {\n this.disposer.dispose()\n this.clear()\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n defaultQualitySelectorImplOptions,\n type QualitySelectorImplOptions,\n qualitySelectorImplOptionsValidator,\n} from '../streaming/abr/QualitySelectorImpl'\nimport type { ObjectSchema } from '@amazon/vinyl-validation'\nimport { object, string } from '@amazon/vinyl-validation'\nimport {\n defaultLoudnessNormalizationControllerImplOptions,\n type LoudnessNormalizationControllerImplOptions,\n loudnessNormalizationControllerImplOptionsValidator,\n} from '../playback/loudness/LoudnessNormalizationControllerImplOptions'\n\nexport interface VinylOptions {\n /**\n * Configuration for the default adaptive bitrate selector.\n */\n readonly abr: QualitySelectorImplOptions\n\n readonly loudnessNormalization: LoudnessNormalizationControllerImplOptions\n\n /**\n * Preferred language for audio content, using a code as defined by RFC 5646 (e.g. 'en', 'ja').\n * When set, only adaptation sets / variants matching this language (or without a language tag)\n * are kept. Null means no language preference (all languages are kept).\n */\n readonly preferredAudioLanguage: string | null\n}\n\nexport const defaultVinylOptions: VinylOptions = {\n abr: defaultQualitySelectorImplOptions,\n loudnessNormalization: defaultLoudnessNormalizationControllerImplOptions,\n preferredAudioLanguage: null,\n}\n\nexport const vinylOptionsValidator: ObjectSchema<VinylOptions> = /* @__PURE__ */ object({\n abr: qualitySelectorImplOptionsValidator,\n loudnessNormalization: loudnessNormalizationControllerImplOptionsValidator,\n preferredAudioLanguage: /* @__PURE__ */ /* @__PURE__ */ string().orNull(),\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Client } from '../client/Client'\nimport {\n type AnyRecord,\n createDisposer,\n type Disposable,\n emptyRanges,\n equalDeep,\n EventHostImpl,\n logDebug,\n logInfo,\n type ReadonlyRanges,\n type ReadonlySet,\n redispatchEvents,\n type Unsubscribe,\n} from '@amazon/vinyl-util'\nimport {\n createContainer,\n type Factories,\n type ValidFactoryOverrides,\n} from '@amazon/vinyl-di'\nimport { playerRegistryRef } from '../global/PlayerRegistry'\nimport type { PlaybackController } from '../playback/PlaybackController'\nimport {\n ALL_PLAYBACK_STATE_EVENTS,\n type PlaybackControllerEventMap,\n type PlaybackNetworkState,\n type PlaybackReadyState,\n} from '../playback/ReadonlyPlaybackController'\nimport type { VinylTrackLoadOptions } from '../track/createVinylTrackFactories'\nimport { type ReadonlyTrack, type TrackUri } from '../track/Track'\nimport {\n ALL_TRACK_CONTROLLER_EVENTS,\n type TrackController,\n type TrackControllerEventMap,\n} from '../track/TrackController'\nimport type {\n InferLoadOptionsFromFactory,\n TrackLoadOptions,\n} from '../track/TrackFactory'\nimport type {\n DefaultVinylFactories,\n InferVinylOverrideDependencyType,\n VinylDependencyOptions,\n} from './createVinylFactories'\nimport { createVinylFactories } from './createVinylFactories'\nimport type { VinylDeps } from './VinylDeps'\nimport type { Capabilities } from '../client/Capabilities'\nimport { initializeVinylGlobal } from '../global/initializeVinylGlobal'\nimport {\n ALL_CONTENT_TYPES,\n type ContentType,\n type MediaQualityMetadata,\n} from '../streaming/MediaQualityMetadata'\nimport type { ReadonlyPlaybackStreamingState } from './ReadonlyPlaybackStreamingState'\nimport type { DrmController } from '../drm/DrmController'\nimport {\n ALL_STREAMING_EVENTS,\n type StreamingEventMap,\n} from '../streaming/StreamingEventMap'\nimport type {\n InferObservableValueType,\n MutableValue,\n} from '@amazon/vinyl-observable'\nimport type { VinylOptions } from './VinylOptions'\nimport type { AutoResetController } from '../track/AutoResetController'\nimport type { ChangeEvent } from '../event/ChangeEvent'\n\n/**\n * Events the Vinyl Player emits.\n */\nexport interface VinylPlayerEventMap<\n TrackLoadOptionsType extends TrackLoadOptions = VinylTrackLoadOptions,\n>\n extends\n PlaybackControllerEventMap,\n TrackControllerEventMap<TrackLoadOptionsType>,\n StreamingEventMap {\n /**\n * Dispatched when {@link VinylPlayer.resetPending} changes.\n *\n * `current` is true when the player has hit a transient, potentially\n * recoverable error (e.g. a network outage) and an automatic reset\n * attempt is scheduled. `current` is false once the pending reset is\n * emitted, the error is cleared, or all retries are exhausted.\n *\n * If `resetPending` becomes false while {@link VinylPlayer.error} is\n * still non-null, all automatic reset attempts have been exhausted\n * and playback will not recover without user action.\n */\n readonly resetPendingChange: ChangeEvent<boolean>\n}\n\n/**\n * A Vinyl Media Player.\n *\n * Unless custom dependencies need to be provided, use {@link createVinylPlayer} to construct\n * a new player implementation.\n */\nexport class VinylPlayer<\n TrackLoadOptionsType extends TrackLoadOptions = VinylTrackLoadOptions,\n OptionsType = VinylOptions,\n>\n extends EventHostImpl<VinylPlayerEventMap<TrackLoadOptionsType>>\n implements\n PlaybackController,\n TrackController<TrackLoadOptionsType>,\n ReadonlyPlaybackStreamingState,\n Disposable\n{\n get [Symbol.toStringTag](): string {\n return 'VinylPlayer'\n }\n\n protected readonly deps: VinylDeps<TrackLoadOptionsType, OptionsType>\n\n private get drmController(): DrmController {\n return this.deps.drmController\n }\n\n private get playbackController(): PlaybackController {\n return this.deps.playbackController\n }\n\n private get trackController(): TrackController<TrackLoadOptionsType> {\n return this.deps.trackController\n }\n\n private get autoResetController(): AutoResetController {\n return this.deps.autoResetController\n }\n\n /**\n * Provides information about the client, such as device and browser capabilities.\n */\n readonly client: Client\n\n private _error: Error | null = null\n\n protected readonly disposer = /* @__PURE__ */ createDisposer()\n\n /**\n * Constructs a new VinylPlayer with the given dependency factories.\n * This constructor is protected, use {@link createVinylPlayer} to construct a new player.\n *\n * @param factories\n * @see createVinylPlayer\n */\n protected constructor(\n factories: Factories<VinylDeps<TrackLoadOptionsType, OptionsType>>\n ) {\n initializeVinylGlobal()\n super()\n const add = this.disposer.add\n this.deps = add(createContainer(factories)).dependencies\n\n this.client = {\n capabilities: this.deps.capabilities,\n }\n playerRegistryRef.value.addPlayer(this)\n this.redispatchSubControllerEvents()\n this.redispatchCurrentTrackEvents()\n this.initializeAutoResetHandling()\n this.initializePreferredLanguageHandling()\n }\n\n protected redispatchSubControllerEvents(): void {\n const add = this.disposer.add\n add(\n redispatchEvents(\n this,\n this.playbackController,\n ALL_PLAYBACK_STATE_EVENTS.filter(notResetEvent)\n )\n )\n add(\n redispatchEvents(\n this,\n this.trackController,\n ALL_TRACK_CONTROLLER_EVENTS\n )\n )\n add(redispatchEvents(this, this.drmController, ['error']))\n\n this.on('error', (event) => {\n this._error = event.error\n })\n }\n\n /**\n * Certain track events are redispatched on the player for the current track.\n */\n protected redispatchCurrentTrackEvents() {\n let sub: Unsubscribe | null = null\n const add = this.disposer.add\n add(\n this.trackController.on('currentTrackChange', (event) => {\n sub?.()\n sub = null\n if (event.current) {\n sub = redispatchEvents(\n this,\n event.current,\n ALL_STREAMING_EVENTS.filter(notResetEvent)\n )\n }\n this.dispatch('fetchedRangesChange', {})\n\n // Emit a quality change event for every stream that has changed\n // for streaming, buffering, and playback\n for (const contentType of ALL_CONTENT_TYPES) {\n for (const [\n eventType,\n getterName,\n ] of qualityEventsAndGetters) {\n const previous =\n event.previous?.[getterName](contentType) ?? null\n const current =\n event.current?.[getterName](contentType) ?? null\n if (previous !== current) {\n this.dispatch(eventType, {\n previous,\n current,\n })\n }\n }\n }\n\n // Emit qualities change events on track switch\n const prevQualities = event.previous?.qualities ?? null\n const curQualities = event.current?.qualities ?? null\n if (prevQualities !== curQualities && curQualities) {\n this.dispatch('qualitiesChange', {\n previous: prevQualities ?? [],\n current: curQualities,\n })\n }\n const prevUnfiltered =\n event.previous?.qualitiesUnfiltered ?? null\n const curUnfiltered = event.current?.qualitiesUnfiltered ?? null\n if (prevUnfiltered !== curUnfiltered && curUnfiltered) {\n this.dispatch('qualitiesUnfilteredChange', {\n previous: prevUnfiltered ?? [],\n current: curUnfiltered,\n })\n }\n })\n )\n }\n\n private initializeAutoResetHandling() {\n // Initializes the binding between the player and the reset handler.\n // On an error, notify the auto reset controller which will\n // monitor network changes and periodically request a reset.\n const { add } = this.disposer\n this.on('error', (event) => {\n this.autoResetController.setError(event.error)\n })\n add(this.autoResetController.on('reset', () => this.reset()))\n add(\n this.autoResetController.on('resetPendingChange', (event) =>\n this.dispatch('resetPendingChange', event)\n )\n )\n }\n\n private initializePreferredLanguageHandling() {\n const { add } = this.disposer\n // When the preferred language changes, clear the prefetch to immediately switch.\n add(\n (this.deps.options as MutableValue<VinylOptions>)\n .pick('preferredAudioLanguage')\n .onData((_value, previous) => {\n if (previous !== undefined) this.clearPrefetch()\n })\n )\n }\n\n /**\n * Returns the current player options.\n * Use `configure` to set.\n */\n get options(): OptionsType {\n return this.deps.options.value\n }\n\n /**\n * Sets options on this player.\n * Options will be merged shallowly, for example,\n * `configure({ abr: { strategy: AbrStrategy.BEST }})` will replace all previous `abr` options, and not\n * change other options such as `loudnessNormalization`.\n *\n * @param options\n */\n configure(options: Partial<OptionsType>): void {\n logDebug(this, 'configure', options)\n const newValue = { ...this.options, ...options }\n if (!equalDeep(newValue, this.options)) {\n this.deps.options.value = newValue\n }\n }\n\n get capabilities(): Capabilities {\n return this.deps.capabilities\n }\n\n //----------------------------------------------------\n // PlaybackController delegate methods\n //----------------------------------------------------\n\n get buffered(): ReadonlyRanges {\n return this.playbackController.buffered\n }\n\n get canPlay(): boolean {\n return this.playbackController.canPlay\n }\n\n get canPlayThrough(): boolean {\n return this.playbackController.canPlayThrough\n }\n\n get currentTime(): number {\n return this.playbackController.currentTime\n }\n\n get currentTimePercent(): number {\n return this.playbackController.currentTimePercent\n }\n\n get defaultPlaybackRate(): number {\n return this.playbackController.defaultPlaybackRate\n }\n\n set defaultPlaybackRate(value: number) {\n this.playbackController.defaultPlaybackRate = value\n }\n\n get duration(): number {\n return this.playbackController.duration\n }\n\n get ended(): boolean {\n return this.playbackController.ended\n }\n\n /**\n * The last error reported.\n */\n get error(): Error | null {\n return this._error\n }\n\n /**\n * True when an error has interrupted playback and an automatic reset\n * is scheduled. This distinguishes transient, potentially recoverable\n * errors (such as a brief network outage) from terminal errors that\n * will not trigger a reset on their own.\n *\n * Listen to `resetPendingChange` events for changes.\n */\n get resetPending(): boolean {\n return this.autoResetController.resetPending\n }\n\n get hasMetadata(): boolean {\n return this.playbackController.hasMetadata\n }\n\n get loop(): boolean {\n return this.playbackController.loop\n }\n\n set loop(value: boolean) {\n this.playbackController.loop = value\n }\n\n get muted(): boolean {\n return this.playbackController.muted\n }\n\n set muted(value: boolean) {\n this.playbackController.muted = value\n }\n\n get networkState(): PlaybackNetworkState {\n return this.playbackController.networkState\n }\n\n get paused(): boolean {\n return this.playbackController.paused\n }\n\n get playbackRate(): number {\n return this.playbackController.playbackRate\n }\n\n set playbackRate(value: number) {\n this.playbackController.playbackRate = value\n }\n\n get playIsPending(): boolean {\n return this.playbackController.playIsPending\n }\n\n get playing(): boolean {\n return this.playbackController.playing\n }\n\n get preservesPitch(): boolean {\n return this.playbackController.preservesPitch\n }\n\n set preservesPitch(value: boolean) {\n this.playbackController.preservesPitch = value\n }\n\n get readyState(): PlaybackReadyState {\n return this.playbackController.readyState\n }\n\n get seekable(): ReadonlyRanges {\n return this.playbackController.seekable\n }\n\n get seeking(): boolean {\n return this.playbackController.seeking\n }\n\n get volume(): number {\n return this.playbackController.volume\n }\n\n set volume(value: number) {\n this.playbackController.volume = value\n }\n\n get waiting(): boolean {\n return this.playbackController.waiting\n }\n\n pause(): void {\n this.playbackController.pause()\n }\n\n play(): Promise<void> {\n return this.playbackController.play()\n }\n\n seekTo(time: number, tolerance?: number): Promise<void> {\n return this.playbackController.seekTo(time, tolerance)\n }\n\n reset() {\n if (!this._error) {\n logDebug(this, 'reset no-op')\n return\n }\n logDebug(this, 'reset')\n this._error = null\n this.drmController.reset()\n this.playbackController.reset()\n this.trackController.reset()\n this.autoResetController.clear()\n this.dispatch('reset', {})\n }\n\n //----------------------------------------------------\n // TrackController delegate methods\n //----------------------------------------------------\n\n get currentTrack(): ReadonlyTrack | null {\n return this.trackController.currentTrack\n }\n\n get queue(): readonly TrackLoadOptionsType[] {\n return this.trackController.queue\n }\n\n preload(...loadOptionsList: TrackLoadOptionsType[]): void {\n this.trackController.preload(...loadOptionsList)\n }\n\n load(...loadOptionsList: TrackLoadOptionsType[]): void {\n this.trackController.load(...loadOptionsList)\n }\n\n enqueue(...loadOptionsList: TrackLoadOptionsType[]): void {\n this.trackController.enqueue(...loadOptionsList)\n }\n\n unload(): void {\n this.trackController.unload()\n }\n\n hasNext(): boolean {\n return this.trackController.hasNext()\n }\n\n next(): void {\n return this.trackController.next()\n }\n\n isTrackCached(uri: TrackUri): boolean {\n return this.trackController.isTrackCached(uri)\n }\n\n getCachedTrack(uri: TrackUri): ReadonlyTrack | null {\n return this.trackController.getCachedTrack(uri)\n }\n\n getCachedTracks(): IterableIterator<ReadonlyTrack> {\n return this.trackController.getCachedTracks()\n }\n\n clearPrefetch(): void {\n this.trackController.clearPrefetch()\n }\n\n clearTrackCache(): void {\n this.trackController.clearTrackCache()\n }\n\n clearQueue(): void {\n this.trackController.clearQueue()\n }\n\n //----------------------------------------------------\n // CurrentTrackStreamingState methods\n //----------------------------------------------------\n\n /**\n * Returns the fetched ranges of the current track.\n * If there is no current track, empty ranges will be returned.\n *\n * Listen to {@link VinylPlayerEventMap.fetchedRangesChange} for changes.\n */\n get fetchedRanges(): ReadonlyRanges {\n return this.currentTrack?.fetchedRanges ?? emptyRanges\n }\n\n /**\n * Returns the time of the prefetch end.\n * If no data has been prefetched for the current track, 0 will be returned.\n *\n * The time given will be in seconds according to the media timeline.\n * It will represent the ending time of the continuous prefetch range from the current playhead time.\n */\n get fetchedTime(): number {\n const time = this.playbackController.currentTime\n const range = this.fetchedRanges.getRangeAt(time)\n if (!range) return 0\n return range[1]\n }\n\n /**\n * Returns current fetched time as a percent of the total duration.\n *\n * @return A number between 0-1\n */\n get fetchedTimePercent(): number {\n return this.duration > 0 ? this.fetchedTime / this.duration : 0\n }\n\n /**\n * Returns the current content types for active streams.\n */\n get contentTypes(): ReadonlySet<ContentType> {\n return this.currentTrack?.contentTypes ?? emptyContentTypes\n }\n\n /**\n * The available qualities for the current period of the current track, after filtering.\n * Null if no track is active or the timeline is not yet available.\n */\n get qualities(): readonly MediaQualityMetadata[] | null {\n return this.currentTrack?.qualities ?? null\n }\n\n /**\n * The available unfiltered qualities for the current period of the current track.\n * Null if no track is active or the timeline is not yet available.\n */\n get qualitiesUnfiltered(): readonly MediaQualityMetadata[] | null {\n return this.currentTrack?.qualitiesUnfiltered ?? null\n }\n\n /**\n * @deprecated Use `getStreamingQuality('audio')`\n */\n get streamingQuality(): MediaQualityMetadata | null {\n return this.getStreamingQuality('audio')\n }\n\n /**\n * @deprecated Use `getBufferingQuality('audio')\n */\n get bufferingQuality(): MediaQualityMetadata | null {\n return this.getStreamingQuality('audio')\n }\n\n /**\n * @deprecated Use `getPlaybackQuality('audio')\n */\n get playbackQuality(): MediaQualityMetadata | null {\n return this.getPlaybackQuality('audio')\n }\n\n /**\n * The streaming quality for the current track.\n * Note that this does not represent the quality of inactive preloading tracks.\n */\n getStreamingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.currentTrack?.getStreamingQuality(contentType) ?? null\n }\n\n /**\n * The currently buffering quality, or null if no data is buffered.\n */\n getBufferingQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.currentTrack?.getBufferingQuality(contentType) ?? null\n }\n\n /**\n * The currently playing quality, or null if no media is playing.\n */\n getPlaybackQuality(contentType: ContentType): MediaQualityMetadata | null {\n return this.currentTrack?.getPlaybackQuality(contentType) ?? null\n }\n\n //----------------------------------------------------\n\n /**\n * Returns true if this player has been disposed.\n */\n get disposed(): boolean {\n return this.disposer.disposed\n }\n\n /**\n * Disposes this player and sub-systems.\n */\n dispose(): void {\n logDebug(this, 'dispose')\n super.dispose()\n this.disposer.dispose()\n playerRegistryRef.value.removePlayer(this)\n }\n}\n\n/**\n * Constructs a new {@link VinylPlayer}.\n *\n * @param options Configuration for default dependencies.\n * @param factoryOverrides Dependency factory overrides.\n */\nexport function createVinylPlayer<\n DependencyOverridesType extends Factories | undefined,\n>(\n options: VinylDependencyOptions,\n factoryOverrides?: ValidFactoryOverrides<\n VinylDeps<any, AnyRecord>,\n DefaultVinylFactories,\n DependencyOverridesType\n >\n): VinylPlayer<\n // The player will accept the load options for the track factories, accounting for overrides.\n InferLoadOptionsFromFactory<\n InferVinylOverrideDependencyType<\n NoInfer<DependencyOverridesType>,\n 'trackFactory'\n >\n >,\n // Infer the options type.\n InferObservableValueType<\n InferVinylOverrideDependencyType<\n NoInfer<DependencyOverridesType>,\n 'options'\n >\n >\n> {\n const player = new (VinylPlayer as any)({\n ...createVinylFactories(options),\n ...factoryOverrides,\n })\n logInfo(player, `VinylPlayer initialized`)\n return player\n}\n\n/**\n * Do not redispatch reset events, only emit the reset event when `player.reset` is called.\n * @param type\n */\nfunction notResetEvent<T extends string>(type: T): type is Exclude<T, 'reset'> {\n return type !== 'reset'\n}\n\nconst qualityEventsAndGetters = [\n ['streamingQualityChange', 'getStreamingQuality'],\n ['bufferingQualityChange', 'getBufferingQuality'],\n ['playbackQualityChange', 'getPlaybackQuality'],\n] as const\n\nconst emptyContentTypes = /* @__PURE__ */ new Set<ContentType>()\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AnyRecord, Disposable } from '@amazon/vinyl-util'\nimport {\n globalRef,\n globalTarget,\n IllegalStateError,\n logWarn,\n remove,\n substitute,\n} from '@amazon/vinyl-util'\n\n/**\n * @private\n */\nconst locale = {\n maxPlayersWarning: `{count} Vinyl Players have been constructed without disposal. Check that player.dispose is properly being called, then increase the maxPlayersWarning option if this was intentional.`,\n} as const\n\n/**\n * A registry of all non-disposed Vinyl players.\n * Used for debugging and cleanup validation.\n */\nexport interface PlayerRegistry {\n /**\n * Returns the non-disposed Vinyl players.\n */\n readonly players: readonly AnyRecord[]\n\n /**\n * Adds a player reference. All players must be removed before disposing VinylGlobal.\n *\n * @param player\n */\n addPlayer(player: AnyRecord): void\n\n /**\n * Removes a player reference.\n *\n * @param player\n */\n removePlayer(player: AnyRecord): void\n}\n\nexport const DEFAULT_MAX_PLAYERS = 5\n\n/**\n * A registry of non-disposed players.\n * Used for leak detection and debugging diagnostics.\n */\nexport class PlayerRegistryImpl implements PlayerRegistry, Disposable {\n private _players: AnyRecord[] = []\n\n private gaveMaxPlayersWarning = false\n\n constructor(\n /**\n * The number of concurrent players before a warning is logged.\n * default: 5\n */\n public maxPlayersWarning: number = DEFAULT_MAX_PLAYERS\n ) {}\n\n get players(): readonly AnyRecord[] {\n return this._players\n }\n\n addPlayer(player: AnyRecord): void {\n this._players.push(player)\n const n = this._players.length\n if (n > this.maxPlayersWarning && !this.gaveMaxPlayersWarning) {\n this.gaveMaxPlayersWarning = true\n logWarn(\n globalTarget,\n substitute(locale.maxPlayersWarning, { count: n })\n )\n }\n }\n\n removePlayer(player: AnyRecord): void {\n remove(this._players, player)\n }\n\n /**\n * @throws An IllegalStateError if all players have not been removed.\n */\n dispose() {\n if (this._players.length)\n throw new IllegalStateError(\n 'All players must be removed before disposing VinylGlobal'\n )\n }\n}\n\nexport const playerRegistryRef = /* @__PURE__ */ globalRef<PlayerRegistry>(\n () => new PlayerRegistryImpl()\n)\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { initializeLogging } from '@amazon/vinyl-util'\nimport { vinylGlobalRef } from './globalRef'\n\nexport function initializeVinylGlobal() {\n initializeLogging()\n vinylGlobalRef.initialize()\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n type AnyRecord,\n getNetworkMetrics,\n getUserAgentInfo,\n globalRef,\n historyLogHandler,\n toDisposable,\n} from '@amazon/vinyl-util'\nimport { playerRegistryRef } from './PlayerRegistry'\nimport { vinylVersion } from './environment'\n\ndeclare global {\n /**\n * A reference to Vinyl's global state, easily accessible via console.\n */\n var vinylGlobal: any\n}\n\n/**\n * For console debugging, gives access to currently active players, logs, and client information.\n */\nexport class VinylGlobal {\n get players() {\n return playerRegistryRef.value.players\n }\n\n /**\n * Returns the first player.\n */\n get player() {\n return playerRegistryRef.value.players[0]\n }\n\n get logs() {\n return historyLogHandler.value?.history\n }\n\n get version() {\n return vinylVersion.str\n }\n\n get userAgentInfo() {\n return getUserAgentInfo()\n }\n\n get network() {\n return getNetworkMetrics()\n }\n\n /**\n * Returns the EWMA low estimate for the client's current bandwidth.\n */\n get bandwidth() {\n return this.network.estimatedDownlinkBandwidth.ewmaLow\n }\n}\n\n/**\n * Set the global vinylGlobal reference for easier console debugging.\n * Intentionally typed as AnyRecord to prevent API usage from code. This is\n * intended only for console debugging and the API may change at any time.\n */\nexport const vinylGlobalRef = /* @__PURE__ */ globalRef((): AnyRecord => {\n global.vinylGlobal = new VinylGlobal()\n return toDisposable(() => {\n delete global.vinylGlobal\n })\n})\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { parseVersion } from '@amazon/vinyl-util'\n\ndeclare global {\n var __VINYL_VERSION__: string | undefined\n}\n\n/**\n * `globalThis.__VINYL_VERSION__` is replaced at build time with the package.version via\n * esbuild's `define` option. In unit tests and unbundled dev builds the replacement does not\n * happen and the global is undefined, so we fall through to a placeholder version.\n */\nexport const vinylVersion = /* @__PURE__ */ parseVersion(\n /* istanbul ignore next */\n globalThis.__VINYL_VERSION__ ?? '0.0.0.0'\n)\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ChangeEvent } from '../event/ChangeEvent'\nimport type { ContentType, MediaQualityMetadata } from './MediaQualityMetadata'\nimport type { BasicErrorEvent } from '../event/BasicErrorEvent'\nimport type { AnyRecord } from '@amazon/vinyl-util'\n\n/**\n * Events a track dispatches related to streaming quality and status.\n */\nexport interface StreamingEventMap {\n /**\n * The actively streamed content types have changed.\n */\n readonly contentTypesChange: ChangeEvent<ReadonlySet<ContentType>>\n\n /**\n * fetchedRanges have been updated.\n */\n readonly fetchedRangesChange: AnyRecord\n\n /**\n * Dispatched when the currently streaming quality changes.\n * This is dispatched when a new streaming quality has been requested.\n */\n readonly streamingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * Dispatched when the currently buffering quality changes.\n * This is dispatched before the segment is appended.\n */\n readonly bufferingQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * The currently playing quality has changed.\n */\n readonly playbackQualityChange: ChangeEvent<MediaQualityMetadata | null>\n\n /**\n * The last segment has finished appending.\n */\n readonly bufferingEnded: AnyRecord\n\n /**\n * Dispatched when a streaming error occurs.\n */\n readonly error: BasicErrorEvent\n\n /**\n * Emitted when the error state has been reset.\n */\n readonly reset: AnyRecord\n\n /**\n * The available qualities for the current period have changed.\n */\n readonly qualitiesChange: ChangeEvent<readonly MediaQualityMetadata[]>\n\n /**\n * The available unfiltered qualities for the current period have changed.\n */\n readonly qualitiesUnfilteredChange: ChangeEvent<\n readonly MediaQualityMetadata[]\n >\n}\n\n/**\n * All streaming-related events a track may emit.\n * These will be bubbled by the player.\n */\nexport const ALL_STREAMING_EVENTS = [\n 'contentTypesChange',\n 'fetchedRangesChange',\n 'streamingQualityChange',\n 'bufferingQualityChange',\n 'playbackQualityChange',\n 'bufferingEnded',\n 'error',\n 'reset',\n 'qualitiesChange',\n 'qualitiesUnfilteredChange',\n] as const satisfies readonly (keyof StreamingEventMap)[]\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ReadonlyPlaybackController } from '../../playback/ReadonlyPlaybackController'\nimport {\n SegmentControllerImpl,\n type SegmentControllerImplOptions,\n} from '../../streaming/SegmentControllerImpl'\nimport type { ContentType } from '../../streaming/MediaQualityMetadata'\nimport type { SegmentController } from '../../streaming/SegmentController'\nimport type { ObservableValue } from '@amazon/vinyl-observable'\nimport type { MediaTimeline } from '../../streaming/MediaTimeline'\nimport type { QualitySelector } from '../../streaming/abr/QualitySelector'\n\nexport type SegmentControllerFactory = (deps: {\n readonly mediaTimelineTransformed: ObservableValue<Promise<MediaTimeline>>\n readonly qualitySelector: QualitySelector\n}) => SegmentController\n\nexport interface SegmentControllerFactoryDeps {\n readonly playbackController: ReadonlyPlaybackController\n}\n\nexport function createSegmentControllerFactory(\n playerDeps: SegmentControllerFactoryDeps,\n contentType: ContentType,\n options?: Partial<SegmentControllerImplOptions>\n) {\n return (trackDeps: {\n readonly mediaTimelineTransformed: ObservableValue<\n Promise<MediaTimeline>\n >\n readonly qualitySelector: QualitySelector\n }) => {\n return new SegmentControllerImpl(\n {\n ...playerDeps,\n ...trackDeps,\n },\n contentType,\n options\n )\n }\n}\n", "/*\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n consoleLogHandler,\n historyLogHandler,\n LogLevel,\n type PartialDeep,\n setLogLevel,\n} from '@amazon/vinyl-util'\nimport type { ValueSchema } from '@amazon/vinyl-validation'\nimport {\n isOneOf,\n number,\n object,\n type ObjectSchema,\n} from '@amazon/vinyl-validation'\nimport { PlayerRegistryImpl, playerRegistryRef } from './PlayerRegistry'\n\n/**\n * Configuration for VinylGlobal.\n */\nexport interface VinylGlobalOptions {\n /**\n * The number of concurrent players before a warning is logged.\n * default: 5\n */\n readonly maxPlayersWarning: number\n\n /**\n * Logging configuration\n */\n readonly logging: {\n readonly history: {\n /**\n * Limits the history log level.\n */\n readonly logLevel: LogLevel\n\n /**\n * Sets the logging history size.\n */\n readonly maxHistorySize: number\n }\n\n /**\n * Gates all log handlers to logs of at least this level.\n */\n readonly logLevel: LogLevel\n\n readonly console: {\n /**\n * Gates console logs\n */\n readonly logLevel: LogLevel\n }\n }\n}\n\nconst logLevelValidator: ValueSchema<LogLevel> = /* @__PURE__ */ (() =>\n isOneOf(\n LogLevel.VERBOSE,\n LogLevel.DEBUG,\n LogLevel.INFO,\n LogLevel.WARN,\n LogLevel.ERROR,\n LogLevel.NONE\n ))()\n\n/**\n * A validator for VinylGlobalOptions applications can set for Vinyl.\n */\nconst vinylGlobalOptionsValidator: ObjectSchema<VinylGlobalOptions> = /* @__PURE__ */ object({\n logging: /* @__PURE__ */ object({\n console: /* @__PURE__ */ object({\n logLevel: logLevelValidator,\n }),\n history: /* @__PURE__ */ object({\n logLevel: logLevelValidator,\n maxHistorySize: /* @__PURE__ */ number(),\n }),\n logLevel: logLevelValidator,\n }),\n maxPlayersWarning: /* @__PURE__ */ number(),\n})\n\nconst vinylGlobalOptionsPartialValidator: ObjectSchema<\n PartialDeep<VinylGlobalOptions>\n> = /* @__PURE__ */ vinylGlobalOptionsValidator.partialDeep()\n\n/**\n * Applies configuration to the current vinyl global options.\n *\n * @param options\n */\nexport function configureVinylGlobal(options: PartialDeep<VinylGlobalOptions>) {\n vinylGlobalOptionsPartialValidator.assert(options)\n // Logging configuration\n if (options.logging) {\n const logging = options.logging\n if (logging.logLevel != null) setLogLevel(logging.logLevel)\n if (logging.history) {\n const history = logging.history\n if (historyLogHandler.value) {\n if (history.maxHistorySize != null)\n historyLogHandler.value.maxHistorySize =\n history.maxHistorySize\n if (history.logLevel != null)\n historyLogHandler.value.logLevel = history.logLevel\n }\n }\n if (logging.console?.logLevel != null) {\n if (consoleLogHandler.value) {\n consoleLogHandler.value.logLevel = logging.console.logLevel\n }\n }\n }\n\n if (\n options.maxPlayersWarning != null &&\n playerRegistryRef.value instanceof PlayerRegistryImpl\n ) {\n playerRegistryRef.value.maxPlayersWarning = options.maxPlayersWarning\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AI,QAAQ,kBAAkB;AAC1B,gDAAkB,MAAM,iBACpB,QAAQ;AAChB,YAAI,QAAQ,YAAY;AACpB,gDAAkB,MAAM,WAAW,QAAQ;AAAA,MACnD;AAAA,IACJ;AACA,UAAI,aAAQ,YAAR,mBAAiB,aAAY,MAAM;AACnC,UAAI,sCAAkB,OAAO;AACzB,8CAAkB,MAAM,WAAW,QAAQ,QAAQ;AAAA,MACvD;AAAA,IACJ;AAAA,EACJ;AAEA,MACI,QAAQ,qBAAqB,QAC7B,kBAAkB,iBAAiB,oBACrC;AACE,sBAAkB,MAAM,oBAAoB,QAAQ;AAAA,EACxD;AACJ;",
|
|
6
|
+
"names": ["data", "CanPlayTypeResult", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "PlayedReason", "WaitedReason", "PlaybackReadyState", "PlaybackNetworkState", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_validation", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_validation", "DrmKeySystem", "import_vinyl_validation", "DrmRobustness", "import_vinyl_util", "contentType", "import_vinyl_util", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_validation", "import_vinyl_util", "record", "src", "contentType", "import_vinyl_util", "import_vinyl_validation", "loadOptionsValidator", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_util", "import_vinyl_util", "time", "period", "contentType", "loadOptionsValidator", "import_vinyl_util", "import_vinyl_validation", "loadOptionsValidator", "import_vinyl_util", "element", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "time", "period", "_a", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "_a", "import_vinyl_util", "contentType", "contentType", "fullMimeType", "import_vinyl_util", "contentType", "_a", "_b", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "contentType", "import_vinyl_observable", "import_vinyl_util", "promise", "import_vinyl_util", "contentType", "data", "import_vinyl_util", "contentType", "onMediaSourceOpen", "import_vinyl_util", "import_vinyl_util", "SegmentStatus", "import_vinyl_util", "contentType", "import_vinyl_util", "time", "element", "contentType", "data", "cachedSegment", "import_vinyl_util", "import_vinyl_di", "contentType", "deps", "import_vinyl_util", "import_vinyl_validation", "AbrStrategy", "import_vinyl_di", "import_vinyl_util", "import_vinyl_mpd_parser", "import_vinyl_util", "import_vinyl_di", "contentType", "contentType", "import_vinyl_util", "import_vinyl_util", "import_vinyl_mpd_parser", "data", "import_vinyl_observable", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "locale", "contentType", "array", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "array", "array", "deps", "data", "contentType", "import_vinyl_observable", "import_vinyl_util", "promise", "import_vinyl_di", "import_vinyl_util", "getContentTypes", "import_vinyl_util", "import_vinyl_di", "contentType", "deps", "data", "import_vinyl_util", "import_vinyl_util", "data", "contentType", "_a", "deps", "data", "import_vinyl_util", "import_vinyl_util", "MediaKeySessionErrorType", "import_vinyl_util", "element", "import_vinyl_util", "import_vinyl_util", "element", "import_vinyl_util", "element", "import_vinyl_util", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_util", "element", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "contentType", "import_vinyl_mpd_parser", "import_vinyl_util", "import_vinyl_validation", "import_vinyl_util", "import_vinyl_di", "import_vinyl_validation", "import_vinyl_util", "import_vinyl_di", "import_vinyl_util", "locale", "import_vinyl_util", "import_vinyl_util", "import_vinyl_util", "contentType", "contentType", "import_vinyl_util", "import_vinyl_validation"]
|
|
7
7
|
}
|