shaka-player 4.2.1 → 4.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/.github/workflows/build-and-test.yaml +42 -22
  2. package/.github/workflows/compute-incremental-coverage.py +14 -3
  3. package/.github/workflows/custom-actions/set-commit-status/action.yaml +1 -5
  4. package/.github/workflows/deflake.yaml +28 -0
  5. package/.github/workflows/demo-version-index.yaml +1 -1
  6. package/.github/workflows/nightly-demo.yaml +1 -1
  7. package/.github/workflows/release-please.yaml +5 -5
  8. package/.github/workflows/report-incremental-coverage.yaml +1 -1
  9. package/.github/workflows/selenium-lab-tests.yaml +21 -10
  10. package/AUTHORS +4 -0
  11. package/CHANGELOG.md +36 -0
  12. package/CONTRIBUTORS +4 -0
  13. package/demo/common/message_ids.js +1 -0
  14. package/demo/config.js +3 -1
  15. package/demo/locales/en.json +1 -0
  16. package/demo/locales/source.json +4 -0
  17. package/dist/demo.compiled.debug.js +7 -6
  18. package/dist/demo.compiled.debug.map +3 -3
  19. package/dist/demo.compiled.js +7 -6
  20. package/dist/demo.compiled.map +3 -3
  21. package/dist/deps.js +4 -4
  22. package/dist/locales.js +32 -32
  23. package/dist/receiver.compiled.debug.js +4 -3
  24. package/dist/receiver.compiled.debug.map +3 -3
  25. package/dist/receiver.compiled.js +4 -3
  26. package/dist/receiver.compiled.map +3 -3
  27. package/dist/shaka-player.compiled.d.ts +3 -2
  28. package/dist/shaka-player.compiled.debug.d.ts +3 -2
  29. package/dist/shaka-player.compiled.debug.externs.js +25 -24
  30. package/dist/shaka-player.compiled.debug.js +268 -259
  31. package/dist/shaka-player.compiled.debug.map +4 -4
  32. package/dist/shaka-player.compiled.externs.js +25 -24
  33. package/dist/shaka-player.compiled.js +749 -746
  34. package/dist/shaka-player.compiled.map +4 -4
  35. package/dist/shaka-player.ui.d.ts +3 -2
  36. package/dist/shaka-player.ui.debug.d.ts +3 -2
  37. package/dist/shaka-player.ui.debug.externs.js +25 -24
  38. package/dist/shaka-player.ui.debug.js +243 -234
  39. package/dist/shaka-player.ui.debug.map +4 -4
  40. package/dist/shaka-player.ui.externs.js +25 -24
  41. package/dist/shaka-player.ui.js +908 -904
  42. package/dist/shaka-player.ui.map +4 -4
  43. package/docs/jsdoc-template/publish.js +33 -0
  44. package/docs/jsdoc-template/tmpl/container.tmpl +4 -1
  45. package/docs/jsdoc.conf.json +1 -0
  46. package/docs/tutorials/welcome.md +2 -2
  47. package/externs/shaka/manifest_parser.js +4 -1
  48. package/externs/shaka/player.js +7 -1
  49. package/lib/ads/client_side_ad_manager.js +12 -2
  50. package/lib/cast/cast_sender.js +39 -14
  51. package/lib/cea/cea608_memory.js +4 -0
  52. package/lib/hls/hls_parser.js +48 -15
  53. package/lib/media/drm_engine.js +59 -7
  54. package/lib/media/media_source_engine.js +43 -15
  55. package/lib/media/playhead.js +1 -1
  56. package/lib/media/segment_index.js +4 -1
  57. package/lib/media/streaming_engine.js +79 -14
  58. package/lib/offline/indexeddb/storage_mechanism.js +24 -0
  59. package/lib/offline/storage.js +1 -0
  60. package/lib/player.js +17 -5
  61. package/lib/polyfill/media_capabilities.js +7 -6
  62. package/lib/text/ttml_text_parser.js +69 -87
  63. package/lib/text/vtt_text_parser.js +1 -1
  64. package/lib/util/error.js +7 -0
  65. package/lib/util/periods.js +9 -9
  66. package/lib/util/platform.js +19 -5
  67. package/lib/util/player_configuration.js +4 -0
  68. package/lib/util/pssh.js +2 -1
  69. package/lib/util/stream_utils.js +2 -1
  70. package/lib/util/xml_utils.js +45 -6
  71. package/package.json +1 -1
  72. package/test/cea/cea608_memory_unit.js +88 -0
  73. package/test/dash/dash_parser_content_protection_unit.js +1 -0
  74. package/test/dash/dash_parser_live_unit.js +1 -0
  75. package/test/dash/dash_parser_manifest_unit.js +1 -0
  76. package/test/dash/dash_parser_segment_base_unit.js +1 -0
  77. package/test/dash/dash_parser_segment_list_unit.js +1 -0
  78. package/test/dash/dash_parser_segment_template_unit.js +1 -0
  79. package/test/hls/hls_live_unit.js +169 -247
  80. package/test/hls/hls_parser_unit.js +60 -2
  81. package/test/media/drm_engine_unit.js +61 -0
  82. package/test/media/media_source_engine_integration.js +36 -0
  83. package/test/media/media_source_engine_unit.js +118 -1
  84. package/test/media/segment_index_unit.js +28 -2
  85. package/test/media/streaming_engine_integration.js +9 -7
  86. package/test/media/streaming_engine_unit.js +29 -0
  87. package/test/offline/offline_integration.js +3 -3
  88. package/test/offline/storage_integration.js +30 -0
  89. package/test/player_integration.js +2 -2
  90. package/test/test/util/dash_parser_util.js +2 -0
  91. package/test/test/util/ttml_utils.js +0 -2
  92. package/test/text/ttml_text_parser_unit.js +46 -0
  93. package/test/text/vtt_text_parser_unit.js +23 -1
  94. package/test/ui/text_displayer_layout_unit.js +17 -2
  95. package/test/util/periods_unit.js +149 -11
  96. package/test/util/xml_utils_unit.js +64 -0
  97. package/ui/controls.js +0 -7
@@ -320,8 +320,14 @@ shaka.media.StreamingEngine = class {
320
320
  * @param {number=} safeMargin
321
321
  * @param {boolean=} force
322
322
  * If true, reload the variant even if it did not change.
323
+ * @param {boolean=} adaptation
324
+ * If true, update the media state to indicate MediaSourceEngine should
325
+ * reset the timestamp offset to ensure the new track segments are correctly
326
+ * placed on the timeline.
323
327
  */
324
- switchVariant(variant, clearBuffer = false, safeMargin = 0, force = false) {
328
+ switchVariant(
329
+ variant, clearBuffer = false, safeMargin = 0, force = false,
330
+ adaptation = false) {
325
331
  this.currentVariant_ = variant;
326
332
 
327
333
  if (!this.startupComplete_) {
@@ -332,12 +338,14 @@ shaka.media.StreamingEngine = class {
332
338
  if (variant.video) {
333
339
  this.switchInternal_(
334
340
  variant.video, /* clearBuffer= */ clearBuffer,
335
- /* safeMargin= */ safeMargin, /* force= */ force);
341
+ /* safeMargin= */ safeMargin, /* force= */ force,
342
+ /* adaptation= */ adaptation);
336
343
  }
337
344
  if (variant.audio) {
338
345
  this.switchInternal_(
339
346
  variant.audio, /* clearBuffer= */ clearBuffer,
340
- /* safeMargin= */ safeMargin, /* force= */ force);
347
+ /* safeMargin= */ safeMargin, /* force= */ force,
348
+ /* adaptation= */ adaptation);
341
349
  }
342
350
  }
343
351
 
@@ -383,9 +391,13 @@ shaka.media.StreamingEngine = class {
383
391
  * @param {number} safeMargin
384
392
  * @param {boolean} force
385
393
  * If true, reload the text stream even if it did not change.
394
+ * @param {boolean=} adaptation
395
+ * If true, update the media state to indicate MediaSourceEngine should
396
+ * reset the timestamp offset to ensure the new track segments are correctly
397
+ * placed on the timeline.
386
398
  * @private
387
399
  */
388
- switchInternal_(stream, clearBuffer, safeMargin, force) {
400
+ switchInternal_(stream, clearBuffer, safeMargin, force, adaptation) {
389
401
  const ContentType = shaka.util.ManifestParserUtils.ContentType;
390
402
  const type = /** @type {!ContentType} */(stream.type);
391
403
  const mediaState = this.mediaStates_.get(type);
@@ -440,6 +452,7 @@ shaka.media.StreamingEngine = class {
440
452
 
441
453
  mediaState.stream = stream;
442
454
  mediaState.segmentIterator = null;
455
+ mediaState.adaptation = !!adaptation;
443
456
 
444
457
  const streamTag = shaka.media.StreamingEngine.logPrefix_(mediaState);
445
458
  shaka.log.debug('switch: switching to Stream ' + streamTag);
@@ -769,12 +782,11 @@ shaka.media.StreamingEngine = class {
769
782
  const mediaSourceEngine = this.playerInterface_.mediaSourceEngine;
770
783
  const forceTransmuxTS = this.config_.forceTransmuxTS;
771
784
 
772
-
773
785
  await mediaSourceEngine.init(streamsByType, forceTransmuxTS,
774
786
  this.manifest_.sequenceMode);
775
787
  this.destroyer_.ensureNotDestroyed();
776
788
 
777
- this.setDuration_();
789
+ this.updateDuration();
778
790
 
779
791
  for (const type of streamsByType.keys()) {
780
792
  const stream = streamsByType.get(type);
@@ -824,9 +836,8 @@ shaka.media.StreamingEngine = class {
824
836
 
825
837
  /**
826
838
  * Sets the MediaSource's duration.
827
- * @private
828
839
  */
829
- setDuration_() {
840
+ updateDuration() {
830
841
  const duration = this.manifest_.presentationTimeline.getDuration();
831
842
  if (duration < Infinity) {
832
843
  this.playerInterface_.mediaSourceEngine.setDuration(duration);
@@ -1001,7 +1012,11 @@ shaka.media.StreamingEngine = class {
1001
1012
  const timeUntilEnd =
1002
1013
  this.manifest_.presentationTimeline.getDuration() - timeNeeded;
1003
1014
  const oneMicrosecond = 1e-6;
1004
- if (timeUntilEnd < oneMicrosecond) {
1015
+
1016
+ const bufferEnd =
1017
+ this.playerInterface_.mediaSourceEngine.bufferEnd(mediaState.type);
1018
+
1019
+ if (timeUntilEnd < oneMicrosecond && !!bufferEnd) {
1005
1020
  // We shouldn't rebuffer if the playhead is close to the end of the
1006
1021
  // presentation.
1007
1022
  shaka.log.debug(logPrefix, 'buffered to end of presentation');
@@ -1031,8 +1046,6 @@ shaka.media.StreamingEngine = class {
1031
1046
  return this.config_.updateIntervalSeconds / 2;
1032
1047
  }
1033
1048
 
1034
- const bufferEnd =
1035
- this.playerInterface_.mediaSourceEngine.bufferEnd(mediaState.type);
1036
1049
  const reference = this.getSegmentReferenceNeeded_(
1037
1050
  mediaState, presentationTime, bufferEnd);
1038
1051
  if (!reference) {
@@ -1238,7 +1251,16 @@ shaka.media.StreamingEngine = class {
1238
1251
  if (this.config_.lowLatencyMode && isReadableStreamSupported && isMP4 &&
1239
1252
  !reference.hlsAes128Key) {
1240
1253
  let remaining = new Uint8Array(0);
1254
+ let processingResult = false;
1255
+ let callbackCalled = false;
1241
1256
  const streamDataCallback = async (data) => {
1257
+ if (processingResult) {
1258
+ // If the fallback result processing was triggered, don't also
1259
+ // append the buffer here. In theory this should never happen,
1260
+ // but it does on some older TVs.
1261
+ return;
1262
+ }
1263
+ callbackCalled = true;
1242
1264
  this.destroyer_.ensureNotDestroyed();
1243
1265
  if (this.fatalError_) {
1244
1266
  return;
@@ -1269,7 +1291,33 @@ shaka.media.StreamingEngine = class {
1269
1291
  }
1270
1292
  };
1271
1293
 
1272
- await this.fetch_(mediaState, reference, streamDataCallback);
1294
+ const result =
1295
+ await this.fetch_(mediaState, reference, streamDataCallback);
1296
+ if (!callbackCalled) {
1297
+ // In some environments, we might be forced to use network plugins
1298
+ // that don't support streamDataCallback. In those cases, as a
1299
+ // fallback, append the buffer here.
1300
+ processingResult = true;
1301
+ this.destroyer_.ensureNotDestroyed();
1302
+ if (this.fatalError_) {
1303
+ return;
1304
+ }
1305
+
1306
+ // If the text stream gets switched between fetch_() and append_(),
1307
+ // the new text parser is initialized, but the new init segment is
1308
+ // not fetched yet. That would cause an error in
1309
+ // TextParser.parseMedia().
1310
+ // See http://b/168253400
1311
+ if (mediaState.waitingToClearBuffer) {
1312
+ shaka.log.info(logPrefix, 'waitingToClearBuffer, skip append');
1313
+ mediaState.performingUpdate = false;
1314
+ this.scheduleUpdate_(mediaState, 0);
1315
+ return;
1316
+ }
1317
+
1318
+ await this.append_(
1319
+ mediaState, presentationTime, stream, reference, result);
1320
+ }
1273
1321
  } else {
1274
1322
  if (this.config_.lowLatencyMode && !isReadableStreamSupported) {
1275
1323
  shaka.log.warning('Low latency streaming mode is enabled, but ' +
@@ -1590,6 +1638,8 @@ shaka.media.StreamingEngine = class {
1590
1638
  shaka.log.v1(logPrefix, 'appending init segment');
1591
1639
  const hasClosedCaptions = mediaState.stream.closedCaptions &&
1592
1640
  mediaState.stream.closedCaptions.size > 0;
1641
+ await this.playerInterface_.beforeAppendSegment(
1642
+ mediaState.type, initSegment);
1593
1643
  await this.playerInterface_.mediaSourceEngine.appendBuffer(
1594
1644
  mediaState.type, initSegment, /* reference= */ null,
1595
1645
  hasClosedCaptions);
@@ -1640,14 +1690,21 @@ shaka.media.StreamingEngine = class {
1640
1690
  shaka.log.v1(logPrefix, 'appending media segment at',
1641
1691
  (reference.syncTime == null ? 'unknown' : reference.syncTime));
1642
1692
 
1693
+ // 'seeked' or 'adaptation' triggered logic applies only to this
1694
+ // appendBuffer() call.
1643
1695
  const seeked = mediaState.seeked;
1644
1696
  mediaState.seeked = false;
1697
+ const adaptation = mediaState.adaptation;
1698
+ mediaState.adaptation = false;
1699
+
1700
+ await this.playerInterface_.beforeAppendSegment(mediaState.type, segment);
1645
1701
  await this.playerInterface_.mediaSourceEngine.appendBuffer(
1646
1702
  mediaState.type,
1647
1703
  segment,
1648
1704
  reference,
1649
1705
  hasClosedCaptions,
1650
- seeked);
1706
+ seeked,
1707
+ adaptation);
1651
1708
  this.destroyer_.ensureNotDestroyed();
1652
1709
  shaka.log.v2(logPrefix, 'appended media segment');
1653
1710
  }
@@ -2024,7 +2081,9 @@ shaka.media.StreamingEngine = class {
2024
2081
  * onEvent: function(!Event),
2025
2082
  * onManifestUpdate: function(),
2026
2083
  * onSegmentAppended: function(),
2027
- * onInitSegmentAppended: function(!number,!shaka.media.InitSegmentReference)
2084
+ * onInitSegmentAppended: function(!number,!shaka.media.InitSegmentReference),
2085
+ * beforeAppendSegment: function(
2086
+ * shaka.util.ManifestParserUtils.ContentType,!BufferSource):Promise
2028
2087
  * }}
2029
2088
  *
2030
2089
  * @property {function():number} getPresentationTime
@@ -2052,6 +2111,9 @@ shaka.media.StreamingEngine = class {
2052
2111
  * @property
2053
2112
  * {function(!number, !shaka.media.InitSegmentReference)} onInitSegmentAppended
2054
2113
  * Called when an init segment is appended to a MediaSource.
2114
+ * @property {!function(shaka.util.ManifestParserUtils.ContentType,
2115
+ * !BufferSource):Promise} beforeAppendSegment
2116
+ * A function called just before appending to the source buffer.
2055
2117
  */
2056
2118
  shaka.media.StreamingEngine.PlayerInterface;
2057
2119
 
@@ -2075,6 +2137,7 @@ shaka.media.StreamingEngine.PlayerInterface;
2075
2137
  * clearBufferSafeMargin: number,
2076
2138
  * clearingBuffer: boolean,
2077
2139
  * seeked: boolean,
2140
+ * adaptation: boolean,
2078
2141
  * recovering: boolean,
2079
2142
  * hasError: boolean,
2080
2143
  * operation: shaka.net.NetworkingEngine.PendingRequest
@@ -2121,6 +2184,8 @@ shaka.media.StreamingEngine.PlayerInterface;
2121
2184
  * True indicates that the buffer is being cleared.
2122
2185
  * @property {boolean} seeked
2123
2186
  * True indicates that the presentation just seeked.
2187
+ * @property {boolean} adaptation
2188
+ * True indicates that the presentation just automatically switched variants.
2124
2189
  * @property {boolean} recovering
2125
2190
  * True indicates that the last segment was not appended because it could not
2126
2191
  * fit in the buffer.
@@ -16,6 +16,7 @@ goog.require('shaka.offline.indexeddb.V5StorageCell');
16
16
  goog.require('shaka.util.Error');
17
17
  goog.require('shaka.util.PublicPromise');
18
18
  goog.require('shaka.util.Platform');
19
+ goog.require('shaka.util.Timer');
19
20
 
20
21
 
21
22
  /**
@@ -55,8 +56,25 @@ shaka.offline.indexeddb.StorageMechanism = class {
55
56
  const version = shaka.offline.indexeddb.StorageMechanism.VERSION;
56
57
 
57
58
  const p = new shaka.util.PublicPromise();
59
+
60
+ // Add a timeout mechanism, for the (rare?) case where no callbacks are
61
+ // called at all, so that this method doesn't hang forever.
62
+ let timedOut = false;
63
+ const timeOutTimer = new shaka.util.Timer(() => {
64
+ timedOut = true;
65
+ p.reject(new shaka.util.Error(
66
+ shaka.util.Error.Severity.CRITICAL,
67
+ shaka.util.Error.Category.STORAGE,
68
+ shaka.util.Error.Code.INDEXED_DB_INIT_TIMED_OUT));
69
+ });
70
+ timeOutTimer.tickAfter(2);
71
+
58
72
  const open = window.indexedDB.open(name, version);
59
73
  open.onsuccess = (event) => {
74
+ if (timedOut) {
75
+ // Too late, we have already given up on opening the storage mechanism.
76
+ return;
77
+ }
60
78
  const db = open.result;
61
79
  this.db_ = db;
62
80
  this.v1_ = shaka.offline.indexeddb.StorageMechanism.createV1_(db);
@@ -68,6 +86,7 @@ shaka.offline.indexeddb.StorageMechanism = class {
68
86
  this.v5_ = shaka.offline.indexeddb.StorageMechanism.createV5_(db);
69
87
  this.sessions_ =
70
88
  shaka.offline.indexeddb.StorageMechanism.createEmeSessionCell_(db);
89
+ timeOutTimer.stop();
71
90
  p.resolve();
72
91
  };
73
92
  open.onupgradeneeded = (event) => {
@@ -75,11 +94,16 @@ shaka.offline.indexeddb.StorageMechanism = class {
75
94
  this.createStores_(open.result);
76
95
  };
77
96
  open.onerror = (event) => {
97
+ if (timedOut) {
98
+ // Too late, we have already given up on opening the storage mechanism.
99
+ return;
100
+ }
78
101
  p.reject(new shaka.util.Error(
79
102
  shaka.util.Error.Severity.CRITICAL,
80
103
  shaka.util.Error.Category.STORAGE,
81
104
  shaka.util.Error.Code.INDEXED_DB_ERROR,
82
105
  open.error));
106
+ timeOutTimer.stop();
83
107
 
84
108
  // Firefox will raise an error on the main thread unless we stop it here.
85
109
  event.preventDefault();
@@ -1169,6 +1169,7 @@ shaka.offline.Storage = class {
1169
1169
  isLowLatencyMode: () => false,
1170
1170
  isAutoLowLatencyMode: () => false,
1171
1171
  enableLowLatencyMode: () => {},
1172
+ updateDuration: () => {},
1172
1173
  };
1173
1174
 
1174
1175
  parser.configure(config.manifest);
package/lib/player.js CHANGED
@@ -1770,6 +1770,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
1770
1770
  enableLowLatencyMode: () => {
1771
1771
  this.configure('streaming.lowLatencyMode', true);
1772
1772
  },
1773
+ updateDuration: () => {
1774
+ if (this.streamingEngine_) {
1775
+ this.streamingEngine_.updateDuration();
1776
+ }
1777
+ },
1773
1778
  };
1774
1779
 
1775
1780
  const startTime = Date.now() / 1000;
@@ -2952,6 +2957,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
2952
2957
  this.qualityObserver_.addMediaQualityChange(mediaQuality, position);
2953
2958
  }
2954
2959
  },
2960
+ beforeAppendSegment: (contentType, segment) => {
2961
+ return this.drmEngine_.parseInbandPssh(contentType, segment);
2962
+ },
2955
2963
  };
2956
2964
 
2957
2965
  return new shaka.media.StreamingEngine(this.manifest_, playerInterface);
@@ -3838,8 +3846,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
3838
3846
  return;
3839
3847
  }
3840
3848
 
3841
- this.switchVariant_(variant, /* fromAdaptation= */ false, clearBuffer,
3842
- safeMargin);
3849
+ this.switchVariant_(
3850
+ variant, /* fromAdaptation= */ false, clearBuffer, safeMargin);
3843
3851
 
3844
3852
  // Workaround for
3845
3853
  // https://github.com/shaka-project/shaka-player/issues/1299
@@ -5376,7 +5384,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
5376
5384
  const currentVariant = this.streamingEngine_.getCurrentVariant();
5377
5385
  if (variant == currentVariant) {
5378
5386
  shaka.log.debug('Variant already selected.');
5379
- // If you want to clear the buffer, we force to reselect the same variant
5387
+ // If you want to clear the buffer, we force to reselect the same variant.
5388
+ // We don't need to reset the timestampOffset since it's the same variant,
5389
+ // so 'adaptation' isn't passed here.
5380
5390
  if (clearBuffer) {
5381
5391
  this.streamingEngine_.switchVariant(variant, clearBuffer, safeMargin,
5382
5392
  /* force= */ true);
@@ -5386,7 +5396,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
5386
5396
 
5387
5397
  // Add entries to the history.
5388
5398
  this.addVariantToSwitchHistory_(variant, fromAdaptation);
5389
- this.streamingEngine_.switchVariant(variant, clearBuffer, safeMargin);
5399
+ this.streamingEngine_.switchVariant(
5400
+ variant, clearBuffer, safeMargin, /* force= */ undefined,
5401
+ /* adaptation= */ fromAdaptation);
5390
5402
  let oldTrack = null;
5391
5403
  if (currentVariant) {
5392
5404
  oldTrack = shaka.util.StreamUtils.variantToTrack(currentVariant);
@@ -6570,7 +6582,7 @@ shaka.Player.TYPICAL_BUFFERING_THRESHOLD_ = 0.5;
6570
6582
  * @define {string} A version number taken from git at compile time.
6571
6583
  * @export
6572
6584
  */
6573
- shaka.Player.version = 'v4.2.1-uncompiled';
6585
+ shaka.Player.version = 'v4.2.3-uncompiled';
6574
6586
 
6575
6587
  // Initialize the deprecation system using the version string we just set
6576
6588
  // on the player.
@@ -24,8 +24,9 @@ shaka.polyfill.MediaCapabilities = class {
24
24
  * @export
25
25
  */
26
26
  static install() {
27
- // Since MediaCapabilities is not fully supported on some Chromecast yet,
28
- // we should always install polyfill for all Chromecast not Android-based.
27
+ // Since MediaCapabilities implementation is buggy on the Chromecast
28
+ // platform (see https://github.com/shaka-project/shaka-player/issues/4569),
29
+ // we should always install polyfills on all Chromecast models.
29
30
  // TODO: re-evaluate MediaCapabilities in the future versions of Chromecast.
30
31
  // Since MediaCapabilities implementation is buggy in Apple browsers, we
31
32
  // should always install polyfill for Apple browsers.
@@ -43,18 +44,18 @@ shaka.polyfill.MediaCapabilities = class {
43
44
  // should always install polyfill for Tizen browsers.
44
45
  // Since MediaCapabilities implementation is buggy in WebOS browsers, we
45
46
  // should always install polyfill for WebOS browsers.
47
+ // Since MediaCapabilities implementation is buggy in EOS browsers, we
48
+ // should always install polyfill for EOS browsers.
46
49
  let canUseNativeMCap = true;
47
50
  if (shaka.util.Platform.isApple() ||
48
51
  shaka.util.Platform.isPS5() ||
49
52
  shaka.util.Platform.isPS4() ||
50
53
  shaka.util.Platform.isWebOS() ||
51
54
  shaka.util.Platform.isTizen() ||
52
- shaka.util.Platform.isChromecast()) {
55
+ shaka.util.Platform.isChromecast() ||
56
+ shaka.util.Platform.isEOS()) {
53
57
  canUseNativeMCap = false;
54
58
  }
55
- if (shaka.util.Platform.isAndroidCastDevice()) {
56
- canUseNativeMCap = true;
57
- }
58
59
  if (canUseNativeMCap && navigator.mediaCapabilities) {
59
60
  shaka.log.info(
60
61
  'MediaCapabilities: Native mediaCapabilities support found.');
@@ -49,8 +49,6 @@ shaka.text.TtmlTextParser = class {
49
49
  const ttsNs = TtmlTextParser.styleNs_;
50
50
  const str = shaka.util.StringUtils.fromUTF8(data);
51
51
  const cues = [];
52
- const parser = new DOMParser();
53
- let xml = null;
54
52
 
55
53
  // dont try to parse empty string as
56
54
  // DOMParser will not throw error but return an errored xml
@@ -58,9 +56,8 @@ shaka.text.TtmlTextParser = class {
58
56
  return cues;
59
57
  }
60
58
 
61
- try {
62
- xml = parser.parseFromString(str, 'text/xml');
63
- } catch (exception) {
59
+ const tt = XmlUtils.parseXmlString(str, 'tt');
60
+ if (!tt) {
64
61
  throw new shaka.util.Error(
65
62
  shaka.util.Error.Severity.CRITICAL,
66
63
  shaka.util.Error.Category.TEXT,
@@ -68,104 +65,89 @@ shaka.text.TtmlTextParser = class {
68
65
  'Failed to parse TTML.');
69
66
  }
70
67
 
71
- if (xml) {
72
- const parserError = xml.getElementsByTagName('parsererror')[0];
73
- if (parserError) {
74
- throw new shaka.util.Error(
75
- shaka.util.Error.Severity.CRITICAL,
76
- shaka.util.Error.Category.TEXT,
77
- shaka.util.Error.Code.INVALID_XML,
78
- parserError.textContent);
79
- }
80
-
81
- const tt = xml.getElementsByTagName('tt')[0];
82
- // TTML should always have tt element.
83
- if (!tt) {
84
- throw new shaka.util.Error(
85
- shaka.util.Error.Severity.CRITICAL,
86
- shaka.util.Error.Category.TEXT,
87
- shaka.util.Error.Code.INVALID_XML,
88
- 'TTML does not contain <tt> tag.');
89
- }
90
-
91
- const body = tt.getElementsByTagName('body')[0];
92
- if (!body) {
93
- return [];
94
- }
68
+ const body = tt.getElementsByTagName('body')[0];
69
+ if (!body) {
70
+ return [];
71
+ }
95
72
 
96
- // Get the framerate, subFrameRate and frameRateMultiplier if applicable.
97
- const frameRate = XmlUtils.getAttributeNSList(tt, ttpNs, 'frameRate');
98
- const subFrameRate = XmlUtils.getAttributeNSList(
99
- tt, ttpNs, 'subFrameRate');
100
- const frameRateMultiplier =
101
- XmlUtils.getAttributeNSList(tt, ttpNs, 'frameRateMultiplier');
102
- const tickRate = XmlUtils.getAttributeNSList(tt, ttpNs, 'tickRate');
73
+ // Get the framerate, subFrameRate and frameRateMultiplier if applicable.
74
+ const frameRate = XmlUtils.getAttributeNSList(tt, ttpNs, 'frameRate');
75
+ const subFrameRate = XmlUtils.getAttributeNSList(
76
+ tt, ttpNs, 'subFrameRate');
77
+ const frameRateMultiplier =
78
+ XmlUtils.getAttributeNSList(tt, ttpNs, 'frameRateMultiplier');
79
+ const tickRate = XmlUtils.getAttributeNSList(tt, ttpNs, 'tickRate');
103
80
 
104
- const cellResolution = XmlUtils.getAttributeNSList(
105
- tt, ttpNs, 'cellResolution');
106
- const spaceStyle = tt.getAttribute('xml:space') || 'default';
107
- const extent = XmlUtils.getAttributeNSList(tt, ttsNs, 'extent');
81
+ const cellResolution = XmlUtils.getAttributeNSList(
82
+ tt, ttpNs, 'cellResolution');
83
+ const spaceStyle = tt.getAttribute('xml:space') || 'default';
84
+ const extent = XmlUtils.getAttributeNSList(tt, ttsNs, 'extent');
108
85
 
109
- if (spaceStyle != 'default' && spaceStyle != 'preserve') {
110
- throw new shaka.util.Error(
111
- shaka.util.Error.Severity.CRITICAL,
112
- shaka.util.Error.Category.TEXT,
113
- shaka.util.Error.Code.INVALID_XML,
114
- 'Invalid xml:space value: ' + spaceStyle);
115
- }
116
- const whitespaceTrim = spaceStyle == 'default';
86
+ if (spaceStyle != 'default' && spaceStyle != 'preserve') {
87
+ throw new shaka.util.Error(
88
+ shaka.util.Error.Severity.CRITICAL,
89
+ shaka.util.Error.Category.TEXT,
90
+ shaka.util.Error.Code.INVALID_XML,
91
+ 'Invalid xml:space value: ' + spaceStyle);
92
+ }
93
+ const whitespaceTrim = spaceStyle == 'default';
117
94
 
118
- const rateInfo = new TtmlTextParser.RateInfo_(
119
- frameRate, subFrameRate, frameRateMultiplier, tickRate);
95
+ const rateInfo = new TtmlTextParser.RateInfo_(
96
+ frameRate, subFrameRate, frameRateMultiplier, tickRate);
120
97
 
121
- const cellResolutionInfo =
122
- TtmlTextParser.getCellResolution_(cellResolution);
98
+ const cellResolutionInfo =
99
+ TtmlTextParser.getCellResolution_(cellResolution);
123
100
 
124
- const metadata = tt.getElementsByTagName('metadata')[0];
125
- const metadataElements = metadata ? XmlUtils.getChildren(metadata) : [];
126
- const styles = Array.from(tt.getElementsByTagName('style'));
127
- const regionElements = Array.from(tt.getElementsByTagName('region'));
101
+ const metadata = tt.getElementsByTagName('metadata')[0];
102
+ const metadataElements = metadata ? XmlUtils.getChildren(metadata) : [];
103
+ const styles = Array.from(tt.getElementsByTagName('style'));
104
+ const regionElements = Array.from(tt.getElementsByTagName('region'));
128
105
 
129
- const cueRegions = [];
130
- for (const region of regionElements) {
131
- const cueRegion =
132
- TtmlTextParser.parseCueRegion_(region, styles, extent);
133
- if (cueRegion) {
134
- cueRegions.push(cueRegion);
135
- }
106
+ const cueRegions = [];
107
+ for (const region of regionElements) {
108
+ const cueRegion =
109
+ TtmlTextParser.parseCueRegion_(region, styles, extent);
110
+ if (cueRegion) {
111
+ cueRegions.push(cueRegion);
136
112
  }
113
+ }
114
+
115
+ // A <body> element should only contain <div> elements, not <p> or <span>
116
+ // elements. We used to allow this, but it is non-compliant, and the
117
+ // loose nature of our previous parser made it difficult to implement TTML
118
+ // nesting more fully.
119
+ if (XmlUtils.findChildren(body, 'p').length) {
120
+ throw new shaka.util.Error(
121
+ shaka.util.Error.Severity.CRITICAL,
122
+ shaka.util.Error.Category.TEXT,
123
+ shaka.util.Error.Code.INVALID_TEXT_CUE,
124
+ '<p> can only be inside <div> in TTML');
125
+ }
137
126
 
138
- // A <body> element should only contain <div> elements, not <p> or <span>
139
- // elements. We used to allow this, but it is non-compliant, and the
140
- // loose nature of our previous parser made it difficult to implement TTML
141
- // nesting more fully.
142
- if (XmlUtils.findChildren(body, 'p').length) {
127
+ for (const div of XmlUtils.findChildren(body, 'div')) {
128
+ // A <div> element should only contain <p>, not <span>.
129
+ if (XmlUtils.findChildren(div, 'span').length) {
143
130
  throw new shaka.util.Error(
144
131
  shaka.util.Error.Severity.CRITICAL,
145
132
  shaka.util.Error.Category.TEXT,
146
133
  shaka.util.Error.Code.INVALID_TEXT_CUE,
147
- '<p> can only be inside <div> in TTML');
148
- }
149
-
150
- for (const div of XmlUtils.findChildren(body, 'div')) {
151
- // A <div> element should only contain <p>, not <span>.
152
- if (XmlUtils.findChildren(div, 'span').length) {
153
- throw new shaka.util.Error(
154
- shaka.util.Error.Severity.CRITICAL,
155
- shaka.util.Error.Category.TEXT,
156
- shaka.util.Error.Code.INVALID_TEXT_CUE,
157
- '<span> can only be inside <p> in TTML');
158
- }
134
+ '<span> can only be inside <p> in TTML');
159
135
  }
136
+ }
160
137
 
161
- const cue = TtmlTextParser.parseCue_(
162
- body, time.periodStart, rateInfo, metadataElements, styles,
163
- regionElements, cueRegions, whitespaceTrim,
164
- cellResolutionInfo, /* parentCueElement= */ null,
165
- /* isContent= */ false);
166
- if (cue) {
167
- cues.push(cue);
138
+ const cue = TtmlTextParser.parseCue_(
139
+ body, time.periodStart, rateInfo, metadataElements, styles,
140
+ regionElements, cueRegions, whitespaceTrim,
141
+ cellResolutionInfo, /* parentCueElement= */ null,
142
+ /* isContent= */ false);
143
+ if (cue) {
144
+ // According to the TTML spec, backgrounds default to transparent.
145
+ // So default the background of the top-level element to transparent.
146
+ // Nested elements may override that background color already.
147
+ if (!cue.backgroundColor) {
148
+ cue.backgroundColor = 'transparent';
168
149
  }
150
+ cues.push(cue);
169
151
  }
170
152
 
171
153
  return cues;
@@ -105,7 +105,7 @@ shaka.text.VttTextParser = class {
105
105
 
106
106
  const rolloverSeconds =
107
107
  shaka.text.VttTextParser.TS_ROLLOVER_ / mpegTimescale;
108
- let segmentStart = time.segmentStart;
108
+ let segmentStart = time.segmentStart - time.periodStart;
109
109
  while (segmentStart >= rolloverSeconds) {
110
110
  segmentStart -= rolloverSeconds;
111
111
  mpegTime += shaka.text.VttTextParser.TS_ROLLOVER_;
package/lib/util/error.js CHANGED
@@ -1013,6 +1013,13 @@ shaka.util.Error.Code = {
1013
1013
  */
1014
1014
  'MODIFY_OPERATION_NOT_SUPPORTED': 9016,
1015
1015
 
1016
+ /**
1017
+ * When attempting to open an indexedDB instance, nothing happened for long
1018
+ * enough for us to time out. This keeps the storage mechanism from hanging
1019
+ * indefinitely, if neither the success nor error callbacks are called.
1020
+ */
1021
+ 'INDEXED_DB_INIT_TIMED_OUT': 9017,
1022
+
1016
1023
  /**
1017
1024
  * CS IMA SDK, required for ad insertion, has not been included on the page.
1018
1025
  */
@@ -1180,15 +1180,6 @@ shaka.util.PeriodCombiner = class {
1180
1180
  return false;
1181
1181
  }
1182
1182
 
1183
- // If the language doesn't match, but the candidate is the "primary"
1184
- // language, then that should be preferred as a fallback.
1185
- if (!best.primary && candidate.primary) {
1186
- return true;
1187
- }
1188
- if (best.primary && !candidate.primary) {
1189
- return false;
1190
- }
1191
-
1192
1183
  // If language-based differences haven't decided this, look at roles. If
1193
1184
  // the candidate has more roles in common with the output, upgrade to the
1194
1185
  // candidate.
@@ -1222,6 +1213,15 @@ shaka.util.PeriodCombiner = class {
1222
1213
  return false;
1223
1214
  }
1224
1215
 
1216
+ // If the language doesn't match, but the candidate is the "primary"
1217
+ // language, then that should be preferred as a fallback.
1218
+ if (!best.primary && candidate.primary) {
1219
+ return true;
1220
+ }
1221
+ if (best.primary && !candidate.primary) {
1222
+ return false;
1223
+ }
1224
+
1225
1225
  // If language-based and role-based features are equivalent, take the audio
1226
1226
  // with the closes channel count to the output.
1227
1227
  const channelsBetterOrWorse =
@@ -164,13 +164,27 @@ shaka.util.Platform = class {
164
164
  }
165
165
 
166
166
  /**
167
- * Check if the current platform is a Android-based Cast devices.
167
+ * Returns a major version number for Chrome, or Chromium-based browsers.
168
168
  *
169
- * @return {boolean}
169
+ * For example:
170
+ * - Chrome 106.0.5249.61 returns 106.
171
+ * - Edge 106.0.1370.34 returns 106 (since this is based on Chromium).
172
+ * - Safari returns null (since this is independent of Chromium).
173
+ *
174
+ * @return {?number} A major version number or null if not Chromium-based.
170
175
  */
171
- static isAndroidCastDevice() {
172
- return shaka.util.Platform.isChromecast() &&
173
- shaka.util.Platform.userAgentContains_('Android');
176
+ static chromeVersion() {
177
+ if (!shaka.util.Platform.userAgentContains_('Chrome')) {
178
+ return null;
179
+ }
180
+
181
+ // Looking for something like "Chrome/106.0.0.0".
182
+ const match = navigator.userAgent.match(/Chrome\/(\d+)/);
183
+ if (match) {
184
+ return parseInt(match[1], /* base= */ 10);
185
+ }
186
+
187
+ return null;
174
188
  }
175
189
 
176
190
  /**