shaka-player 4.2.9 → 4.2.10

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 (80) hide show
  1. package/.github/workflows/selenium-lab-tests.yaml +23 -1
  2. package/AUTHORS +2 -1
  3. package/CHANGELOG.md +27 -0
  4. package/CONTRIBUTORS +4 -1
  5. package/dist/controls.css +1 -1
  6. package/dist/demo.compiled.debug.js +154 -276
  7. package/dist/demo.compiled.debug.map +4 -4
  8. package/dist/demo.compiled.js +154 -276
  9. package/dist/demo.compiled.map +4 -4
  10. package/dist/deps.js +1 -1
  11. package/dist/locales.js +30 -30
  12. package/dist/receiver.compiled.debug.js +36 -65
  13. package/dist/receiver.compiled.debug.map +4 -4
  14. package/dist/receiver.compiled.js +36 -65
  15. package/dist/receiver.compiled.map +4 -4
  16. package/dist/shaka-player.compiled.d.ts +12 -3
  17. package/dist/shaka-player.compiled.debug.d.ts +12 -3
  18. package/dist/shaka-player.compiled.debug.externs.js +17 -12
  19. package/dist/shaka-player.compiled.debug.js +150 -147
  20. package/dist/shaka-player.compiled.debug.map +4 -4
  21. package/dist/shaka-player.compiled.externs.js +17 -12
  22. package/dist/shaka-player.compiled.js +822 -820
  23. package/dist/shaka-player.compiled.map +3 -3
  24. package/dist/shaka-player.ui.d.ts +12 -3
  25. package/dist/shaka-player.ui.debug.d.ts +12 -3
  26. package/dist/shaka-player.ui.debug.externs.js +5 -0
  27. package/dist/shaka-player.ui.debug.js +160 -157
  28. package/dist/shaka-player.ui.debug.map +3 -3
  29. package/dist/shaka-player.ui.externs.js +5 -0
  30. package/dist/shaka-player.ui.js +952 -949
  31. package/dist/shaka-player.ui.map +3 -3
  32. package/docs/tutorials/a11y.md +0 -4
  33. package/docs/tutorials/ad_monetization.md +0 -4
  34. package/docs/tutorials/basic-usage.md +0 -5
  35. package/docs/tutorials/config.md +0 -5
  36. package/docs/tutorials/debugging.md +0 -5
  37. package/docs/tutorials/drm-config.md +0 -5
  38. package/docs/tutorials/fairplay.md +2 -2
  39. package/docs/tutorials/license-server-auth.md +0 -5
  40. package/docs/tutorials/license-wrapping.md +0 -5
  41. package/docs/tutorials/network-and-buffering-config.md +0 -5
  42. package/docs/tutorials/ui-customization.md +0 -5
  43. package/docs/tutorials/ui.md +0 -7
  44. package/docs/tutorials/welcome.md +0 -5
  45. package/externs/network_information.js +7 -2
  46. package/externs/shaka/abr_manager.js +6 -0
  47. package/externs/shaka/net.js +1 -0
  48. package/externs/shaka/player.js +13 -7
  49. package/lib/abr/simple_abr_manager.js +27 -3
  50. package/lib/ads/client_side_ad_manager.js +6 -3
  51. package/lib/dash/dash_parser.js +49 -48
  52. package/lib/debug/log.js +9 -13
  53. package/lib/media/media_source_engine.js +11 -4
  54. package/lib/media/segment_index.js +2 -0
  55. package/lib/media/streaming_engine.js +8 -3
  56. package/lib/net/http_fetch_plugin.js +79 -57
  57. package/lib/net/networking_engine.js +1 -0
  58. package/lib/player.js +22 -3
  59. package/lib/polyfill/media_capabilities.js +13 -0
  60. package/lib/text/mp4_vtt_parser.js +4 -0
  61. package/lib/text/text_engine.js +1 -0
  62. package/lib/util/manifest_parser_utils.js +1 -2
  63. package/lib/util/mime_utils.js +11 -0
  64. package/lib/util/periods.js +5 -5
  65. package/lib/util/stream_utils.js +2 -2
  66. package/maintained-branches.md +3 -4
  67. package/package.json +1 -1
  68. package/test/media/content_workarounds_unit.js +43 -0
  69. package/test/media/drm_engine_integration.js +4 -17
  70. package/test/media/streaming_engine_unit.js +6 -1
  71. package/test/net/networking_engine_unit.js +6 -1
  72. package/test/player_integration.js +39 -0
  73. package/test/player_unit.js +57 -0
  74. package/test/polyfill/media_capabilities_unit.js +0 -1
  75. package/test/test/assets/text-clip-alt.vtt +63 -0
  76. package/test/test/util/fake_drm_engine.js +3 -0
  77. package/test/test/util/simple_fakes.js +6 -0
  78. package/test/test/util/test_scheme.js +9 -14
  79. package/test/text/mp4_vtt_parser_unit.js +8 -0
  80. package/test/util/mime_utils_unit.js +10 -0
@@ -120,65 +120,77 @@ shaka.net.HttpFetchPlugin = class {
120
120
  // not the body yet.
121
121
  headersReceived(shaka.net.HttpFetchPlugin.headersToGenericObject_(
122
122
  response.headers));
123
- // Getting the reader in this way allows us to observe the process of
124
- // downloading the body, instead of just waiting for an opaque promise to
125
- // resolve.
126
- // We first clone the response because calling getReader locks the body
127
- // stream; if we didn't clone it here, we would be unable to get the
128
- // response's arrayBuffer later.
129
- const reader = response.clone().body.getReader();
130
-
131
- const contentLengthRaw = response.headers.get('Content-Length');
132
- const contentLength =
133
- contentLengthRaw ? parseInt(contentLengthRaw, 10) : 0;
134
-
135
- const start = (controller) => {
136
- const push = async () => {
137
- let readObj;
138
- try {
139
- readObj = await reader.read();
140
- } catch (e) {
141
- // If we abort the request, we'll get an error here. Just ignore it
142
- // since real errors will be reported when we read the buffer below.
143
- shaka.log.v1('error reading from stream', e.message);
144
- return;
145
- }
146
-
147
- if (!readObj.done) {
148
- loaded += readObj.value.byteLength;
149
- if (streamDataCallback) {
150
- await streamDataCallback(readObj.value);
123
+
124
+ // In new versions of Chromium, HEAD requests now have a response body
125
+ // that is null.
126
+ // So just don't try to download the body at all, if it's a HEAD request,
127
+ // to avoid null reference errors.
128
+ // See: https://crbug.com/1297060
129
+ if (init.method != 'HEAD') {
130
+ goog.asserts.assert(response.body,
131
+ 'non-HEAD responses should have a body');
132
+
133
+ // Getting the reader in this way allows us to observe the process of
134
+ // downloading the body, instead of just waiting for an opaque promise
135
+ // to resolve.
136
+ // We first clone the response because calling getReader locks the body
137
+ // stream; if we didn't clone it here, we would be unable to get the
138
+ // response's arrayBuffer later.
139
+ const reader = response.clone().body.getReader();
140
+
141
+ const contentLengthRaw = response.headers.get('Content-Length');
142
+ const contentLength =
143
+ contentLengthRaw ? parseInt(contentLengthRaw, 10) : 0;
144
+
145
+ const start = (controller) => {
146
+ const push = async () => {
147
+ let readObj;
148
+ try {
149
+ readObj = await reader.read();
150
+ } catch (e) {
151
+ // If we abort the request, we'll get an error here. Just ignore
152
+ // it since real errors will be reported when we read the buffer
153
+ // below.
154
+ shaka.log.v1('error reading from stream', e.message);
155
+ return;
156
+ }
157
+
158
+ if (!readObj.done) {
159
+ loaded += readObj.value.byteLength;
160
+ if (streamDataCallback) {
161
+ await streamDataCallback(readObj.value);
162
+ }
163
+ }
164
+
165
+ const currentTime = Date.now();
166
+ // If the time between last time and this time we got progress event
167
+ // is long enough, or if a whole segment is downloaded, call
168
+ // progressUpdated().
169
+ if (currentTime - lastTime > 100 || readObj.done) {
170
+ progressUpdated(currentTime - lastTime, loaded - lastLoaded,
171
+ contentLength - loaded);
172
+ lastLoaded = loaded;
173
+ lastTime = currentTime;
174
+ }
175
+
176
+ if (readObj.done) {
177
+ goog.asserts.assert(!readObj.value,
178
+ 'readObj should be unset when "done" is true.');
179
+ controller.close();
180
+ } else {
181
+ controller.enqueue(readObj.value);
182
+ push();
151
183
  }
152
- }
153
-
154
- const currentTime = Date.now();
155
- // If the time between last time and this time we got progress event
156
- // is long enough, or if a whole segment is downloaded, call
157
- // progressUpdated().
158
- if (currentTime - lastTime > 100 || readObj.done) {
159
- progressUpdated(currentTime - lastTime, loaded - lastLoaded,
160
- contentLength - loaded);
161
- lastLoaded = loaded;
162
- lastTime = currentTime;
163
- }
164
-
165
- if (readObj.done) {
166
- goog.asserts.assert(!readObj.value,
167
- 'readObj should be unset when "done" is true.');
168
- controller.close();
169
- } else {
170
- controller.enqueue(readObj.value);
171
- push();
172
- }
184
+ };
185
+ push();
173
186
  };
174
- push();
175
- };
176
- // Create a ReadableStream to use the reader. We don't need to use the
177
- // actual stream for anything, though, as we are using the response's
178
- // arrayBuffer method to get the body, so we don't store the
179
- // ReadableStream.
180
- new ReadableStream({start}); // eslint-disable-line no-new
181
- arrayBuffer = await response.arrayBuffer();
187
+ // Create a ReadableStream to use the reader. We don't need to use the
188
+ // actual stream for anything, though, as we are using the response's
189
+ // arrayBuffer method to get the body, so we don't store the
190
+ // ReadableStream.
191
+ new ReadableStream({start}); // eslint-disable-line no-new
192
+ arrayBuffer = await response.arrayBuffer();
193
+ }
182
194
  } catch (error) {
183
195
  if (abortStatus.canceled) {
184
196
  throw new shaka.util.Error(
@@ -243,6 +255,16 @@ shaka.net.HttpFetchPlugin = class {
243
255
  } else {
244
256
  return false;
245
257
  }
258
+ // Old fetch implementations hasn't body and ReadableStream implementation
259
+ // See: https://github.com/shaka-project/shaka-player/issues/5088
260
+ if (window.Response) {
261
+ const response = new Response('');
262
+ if (!response.body) {
263
+ return false;
264
+ }
265
+ } else {
266
+ return false;
267
+ }
246
268
  return !!(window.fetch && window.AbortController);
247
269
  }
248
270
  };
@@ -312,6 +312,7 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {
312
312
  if (!responseAndGotProgress.gotProgress &&
313
313
  this.onProgressUpdated_ &&
314
314
  !response.fromCache &&
315
+ request.method != 'HEAD' &&
315
316
  type == shaka.net.NetworkingEngine.RequestType.SEGMENT) {
316
317
  this.onProgressUpdated_(response.timeMs, response.data.byteLength);
317
318
  }
package/lib/player.js CHANGED
@@ -806,7 +806,6 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
806
806
  }
807
807
 
808
808
  this.abrManagerFactory_ = null;
809
- this.abrManager_ = null;
810
809
  this.config_ = null;
811
810
  this.stats_ = null;
812
811
  this.videoContainer_ = null;
@@ -817,6 +816,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
817
816
  this.networkingEngine_ = null;
818
817
  }
819
818
 
819
+ if (this.abrManager_) {
820
+ this.abrManager_.release();
821
+ this.abrManager_ = null;
822
+ }
823
+
820
824
  // FakeEventTarget implements IReleasable
821
825
  super.release();
822
826
  }
@@ -1232,6 +1236,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
1232
1236
  */
1233
1237
  shouldUseSrcEquals_(payload) {
1234
1238
  const Platform = shaka.util.Platform;
1239
+ const MimeUtils = shaka.util.MimeUtils;
1235
1240
 
1236
1241
  // If we are using a platform that does not support media source, we will
1237
1242
  // fall back to src= to handle all playback.
@@ -1286,7 +1291,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
1286
1291
  // version there.
1287
1292
 
1288
1293
  // Native HLS can be preferred on any platform via this flag:
1289
- if (this.config_.streaming.preferNativeHls) {
1294
+ if (MimeUtils.isHlsType(mimeType) &&
1295
+ this.config_.streaming.preferNativeHls) {
1290
1296
  return true;
1291
1297
  }
1292
1298
 
@@ -4086,6 +4092,19 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
4086
4092
  firstVariantWithLabel.language, '', 0, label);
4087
4093
 
4088
4094
  this.chooseVariantAndSwitch_();
4095
+ } else if (this.video_ && this.video_.audioTracks) {
4096
+ const audioTracks = Array.from(this.video_.audioTracks);
4097
+
4098
+ let trackMatch = null;
4099
+
4100
+ for (const audioTrack of audioTracks) {
4101
+ if (audioTrack.label == label) {
4102
+ trackMatch = audioTrack;
4103
+ }
4104
+ }
4105
+ if (trackMatch) {
4106
+ this.switchHtml5Track_(trackMatch);
4107
+ }
4089
4108
  }
4090
4109
  }
4091
4110
 
@@ -6607,7 +6626,7 @@ shaka.Player.TYPICAL_BUFFERING_THRESHOLD_ = 0.5;
6607
6626
  * @define {string} A version number taken from git at compile time.
6608
6627
  * @export
6609
6628
  */
6610
- shaka.Player.version = 'v4.2.9-uncompiled';
6629
+ shaka.Player.version = 'v4.2.10-uncompiled';
6611
6630
 
6612
6631
  // Initialize the deprecation system using the version string we just set
6613
6632
  // on the player.
@@ -115,6 +115,19 @@ shaka.polyfill.MediaCapabilities = class {
115
115
  if (shaka.util.Platform.isChromecast()) {
116
116
  isSupported =
117
117
  shaka.polyfill.MediaCapabilities.canCastDisplayType_(videoConfig);
118
+ } else if (shaka.util.Platform.isTizen()) {
119
+ let extendedType = videoConfig.contentType;
120
+ if (videoConfig.width && videoConfig.height) {
121
+ extendedType += `; width=${videoConfig.width}`;
122
+ extendedType += `; height=${videoConfig.height}`;
123
+ }
124
+ if (videoConfig.framerate) {
125
+ extendedType += `; framerate=${videoConfig.framerate}`;
126
+ }
127
+ if (videoConfig.bitrate) {
128
+ extendedType += `; bitrate=${videoConfig.bitrate}`;
129
+ }
130
+ isSupported = MediaSource.isTypeSupported(extendedType);
118
131
  } else {
119
132
  isSupported = MediaSource.isTypeSupported(videoConfig.contentType);
120
133
  }
@@ -97,6 +97,10 @@ shaka.text.Mp4VttParser = class {
97
97
  * @export
98
98
  */
99
99
  parseMedia(data, time) {
100
+ if (!data.length) {
101
+ return [];
102
+ }
103
+
100
104
  if (!this.timescale_) {
101
105
  // Missing timescale for VTT content. We should have seen the init
102
106
  // segment.
@@ -139,6 +139,7 @@ shaka.text.TextEngine = class {
139
139
  // into TextEngine and TextDisplayer.
140
140
  if (mimeType == shaka.util.MimeUtils.CEA608_CLOSED_CAPTION_MIMETYPE ||
141
141
  mimeType == shaka.util.MimeUtils.CEA708_CLOSED_CAPTION_MIMETYPE) {
142
+ this.parser_ = null;
142
143
  return;
143
144
  }
144
145
 
@@ -185,8 +185,7 @@ shaka.util.ManifestParserUtils.AUDIO_CODEC_REGEXPS_ = [
185
185
  /^mp4a/,
186
186
  /^[ae]c-3$/,
187
187
  /^ac-4$/,
188
- /^dts[cx]$/, // DTS Surround Sound
189
- /^[du]dts$/, // DTS Surround Sound
188
+ /^dts[cex]$/, // DTS Digital Surround (dtsc), DTS Express (dtse), DTS:X (dtsx)
190
189
  ];
191
190
 
192
191
 
@@ -196,6 +196,17 @@ shaka.util.MimeUtils = class {
196
196
  return value;
197
197
  }
198
198
 
199
+ /**
200
+ * Checks if the given MIME type is HLS MIME type.
201
+ *
202
+ * @param {string} mimeType
203
+ * @return {boolean}
204
+ */
205
+ static isHlsType(mimeType) {
206
+ return mimeType === 'application/x-mpegurl' ||
207
+ mimeType === 'application/vnd.apple.mpegurl';
208
+ }
209
+
199
210
  /**
200
211
  * Get the base and profile of a codec string. Where [0] will be the codec
201
212
  * base and [1] will be the profile.
@@ -671,11 +671,11 @@ shaka.util.PeriodCombiner = class {
671
671
  // Also checks if the segmentIndex is still valid after the async
672
672
  // operations, to make sure we stop if the active stream has changed.
673
673
  if (outputStream.segmentIndex instanceof shaka.media.MetaSegmentIndex) {
674
- for (let i = 0; i < streams.length; i++) {
674
+ for (let i = firstNewPeriodIndex; i < streams.length; i++) {
675
675
  const match = streams[i];
676
- if (match.segmentIndex && i >= firstNewPeriodIndex) {
677
- goog.asserts.assert(match.segmentIndex,
678
- 'stream should have a segmentIndex.');
676
+ goog.asserts.assert(match.segmentIndex,
677
+ 'stream should have a segmentIndex.');
678
+ if (match.segmentIndex) {
679
679
  outputStream.segmentIndex.appendSegmentIndex(match.segmentIndex);
680
680
  }
681
681
  }
@@ -728,7 +728,7 @@ shaka.util.PeriodCombiner = class {
728
728
  // in advance. concat() will add them to the output's MetaSegmentIndex.
729
729
  }
730
730
 
731
- if (!outputStream.matchedStreams) {
731
+ if (!outputStream.matchedStreams || !outputStream.matchedStreams.length) {
732
732
  // This is not a stream we can build output from, but it may become part
733
733
  // of another output based on another period's stream.
734
734
  return null;
@@ -828,7 +828,7 @@ shaka.util.StreamUtils = class {
828
828
  const video = variant.video;
829
829
  if (audio && currentVariant && currentVariant.audio) {
830
830
  if (!StreamUtils.areStreamsCompatible_(audio, currentVariant.audio)) {
831
- shaka.log.debug('Droping variant - not compatible with active audio',
831
+ shaka.log.debug('Dropping variant - not compatible with active audio',
832
832
  'active audio',
833
833
  StreamUtils.getStreamSummaryString_(currentVariant.audio),
834
834
  'variant.audio',
@@ -839,7 +839,7 @@ shaka.util.StreamUtils = class {
839
839
 
840
840
  if (video && currentVariant && currentVariant.video) {
841
841
  if (!StreamUtils.areStreamsCompatible_(video, currentVariant.video)) {
842
- shaka.log.debug('Droping variant - not compatible with active video',
842
+ shaka.log.debug('Dropping variant - not compatible with active video',
843
843
  'active video',
844
844
  StreamUtils.getStreamSummaryString_(currentVariant.video),
845
845
  'variant.video',
@@ -2,10 +2,9 @@
2
2
 
3
3
  We are currently maintaining the following branches of Shaka Player:
4
4
 
5
- - v4.1 (latest)
6
- - v4.0 (previous)
7
- - v3.3 (LTS until April 30, 2023)
8
- - v3.2 (in use by the Cast Application Framework)
5
+ - v4.3 (latest, also in use by the Cast Application Framework)
6
+ - v4.2 (previous)
7
+ - No active LTS branches at this time
9
8
 
10
9
  Other branches are no longer receiving bug fixes, and we recommend you upgrade
11
10
  to a maintained branch. For details on upgrading, please see our
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shaka-player",
3
3
  "description": "DASH/EME video player library",
4
- "version": "4.2.9",
4
+ "version": "4.2.10",
5
5
  "homepage": "https://github.com/shaka-project/shaka-player",
6
6
  "author": "Google",
7
7
  "maintainers": [
@@ -0,0 +1,43 @@
1
+ /*! @license
2
+ * Shaka Player
3
+ * Copyright 2016 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ describe('ContentWorkarounds', () => {
8
+ const encryptionBoxes = {
9
+ 'encv': ['hev1', 'hvc1', 'avc1', 'avc3'],
10
+ 'enca': ['ac-3', 'ec-3', 'mp4a'],
11
+ };
12
+ for (const encryptionBox of Object.keys(encryptionBoxes)) {
13
+ for (const box of encryptionBoxes[encryptionBox]) {
14
+ it(`adds ${encryptionBox} box for ${box}`, () => {
15
+ const boxType = [];
16
+ for (const char of box) {
17
+ boxType.push(char.charCodeAt(0));
18
+ }
19
+ const unencrypted = new Uint8Array([
20
+ 0x00, 0x00, 0x00, 0x20, // size
21
+ 0x73, 0x74, 0x73, 0x64, // stsd
22
+ 0x01, // version
23
+ 0x12, 0x34, 0x56, // flags
24
+ 0x00, 0x00, 0x00, 0x01, // count
25
+ 0x00, 0x00, 0x00, 0x10, // size
26
+ ...boxType, // box type
27
+ 0x01, // version
28
+ 0x12, 0x34, 0x56, // flags
29
+ 0x00, 0x11, 0x22, 0x33, // payload
30
+ ]);
31
+
32
+ const faked =
33
+ shaka.media.ContentWorkarounds.fakeEncryption(unencrypted);
34
+ const spy = jasmine.createSpy('boxCallback');
35
+ new shaka.util.Mp4Parser()
36
+ .fullBox('stsd', shaka.util.Mp4Parser.sampleDescription)
37
+ .box(encryptionBox, /** @type {!Function} */ (spy))
38
+ .parse(faked);
39
+ expect(spy).toHaveBeenCalled();
40
+ });
41
+ }
42
+ }
43
+ });
@@ -74,19 +74,6 @@ describe('DrmEngine', () => {
74
74
  onEventSpy = jasmine.createSpy('onEvent');
75
75
 
76
76
  networkingEngine = new shaka.net.NetworkingEngine();
77
- networkingEngine.registerRequestFilter((type, request) => {
78
- if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) {
79
- return;
80
- }
81
-
82
- request.headers['X-AxDRM-Message'] = [
83
- 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lk',
84
- 'IjoiNjllNTQwODgtZTllMC00NTMwLThjMWEtMWViNmRjZDBkMTRlIiwibWVzc2FnZSI6e',
85
- 'yJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImtleXMiOlt7ImlkIjoiNmU1YTFkMj',
86
- 'YtMjc1Ny00N2Q3LTgwNDYtZWFhNWQxZDM0YjVhIn1dfX0.yF7PflOPv9qHnu3ZWJNZ12j',
87
- 'gkqTabmwXbDWk_47tLNE',
88
- ].join('');
89
- });
90
77
 
91
78
  const playerInterface = {
92
79
  netEngine: networkingEngine,
@@ -99,22 +86,22 @@ describe('DrmEngine', () => {
99
86
  drmEngine = new shaka.media.DrmEngine(playerInterface);
100
87
  const config = shaka.util.PlayerConfiguration.createDefault().drm;
101
88
  config.servers['com.widevine.alpha'] =
102
- 'https://drm-widevine-licensing.axtest.net/AcquireLicense';
89
+ 'https://cwip-shaka-proxy.appspot.com/specific_key?blodJidXR9eARuql0dNLWg=GX8m9XLIZNIzizrl0RTqnA';
103
90
  config.servers['com.microsoft.playready'] =
104
- 'https://drm-playready-licensing.axtest.net/AcquireLicense';
91
+ 'https://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(kid:6e5a1d26-2757-47d7-8046-eaa5d1d34b5a,contentkey:GX8m9XLIZNIzizrl0RTqnA==,sl:150)';
105
92
  drmEngine.configure(config);
106
93
 
107
94
  manifest = shaka.test.ManifestGenerator.generate((manifest) => {
108
95
  manifest.addVariant(0, (variant) => {
109
96
  variant.addVideo(1, (stream) => {
110
97
  stream.encrypted = true;
111
- stream.addDrmInfo('com.widevine.alpha');
112
98
  stream.addDrmInfo('com.microsoft.playready');
99
+ stream.addDrmInfo('com.widevine.alpha');
113
100
  });
114
101
  variant.addAudio(2, (stream) => {
115
102
  stream.encrypted = true;
116
- stream.addDrmInfo('com.widevine.alpha');
117
103
  stream.addDrmInfo('com.microsoft.playready');
104
+ stream.addDrmInfo('com.widevine.alpha');
118
105
  });
119
106
  });
120
107
  });
@@ -3297,7 +3297,12 @@ describe('StreamingEngine', () => {
3297
3297
  netEngine.request.and.callFake((requestType, request) => {
3298
3298
  const buffer = new ArrayBuffer(0);
3299
3299
  /** @type {shaka.extern.Response} */
3300
- const response = {uri: request.uris[0], data: buffer, headers: {}};
3300
+ const response = {
3301
+ uri: request.uris[0],
3302
+ originalUri: request.uris[0],
3303
+ data: buffer,
3304
+ headers: {},
3305
+ };
3301
3306
  return shaka.util.AbortableOperation.completed(response);
3302
3307
  });
3303
3308
 
@@ -1226,6 +1226,11 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ () => {
1226
1226
 
1227
1227
  /** @return {shaka.extern.Response} */
1228
1228
  function createResponse() {
1229
- return {uri: '', data: new ArrayBuffer(5), headers: {}};
1229
+ return {
1230
+ uri: '',
1231
+ originalUri: '',
1232
+ data: new ArrayBuffer(5),
1233
+ headers: {},
1234
+ };
1230
1235
  }
1231
1236
  }); // describe('NetworkingEngine')
@@ -401,6 +401,45 @@ describe('Player', () => {
401
401
  player.setTextTrackVisibility(true);
402
402
  expect(getTracksActive()).toEqual([false, true]);
403
403
  });
404
+
405
+ // https://github.com/shaka-project/shaka-player/issues/4821
406
+ it('loads a single text stream', async () => {
407
+ player.configure({preferredTextLanguage: 'en'});
408
+ await player.load('test:sintel_no_text_compiled');
409
+
410
+ // Add preferred language text track.
411
+ const locationUri = new goog.Uri(location.href);
412
+ const partialUri = new goog.Uri('/base/test/test/assets/text-clip.vtt');
413
+ const absoluteUri = locationUri.resolve(partialUri);
414
+ await player.addTextTrackAsync(
415
+ absoluteUri.toString(), 'en', 'subtitles', 'text/vtt');
416
+
417
+ // Add alternate language text track.
418
+ // Two text tracks with same timings but different text
419
+ // are necessary for test.
420
+ const partialUri2 =
421
+ new goog.Uri('/base/test/test/assets/text-clip-alt.vtt');
422
+ const absoluteUri2 = locationUri.resolve(partialUri2);
423
+ await player.addTextTrackAsync(
424
+ absoluteUri2.toString(), 'fr', 'subtitles', 'text/vtt');
425
+
426
+ const textTracks = player.getTextTracks();
427
+ expect(textTracks.length).toBe(2);
428
+ expect(textTracks[0].language).toBe('en');
429
+ expect(textTracks[1].language).toBe('fr');
430
+
431
+ // Enable text visibilty and immediately change language.
432
+ // Only one set of cues should be active.
433
+ // Cues should be of the selected language track.
434
+ player.setTextTrackVisibility(true);
435
+ player.selectTextLanguage('fr');
436
+ video.currentTime = 5;
437
+ video.play();
438
+ await waiter.waitForMovementOrFailOnTimeout(video, 10);
439
+
440
+ expect(video.textTracks[0].activeCues.length).toBe(1);
441
+ expect(player.getTextTracks()[1].active).toBe(true);
442
+ });
404
443
  }); // describe('setTextTrackVisibility')
405
444
 
406
445
  describe('plays', () => {
@@ -205,6 +205,7 @@ describe('Player', () => {
205
205
  await player.destroy();
206
206
 
207
207
  expect(abrManager.stop).toHaveBeenCalled();
208
+ expect(abrManager.release).toHaveBeenCalled();
208
209
  expect(networkingEngine.destroy).toHaveBeenCalled();
209
210
  expect(drmEngine.destroy).toHaveBeenCalled();
210
211
  expect(playhead.release).toHaveBeenCalled();
@@ -243,6 +244,7 @@ describe('Player', () => {
243
244
  parser.start.and.returnValue(p);
244
245
  parser.stop.and.callFake(() => {
245
246
  expect(abrManager.stop).not.toHaveBeenCalled();
247
+ expect(abrManager.release).not.toHaveBeenCalled();
246
248
  expect(networkingEngine.destroy).not.toHaveBeenCalled();
247
249
  });
248
250
  shaka.media.ManifestParser.registerParserByMime(
@@ -252,6 +254,7 @@ describe('Player', () => {
252
254
  await shaka.test.Util.shortDelay();
253
255
  await player.destroy();
254
256
  expect(abrManager.stop).toHaveBeenCalled();
257
+ expect(abrManager.release).toHaveBeenCalled();
255
258
  expect(networkingEngine.destroy).toHaveBeenCalled();
256
259
  expect(parser.stop).toHaveBeenCalled();
257
260
  await expectAsync(load).toBeRejected();
@@ -551,6 +554,60 @@ describe('Player', () => {
551
554
  expect(streamingEngine.unloadTextStream).not.toHaveBeenCalled();
552
555
  });
553
556
  });
557
+
558
+ describe('when config.streaming.preferNativeHls is set to true', () => {
559
+ beforeEach(() => {
560
+ shaka.media.ManifestParser.registerParserByMime(
561
+ 'application/x-mpegurl',
562
+ () => new shaka.test.FakeManifestParser(manifest));
563
+ });
564
+
565
+ afterEach(() => {
566
+ shaka.media.ManifestParser.unregisterParserByMime(
567
+ 'application/x-mpegurl');
568
+ video.canPlayType.calls.reset();
569
+ });
570
+
571
+ it('only applies to HLS streams', async () => {
572
+ video.canPlayType.and.returnValue('maybe');
573
+ spyOn(shaka.util.Platform, 'anyMediaElement').and.returnValue(video);
574
+ spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
575
+ spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);
576
+ // Make sure player.load() resolves for src=
577
+ spyOn(shaka.util.MediaReadyState, 'waitForReadyState').and.callFake(
578
+ (mediaElement, readyState, eventManager, callback) => {
579
+ callback();
580
+ });
581
+
582
+ player.configure({
583
+ streaming: {
584
+ preferNativeHls: true,
585
+ useNativeHlsOnSafari: false,
586
+ },
587
+ });
588
+
589
+ await player.load(fakeManifestUri, undefined, 'application/x-mpegurl');
590
+
591
+ expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.SRC_EQUALS);
592
+ });
593
+
594
+ it('does not apply to non-HLS streams', async () => {
595
+ video.canPlayType.and.returnValue('maybe');
596
+ spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
597
+ spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);
598
+
599
+ player.configure({
600
+ streaming: {
601
+ preferNativeHls: true,
602
+ useNativeHlsOnSafari: false,
603
+ },
604
+ });
605
+
606
+ await player.load(fakeManifestUri, 0, fakeMimeType);
607
+
608
+ expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.MEDIA_SOURCE);
609
+ });
610
+ });
554
611
  }); // describe('load/unload')
555
612
 
556
613
  describe('getConfiguration', () => {
@@ -67,7 +67,6 @@ describe('MediaCapabilities', () => {
67
67
  width: 512,
68
68
  },
69
69
  };
70
- shaka.polyfill.MediaCapabilities.memoizedMediaKeySystemAccessRequests_ = {};
71
70
 
72
71
  mockCanDisplayType = jasmine.createSpy('canDisplayType');
73
72
  mockCanDisplayType.and.returnValue(false);