feat: Add Device API (#8210)

The goal is to simplify and abstract feature logic detection. Currently
lots of places depend on various calls to `shaka.util.Platform` and
mainteinance of this is hard & not easy to read.

By introducing device API ideally rest of the player logic would look
into device features instead of directly checking platform. Additionally
we can more easily cache needed values, so we won't have to parse user
agent several times anymore.

---------

Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
This commit is contained in:
Wojciech Tyczyński
2025-06-02 13:46:40 +02:00
committed by GitHub
parent 9ac3f51473
commit 970d7756ea
78 changed files with 2727 additions and 1569 deletions
+5 -3
View File
@@ -7,11 +7,11 @@
goog.provide('shaka.util.StringUtils');
goog.require('goog.asserts');
goog.require('shaka.device.DeviceFactory');
goog.require('shaka.log');
goog.require('shaka.util.BufferUtils');
goog.require('shaka.util.Error');
goog.require('shaka.util.Lazy');
goog.require('shaka.util.Platform');
/**
@@ -38,7 +38,8 @@ shaka.util.StringUtils = class {
uint8 = uint8.subarray(3);
}
if (window.TextDecoder && !shaka.util.Platform.isPS4()) {
if (window.TextDecoder && !shaka.device.DeviceFactory.getDevice()
.shouldAvoidUseTextDecoderEncoder()) {
// Use the TextDecoder interface to decode the text. This has the
// advantage compared to the previously-standard decodeUriComponent that
// it will continue parsing even if it finds an invalid UTF8 character,
@@ -208,7 +209,8 @@ shaka.util.StringUtils = class {
* @export
*/
static toUTF8(str) {
if (window.TextEncoder && !shaka.util.Platform.isPS4()) {
if (window.TextEncoder && !shaka.device.DeviceFactory.getDevice()
.shouldAvoidUseTextDecoderEncoder()) {
const utf8Encoder = new TextEncoder();
return shaka.util.BufferUtils.toArrayBuffer(utf8Encoder.encode(str));
} else {