shaka-player 4.7.12 → 4.8.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.
Files changed (120) hide show
  1. package/AUTHORS +1 -0
  2. package/CONTRIBUTORS +1 -0
  3. package/LICENSE +54 -0
  4. package/README.md +22 -1
  5. package/dist/controls.css +1 -1
  6. package/dist/controls.css.map +1 -1
  7. package/dist/deps.js +36 -25
  8. package/dist/locales.js +40 -30
  9. package/dist/shaka-player.compiled.d.ts +196 -46
  10. package/dist/shaka-player.compiled.debug.d.ts +196 -46
  11. package/dist/shaka-player.compiled.debug.externs.js +474 -337
  12. package/dist/shaka-player.compiled.debug.js +992 -871
  13. package/dist/shaka-player.compiled.debug.map +4 -4
  14. package/dist/shaka-player.compiled.externs.js +474 -337
  15. package/dist/shaka-player.compiled.js +1248 -1174
  16. package/dist/shaka-player.compiled.map +4 -4
  17. package/dist/shaka-player.ui.d.ts +259 -49
  18. package/dist/shaka-player.ui.debug.d.ts +259 -49
  19. package/dist/shaka-player.ui.debug.externs.js +591 -376
  20. package/dist/shaka-player.ui.debug.js +1208 -1003
  21. package/dist/shaka-player.ui.debug.map +4 -4
  22. package/dist/shaka-player.ui.externs.js +591 -376
  23. package/dist/shaka-player.ui.js +1533 -1408
  24. package/dist/shaka-player.ui.map +4 -4
  25. package/externs/device_sensor_event.js +18 -0
  26. package/externs/hisense.js +16 -0
  27. package/externs/playstation.js +31 -0
  28. package/externs/shaka/abr_manager.js +3 -1
  29. package/externs/shaka/ads.js +5 -0
  30. package/externs/shaka/codecs.js +13 -0
  31. package/externs/shaka/manifest.js +69 -7
  32. package/externs/shaka/net.js +13 -1
  33. package/externs/shaka/offline.js +7 -1
  34. package/externs/shaka/player.js +184 -13
  35. package/externs/shaka/text.js +19 -0
  36. package/externs/tizen.js +41 -0
  37. package/externs/webos.js +19 -0
  38. package/externs/xbox.js +43 -0
  39. package/lib/abr/simple_abr_manager.js +9 -1
  40. package/lib/ads/ad_manager.js +19 -2
  41. package/lib/ads/client_side_ad_manager.js +5 -3
  42. package/lib/ads/media_tailor_ad_manager.js +9 -0
  43. package/lib/cast/cast_receiver.js +0 -14
  44. package/lib/cast/cast_utils.js +1 -0
  45. package/lib/cea/mp4_cea_parser.js +6 -1
  46. package/lib/dash/content_protection.js +97 -53
  47. package/lib/dash/dash_parser.js +240 -179
  48. package/lib/dash/mpd_utils.js +72 -65
  49. package/lib/dash/segment_base.js +35 -22
  50. package/lib/dash/segment_list.js +39 -31
  51. package/lib/dash/segment_template.js +47 -23
  52. package/lib/hls/hls_parser.js +376 -165
  53. package/lib/media/buffering_observer.js +25 -1
  54. package/lib/media/drm_engine.js +91 -71
  55. package/lib/media/manifest_filterer.js +220 -0
  56. package/lib/media/media_source_engine.js +108 -29
  57. package/lib/media/playhead.js +3 -3
  58. package/lib/media/preload_manager.js +827 -0
  59. package/lib/media/presentation_timeline.js +11 -0
  60. package/lib/media/segment_index.js +60 -49
  61. package/lib/media/segment_prefetch.js +140 -43
  62. package/lib/media/segment_reference.js +31 -8
  63. package/lib/media/segment_utils.js +208 -25
  64. package/lib/media/streaming_engine.js +321 -77
  65. package/lib/mss/content_protection.js +31 -25
  66. package/lib/mss/mss_parser.js +78 -55
  67. package/lib/net/networking_engine.js +49 -4
  68. package/lib/offline/indexeddb/v1_storage_cell.js +2 -0
  69. package/lib/offline/indexeddb/v2_storage_cell.js +2 -0
  70. package/lib/offline/manifest_converter.js +10 -3
  71. package/lib/offline/storage.js +5 -3
  72. package/lib/player.js +896 -674
  73. package/lib/polyfill/media_capabilities.js +16 -1
  74. package/lib/text/simple_text_displayer.js +9 -0
  75. package/lib/text/stub_text_displayer.js +7 -0
  76. package/lib/text/text_engine.js +16 -3
  77. package/lib/text/ttml_text_parser.js +116 -114
  78. package/lib/text/ui_text_displayer.js +28 -11
  79. package/lib/text/vtt_text_parser.js +54 -115
  80. package/lib/transmuxer/opus.js +91 -0
  81. package/lib/transmuxer/ts_transmuxer.js +115 -0
  82. package/lib/util/cmcd_manager.js +152 -3
  83. package/lib/util/dom_utils.js +11 -0
  84. package/lib/util/error.js +5 -0
  85. package/lib/util/fake_event.js +2 -0
  86. package/lib/util/manifest_parser_utils.js +97 -3
  87. package/lib/util/mime_utils.js +10 -5
  88. package/lib/util/mp4_box_parsers.js +346 -17
  89. package/lib/util/mp4_generator.js +23 -0
  90. package/lib/util/periods.js +24 -37
  91. package/lib/util/platform.js +161 -9
  92. package/lib/util/player_configuration.js +61 -3
  93. package/lib/util/stats.js +16 -0
  94. package/lib/util/stream_utils.js +350 -277
  95. package/lib/util/string_utils.js +36 -0
  96. package/lib/util/tXml.js +814 -0
  97. package/lib/util/ts_parser.js +50 -0
  98. package/lib/util/xml_utils.js +10 -338
  99. package/package.json +2 -2
  100. package/shaka-player.uncompiled.js +8 -0
  101. package/ui/controls.js +187 -5
  102. package/ui/enums.js +2 -0
  103. package/ui/externs/ui.js +30 -3
  104. package/ui/gl_matrix/matrix_4x4.js +568 -0
  105. package/ui/gl_matrix/matrix_quaternion.js +45 -0
  106. package/ui/less/containers.less +11 -0
  107. package/ui/locales/en-GB.json +2 -0
  108. package/ui/locales/en.json +2 -0
  109. package/ui/locales/es-419.json +2 -0
  110. package/ui/locales/es.json +2 -0
  111. package/ui/locales/source.json +8 -0
  112. package/ui/recenter_vr.js +126 -0
  113. package/ui/resolution_selection.js +25 -5
  114. package/ui/statistics_button.js +12 -0
  115. package/ui/text_selection.js +1 -1
  116. package/ui/toggle_stereoscopic.js +127 -0
  117. package/ui/ui.js +74 -38
  118. package/ui/vr_manager.js +557 -0
  119. package/ui/vr_utils.js +232 -0
  120. package/ui/vr_webgl.js +697 -0
package/ui/controls.js CHANGED
@@ -22,6 +22,7 @@ goog.require('shaka.ui.Locales');
22
22
  goog.require('shaka.ui.Localization');
23
23
  goog.require('shaka.ui.SeekBar');
24
24
  goog.require('shaka.ui.Utils');
25
+ goog.require('shaka.ui.VRManager');
25
26
  goog.require('shaka.util.Dom');
26
27
  goog.require('shaka.util.EventManager');
27
28
  goog.require('shaka.util.FakeEvent');
@@ -42,9 +43,10 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
42
43
  * @param {!shaka.Player} player
43
44
  * @param {!HTMLElement} videoContainer
44
45
  * @param {!HTMLMediaElement} video
46
+ * @param {?HTMLCanvasElement} vrCanvas
45
47
  * @param {shaka.extern.UIConfiguration} config
46
48
  */
47
- constructor(player, videoContainer, video, config) {
49
+ constructor(player, videoContainer, video, vrCanvas, config) {
48
50
  super();
49
51
 
50
52
  /** @private {boolean} */
@@ -76,6 +78,9 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
76
78
  /** @private {!HTMLElement} */
77
79
  this.videoContainer_ = videoContainer;
78
80
 
81
+ /** @private {?HTMLCanvasElement} */
82
+ this.vrCanvas_ = vrCanvas;
83
+
79
84
  /** @private {shaka.extern.IAdManager} */
80
85
  this.adManager_ = this.player_.getAdManager();
81
86
 
@@ -169,6 +174,9 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
169
174
  /** @private {shaka.util.EventManager} */
170
175
  this.eventManager_ = new shaka.util.EventManager();
171
176
 
177
+ /** @private {?shaka.ui.VRManager} */
178
+ this.vr_ = null;
179
+
172
180
  // Configure and create the layout of the controls
173
181
  this.configure(this.config_);
174
182
  this.addEventListeners_();
@@ -187,7 +195,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
187
195
  this.onCastStatusChange_();
188
196
 
189
197
  // Start this timer after we are finished initializing everything,
190
- this.timeAndSeekRangeTimer_.tickEvery(/* seconds= */ 0.125);
198
+ this.timeAndSeekRangeTimer_.tickEvery(this.config_.refreshTickInSeconds);
191
199
 
192
200
  this.eventManager_.listen(this.localization_,
193
201
  shaka.ui.Localization.LOCALE_CHANGED, (e) => {
@@ -230,6 +238,11 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
230
238
  this.timeAndSeekRangeTimer_ = null;
231
239
  }
232
240
 
241
+ if (this.vr_) {
242
+ this.vr_.release();
243
+ this.vr_ = null;
244
+ }
245
+
233
246
  // Important! Release all child elements before destroying the cast proxy
234
247
  // or player. This makes sure those destructions will not trigger event
235
248
  // listeners in the UI which would then invoke the cast proxy or player.
@@ -334,6 +347,10 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
334
347
  this.contextMenu_ = null;
335
348
  }
336
349
 
350
+ if (this.vr_) {
351
+ this.vr_.configure(config);
352
+ }
353
+
337
354
  if (this.controlsContainer_) {
338
355
  shaka.util.Dom.removeAllChildren(this.controlsContainer_);
339
356
  this.releaseChildElements_();
@@ -343,6 +360,13 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
343
360
  // re-created or uprooted in the DOM, even when the DOM is re-created,
344
361
  // since that seemingly breaks the IMA SDK.
345
362
  this.addClientAdContainer_();
363
+
364
+ goog.asserts.assert(
365
+ this.controlsContainer_, 'Should have a controlsContainer_!');
366
+ goog.asserts.assert(this.localVideo_, 'Should have a localVideo_!');
367
+ goog.asserts.assert(this.player_, 'Should have a player_!');
368
+ this.vr_ = new shaka.ui.VRManager(this.controlsContainer_, this.vrCanvas_,
369
+ this.localVideo_, this.player_, this.config_);
346
370
  }
347
371
 
348
372
  // Create the new layout
@@ -1172,6 +1196,10 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
1172
1196
  this.onCastStatusChange_();
1173
1197
  });
1174
1198
 
1199
+ this.eventManager_.listen(this.vr_, 'vrstatuschanged', () => {
1200
+ this.dispatchEvent(new shaka.util.FakeEvent('vrstatuschanged'));
1201
+ });
1202
+
1175
1203
  this.eventManager_.listen(this.videoContainer_, 'keydown', (e) => {
1176
1204
  this.onControlsKeyDown_(/** @type {!KeyboardEvent} */(e));
1177
1205
  });
@@ -1384,7 +1412,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
1384
1412
 
1385
1413
  /** @private */
1386
1414
  onContainerClick_() {
1387
- if (!this.enabled_) {
1415
+ if (!this.enabled_ || this.isPlayingVR()) {
1388
1416
  return;
1389
1417
  }
1390
1418
 
@@ -1449,7 +1477,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
1449
1477
  case 'ArrowLeft':
1450
1478
  // If it's not focused on the volume bar, move the seek time backward
1451
1479
  // for a few sec. Otherwise, the volume will be adjusted automatically.
1452
- if (this.seekBar_ && !isVolumeBar && keyboardSeekDistance > 0) {
1480
+ if (this.seekBar_ && isSeekBar && !isVolumeBar &&
1481
+ keyboardSeekDistance > 0) {
1453
1482
  event.preventDefault();
1454
1483
  this.seek_(this.seekBar_.getValue() - keyboardSeekDistance);
1455
1484
  }
@@ -1457,7 +1486,8 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
1457
1486
  case 'ArrowRight':
1458
1487
  // If it's not focused on the volume bar, move the seek time forward
1459
1488
  // for a few sec. Otherwise, the volume will be adjusted automatically.
1460
- if (this.seekBar_ && !isVolumeBar && keyboardSeekDistance > 0) {
1489
+ if (this.seekBar_ && isSeekBar && !isVolumeBar &&
1490
+ keyboardSeekDistance > 0) {
1461
1491
  event.preventDefault();
1462
1492
  this.seek_(this.seekBar_.getValue() + keyboardSeekDistance);
1463
1493
  }
@@ -1700,6 +1730,149 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
1700
1730
  this.eventManager_.unlisten(window, 'mousedown');
1701
1731
  }
1702
1732
 
1733
+ /**
1734
+ * @export
1735
+ */
1736
+ showUI() {
1737
+ const event = new Event('mousemove', {bubbles: false, cancelable: false});
1738
+ this.onMouseMove_(event);
1739
+ }
1740
+
1741
+ /**
1742
+ * @export
1743
+ */
1744
+ hideUI() {
1745
+ this.onMouseLeave_();
1746
+ }
1747
+
1748
+ /**
1749
+ * @return {shaka.ui.VRManager}
1750
+ */
1751
+ getVR() {
1752
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1753
+ return this.vr_;
1754
+ }
1755
+
1756
+ /**
1757
+ * Returns if a VR is capable.
1758
+ *
1759
+ * @return {boolean}
1760
+ * @export
1761
+ */
1762
+ canPlayVR() {
1763
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1764
+ return this.vr_.canPlayVR();
1765
+ }
1766
+
1767
+ /**
1768
+ * Returns if a VR is supported.
1769
+ *
1770
+ * @return {boolean}
1771
+ * @export
1772
+ */
1773
+ isPlayingVR() {
1774
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1775
+ return this.vr_.isPlayingVR();
1776
+ }
1777
+
1778
+ /**
1779
+ * Reset VR view.
1780
+ */
1781
+ resetVR() {
1782
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1783
+ this.vr_.reset();
1784
+ }
1785
+
1786
+ /**
1787
+ * Get the angle of the north.
1788
+ *
1789
+ * @return {?number}
1790
+ * @export
1791
+ */
1792
+ getVRNorth() {
1793
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1794
+ return this.vr_.getNorth();
1795
+ }
1796
+
1797
+ /**
1798
+ * Returns the angle of the current field of view displayed in degrees.
1799
+ *
1800
+ * @return {?number}
1801
+ * @export
1802
+ */
1803
+ getVRFieldOfView() {
1804
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1805
+ return this.vr_.getFieldOfView();
1806
+ }
1807
+
1808
+ /**
1809
+ * Changing the field of view increases or decreases the portion of the video
1810
+ * that is viewed at one time. If the field of view is decreased, a small
1811
+ * part of the video will be seen, but with more detail. If the field of view
1812
+ * is increased, a larger part of the video will be seen, but with less
1813
+ * detail.
1814
+ *
1815
+ * @param {number} fieldOfView In degrees
1816
+ * @export
1817
+ */
1818
+ setVRFieldOfView(fieldOfView) {
1819
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1820
+ this.vr_.setFieldOfView(fieldOfView);
1821
+ }
1822
+
1823
+ /**
1824
+ * Toggle stereoscopic mode.
1825
+ *
1826
+ * @export
1827
+ */
1828
+ toggleStereoscopicMode() {
1829
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1830
+ this.vr_.toggleStereoscopicMode();
1831
+ }
1832
+
1833
+ /**
1834
+ * Returns true if stereoscopic mode is enabled.
1835
+ *
1836
+ * @return {boolean}
1837
+ */
1838
+ isStereoscopicModeEnabled() {
1839
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1840
+ return this.vr_.isStereoscopicModeEnabled();
1841
+ }
1842
+
1843
+ /**
1844
+ * Increment the yaw in X angle in degrees.
1845
+ *
1846
+ * @param {number} angle In degrees
1847
+ * @export
1848
+ */
1849
+ incrementYaw(angle) {
1850
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1851
+ this.vr_.incrementYaw(angle);
1852
+ }
1853
+
1854
+ /**
1855
+ * Increment the pitch in X angle in degrees.
1856
+ *
1857
+ * @param {number} angle In degrees
1858
+ * @export
1859
+ */
1860
+ incrementPitch(angle) {
1861
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1862
+ this.vr_.incrementPitch(angle);
1863
+ }
1864
+
1865
+ /**
1866
+ * Increment the roll in X angle in degrees.
1867
+ *
1868
+ * @param {number} angle In degrees
1869
+ * @export
1870
+ */
1871
+ incrementRoll(angle) {
1872
+ goog.asserts.assert(this.vr_ != null, 'Should have a VR manager!');
1873
+ this.vr_.incrementRoll(angle);
1874
+ }
1875
+
1703
1876
  /**
1704
1877
  * Create a localization instance already pre-loaded with all the locales that
1705
1878
  * we support.
@@ -1734,6 +1907,15 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
1734
1907
  */
1735
1908
 
1736
1909
 
1910
+ /**
1911
+ * @event shaka.ui.Controls#VRStatusChangedEvent
1912
+ * @description Fired when VR status change
1913
+ * @property {string} type
1914
+ * 'vrstatuschanged'
1915
+ * @exportDoc
1916
+ */
1917
+
1918
+
1737
1919
  /**
1738
1920
  * @event shaka.ui.Controls#SubMenuOpenEvent
1739
1921
  * @description Fired when one of the overflow submenus is opened
package/ui/enums.js CHANGED
@@ -44,4 +44,6 @@ shaka.ui.Enums.MaterialDesignIcons = {
44
44
  'REPLAY': 'replay',
45
45
  'STATISTICS_ON': 'insert_chart_outlined',
46
46
  'STATISTICS_OFF': 'insert_chart',
47
+ 'RECENTER_VR': 'control_camera',
48
+ 'TOGGLE_STEREOSCOPIC': '3d_rotation',
47
49
  };
package/ui/externs/ui.js CHANGED
@@ -78,6 +78,7 @@ shaka.extern.UIVolumeBarColors;
78
78
  * seekBarColors: shaka.extern.UISeekBarColors,
79
79
  * volumeBarColors: shaka.extern.UIVolumeBarColors,
80
80
  * trackLabelFormat: shaka.ui.Overlay.TrackLabelFormat,
81
+ * textTrackLabelFormat: shaka.ui.Overlay.TrackLabelFormat,
81
82
  * fadeDelay: number,
82
83
  * doubleClickForFullscreen: boolean,
83
84
  * singleClickForPlayAndPause: boolean,
@@ -91,7 +92,10 @@ shaka.extern.UIVolumeBarColors;
91
92
  * preferDocumentPictureInPicture: boolean,
92
93
  * showAudioChannelCountVariants: boolean,
93
94
  * seekOnTaps: boolean,
94
- * tapSeekDistance: number
95
+ * tapSeekDistance: number,
96
+ * refreshTickInSeconds: number,
97
+ * displayInVrMode: boolean,
98
+ * defaultVrProjectionMode: string
95
99
  * }}
96
100
  *
97
101
  * @property {!Array.<string>} controlPanelElements
@@ -147,8 +151,18 @@ shaka.extern.UIVolumeBarColors;
147
151
  * colors used in the linear gradient constructed in JavaScript, since you
148
152
  * cannot do this in pure CSS.
149
153
  * @property {shaka.ui.Overlay.TrackLabelFormat} trackLabelFormat
150
- * An enum that determines what is shown in the labels for text track and
151
- * audio variant selection.
154
+ * An enum that determines what is shown in the labels for audio variant
155
+ * selection.
156
+ * LANGUAGE means that only the language of the item is shown.
157
+ * ROLE means that only the role of the item is shown.
158
+ * LANGUAGE_ROLE means both language and role are shown, or just language if
159
+ * there is no role.
160
+ * LABEL means the non-standard DASH "label" attribute or the standard DASH
161
+ * "Label" element or the HLS "NAME" attribute are shown.
162
+ * Defaults to LANGUAGE.
163
+ * @property {shaka.ui.Overlay.TrackLabelFormat} textTrackLabelFormat
164
+ * An enum that determines what is shown in the labels for text track
165
+ * selection.
152
166
  * LANGUAGE means that only the language of the item is shown.
153
167
  * ROLE means that only the role of the item is shown.
154
168
  * LANGUAGE_ROLE means both language and role are shown, or just language if
@@ -167,6 +181,7 @@ shaka.extern.UIVolumeBarColors;
167
181
  * Defaults to true.
168
182
  * @property {boolean} singleClickForPlayAndPause
169
183
  * Whether or not clicking on the video should cause it to play or pause.
184
+ * It does not work in VR mode.
170
185
  * Defaults to true.
171
186
  * @property {boolean} enableKeyboardPlaybackControls
172
187
  * Whether or not playback controls via keyboard is enabled, such as seek
@@ -217,6 +232,18 @@ shaka.extern.UIVolumeBarColors;
217
232
  * right part of the video. If less than or equal to 0,
218
233
  * no seeking will occur.
219
234
  * Defaults to 10 seconds.
235
+ * @property {number} refreshTickInSeconds
236
+ * The time interval, in seconds, to update the seek bar.
237
+ * Defaults to 0.125 seconds.
238
+ * @property {boolean} displayInVrMode
239
+ * If true, the content will be treated as VR.
240
+ * If false, it will only be treated as VR if we automatically detect it as
241
+ * such. (See the Enabling VR section in docs/tutorials/ui.md)
242
+ * Defaults to false.
243
+ * @property {string} defaultVrProjectionMode
244
+ * Indicate the default VR projection mode.
245
+ * Possible values: <code>'equirectangular'</code> or <code>'cubemap'</code>.
246
+ * Defaults to <code>'equirectangular'</code>.
220
247
  * @exportDoc
221
248
  */
222
249
  shaka.extern.UIConfiguration;