From 1693c88d9a400a6b4a69f2d290223d9e4b3c0a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Velad=20Galva=CC=81n?= Date: Tue, 5 Sep 2023 15:08:07 +0200 Subject: [PATCH] feat: Add manifestupdated event --- externs/shaka/manifest_parser.js | 5 ++++- lib/dash/dash_parser.js | 2 ++ lib/hls/hls_parser.js | 7 +++++++ lib/offline/storage.js | 1 + lib/player.js | 17 +++++++++++++++++ lib/util/fake_event.js | 1 + .../dash/dash_parser_content_protection_unit.js | 1 + test/dash/dash_parser_live_unit.js | 1 + test/dash/dash_parser_manifest_unit.js | 1 + test/dash/dash_parser_segment_base_unit.js | 1 + test/dash/dash_parser_segment_list_unit.js | 1 + test/dash/dash_parser_segment_template_unit.js | 1 + test/hls/hls_live_unit.js | 1 + test/hls/hls_parser_unit.js | 1 + test/mss/mss_parser_unit.js | 1 + test/test/util/dash_parser_util.js | 2 ++ test/test/util/mss_parser_util.js | 2 ++ 17 files changed, 45 insertions(+), 1 deletion(-) diff --git a/externs/shaka/manifest_parser.js b/externs/shaka/manifest_parser.js index c3f8b6e592..6e36c410da 100644 --- a/externs/shaka/manifest_parser.js +++ b/externs/shaka/manifest_parser.js @@ -109,7 +109,8 @@ shaka.extern.ManifestParser = class { * isAutoLowLatencyMode: function():boolean, * enableLowLatencyMode: function(), * updateDuration: function(), - * newDrmInfo: function(shaka.extern.Stream) + * newDrmInfo: function(shaka.extern.Stream), + * onManifestUpdated: function() * }} * * @description @@ -144,6 +145,8 @@ shaka.extern.ManifestParser = class { * @property {function(shaka.extern.Stream)} newDrmInfo * Inform the player of new DRM info that needs to be processed for the given * stream. + * @property {function()} onManifestUpdated + * Should be called when the manifest is updated. * @exportDoc */ shaka.extern.ManifestParser.PlayerInterface; diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index e35c06db8c..c0e809d721 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -1453,6 +1453,8 @@ shaka.dash.DashParser = class { return; } + this.playerInterface_.onManifestUpdated(); + this.setUpdateTimer_(updateDelay); } diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 62143b0310..919d801d04 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -3678,6 +3678,13 @@ shaka.hls.HlsParser = class { // Try again very soon. this.updatePlaylistTimer_.tickAfter(/* seconds= */ 0.1); } + + // Detect a call to stop() + if (!this.playerInterface_) { + return; + } + + this.playerInterface_.onManifestUpdated(); } diff --git a/lib/offline/storage.js b/lib/offline/storage.js index d1c02e5799..bdace4c6f4 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -1168,6 +1168,7 @@ shaka.offline.Storage = class { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; parser.configure(config.manifest); diff --git a/lib/player.js b/lib/player.js index 8078794dd1..681136cde3 100644 --- a/lib/player.js +++ b/lib/player.js @@ -314,6 +314,18 @@ goog.requireType('shaka.routing.Payload'); */ +/** + * @event shaka.Player.ManifestUpdatedEvent + * @description Fired after the manifest has been updated (live streams). + * @property {string} type + * 'manifestupdated' + * @property {boolean} isLive + * True when the playlist is live. Useful to detect transition from live + * to static playlist.. + * @exportDoc + */ + + /** * @event shaka.Player.MetadataEvent * @description Triggers after metadata associated with the stream is found. @@ -1904,6 +1916,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget { this.processDrmInfos_(currentDrmInfo.keySystem, stream); } }, + onManifestUpdated: () => { + const eventName = shaka.util.FakeEvent.EventName.ManifestUpdated; + const data = (new Map()).set('isLive', this.isLive()); + this.dispatchEvent(this.makeEvent_(eventName, data)); + }, }; const startTime = Date.now() / 1000; diff --git a/lib/util/fake_event.js b/lib/util/fake_event.js index 01ad79a89c..11249f6522 100644 --- a/lib/util/fake_event.js +++ b/lib/util/fake_event.js @@ -167,6 +167,7 @@ shaka.util.FakeEvent.EventName = { Loaded: 'loaded', Loading: 'loading', ManifestParsed: 'manifestparsed', + ManifestUpdated: 'manifestupdated', MediaQualityChanged: 'mediaqualitychanged', Metadata: 'metadata', OnStateChange: 'onstatechange', diff --git a/test/dash/dash_parser_content_protection_unit.js b/test/dash/dash_parser_content_protection_unit.js index ac33966584..955c106036 100644 --- a/test/dash/dash_parser_content_protection_unit.js +++ b/test/dash/dash_parser_content_protection_unit.js @@ -45,6 +45,7 @@ describe('DashParser ContentProtection', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; const actual = await dashParser.start( diff --git a/test/dash/dash_parser_live_unit.js b/test/dash/dash_parser_live_unit.js index 6420aad36a..947548e333 100644 --- a/test/dash/dash_parser_live_unit.js +++ b/test/dash/dash_parser_live_unit.js @@ -36,6 +36,7 @@ describe('DashParser Live', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; }); diff --git a/test/dash/dash_parser_manifest_unit.js b/test/dash/dash_parser_manifest_unit.js index 6fd0cfb2e8..147243c300 100644 --- a/test/dash/dash_parser_manifest_unit.js +++ b/test/dash/dash_parser_manifest_unit.js @@ -54,6 +54,7 @@ describe('DashParser Manifest', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; }); diff --git a/test/dash/dash_parser_segment_base_unit.js b/test/dash/dash_parser_segment_base_unit.js index 19f2fa67b0..cd99c12fa0 100644 --- a/test/dash/dash_parser_segment_base_unit.js +++ b/test/dash/dash_parser_segment_base_unit.js @@ -40,6 +40,7 @@ describe('DashParser SegmentBase', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; }); diff --git a/test/dash/dash_parser_segment_list_unit.js b/test/dash/dash_parser_segment_list_unit.js index 0dce34c149..7b08719a94 100644 --- a/test/dash/dash_parser_segment_list_unit.js +++ b/test/dash/dash_parser_segment_list_unit.js @@ -350,6 +350,7 @@ describe('DashParser SegmentList', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; const manifest = await dashParser.start('dummy://foo', playerInterface); const stream = manifest.variants[0].video; diff --git a/test/dash/dash_parser_segment_template_unit.js b/test/dash/dash_parser_segment_template_unit.js index 2d85126bc0..053fa9ebf1 100644 --- a/test/dash/dash_parser_segment_template_unit.js +++ b/test/dash/dash_parser_segment_template_unit.js @@ -49,6 +49,7 @@ describe('DashParser SegmentTemplate', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; }); diff --git a/test/hls/hls_live_unit.js b/test/hls/hls_live_unit.js index bd4b94285f..3789eee9e5 100644 --- a/test/hls/hls_live_unit.js +++ b/test/hls/hls_live_unit.js @@ -77,6 +77,7 @@ describe('HlsParser live', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; parser = new shaka.hls.HlsParser(); diff --git a/test/hls/hls_parser_unit.js b/test/hls/hls_parser_unit.js index e64c3d70f4..74b01d06ae 100644 --- a/test/hls/hls_parser_unit.js +++ b/test/hls/hls_parser_unit.js @@ -90,6 +90,7 @@ describe('HlsParser', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: shaka.test.Util.spyFunc(newDrmInfoSpy), + onManifestUpdated: () => {}, }; parser = new shaka.hls.HlsParser(); diff --git a/test/mss/mss_parser_unit.js b/test/mss/mss_parser_unit.js index 2ce8666b74..27c259de1a 100644 --- a/test/mss/mss_parser_unit.js +++ b/test/mss/mss_parser_unit.js @@ -79,6 +79,7 @@ describe('MssParser Manifest', () => { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; }); diff --git a/test/test/util/dash_parser_util.js b/test/test/util/dash_parser_util.js index cf9647d378..dabf2c5f9e 100644 --- a/test/test/util/dash_parser_util.js +++ b/test/test/util/dash_parser_util.js @@ -45,6 +45,7 @@ shaka.test.Dash = class { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; const manifest = await dashParser.start('dummy://foo', playerInterface); const stream = manifest.variants[0].video; @@ -81,6 +82,7 @@ shaka.test.Dash = class { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; const p = dashParser.start('dummy://foo', playerInterface); await expectAsync(p).toBeRejectedWith( diff --git a/test/test/util/mss_parser_util.js b/test/test/util/mss_parser_util.js index ca5fd14e38..63b61e22fb 100644 --- a/test/test/util/mss_parser_util.js +++ b/test/test/util/mss_parser_util.js @@ -45,6 +45,7 @@ shaka.test.Mss = class { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; const manifest = await mssParser.start('dummy://foo', playerInterface); const stream = manifest.variants[0].audio; @@ -81,6 +82,7 @@ shaka.test.Mss = class { enableLowLatencyMode: () => {}, updateDuration: () => {}, newDrmInfo: (stream) => {}, + onManifestUpdated: () => {}, }; const p = mssParser.start('dummy://foo', playerInterface); await expectAsync(p).toBeRejectedWith(