shaka-player 4.5.0 → 4.6.1

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 (214) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  2. package/AUTHORS +2 -0
  3. package/CHANGELOG.md +109 -0
  4. package/CODE_OF_CONDUCT.md +1 -1
  5. package/CONTRIBUTORS +2 -0
  6. package/README.md +38 -32
  7. package/demo/common/asset.js +11 -17
  8. package/demo/common/assets.js +117 -11
  9. package/demo/config.js +28 -1
  10. package/demo/custom.js +52 -38
  11. package/demo/main.js +11 -3
  12. package/demo/search.js +7 -0
  13. package/dist/controls.css +1 -1
  14. package/dist/controls.css.map +1 -1
  15. package/dist/demo.compiled.debug.js +133 -124
  16. package/dist/demo.compiled.debug.map +3 -3
  17. package/dist/demo.compiled.js +133 -124
  18. package/dist/demo.compiled.map +3 -3
  19. package/dist/deps.js +20 -18
  20. package/dist/locales.js +34 -30
  21. package/dist/receiver.compiled.debug.js +58 -50
  22. package/dist/receiver.compiled.debug.map +3 -3
  23. package/dist/receiver.compiled.js +58 -50
  24. package/dist/receiver.compiled.map +3 -3
  25. package/dist/shaka-player.compiled.d.ts +440 -390
  26. package/dist/shaka-player.compiled.debug.d.ts +440 -390
  27. package/dist/shaka-player.compiled.debug.externs.js +162 -77
  28. package/dist/shaka-player.compiled.debug.js +789 -738
  29. package/dist/shaka-player.compiled.debug.map +4 -4
  30. package/dist/shaka-player.compiled.externs.js +162 -77
  31. package/dist/shaka-player.compiled.js +1147 -1113
  32. package/dist/shaka-player.compiled.map +4 -4
  33. package/dist/shaka-player.ui.d.ts +491 -437
  34. package/dist/shaka-player.ui.debug.d.ts +491 -437
  35. package/dist/shaka-player.ui.debug.externs.js +167 -77
  36. package/dist/shaka-player.ui.debug.js +857 -791
  37. package/dist/shaka-player.ui.debug.map +4 -4
  38. package/dist/shaka-player.ui.externs.js +167 -77
  39. package/dist/shaka-player.ui.js +1359 -1314
  40. package/dist/shaka-player.ui.map +4 -4
  41. package/docs/tutorials/ad_monetization.md +54 -0
  42. package/docs/tutorials/basic-usage.md +2 -1
  43. package/docs/tutorials/errors.md +2 -1
  44. package/docs/tutorials/offline.md +10 -8
  45. package/docs/tutorials/plugins.md +5 -0
  46. package/docs/tutorials/ui-customization.md +13 -0
  47. package/docs/tutorials/ui.md +2 -1
  48. package/docs/tutorials/upgrade.md +3 -0
  49. package/externs/managedmediasource.js +24 -0
  50. package/externs/shaka/abr_manager.js +6 -2
  51. package/externs/shaka/cea.js +7 -0
  52. package/externs/shaka/codecs.js +5 -3
  53. package/externs/shaka/manifest.js +21 -5
  54. package/externs/shaka/manifest_parser.js +17 -0
  55. package/externs/shaka/net.js +2 -2
  56. package/externs/shaka/offline.js +9 -2
  57. package/externs/shaka/player.js +53 -7
  58. package/externs/shaka/text.js +3 -1
  59. package/externs/shaka/transmuxer.js +1 -1
  60. package/lib/abr/simple_abr_manager.js +25 -8
  61. package/lib/ads/media_tailor_ad_manager.js +14 -3
  62. package/lib/cast/cast_receiver.js +1 -1
  63. package/lib/cea/cea_decoder.js +28 -0
  64. package/lib/cea/dummy_caption_decoder.js +5 -0
  65. package/lib/dash/dash_parser.js +251 -84
  66. package/lib/dash/mpd_utils.js +52 -31
  67. package/lib/dash/segment_base.js +4 -5
  68. package/lib/dash/segment_list.js +5 -4
  69. package/lib/dash/segment_template.js +92 -29
  70. package/lib/hls/hls_classes.js +28 -43
  71. package/lib/hls/hls_parser.js +770 -652
  72. package/lib/hls/hls_utils.js +64 -5
  73. package/lib/hls/manifest_text_parser.js +7 -11
  74. package/lib/media/adaptation_set.js +20 -13
  75. package/lib/media/adaptation_set_criteria.js +70 -18
  76. package/lib/media/closed_caption_parser.js +13 -0
  77. package/lib/media/content_workarounds.js +6 -0
  78. package/lib/media/drm_engine.js +8 -13
  79. package/lib/media/manifest_parser.js +8 -113
  80. package/lib/media/media_source_capabilities.js +10 -3
  81. package/lib/media/media_source_engine.js +75 -21
  82. package/lib/media/play_rate_controller.js +8 -38
  83. package/lib/media/presentation_timeline.js +7 -1
  84. package/lib/media/quality_observer.js +1 -1
  85. package/lib/media/segment_index.js +5 -5
  86. package/lib/media/segment_prefetch.js +92 -24
  87. package/lib/media/segment_reference.js +67 -1
  88. package/lib/media/segment_utils.js +343 -0
  89. package/lib/media/stall_detector.js +0 -3
  90. package/lib/media/streaming_engine.js +72 -44
  91. package/lib/mss/mss_parser.js +18 -2
  92. package/lib/net/networking_engine.js +66 -12
  93. package/lib/net/networking_utils.js +95 -0
  94. package/lib/offline/indexeddb/v1_storage_cell.js +2 -0
  95. package/lib/offline/indexeddb/v2_storage_cell.js +2 -0
  96. package/lib/offline/manifest_converter.js +2 -0
  97. package/lib/offline/offline_manifest_parser.js +10 -0
  98. package/lib/offline/storage.js +11 -7
  99. package/lib/player.js +998 -1503
  100. package/lib/polyfill/mediasource.js +22 -1
  101. package/lib/text/mp4_ttml_parser.js +2 -2
  102. package/lib/text/srt_text_parser.js +2 -2
  103. package/lib/text/stub_text_displayer.js +51 -0
  104. package/lib/text/text_engine.js +3 -2
  105. package/lib/text/ttml_text_parser.js +28 -5
  106. package/lib/text/ui_text_displayer.js +4 -0
  107. package/lib/text/vtt_text_parser.js +7 -2
  108. package/lib/transmuxer/aac_transmuxer.js +1 -1
  109. package/lib/transmuxer/ac3_transmuxer.js +1 -1
  110. package/lib/transmuxer/ec3_transmuxer.js +1 -1
  111. package/lib/transmuxer/h264.js +5 -4
  112. package/lib/transmuxer/h265.js +5 -4
  113. package/lib/transmuxer/mp3_transmuxer.js +1 -1
  114. package/lib/transmuxer/mpeg_ts_transmuxer.js +1 -1
  115. package/lib/transmuxer/mss_transmuxer.js +1 -1
  116. package/lib/transmuxer/ts_transmuxer.js +33 -13
  117. package/lib/util/buffer_utils.js +26 -4
  118. package/lib/util/content_steering_manager.js +358 -0
  119. package/lib/util/error.js +2 -6
  120. package/lib/util/fairplay_utils.js +1 -1
  121. package/lib/util/fake_event.js +5 -1
  122. package/lib/util/id3_utils.js +50 -1
  123. package/lib/util/manifest_parser_utils.js +12 -8
  124. package/lib/util/mp4_generator.js +2 -4
  125. package/lib/util/mutex.js +59 -0
  126. package/lib/util/object_utils.js +1 -1
  127. package/lib/util/periods.js +154 -179
  128. package/lib/util/platform.js +4 -3
  129. package/lib/util/player_configuration.js +35 -6
  130. package/lib/util/stream_utils.js +105 -98
  131. package/lib/util/ts_parser.js +124 -73
  132. package/lib/util/uint8array_utils.js +5 -1
  133. package/lib/util/xml_utils.js +5 -0
  134. package/maintained-branches.md +2 -2
  135. package/package.json +1 -1
  136. package/roadmap.md +15 -5
  137. package/shaka-player.uncompiled.js +0 -1
  138. package/test/abr/simple_abr_manager_unit.js +33 -33
  139. package/test/ads/ad_manager_unit.js +3 -2
  140. package/test/cast/cast_receiver_integration.js +3 -4
  141. package/test/cast/cast_utils_unit.js +2 -0
  142. package/test/cea/cea_decoder_unit.js +7 -0
  143. package/test/codec_switching/codec_switching_integration.js +2 -1
  144. package/test/dash/dash_parser_integration.js +2 -1
  145. package/test/dash/dash_parser_live_unit.js +0 -19
  146. package/test/dash/dash_parser_manifest_unit.js +494 -2
  147. package/test/dash/mpd_utils_unit.js +61 -30
  148. package/test/hls/hls_live_unit.js +12 -3
  149. package/test/hls/hls_parser_unit.js +417 -27
  150. package/test/hls/manifest_text_parser_unit.js +32 -99
  151. package/test/media/adaptation_set_criteria_unit.js +172 -21
  152. package/test/media/adaptation_set_unit.js +1 -0
  153. package/test/media/content_workarounds_unit.js +1 -1
  154. package/test/media/drm_engine_unit.js +3 -3
  155. package/test/media/media_source_engine_unit.js +1 -1
  156. package/test/media/play_rate_controller_unit.js +0 -48
  157. package/test/media/segment_index_unit.js +2 -1
  158. package/test/mss/mss_player_integration.js +3 -2
  159. package/test/net/networking_engine_unit.js +3 -3
  160. package/test/{media/manifest_parser_unit.js → net/networking_utils_unit.js} +2 -2
  161. package/test/offline/manifest_convert_unit.js +9 -0
  162. package/test/offline/offline_integration.js +2 -1
  163. package/test/offline/storage_integration.js +21 -9
  164. package/test/player_external.js +4 -2
  165. package/test/player_integration.js +15 -4
  166. package/test/player_load_graph_integration.js +47 -151
  167. package/test/player_src_equals_external.js +1 -0
  168. package/test/player_src_equals_integration.js +71 -4
  169. package/test/player_unit.js +80 -27
  170. package/test/test/util/fake_media_source_engine.js +5 -0
  171. package/test/test/util/fake_networking_engine.js +9 -1
  172. package/test/test/util/fake_segment_prefetch.js +3 -0
  173. package/test/test/util/manifest_generator.js +4 -0
  174. package/test/test/util/manifest_parser_util.js +14 -2
  175. package/test/test/util/offline_utils.js +1 -0
  176. package/test/test/util/simple_fakes.js +2 -2
  177. package/test/test/util/streaming_engine_util.js +3 -0
  178. package/test/test/util/test_scheme.js +6 -0
  179. package/test/test/util/ui_utils.js +4 -3
  180. package/test/text/mp4_ttml_parser_unit.js +4 -4
  181. package/test/text/srt_text_parser_unit.js +1 -1
  182. package/test/text/text_displayer_layout_unit.js +1 -1
  183. package/test/text/text_engine_unit.js +6 -0
  184. package/test/text/ttml_text_parser_unit.js +33 -2
  185. package/test/transmuxer/transmuxer_engine_integration.js +9 -0
  186. package/test/transmuxer/transmuxer_integration.js +33 -3
  187. package/test/ui/ad_ui_unit.js +2 -2
  188. package/test/ui/ui_customization_unit.js +17 -16
  189. package/test/ui/ui_integration.js +30 -20
  190. package/test/ui/ui_unit.js +25 -19
  191. package/test/util/buffer_utils_unit.js +1 -1
  192. package/test/util/content_steering_manager_unit.js +427 -0
  193. package/test/util/id3_utils_unit.js +52 -0
  194. package/test/util/stream_utils_unit.js +17 -113
  195. package/test/util/ts_parser_unit.js +3 -3
  196. package/third_party/closure-uri/uri.js +13 -1
  197. package/ui/audio_language_selection.js +9 -2
  198. package/ui/externs/ui.js +17 -2
  199. package/ui/language_utils.js +43 -8
  200. package/ui/less/range_elements.less +33 -0
  201. package/ui/locales/en.json +1 -0
  202. package/ui/locales/es-419.json +1 -0
  203. package/ui/locales/es.json +1 -0
  204. package/ui/locales/source.json +4 -0
  205. package/ui/localization.js +10 -0
  206. package/ui/remote_button.js +3 -1
  207. package/ui/resolution_selection.js +47 -10
  208. package/ui/seek_bar.js +296 -3
  209. package/ui/text_selection.js +2 -1
  210. package/ui/ui.js +6 -2
  211. package/lib/routing/node.js +0 -23
  212. package/lib/routing/payload.js +0 -47
  213. package/lib/routing/walker.js +0 -587
  214. package/test/routing/walker_unit.js +0 -505
@@ -63,7 +63,7 @@ shaka.abr.SimpleAbrManager = class {
63
63
  this.bandwidthEstimator_.configure(this.config_.advanced);
64
64
  }
65
65
  const chosenVariant = this.chooseVariant();
66
- if (chosenVariant) {
66
+ if (chosenVariant && navigator.onLine) {
67
67
  this.switch_(chosenVariant, this.config_.clearBufferSwitch,
68
68
  this.config_.safeMarginSwitch);
69
69
  }
@@ -165,10 +165,12 @@ shaka.abr.SimpleAbrManager = class {
165
165
 
166
166
 
167
167
  /**
168
+ * @param {boolean=} preferFastSwitching
169
+ * @return {shaka.extern.Variant}
168
170
  * @override
169
171
  * @export
170
172
  */
171
- chooseVariant() {
173
+ chooseVariant(preferFastSwitching = false) {
172
174
  const SimpleAbrManager = shaka.abr.SimpleAbrManager;
173
175
 
174
176
  let maxHeight = Infinity;
@@ -190,9 +192,24 @@ shaka.abr.SimpleAbrManager = class {
190
192
  maxWidth, this.mediaElement_.clientWidth * devicePixelRatio);
191
193
  }
192
194
 
195
+ let normalVariants = this.variants_.filter((variant) => {
196
+ return !shaka.util.StreamUtils.isFastSwitching(variant);
197
+ });
198
+ if (!normalVariants.length) {
199
+ normalVariants = this.variants_;
200
+ }
201
+
202
+ let variants = normalVariants;
203
+ if (preferFastSwitching &&
204
+ normalVariants.length != this.variants_.length) {
205
+ variants = this.variants_.filter((variant) => {
206
+ return shaka.util.StreamUtils.isFastSwitching(variant);
207
+ });
208
+ }
209
+
193
210
  // Get sorted Variants.
194
211
  let sortedVariants = SimpleAbrManager.filterAndSortVariants_(
195
- this.config_.restrictions, this.variants_,
212
+ this.config_.restrictions, variants,
196
213
  /* maxHeight= */ Infinity, /* maxWidth= */ Infinity);
197
214
 
198
215
  if (maxHeight != Infinity || maxWidth != Infinity) {
@@ -206,14 +223,14 @@ shaka.abr.SimpleAbrManager = class {
206
223
  }
207
224
 
208
225
  sortedVariants = SimpleAbrManager.filterAndSortVariants_(
209
- this.config_.restrictions, this.variants_, maxHeight, maxWidth);
226
+ this.config_.restrictions, variants, maxHeight, maxWidth);
210
227
  }
211
228
 
212
229
  const defaultBandwidthEstimate = this.getDefaultBandwidth_();
213
230
  const currentBandwidth = this.bandwidthEstimator_.getBandwidthEstimate(
214
231
  defaultBandwidthEstimate);
215
232
 
216
- if (this.variants_.length && !sortedVariants.length) {
233
+ if (variants.length && !sortedVariants.length) {
217
234
  // If we couldn't meet the ABR restrictions, we should still play
218
235
  // something.
219
236
  // These restrictions are not "hard" restrictions in the way that
@@ -222,7 +239,7 @@ shaka.abr.SimpleAbrManager = class {
222
239
  shaka.log.warning('No variants met the ABR restrictions. ' +
223
240
  'Choosing a variant by lowest bandwidth.');
224
241
  sortedVariants = SimpleAbrManager.filterAndSortVariants_(
225
- /* restrictions= */ null, this.variants_,
242
+ /* restrictions= */ null, variants,
226
243
  /* maxHeight= */ Infinity, /* maxWidth= */ Infinity);
227
244
  sortedVariants = [sortedVariants[0]];
228
245
  }
@@ -285,7 +302,7 @@ shaka.abr.SimpleAbrManager = class {
285
302
  * @override
286
303
  * @export
287
304
  */
288
- segmentDownloaded(deltaTimeMs, numBytes) {
305
+ segmentDownloaded(deltaTimeMs, numBytes, allowSwitch) {
289
306
  shaka.log.v2('Segment downloaded:',
290
307
  'deltaTimeMs=' + deltaTimeMs,
291
308
  'numBytes=' + numBytes,
@@ -294,7 +311,7 @@ shaka.abr.SimpleAbrManager = class {
294
311
  goog.asserts.assert(deltaTimeMs >= 0, 'expected a non-negative duration');
295
312
  this.bandwidthEstimator_.sample(deltaTimeMs, numBytes);
296
313
 
297
- if ((this.lastTimeChosenMs_ != null) && this.enabled_) {
314
+ if (allowSwitch && (this.lastTimeChosenMs_ != null) && this.enabled_) {
298
315
  this.suggestStreams_();
299
316
  }
300
317
  }
@@ -612,8 +612,13 @@ shaka.ads.MediaTailorAdManager = class {
612
612
  */
613
613
  setupCurrentAdListeners_() {
614
614
  const MediaTailorAdManager = shaka.ads.MediaTailorAdManager;
615
- this.sendTrackingEvent_(MediaTailorAdManager.IMPRESSION_);
616
- this.sendTrackingEvent_(MediaTailorAdManager.START_);
615
+ let needFirstEvents = false;
616
+ if (!this.video_.paused) {
617
+ this.sendTrackingEvent_(MediaTailorAdManager.IMPRESSION_);
618
+ this.sendTrackingEvent_(MediaTailorAdManager.START_);
619
+ } else {
620
+ needFirstEvents = true;
621
+ }
617
622
  this.adListeners_.push({
618
623
  target: this.video_,
619
624
  type: 'volumechange',
@@ -636,7 +641,13 @@ shaka.ads.MediaTailorAdManager = class {
636
641
  target: this.video_,
637
642
  type: 'play',
638
643
  listener: () => {
639
- this.sendTrackingEvent_(MediaTailorAdManager.RESUME_);
644
+ if (needFirstEvents) {
645
+ this.sendTrackingEvent_(MediaTailorAdManager.IMPRESSION_);
646
+ this.sendTrackingEvent_(MediaTailorAdManager.START_);
647
+ needFirstEvents = false;
648
+ } else {
649
+ this.sendTrackingEvent_(MediaTailorAdManager.RESUME_);
650
+ }
640
651
  },
641
652
  });
642
653
  this.adListeners_.push({
@@ -408,7 +408,7 @@ shaka.cast.CastReceiver = class extends shaka.util.FakeEventTarget {
408
408
  } catch (error) {
409
409
  // Pass any errors through to the app.
410
410
  goog.asserts.assert(error instanceof shaka.util.Error,
411
- 'Wrong error type!');
411
+ 'Wrong error type! Error: ' + error);
412
412
  const eventType = shaka.util.FakeEvent.EventName.Error;
413
413
  const data = (new Map()).set('detail', error);
414
414
  const event = new shaka.util.FakeEvent(eventType, data);
@@ -83,6 +83,12 @@ shaka.cea.CeaDecoder = class {
83
83
  */
84
84
  this.waitingForFirstPacket_ = true;
85
85
 
86
+ /**
87
+ * Set used to track available streams.
88
+ * @private {!Set.<string>}
89
+ */
90
+ this.streams_ = new Set();
91
+
86
92
  this.reset();
87
93
  }
88
94
 
@@ -131,6 +137,9 @@ shaka.cea.CeaDecoder = class {
131
137
  const reader = new shaka.util.DataViewReader(
132
138
  userDataSeiMessage, shaka.util.DataViewReader.Endianness.BIG_ENDIAN);
133
139
 
140
+ if (reader.getLength() < shaka.cea.CeaDecoder.MIN_LENGTH) {
141
+ return;
142
+ }
134
143
  if (reader.readUint8() !== shaka.cea.CeaDecoder.USA_COUNTRY_CODE) {
135
144
  return;
136
145
  }
@@ -300,6 +309,8 @@ shaka.cea.CeaDecoder = class {
300
309
  return null;
301
310
  }
302
311
 
312
+ this.streams_.add(selectedMode);
313
+
303
314
  // Process the clean CC data pair.
304
315
  let parsedClosedCaption = null;
305
316
  if (shaka.cea.Cea608DataChannel.isControlCode(ccPacket.ccData1)) {
@@ -340,6 +351,7 @@ shaka.cea.CeaDecoder = class {
340
351
 
341
352
  // As per CEA-708-E, service number 0 is invalid, and should be ignored.
342
353
  if (serviceNumber != 0) {
354
+ this.streams_.add('svc'+ serviceNumber);
343
355
  // If the service doesn't already exist, create it.
344
356
  if (!this.serviceNumberToService_.has(serviceNumber)) {
345
357
  const service = new shaka.cea.Cea708Service(serviceNumber);
@@ -386,6 +398,15 @@ shaka.cea.CeaDecoder = class {
386
398
  }
387
399
  return parity === 1;
388
400
  }
401
+
402
+ /**
403
+ * Returns the streams that the CEA decoder found.
404
+ *
405
+ * @override
406
+ */
407
+ getStreams() {
408
+ return Array.from(this.streams_);
409
+ }
389
410
  };
390
411
 
391
412
  /**
@@ -417,5 +438,12 @@ shaka.cea.CeaDecoder.NTSC_CC_FIELD_2 = 1;
417
438
  */
418
439
  shaka.cea.CeaDecoder.USA_COUNTRY_CODE = 0xb5;
419
440
 
441
+ /**
442
+ * Caption packet min length
443
+ * Country Code + ATSC_PROVIDER_CODE + ATSC_1_USER_IDENTIFIER + USER_DATA_TYPE
444
+ * @private @const {number}
445
+ */
446
+ shaka.cea.CeaDecoder.MIN_LENGTH = 8;
447
+
420
448
  shaka.media.ClosedCaptionParser.registerDecoder(
421
449
  () => new shaka.cea.CeaDecoder());
@@ -18,4 +18,9 @@ shaka.cea.DummyCaptionDecoder = class {
18
18
 
19
19
  /** @override */
20
20
  clear() {}
21
+
22
+ /** @override */
23
+ getStreams() {
24
+ return [];
25
+ }
21
26
  };