shaka-player 4.9.12 → 4.10.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 +4 -0
- package/dist/controls.css +2 -2
- package/dist/controls.css.map +1 -1
- package/dist/deps.js +24 -19
- package/dist/locales.js +45 -34
- package/dist/shaka-player.compiled.d.ts +291 -12
- package/dist/shaka-player.compiled.debug.d.ts +291 -12
- package/dist/shaka-player.compiled.debug.externs.js +443 -6
- package/dist/shaka-player.compiled.debug.js +648 -553
- package/dist/shaka-player.compiled.debug.map +4 -4
- package/dist/shaka-player.compiled.externs.js +443 -6
- package/dist/shaka-player.compiled.js +1320 -1265
- package/dist/shaka-player.compiled.map +4 -4
- package/dist/shaka-player.ui.d.ts +306 -13
- package/dist/shaka-player.ui.debug.d.ts +306 -13
- package/dist/shaka-player.ui.debug.externs.js +477 -18
- package/dist/shaka-player.ui.debug.js +796 -678
- package/dist/shaka-player.ui.debug.map +4 -4
- package/dist/shaka-player.ui.externs.js +477 -18
- package/dist/shaka-player.ui.js +1594 -1527
- package/dist/shaka-player.ui.map +4 -4
- package/externs/shaka/ads.js +21 -1
- package/externs/shaka/manifest.js +20 -1
- package/externs/shaka/manifest_parser.js +18 -1
- package/externs/shaka/player.js +164 -50
- package/lib/ads/ad_manager.js +225 -10
- package/lib/ads/ad_utils.js +323 -0
- package/lib/ads/ads_stats.js +24 -0
- package/lib/ads/client_side_ad_manager.js +42 -34
- package/lib/ads/interstitial_ad.js +292 -0
- package/lib/ads/interstitial_ad_manager.js +772 -0
- package/lib/ads/media_tailor_ad_manager.js +19 -22
- package/lib/ads/server_side_ad_manager.js +12 -15
- package/lib/cast/cast_utils.js +1 -0
- package/lib/cea/cea_utils.js +12 -0
- package/lib/cea/mp4_cea_parser.js +17 -0
- package/lib/dash/dash_parser.js +81 -28
- package/lib/dash/segment_base.js +3 -0
- package/lib/hls/hls_parser.js +429 -121
- package/lib/hls/manifest_text_parser.js +1 -0
- package/lib/media/adaptation_set_criteria.js +31 -1
- package/lib/media/drm_engine.js +16 -2
- package/lib/media/manifest_filterer.js +7 -5
- package/lib/media/preload_manager.js +8 -10
- package/lib/media/presentation_timeline.js +24 -0
- package/lib/media/quality_observer.js +68 -2
- package/lib/media/segment_reference.js +1 -1
- package/lib/media/segment_utils.js +33 -1
- package/lib/media/streaming_engine.js +120 -43
- package/lib/mss/mss_parser.js +13 -2
- package/lib/net/networking_engine.js +1 -0
- package/lib/offline/manifest_converter.js +3 -0
- package/lib/offline/offline_manifest_parser.js +5 -0
- package/lib/offline/storage.js +2 -0
- package/lib/player.js +498 -165
- package/lib/util/fake_event.js +1 -0
- package/lib/util/manifest_parser_utils.js +9 -2
- package/lib/util/mp4_box_parsers.js +32 -0
- package/lib/util/player_configuration.js +21 -9
- package/lib/util/stats.js +43 -0
- package/package.json +1 -1
- package/shaka-player.uncompiled.js +2 -0
- package/ui/ad_counter.js +3 -3
- package/ui/ad_position.js +3 -3
- package/ui/ad_statistics_button.js +237 -0
- package/ui/audio_language_selection.js +8 -4
- package/ui/controls.js +6 -3
- package/ui/element.js +3 -3
- package/ui/enums.js +1 -0
- package/ui/externs/ui.js +3 -0
- package/ui/language_utils.js +48 -3
- package/ui/less/containers.less +32 -0
- package/ui/less/thumbnails.less +13 -0
- package/ui/locales/en.json +2 -0
- package/ui/locales/es-419.json +2 -0
- package/ui/locales/es.json +3 -0
- package/ui/locales/fr.json +1 -0
- package/ui/locales/pl.json +1 -0
- package/ui/locales/pt-BR.json +1 -0
- package/ui/locales/pt-PT.json +1 -0
- package/ui/locales/source.json +8 -0
- package/ui/mute_button.js +4 -4
- package/ui/overflow_menu.js +3 -3
- package/ui/play_button.js +5 -7
- package/ui/presentation_time.js +3 -3
- package/ui/save_video_frame_button.js +196 -0
- package/ui/seek_bar.js +75 -20
- package/ui/skip_ad_button.js +4 -4
- package/ui/statistics_button.js +14 -2
- package/ui/ui.js +15 -0
- package/ui/volume_bar.js +4 -4
package/lib/player.js
CHANGED
|
@@ -174,7 +174,6 @@ goog.requireType('shaka.media.PresentationTimeline');
|
|
|
174
174
|
* @description Fired when the media quality changes at the playhead.
|
|
175
175
|
* That may be caused by an adaptation change or a DASH period transition.
|
|
176
176
|
* Separate events are emitted for audio and video contentTypes.
|
|
177
|
-
* This is supported for only DASH streams at this time.
|
|
178
177
|
* @property {string} type
|
|
179
178
|
* 'mediaqualitychanged'
|
|
180
179
|
* @property {shaka.extern.MediaQualityInfo} mediaQuality
|
|
@@ -184,6 +183,19 @@ goog.requireType('shaka.media.PresentationTimeline');
|
|
|
184
183
|
* @exportDoc
|
|
185
184
|
*/
|
|
186
185
|
|
|
186
|
+
/**
|
|
187
|
+
* @event shaka.Player.AudioTrackChangedEvent
|
|
188
|
+
* @description Fired when the audio track changes at the playhead.
|
|
189
|
+
* That may be caused by a user requesting to chang audio tracks.
|
|
190
|
+
* @property {string} type
|
|
191
|
+
* 'audiotrackchanged'
|
|
192
|
+
* @property {shaka.extern.MediaQualityInfo} mediaQuality
|
|
193
|
+
* Information about media quality at the playhead position.
|
|
194
|
+
* @property {number} position
|
|
195
|
+
* The playhead position.
|
|
196
|
+
* @exportDoc
|
|
197
|
+
*/
|
|
198
|
+
|
|
187
199
|
|
|
188
200
|
/**
|
|
189
201
|
* @event shaka.Player.BufferingEvent
|
|
@@ -331,7 +343,7 @@ goog.requireType('shaka.media.PresentationTimeline');
|
|
|
331
343
|
* The time that describes the end of the range of the metadata to which
|
|
332
344
|
* the cue applies.
|
|
333
345
|
* @property {string} metadataType
|
|
334
|
-
* Type of metadata. Eg: org.id3 or
|
|
346
|
+
* Type of metadata. Eg: 'org.id3' or 'com.apple.quicktime.HLS'
|
|
335
347
|
* @property {shaka.extern.MetadataFrame} payload
|
|
336
348
|
* The metadata itself
|
|
337
349
|
* @exportDoc
|
|
@@ -709,6 +721,15 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
709
721
|
/** @private {?shaka.extern.PlayerConfiguration} */
|
|
710
722
|
this.config_ = this.defaultConfig_();
|
|
711
723
|
|
|
724
|
+
/** @private {?number} */
|
|
725
|
+
this.currentTargetLatency_ = null;
|
|
726
|
+
|
|
727
|
+
/** @private {number} */
|
|
728
|
+
this.rebufferingCount_ = -1;
|
|
729
|
+
|
|
730
|
+
/** @private {?number} */
|
|
731
|
+
this.targetLatencyReached_ = null;
|
|
732
|
+
|
|
712
733
|
/**
|
|
713
734
|
* The TextDisplayerFactory that was last used to make a text displayer.
|
|
714
735
|
* Stored so that we can tell if a new type of text displayer is desired.
|
|
@@ -778,6 +799,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
778
799
|
/** @private {HTMLMediaElement} */
|
|
779
800
|
this.preloadDueAdManagerVideo_ = null;
|
|
780
801
|
|
|
802
|
+
/** @private {boolean} */
|
|
803
|
+
this.preloadDueAdManagerVideoEnded_ = false;
|
|
804
|
+
|
|
781
805
|
/** @private {shaka.util.Timer} */
|
|
782
806
|
this.preloadDueAdManagerTimer_ = new shaka.util.Timer(async () => {
|
|
783
807
|
if (this.preloadDueAdManager_) {
|
|
@@ -785,8 +809,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
785
809
|
await this.attach(
|
|
786
810
|
this.preloadDueAdManagerVideo_, /* initializeMediaSource= */ true);
|
|
787
811
|
await this.load(this.preloadDueAdManager_);
|
|
788
|
-
this.
|
|
812
|
+
if (!this.preloadDueAdManagerVideoEnded_) {
|
|
813
|
+
this.preloadDueAdManagerVideo_.play();
|
|
814
|
+
} else {
|
|
815
|
+
this.preloadDueAdManagerVideo_.pause();
|
|
816
|
+
}
|
|
789
817
|
this.preloadDueAdManager_ = null;
|
|
818
|
+
this.preloadDueAdManagerVideoEnded_ = false;
|
|
790
819
|
}
|
|
791
820
|
});
|
|
792
821
|
|
|
@@ -794,50 +823,43 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
794
823
|
this.adManager_ = shaka.Player.adManagerFactory_();
|
|
795
824
|
this.adManager_.configure(this.config_.ads);
|
|
796
825
|
|
|
797
|
-
// Note: we don't use shaka.ads.
|
|
798
|
-
// optional module in the player.
|
|
826
|
+
// Note: we don't use shaka.ads.Utils.AD_CONTENT_PAUSE_REQUESTED to
|
|
827
|
+
// avoid add a optional module in the player.
|
|
799
828
|
this.adManagerEventManager_.listen(
|
|
800
|
-
this.adManager_, 'ad-
|
|
801
|
-
if (this.config_.ads.supportsMultipleMediaElements) {
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
const event = /** @type {?google.ima.AdEvent} */
|
|
805
|
-
(e['originalEvent']);
|
|
806
|
-
if (!event) {
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
const contentPauseRequested =
|
|
810
|
-
google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED;
|
|
811
|
-
if (event.type != contentPauseRequested) {
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
829
|
+
this.adManager_, 'ad-content-pause-requested', async (e) => {
|
|
814
830
|
this.preloadDueAdManagerTimer_.stop();
|
|
815
831
|
if (!this.preloadDueAdManager_) {
|
|
816
832
|
this.preloadDueAdManagerVideo_ = this.video_;
|
|
817
|
-
this.
|
|
818
|
-
|
|
833
|
+
this.preloadDueAdManagerVideoEnded_ = this.video_.ended;
|
|
834
|
+
const saveLivePosition = /** @type {boolean} */(
|
|
835
|
+
e['saveLivePosition']) || false;
|
|
836
|
+
this.preloadDueAdManager_ = await this.detachAndSavePreload(
|
|
837
|
+
/* keepAdManager= */ true, saveLivePosition);
|
|
819
838
|
}
|
|
820
839
|
});
|
|
821
840
|
|
|
822
|
-
// Note: we don't use shaka.ads.
|
|
823
|
-
// optional module in the player.
|
|
841
|
+
// Note: we don't use shaka.ads.Utils.AD_CONTENT_RESUME_REQUESTED to
|
|
842
|
+
// avoid add a optional module in the player.
|
|
824
843
|
this.adManagerEventManager_.listen(
|
|
825
|
-
this.adManager_, 'ad-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
const event = /** @type {?google.ima.AdEvent} */
|
|
830
|
-
(e['originalEvent']);
|
|
831
|
-
if (!event) {
|
|
832
|
-
return;
|
|
833
|
-
}
|
|
834
|
-
const contentResumeRequested =
|
|
835
|
-
google.ima.AdEvent.Type.CONTENT_RESUME_REQUESTED;
|
|
836
|
-
if (event.type != contentResumeRequested) {
|
|
837
|
-
return;
|
|
844
|
+
this.adManager_, 'ad-content-resume-requested', (e) => {
|
|
845
|
+
const offset = /** @type {number} */(e['offset']) || 0;
|
|
846
|
+
if (this.preloadDueAdManager_) {
|
|
847
|
+
this.preloadDueAdManager_.setOffsetToStartTime(offset);
|
|
838
848
|
}
|
|
839
849
|
this.preloadDueAdManagerTimer_.tickAfter(0.1);
|
|
840
850
|
});
|
|
851
|
+
|
|
852
|
+
// Note: we don't use shaka.ads.Utils.AD_CONTENT_ATTACH_REQUESTED to
|
|
853
|
+
// avoid add a optional module in the player.
|
|
854
|
+
this.adManagerEventManager_.listen(
|
|
855
|
+
this.adManager_, 'ad-content-attach-requested', async (e) => {
|
|
856
|
+
if (!this.video_ && this.preloadDueAdManagerVideo_) {
|
|
857
|
+
goog.asserts.assert(this.preloadDueAdManagerVideo_,
|
|
858
|
+
'Must have video');
|
|
859
|
+
await this.attach(this.preloadDueAdManagerVideo_,
|
|
860
|
+
/* initializeMediaSource= */ true);
|
|
861
|
+
}
|
|
862
|
+
});
|
|
841
863
|
}
|
|
842
864
|
|
|
843
865
|
// If the browser comes back online after being offline, then try to play
|
|
@@ -947,14 +969,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
947
969
|
// A PreloadManager can only be used with the Player instance that created
|
|
948
970
|
// it, so all PreloadManagers this Player has created are now useless.
|
|
949
971
|
// Destroy any remaining managers now, to help prevent memory leaks.
|
|
950
|
-
|
|
951
|
-
for (const preloadManager of this.createdPreloadManagers_) {
|
|
952
|
-
if (!preloadManager.isDestroyed()) {
|
|
953
|
-
preloadManagerDestroys.push(preloadManager.destroy());
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
this.createdPreloadManagers_ = [];
|
|
957
|
-
await Promise.all(preloadManagerDestroys);
|
|
972
|
+
await this.destroyAllPreloads();
|
|
958
973
|
|
|
959
974
|
// Tear-down the event managers to ensure handlers stop firing.
|
|
960
975
|
if (this.globalEventManager_) {
|
|
@@ -1461,6 +1476,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1461
1476
|
this.stats_ = new shaka.util.Stats(); // Replace with a clean object.
|
|
1462
1477
|
this.lastTextFactory_ = null;
|
|
1463
1478
|
|
|
1479
|
+
this.targetLatencyReached_ = null;
|
|
1480
|
+
this.currentTargetLatency_ = null;
|
|
1481
|
+
this.rebufferingCount_ = -1;
|
|
1482
|
+
|
|
1464
1483
|
this.externalSrcEqualsThumbnailsStreams_ = [];
|
|
1465
1484
|
|
|
1466
1485
|
this.completionPercent_ = NaN;
|
|
@@ -1472,7 +1491,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1472
1491
|
}
|
|
1473
1492
|
|
|
1474
1493
|
if (initializeMediaSource && shaka.util.Platform.supportsMediaSource() &&
|
|
1475
|
-
!this.mediaSourceEngine_) {
|
|
1494
|
+
!this.mediaSourceEngine_ && this.video_) {
|
|
1476
1495
|
await this.initializeMediaSourceEngineInner_();
|
|
1477
1496
|
}
|
|
1478
1497
|
}
|
|
@@ -1624,8 +1643,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1624
1643
|
// asset.
|
|
1625
1644
|
const shouldUseSrcEquals = !preloadManager;
|
|
1626
1645
|
|
|
1627
|
-
const startTimeOfLoad =
|
|
1628
|
-
preloadManager.getStartTimeOfLoad() : (Date.now() / 1000);
|
|
1646
|
+
const startTimeOfLoad = Date.now() / 1000;
|
|
1629
1647
|
|
|
1630
1648
|
// Stats are for a single playback/load session. Stats must be initialized
|
|
1631
1649
|
// before we allow calls to |updateStateHistory|.
|
|
@@ -1661,6 +1679,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1661
1679
|
this.manifestFilterer_ = preloadManager.getManifestFilterer();
|
|
1662
1680
|
this.parserFactory_ = preloadManager.getParserFactory();
|
|
1663
1681
|
this.parser_ = preloadManager.receiveParser();
|
|
1682
|
+
if (this.parser_ && this.parser_.setMediaElement && this.video_) {
|
|
1683
|
+
this.parser_.setMediaElement(this.video_);
|
|
1684
|
+
}
|
|
1664
1685
|
this.regionTimeline_ = preloadManager.receiveRegionTimeline();
|
|
1665
1686
|
this.qualityObserver_ = preloadManager.getQualityObserver();
|
|
1666
1687
|
this.manifest_ = preloadManager.getManifest();
|
|
@@ -1789,37 +1810,41 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1789
1810
|
* attached to something else.
|
|
1790
1811
|
*
|
|
1791
1812
|
* @param {boolean=} keepAdManager
|
|
1813
|
+
* @param {boolean=} saveLivePosition
|
|
1792
1814
|
* @return {!Promise.<?shaka.media.PreloadManager>}
|
|
1793
1815
|
* @export
|
|
1794
1816
|
*/
|
|
1795
|
-
async detachAndSavePreload(keepAdManager = false) {
|
|
1796
|
-
const preloadManager = await this.savePreload_();
|
|
1817
|
+
async detachAndSavePreload(keepAdManager = false, saveLivePosition = false) {
|
|
1818
|
+
const preloadManager = await this.savePreload_(saveLivePosition);
|
|
1797
1819
|
await this.detach(keepAdManager);
|
|
1798
1820
|
return preloadManager;
|
|
1799
1821
|
}
|
|
1800
1822
|
|
|
1801
1823
|
/**
|
|
1824
|
+
* @param {boolean=} saveLivePosition
|
|
1802
1825
|
* @return {!Promise.<?shaka.media.PreloadManager>}
|
|
1803
1826
|
* @private
|
|
1804
1827
|
*/
|
|
1805
|
-
async savePreload_() {
|
|
1828
|
+
async savePreload_(saveLivePosition = false) {
|
|
1806
1829
|
let preloadManager = null;
|
|
1807
1830
|
if (this.manifest_ && this.parser_ && this.parserFactory_ &&
|
|
1808
1831
|
this.assetUri_) {
|
|
1809
1832
|
let startTime = this.video_.currentTime;
|
|
1810
|
-
if (this.isLive()) {
|
|
1833
|
+
if (this.isLive() && !saveLivePosition) {
|
|
1811
1834
|
startTime = null;
|
|
1812
1835
|
}
|
|
1813
1836
|
// We have enough information to make a PreloadManager!
|
|
1814
|
-
const startTimeOfLoad = Date.now() / 1000;
|
|
1815
1837
|
preloadManager = await this.makePreloadManager_(
|
|
1816
1838
|
this.assetUri_,
|
|
1817
1839
|
startTime,
|
|
1818
1840
|
this.mimeType_,
|
|
1819
|
-
startTimeOfLoad,
|
|
1820
1841
|
/* allowPrefetch= */ true,
|
|
1821
1842
|
/* disableVideo= */ false,
|
|
1822
1843
|
/* allowMakeAbrManager= */ false);
|
|
1844
|
+
this.createdPreloadManagers_.push(preloadManager);
|
|
1845
|
+
if (this.parser_ && this.parser_.setMediaElement) {
|
|
1846
|
+
this.parser_.setMediaElement(/* mediaElement= */ null);
|
|
1847
|
+
}
|
|
1823
1848
|
preloadManager.attachManifest(
|
|
1824
1849
|
this.manifest_, this.parser_, this.parserFactory_);
|
|
1825
1850
|
preloadManager.attachAbrManager(
|
|
@@ -1877,6 +1902,21 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1877
1902
|
return preloadManager;
|
|
1878
1903
|
}
|
|
1879
1904
|
|
|
1905
|
+
/**
|
|
1906
|
+
* Calls |destroy| on each PreloadManager object this player has created.
|
|
1907
|
+
* @export
|
|
1908
|
+
*/
|
|
1909
|
+
async destroyAllPreloads() {
|
|
1910
|
+
const preloadManagerDestroys = [];
|
|
1911
|
+
for (const preloadManager of this.createdPreloadManagers_) {
|
|
1912
|
+
if (!preloadManager.isDestroyed()) {
|
|
1913
|
+
preloadManagerDestroys.push(preloadManager.destroy());
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
this.createdPreloadManagers_ = [];
|
|
1917
|
+
await Promise.all(preloadManagerDestroys);
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1880
1920
|
/**
|
|
1881
1921
|
* @param {string} assetUri
|
|
1882
1922
|
* @param {?number} startTime
|
|
@@ -1888,7 +1928,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1888
1928
|
async preloadInner_(assetUri, startTime, mimeType, standardLoad = false) {
|
|
1889
1929
|
goog.asserts.assert(this.networkingEngine_, 'Should have a net engine!');
|
|
1890
1930
|
goog.asserts.assert(this.config_, 'Config must not be null!');
|
|
1891
|
-
const startTimeOfLoad = Date.now() / 1000;
|
|
1892
1931
|
if (!mimeType) {
|
|
1893
1932
|
mimeType = await this.guessMimeType_(assetUri);
|
|
1894
1933
|
}
|
|
@@ -1914,23 +1953,34 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
1914
1953
|
disableVideo = true;
|
|
1915
1954
|
}
|
|
1916
1955
|
}
|
|
1917
|
-
|
|
1918
|
-
assetUri, startTime, mimeType || null,
|
|
1956
|
+
let preloadManagerPromise = this.makePreloadManager_(
|
|
1957
|
+
assetUri, startTime, mimeType || null,
|
|
1919
1958
|
/* allowPrefetch= */ !standardLoad, disableVideo, allowMakeAbrManager);
|
|
1959
|
+
if (!standardLoad) {
|
|
1960
|
+
// We only need to track the PreloadManager if it is not part of a
|
|
1961
|
+
// standard load. If it is, the load() method will handle destroying it.
|
|
1962
|
+
// Adding a standard load PreloadManager to the createdPreloadManagers_
|
|
1963
|
+
// array runs the risk that the user will call destroyAllPreloads and
|
|
1964
|
+
// destroy that PreloadManager mid-load.
|
|
1965
|
+
preloadManagerPromise = preloadManagerPromise.then((preloadManager) => {
|
|
1966
|
+
this.createdPreloadManagers_.push(preloadManager);
|
|
1967
|
+
return preloadManager;
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1970
|
+
return preloadManagerPromise;
|
|
1920
1971
|
}
|
|
1921
1972
|
|
|
1922
1973
|
/**
|
|
1923
1974
|
* @param {string} assetUri
|
|
1924
1975
|
* @param {?number} startTime
|
|
1925
1976
|
* @param {?string} mimeType
|
|
1926
|
-
* @param {number} startTimeOfLoad
|
|
1927
1977
|
* @param {boolean=} allowPrefetch
|
|
1928
1978
|
* @param {boolean=} disableVideo
|
|
1929
1979
|
* @param {boolean=} allowMakeAbrManager
|
|
1930
1980
|
* @return {!Promise.<!shaka.media.PreloadManager>}
|
|
1931
1981
|
* @private
|
|
1932
1982
|
*/
|
|
1933
|
-
async makePreloadManager_(assetUri, startTime, mimeType,
|
|
1983
|
+
async makePreloadManager_(assetUri, startTime, mimeType,
|
|
1934
1984
|
allowPrefetch = true, disableVideo = false, allowMakeAbrManager = true) {
|
|
1935
1985
|
goog.asserts.assert(this.networkingEngine_, 'Must have net engine');
|
|
1936
1986
|
/** @type {?shaka.media.PreloadManager} */
|
|
@@ -2033,6 +2083,31 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2033
2083
|
});
|
|
2034
2084
|
},
|
|
2035
2085
|
getBandwidthEstimate: () => this.abrManager_.getBandwidthEstimate(),
|
|
2086
|
+
onMetadata: (type, startTime, endTime, values) => {
|
|
2087
|
+
let metadataType = type;
|
|
2088
|
+
if (type == 'com.apple.hls.interstitial') {
|
|
2089
|
+
metadataType = 'com.apple.quicktime.HLS';
|
|
2090
|
+
/** @type {shaka.extern.Interstitial} */
|
|
2091
|
+
const interstitial = {
|
|
2092
|
+
startTime,
|
|
2093
|
+
endTime,
|
|
2094
|
+
values,
|
|
2095
|
+
};
|
|
2096
|
+
if (this.adManager_) {
|
|
2097
|
+
goog.asserts.assert(this.video_, 'Must have video');
|
|
2098
|
+
this.adManager_.onInterstitialMetadata(
|
|
2099
|
+
this, this.video_, interstitial);
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
for (const payload of values) {
|
|
2103
|
+
preloadManager.addQueuedOperation(false, () => {
|
|
2104
|
+
this.dispatchMetadataEvent_(
|
|
2105
|
+
startTime, endTime, metadataType, payload);
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
},
|
|
2109
|
+
disableStream: (stream) => this.disableStream(
|
|
2110
|
+
stream, this.config_.streaming.maxDisabledTime),
|
|
2036
2111
|
};
|
|
2037
2112
|
const regionTimeline =
|
|
2038
2113
|
new shaka.media.RegionTimeline(() => this.seekRange());
|
|
@@ -2061,6 +2136,15 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2061
2136
|
const position = event['position'];
|
|
2062
2137
|
this.onMediaQualityChange_(mediaQualityInfo, position);
|
|
2063
2138
|
});
|
|
2139
|
+
|
|
2140
|
+
qualityObserver.addEventListener('audiotrackchange', (event) => {
|
|
2141
|
+
/** @type {shaka.extern.MediaQualityInfo} */
|
|
2142
|
+
const mediaQualityInfo = event['quality'];
|
|
2143
|
+
/** @type {number} */
|
|
2144
|
+
const position = event['position'];
|
|
2145
|
+
this.onMediaQualityChange_(mediaQualityInfo, position,
|
|
2146
|
+
/* audioTrackChanged= */ true);
|
|
2147
|
+
});
|
|
2064
2148
|
}
|
|
2065
2149
|
let firstEvent = true;
|
|
2066
2150
|
const drmPlayerInterface = {
|
|
@@ -2125,8 +2209,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2125
2209
|
allowMakeAbrManager,
|
|
2126
2210
|
};
|
|
2127
2211
|
preloadManager = new shaka.media.PreloadManager(
|
|
2128
|
-
assetUri, mimeType,
|
|
2129
|
-
this.createdPreloadManagers_.push(preloadManager);
|
|
2212
|
+
assetUri, mimeType, startTime, playerInterface);
|
|
2130
2213
|
return preloadManager;
|
|
2131
2214
|
}
|
|
2132
2215
|
|
|
@@ -2199,11 +2282,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2199
2282
|
// example, Android has native HLS, but we'd prefer our own MediaSource
|
|
2200
2283
|
// version there.
|
|
2201
2284
|
if (MimeUtils.isHlsType(mimeType)) {
|
|
2202
|
-
// Native HLS can be preferred on any platform via this flag:
|
|
2203
|
-
if (this.config_.streaming.preferNativeHls) {
|
|
2204
|
-
return true;
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
2285
|
// Native FairPlay HLS can be preferred on Apple platfforms.
|
|
2208
2286
|
if (Platform.isApple() &&
|
|
2209
2287
|
(this.config_.drm.servers['com.apple.fps'] ||
|
|
@@ -2211,11 +2289,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2211
2289
|
return this.config_.streaming.useNativeHlsForFairPlay;
|
|
2212
2290
|
}
|
|
2213
2291
|
|
|
2214
|
-
//
|
|
2215
|
-
|
|
2216
|
-
if (Platform.isApple()) {
|
|
2217
|
-
return this.config_.streaming.useNativeHlsOnSafari;
|
|
2218
|
-
}
|
|
2292
|
+
// Native HLS can be preferred on any platform via this flag:
|
|
2293
|
+
return this.config_.streaming.preferNativeHls;
|
|
2219
2294
|
}
|
|
2220
2295
|
|
|
2221
2296
|
// In all other cases, we prefer MediaSource.
|
|
@@ -2377,28 +2452,40 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2377
2452
|
// Unless the user has already picked a variant, anyway, by calling
|
|
2378
2453
|
// selectVariantTrack before this loading stage.
|
|
2379
2454
|
let initialVariant = prefetchedVariant;
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2455
|
+
let toLazyLoad;
|
|
2456
|
+
let activeVariant;
|
|
2457
|
+
do {
|
|
2458
|
+
activeVariant = this.streamingEngine_.getCurrentVariant();
|
|
2459
|
+
if (!activeVariant && !initialVariant) {
|
|
2460
|
+
initialVariant = this.chooseVariant_(/* initialSelection= */ true);
|
|
2461
|
+
goog.asserts.assert(initialVariant, 'Must choose an initial variant!');
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
// Lazy-load the stream, so we will have enough info to make the playhead.
|
|
2465
|
+
const createSegmentIndexPromises = [];
|
|
2466
|
+
toLazyLoad = activeVariant || initialVariant;
|
|
2467
|
+
for (const stream of [toLazyLoad.video, toLazyLoad.audio]) {
|
|
2468
|
+
if (stream && !stream.segmentIndex) {
|
|
2469
|
+
createSegmentIndexPromises.push(stream.createSegmentIndex());
|
|
2470
|
+
}
|
|
2392
2471
|
}
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2472
|
+
if (createSegmentIndexPromises.length > 0) {
|
|
2473
|
+
// eslint-disable-next-line no-await-in-loop
|
|
2474
|
+
await Promise.all(createSegmentIndexPromises);
|
|
2475
|
+
}
|
|
2476
|
+
} while (!toLazyLoad || toLazyLoad.disabledUntilTime != 0);
|
|
2397
2477
|
|
|
2398
2478
|
if (this.parser_ && this.parser_.onInitialVariantChosen) {
|
|
2399
2479
|
this.parser_.onInitialVariantChosen(toLazyLoad);
|
|
2400
2480
|
}
|
|
2401
2481
|
|
|
2482
|
+
if (this.manifest_.isLowLatency && !this.config_.streaming.lowLatencyMode) {
|
|
2483
|
+
shaka.log.alwaysWarn('Low-latency live stream detected, but ' +
|
|
2484
|
+
'low-latency streaming mode is not enabled in Shaka Player. ' +
|
|
2485
|
+
'Set streaming.lowLatencyMode configuration to true, and see ' +
|
|
2486
|
+
'https://bit.ly/3clctcj for details.');
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2402
2489
|
shaka.Player.applyPlayRange_(this.manifest_.presentationTimeline,
|
|
2403
2490
|
this.config_.playRangeStart,
|
|
2404
2491
|
this.config_.playRangeEnd);
|
|
@@ -2507,9 +2594,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2507
2594
|
|
|
2508
2595
|
const isLive = this.isLive();
|
|
2509
2596
|
|
|
2510
|
-
if ((isLive && (this.config_.streaming.liveSync
|
|
2597
|
+
if ((isLive && ((this.config_.streaming.liveSync &&
|
|
2598
|
+
this.config_.streaming.liveSync.enabled) ||
|
|
2511
2599
|
this.manifest_.serviceDescription ||
|
|
2512
|
-
this.config_.streaming.
|
|
2600
|
+
this.config_.streaming.liveSync.panicMode)) ||
|
|
2513
2601
|
this.config_.streaming.vodDynamicPlaybackRate) {
|
|
2514
2602
|
const onTimeUpdate = () => this.onTimeUpdate_();
|
|
2515
2603
|
this.loadEventManager_.listen(mediaElement, 'timeupdate', onTimeUpdate);
|
|
@@ -2894,8 +2982,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2894
2982
|
|
|
2895
2983
|
const isLive = this.isLive();
|
|
2896
2984
|
|
|
2897
|
-
if ((isLive && (this.config_.streaming.liveSync
|
|
2898
|
-
this.config_.streaming.
|
|
2985
|
+
if ((isLive && ((this.config_.streaming.liveSync &&
|
|
2986
|
+
this.config_.streaming.liveSync.enabled) ||
|
|
2987
|
+
this.config_.streaming.liveSync.panicMode)) ||
|
|
2899
2988
|
this.config_.streaming.vodDynamicPlaybackRate) {
|
|
2900
2989
|
const onTimeUpdate = () => this.onTimeUpdate_();
|
|
2901
2990
|
this.loadEventManager_.listen(mediaElement, 'timeupdate', onTimeUpdate);
|
|
@@ -2984,6 +3073,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2984
3073
|
return;
|
|
2985
3074
|
}
|
|
2986
3075
|
|
|
3076
|
+
/** @type {!Array.<shaka.extern.Interstitial>} */
|
|
3077
|
+
const interstitials = [];
|
|
3078
|
+
|
|
2987
3079
|
for (const cue of track.activeCues) {
|
|
2988
3080
|
this.dispatchMetadataEvent_(cue.startTime, cue.endTime,
|
|
2989
3081
|
cue.type, cue.value);
|
|
@@ -2991,6 +3083,42 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
2991
3083
|
if (this.adManager_) {
|
|
2992
3084
|
this.adManager_.onCueMetadataChange(cue.value);
|
|
2993
3085
|
}
|
|
3086
|
+
if (cue.type == 'com.apple.quicktime.HLS' && cue.startTime != null) {
|
|
3087
|
+
let interstitial = interstitials.find((i) => {
|
|
3088
|
+
return i.startTime == cue.startTime && i.endTime == cue.endTime;
|
|
3089
|
+
});
|
|
3090
|
+
if (!interstitial) {
|
|
3091
|
+
interstitial = /** @type {shaka.extern.Interstitial} */ ({
|
|
3092
|
+
startTime: cue.startTime,
|
|
3093
|
+
endTime: cue.endTime,
|
|
3094
|
+
values: [],
|
|
3095
|
+
});
|
|
3096
|
+
interstitials.push(interstitial);
|
|
3097
|
+
}
|
|
3098
|
+
interstitial.values.push(cue.value);
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
for (const interstitial of interstitials) {
|
|
3102
|
+
const isValidInterstitial = interstitial.values.some((value) => {
|
|
3103
|
+
return value.key == 'X-ASSET-URI' || value.key == 'X-ASSET-LIST';
|
|
3104
|
+
});
|
|
3105
|
+
if (!isValidInterstitial) {
|
|
3106
|
+
continue;
|
|
3107
|
+
}
|
|
3108
|
+
if (this.adManager_) {
|
|
3109
|
+
// It seems that CUE is natively omitted, by default we use CUE=ONCE
|
|
3110
|
+
// to avoid repeating them.
|
|
3111
|
+
interstitial.values.push({
|
|
3112
|
+
key: 'CUE',
|
|
3113
|
+
description: '',
|
|
3114
|
+
data: 'ONCE',
|
|
3115
|
+
mimeType: null,
|
|
3116
|
+
pictureType: null,
|
|
3117
|
+
});
|
|
3118
|
+
goog.asserts.assert(this.video_, 'Must have video');
|
|
3119
|
+
this.adManager_.onInterstitialMetadata(
|
|
3120
|
+
this, this.video_, interstitial);
|
|
3121
|
+
}
|
|
2994
3122
|
}
|
|
2995
3123
|
});
|
|
2996
3124
|
|
|
@@ -3214,6 +3342,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
3214
3342
|
const stats = getStats();
|
|
3215
3343
|
if (stats) {
|
|
3216
3344
|
stats.addBytesDownloaded(bytesDownloaded);
|
|
3345
|
+
if (type === shaka.net.NetworkingEngine.RequestType.MANIFEST) {
|
|
3346
|
+
stats.setManifestSize(bytesDownloaded);
|
|
3347
|
+
}
|
|
3217
3348
|
}
|
|
3218
3349
|
}
|
|
3219
3350
|
};
|
|
@@ -3525,6 +3656,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
3525
3656
|
* @export
|
|
3526
3657
|
*/
|
|
3527
3658
|
configure(config, value) {
|
|
3659
|
+
const Platform = shaka.util.Platform;
|
|
3660
|
+
|
|
3528
3661
|
goog.asserts.assert(this.config_, 'Config must not be null!');
|
|
3529
3662
|
goog.asserts.assert(typeof(config) == 'object' || arguments.length == 2,
|
|
3530
3663
|
'String configs should have values!');
|
|
@@ -3562,6 +3695,121 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
3562
3695
|
'streaming.useNativeHlsOnSafari configuration',
|
|
3563
3696
|
'Please Use streaming.useNativeHlsForFairPlay or ' +
|
|
3564
3697
|
'streaming.preferNativeHls instead.');
|
|
3698
|
+
config['streaming']['preferNativeHls'] =
|
|
3699
|
+
config['streaming']['useNativeHlsOnSafari'] && Platform.isApple();
|
|
3700
|
+
delete config['streaming']['useNativeHlsOnSafari'];
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
// Deprecate 'streaming.liveSync' boolean configuration.
|
|
3704
|
+
if (config['streaming'] &&
|
|
3705
|
+
typeof config['streaming']['liveSync'] == 'boolean') {
|
|
3706
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3707
|
+
'streaming.liveSync',
|
|
3708
|
+
'Please Use streaming.liveSync.enabled instead.');
|
|
3709
|
+
const liveSyncValue = config['streaming']['liveSync'];
|
|
3710
|
+
config['streaming']['liveSync'] = {};
|
|
3711
|
+
config['streaming']['liveSync']['enabled'] = liveSyncValue;
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
// map liveSyncMinLatency and liveSyncMaxLatency to liveSync.targetLatency
|
|
3715
|
+
// if liveSync.targetLatency isn't set.
|
|
3716
|
+
if (config['streaming'] && (!config['streaming']['liveSync'] ||
|
|
3717
|
+
!('targetLatency' in config['streaming']['liveSync'])) &&
|
|
3718
|
+
('liveSyncMinLatency' in config['streaming'] ||
|
|
3719
|
+
'liveSyncMaxLatency' in config['streaming'])) {
|
|
3720
|
+
const min = config['streaming']['liveSyncMinLatency'] || 0;
|
|
3721
|
+
const max = config['streaming']['liveSyncMaxLatency'] || 1;
|
|
3722
|
+
const mid = Math.abs(max - min) / 2;
|
|
3723
|
+
config['streaming']['liveSync'] = config['streaming']['liveSync'] || {};
|
|
3724
|
+
config['streaming']['liveSync']['targetLatency'] = min + mid;
|
|
3725
|
+
config['streaming']['liveSync']['targetLatencyTolerance'] = mid;
|
|
3726
|
+
}
|
|
3727
|
+
// Deprecate 'streaming.liveSyncMaxLatency' configuration.
|
|
3728
|
+
if (config['streaming'] && 'liveSyncMaxLatency' in config['streaming']) {
|
|
3729
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3730
|
+
'streaming.liveSyncMaxLatency',
|
|
3731
|
+
'Please Use streaming.liveSync.targetLatency and ' +
|
|
3732
|
+
'streaming.liveSync.targetLatencyTolerance instead. ' +
|
|
3733
|
+
'Or, set the values in your DASH manifest');
|
|
3734
|
+
delete config['streaming']['liveSyncMaxLatency'];
|
|
3735
|
+
}
|
|
3736
|
+
// Deprecate 'streaming.liveSyncMinLatency' configuration.
|
|
3737
|
+
if (config['streaming'] && 'liveSyncMinLatency' in config['streaming']) {
|
|
3738
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3739
|
+
'streaming.liveSyncMinLatency',
|
|
3740
|
+
'Please Use streaming.liveSync.targetLatency and ' +
|
|
3741
|
+
'streaming.liveSync.targetLatencyTolerance instead. ' +
|
|
3742
|
+
'Or, set the values in your DASH manifest');
|
|
3743
|
+
delete config['streaming']['liveSyncMinLatency'];
|
|
3744
|
+
}
|
|
3745
|
+
|
|
3746
|
+
// Deprecate 'streaming.liveSyncTargetLatency' configuration.
|
|
3747
|
+
if (config['streaming'] && 'liveSyncTargetLatency' in config['streaming']) {
|
|
3748
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3749
|
+
'streaming.liveSyncTargetLatency',
|
|
3750
|
+
'Please Use streaming.liveSync.targetLatency instead.');
|
|
3751
|
+
config['streaming']['liveSync'] = config['streaming']['liveSync'] || {};
|
|
3752
|
+
config['streaming']['liveSync']['targetLatency'] =
|
|
3753
|
+
config['streaming']['liveSyncTargetLatency'];
|
|
3754
|
+
delete config['streaming']['liveSyncTargetLatency'];
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
// Deprecate 'streaming.liveSyncTargetLatencyTolerance' configuration.
|
|
3758
|
+
if (config['streaming'] &&
|
|
3759
|
+
'liveSyncTargetLatencyTolerance' in config['streaming']) {
|
|
3760
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3761
|
+
'streaming.liveSyncTargetLatencyTolerance',
|
|
3762
|
+
'Please Use streaming.liveSync.targetLatencyTolerance instead.');
|
|
3763
|
+
config['streaming']['liveSync'] = config['streaming']['liveSync'] || {};
|
|
3764
|
+
config['streaming']['liveSync']['targetLatencyTolerance'] =
|
|
3765
|
+
config['streaming']['liveSyncTargetLatencyTolerance'];
|
|
3766
|
+
delete config['streaming']['liveSyncTargetLatencyTolerance'];
|
|
3767
|
+
}
|
|
3768
|
+
|
|
3769
|
+
// Deprecate 'streaming.liveSyncPlaybackRate' configuration.
|
|
3770
|
+
if (config['streaming'] && 'liveSyncPlaybackRate' in config['streaming']) {
|
|
3771
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3772
|
+
'streaming.liveSyncPlaybackRate',
|
|
3773
|
+
'Please Use streaming.liveSync.maxPlaybackRate instead.');
|
|
3774
|
+
config['streaming']['liveSync'] = config['streaming']['liveSync'] || {};
|
|
3775
|
+
config['streaming']['liveSync']['maxPlaybackRate'] =
|
|
3776
|
+
config['streaming']['liveSyncPlaybackRate'];
|
|
3777
|
+
delete config['streaming']['liveSyncPlaybackRate'];
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
// Deprecate 'streaming.liveSyncMinPlaybackRate' configuration.
|
|
3781
|
+
if (config['streaming'] &&
|
|
3782
|
+
'liveSyncMinPlaybackRate' in config['streaming']) {
|
|
3783
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3784
|
+
'streaming.liveSyncMinPlaybackRate',
|
|
3785
|
+
'Please Use streaming.liveSync.minPlaybackRate instead.');
|
|
3786
|
+
config['streaming']['liveSync'] = config['streaming']['liveSync'] || {};
|
|
3787
|
+
config['streaming']['liveSync']['minPlaybackRate'] =
|
|
3788
|
+
config['streaming']['liveSyncMinPlaybackRate'];
|
|
3789
|
+
delete config['streaming']['liveSyncMinPlaybackRate'];
|
|
3790
|
+
}
|
|
3791
|
+
|
|
3792
|
+
// Deprecate 'streaming.liveSyncPanicMode' configuration.
|
|
3793
|
+
if (config['streaming'] && 'liveSyncPanicMode' in config['streaming']) {
|
|
3794
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3795
|
+
'streaming.liveSyncPanicMode',
|
|
3796
|
+
'Please Use streaming.liveSync.panicMode instead.');
|
|
3797
|
+
config['streaming']['liveSync'] = config['streaming']['liveSync'] || {};
|
|
3798
|
+
config['streaming']['liveSync']['panicMode'] =
|
|
3799
|
+
config['streaming']['liveSyncPanicMode'];
|
|
3800
|
+
delete config['streaming']['liveSyncPanicMode'];
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
// Deprecate 'streaming.liveSyncPanicThreshold' configuration.
|
|
3804
|
+
if (config['streaming'] &&
|
|
3805
|
+
'liveSyncPanicThreshold' in config['streaming']) {
|
|
3806
|
+
shaka.Deprecate.deprecateFeature(5,
|
|
3807
|
+
'streaming.liveSyncPanicThreshold',
|
|
3808
|
+
'Please Use streaming.liveSync.panicThreshold instead.');
|
|
3809
|
+
config['streaming']['liveSync'] = config['streaming']['liveSync'] || {};
|
|
3810
|
+
config['streaming']['liveSync']['panicThreshold'] =
|
|
3811
|
+
config['streaming']['liveSyncPanicThreshold'];
|
|
3812
|
+
delete config['streaming']['liveSyncPanicThreshold'];
|
|
3565
3813
|
}
|
|
3566
3814
|
|
|
3567
3815
|
// Deprecate 'mediaSource.sourceBufferExtraFeatures' configuration.
|
|
@@ -4063,6 +4311,16 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
4063
4311
|
}
|
|
4064
4312
|
}
|
|
4065
4313
|
|
|
4314
|
+
/**
|
|
4315
|
+
* Indicates if the player has fully loaded the stream.
|
|
4316
|
+
*
|
|
4317
|
+
* @return {boolean}
|
|
4318
|
+
* @export
|
|
4319
|
+
*/
|
|
4320
|
+
isFullyLoaded() {
|
|
4321
|
+
return this.fullyLoaded_;
|
|
4322
|
+
}
|
|
4323
|
+
|
|
4066
4324
|
/**
|
|
4067
4325
|
* Get the key system currently used by EME. If EME is not being used, this
|
|
4068
4326
|
* will return an empty string. If the player has not loaded content, this
|
|
@@ -4707,9 +4965,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
4707
4965
|
* @param {string=} role
|
|
4708
4966
|
* @param {number=} channelsCount
|
|
4709
4967
|
* @param {number=} safeMargin
|
|
4968
|
+
* @param {string=} codec
|
|
4710
4969
|
* @export
|
|
4711
4970
|
*/
|
|
4712
|
-
selectAudioLanguage(language, role, channelsCount = 0, safeMargin = 0
|
|
4971
|
+
selectAudioLanguage(language, role, channelsCount = 0, safeMargin = 0,
|
|
4972
|
+
codec = '') {
|
|
4713
4973
|
if (this.manifest_ && this.playhead_) {
|
|
4714
4974
|
this.currentAdaptationSetCriteria_ =
|
|
4715
4975
|
new shaka.media.PreferenceBasedCriteria(
|
|
@@ -4722,7 +4982,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
4722
4982
|
/* audioLabel= */ '',
|
|
4723
4983
|
/* videoLabel= */ '',
|
|
4724
4984
|
this.config_.mediaSource.codecSwitchingStrategy,
|
|
4725
|
-
this.config_.manifest.dash.enableAudioGroups
|
|
4985
|
+
this.config_.manifest.dash.enableAudioGroups,
|
|
4986
|
+
codec);
|
|
4726
4987
|
|
|
4727
4988
|
const diff = (a, b) => {
|
|
4728
4989
|
if (!a.video && !b.video) {
|
|
@@ -4742,6 +5003,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
4742
5003
|
this.currentAdaptationSetCriteria_.create(this.manifest_.variants);
|
|
4743
5004
|
let bestVariant = null;
|
|
4744
5005
|
for (const curVariant of set.values()) {
|
|
5006
|
+
if (!shaka.util.StreamUtils.isPlayable(curVariant)) {
|
|
5007
|
+
continue;
|
|
5008
|
+
}
|
|
4745
5009
|
if (!bestVariant ||
|
|
4746
5010
|
diff(bestVariant, active) > diff(curVariant, active)) {
|
|
4747
5011
|
bestVariant = curVariant;
|
|
@@ -5264,10 +5528,14 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
5264
5528
|
this.stats_.setLiveLatency(latency);
|
|
5265
5529
|
}
|
|
5266
5530
|
|
|
5267
|
-
if (this.manifest_
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
this.
|
|
5531
|
+
if (this.manifest_) {
|
|
5532
|
+
this.stats_.setManifestPeriodCount(this.manifest_.periodCount);
|
|
5533
|
+
this.stats_.setManifestGapCount(this.manifest_.gapCount);
|
|
5534
|
+
if (this.manifest_.presentationTimeline) {
|
|
5535
|
+
const maxSegmentDuration =
|
|
5536
|
+
this.manifest_.presentationTimeline.getMaxSegmentDuration();
|
|
5537
|
+
this.stats_.setMaxSegmentDuration(maxSegmentDuration);
|
|
5538
|
+
}
|
|
5271
5539
|
}
|
|
5272
5540
|
|
|
5273
5541
|
const estimate = this.abrManager_.getBandwidthEstimate();
|
|
@@ -6091,6 +6359,30 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
6091
6359
|
this.cmcdManager_.setBuffering(isBuffering);
|
|
6092
6360
|
}
|
|
6093
6361
|
this.updateStateHistory_();
|
|
6362
|
+
|
|
6363
|
+
const dynamicTargetLatency =
|
|
6364
|
+
this.config_.streaming.liveSync.dynamicTargetLatency.enabled;
|
|
6365
|
+
const maxAttempts =
|
|
6366
|
+
this.config_.streaming.liveSync.dynamicTargetLatency.maxAttempts;
|
|
6367
|
+
|
|
6368
|
+
|
|
6369
|
+
if (dynamicTargetLatency && isBuffering &&
|
|
6370
|
+
this.rebufferingCount_ < maxAttempts) {
|
|
6371
|
+
const maxLatency =
|
|
6372
|
+
this.config_.streaming.liveSync.dynamicTargetLatency.maxLatency;
|
|
6373
|
+
|
|
6374
|
+
const targetLatencyTolerance =
|
|
6375
|
+
this.config_.streaming.liveSync.targetLatencyTolerance;
|
|
6376
|
+
const rebufferIncrement =
|
|
6377
|
+
this.config_.streaming.liveSync.dynamicTargetLatency
|
|
6378
|
+
.rebufferIncrement;
|
|
6379
|
+
if (this.currentTargetLatency_) {
|
|
6380
|
+
this.currentTargetLatency_ = Math.min(
|
|
6381
|
+
this.currentTargetLatency_ +
|
|
6382
|
+
++this.rebufferingCount_ * rebufferIncrement,
|
|
6383
|
+
maxLatency - targetLatencyTolerance);
|
|
6384
|
+
}
|
|
6385
|
+
}
|
|
6094
6386
|
}
|
|
6095
6387
|
|
|
6096
6388
|
// Surface the buffering event so that the app knows if/when we are
|
|
@@ -6217,52 +6509,78 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
6217
6509
|
return;
|
|
6218
6510
|
}
|
|
6219
6511
|
|
|
6220
|
-
let
|
|
6221
|
-
let
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6512
|
+
let targetLatency;
|
|
6513
|
+
let maxLatency;
|
|
6514
|
+
let maxPlaybackRate;
|
|
6515
|
+
let minLatency;
|
|
6516
|
+
let minPlaybackRate;
|
|
6517
|
+
const targetLatencyTolerance =
|
|
6518
|
+
this.config_.streaming.liveSync.targetLatencyTolerance;
|
|
6519
|
+
const dynamicTargetLatency =
|
|
6520
|
+
this.config_.streaming.liveSync.dynamicTargetLatency.enabled;
|
|
6521
|
+
const stabilityThreshold =
|
|
6522
|
+
this.config_.streaming.liveSync.dynamicTargetLatency.stabilityThreshold;
|
|
6523
|
+
|
|
6524
|
+
if (this.config_.streaming.liveSync &&
|
|
6525
|
+
this.config_.streaming.liveSync.enabled) {
|
|
6526
|
+
targetLatency = this.config_.streaming.liveSync.targetLatency;
|
|
6527
|
+
maxLatency = targetLatency + targetLatencyTolerance;
|
|
6528
|
+
minLatency = Math.max(0, targetLatency - targetLatencyTolerance);
|
|
6529
|
+
maxPlaybackRate = this.config_.streaming.liveSync.maxPlaybackRate;
|
|
6530
|
+
minPlaybackRate = this.config_.streaming.liveSync.minPlaybackRate;
|
|
6225
6531
|
} else {
|
|
6226
6532
|
// serviceDescription must override if it is defined in the MPD and
|
|
6227
6533
|
// liveSync configuration is not set.
|
|
6228
6534
|
if (this.manifest_ && this.manifest_.serviceDescription) {
|
|
6229
|
-
|
|
6535
|
+
targetLatency = this.manifest_.serviceDescription.targetLatency;
|
|
6230
6536
|
if (this.manifest_.serviceDescription.targetLatency != null) {
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
this.config_.streaming.liveSyncTargetLatencyTolerance;
|
|
6537
|
+
maxLatency = this.manifest_.serviceDescription.targetLatency +
|
|
6538
|
+
targetLatencyTolerance;
|
|
6234
6539
|
} else if (this.manifest_.serviceDescription.maxLatency != null) {
|
|
6235
|
-
|
|
6540
|
+
maxLatency = this.manifest_.serviceDescription.maxLatency;
|
|
6236
6541
|
}
|
|
6237
|
-
liveSyncPlaybackRate =
|
|
6238
|
-
this.manifest_.serviceDescription.maxPlaybackRate ||
|
|
6239
|
-
this.config_.streaming.liveSyncPlaybackRate;
|
|
6240
|
-
}
|
|
6241
|
-
}
|
|
6242
|
-
|
|
6243
|
-
let liveSyncMinLatency;
|
|
6244
|
-
let liveSyncMinPlaybackRate;
|
|
6245
|
-
if (this.config_.streaming.liveSync) {
|
|
6246
|
-
liveSyncMinLatency = this.config_.streaming.liveSyncMinLatency;
|
|
6247
|
-
liveSyncMinPlaybackRate = this.config_.streaming.liveSyncMinPlaybackRate;
|
|
6248
|
-
} else {
|
|
6249
|
-
// serviceDescription must override if it is defined in the MPD and
|
|
6250
|
-
// liveSync configuration is not set.
|
|
6251
|
-
if (this.manifest_ && this.manifest_.serviceDescription) {
|
|
6252
|
-
liveSyncMinLatency = this.config_.streaming.liveSyncMinLatency;
|
|
6253
6542
|
if (this.manifest_.serviceDescription.targetLatency != null) {
|
|
6254
|
-
|
|
6543
|
+
minLatency = Math.max(0,
|
|
6255
6544
|
this.manifest_.serviceDescription.targetLatency -
|
|
6256
|
-
|
|
6545
|
+
targetLatencyTolerance);
|
|
6257
6546
|
} else if (this.manifest_.serviceDescription.minLatency != null) {
|
|
6258
|
-
|
|
6547
|
+
minLatency = this.manifest_.serviceDescription.minLatency;
|
|
6259
6548
|
}
|
|
6260
|
-
|
|
6549
|
+
maxPlaybackRate =
|
|
6550
|
+
this.manifest_.serviceDescription.maxPlaybackRate ||
|
|
6551
|
+
this.config_.streaming.liveSync.maxPlaybackRate;
|
|
6552
|
+
minPlaybackRate =
|
|
6261
6553
|
this.manifest_.serviceDescription.minPlaybackRate ||
|
|
6262
|
-
this.config_.streaming.
|
|
6554
|
+
this.config_.streaming.liveSync.minPlaybackRate;
|
|
6263
6555
|
}
|
|
6264
6556
|
}
|
|
6265
6557
|
|
|
6558
|
+
if (!this.currentTargetLatency_ && typeof targetLatency === 'number') {
|
|
6559
|
+
this.currentTargetLatency_ = targetLatency;
|
|
6560
|
+
}
|
|
6561
|
+
|
|
6562
|
+
const maxAttempts =
|
|
6563
|
+
this.config_.streaming.liveSync.dynamicTargetLatency.maxAttempts;
|
|
6564
|
+
if (dynamicTargetLatency && this.targetLatencyReached_ &&
|
|
6565
|
+
this.currentTargetLatency_ !== null &&
|
|
6566
|
+
typeof targetLatency === 'number' &&
|
|
6567
|
+
this.rebufferingCount_ < maxAttempts &&
|
|
6568
|
+
(Date.now() - this.targetLatencyReached_) > stabilityThreshold * 1000) {
|
|
6569
|
+
const dynamicMinLatency =
|
|
6570
|
+
this.config_.streaming.liveSync.dynamicTargetLatency.minLatency;
|
|
6571
|
+
const latencyIncrement = (targetLatency - dynamicMinLatency) / 2;
|
|
6572
|
+
this.currentTargetLatency_ = Math.max(
|
|
6573
|
+
this.currentTargetLatency_ - latencyIncrement,
|
|
6574
|
+
// current target latency should be within the tolerance of the min
|
|
6575
|
+
// latency to not overshoot it
|
|
6576
|
+
dynamicMinLatency + targetLatencyTolerance);
|
|
6577
|
+
this.targetLatencyReached_ = Date.now();
|
|
6578
|
+
}
|
|
6579
|
+
if (dynamicTargetLatency && this.currentTargetLatency_ !== null) {
|
|
6580
|
+
maxLatency = this.currentTargetLatency_ + targetLatencyTolerance;
|
|
6581
|
+
minLatency = this.currentTargetLatency_ - targetLatencyTolerance;
|
|
6582
|
+
}
|
|
6583
|
+
|
|
6266
6584
|
const latency = seekRange.end - this.video_.currentTime;
|
|
6267
6585
|
let offset = 0;
|
|
6268
6586
|
// In src= mode, the seek range isn't updated frequently enough, so we need
|
|
@@ -6273,45 +6591,49 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
6273
6591
|
const buffered = this.video_.buffered;
|
|
6274
6592
|
if (buffered.length > 0) {
|
|
6275
6593
|
const bufferedEnd = buffered.end(buffered.length - 1);
|
|
6276
|
-
offset = Math.max(
|
|
6594
|
+
offset = Math.max(maxPlaybackRate, bufferedEnd - seekRange.end);
|
|
6277
6595
|
}
|
|
6278
6596
|
}
|
|
6279
6597
|
|
|
6280
|
-
const panicMode = this.config_.streaming.
|
|
6281
|
-
const panicThreshold =
|
|
6598
|
+
const panicMode = this.config_.streaming.liveSync.panicMode;
|
|
6599
|
+
const panicThreshold =
|
|
6600
|
+
this.config_.streaming.liveSync.panicThreshold * 1000;
|
|
6282
6601
|
const timeSinceLastRebuffer =
|
|
6283
6602
|
Date.now() - this.bufferObserver_.getLastRebufferTime();
|
|
6284
|
-
if (panicMode && !
|
|
6285
|
-
|
|
6603
|
+
if (panicMode && !minPlaybackRate) {
|
|
6604
|
+
minPlaybackRate = this.config_.streaming.liveSync.minPlaybackRate;
|
|
6286
6605
|
}
|
|
6287
6606
|
|
|
6288
|
-
if (panicMode &&
|
|
6607
|
+
if (panicMode && minPlaybackRate &&
|
|
6289
6608
|
timeSinceLastRebuffer <= panicThreshold) {
|
|
6290
|
-
if (playbackRate !=
|
|
6609
|
+
if (playbackRate != minPlaybackRate) {
|
|
6291
6610
|
shaka.log.debug('Time since last rebuffer (' +
|
|
6292
6611
|
timeSinceLastRebuffer + 's) ' +
|
|
6293
|
-
'is less than the
|
|
6294
|
-
's). Updating playbackRate to ' +
|
|
6295
|
-
this.trickPlay(
|
|
6296
|
-
}
|
|
6297
|
-
} else if (
|
|
6298
|
-
|
|
6299
|
-
if (playbackRate !=
|
|
6300
|
-
shaka.log.debug('Latency (' + latency + 's) ' +
|
|
6301
|
-
'
|
|
6302
|
-
'Updating playbackRate to ' +
|
|
6303
|
-
this.trickPlay(
|
|
6304
|
-
}
|
|
6305
|
-
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
'
|
|
6311
|
-
|
|
6312
|
-
|
|
6612
|
+
'is less than the live sync panicThreshold (' + panicThreshold +
|
|
6613
|
+
's). Updating playbackRate to ' + minPlaybackRate);
|
|
6614
|
+
this.trickPlay(minPlaybackRate);
|
|
6615
|
+
}
|
|
6616
|
+
} else if (maxLatency && maxPlaybackRate &&
|
|
6617
|
+
(latency - offset) > maxLatency) {
|
|
6618
|
+
if (playbackRate != maxPlaybackRate) {
|
|
6619
|
+
shaka.log.debug('Latency (' + latency + 's) is greater than ' +
|
|
6620
|
+
'live sync maxLatency (' + maxLatency + 's). ' +
|
|
6621
|
+
'Updating playbackRate to ' + maxPlaybackRate);
|
|
6622
|
+
this.trickPlay(maxPlaybackRate);
|
|
6623
|
+
}
|
|
6624
|
+
this.targetLatencyReached_ = null;
|
|
6625
|
+
} else if (minLatency && minPlaybackRate &&
|
|
6626
|
+
(latency - offset) < minLatency) {
|
|
6627
|
+
if (playbackRate != minPlaybackRate) {
|
|
6628
|
+
shaka.log.debug('Latency (' + latency + 's) is smaller than ' +
|
|
6629
|
+
'live sync minLatency (' + minLatency + 's). ' +
|
|
6630
|
+
'Updating playbackRate to ' + minPlaybackRate);
|
|
6631
|
+
this.trickPlay(minPlaybackRate);
|
|
6632
|
+
}
|
|
6633
|
+
this.targetLatencyReached_ = null;
|
|
6313
6634
|
} else if (playbackRate !== this.playRateController_.getDefaultRate()) {
|
|
6314
6635
|
this.cancelTrickPlay();
|
|
6636
|
+
this.targetLatencyReached_ = Date.now();
|
|
6315
6637
|
}
|
|
6316
6638
|
}
|
|
6317
6639
|
|
|
@@ -6453,6 +6775,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
6453
6775
|
return str;
|
|
6454
6776
|
};
|
|
6455
6777
|
|
|
6778
|
+
let shouldStopTimer = true;
|
|
6456
6779
|
for (const variant of this.manifest_.variants) {
|
|
6457
6780
|
if (variant.disabledUntilTime > 0 && variant.disabledUntilTime <= now) {
|
|
6458
6781
|
variant.disabledUntilTime = 0;
|
|
@@ -6460,15 +6783,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
6460
6783
|
|
|
6461
6784
|
shaka.log.v2('Re-enabled variant with ' + streamsAsString(variant));
|
|
6462
6785
|
}
|
|
6786
|
+
if (variant.disabledUntilTime > 0) {
|
|
6787
|
+
shouldStopTimer = false;
|
|
6788
|
+
}
|
|
6463
6789
|
}
|
|
6464
6790
|
|
|
6465
|
-
const shouldStopTimer = this.manifest_.variants.every((variant) => {
|
|
6466
|
-
goog.asserts.assert(
|
|
6467
|
-
variant.disabledUntilTime >= 0,
|
|
6468
|
-
'|variant.disableTimeUntilTime| must always be >= 0');
|
|
6469
|
-
return variant.disabledUntilTime === 0;
|
|
6470
|
-
});
|
|
6471
|
-
|
|
6472
6791
|
if (shouldStopTimer) {
|
|
6473
6792
|
this.checkVariantsTimer_.stop();
|
|
6474
6793
|
}
|
|
@@ -6901,7 +7220,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
6901
7220
|
const hasAltStream = this.manifest_.variants.some((variant) => {
|
|
6902
7221
|
const altStream = variant[stream.type];
|
|
6903
7222
|
|
|
6904
|
-
if (altStream && altStream.id !== stream.id
|
|
7223
|
+
if (altStream && altStream.id !== stream.id &&
|
|
7224
|
+
!variant.disabledUntilTime) {
|
|
6905
7225
|
if (shaka.util.StreamUtils.isAudio(stream)) {
|
|
6906
7226
|
return stream.language === altStream.language;
|
|
6907
7227
|
}
|
|
@@ -6962,6 +7282,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
6962
7282
|
return;
|
|
6963
7283
|
}
|
|
6964
7284
|
|
|
7285
|
+
if (error.severity === shaka.util.Error.Severity.RECOVERABLE) {
|
|
7286
|
+
this.stats_.addNonFatalError();
|
|
7287
|
+
}
|
|
7288
|
+
|
|
6965
7289
|
let fireError = true;
|
|
6966
7290
|
if (this.fullyLoaded_ && this.manifest_ && this.streamingEngine_ &&
|
|
6967
7291
|
(error.code == shaka.util.Error.Code.VIDEO_ERROR ||
|
|
@@ -7027,10 +7351,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
7027
7351
|
*
|
|
7028
7352
|
* @param {shaka.extern.MediaQualityInfo} mediaQuality
|
|
7029
7353
|
* @param {number} position
|
|
7354
|
+
* @param {boolean} audioTrackChanged This is to specify whether this should
|
|
7355
|
+
* trigger a MediaQualityChangedEvent or an AudioTrackChangedEvent. Defaults
|
|
7356
|
+
* to false to trigger MediaQualityChangedEvent.
|
|
7030
7357
|
*
|
|
7031
7358
|
* @private
|
|
7032
7359
|
*/
|
|
7033
|
-
onMediaQualityChange_(mediaQuality, position) {
|
|
7360
|
+
onMediaQualityChange_(mediaQuality, position, audioTrackChanged = false) {
|
|
7034
7361
|
// Always make a copy to avoid exposing our internal data to the app.
|
|
7035
7362
|
const clone = {
|
|
7036
7363
|
bandwidth: mediaQuality.bandwidth,
|
|
@@ -7043,6 +7370,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
7043
7370
|
channelsCount: mediaQuality.channelsCount,
|
|
7044
7371
|
pixelAspectRatio: mediaQuality.pixelAspectRatio,
|
|
7045
7372
|
width: mediaQuality.width,
|
|
7373
|
+
label: mediaQuality.label,
|
|
7374
|
+
roles: mediaQuality.roles,
|
|
7375
|
+
language: mediaQuality.language,
|
|
7046
7376
|
};
|
|
7047
7377
|
|
|
7048
7378
|
const data = new Map()
|
|
@@ -7050,7 +7380,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
|
|
7050
7380
|
.set('position', position);
|
|
7051
7381
|
|
|
7052
7382
|
this.dispatchEvent(shaka.Player.makeEvent_(
|
|
7053
|
-
|
|
7383
|
+
audioTrackChanged ?
|
|
7384
|
+
shaka.util.FakeEvent.EventName.AudioTrackChanged :
|
|
7385
|
+
shaka.util.FakeEvent.EventName.MediaQualityChanged,
|
|
7386
|
+
data));
|
|
7054
7387
|
}
|
|
7055
7388
|
|
|
7056
7389
|
/**
|
|
@@ -7468,7 +7801,7 @@ shaka.Player.TYPICAL_BUFFERING_THRESHOLD_ = 0.5;
|
|
|
7468
7801
|
* @export
|
|
7469
7802
|
*/
|
|
7470
7803
|
// eslint-disable-next-line no-useless-concat
|
|
7471
|
-
shaka.Player.version = 'v4.
|
|
7804
|
+
shaka.Player.version = 'v4.10.0' + '-uncompiled'; // x-release-please-version
|
|
7472
7805
|
|
|
7473
7806
|
// Initialize the deprecation system using the version string we just set
|
|
7474
7807
|
// on the player.
|