shaka-player 4.12.4 → 4.12.5

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.
@@ -1505,6 +1505,9 @@ shaka.dash.DashParser = class {
1505
1505
  let shouldDeleteIndex = true;
1506
1506
  for (const contextId of this.indexStreamMap_[pId]) {
1507
1507
  const stream = this.streamMap_[contextId];
1508
+ if (!stream) {
1509
+ continue;
1510
+ }
1508
1511
  if (stream.segmentIndex && !stream.segmentIndex.isEmpty()) {
1509
1512
  shouldDeleteIndex = false;
1510
1513
  continue;
@@ -928,14 +928,16 @@ shaka.media.DrmEngine = class {
928
928
  'Got MediaKeySystemAccess with configuration',
929
929
  realConfig);
930
930
 
931
+ const keySystem =
932
+ this.config_.keySystemsMapping[mediaKeySystemAccess.keySystem] ||
933
+ mediaKeySystemAccess.keySystem;
934
+
931
935
  if (variants.length) {
932
936
  this.currentDrmInfo_ = this.createDrmInfoByInfos_(
933
- mediaKeySystemAccess.keySystem,
934
- drmInfosByKeySystem.get(mediaKeySystemAccess.keySystem));
937
+ keySystem, drmInfosByKeySystem.get(keySystem));
935
938
  } else {
936
939
  this.currentDrmInfo_ = shaka.media.DrmEngine.createDrmInfoByConfigs_(
937
- mediaKeySystemAccess.keySystem,
938
- configsByKeySystem.get(mediaKeySystemAccess.keySystem));
940
+ keySystem, configsByKeySystem.get(keySystem));
939
941
  }
940
942
  if (!this.currentDrmInfo_.licenseServerUri) {
941
943
  throw new shaka.util.Error(
@@ -1050,8 +1052,12 @@ shaka.media.DrmEngine = class {
1050
1052
  if (!decodingInfo.supported || !decodingInfo.keySystemAccess) {
1051
1053
  continue;
1052
1054
  }
1053
- const drmInfos =
1054
- drmInfosByKeySystem.get(decodingInfo.keySystemAccess.keySystem);
1055
+ const originalKeySystem = decodingInfo.keySystemAccess.keySystem;
1056
+ let drmInfos = drmInfosByKeySystem.get(originalKeySystem);
1057
+ if (!drmInfos && this.config_.keySystemsMapping[originalKeySystem]) {
1058
+ drmInfos = drmInfosByKeySystem.get(
1059
+ this.config_.keySystemsMapping[originalKeySystem]);
1060
+ }
1055
1061
  for (const info of drmInfos) {
1056
1062
  if (!!info.licenseServerUri == shouldHaveLicenseServer) {
1057
1063
  return decodingInfo.keySystemAccess;
@@ -2001,18 +2007,10 @@ shaka.media.DrmEngine = class {
2001
2007
  * @private
2002
2008
  */
2003
2009
  async closeSession_(session) {
2004
- const DrmEngine = shaka.media.DrmEngine;
2005
-
2006
- const timeout = new Promise((resolve, reject) => {
2007
- const timer = new shaka.util.Timer(reject);
2008
- timer.tickAfter(DrmEngine.CLOSE_TIMEOUT_);
2009
- });
2010
-
2011
2010
  try {
2012
- await Promise.race([
2013
- Promise.all([session.close(), session.closed]),
2014
- timeout,
2015
- ]);
2011
+ await shaka.util.Functional.promiseWithTimeout(
2012
+ shaka.media.DrmEngine.CLOSE_TIMEOUT_,
2013
+ Promise.all([session.close(), session.closed]));
2016
2014
  } catch (e) {
2017
2015
  shaka.log.warning('Timeout waiting for session close');
2018
2016
  }
@@ -50,7 +50,8 @@ shaka.media.ManifestFilterer = class {
50
50
  async filterManifest(manifest) {
51
51
  goog.asserts.assert(manifest, 'Manifest should exist!');
52
52
  await shaka.util.StreamUtils.filterManifest(this.drmEngine_, manifest,
53
- this.config_.drm.preferredKeySystems);
53
+ this.config_.drm.preferredKeySystems,
54
+ this.config_.drm.keySystemsMapping);
54
55
  if (!this.config_.streaming.dontChooseCodecs) {
55
56
  shaka.util.StreamUtils.chooseCodecsAndFilterManifest(
56
57
  manifest,
@@ -466,12 +466,12 @@ shaka.media.MediaSourceEngine = class {
466
466
  cleanup.push(this.textEngine_.destroy());
467
467
  }
468
468
 
469
+ await Promise.all(cleanup);
470
+
469
471
  for (const contentType in this.transmuxers_) {
470
- cleanup.push(this.transmuxers_[contentType].destroy());
472
+ this.transmuxers_[contentType].destroy();
471
473
  }
472
474
 
473
-
474
- await Promise.all(cleanup);
475
475
  if (this.eventManager_) {
476
476
  this.eventManager_.release();
477
477
  this.eventManager_ = null;
@@ -692,7 +692,8 @@ shaka.media.MediaSourceEngine = class {
692
692
  * @return {boolean}
693
693
  */
694
694
  isStreamingAllowed() {
695
- return this.streamingAllowed_ && !this.usingRemotePlayback_;
695
+ return this.streamingAllowed_ && !this.usingRemotePlayback_ &&
696
+ !this.reloadingMediaSource_;
696
697
  }
697
698
 
698
699
  /**
@@ -1859,11 +1860,13 @@ shaka.media.MediaSourceEngine = class {
1859
1860
 
1860
1861
  /** @type {!Array.<!shaka.util.PublicPromise>} */
1861
1862
  const allWaiters = [];
1863
+ /** @type {!Array.<!shaka.util.ManifestParserUtils.ContentType>} */
1864
+ const contentTypes = Object.keys(this.sourceBuffers_);
1862
1865
 
1863
1866
  // Enqueue a 'wait' operation onto each queue.
1864
1867
  // This operation signals its readiness when it starts.
1865
1868
  // When all wait operations are ready, the real operation takes place.
1866
- for (const contentType in this.sourceBuffers_) {
1869
+ for (const contentType of contentTypes) {
1867
1870
  const ready = new shaka.util.PublicPromise();
1868
1871
  const operation = {
1869
1872
  start: () => ready.resolve(),
@@ -1893,7 +1896,7 @@ shaka.media.MediaSourceEngine = class {
1893
1896
  // assert at the end of destroy passes. In compiled mode, the queues
1894
1897
  // are wiped in destroy.
1895
1898
  if (goog.DEBUG) {
1896
- for (const contentType in this.sourceBuffers_) {
1899
+ for (const contentType of contentTypes) {
1897
1900
  if (this.queues_[contentType].length) {
1898
1901
  goog.asserts.assert(
1899
1902
  this.queues_[contentType].length == 1,
@@ -1910,7 +1913,7 @@ shaka.media.MediaSourceEngine = class {
1910
1913
 
1911
1914
  if (goog.DEBUG) {
1912
1915
  // If we did it correctly, nothing is updating.
1913
- for (const contentType in this.sourceBuffers_) {
1916
+ for (const contentType of contentTypes) {
1914
1917
  goog.asserts.assert(
1915
1918
  this.sourceBuffers_[contentType].updating == false,
1916
1919
  'SourceBuffers should not be updating after a blocking op!');
@@ -1930,7 +1933,7 @@ shaka.media.MediaSourceEngine = class {
1930
1933
  null);
1931
1934
  } finally {
1932
1935
  // Unblock the queues.
1933
- for (const contentType in this.sourceBuffers_) {
1936
+ for (const contentType of contentTypes) {
1934
1937
  this.popFromQueue_(contentType);
1935
1938
  }
1936
1939
  }
@@ -1942,6 +1945,7 @@ shaka.media.MediaSourceEngine = class {
1942
1945
  * @private
1943
1946
  */
1944
1947
  popFromQueue_(contentType) {
1948
+ goog.asserts.assert(this.queues_[contentType], 'Queue should exist');
1945
1949
  // Remove the in-progress operation, which is now complete.
1946
1950
  this.queues_[contentType].shift();
1947
1951
  this.startOperation_(contentType);
@@ -2099,48 +2103,6 @@ shaka.media.MediaSourceEngine = class {
2099
2103
  null);
2100
2104
  }
2101
2105
 
2102
- /**
2103
- * Returns the source buffer parameters
2104
- * @param {shaka.util.ManifestParserUtils.ContentType} contentType
2105
- * @return {?shaka.media.MediaSourceEngine.SourceBufferParams}
2106
- * @private
2107
- */
2108
- getSourceBufferParams_(contentType) {
2109
- if (!this.sourceBuffers_[contentType]) {
2110
- return null;
2111
- }
2112
- return {
2113
- timestampOffset: this.sourceBuffers_[contentType].timestampOffset,
2114
- appendWindowStart: this.sourceBuffers_[contentType].appendWindowStart,
2115
- appendWindowEnd: this.sourceBuffers_[contentType].appendWindowEnd,
2116
- };
2117
- }
2118
-
2119
- /**
2120
- * Restore source buffer parameters
2121
- * @param {shaka.util.ManifestParserUtils.ContentType} contentType
2122
- * @param {?shaka.media.MediaSourceEngine.SourceBufferParams} params
2123
- * @private
2124
- */
2125
- restoreSourceBufferParams_(contentType, params) {
2126
- if (!params) {
2127
- return;
2128
- }
2129
-
2130
- if (!this.sourceBuffers_[contentType]) {
2131
- shaka.log.warning('Attempted to restore a non-existent source buffer');
2132
- return;
2133
- }
2134
-
2135
- this.sourceBuffers_[contentType].timestampOffset =
2136
- params.timestampOffset;
2137
- // `end` needs to be set before `start`
2138
- this.sourceBuffers_[contentType].appendWindowEnd =
2139
- params.appendWindowEnd;
2140
- this.sourceBuffers_[contentType].appendWindowStart =
2141
- params.appendWindowStart;
2142
- }
2143
-
2144
2106
  /**
2145
2107
  * Resets the MediaSource and re-adds source buffers due to codec mismatch
2146
2108
  *
@@ -2149,7 +2111,6 @@ shaka.media.MediaSourceEngine = class {
2149
2111
  * @private
2150
2112
  */
2151
2113
  async reset_(streamsByType) {
2152
- const Functional = shaka.util.Functional;
2153
2114
  const ContentType = shaka.util.ManifestParserUtils.ContentType;
2154
2115
  this.reloadingMediaSource_ = true;
2155
2116
  this.needSplitMuxedContent_ = false;
@@ -2171,36 +2132,19 @@ shaka.media.MediaSourceEngine = class {
2171
2132
  try {
2172
2133
  this.eventManager_.removeAll();
2173
2134
 
2174
- const cleanup = [];
2175
2135
  for (const contentType in this.transmuxers_) {
2176
- cleanup.push(this.transmuxers_[contentType].destroy());
2177
- }
2178
- for (const contentType in this.queues_) {
2179
- // Make a local copy of the queue and the first item.
2180
- const q = this.queues_[contentType];
2181
- const inProgress = q[0];
2182
-
2183
- // Drop everything else out of the original queue.
2184
- this.queues_[contentType] = q.slice(0, 1);
2185
-
2186
- // We will wait for this item to complete/fail.
2187
- if (inProgress) {
2188
- cleanup.push(inProgress.p.catch(Functional.noop));
2189
- }
2190
-
2191
- // The rest will be rejected silently if possible.
2192
- for (const item of q.slice(1)) {
2193
- item.p.reject(shaka.util.Destroyer.destroyedError());
2194
- }
2136
+ this.transmuxers_[contentType].destroy();
2195
2137
  }
2196
2138
  for (const contentType in this.sourceBuffers_) {
2197
2139
  const sourceBuffer = this.sourceBuffers_[contentType];
2198
2140
  try {
2199
2141
  this.mediaSource_.removeSourceBuffer(sourceBuffer);
2200
- } catch (e) {}
2142
+ } catch (e) {
2143
+ shaka.log.debug('Exception on removeSourceBuffer', e);
2144
+ }
2201
2145
  }
2202
- await Promise.all(cleanup);
2203
2146
  this.transmuxers_ = {};
2147
+ this.sourceBuffers_ = {};
2204
2148
 
2205
2149
  const previousDuration = this.mediaSource_.duration;
2206
2150
  this.mediaSourceOpen_ = new shaka.util.PublicPromise();
@@ -2231,23 +2175,17 @@ shaka.media.MediaSourceEngine = class {
2231
2175
  onSourceBufferAdded);
2232
2176
 
2233
2177
  for (const contentType of streamsByType.keys()) {
2234
- const previousParams = this.getSourceBufferParams_(contentType);
2235
2178
  const stream = streamsByType.get(contentType);
2236
2179
  // eslint-disable-next-line no-await-in-loop
2237
2180
  await this.initSourceBuffer_(contentType, stream, stream.codecs);
2238
- if (this.needSplitMuxedContent_) {
2239
- this.queues_[ContentType.AUDIO] = [];
2240
- this.queues_[ContentType.VIDEO] = [];
2241
- } else {
2242
- this.queues_[contentType] = [];
2243
- }
2244
-
2245
- this.restoreSourceBufferParams_(contentType, previousParams);
2246
2181
  }
2247
2182
  const audio = streamsByType.get(ContentType.AUDIO);
2248
2183
  if (audio && audio.isAudioMuxedInVideo) {
2249
2184
  this.needSplitMuxedContent_ = true;
2250
2185
  }
2186
+ if (this.needSplitMuxedContent_ && !this.queues_[ContentType.AUDIO]) {
2187
+ this.queues_[ContentType.AUDIO] = [];
2188
+ }
2251
2189
 
2252
2190
  // Fake a seek to catchup the playhead.
2253
2191
  this.video_.currentTime = currentTime;
@@ -2393,13 +2331,12 @@ shaka.media.MediaSourceEngine = class {
2393
2331
  * Returns true if it's necessary codec switch to load the new stream.
2394
2332
  *
2395
2333
  * @param {shaka.util.ManifestParserUtils.ContentType} contentType
2396
- * @param {shaka.extern.Stream} stream
2397
2334
  * @param {string} refMimeType
2398
2335
  * @param {string} refCodecs
2399
2336
  * @return {boolean}
2400
2337
  * @private
2401
2338
  */
2402
- isCodecSwitchNecessary_(contentType, stream, refMimeType, refCodecs) {
2339
+ isCodecSwitchNecessary_(contentType, refMimeType, refCodecs) {
2403
2340
  if (contentType == shaka.util.ManifestParserUtils.ContentType.TEXT) {
2404
2341
  return false;
2405
2342
  }
@@ -2443,13 +2380,12 @@ shaka.media.MediaSourceEngine = class {
2443
2380
  * new stream.
2444
2381
  *
2445
2382
  * @param {shaka.util.ManifestParserUtils.ContentType} contentType
2446
- * @param {shaka.extern.Stream} stream
2447
2383
  * @param {string} mimeType
2448
2384
  * @param {string} codecs
2449
2385
  * @return {boolean}
2450
2386
  */
2451
- isResetMediaSourceNecessary(contentType, stream, mimeType, codecs) {
2452
- if (!this.isCodecSwitchNecessary_(contentType, stream, mimeType, codecs)) {
2387
+ isResetMediaSourceNecessary(contentType, mimeType, codecs) {
2388
+ if (!this.isCodecSwitchNecessary_(contentType, mimeType, codecs)) {
2453
2389
  return false;
2454
2390
  }
2455
2391
 
@@ -2540,12 +2476,3 @@ shaka.media.MediaSourceEngine.SourceBufferMode_ = {
2540
2476
  * Called when an embedded 'emsg' box should trigger a manifest update.
2541
2477
  */
2542
2478
  shaka.media.MediaSourceEngine.PlayerInterface;
2543
-
2544
- /**
2545
- * @typedef {{
2546
- * timestampOffset: number,
2547
- * appendWindowStart: number,
2548
- * appendWindowEnd: number
2549
- * }}
2550
- */
2551
- shaka.media.MediaSourceEngine.SourceBufferParams;
@@ -2011,7 +2011,7 @@ shaka.media.StreamingEngine = class {
2011
2011
  const isResetMediaSourceNecessary =
2012
2012
  mediaState.lastCodecs && mediaState.lastMimeType &&
2013
2013
  this.playerInterface_.mediaSourceEngine.isResetMediaSourceNecessary(
2014
- mediaState.type, mediaState.stream, mimeType, fullCodecs);
2014
+ mediaState.type, mimeType, fullCodecs);
2015
2015
  if (isResetMediaSourceNecessary) {
2016
2016
  let otherState = null;
2017
2017
  if (mediaState.type === ContentType.VIDEO) {
@@ -2025,6 +2025,10 @@ shaka.media.StreamingEngine = class {
2025
2025
  // Then clear our cache of the last init segment, since MSE will be
2026
2026
  // reloaded and no init segment will be there post-reload.
2027
2027
  otherState.lastInitSegmentReference = null;
2028
+ // Clear cache of append window start and end, since they will need
2029
+ // to be reapplied post-reload by streaming engine.
2030
+ otherState.lastAppendWindowStart = null;
2031
+ otherState.lastAppendWindowEnd = null;
2028
2032
  // Now force the existing buffer to be cleared. It is not necessary
2029
2033
  // to perform the MSE clear operation, but this has the side-effect
2030
2034
  // that our state for that stream will then match MSE's post-reload
@@ -2729,6 +2733,8 @@ shaka.media.StreamingEngine = class {
2729
2733
  const audioMediaState = this.mediaStates_.get(ContentType.AUDIO);
2730
2734
  if (audioMediaState) {
2731
2735
  audioMediaState.lastInitSegmentReference = null;
2736
+ audioMediaState.lastAppendWindowStart = null;
2737
+ audioMediaState.lastAppendWindowEnd = null;
2732
2738
  if (clearBuffer) {
2733
2739
  this.forceClearBuffer_(audioMediaState);
2734
2740
  }
@@ -2740,6 +2746,8 @@ shaka.media.StreamingEngine = class {
2740
2746
  const videoMediaState = this.mediaStates_.get(ContentType.VIDEO);
2741
2747
  if (videoMediaState) {
2742
2748
  videoMediaState.lastInitSegmentReference = null;
2749
+ videoMediaState.lastAppendWindowStart = null;
2750
+ videoMediaState.lastAppendWindowEnd = null;
2743
2751
  if (clearBuffer) {
2744
2752
  this.forceClearBuffer_(videoMediaState);
2745
2753
  }
@@ -702,7 +702,7 @@ shaka.offline.Storage = class {
702
702
  // to play later (no point storing something we can't play).
703
703
  await shaka.util.StreamUtils.filterManifestByMediaCapabilities(
704
704
  drmEngine, manifest, config.offline.usePersistentLicense,
705
- config.drm.preferredKeySystems);
705
+ config.drm.preferredKeySystems, config.drm.keySystemsMapping);
706
706
 
707
707
  // Gather all tracks.
708
708
  const allTracks = [];
package/lib/player.js CHANGED
@@ -3136,15 +3136,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
3136
3136
  fullyLoaded.reject(this.videoErrorToShakaError_());
3137
3137
  });
3138
3138
 
3139
- const timeout = new Promise((resolve, reject) => {
3140
- const timer = new shaka.util.Timer(reject);
3141
- timer.tickAfter(this.config_.streaming.loadTimeout);
3142
- });
3143
-
3144
- await Promise.race([
3145
- fullyLoaded,
3146
- timeout,
3147
- ]);
3139
+ await shaka.util.Functional.promiseWithTimeout(
3140
+ this.config_.streaming.loadTimeout, fullyLoaded);
3148
3141
 
3149
3142
  const isLive = this.isLive();
3150
3143
 
@@ -8275,7 +8268,7 @@ shaka.Player.TYPICAL_BUFFERING_THRESHOLD_ = 0.5;
8275
8268
  * @export
8276
8269
  */
8277
8270
  // eslint-disable-next-line no-useless-concat, max-len
8278
- shaka.Player.version = 'v4.12.4' + '-uncompiled'; // x-release-please-version
8271
+ shaka.Player.version = 'v4.12.5' + '-uncompiled'; // x-release-please-version
8279
8272
 
8280
8273
  // Initialize the deprecation system using the version string we just set
8281
8274
  // on the player.
@@ -179,6 +179,9 @@ shaka.util.MimeUtils = class {
179
179
  return 'vvc'; // H266
180
180
  case base === 'dvh1':
181
181
  case base === 'dvhe':
182
+ if (profile && profile.startsWith('05')) {
183
+ return 'dovi-p5'; // Dolby Vision profile 5
184
+ }
182
185
  return 'dovi-hevc'; // Dolby Vision based in HEVC
183
186
  case base === 'dvav':
184
187
  case base === 'dva1':
@@ -89,4 +89,87 @@ shaka.util.ObjectUtils = class {
89
89
  }
90
90
  return clone;
91
91
  }
92
+
93
+
94
+ /**
95
+ * Constructs a string out of a value, similar to the JSON.stringify method.
96
+ * Unlike that method, this guarantees that the order of the keys in an
97
+ * object is alphabetical, so it can be used as a way to reliably compare two
98
+ * objects.
99
+ *
100
+ * @param {?} value
101
+ * @return {string}
102
+ */
103
+ static alphabeticalKeyOrderStringify(value) {
104
+ if (Array.isArray(value)) {
105
+ return shaka.util.ObjectUtils.arrayStringify_(value);
106
+ } else if (typeof value == 'function') {
107
+ // For safety, skip functions. For function x,
108
+ // x.prototype.constructor.prototype === x.prototype, so all functions
109
+ // contain circular references if treated like Objects.
110
+ return '';
111
+ } else if (value instanceof Object) {
112
+ return shaka.util.ObjectUtils.objectStringify_(value);
113
+ } else {
114
+ return JSON.stringify(value);
115
+ }
116
+ }
117
+
118
+
119
+ /**
120
+ * Helper for alphabeticalKeyOrderStringify for objects.
121
+ *
122
+ * @param {!Object} obj
123
+ * @return {string}
124
+ * @private
125
+ */
126
+ static objectStringify_(obj) {
127
+ // NOTE: This excludes prototype chain keys. For now, this is intended for
128
+ // anonymous objects only, so we don't care. If that changes, go back to a
129
+ // for-in loop.
130
+ const keys = Object.keys(obj);
131
+ // Alphabetically sort the keys, so they will be in a reliable order.
132
+ keys.sort();
133
+
134
+ const terms = [];
135
+ for (const key of keys) {
136
+ const escapedKey = JSON.stringify(key);
137
+ const value = obj[key];
138
+ if (value !== undefined) {
139
+ const escapedValue =
140
+ shaka.util.ObjectUtils.alphabeticalKeyOrderStringify(value);
141
+ if (escapedValue) {
142
+ terms.push(escapedKey + ':' + escapedValue);
143
+ }
144
+ }
145
+ }
146
+ return '{' + terms.join(',') + '}';
147
+ }
148
+
149
+
150
+ /**
151
+ * Helper for alphabeticalKeyOrderStringify for arrays.
152
+ *
153
+ * This could itself be JSON.stringify, except we want objects within the
154
+ * array to go through our own stringifiers.
155
+ *
156
+ * @param {!Array} arr
157
+ * @return {string}
158
+ * @private
159
+ */
160
+ static arrayStringify_(arr) {
161
+ const terms = [];
162
+ for (let index = 0; index < arr.length; index++) {
163
+ const escapedKey = index.toString();
164
+ const value = arr[index];
165
+ if (value !== undefined) {
166
+ const escapedValue =
167
+ shaka.util.ObjectUtils.alphabeticalKeyOrderStringify(value);
168
+ if (escapedValue) {
169
+ terms.push(escapedKey + ':' + escapedValue);
170
+ }
171
+ }
172
+ }
173
+ return '[' + terms.join(',') + ']';
174
+ }
92
175
  };
@@ -780,46 +780,6 @@ shaka.util.Platform = class {
780
780
  shaka.log.alwaysWarn('Tizen: Error detecting screen size, default ' +
781
781
  'screen size 1920x1080.');
782
782
  }
783
- } else if (Platform.isXboxOne()) {
784
- maxResolution.width = 1920;
785
- maxResolution.height = 1080;
786
- try {
787
- let winRT = undefined;
788
-
789
- // Try to access to WinRT for WebView, if it's not defined,
790
- // try to access to WinRT for WebView2, if it's not defined either,
791
- // let it throw.
792
- if (typeof Windows !== 'undefined') {
793
- winRT = Windows;
794
- } else {
795
- winRT = chrome.webview.hostObjects.sync.Windows;
796
- }
797
-
798
- const protectionCapabilities =
799
- new winRT.Media.Protection.ProtectionCapabilities();
800
- const protectionResult =
801
- winRT.Media.Protection.ProtectionCapabilityResult;
802
- // isTypeSupported may return "maybe", which means the operation is not
803
- // completed. This means we need to retry
804
- // https://learn.microsoft.com/en-us/uwp/api/windows.media.protection.protectioncapabilityresult?view=winrt-22621
805
- let result = null;
806
- const type =
807
- 'video/mp4;codecs="hvc1,mp4a";features="decode-res-x=3840,' +
808
- 'decode-res-y=2160,decode-bitrate=20000,decode-fps=30,' +
809
- 'decode-bpc=10,display-res-x=3840,display-res-y=2160,' +
810
- 'display-bpc=8"';
811
- const keySystem = 'com.microsoft.playready.recommendation';
812
- do {
813
- result = protectionCapabilities.isTypeSupported(type, keySystem);
814
- } while (result === protectionResult.maybe);
815
- if (result === protectionResult.probably) {
816
- maxResolution.width = 3840;
817
- maxResolution.height = 2160;
818
- }
819
- } catch (e) {
820
- shaka.log.alwaysWarn('Xbox: Error detecting screen size, default ' +
821
- 'screen size 1920x1080.');
822
- }
823
783
  } else if (Platform.isWebOS()) {
824
784
  try {
825
785
  const deviceInfo =
@@ -866,6 +826,54 @@ shaka.util.Platform = class {
866
826
  maxResolution.width = 1920;
867
827
  maxResolution.height = 1080;
868
828
  }
829
+ } else {
830
+ // For Xbox and UWP apps.
831
+ let winRT = undefined;
832
+ try {
833
+ // Try to access to WinRT for WebView, if it's not defined,
834
+ // try to access to WinRT for WebView2, if it's not defined either,
835
+ // let it throw.
836
+ if (typeof Windows !== 'undefined') {
837
+ winRT = Windows;
838
+ } else {
839
+ winRT = chrome.webview.hostObjects.sync.Windows;
840
+ }
841
+ } catch (e) {}
842
+ if (winRT) {
843
+ maxResolution.width = 1920;
844
+ maxResolution.height = 1080;
845
+ try {
846
+ const protectionCapabilities =
847
+ new winRT.Media.Protection.ProtectionCapabilities();
848
+ const protectionResult =
849
+ winRT.Media.Protection.ProtectionCapabilityResult;
850
+ // isTypeSupported may return "maybe", which means the operation
851
+ // is not completed. This means we need to retry
852
+ // https://learn.microsoft.com/en-us/uwp/api/windows.media.protection.protectioncapabilityresult?view=winrt-22621
853
+ let result = null;
854
+ const type =
855
+ 'video/mp4;codecs="hvc1,mp4a";features="decode-res-x=3840,' +
856
+ 'decode-res-y=2160,decode-bitrate=20000,decode-fps=30,' +
857
+ 'decode-bpc=10,display-res-x=3840,display-res-y=2160,' +
858
+ 'display-bpc=8"';
859
+ const keySystem = 'com.microsoft.playready.recommendation';
860
+ do {
861
+ result = protectionCapabilities.isTypeSupported(type, keySystem);
862
+ } while (result === protectionResult.maybe);
863
+ if (result === protectionResult.probably) {
864
+ maxResolution.width = 3840;
865
+ maxResolution.height = 2160;
866
+ }
867
+ } catch (e) {
868
+ shaka.log.alwaysWarn('Xbox: Error detecting screen size, default ' +
869
+ 'screen size 1920x1080.');
870
+ }
871
+ } else if (Platform.isXboxOne()) {
872
+ maxResolution.width = 1920;
873
+ maxResolution.height = 1080;
874
+ shaka.log.alwaysWarn('Xbox: Error detecting screen size, default ' +
875
+ 'screen size 1920x1080.');
876
+ }
869
877
  }
870
878
  return maxResolution;
871
879
  }