Source: lib/device/playstation.js

  1. /*! @license
  2. * Shaka Player
  3. * Copyright 2025 Google LLC
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. goog.provide('shaka.device.PlayStation');
  7. goog.require('shaka.device.AbstractDevice');
  8. goog.require('shaka.device.DeviceFactory');
  9. goog.require('shaka.device.IDevice');
  10. goog.require('shaka.log');
  11. goog.require('shaka.util.Lazy');
  12. /**
  13. * @final
  14. */
  15. shaka.device.PlayStation = class extends shaka.device.AbstractDevice {
  16. constructor() {
  17. super();
  18. /** @private {!shaka.util.Lazy<?number>} */
  19. this.version_ = new shaka.util.Lazy(() => {
  20. const match = navigator.userAgent.match(/PlayStation (\d+)/);
  21. if (match) {
  22. return parseInt(match[1], 10);
  23. }
  24. return null;
  25. });
  26. }
  27. /**
  28. * @override
  29. */
  30. getDeviceName() {
  31. return 'PlayStation';
  32. }
  33. /**
  34. * @override
  35. */
  36. getDeviceType() {
  37. return shaka.device.IDevice.DeviceType.CONSOLE;
  38. }
  39. /**
  40. * @override
  41. */
  42. getBrowserEngine() {
  43. return shaka.device.IDevice.BrowserEngine.WEBKIT;
  44. }
  45. /**
  46. * @override
  47. */
  48. getVersion() {
  49. return this.version_.value();
  50. }
  51. /**
  52. * @override
  53. */
  54. supportsMediaCapabilities() {
  55. return false;
  56. }
  57. /**
  58. * @override
  59. */
  60. supportsSequenceMode() {
  61. return false;
  62. }
  63. /**
  64. * @override
  65. */
  66. supportsSmoothCodecSwitching() {
  67. return false;
  68. }
  69. /**
  70. * @override
  71. */
  72. shouldAvoidUseTextDecoderEncoder() {
  73. return this.getVersion() === 4;
  74. }
  75. /**
  76. * @override
  77. */
  78. async detectMaxHardwareResolution() {
  79. const maxResolution = {width: 1920, height: 1080};
  80. let supports4K = false;
  81. try {
  82. const result = await window.msdk.device.getDisplayInfo();
  83. supports4K = result.resolution === '4K';
  84. } catch (e) {
  85. try {
  86. const result = await window.msdk.device.getDisplayInfoImmediate();
  87. supports4K = result.resolution === '4K';
  88. } catch (e) {
  89. shaka.log.alwaysWarn(
  90. 'PlayStation: Failed to get the display info:', e);
  91. }
  92. }
  93. if (supports4K) {
  94. maxResolution.width = 3840;
  95. maxResolution.height = 2160;
  96. }
  97. return maxResolution;
  98. }
  99. /**
  100. * @override
  101. */
  102. adjustConfig(config) {
  103. super.adjustConfig(config);
  104. // The PS4 only supports the Playready DRM, so it should
  105. // prefer that key system by default to improve startup performance.
  106. if (this.getVersion() === 4) {
  107. config.drm.preferredKeySystems.push('com.microsoft.playready');
  108. }
  109. config.streaming.clearDecodingCache = true;
  110. return config;
  111. }
  112. /**
  113. * @override
  114. */
  115. returnLittleEndianUsingPlayReady() {
  116. return this.getVersion() === 4;
  117. }
  118. /**
  119. * @override
  120. */
  121. supportsEncryptionSchemePolyfill() {
  122. return this.getVersion() !== 4;
  123. }
  124. /**
  125. * @return {boolean}
  126. * @private
  127. */
  128. static isPlayStation_() {
  129. return navigator.userAgent.includes('PlayStation');
  130. }
  131. };
  132. if (shaka.device.PlayStation.isPlayStation_()) {
  133. shaka.device.DeviceFactory.registerDeviceFactory(
  134. () => new shaka.device.PlayStation());
  135. }