shaka-player 4.7.1 → 4.7.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.
@@ -13,27 +13,35 @@
13
13
  /**
14
14
  * @typedef {{
15
15
  * Utils: !ISOBoxerUtils,
16
- * parseBuffer: function(!(ArrayBuffer|ArrayBufferView)):!ISOBoxer,
16
+ * parseBuffer: function(!(ArrayBuffer|ArrayBufferView)):!ISOFile,
17
17
  * createBox: function(string, !ISOBoxer, boolean=):!ISOBoxer,
18
18
  * createFullBox: function(string, !ISOBoxer, ?ISOBoxer=):!ISOBoxer,
19
19
  * addBoxProcessor: function(string, function()):!ISOBoxer,
20
- * createFile: function():!ISOBoxer,
21
- * write: function():!ArrayBuffer,
22
- * fetch: function(!ArrayBuffer):!ISOBoxer
20
+ * createFile: function():!ISOFile,
23
21
  * }}
24
22
  * @property {!ISOBoxerUtils} Utils
25
- * @property {function(!(ArrayBuffer|ArrayBufferView)):!ISOBoxer} parseBuffer
23
+ * @property {function(!(ArrayBuffer|ArrayBufferView)):!ISOFile} parseBuffer
26
24
  * @property {function(string, !ISOBoxer, boolean=):!ISOBoxer} createBox
27
25
  * @property {function(string, !ISOBoxer, ?ISOBoxer=):!ISOBoxer} createFullBox
28
26
  * @property {function(string, function()):!ISOBoxer} addBoxProcessor
29
- * @property {function():!ISOBoxer} createFile
30
- * @property {function():!ArrayBuffer} write
31
- * @property {function(!ArrayBuffer):!ISOBoxer} fetch
27
+ * @property {function():!ISOFile} createFile
32
28
  * @const
33
29
  */
34
30
  var ISOBoxer;
35
31
 
36
32
 
33
+ /**
34
+ * @typedef {{
35
+ * write: function():!ArrayBuffer,
36
+ * fetch: function(string):!ISOBox
37
+ * }}
38
+ * @property {function():!ArrayBuffer} write
39
+ * @property {function(string):!ISOBox} fetch
40
+ * @const
41
+ */
42
+ var ISOFile;
43
+
44
+
37
45
  /**
38
46
  * @typedef {{
39
47
  * appendBox: function(!ISOBoxer, !ISOBoxer):!ISOBox
@@ -91,7 +99,7 @@ var ISOBoxerUtils;
91
99
  * graphicsmode: number,
92
100
  * opcolor: Array.<number>,
93
101
  * balance: number,
94
- * entries: Array.<!ISOBox>,
102
+ * entries: Array.<!ISOEntry>,
95
103
  * location: string,
96
104
  * data_reference_index: number,
97
105
  * pre_defined1: number,
@@ -119,7 +127,7 @@ var ISOBoxerUtils;
119
127
  * default_sample_size: number,
120
128
  * default_sample_flags: number,
121
129
  * baseMediaDecodeTime: number,
122
- * usertype: ?string,
130
+ * usertype: (string|null|undefined),
123
131
  * offset: Array.<number>,
124
132
  * sample_info_size: Array.<number>,
125
133
  * data_offset: number
@@ -170,7 +178,7 @@ var ISOBoxerUtils;
170
178
  * @property {number} graphicsmode
171
179
  * @property {Array.<number>} opcolor
172
180
  * @property {number} balance
173
- * @property {Array.<!ISOBox} entries
181
+ * @property {Array.<!ISOEntry>} entries
174
182
  * @property {string} location
175
183
  * @property {number} data_reference_index
176
184
  * @property {number} pre_defined1
@@ -198,7 +206,7 @@ var ISOBoxerUtils;
198
206
  * @property {number} default_sample_size
199
207
  * @property {number} default_sample_flags
200
208
  * @property {number} baseMediaDecodeTime
201
- * @property {?string} usertype
209
+ * @property {string|null|undefined} usertype
202
210
  * @property {Array.<number} offset
203
211
  * @property {Array.<number} sample_info_size
204
212
  * @property {number} data_offset
@@ -4,6 +4,10 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
+ /**
8
+ * @externs
9
+ */
10
+
7
11
  /**
8
12
  * @typedef {{
9
13
  * data: !Uint8Array,
@@ -207,6 +207,15 @@ shaka.ads.ClientSideAd = class {
207
207
  }
208
208
  }
209
209
 
210
+ /**
211
+ * It's required for a muted ad to start when autoplaying.
212
+ *
213
+ * @param {number} videoVolume
214
+ */
215
+ setInitialMuted(videoVolume) {
216
+ this.volume_ = videoVolume;
217
+ this.manager_.setVolume(0);
218
+ }
210
219
 
211
220
  /**
212
221
  * @override
@@ -532,9 +532,10 @@ shaka.ads.ClientSideAdManager = class {
532
532
  if (this.ad_.isLinear()) {
533
533
  this.adContainer_.setAttribute('ad-active', 'true');
534
534
  this.video_.pause();
535
- this.ad_.setVolume(this.video_.volume);
536
535
  if (this.video_.muted) {
537
- this.ad_.setMuted(true);
536
+ this.ad_.setInitialMuted(this.video_.volume);
537
+ } else {
538
+ this.ad_.setVolume(this.video_.volume);
538
539
  }
539
540
  }
540
541
  }
@@ -576,8 +576,9 @@ shaka.ads.MediaTailorAdManager = class {
576
576
  if (!app.data.source.length) {
577
577
  continue;
578
578
  }
579
- const imageElement = document.createElement('img');
580
- imageElement.setAttribute('src', app.data.source[0].url);
579
+ const imageElement = /** @type {!HTMLImageElement} */ (
580
+ document.createElement('img'));
581
+ imageElement.src = app.data.source[0].url;
581
582
  imageElement.style.top = (app.placeholder.top || 0) + '%';
582
583
  imageElement.style.height = (100 - (app.placeholder.top || 0)) + '%';
583
584
  imageElement.style.left = (app.placeholder.left || 0) + '%';
@@ -136,9 +136,11 @@ shaka.dash.DashParser = class {
136
136
  this.contentSteeringManager_.configure(this.config_);
137
137
  }
138
138
 
139
- this.periodCombiner_.setAllowMultiTypeVariants(
140
- this.config_.dash.multiTypeVariantsAllowed &&
141
- shaka.media.Capabilities.isChangeTypeSupported());
139
+ if (this.periodCombiner_) {
140
+ this.periodCombiner_.setAllowMultiTypeVariants(
141
+ this.config_.dash.multiTypeVariantsAllowed &&
142
+ shaka.media.Capabilities.isChangeTypeSupported());
143
+ }
142
144
  }
143
145
 
144
146
  /**
@@ -1607,7 +1609,6 @@ shaka.dash.DashParser = class {
1607
1609
  hdr,
1608
1610
  videoLayout: undefined,
1609
1611
  tilesLayout,
1610
- matchedStreams: [],
1611
1612
  accessibilityPurpose,
1612
1613
  external: false,
1613
1614
  fastSwitching: false,
@@ -295,6 +295,7 @@ shaka.hls.HlsParser = class {
295
295
  this.groupIdToStreamInfosMap_.clear();
296
296
  this.groupIdToCodecsMap_.clear();
297
297
  this.globalVariables_.clear();
298
+ this.mapTagToInitSegmentRefMap_.clear();
298
299
 
299
300
  if (this.contentSteeringManager_) {
300
301
  this.contentSteeringManager_.destroy();
@@ -905,6 +906,7 @@ shaka.hls.HlsParser = class {
905
906
  let initData = null;
906
907
  const initSegmentRef = this.getInitSegmentReference_(
907
908
  playlist, middleSegment.tags, getUris);
909
+ this.mapTagToInitSegmentRefMap_.clear();
908
910
  if (initSegmentRef) {
909
911
  const initSegmentRequest = shaka.net.NetworkingEngine.makeRequest(
910
912
  initSegmentRef.getUris(), this.config_.retryParameters);
@@ -2235,7 +2237,7 @@ shaka.hls.HlsParser = class {
2235
2237
  stream.keyIds = realStream.keyIds;
2236
2238
  stream.mimeType = realStream.mimeType;
2237
2239
  stream.bandwidth = realStream.bandwidth;
2238
- stream.codecs = realStream.codecs || stream.codecs;
2240
+ stream.codecs = stream.codecs || realStream.codecs;
2239
2241
 
2240
2242
  // Since we lazy-loaded this content, the player may need to create new
2241
2243
  // sessions for the DRM info in this stream.
@@ -3450,6 +3452,13 @@ shaka.hls.HlsParser = class {
3450
3452
  if (this.isLive_() && mediaSequenceToStartTime.has(position)) {
3451
3453
  firstStartTime = mediaSequenceToStartTime.get(position);
3452
3454
  }
3455
+ // This is for recovering from disconnects.
3456
+ if (firstStartTime === 0 &&
3457
+ this.presentationType_ == shaka.hls.HlsParser.PresentationType_.LIVE &&
3458
+ mediaSequenceToStartTime.size > 0 &&
3459
+ !mediaSequenceToStartTime.has(position)) {
3460
+ firstStartTime = this.presentationTimeline_.getSegmentAvailabilityStart();
3461
+ }
3453
3462
 
3454
3463
  /** @type {!Array.<!shaka.media.SegmentReference>} */
3455
3464
  const references = [];
@@ -3764,7 +3773,9 @@ shaka.hls.HlsParser = class {
3764
3773
 
3765
3774
  contentMimeType = response.headers['content-type'];
3766
3775
  } catch (error) {
3767
- if (error && error.code == shaka.util.Error.Code.HTTP_ERROR) {
3776
+ if (error &&
3777
+ (error.code == shaka.util.Error.Code.HTTP_ERROR ||
3778
+ error.code == shaka.util.Error.Code.BAD_HTTP_STATUS)) {
3768
3779
  headRequest.method = 'GET';
3769
3780
  const response = await this.makeNetworkRequest_(
3770
3781
  headRequest, requestType, {type});
@@ -460,9 +460,10 @@ shaka.media.MediaSourceEngine = class {
460
460
  * @param {shaka.util.ManifestParserUtils.ContentType} contentType
461
461
  * @param {shaka.extern.Stream} stream
462
462
  * @param {string} codecs
463
+ * @param {boolean=} forceTransmux
463
464
  * @private
464
465
  */
465
- initSourceBuffer_(contentType, stream, codecs) {
466
+ initSourceBuffer_(contentType, stream, codecs, forceTransmux = false) {
466
467
  const ContentType = shaka.util.ManifestParserUtils.ContentType;
467
468
 
468
469
  goog.asserts.assert(
@@ -474,7 +475,7 @@ shaka.media.MediaSourceEngine = class {
474
475
  if (contentType == ContentType.TEXT) {
475
476
  this.reinitText(mimeType, this.sequenceMode_, stream.external);
476
477
  } else {
477
- let needTransmux = this.config_.forceTransmux;
478
+ let needTransmux = this.config_.forceTransmux || forceTransmux;
478
479
  if (!shaka.media.Capabilities.isTypeSupported(mimeType) ||
479
480
  (!this.sequenceMode_ &&
480
481
  shaka.util.MimeUtils.RAW_FORMATS.includes(mimeType))) {
@@ -491,8 +492,10 @@ shaka.media.MediaSourceEngine = class {
491
492
  ContentType.VIDEO, (codecs || '').split(','));
492
493
  if (audioCodec && videoCodec) {
493
494
  this.needSplitMuxedContent_ = true;
494
- this.initSourceBuffer_(ContentType.AUDIO, stream, audioCodec);
495
- this.initSourceBuffer_(ContentType.VIDEO, stream, videoCodec);
495
+ this.initSourceBuffer_(
496
+ ContentType.AUDIO, stream, audioCodec, /* forceTransmux= */ true);
497
+ this.initSourceBuffer_(
498
+ ContentType.VIDEO, stream, videoCodec, /* forceTransmux= */ true);
496
499
  return;
497
500
  }
498
501
  const transmuxerPlugin =
@@ -1854,7 +1857,8 @@ shaka.media.MediaSourceEngine = class {
1854
1857
  let needTransmux = this.config_.forceTransmux;
1855
1858
  if (!shaka.media.Capabilities.isTypeSupported(newMimeType) ||
1856
1859
  (!this.sequenceMode_ &&
1857
- shaka.util.MimeUtils.RAW_FORMATS.includes(newMimeType))) {
1860
+ shaka.util.MimeUtils.RAW_FORMATS.includes(newMimeType)) ||
1861
+ codecs.includes(',')) {
1858
1862
  needTransmux = true;
1859
1863
  }
1860
1864
  const TransmuxerEngine = shaka.transmuxer.TransmuxerEngine;
@@ -1935,7 +1939,8 @@ shaka.media.MediaSourceEngine = class {
1935
1939
  let needTransmux = this.config_.forceTransmux;
1936
1940
  if (!shaka.media.Capabilities.isTypeSupported(newMimeType) ||
1937
1941
  (!this.sequenceMode_ &&
1938
- shaka.util.MimeUtils.RAW_FORMATS.includes(newMimeType))) {
1942
+ shaka.util.MimeUtils.RAW_FORMATS.includes(newMimeType)) ||
1943
+ stream.codecs.includes(',')) {
1939
1944
  needTransmux = true;
1940
1945
  }
1941
1946
  const newMimeTypeWithAllCodecs =
@@ -165,12 +165,12 @@ shaka.media.SegmentPrefetch = class {
165
165
  if (reference instanceof shaka.media.SegmentReference) {
166
166
  shaka.log.debug(
167
167
  logPrefix,
168
- 'reused prefetched segment at time:', reference.startTime,
168
+ 'missed segment at time:', reference.startTime,
169
169
  'mapSize', this.segmentPrefetchMap_.size);
170
170
  } else {
171
171
  shaka.log.debug(
172
172
  logPrefix,
173
- 'reused prefetched init segment at time, mapSize',
173
+ 'missed init segment at time, mapSize',
174
174
  this.segmentPrefetchMap_.size);
175
175
  }
176
176
  return null;
@@ -37,7 +37,9 @@ shaka.net.NetworkingUtils = class {
37
37
  const response = await netEngine.request(type, request).promise;
38
38
  mimeType = response.headers['content-type'];
39
39
  } catch (error) {
40
- if (error && error.code == shaka.util.Error.Code.HTTP_ERROR) {
40
+ if (error &&
41
+ (error.code == shaka.util.Error.Code.HTTP_ERROR ||
42
+ error.code == shaka.util.Error.Code.BAD_HTTP_STATUS)) {
41
43
  request.method = 'GET';
42
44
  const response = await netEngine.request(type, request).promise;
43
45
  mimeType = response.headers['content-type'];
package/lib/player.js CHANGED
@@ -6865,7 +6865,7 @@ shaka.Player.TYPICAL_BUFFERING_THRESHOLD_ = 0.5;
6865
6865
  * @export
6866
6866
  */
6867
6867
  // eslint-disable-next-line no-useless-concat
6868
- shaka.Player.version = 'v4.7.1' + '-uncompiled'; // x-release-please-version
6868
+ shaka.Player.version = 'v4.7.3' + '-uncompiled'; // x-release-please-version
6869
6869
 
6870
6870
  // Initialize the deprecation system using the version string we just set
6871
6871
  // on the player.
@@ -791,3 +791,9 @@ shaka.polyfill.PatchedMediaKeysApple.MediaKeyStatusMap = class {
791
791
  goog.asserts.assert(false, 'Not used! Provided only for the compiler.');
792
792
  }
793
793
  };
794
+
795
+ if (!navigator.requestMediaKeySystemAccess ||
796
+ // eslint-disable-next-line no-restricted-syntax
797
+ !MediaKeySystemAccess.prototype.getConfiguration) {
798
+ shaka.polyfill.register(shaka.polyfill.PatchedMediaKeysApple.install);
799
+ }
@@ -154,6 +154,11 @@ shaka.text.UITextDisplayer = class {
154
154
  * @export
155
155
  */
156
156
  destroy() {
157
+ // Return resolved promise if destroy() has been called.
158
+ if (!this.textContainer_) {
159
+ return Promise.resolve();
160
+ }
161
+
157
162
  // Remove the text container element from the UI.
158
163
  this.videoContainer_.removeChild(this.textContainer_);
159
164
  this.textContainer_ = null;
@@ -176,6 +181,8 @@ shaka.text.UITextDisplayer = class {
176
181
  this.resizeObserver_.disconnect();
177
182
  this.resizeObserver_ = null;
178
183
  }
184
+
185
+ return Promise.resolve();
179
186
  }
180
187
 
181
188
 
@@ -253,6 +253,7 @@ shaka.transmuxer.MssTransmuxer = class {
253
253
  */
254
254
  processMediaSegment_(data, stream, reference) {
255
255
  let i;
256
+ /** @type {!ISOFile} */
256
257
  const isoFile = this.isoBoxer_.parseBuffer(data);
257
258
  // Update track_Id in tfhd box
258
259
  const tfhd = isoFile.fetch('tfhd');
@@ -313,8 +314,8 @@ shaka.transmuxer.MssTransmuxer = class {
313
314
  // (subsample_count field size)
314
315
  // 6 = 2 (BytesOfClearData field size) + 4
315
316
  // (BytesOfEncryptedData field size)
316
- saiz.sample_info_size[i] =
317
- 10 + (6 * sepiff.entry[i].NumberOfEntries);
317
+ const entry = /** @type {!ISOEntry} */ (sepiff.entry[i]);
318
+ saiz.sample_info_size[i] = 10 + (6 * entry.NumberOfEntries);
318
319
  }
319
320
  } else {
320
321
  // No sub-sample encryption => set default
@@ -705,7 +705,7 @@ shaka.transmuxer.TsTransmuxer = class {
705
705
  /** @type {?number} */
706
706
  let baseMediaDecodeTime = null;
707
707
 
708
- let nalus = [];
708
+ const nalus = [];
709
709
  const videoData = tsParser.getVideoData();
710
710
  if (!videoData.length) {
711
711
  throw new shaka.util.Error(
@@ -716,7 +716,7 @@ shaka.transmuxer.TsTransmuxer = class {
716
716
  for (let i = 0; i < videoData.length; i++) {
717
717
  const pes = videoData[i];
718
718
  const dataNalus = pes.nalus;
719
- nalus = nalus.concat(dataNalus);
719
+ nalus.push(...dataNalus);
720
720
  const frame = H264.parseFrame(dataNalus);
721
721
  if (!frame) {
722
722
  continue;
@@ -797,7 +797,7 @@ shaka.transmuxer.TsTransmuxer = class {
797
797
  /** @type {?number} */
798
798
  let baseMediaDecodeTime = null;
799
799
 
800
- let nalus = [];
800
+ const nalus = [];
801
801
  const videoData = tsParser.getVideoData();
802
802
  if (!videoData.length) {
803
803
  throw new shaka.util.Error(
@@ -808,7 +808,7 @@ shaka.transmuxer.TsTransmuxer = class {
808
808
  for (let i = 0; i < videoData.length; i++) {
809
809
  const pes = videoData[i];
810
810
  const dataNalus = pes.nalus;
811
- nalus = nalus.concat(dataNalus);
811
+ nalus.push(...dataNalus);
812
812
  const frame = H265.parseFrame(dataNalus);
813
813
  if (!frame) {
814
814
  continue;
@@ -47,10 +47,11 @@ shaka.util.Mp4Generator = class {
47
47
  goog.asserts.assert(this.streamInfos_.length > 0,
48
48
  'StreamInfos must have elements');
49
49
  const Mp4Generator = shaka.util.Mp4Generator;
50
- let traks = new Uint8Array([]);
50
+ const trakArrays = [];
51
51
  for (const streamInfo of this.streamInfos_) {
52
- traks = shaka.util.Uint8ArrayUtils.concat(traks, this.trak_(streamInfo));
52
+ trakArrays.push(this.trak_(streamInfo));
53
53
  }
54
+ const traks = shaka.util.Uint8ArrayUtils.concat(...trakArrays);
54
55
  const firstStreamInfo = this.streamInfos_[0];
55
56
  return Mp4Generator.box('moov',
56
57
  this.mvhd_(firstStreamInfo),
@@ -693,10 +694,11 @@ shaka.util.Mp4Generator = class {
693
694
  */
694
695
  mvex_() {
695
696
  const Mp4Generator = shaka.util.Mp4Generator;
696
- let trexs = new Uint8Array([]);
697
+ const trexArrays = [];
697
698
  for (const streamInfo of this.streamInfos_) {
698
- trexs = shaka.util.Uint8ArrayUtils.concat(trexs, this.trex_(streamInfo));
699
+ trexArrays.push(this.trex_(streamInfo));
699
700
  }
701
+ const trexs = shaka.util.Uint8ArrayUtils.concat(...trexArrays);
700
702
  return Mp4Generator.box('mvex', trexs);
701
703
  }
702
704
 
@@ -730,9 +732,9 @@ shaka.util.Mp4Generator = class {
730
732
  * @private
731
733
  */
732
734
  pssh_(streamInfo) {
733
- let boxes = new Uint8Array([]);
735
+ const initDatas = [];
734
736
  if (!streamInfo.encrypted) {
735
- return boxes;
737
+ return new Uint8Array([]);
736
738
  }
737
739
 
738
740
  for (const drmInfo of streamInfo.stream.drmInfos) {
@@ -740,9 +742,10 @@ shaka.util.Mp4Generator = class {
740
742
  continue;
741
743
  }
742
744
  for (const initData of drmInfo.initData) {
743
- boxes = shaka.util.Uint8ArrayUtils.concat(boxes, initData.initData);
745
+ initDatas.push(initData.initData);
744
746
  }
745
747
  }
748
+ const boxes = shaka.util.Uint8ArrayUtils.concat(...initDatas);
746
749
  return boxes;
747
750
  }
748
751
 
@@ -845,11 +848,12 @@ shaka.util.Mp4Generator = class {
845
848
  * @return {!Uint8Array}
846
849
  */
847
850
  segmentData() {
848
- let result = new Uint8Array([]);
851
+ const segmentDataArray = [];
849
852
  for (const streamInfo of this.streamInfos_) {
850
- result = shaka.util.Uint8ArrayUtils.concat(result,
851
- this.moof_(streamInfo), this.mdat_(streamInfo));
853
+ segmentDataArray.push(
854
+ ...[this.moof_(streamInfo), this.mdat_(streamInfo)]);
852
855
  }
856
+ const result = shaka.util.Uint8ArrayUtils.concat(...segmentDataArray);
853
857
  return result;
854
858
  }
855
859